Система диалогов.
This commit is contained in:
parent
3c1619ee9f
commit
2a2399dc2c
8 changed files with 264 additions and 88 deletions
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://cmn7af4dsj8v2"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://cmn7af4dsj8v2"]
|
||||
|
||||
[ext_resource type="FontFile" uid="uid://dwn20pw40jpxm" path="res://fonts/ZxSpectrum7-nROZ0.ttf" id="1_e4s1h"]
|
||||
[ext_resource type="Script" path="res://scripts/Dialog.cs" id="2_a35aq"]
|
||||
|
||||
[sub_resource type="Theme" id="Theme_gtdw8"]
|
||||
default_font = ExtResource("1_e4s1h")
|
||||
|
@ -9,34 +10,56 @@ default_font_size = 10
|
|||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tctyf"]
|
||||
bg_color = Color(0.532017, 0.646565, 0.382003, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yovy8"]
|
||||
bg_color = Color(0.704854, 0.51027, 0.802981, 1)
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_8nvov"]
|
||||
font = ExtResource("1_e4s1h")
|
||||
font_size = 10
|
||||
outline_color = Color(0, 0, 0, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dk342"]
|
||||
bg_color = Color(0.906641, 0.460702, 0.0359737, 1)
|
||||
|
||||
[node name="Dialog" type="PanelContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -544.0
|
||||
offset_bottom = -451.0
|
||||
offset_bottom = -443.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
theme = SubResource("Theme_gtdw8")
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_tctyf")
|
||||
script = ExtResource("2_a35aq")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer"]
|
||||
[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Test dialog"
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_yovy8")
|
||||
|
||||
[node name="TextBox" type="Label" parent="VBoxContainer/PanelContainer"]
|
||||
custom_minimum_size = Vector2(96, 10)
|
||||
layout_mode = 2
|
||||
text = "Placeholder text"
|
||||
label_settings = SubResource("LabelSettings_8nvov")
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
|
||||
[node name="PanelContainer" type="PanelContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_dk342")
|
||||
|
||||
[node name="AuthorBox" type="Label" parent="VBoxContainer/HBoxContainer/PanelContainer"]
|
||||
custom_minimum_size = Vector2(96, 10)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
text = "NPC name"
|
||||
autowrap_mode = 3
|
||||
|
|
|
@ -9,7 +9,7 @@ script = ExtResource("1_xeo83")
|
|||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("2_r10xf")
|
||||
frame_progress = 0.606473
|
||||
frame_progress = 0.220485
|
||||
|
||||
[node name="Interactable" parent="." instance=ExtResource("2_hcfxj")]
|
||||
SpriteOffset = Vector2(0, -35)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=13 format=3 uid="uid://dfdsnwub212o6"]
|
||||
[gd_scene load_steps=14 format=3 uid="uid://dfdsnwub212o6"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/Player.cs" id="1_68nsf"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://e8ybb7seykdx" path="res://resources/sprites/player/player.tres" id="1_be2ex"]
|
||||
[ext_resource type="FontFile" uid="uid://dwn20pw40jpxm" path="res://fonts/ZxSpectrum7-nROZ0.ttf" id="3_w5ojp"]
|
||||
[ext_resource type="PackedScene" uid="uid://cmn7af4dsj8v2" path="res://prefabs/Dialog.tscn" id="4_owmws"]
|
||||
[ext_resource type="Script" path="res://scripts/ChatLogContainer.cs" id="4_tbl72"]
|
||||
[ext_resource type="PackedScene" uid="uid://phjermaw6phb" path="res://prefabs/AudioCollection.tscn" id="5_wnylg"]
|
||||
[ext_resource type="AudioStream" uid="uid://cb0344er3onkq" path="res://resources/sounds/door/doorOpen_1.ogg" id="7_2fkyu"]
|
||||
[ext_resource type="AudioStream" uid="uid://87caolv1uksk" path="res://resources/sounds/door/doorClose_3.ogg" id="8_4v0xv"]
|
||||
|
@ -41,26 +42,76 @@ shape = SubResource("RectangleShape2D_sed4o")
|
|||
offset = Vector2(0, -20)
|
||||
zoom = Vector2(2, 2)
|
||||
|
||||
[node name="ChatLog" type="PanelContainer" parent="Camera2D"]
|
||||
[node name="Control" type="Control" parent="Camera2D"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
theme = SubResource("Theme_8jldp")
|
||||
|
||||
[node name="ChatLog" type="PanelContainer" parent="Camera2D/Control"]
|
||||
layout_mode = 0
|
||||
offset_left = 160.0
|
||||
offset_top = -140.0
|
||||
offset_right = 276.0
|
||||
offset_right = 256.0
|
||||
offset_bottom = 100.0
|
||||
theme = SubResource("Theme_8jldp")
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_l7l8c")
|
||||
|
||||
[node name="HFlowContainer" type="VBoxContainer" parent="Camera2D/ChatLog"]
|
||||
[node name="PanelContainer" type="PanelContainer" parent="Camera2D/Control"]
|
||||
layout_mode = 0
|
||||
offset_left = 160.0
|
||||
offset_top = -140.0
|
||||
offset_right = 256.0
|
||||
offset_bottom = -130.0
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_l7l8c")
|
||||
|
||||
[node name="Label" type="Label" parent="Camera2D/Control/PanelContainer"]
|
||||
layout_mode = 2
|
||||
text = "Chat Log"
|
||||
|
||||
[node name="ChatLogContainer" type="VBoxContainer" parent="Camera2D/Control"]
|
||||
layout_mode = 2
|
||||
offset_left = 160.0
|
||||
offset_top = -130.0
|
||||
offset_right = 256.0
|
||||
offset_bottom = -56.0
|
||||
theme_override_constants/separation = 0
|
||||
script = ExtResource("4_tbl72")
|
||||
|
||||
[node name="PlaceholderDialog" parent="Camera2D/Control/ChatLogContainer" instance=ExtResource("4_owmws")]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Camera2D/ChatLog/HFlowContainer"]
|
||||
[node name="PlaceholderDialog2" parent="Camera2D/Control/ChatLogContainer" instance=ExtResource("4_owmws")]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "Chat"
|
||||
Text = "Placeholder text 2"
|
||||
Author = "NPC name 2"
|
||||
|
||||
[node name="Dialog" parent="Camera2D/ChatLog/HFlowContainer" instance=ExtResource("4_owmws")]
|
||||
[node name="CloseLabel" type="PanelContainer" parent="Camera2D/Control"]
|
||||
layout_mode = 2
|
||||
offset_left = 160.0
|
||||
offset_top = 90.0
|
||||
offset_right = 256.0
|
||||
offset_bottom = 100.0
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_l7l8c")
|
||||
|
||||
[node name="Dialog2" parent="Camera2D/ChatLog/HFlowContainer" instance=ExtResource("4_owmws")]
|
||||
[node name="Label" type="Label" parent="Camera2D/Control/CloseLabel"]
|
||||
layout_mode = 2
|
||||
text = "C - Exit"
|
||||
|
||||
[node name="NextLabel" type="PanelContainer" parent="Camera2D/Control"]
|
||||
layout_mode = 2
|
||||
offset_left = 160.0
|
||||
offset_top = 90.0
|
||||
offset_right = 256.0
|
||||
offset_bottom = 100.0
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_l7l8c")
|
||||
|
||||
[node name="Label" type="Label" parent="Camera2D/Control/NextLabel"]
|
||||
layout_mode = 2
|
||||
text = "E - Next"
|
||||
|
||||
[node name="Footsteps" parent="." instance=ExtResource("5_wnylg")]
|
||||
RandomPitch = true
|
||||
|
|
|
@ -158,7 +158,7 @@ Exit = NodePath("../Door_QUOTERS")
|
|||
|
||||
[node name="Test" parent="NPCs" instance=ExtResource("3_cu4p0")]
|
||||
position = Vector2(652, 14)
|
||||
NPCName = "Cock"
|
||||
NPCName = "Chef"
|
||||
Frames = ExtResource("4_7refo")
|
||||
|
||||
[node name="Captain" parent="NPCs" instance=ExtResource("3_cu4p0")]
|
||||
|
@ -175,6 +175,8 @@ Frames = ExtResource("6_hfiji")
|
|||
position = Vector2(1307, 254)
|
||||
NPCName = "Crewmate"
|
||||
Frames = ExtResource("7_3qwvo")
|
||||
DefaultDialogLine = "Прости. Я сейчас занят."
|
||||
DialogLines = ["Test message.", "Hi! My name is Vanyok. I'm your crewmate.", "Тестовое сообщение.", "Привет! Меня зовут Ванек. Я твой напарник по команде. "]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_mmd6a")]
|
||||
position = Vector2(1054, 255)
|
||||
|
|
23
scripts/ChatLogContainer.cs
Normal file
23
scripts/ChatLogContainer.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class ChatLogContainer : VBoxContainer
|
||||
{
|
||||
private const float MaxChatLogContainerSize = 220;
|
||||
|
||||
private Vector2 _initialPosition;
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_initialPosition = Position;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (Size.Y > MaxChatLogContainerSize)
|
||||
{
|
||||
Position = _initialPosition + new Vector2(Size.X, MaxChatLogContainerSize) - Size;
|
||||
}
|
||||
}
|
||||
}
|
34
scripts/Dialog.cs
Normal file
34
scripts/Dialog.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
[Tool]
|
||||
public partial class Dialog : PanelContainer
|
||||
{
|
||||
[Export] public string Text = "Placeholder text";
|
||||
[Export] public string Author = "NPC name";
|
||||
|
||||
private Label _textBox;
|
||||
private Label _authorBox;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_textBox = (Label)FindChild("TextBox");
|
||||
_authorBox = (Label)FindChild("AuthorBox");
|
||||
if (!Engine.IsEditorHint())
|
||||
{
|
||||
_textBox.Text = Text;
|
||||
_authorBox.Text = Author;
|
||||
}
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
if (_textBox.Text != Text) _textBox.Text = Text;
|
||||
if (_authorBox.Text != Author) _authorBox.Text = Author;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,15 +7,31 @@ public partial class NPC : Node2D
|
|||
{
|
||||
[Export] public string NPCName;
|
||||
[Export] public SpriteFrames Frames;
|
||||
[Export] public string DefaultDialogLine;
|
||||
[Export] public Array<string> DialogLines = new Array<string>();
|
||||
|
||||
public bool Flip
|
||||
{
|
||||
get => _sprite.FlipH;
|
||||
set => _sprite.FlipH = value;
|
||||
}
|
||||
|
||||
private AnimatedSprite2D _sprite;
|
||||
|
||||
private int _currentDialogLine;
|
||||
|
||||
//Диалог закончен, если больше нет строк диалога.
|
||||
public bool IsDialogEnded => _currentDialogLine == DialogLines.Count;
|
||||
|
||||
//Возвращаем строку диалога и увеличиваем счетчик текущей строки если диалог законче, и возвращаем строку по-умолчанию, если диалог законен.
|
||||
public string Message => IsDialogEnded ? DefaultDialogLine : DialogLines[_currentDialogLine++];
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
if (Frames is not null) _sprite.SpriteFrames = Frames;
|
||||
_sprite.Play("default");
|
||||
_currentDialogLine = 0;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
@ -30,18 +46,6 @@ public partial class NPC : Node2D
|
|||
}
|
||||
}
|
||||
|
||||
public void test()
|
||||
{
|
||||
if (_sprite.Animation == "walk")
|
||||
{
|
||||
_sprite.Play("default");
|
||||
}
|
||||
else
|
||||
{
|
||||
_sprite.Play("walk");
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_interactable_player_near_by(Player player)
|
||||
{
|
||||
player.InteractableObjects.Add(this);
|
||||
|
|
|
@ -6,17 +6,20 @@ public partial class Player : CharacterBody2D
|
|||
{
|
||||
private const double TransitionTime = 0.5;
|
||||
private const double CameraTransitionTime = 0.25;
|
||||
|
||||
public enum State
|
||||
{
|
||||
Normal,
|
||||
Wait,
|
||||
Transition,
|
||||
ReadChat
|
||||
ReadChat,
|
||||
ChatWithNPC
|
||||
}
|
||||
|
||||
private State _state;
|
||||
|
||||
[Export] public State CurrentState
|
||||
|
||||
[Export]
|
||||
public State CurrentState
|
||||
{
|
||||
get => _state;
|
||||
private set
|
||||
|
@ -24,29 +27,33 @@ public partial class Player : CharacterBody2D
|
|||
switch (value)
|
||||
{
|
||||
case State.Normal:
|
||||
if (_state == State.Transition) DoorSounds.Play();
|
||||
if (_state == State.Transition) _doorSounds.Play();
|
||||
Visible = true;
|
||||
break;
|
||||
case State.Transition:
|
||||
Visible = false;
|
||||
break;
|
||||
case State.ReadChat:
|
||||
// ChatLog.Visible = !ChatLog.Visible;
|
||||
_nextLabel.Visible = false;
|
||||
break;
|
||||
case State.Wait:
|
||||
break;
|
||||
case State.ChatWithNPC:
|
||||
_nextLabel.Visible = true;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
_state = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Export] public float Speed = 300.0f;
|
||||
|
||||
// Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
public float Gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
|
||||
|
||||
|
||||
public List<Node2D> InteractableObjects = new List<Node2D>();
|
||||
|
||||
public Node2D InteractableObject
|
||||
|
@ -69,27 +76,34 @@ public partial class Player : CharacterBody2D
|
|||
return nearObj;
|
||||
}
|
||||
}
|
||||
|
||||
protected AnimatedSprite2D Sprite;
|
||||
protected PanelContainer ChatLog;
|
||||
protected Camera2D Camera;
|
||||
protected AudioCollection Footsteps;
|
||||
protected AudioCollection DoorSounds;
|
||||
|
||||
|
||||
private AnimatedSprite2D _sprite;
|
||||
private PanelContainer _chatLog;
|
||||
private PanelContainer _nextLabel;
|
||||
private VBoxContainer _chatLogContainer;
|
||||
private Camera2D _camera;
|
||||
private AudioCollection _footsteps;
|
||||
private AudioCollection _doorSounds;
|
||||
|
||||
private Vector2 _newPosition;
|
||||
private double _currentTransitionTime = 0;
|
||||
private double _currentCameraTransitionTime = 0;
|
||||
private Vector2 _previousPosition;
|
||||
private Vector2 _nextPosition;
|
||||
private Vector2 _cameraDefaultPosition = new(0, -20);
|
||||
private Vector2 _cameraChatLogPosition = new(116, -20);
|
||||
private Vector2 _cameraChatLogPosition = new(96, -20);
|
||||
|
||||
private PackedScene _dialogBox = GD.Load<PackedScene>("res://prefabs/Dialog.tscn");
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
ChatLog = (PanelContainer)FindChild("ChatLog");
|
||||
Camera = (Camera2D)FindChild("Camera2D");
|
||||
Footsteps = (AudioCollection)FindChild("Footsteps");
|
||||
DoorSounds = (AudioCollection)FindChild("DoorSounds");
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_chatLog = (PanelContainer)FindChild("ChatLog");
|
||||
_nextLabel = (PanelContainer)FindChild("NextLabel");
|
||||
_chatLogContainer = (VBoxContainer)FindChild("ChatLogContainer");
|
||||
_camera = (Camera2D)FindChild("Camera2D");
|
||||
_footsteps = (AudioCollection)FindChild("Footsteps");
|
||||
_doorSounds = (AudioCollection)FindChild("DoorSounds");
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
|
@ -97,12 +111,13 @@ public partial class Player : CharacterBody2D
|
|||
switch (CurrentState)
|
||||
{
|
||||
case State.Normal:
|
||||
|
||||
if (Camera.Offset != _cameraDefaultPosition)
|
||||
|
||||
if (_camera.Offset != _cameraDefaultPosition)
|
||||
{
|
||||
if (_currentCameraTransitionTime < CameraTransitionTime)
|
||||
{
|
||||
Camera.Offset = _cameraChatLogPosition.Lerp(_cameraDefaultPosition, (float)(_currentCameraTransitionTime * 1/CameraTransitionTime));
|
||||
_camera.Offset = _cameraChatLogPosition.Lerp(_cameraDefaultPosition,
|
||||
(float)(_currentCameraTransitionTime * 1 / CameraTransitionTime));
|
||||
_currentCameraTransitionTime += delta;
|
||||
}
|
||||
else
|
||||
|
@ -110,51 +125,37 @@ public partial class Player : CharacterBody2D
|
|||
_currentCameraTransitionTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector2 velocity = Velocity;
|
||||
|
||||
// if (!IsOnFloor())
|
||||
// {
|
||||
// velocity += GetGravity() * (float)delta;
|
||||
// }
|
||||
//
|
||||
// if (IsOnFloor() && !Visible)
|
||||
// {
|
||||
// Visible = true;
|
||||
// }
|
||||
|
||||
Vector2 direction = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||
if (direction != Vector2.Zero)
|
||||
{
|
||||
Footsteps.Play();
|
||||
// if (!Footsteps.IsPlaying())
|
||||
// {
|
||||
// // Footsteps.PitchScale = (float)GD.RandRange(0.5, 1.0);
|
||||
// Footsteps.Play();
|
||||
// }
|
||||
_footsteps.Play();
|
||||
velocity.X = direction.X * Speed;
|
||||
Sprite.Play("walk");
|
||||
Sprite.FlipH = direction.X switch
|
||||
_sprite.Play("walk");
|
||||
_sprite.FlipH = direction.X switch
|
||||
{
|
||||
> 0 => false,
|
||||
< 0 => true,
|
||||
_ => Sprite.FlipH
|
||||
_ => _sprite.FlipH
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// Footsteps.Stop();
|
||||
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
|
||||
Sprite.Play("default");
|
||||
_sprite.Play("default");
|
||||
}
|
||||
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
break;
|
||||
case State.Transition:
|
||||
if (_currentTransitionTime < TransitionTime)
|
||||
{
|
||||
GlobalPosition = _previousPosition.Lerp(_nextPosition, (float)(_currentTransitionTime * 1/TransitionTime));
|
||||
GlobalPosition = _previousPosition.Lerp(_nextPosition,
|
||||
(float)(_currentTransitionTime * 1 / TransitionTime));
|
||||
_currentTransitionTime += delta;
|
||||
}
|
||||
else
|
||||
|
@ -165,25 +166,33 @@ public partial class Player : CharacterBody2D
|
|||
|
||||
break;
|
||||
case State.ReadChat:
|
||||
if (Camera.Offset != _cameraChatLogPosition)
|
||||
{
|
||||
if (_currentCameraTransitionTime < CameraTransitionTime)
|
||||
{
|
||||
Camera.Offset = _cameraDefaultPosition.Lerp(_cameraChatLogPosition, (float)(_currentCameraTransitionTime * 1/CameraTransitionTime));
|
||||
_currentCameraTransitionTime += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentCameraTransitionTime = 0;
|
||||
}
|
||||
}
|
||||
ShowChatLog(delta);
|
||||
break;
|
||||
case State.ChatWithNPC:
|
||||
ShowChatLog(delta);
|
||||
break;
|
||||
case State.Wait:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ShowChatLog(double delta)
|
||||
{
|
||||
if (_camera.Offset != _cameraChatLogPosition)
|
||||
{
|
||||
if (_currentCameraTransitionTime < CameraTransitionTime)
|
||||
{
|
||||
_camera.Offset = _cameraDefaultPosition.Lerp(_cameraChatLogPosition,
|
||||
(float)(_currentCameraTransitionTime * 1 / CameraTransitionTime));
|
||||
_currentCameraTransitionTime += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentCameraTransitionTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
|
@ -192,12 +201,41 @@ public partial class Player : CharacterBody2D
|
|||
{
|
||||
if (InteractableObject is NPC npc)
|
||||
{
|
||||
npc.test();
|
||||
void AddMessage()
|
||||
{
|
||||
var msg = _dialogBox.Instantiate<Dialog>();
|
||||
msg.Text = npc.Message;
|
||||
msg.Author = npc.NPCName;
|
||||
_chatLogContainer.AddChild(msg);
|
||||
if (npc.IsDialogEnded) CurrentState = State.ReadChat;
|
||||
}
|
||||
|
||||
switch (CurrentState)
|
||||
{
|
||||
case State.Normal:
|
||||
|
||||
if (GlobalPosition.X - npc.GlobalPosition.X > 0)
|
||||
{
|
||||
npc.Flip = false;
|
||||
_sprite.FlipH = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
npc.Flip = true;
|
||||
_sprite.FlipH = false;
|
||||
}
|
||||
CurrentState = State.ChatWithNPC;
|
||||
AddMessage();
|
||||
break;
|
||||
case State.ChatWithNPC:
|
||||
AddMessage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (InteractableObject is Door door)
|
||||
{
|
||||
DoorSounds.Play();
|
||||
_doorSounds.Play();
|
||||
_previousPosition = GlobalPosition;
|
||||
_nextPosition = door.Exit.GlobalPosition;
|
||||
CurrentState = State.Wait;
|
||||
|
@ -225,4 +263,5 @@ public partial class Player : CharacterBody2D
|
|||
CurrentState = State.Transition;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue