-
-
Save Syjgin/b874f03cb772004c8e7b7e42e2aa5336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Components; | |
using Data; | |
using Dialogues.PopupQueue; | |
using EventBus; | |
using UnityEngine; | |
using Zenject; | |
namespace GameInput | |
{ | |
public class InputHandler : MonoBehaviour | |
{ | |
[Inject] private PersistentDatabase _persistentDatabase; | |
[Inject] private GameEventBus _gameEventBus; | |
//события для оповещения о вводе | |
... | |
public EventHandlers.PopupStateChangeEvent PopupStateChanged; | |
public EventHandlers.TextPopupReplyClick TextPopupReplyClick; | |
public EventHandlers.PopupConfirmReplyEvent ConfirmPopupReplyClick; | |
private EventHandlers.InputSettingsChanged _onInputSettingsChanged; | |
private GameScene _currentScene; | |
private SettingsConfig _settingsConfig; | |
private readonly PopupQueue _popupQueue = new(); | |
private PopupQueueElementType _baseElementType = PopupQueueElementType.NoPopup; | |
private void OnEnable() | |
{ | |
_gameEventBus.GameSceneLoaded += GameSceneLoaded; | |
_gameEventBus.GameStateLoaded += GameStateLoaded; | |
} | |
private void GameSceneLoaded(GameScene scene) | |
{ | |
_currentScene = scene; | |
_baseElementType = _popupQueue.Init(scene); | |
} | |
private void OnDisable() | |
{ | |
_gameEventBus.GameSceneLoaded -= GameSceneLoaded; | |
_gameEventBus.GameStateLoaded -= GameStateLoaded; | |
} | |
private void GameStateLoaded(SaveFile currentSave) | |
{ | |
if (_currentScene == GameScene.Platform) | |
{ | |
var platform = currentSave.LastPlatform; | |
TryOpenDialog(new PlatformDialogueDefinition { Platform = platform}); | |
} | |
else | |
{ | |
NotifyStateChanged(); | |
} | |
} | |
private void Update() | |
{ | |
HandleEngine(); | |
HandleRotation(); | |
HandleBuoyancy(); | |
HandleMouse(); | |
HandleWheel(); | |
HandleUi(); | |
} | |
public void TryCloseDialog(bool force = false) | |
{ | |
if(_popupQueue.TryCloseCurrentElement(force)) | |
NotifyStateChanged(); | |
if(_popupQueue.TryEnqueuePreviousElement()) | |
NotifyStateChanged(); | |
} | |
public void TryOpenDialog(IPopupQueueElement popupQueueElement) | |
{ | |
if (_popupQueue.TryEnqueueElement(popupQueueElement)) | |
{ | |
NotifyStateChanged(); | |
} | |
} | |
private void NotifyStateChanged() | |
{ | |
PopupStateChanged?.Invoke(_popupQueue.GetCurrentElement(), _popupQueue.GetLastOperation()); | |
} | |
//обработка ввода | |
... | |
private void HandleUi() | |
{ | |
if (Input.GetKeyDown(_settingsConfig.Menu)) | |
{ | |
TryCloseDialog(); | |
return; | |
} | |
... | |
if (Input.GetKeyDown(_settingsConfig.Inventory)) | |
{ | |
if (_popupQueue.GetCurrentElement().ElementType == PopupQueueElementType.AirshipPopup) | |
{ | |
TryCloseDialog(); | |
return; | |
} | |
TryOpenDialog(new AirshipPopupDefinition()); | |
return; | |
} | |
} | |
public PopupQueueElementType GetBasePopupType() | |
{ | |
return _baseElementType; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment