Decision WORKS YAY
This commit is contained in:
1 parent
739d1f0374
commit
ccc4c04234
177 files changed
+208565
-120026
No files matched your search
@@ -6,8 +6,10 @@ using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Code.Infrastructure.Utils;
|
||||
using Code.OfficeGame.BattleMode.Actions.Player;
|
||||
using Code.OfficeGame.BattleMode.UI;
|
||||
using Code.OfficeGame.Player;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using KinematicCharacterController;
|
||||
@@ -40,6 +42,7 @@ namespace Code.Game.TestingLevel
|
||||
#endif
|
||||
|
||||
Context.InputService.EnableMap(ActionMappings.OpenMovement);
|
||||
Context.InputService.EnableMap(ActionMappings.UI); //
|
||||
|
||||
await Context.Camera.SwitchState(CameraMode.OpenMovement);
|
||||
|
||||
@@ -69,6 +72,10 @@ namespace Code.Game.TestingLevel
|
||||
|
||||
playerMovementController.Freeze = true;
|
||||
|
||||
BattleActionDecisionPanel battleActionDecisionPanel =
|
||||
(BattleActionDecisionPanel) await Context.UIFactory
|
||||
.LoadPanel(UIPanelType.BattleActionDecision,false);
|
||||
|
||||
// ((OpenMovementCameraState)Context.Camera.CurrentBaseState).SetTarget(player.transform);
|
||||
|
||||
void InstallExtra(Scene scene, ContainerBuilder builder)
|
||||
@@ -80,6 +87,8 @@ namespace Code.Game.TestingLevel
|
||||
builder.RegisterValue(playerControlsProvider);
|
||||
builder.RegisterValue(playerAnimatorProvider);
|
||||
builder.RegisterValue(playerTimelineActor);
|
||||
|
||||
builder.RegisterValue(battleActionDecisionPanel);
|
||||
}
|
||||
|
||||
await UniTask.WhenAll(
|
||||
|
||||
@@ -14,7 +14,9 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
public interface IUIFactory
|
||||
{
|
||||
// Новый
|
||||
Canvas GameplayCanvas { get; }
|
||||
// Тот что был создан на сцене
|
||||
Canvas Canvas { get; }
|
||||
UniTask<UIPanel> LoadPanel(UIPanelType panelType, bool gameplayCanvas, Transform parent = null);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public bool Finished { get; protected set; }
|
||||
public abstract void Tick(float tickDelta);
|
||||
public abstract UniTask<bool> DecideAction();
|
||||
public abstract UniTask<BattleActionDecisionResultCode> DecideAction();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public enum BattleActionDecisionResultCode
|
||||
{
|
||||
Decided,
|
||||
Deciding,
|
||||
CancelDecision
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6aa25f1eaf09411a875619aca0a36a3e
|
||||
timeCreated: 1792758849
|
||||
@@ -4,7 +4,6 @@ using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Input;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using KinematicCharacterController;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -127,18 +126,20 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
}
|
||||
|
||||
private CancellationTokenSource _waitForEnterTokenSource;
|
||||
private bool _positionChosen;
|
||||
private BattleActionDecisionResultCode _decisionResultCode;
|
||||
|
||||
public override async UniTask<bool> DecideAction()
|
||||
public override async UniTask<BattleActionDecisionResultCode> DecideAction()
|
||||
{
|
||||
_waitForEnterTokenSource = new CancellationTokenSource();
|
||||
_positionChosen = false;
|
||||
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
|
||||
_targetPosition = _playerMovementController.transform.position;
|
||||
|
||||
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Select,
|
||||
SelectPosition);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
|
||||
ConfirmPosition);
|
||||
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
|
||||
CancelPosition);
|
||||
|
||||
await UniTask.WaitUntilCanceled(_waitForEnterTokenSource.Token).SuppressCancellationThrow();
|
||||
|
||||
@@ -146,12 +147,21 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
SelectPosition);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
|
||||
ConfirmPosition);
|
||||
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
|
||||
CancelPosition);
|
||||
|
||||
_waitForEnterTokenSource.Dispose();
|
||||
_waitForEnterTokenSource = null;
|
||||
|
||||
Finished = !_positionChosen;
|
||||
return _positionChosen;
|
||||
Finished = _decisionResultCode != BattleActionDecisionResultCode.Decided;
|
||||
|
||||
return _decisionResultCode;
|
||||
}
|
||||
|
||||
private void CancelPosition(InputAction.CallbackContext obj)
|
||||
{
|
||||
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
|
||||
_waitForEnterTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
private void ConfirmPosition(InputAction.CallbackContext input)
|
||||
@@ -164,9 +174,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
_corners = _path.corners;
|
||||
_currentCornerIndex = _corners.Length > 1 ? 1 : 0;
|
||||
_positionChosen = true;
|
||||
_decisionResultCode = BattleActionDecisionResultCode.Decided;
|
||||
}
|
||||
|
||||
else _decisionResultCode = BattleActionDecisionResultCode.Deciding;
|
||||
|
||||
_waitForEnterTokenSource?.Cancel();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
public enum BattleActionType
|
||||
{
|
||||
None,
|
||||
Wait,
|
||||
Move
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
if (_waitFrames <= 0) Finished = true;
|
||||
}
|
||||
|
||||
public override async UniTask<bool> DecideAction()
|
||||
public override async UniTask<BattleActionDecisionResultCode> DecideAction()
|
||||
{
|
||||
Finished = false;
|
||||
|
||||
_waitFrames = 120;
|
||||
|
||||
return true;
|
||||
return BattleActionDecisionResultCode.Decided;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public BattleAction CurrentAction { get; protected set;}
|
||||
public bool Finished => CurrentAction == null || CurrentAction.Finished;
|
||||
|
||||
public abstract UniTask DecideAction(CancellationToken ct);
|
||||
public abstract UniTask DecideAction(CancellationToken ctx);
|
||||
|
||||
public Animator animator;
|
||||
|
||||
protected Dictionary<BattleActionType, BattleAction> BattleActions = new();
|
||||
protected readonly Dictionary<BattleActionType, BattleAction> BattleActions = new();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Threading;
|
||||
using Code.Game.Gameplay.Player;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.OfficeGame.BattleMode.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
@@ -10,6 +11,8 @@ namespace Code.OfficeGame.BattleMode.Actions.Player
|
||||
{
|
||||
public class PlayerTimelineActor : EntityTimelineActor
|
||||
{
|
||||
[Inject] private BattleActionDecisionPanel _battleActionDecisionPanel;
|
||||
|
||||
[Inject]
|
||||
private void Construct(
|
||||
CameraStateMachine cameraStateMachine,
|
||||
@@ -17,20 +20,41 @@ namespace Code.OfficeGame.BattleMode.Actions.Player
|
||||
PlayerMovementController playerMovementController)
|
||||
{
|
||||
BattleActions.Add(BattleActionType.Wait, new BattleActionWait());
|
||||
BattleActions.Add(BattleActionType.Move, new BattleActionMove(cameraStateMachine, inputService, playerMovementController));
|
||||
BattleActions.Add(BattleActionType.Move,
|
||||
new BattleActionMove(cameraStateMachine, inputService, playerMovementController));
|
||||
}
|
||||
|
||||
public override async UniTask DecideAction(CancellationToken ct)
|
||||
public override async UniTask DecideAction(CancellationToken ctx)
|
||||
{
|
||||
bool succeded = false;
|
||||
BattleActionDecisionResultCode decision = BattleActionDecisionResultCode.Deciding;
|
||||
|
||||
var decidedAction = BattleActionType.Move; // T
|
||||
_battleActionDecisionPanel.SetEntityInfo(BattleActions);
|
||||
|
||||
while (!succeded || ct.IsCancellationRequested)
|
||||
BattleActionType decidedAction = BattleActionType.None;
|
||||
|
||||
while (decidedAction == BattleActionType.None || ctx.IsCancellationRequested)
|
||||
{
|
||||
Debug.Log("player decided to move");
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
|
||||
await _battleActionDecisionPanel.Open(ctx);
|
||||
|
||||
succeded = await BattleActions[decidedAction].DecideAction();
|
||||
decidedAction = await _battleActionDecisionPanel.GetDecision(ctx);
|
||||
|
||||
while (decidedAction != BattleActionType.None
|
||||
&& decision == BattleActionDecisionResultCode.Deciding
|
||||
&& !ctx.IsCancellationRequested)
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
await _battleActionDecisionPanel.Close(ctx);
|
||||
|
||||
// Панель UI здесь
|
||||
|
||||
decision = await BattleActions[decidedAction].DecideAction();
|
||||
|
||||
if (decision == BattleActionDecisionResultCode.CancelDecision)
|
||||
decidedAction = BattleActionType.None;
|
||||
}
|
||||
}
|
||||
|
||||
CurrentAction = BattleActions[decidedAction];
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba88f56679ed4d33914ac7a9974f8390
|
||||
timeCreated: 1792755196
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.UI;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using LitMotion;
|
||||
using LitMotion.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.UI
|
||||
{
|
||||
public class BattleActionDecisionPanel : UIPanel
|
||||
{
|
||||
[SerializeField] private float duration = 0.35f;
|
||||
[SerializeField] private Button actionButtonPrefab;
|
||||
|
||||
private List<Button> _actionButtons = new();
|
||||
|
||||
private UniTaskCompletionSource<BattleActionType> _decisionCompletionSource;
|
||||
private MotionHandle _motionHandle;
|
||||
|
||||
public void SetEntityInfo(Dictionary<BattleActionType, BattleAction> battleActions)
|
||||
{
|
||||
_decisionCompletionSource = new();
|
||||
|
||||
foreach (var button in _actionButtons) Destroy(button.gameObject);
|
||||
|
||||
_actionButtons.Clear();
|
||||
|
||||
foreach (var action in battleActions.Keys)
|
||||
{
|
||||
var button = Instantiate(actionButtonPrefab, transform);
|
||||
|
||||
_actionButtons.Add(button);
|
||||
|
||||
button.onClick.AddListener(() => _decisionCompletionSource.TrySetResult(action));
|
||||
|
||||
//button.GetComponentInChildren<Text>().text = action.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask<BattleActionType> GetDecision(CancellationToken cts)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _decisionCompletionSource.Task
|
||||
.AttachExternalCancellation(cts);
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
return BattleActionType.None;
|
||||
}
|
||||
}
|
||||
|
||||
public override async UniTask Open(CancellationToken cts = default)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
float startY = -((RectTransform)transform).rect.height;
|
||||
float targetY = 0f;
|
||||
|
||||
_motionHandle = LMotion.Create(startY, targetY, duration)
|
||||
.WithEase(Ease.OutCubic)
|
||||
.WithScheduler(MotionScheduler.UpdateIgnoreTimeScale)
|
||||
.BindToAnchoredPositionY(((RectTransform)transform));
|
||||
|
||||
await _motionHandle.ToUniTask(cts);
|
||||
}
|
||||
|
||||
public override async UniTask Close(CancellationToken cts = default)
|
||||
{
|
||||
float startY = ((RectTransform)transform).anchoredPosition.y;
|
||||
float targetY = -((RectTransform)transform).rect.height;
|
||||
|
||||
_motionHandle = LMotion.Create(startY, targetY, duration)
|
||||
.WithEase(Ease.InBack)
|
||||
.WithScheduler(MotionScheduler.UpdateIgnoreTimeScale)
|
||||
.BindToAnchoredPositionY((RectTransform)transform);
|
||||
|
||||
await _motionHandle.ToUniTask(cts);
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff051dd3d8594dbf8e89477b15ed489e
|
||||
timeCreated: 1792755210
|
||||
@@ -4,7 +4,8 @@ namespace Code.Infrastructure.Input
|
||||
{
|
||||
Debug,
|
||||
OpenMovement,
|
||||
BattleMode
|
||||
BattleMode,
|
||||
UI
|
||||
}
|
||||
|
||||
// Написать, чтобы розлин сама писала этот енам
|
||||
@@ -20,7 +21,8 @@ namespace Code.Infrastructure.Input
|
||||
Movement,
|
||||
Watchment,
|
||||
Select,
|
||||
Confirm
|
||||
Confirm,
|
||||
Cancel
|
||||
}
|
||||
// Написать, чтобы розлин сама писала этот енам
|
||||
public enum DebugActions
|
||||
|
||||
@@ -2,7 +2,6 @@ namespace Code.Infrastructure.UI
|
||||
{
|
||||
public enum UIPanelType
|
||||
{
|
||||
// Cleaning
|
||||
Cleaning
|
||||
BattleActionDecision
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user