Skip to content

Commit 7ccd458

Browse files
committed
1. Unit animations can be toggled with Caps Lock
2. Unit animations can be temporarily be switched on and off by holding down Shift 3. Refactored actions that are mapped to G (single and combo) 4. Fix disband unit throwing an exception when no unit is selected
1 parent 1ea1c04 commit 7ccd458

File tree

6 files changed

+84
-14
lines changed

6 files changed

+84
-14
lines changed

C7/Animations/AnimationController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using C7Engine;
32
using C7GameData;
43
using Godot;
@@ -50,6 +49,9 @@ public void HandleEngineMessage(AnimationMessage msg) {
5049
mSEA.markCompleted();
5150
}
5251
break;
52+
case MsgStartStopAllAnimations mSSAA:
53+
animTracker.endAllImmediately = !mSSAA.animationsEnabled;
54+
break;
5355
}
5456
}
5557

@@ -63,8 +65,11 @@ public void updateAnimations() {
6365
animTracker.update();
6466
}
6567

68+
public void ToggleAnimationsEnabled() {
69+
new MsgToggleAnimationsEnabled().send();
70+
}
71+
6672
public void SetAnimationsEnabled(bool enabled) {
6773
new MsgSetAnimationsEnabled(enabled).send();
68-
animTracker.endAllImmediately = !enabled;
6974
}
7075
}

C7/Game.cs

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

446446
private void HandleLeftMouseButton(InputEventMouseButton eventMouseButton) {
447447
GetViewport().SetInputAsHandled();
448-
if (eventMouseButton.IsPressed()) {
448+
Control uiHover = GetViewport().GuiGetHoveredControl();
449+
// Can't drag the map when the mouse is over a ui element
450+
if (eventMouseButton.IsPressed() && uiHover is not TextureButton) {
449451
OldPosition = eventMouseButton.Position;
450452
IsMovingCamera = true;
451453

@@ -583,9 +585,6 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
583585
if (eventKeyDown.Keycode == Godot.Key.O && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
584586
ToggleObserverMode();
585587
}
586-
if (eventKeyDown.Keycode == Godot.Key.G && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
587-
ToggleGridCoordinates();
588-
}
589588
if (eventKeyDown.Keycode == Godot.Key.T && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
590589
ToggleC7Graphics();
591590
}
@@ -610,6 +609,32 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
610609
mapView.centerCameraOnTile(capital.location);
611610
}
612611
}
612+
// For inputs that have the same keys mapped to multiple actions like G
613+
// we need to manually handle what is triggered by adding extra conditions.
614+
// Otherwise when pressing CTRL + G for example, both the go-to
615+
// and the toggle grid actions are triggered, because godot does not distinguish
616+
// single key presses from combos, it sends both signals.
617+
// Sometimes even worse, when pressing CTRL + G, it only sends the go-to signal.
618+
// We continue to map these to an action and not call them directly,
619+
// because we could add a button in the ui that does the same and this would call the action too.
620+
if (eventKeyDown.Keycode == Godot.Key.G) {
621+
// Toggle Coordinates
622+
if (eventKeyDown.IsCommandOrControlPressed()
623+
&& eventKeyDown.ShiftPressed
624+
&& eventKeyDown.AltPressed) {
625+
ProcessAction(C7Action.ToggleCoordinates);
626+
}
627+
// Toggle Grid
628+
else if (eventKeyDown.IsCommandOrControlPressed()) {
629+
ProcessAction(C7Action.ToggleGrid);
630+
}
631+
// Trigger Unit go-to
632+
else if (!eventKeyDown.IsCommandOrControlPressed()
633+
&& !eventKeyDown.ShiftPressed
634+
&& !eventKeyDown.AltPressed) {
635+
ProcessAction(C7Action.UnitGoto);
636+
}
637+
}
613638
}
614639

615640
private void ToggleObserverMode() {
@@ -667,10 +692,18 @@ private void ProcessActions() {
667692
foreach (StringName action in actions) {
668693
if (Input.IsActionJustPressed(action)) {
669694
ProcessAction(action.ToString());
695+
} else if (Input.IsActionJustReleased(action)) {
696+
ProcessOnReleaseAction(action.ToString());
670697
}
671698
}
672699
}
673700

701+
private void ProcessOnReleaseAction(string currentAction) {
702+
if (currentAction == C7Action.EnableTempAnimations) {
703+
animationController.SetAnimationsEnabled(true);
704+
}
705+
}
706+
674707
private void ProcessAction(string currentAction) {
675708
if (currentAction == C7Action.Escape && popupOverlay.ShowingPopup) {
676709
popupOverlay.OnHidePopup();
@@ -719,6 +752,10 @@ private void ProcessAction(string currentAction) {
719752
this.mapView.gridLayer.visible = !this.mapView.gridLayer.visible;
720753
}
721754

755+
if (currentAction == C7Action.ToggleCoordinates) {
756+
ToggleGridCoordinates();
757+
}
758+
722759
if (currentAction == C7Action.Escape && this.gotoInfo == null) {
723760
log.Debug("Got request for escape/quit");
724761
popupOverlay.ShowPopup(new EscapeQuitPopup(), PopupOverlay.PopupCategory.Info);
@@ -733,9 +770,11 @@ private void ProcessAction(string currentAction) {
733770
}
734771

735772
if (currentAction == C7Action.ToggleAnimations) {
773+
animationController.ToggleAnimationsEnabled();
774+
}
775+
776+
if (currentAction == C7Action.EnableTempAnimations) {
736777
animationController.SetAnimationsEnabled(false);
737-
} else if (Input.IsActionJustReleased(C7Action.ToggleAnimations)) {
738-
animationController.SetAnimationsEnabled(true);
739778
}
740779

741780
// actions with unit buttons, which are only relevant during the player
@@ -758,6 +797,9 @@ private void ProcessAction(string currentAction) {
758797
}
759798

760799
if (currentAction == C7Action.UnitDisband) {
800+
if (CurrentlySelectedUnit == null || CurrentlySelectedUnit == MapUnit.NONE) {
801+
return;
802+
}
761803
popupOverlay.ShowPopup(
762804
new ConfirmationPopup(
763805
$"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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ public MsgSetAnimationsEnabled(bool enabled) {
326326

327327
public override void process() {
328328
EngineStorage.animationsEnabled = enabled;
329+
new MsgStartStopAllAnimations().send();
330+
}
331+
}
332+
333+
public class MsgToggleAnimationsEnabled : MessageToEngine {
334+
335+
public MsgToggleAnimationsEnabled() {
336+
}
337+
338+
public override void process() {
339+
EngineStorage.animationsEnabled = !EngineStorage.animationsEnabled;
340+
new MsgStartStopAllAnimations().send();
329341
}
330342
}
331343

C7Engine/EntryPoints/MessageToUI.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public MsgStartEffectAnimation(Tile tile, AnimatedEffect effect, AnimationEnding
5151
}
5252
}
5353

54+
public class MsgStartStopAllAnimations : AnimationMessage {
55+
public bool animationsEnabled;
56+
public MsgStartStopAllAnimations() {
57+
animationsEnabled = EngineStorage.animationsEnabled;
58+
}
59+
}
60+
5461
public class MsgStartTurn : MessageToUI { }
5562

5663
public class MsgShowScienceAdvisor : MessageToUI { }

0 commit comments

Comments
 (0)