Skip to content

Commit 260ef34

Browse files
authored
Merge pull request #842 from stavrosfa/fix/hotkey-and-ui-fixes
Hotkey and UI fixes
2 parents 6851c9d + 214a85f commit 260ef34

File tree

5 files changed

+73
-13
lines changed

5 files changed

+73
-13
lines changed

C7/Animations/AnimationController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using C7Engine;
32
using C7GameData;
43
using Godot;
@@ -63,6 +62,11 @@ public void updateAnimations() {
6362
animTracker.update();
6463
}
6564

65+
public void ToggleAnimationsEnabled() {
66+
new MsgToggleAnimationsEnabled().send();
67+
animTracker.endAllImmediately = !animTracker.endAllImmediately;
68+
}
69+
6670
public void SetAnimationsEnabled(bool enabled) {
6771
new MsgSetAnimationsEnabled(enabled).send();
6872
animTracker.endAllImmediately = !enabled;

C7/Game.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ private void AdjustZoom(float delta) {
457457

458458
private void HandleLeftMouseButton(InputEventMouseButton eventMouseButton) {
459459
GetViewport().SetInputAsHandled();
460-
if (eventMouseButton.IsPressed()) {
460+
Control uiHover = GetViewport().GuiGetHoveredControl();
461+
// Can't drag the map when the mouse is over a ui element
462+
if (eventMouseButton.IsPressed() && uiHover is not TextureButton) {
461463
OldPosition = eventMouseButton.Position;
462464
IsMovingCamera = true;
463465

@@ -595,9 +597,6 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
595597
if (eventKeyDown.Keycode == Godot.Key.O && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
596598
ToggleObserverMode();
597599
}
598-
if (eventKeyDown.Keycode == Godot.Key.G && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
599-
ToggleGridCoordinates();
600-
}
601600
if (eventKeyDown.Keycode == Godot.Key.T && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
602601
ToggleC7Graphics();
603602
}
@@ -622,6 +621,32 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
622621
mapView.centerCameraOnTile(capital.location);
623622
}
624623
}
624+
// For inputs that have the same keys mapped to multiple actions like G
625+
// we need to manually handle what is triggered by adding extra conditions.
626+
// Otherwise when pressing CTRL + G for example, both the go-to
627+
// and the toggle grid actions are triggered, because godot does not distinguish
628+
// single key presses from combos, it sends both signals.
629+
// Sometimes even worse, when pressing CTRL + G, it only sends the go-to signal.
630+
// We continue to map these to an action and not call them directly,
631+
// because we could add a button in the ui that does the same and this would call the action too.
632+
if (eventKeyDown.Keycode == Godot.Key.G) {
633+
// Toggle Coordinates
634+
if (eventKeyDown.IsCommandOrControlPressed()
635+
&& eventKeyDown.ShiftPressed
636+
&& eventKeyDown.AltPressed) {
637+
ProcessAction(C7Action.ToggleCoordinates);
638+
}
639+
// Toggle Grid
640+
else if (eventKeyDown.IsCommandOrControlPressed()) {
641+
ProcessAction(C7Action.ToggleGrid);
642+
}
643+
// Trigger Unit go-to
644+
else if (!eventKeyDown.IsCommandOrControlPressed()
645+
&& !eventKeyDown.ShiftPressed
646+
&& !eventKeyDown.AltPressed) {
647+
ProcessAction(C7Action.UnitGoto);
648+
}
649+
}
625650
}
626651

627652
private void ToggleObserverMode() {
@@ -679,10 +704,18 @@ private void ProcessActions() {
679704
foreach (StringName action in actions) {
680705
if (Input.IsActionJustPressed(action)) {
681706
ProcessAction(action.ToString());
707+
} else if (Input.IsActionJustReleased(action)) {
708+
ProcessOnReleaseAction(action.ToString());
682709
}
683710
}
684711
}
685712

713+
private void ProcessOnReleaseAction(string currentAction) {
714+
if (currentAction == C7Action.EnableTempAnimations) {
715+
animationController.SetAnimationsEnabled(true);
716+
}
717+
}
718+
686719
private void ProcessAction(string currentAction) {
687720
if (currentAction == C7Action.Escape && popupOverlay.ShowingPopup) {
688721
popupOverlay.OnHidePopup();
@@ -731,6 +764,10 @@ private void ProcessAction(string currentAction) {
731764
this.mapView.gridLayer.visible = !this.mapView.gridLayer.visible;
732765
}
733766

767+
if (currentAction == C7Action.ToggleCoordinates) {
768+
ToggleGridCoordinates();
769+
}
770+
734771
if (currentAction == C7Action.Escape && this.gotoInfo == null) {
735772
log.Debug("Got request for escape/quit");
736773
popupOverlay.ShowPopup(new EscapeQuitPopup(), PopupOverlay.PopupCategory.Info);
@@ -745,9 +782,11 @@ private void ProcessAction(string currentAction) {
745782
}
746783

747784
if (currentAction == C7Action.ToggleAnimations) {
785+
animationController.ToggleAnimationsEnabled();
786+
}
787+
788+
if (currentAction == C7Action.EnableTempAnimations) {
748789
animationController.SetAnimationsEnabled(false);
749-
} else if (Input.IsActionJustReleased(C7Action.ToggleAnimations)) {
750-
animationController.SetAnimationsEnabled(true);
751790
}
752791

753792
// actions with unit buttons, which are only relevant during the player
@@ -770,6 +809,9 @@ private void ProcessAction(string currentAction) {
770809
}
771810

772811
if (currentAction == C7Action.UnitDisband) {
812+
if (CurrentlySelectedUnit == null || CurrentlySelectedUnit == MapUnit.NONE) {
813+
return;
814+
}
773815
popupOverlay.ShowPopup(
774816
new ConfirmationPopup(
775817
$"Disband {CurrentlySelectedUnit.unitType.name}? Pardon me but these are OUR people. Do \nyou really want to disband them?",

C7/project.godot

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ down={
6161
}
6262
unit_goto={
6363
"deadzone": 0.5,
64-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null)
65-
]
64+
"events": []
6665
}
6766
end_turn={
6867
"deadzone": 0.5,
@@ -120,9 +119,7 @@ move_unit_southwest={
120119
}
121120
toggle_grid={
122121
"deadzone": 0.5,
123-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":true,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
124-
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
125-
]
122+
"events": []
126123
}
127124
escape={
128125
"deadzone": 0.5,
@@ -136,7 +133,7 @@ toggle_zoom={
136133
}
137134
toggle_animations={
138135
"deadzone": 0.5,
139-
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
136+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194329,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
140137
]
141138
}
142139
unit_hold={
@@ -199,6 +196,11 @@ unit_irrigate={
199196
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null)
200197
]
201198
}
199+
enable_temp_animations={
200+
"deadzone": 0.5,
201+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
202+
]
203+
}
202204

203205
[mono]
204206

C7Engine/Actions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public static class C7Action {
1717
public const string MoveUnitNorth = "move_unit_north";
1818
public const string MoveUnitNortheast = "move_unit_northeast";
1919
public const string ToggleAnimations = "toggle_animations";
20+
public const string EnableTempAnimations = "enable_temp_animations";
2021
public const string ToggleGrid = "toggle_grid";
22+
public const string ToggleCoordinates = "toggle_coordinates";
2123
public const string ToggleZoom = "toggle_zoom";
2224
public const string UnitBombard = "unit_bombard";
2325
public const string UnitBuildCity = "unit_build_city";

C7Engine/EntryPoints/MessageToEngine.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ public override void process() {
329329
}
330330
}
331331

332+
public class MsgToggleAnimationsEnabled : MessageToEngine {
333+
334+
public MsgToggleAnimationsEnabled() {
335+
}
336+
337+
public override void process() {
338+
EngineStorage.animationsEnabled = !EngineStorage.animationsEnabled;
339+
}
340+
}
341+
332342
public class MsgBuildCity : MessageToEngine {
333343
private MapUnit unit;
334344
private string name;

0 commit comments

Comments
 (0)