Added robot follow button
This commit is contained in:
@@ -33,6 +33,11 @@ layout_mode = 2
|
|||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
text = "Jump to"
|
text = "Jump to"
|
||||||
|
|
||||||
|
[node name="Follow" type="Button" parent="HBoxContainer" unique_id=101092106]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
text = "Follow"
|
||||||
|
|
||||||
[node name="CurrentScript" type="RichTextLabel" parent="HBoxContainer" unique_id=425408407]
|
[node name="CurrentScript" type="RichTextLabel" parent="HBoxContainer" unique_id=425408407]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
@@ -42,3 +47,4 @@ horizontal_alignment = 1
|
|||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
[connection signal="pressed" from="HBoxContainer/Jump" to="." method="OnJumpToClicked"]
|
[connection signal="pressed" from="HBoxContainer/Jump" to="." method="OnJumpToClicked"]
|
||||||
|
[connection signal="pressed" from="HBoxContainer/Follow" to="." method="OnFollowToClicked"]
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ public class SurvivalState
|
|||||||
{
|
{
|
||||||
energy = Math.Clamp(energy + 40f, 0f, maxEnergy);
|
energy = Math.Clamp(energy + 40f, 0f, maxEnergy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GameData.inventory.TryRemoveItem("coal", 1))
|
||||||
|
{
|
||||||
|
energy = Math.Clamp(energy + 10f, 0f, maxEnergy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateStatus()
|
private void UpdateStatus()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ public partial class Camera3d : Camera3D
|
|||||||
[Export] public float Speed = 7.5f;
|
[Export] public float Speed = 7.5f;
|
||||||
[Export] public float MouseSensitivity = 0.2f;
|
[Export] public float MouseSensitivity = 0.2f;
|
||||||
[Export] public float ScrollStrength = 5.0f;
|
[Export] public float ScrollStrength = 5.0f;
|
||||||
|
private Robot robot;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
@@ -33,13 +34,27 @@ public partial class Camera3d : Camera3D
|
|||||||
|
|
||||||
if (direction != Vector3.Zero)
|
if (direction != Vector3.Zero)
|
||||||
{
|
{
|
||||||
|
if(robot != null) robot = null;
|
||||||
direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d;
|
direction = direction.Normalized() * Speed * (Input.IsActionPressed("sprint") ? 2.5f : 1) * d;
|
||||||
Translate(direction);
|
Translate(direction);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(robot != null)
|
||||||
|
{
|
||||||
|
Position = new Vector3(robot.Position.X, 10 - visibleLayer * 4, robot.Position.Z + 4f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (Position.Y != 10 - visibleLayer * 4)
|
if (Position.Y != 10 - visibleLayer * 4)
|
||||||
{
|
{
|
||||||
Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z);
|
Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Follow(Robot robot)
|
||||||
|
{
|
||||||
|
this.robot = robot;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public partial class UIHandler : Control
|
|||||||
{
|
{
|
||||||
[Export] CodingWindow codingWindow;
|
[Export] CodingWindow codingWindow;
|
||||||
[Export] RobotList robotList;
|
[Export] RobotList robotList;
|
||||||
[Export] Camera3D mainCam;
|
[Export] Camera3d mainCam;
|
||||||
[Export] Map map;
|
[Export] Map map;
|
||||||
[Export] RichTextLabel FPS;
|
[Export] RichTextLabel FPS;
|
||||||
[Export] RichTextLabel RAM;
|
[Export] RichTextLabel RAM;
|
||||||
@@ -27,15 +27,18 @@ public partial class UIHandler : Control
|
|||||||
|
|
||||||
|
|
||||||
private bool receivedRobotJumpSignal = false;
|
private bool receivedRobotJumpSignal = false;
|
||||||
|
private bool receivedRobotFollowSignal = false;
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
UIStyle.Apply(this);
|
UIStyle.Apply(this);
|
||||||
robotList.OnRobotJumpTo += OnRobotJumpTo;
|
robotList.OnRobotJumpTo += OnRobotJumpTo;
|
||||||
|
robotList.OnRobotFollow += OnRobotFollow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
{
|
{
|
||||||
robotList.OnRobotJumpTo -= OnRobotJumpTo;
|
robotList.OnRobotJumpTo -= OnRobotJumpTo;
|
||||||
|
robotList.OnRobotFollow -= OnRobotFollow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
@@ -81,6 +84,7 @@ public partial class UIHandler : Control
|
|||||||
|
|
||||||
public void HandleRobotListButton()
|
public void HandleRobotListButton()
|
||||||
{
|
{
|
||||||
|
receivedRobotFollowSignal = false;
|
||||||
receivedRobotJumpSignal = false;
|
receivedRobotJumpSignal = false;
|
||||||
OpenUIElement(robotList);
|
OpenUIElement(robotList);
|
||||||
}
|
}
|
||||||
@@ -182,6 +186,15 @@ public partial class UIHandler : Control
|
|||||||
OpenUIElement(codingWindow);
|
OpenUIElement(codingWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRobotFollow(Robot robot)
|
||||||
|
{
|
||||||
|
if (receivedRobotFollowSignal) return;
|
||||||
|
|
||||||
|
receivedRobotFollowSignal = true;
|
||||||
|
mainCam.Follow(robot);
|
||||||
|
OpenUIElement(codingWindow);
|
||||||
|
}
|
||||||
|
|
||||||
private void DisplaySurvivalStats()
|
private void DisplaySurvivalStats()
|
||||||
{
|
{
|
||||||
energyLabel.Text = $"Energy: {GameData.survival.energy:0}/{GameData.survival.maxEnergy:0}";
|
energyLabel.Text = $"Energy: {GameData.survival.energy:0}/{GameData.survival.maxEnergy:0}";
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ public partial class RobotDisplay : PanelContainer
|
|||||||
[Export] public RichTextLabel currentScript;
|
[Export] public RichTextLabel currentScript;
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
||||||
|
[Signal]
|
||||||
|
public delegate void OnRobotFollowEventHandler(Robot robot);
|
||||||
public Robot robot;
|
public Robot robot;
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
@@ -22,4 +24,9 @@ public partial class RobotDisplay : PanelContainer
|
|||||||
{
|
{
|
||||||
EmitSignal(SignalName.OnRobotJumpTo, robot);
|
EmitSignal(SignalName.OnRobotJumpTo, robot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnFollowToClicked()
|
||||||
|
{
|
||||||
|
EmitSignal(SignalName.OnRobotFollow, robot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ public partial class RobotList : PanelContainer
|
|||||||
[Export] Button spawnRobot;
|
[Export] Button spawnRobot;
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
||||||
|
[Signal]
|
||||||
|
public delegate void OnRobotFollowEventHandler(Robot robot);
|
||||||
private PackedScene robotDisplayPrefab;
|
private PackedScene robotDisplayPrefab;
|
||||||
private string spawnId = "";
|
private string spawnId = "";
|
||||||
|
|
||||||
@@ -46,6 +48,11 @@ public partial class RobotList : PanelContainer
|
|||||||
EmitSignal(SignalName.OnRobotJumpTo, robot);
|
EmitSignal(SignalName.OnRobotJumpTo, robot);
|
||||||
Visible = false;
|
Visible = false;
|
||||||
};
|
};
|
||||||
|
display.OnRobotFollow += (robot) =>
|
||||||
|
{
|
||||||
|
EmitSignal(SignalName.OnRobotFollow, robot);
|
||||||
|
Visible = false;
|
||||||
|
};
|
||||||
robotList.AddChild(display);
|
robotList.AddChild(display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user