Межинтерфейс
This commit is contained in:
1 parent
45fe19be24
commit
edf3821c0d
9 files changed
+74
-45
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using Code.App.StateMachine;
|
||||
using Code.StateMachine;
|
||||
using Code.UI;
|
||||
|
||||
namespace Code.App.AppStates
|
||||
{
|
||||
@@ -10,6 +11,9 @@ namespace Code.App.AppStates
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
Context.UIService.LoadingScreen.Show();
|
||||
Context.UIService.SwitchPanelTo(UIPanel.GameOver);
|
||||
|
||||
base.EnterState();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace Code.App.AppStates
|
||||
|
||||
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
|
||||
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
|
||||
|
||||
_playerHealth.OnDeath += EndGame;
|
||||
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveMoney);
|
||||
@@ -46,6 +48,8 @@ namespace Code.App.AppStates
|
||||
base.EnterState();
|
||||
}
|
||||
|
||||
|
||||
// Debug
|
||||
private void GiveHealth(InputAction.CallbackContext context)
|
||||
{
|
||||
UnityEngine.Debug.Log("Giving health");
|
||||
@@ -74,6 +78,11 @@ namespace Code.App.AppStates
|
||||
{
|
||||
}
|
||||
|
||||
private void EndGame()
|
||||
{
|
||||
Context.StateMachine.SwitchState(AppState.GameOver);
|
||||
}
|
||||
|
||||
public override void ExitState()
|
||||
{
|
||||
_playerHealth = null;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Code.App
|
||||
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
|
||||
|
||||
InitializeCamera(containerBuilder, staticDataService);
|
||||
containerBuilder.AddSingleton(typeof(UIFactory), typeof(IUIFactory));
|
||||
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
|
||||
containerBuilder.AddSingleton(typeof(SceneLoaderService), typeof(ISceneLoaderService));
|
||||
|
||||
|
||||
@@ -10,22 +10,28 @@ namespace Code.UI
|
||||
{
|
||||
[SerializeField] private Image dispatcher;
|
||||
[SerializeField] private TMP_Text timer;
|
||||
|
||||
private HealthBar _healthBar;
|
||||
private MoneyBar _moneyBar;
|
||||
[SerializeField] private Image healthBar;
|
||||
[SerializeField] private TMP_Text moneyText;
|
||||
|
||||
public void Initialize(PlayerMoney money, PlayerHealth health, HealthBar healthBar = null, MoneyBar moneyBar = null)
|
||||
private void MoneyUpdate(int count, int money)
|
||||
{
|
||||
_healthBar = healthBar;
|
||||
_moneyBar = moneyBar;
|
||||
|
||||
money.OnMoneyGet += _moneyBar.MoneyUpdate;
|
||||
money.OnMoneyLoose += _moneyBar.MoneyUpdate;
|
||||
_moneyBar.MoneyUpdate(0,money.Money);
|
||||
|
||||
health.OnDamage += _healthBar.HealthUpdate;
|
||||
_healthBar.HealthUpdate(0,health);
|
||||
// TODO Анимация получения\потери
|
||||
moneyText.text = money.ToString();
|
||||
}
|
||||
private void HealthUpdate(int count, PlayerHealth health)
|
||||
{
|
||||
// TODO Анимация потери
|
||||
float fillAmount = (float)health.HealthPoints / health.MaxHealthPoints;
|
||||
healthBar.fillAmount = fillAmount;
|
||||
}
|
||||
public void Initialize(PlayerMoney money, PlayerHealth health)
|
||||
{
|
||||
money.OnMoneyGet += MoneyUpdate;
|
||||
money.OnMoneyLoose += MoneyUpdate;
|
||||
MoneyUpdate(0,money.Money);
|
||||
|
||||
health.OnDamage += HealthUpdate;
|
||||
HealthUpdate(0,health);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Code.UI
|
||||
{
|
||||
public interface IUIFactory
|
||||
{
|
||||
MoneyBar CreateMoneybar(Canvas canvas);
|
||||
HealthBar CreateHealthbar(Canvas canvas);
|
||||
Canvas CreateCanvas();
|
||||
UIElement CreatePanel(Canvas canvas, UIPanel uiPanel);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Code.UI.GameplayElements;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -6,10 +5,20 @@ namespace Code.UI
|
||||
{
|
||||
public class UIFactory : IUIFactory
|
||||
{
|
||||
[Inject] private HealthBar healthbarPrefab;
|
||||
[Inject] private MoneyBar moneybarPrefab;
|
||||
[Inject] private UIElement[] _uiPanelsPrefabs;
|
||||
[Inject] private Canvas _canvasPrefab;
|
||||
|
||||
public MoneyBar CreateMoneybar(Canvas canvas) => Object.Instantiate(moneybarPrefab, canvas.transform);
|
||||
public HealthBar CreateHealthbar(Canvas canvas) => Object.Instantiate(healthbarPrefab, canvas.transform);
|
||||
public Canvas CreateCanvas()
|
||||
{
|
||||
Canvas canvas = Object.Instantiate(_canvasPrefab);
|
||||
Object.DontDestroyOnLoad(canvas);
|
||||
|
||||
return canvas;
|
||||
}
|
||||
|
||||
public UIElement CreatePanel(Canvas canvas, UIPanel uiPanel)
|
||||
{
|
||||
return Object.Instantiate(_uiPanelsPrefabs[(int)uiPanel], canvas.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Code.UI
|
||||
{
|
||||
Loading,
|
||||
MainMenu,
|
||||
Gameplay
|
||||
Gameplay,
|
||||
GameOver
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,18 @@ namespace Code.UI
|
||||
{
|
||||
public class UIService : IUIService
|
||||
{
|
||||
private UIElement[] _uiPanelsPrefabs;
|
||||
private Canvas _canvas;
|
||||
private IUIFactory _factory;
|
||||
|
||||
public UIElement CurrentPanel { get; private set; }
|
||||
public LoadingPanel LoadingScreen { get; private set; }
|
||||
|
||||
public UIService(UIElement[] uiPanelsPrefabs, Canvas canvas)
|
||||
|
||||
public UIService(IUIFactory factory)
|
||||
{
|
||||
_canvas = Object.Instantiate(canvas);
|
||||
Object.DontDestroyOnLoad(_canvas);
|
||||
_factory = factory;
|
||||
_canvas = _factory.CreateCanvas();
|
||||
|
||||
_uiPanelsPrefabs = uiPanelsPrefabs;
|
||||
|
||||
LoadingScreen = (LoadingPanel) Object.Instantiate(_uiPanelsPrefabs[(int)UIPanel.Loading], _canvas.transform);
|
||||
LoadingScreen = (LoadingPanel) _factory.CreatePanel(_canvas,UIPanel.Loading);
|
||||
}
|
||||
|
||||
public void EnablePanel() => CurrentPanel.gameObject.SetActive(true);
|
||||
@@ -26,7 +25,7 @@ namespace Code.UI
|
||||
{
|
||||
if(CurrentPanel) Object.Destroy(CurrentPanel.gameObject);
|
||||
|
||||
CurrentPanel = Object.Instantiate(_uiPanelsPrefabs[(int)uiPanel], _canvas.transform);
|
||||
CurrentPanel = _factory.CreatePanel(_canvas, uiPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user