Add prompts

This commit is contained in:
Sofia 2024-08-20 17:49:13 +03:00
parent 5331087313
commit fea4df8284
4 changed files with 78 additions and 30 deletions

View File

@ -2,7 +2,7 @@
[ext_resource type="Script" path="res://scripts/Hud.cs" id="1_hvqpl"] [ext_resource type="Script" path="res://scripts/Hud.cs" id="1_hvqpl"]
[node name="HUD" type="Control" node_paths=PackedStringArray("HoverText", "CameraHeightContainer", "CameraHeightSlider")] [node name="HUD" type="Control" node_paths=PackedStringArray("HoverText", "CameraHeightContainer", "CameraHeightSlider", "CornerPrompt")]
layout_mode = 3 layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
@ -14,6 +14,7 @@ script = ExtResource("1_hvqpl")
HoverText = NodePath("CenterContainer2/HoverText") HoverText = NodePath("CenterContainer2/HoverText")
CameraHeightContainer = NodePath("CameraHeightContainer") CameraHeightContainer = NodePath("CameraHeightContainer")
CameraHeightSlider = NodePath("CameraHeightContainer/CameraHeightSlider") CameraHeightSlider = NodePath("CameraHeightContainer/CameraHeightSlider")
CornerPrompt = NodePath("TableRecallPrompt")
[node name="CenterContainer" type="CenterContainer" parent="."] [node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1 layout_mode = 1
@ -56,23 +57,25 @@ horizontal_alignment = 1
[node name="CenterContainer2" type="CenterContainer" parent="."] [node name="CenterContainer2" type="CenterContainer" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 7 anchors_preset = 12
anchor_left = 0.5
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 0.5 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = -94.0 offset_top = -134.0
offset_top = -118.59
offset_right = 95.0
offset_bottom = -73.59
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 0 grow_vertical = 0
[node name="HoverText" type="RichTextLabel" parent="CenterContainer2"] [node name="HoverText" type="Label" parent="CenterContainer2"]
layout_mode = 2 layout_mode = 2
theme_override_font_sizes/normal_font_size = 32 theme_override_font_sizes/font_size = 24
bbcode_enabled = true
text = "[Hover Text]" text = "[Hover Text]"
fit_content = true horizontal_alignment = 1
scroll_active = false
autowrap_mode = 0 [node name="TableRecallPrompt" type="Label" parent="."]
layout_mode = 1
offset_left = 34.0
offset_top = 22.0
offset_right = 314.0
offset_bottom = 67.0
theme_override_font_sizes/font_size = 24
text = "[Table Recall Text]"

View File

@ -26,6 +26,7 @@ namespace Gmtk24 {
Name = "BuildingBlock"; Name = "BuildingBlock";
FreezeMode = FreezeModeEnum.Kinematic; FreezeMode = FreezeModeEnum.Kinematic;
CanSleep = false; CanSleep = false;
InteractName = "Pick Up";
} }
public override void _Ready() { public override void _Ready() {

View File

@ -1,4 +1,6 @@
using Godot; using Godot;
using Godot.Collections;
using System.Linq;
using System.Text; using System.Text;
namespace Gmtk24 { namespace Gmtk24 {
@ -6,16 +8,20 @@ namespace Gmtk24 {
[Export] [Export]
public Player Player; public Player Player;
[Export] [Export]
public RichTextLabel HoverText; public Label HoverText;
[Export] [Export]
public bool InteractionPaused = false; public bool InteractionPaused = false;
[Export] [Export]
public Container CameraHeightContainer; public Container CameraHeightContainer;
[Export] [Export]
public Slider CameraHeightSlider; public Slider CameraHeightSlider;
[Export]
public Label CornerPrompt;
private Interactible Hovered; private Interactible Hovered;
private Dictionary<string, string> ButtonNames = new();
public override void _Process(double delta) { public override void _Process(double delta) {
if (Player == null) if (Player == null)
return; return;
@ -30,7 +36,8 @@ namespace Gmtk24 {
} }
if (!InteractionPaused && collider is Interactible interactible) { if (!InteractionPaused) {
if (collider is Interactible interactible) {
if (interactible != Hovered) { if (interactible != Hovered) {
Hovered?.SetHovered(false); Hovered?.SetHovered(false);
interactible.SetHovered(true); interactible.SetHovered(true);
@ -38,24 +45,61 @@ namespace Gmtk24 {
Hovered = interactible; Hovered = interactible;
StringBuilder Builder = new StringBuilder(); HoverText.Text = $"{FormButtonNames("interact")}: {interactible.InteractName}";
foreach (var e in InputMap.ActionGetEvents("interact")) { } else {
Builder.Append($"{e.AsText().Replace("(Physical)", "")}: {interactible.InteractName}"); HoverText.Text = "";
} }
HoverText.Text = Builder.ToString();
} else { } else {
Hovered?.SetHovered(false); Hovered?.SetHovered(false);
Hovered = null; Hovered = null;
if (Player.Table.Orbit.HeldBlock != null) {
var release = FormButtonNames("release_block");
var place = FormButtonNames("place_block");
var rotate_right = FormButtonNames("rotate_block_right");
var rotate_left = FormButtonNames("rotate_block_left");
HoverText.Text = $"{place}: Place Block\n{release}: Throw Block\nRotate Block: ({rotate_right}/{rotate_left})";
} else {
HoverText.Text = ""; HoverText.Text = "";
} }
} }
if (!Player.Table.Orbit.IsEnabled) {
var names = FormButtonNames("toggle_table");
if (Player.Table.IsEnabled)
CornerPrompt.Text = $"{names}: {"Recall Table"}";
else
CornerPrompt.Text = $"{names}: {"Spawn Table"}";
} else {
if (Player.Table.Orbit.HeldBlock == null) {
var zoom_out = FormButtonNames("zoom_orbit_out");
var zoom_in = FormButtonNames("zoom_orbit_out");
var drag = FormButtonNames("drag_orbit");
CornerPrompt.Text = $"Zoom: {zoom_in}/{zoom_out}\nDrag: {drag}";
} else {
CornerPrompt.Text = "";
}
}
}
public override void _UnhandledInput(InputEvent @event) { public override void _UnhandledInput(InputEvent @event) {
if (@event.IsAction("interact") && Hovered != null) { if (@event.IsAction("interact") && Hovered != null) {
Hovered.HandleInput(@event); Hovered.HandleInput(@event);
GetViewport().SetInputAsHandled(); GetViewport().SetInputAsHandled();
} }
} }
private string FormButtonNames(string actionName) {
if (!ButtonNames.ContainsKey(actionName)) {
ButtonNames.Add(actionName, InputMap.ActionGetEvents(actionName)
.Select(e => e.AsText().Replace(" (Physical)", ""))
.Aggregate((a, b) => $"{a}, {b}"));
}
return ButtonNames[actionName];
}
public void ResetPromptCache() {
ButtonNames.Clear();
}
} }
} }

View File

@ -93,7 +93,7 @@ namespace Gmtk24 {
if (!IsEnabled) if (!IsEnabled)
return; return;
if (@event.IsAction("toggle_pause_menu")) { if (@event.IsAction("toggle_pause_menu") && HeldBlock == null) {
SetEnabled(false); SetEnabled(false);
GetViewport().SetInputAsHandled(); GetViewport().SetInputAsHandled();
} }