Допил интерфейса, здоровья, денег

This commit is contained in:
ThomasCharester committed 2025-10-30 21:13:42 +03:00
1 parent b214bb0f63
commit bea109175b
29 files changed
+675 -789

No files matched your search

@@ -6,13 +6,15 @@ using Code.Scenes;
using Code.StateMachine;
using Code.UI;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.App.AppStates
{
public class GameplayState : BaseState<AppStateMachineContext>
{
private PlayerHealthPoints _playerHealthPoints;
private PlayerHealth _playerHealth;
private PlayerMoney _playerMoney;
public GameplayState(AppStateMachineContext context) : base(context)
{
}
@@ -21,28 +23,65 @@ namespace Code.App.AppStates
{
Context.SceneLoaderService.LoadScene((int)SceneIds.MovementDev, SceneLoaded);
Context.InputService.EnableMap(ActionMappings.Gameplay);
Context.UIService.LoadingScreen.Show();
Context.UIService.SwitchPanelTo(UIPanel.Gameplay);
Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.LooseHealth, LooseHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.LooseMoney, LooseMoney);
}
private void SceneLoaded()
{
((GameplayPanel)Context.UIService.CurrentPanel).Initialize(_playerMoney, _playerHealth);
Context.UIService.LoadingScreen.Hide();
base.EnterState();
}
private void GiveHealth(InputAction.CallbackContext context)
{
_playerHealth.GetDamage(-1);
}
private void LooseHealth(InputAction.CallbackContext context)
{
_playerHealth.GetDamage(1);
}
private void GiveMoney(InputAction.CallbackContext context)
{
_playerMoney.GiveMoney(100);
}
private void LooseMoney(InputAction.CallbackContext context)
{
_playerMoney.GiveMoney(100);
}
public override void Tick()
{
}
public override void ExitState()
{
_playerHealth = null;
_playerMoney = null;
Context.InputService.DisableMap(ActionMappings.Gameplay);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveHealth);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.LooseHealth, LooseHealth);
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.LooseMoney, LooseMoney);
base.ExitState();
}
}
@@ -1,6 +1,7 @@
using Code.App.StateMachine;
using Code.Configs;
using Code.Gameplay.Camera;
using Code.Gameplay.Player;
using Code.Input;
using Code.Scenes;
using Code.StaticData;
@@ -22,6 +23,7 @@ namespace Code.App
InstallInfrastructureUnit(containerBuilder, staticDataService);
containerBuilder.AddSingleton(typeof(InputService), typeof(IInputService));
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
InitializeCamera(containerBuilder, staticDataService);
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
@@ -61,6 +63,7 @@ namespace Code.App
containerBuilder.AddSingleton(staticDataService, typeof(IStaticDataService));
containerBuilder.AddSingleton(staticDataService.InputConfig.inputActionAsset, typeof(InputActionAsset));
containerBuilder.AddSingleton(staticDataService.CameraConfig, typeof(CameraConfig));
containerBuilder.AddSingleton(staticDataService.PlayerConfig, typeof(PlayerConfig));
containerBuilder.AddSingleton(staticDataService.CharacterConfig, typeof(CharacterConfig));
containerBuilder.AddSingleton(staticDataService.UIConfig.canvasPrefab, typeof(Canvas));
containerBuilder.AddSingleton(staticDataService.UIConfig.uiElementsPrefabs, typeof(UIElement[]));
@@ -1,4 +1,5 @@
using Code.Gameplay.Camera;
using Code.Gameplay.Player;
using Code.Input;
using Code.Scenes;
using Code.UI;
@@ -8,10 +9,11 @@ namespace Code.App.StateMachine
{
public class AppStateMachineContext
{
[Inject] public ISceneLoaderService SceneLoaderService;
[Inject] public IInputService InputService;
[Inject] public AppStateMachine StateMachine;
[Inject] public CameraStateMachine CameraStateMachine;
[Inject] public IUIService UIService;
[Inject] public ISceneLoaderService SceneLoaderService { get; private set; }
[Inject] public IInputService InputService { get; private set; }
[Inject] public AppStateMachine StateMachine { get; private set; }
[Inject] public CameraStateMachine CameraStateMachine { get; private set; }
[Inject] public IUIService UIService { get; private set; }
[Inject] public IPlayerFactory PlayerFactory { get; private set; }
}
}
@@ -0,0 +1,8 @@
namespace Code.Gameplay.Player
{
public interface IPlayerFactory
{
PlayerHealth CreatePlayerHealth(int count = -1);
PlayerMoney CreatePlayerMoney(int count = 0);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d2689e8fb7e48a4a8a62a97d292e1e3
timeCreated: 1761761977
@@ -4,15 +4,16 @@ using Reflex.Attributes;
namespace Code.Gameplay.Player
{
public class PlayerFactory
public class PlayerFactory : IPlayerFactory
{
[Inject] PlayerConfig _playerConfig;
public PlayerHealthPoints CreatePlayerHP(int count = -1)
public PlayerHealth CreatePlayerHealth(int count = -1)
{
if (count < 0) count = _playerConfig.maxHealth;
return new PlayerHealthPoints(count);
return new(count);
}
public PlayerMoney CreatePlayerMoney(int count = 0) => new(count);
}
}
@@ -1,27 +0,0 @@
namespace Code.Gameplay.Player
{
public class PlayerHealthPoints
{
public delegate void OnDeathDelegate();
public event OnDeathDelegate OnDeath;
public delegate void OnDamageDelegate(int damage);
public event OnDamageDelegate OnDamage;
private int _healthPoints;
public int HealthPoints => _healthPoints;
public void GetDamage(int count)
{
_healthPoints -= count;
OnDamage?.Invoke(count);
if (_healthPoints <= 0) OnDeath?.Invoke();
}
public PlayerHealthPoints(int healthPoints = 1) => _healthPoints = healthPoints;
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 105512e4d3af4b36932a0d569b87c68e
timeCreated: 1761059874
@@ -6,22 +6,27 @@ namespace Code.Gameplay.Player
public event OnDeathDelegate OnDeath;
public delegate void OnDamageDelegate(int damage);
public delegate void OnDamageDelegate(int damage, int health);
public event OnDamageDelegate OnDamage;
private int _healthPoints;
public int HealthPoints => _healthPoints;
public int MaxHealthPoints { get; private set; }
public void GetDamage(int count)
{
_healthPoints -= count;
OnDamage?.Invoke(count);
OnDamage?.Invoke(count, _healthPoints);
if (_healthPoints <= 0) OnDeath?.Invoke();
}
public PlayerHealth(int healthPoints = 1) => _healthPoints = healthPoints;
public PlayerHealth(int maxHealthPoints = 1)
{
_healthPoints = maxHealthPoints;
MaxHealthPoints = maxHealthPoints;
}
}
}
@@ -0,0 +1,26 @@
namespace Code.Gameplay.Player
{
public class PlayerMoney
{
public delegate void OnMoneyGetDelegate(int count, int money);
public event OnMoneyGetDelegate OnMoneyGet;
public delegate void OnMoneyLooseDelegate(int count, int money);
public event OnMoneyLooseDelegate OnMoneyLoose;
private int _money;
public int Money => _money;
public void GiveMoney(int amount)
{
_money += amount;
OnMoneyGet?.Invoke(amount, _money);
}
public void LooseMoney(int amount)
{
_money -= amount;
OnMoneyLoose?.Invoke(amount, _money);
}
public PlayerMoney(int money) => _money = money;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 455b08dd38eb4f4f8ab62b9493cd5e12
timeCreated: 1761760097
@@ -4,6 +4,7 @@ namespace Code.Input
{
MainMenu,
UI,
Gameplay
Gameplay,
Debug
}
}
@@ -6,4 +6,11 @@ namespace Code.Input
Look,
Zoom
}
public enum DebugActions
{
GiveHealth,
LooseHealth,
GiveMoney,
LooseMoney
}
}
@@ -1,4 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.Input
{
@@ -19,5 +21,7 @@ namespace Code.Input
// Для переключения режима камеры
bool ToggleCameraModePressed { get; }
void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
void DebugUnbindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
}
}
@@ -21,6 +21,8 @@ namespace Code.Input
{
_inputActionAsset = inputActionAsset;
SetupInputCallbacks();
inputActionAsset.actionMaps[(int)ActionMappings.Debug].Enable();
}
// Обработка всех карт ввода
@@ -165,10 +167,10 @@ namespace Code.Input
public void EnableMap(ActionMappings actionMap) => _inputActionAsset.actionMaps[(int)actionMap].Enable();
public void DisableMap(ActionMappings actionMap) => _inputActionAsset.actionMaps[(int)actionMap].Disable();
public void BindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action) => _inputActionAsset
public void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action) => _inputActionAsset
.actionMaps[mapId].actions[actionId].performed += action;
public void UnbindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action) =>
public void DebugUnbindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action) =>
_inputActionAsset
.actionMaps[mapId].actions[actionId].performed -= action;
@@ -6,6 +6,7 @@ namespace Code.Scenes
MainMenu,
Gameplay,
// TODO: поменяно для теста
MovementDev
MovementDev,
DevGen
}
}
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Code.Configs;
@@ -11,5 +12,6 @@ namespace Code.StaticData
CameraConfig CameraConfig { get; }
CharacterConfig CharacterConfig { get; }
UIConfig UIConfig { get; }
PlayerConfig PlayerConfig { get; }
}
}
@@ -11,6 +11,7 @@ namespace Code.StaticData
public CameraConfig CameraConfig { get; private set; }
public CharacterConfig CharacterConfig { get; private set; }
public UIConfig UIConfig { get; private set; }
public PlayerConfig PlayerConfig { get; private set; }
public void Load()
{
@@ -19,6 +20,7 @@ namespace Code.StaticData
CameraConfig = Resources.Load<CameraConfig>(string.Format(StringPaths.ConfigSingle, "App", "CameraConfig"));
CharacterConfig = Resources.Load<CharacterConfig>(string.Format(StringPaths.ConfigSingle, "App", "CharacterConfig"));
UIConfig = Resources.Load<UIConfig>(string.Format(StringPaths.ConfigSingle, "App", "UIConfig"));
PlayerConfig = Resources.Load<PlayerConfig>(string.Format(StringPaths.ConfigSingle, "App", "PlayerConfig"));
}
}
}
@@ -0,0 +1,50 @@
using Code.Gameplay.Player;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Code.UI
{
public class GameplayPanel : UIElement
{
[SerializeField] private Image healthBar;
[SerializeField] private Image dispatcher;
[SerializeField] private TMP_Text moneyText;
[SerializeField] private TMP_Text timer;
private int _maxHealth;
public void Initialize(PlayerMoney money, PlayerHealth health)
{
money.OnMoneyGet += MoneyUpdate;
money.OnMoneyLoose += MoneyUpdate;
moneyText.text = money.Money.ToString();
health.OnDamage += HealthUpdate;
healthBar.fillAmount = (float)health.HealthPoints / _maxHealth * 100f;
_maxHealth = health.MaxHealthPoints;
}
private void MoneyUpdate(int count, int money)
{
// TODO Анимация получения\потери
moneyText.text = money.ToString();
}
private void HealthUpdate(int count, int health)
{
// TODO Анимация потери
healthBar.fillAmount = (float)health / _maxHealth * 100f;
}
private void Update()
{
timer.text = Time.deltaTime.ToString();
}
public void Hide()
{
}
public void Show()
{
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d79893d2e9024719924dc5c15d582e33
timeCreated: 1761760839