Интерфейс для диалогов
This commit is contained in:
parent
7afef58a7f
commit
65003d3030
10 changed files with 288 additions and 49 deletions
|
@ -3,21 +3,99 @@ using System;
|
|||
|
||||
public partial class ChatLogContainer : VBoxContainer
|
||||
{
|
||||
private const float MaxChatLogContainerSize = 220;
|
||||
public enum ChatState
|
||||
{
|
||||
Hidden,
|
||||
Default,
|
||||
Scrolling
|
||||
}
|
||||
|
||||
private ChatState _state;
|
||||
|
||||
public ChatState CurrentState
|
||||
{
|
||||
get => _state;
|
||||
set
|
||||
{
|
||||
_state = value;
|
||||
switch (_state)
|
||||
{
|
||||
case ChatState.Hidden:
|
||||
break;
|
||||
case ChatState.Default:
|
||||
break;
|
||||
case ChatState.Scrolling:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const float MaxChatLogContainerSize = 200;
|
||||
|
||||
private Vector2 _initialPosition;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_initialPosition = Position;
|
||||
_state = ChatState.Default;
|
||||
}
|
||||
|
||||
private Vector2 GetBottomPosition()
|
||||
{
|
||||
return _initialPosition + new Vector2(Size.X, MaxChatLogContainerSize) - Size;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (Size.Y > MaxChatLogContainerSize)
|
||||
if (CurrentState is ChatState.Default && Size.Y > MaxChatLogContainerSize)
|
||||
{
|
||||
Position = _initialPosition + new Vector2(Size.X, MaxChatLogContainerSize) - Size;
|
||||
Position = GetBottomPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("ui_down"))
|
||||
{
|
||||
switch (CurrentState)
|
||||
{
|
||||
case ChatState.Hidden:
|
||||
return;
|
||||
case ChatState.Default:
|
||||
CurrentState = ChatState.Scrolling;
|
||||
break;
|
||||
case ChatState.Scrolling:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
|
||||
Position = (Position + new Vector2(0, -10)).Clamp(GetBottomPosition(), _initialPosition);
|
||||
}
|
||||
if (@event.IsActionPressed("ui_up"))
|
||||
{
|
||||
switch (CurrentState)
|
||||
{
|
||||
case ChatState.Hidden:
|
||||
return;
|
||||
case ChatState.Default:
|
||||
CurrentState = ChatState.Scrolling;
|
||||
break;
|
||||
case ChatState.Scrolling:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
Position = (Position + new Vector2(0, 10)).Clamp(GetBottomPosition(), _initialPosition);
|
||||
}
|
||||
if (CurrentState is ChatState.Default or ChatState.Scrolling)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
|||
[Tool]
|
||||
public partial class Dialog : PanelContainer
|
||||
{
|
||||
|
||||
[Export] public string Text = "Placeholder text";
|
||||
[Export] public string Author = "NPC name";
|
||||
|
||||
|
|
|
@ -35,11 +35,15 @@ public partial class Player : CharacterBody2D
|
|||
break;
|
||||
case State.ReadChat:
|
||||
_nextLabel.Visible = false;
|
||||
_exitLabel.Visible = true;
|
||||
_chatLogContainer.CurrentState = ChatLogContainer.ChatState.Default;
|
||||
break;
|
||||
case State.Wait:
|
||||
break;
|
||||
case State.ChatWithNPC:
|
||||
_nextLabel.Visible = true;
|
||||
_exitLabel.Visible = false;
|
||||
_chatLogContainer.CurrentState = ChatLogContainer.ChatState.Default;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
@ -80,7 +84,8 @@ public partial class Player : CharacterBody2D
|
|||
private AnimatedSprite2D _sprite;
|
||||
private PanelContainer _chatLog;
|
||||
private PanelContainer _nextLabel;
|
||||
private VBoxContainer _chatLogContainer;
|
||||
private PanelContainer _exitLabel;
|
||||
private ChatLogContainer _chatLogContainer;
|
||||
private Camera2D _camera;
|
||||
private AudioCollection _footsteps;
|
||||
private AudioCollection _doorSounds;
|
||||
|
@ -91,7 +96,7 @@ public partial class Player : CharacterBody2D
|
|||
private Vector2 _previousPosition;
|
||||
private Vector2 _nextPosition;
|
||||
private Vector2 _cameraDefaultPosition = new(0, -20);
|
||||
private Vector2 _cameraChatLogPosition = new(96, -20);
|
||||
private Vector2 _cameraChatLogPosition = new(108, -20);
|
||||
|
||||
private PackedScene _dialogBox = GD.Load<PackedScene>("res://prefabs/Dialog.tscn");
|
||||
|
||||
|
@ -100,7 +105,8 @@ public partial class Player : CharacterBody2D
|
|||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_chatLog = (PanelContainer)FindChild("ChatLog");
|
||||
_nextLabel = (PanelContainer)FindChild("NextLabel");
|
||||
_chatLogContainer = (VBoxContainer)FindChild("ChatLogContainer");
|
||||
_exitLabel = (PanelContainer)FindChild("ExitLabel");
|
||||
_chatLogContainer = (ChatLogContainer)FindChild("ChatLogContainer");
|
||||
_camera = (Camera2D)FindChild("Camera2D");
|
||||
_footsteps = (AudioCollection)FindChild("Footsteps");
|
||||
_doorSounds = (AudioCollection)FindChild("DoorSounds");
|
||||
|
@ -251,6 +257,7 @@ public partial class Player : CharacterBody2D
|
|||
break;
|
||||
case State.ReadChat:
|
||||
CurrentState = State.Normal;
|
||||
_chatLogContainer.CurrentState = ChatLogContainer.ChatState.Hidden;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue