Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion C7/Animations/AnimationController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using C7Engine;
using C7GameData;
using Godot;
Expand Down Expand Up @@ -63,6 +62,11 @@ public void updateAnimations() {
animTracker.update();
}

public void ToggleAnimationsEnabled() {
new MsgToggleAnimationsEnabled().send();
animTracker.endAllImmediately = !animTracker.endAllImmediately;
}

public void SetAnimationsEnabled(bool enabled) {
new MsgSetAnimationsEnabled(enabled).send();
animTracker.endAllImmediately = !enabled;
Expand Down
54 changes: 48 additions & 6 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ private void AdjustZoom(float delta) {

private void HandleLeftMouseButton(InputEventMouseButton eventMouseButton) {
GetViewport().SetInputAsHandled();
if (eventMouseButton.IsPressed()) {
Control uiHover = GetViewport().GuiGetHoveredControl();
// Can't drag the map when the mouse is over a ui element
if (eventMouseButton.IsPressed() && uiHover is not TextureButton) {
OldPosition = eventMouseButton.Position;
IsMovingCamera = true;

Expand Down Expand Up @@ -583,9 +585,6 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
if (eventKeyDown.Keycode == Godot.Key.O && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
ToggleObserverMode();
}
if (eventKeyDown.Keycode == Godot.Key.G && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
ToggleGridCoordinates();
}
if (eventKeyDown.Keycode == Godot.Key.T && eventKeyDown.ShiftPressed && eventKeyDown.IsCommandOrControlPressed() && eventKeyDown.AltPressed) {
ToggleC7Graphics();
}
Expand All @@ -610,6 +609,32 @@ private void HandleKeyboardInput(InputEventKey eventKeyDown) {
mapView.centerCameraOnTile(capital.location);
}
}
// For inputs that have the same keys mapped to multiple actions like G
// we need to manually handle what is triggered by adding extra conditions.
// Otherwise when pressing CTRL + G for example, both the go-to
// and the toggle grid actions are triggered, because godot does not distinguish
// single key presses from combos, it sends both signals.
// Sometimes even worse, when pressing CTRL + G, it only sends the go-to signal.
// We continue to map these to an action and not call them directly,
// because we could add a button in the ui that does the same and this would call the action too.
if (eventKeyDown.Keycode == Godot.Key.G) {
// Toggle Coordinates
if (eventKeyDown.IsCommandOrControlPressed()
&& eventKeyDown.ShiftPressed
&& eventKeyDown.AltPressed) {
ProcessAction(C7Action.ToggleCoordinates);
}
// Toggle Grid
else if (eventKeyDown.IsCommandOrControlPressed()) {
ProcessAction(C7Action.ToggleGrid);
}
// Trigger Unit go-to
else if (!eventKeyDown.IsCommandOrControlPressed()
&& !eventKeyDown.ShiftPressed
&& !eventKeyDown.AltPressed) {
ProcessAction(C7Action.UnitGoto);
}
}
}

private void ToggleObserverMode() {
Expand Down Expand Up @@ -667,10 +692,18 @@ private void ProcessActions() {
foreach (StringName action in actions) {
if (Input.IsActionJustPressed(action)) {
ProcessAction(action.ToString());
} else if (Input.IsActionJustReleased(action)) {
ProcessOnReleaseAction(action.ToString());
}
}
}

private void ProcessOnReleaseAction(string currentAction) {
if (currentAction == C7Action.EnableTempAnimations) {
animationController.SetAnimationsEnabled(true);
}
}

private void ProcessAction(string currentAction) {
if (currentAction == C7Action.Escape && popupOverlay.ShowingPopup) {
popupOverlay.OnHidePopup();
Expand Down Expand Up @@ -719,6 +752,10 @@ private void ProcessAction(string currentAction) {
this.mapView.gridLayer.visible = !this.mapView.gridLayer.visible;
}

if (currentAction == C7Action.ToggleCoordinates) {
ToggleGridCoordinates();
}

if (currentAction == C7Action.Escape && this.gotoInfo == null) {
log.Debug("Got request for escape/quit");
popupOverlay.ShowPopup(new EscapeQuitPopup(), PopupOverlay.PopupCategory.Info);
Expand All @@ -733,9 +770,11 @@ private void ProcessAction(string currentAction) {
}

if (currentAction == C7Action.ToggleAnimations) {
animationController.ToggleAnimationsEnabled();
}

if (currentAction == C7Action.EnableTempAnimations) {
animationController.SetAnimationsEnabled(false);
} else if (Input.IsActionJustReleased(C7Action.ToggleAnimations)) {
animationController.SetAnimationsEnabled(true);
}

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

if (currentAction == C7Action.UnitDisband) {
if (CurrentlySelectedUnit == null || CurrentlySelectedUnit == MapUnit.NONE) {
return;
}
popupOverlay.ShowPopup(
new ConfirmationPopup(
$"Disband {CurrentlySelectedUnit.unitType.name}? Pardon me but these are OUR people. Do \nyou really want to disband them?",
Expand Down
14 changes: 8 additions & 6 deletions C7/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ down={
}
unit_goto={
"deadzone": 0.5,
"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)
]
"events": []
}
end_turn={
"deadzone": 0.5,
Expand Down Expand Up @@ -120,9 +119,7 @@ move_unit_southwest={
}
toggle_grid={
"deadzone": 0.5,
"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)
, 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)
]
"events": []
}
escape={
"deadzone": 0.5,
Expand All @@ -136,7 +133,7 @@ toggle_zoom={
}
toggle_animations={
"deadzone": 0.5,
"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)
"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)
]
}
unit_hold={
Expand Down Expand Up @@ -199,6 +196,11 @@ unit_irrigate={
"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)
]
}
enable_temp_animations={
"deadzone": 0.5,
"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)
]
}

[mono]

Expand Down
2 changes: 2 additions & 0 deletions C7Engine/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public static class C7Action {
public const string MoveUnitNorth = "move_unit_north";
public const string MoveUnitNortheast = "move_unit_northeast";
public const string ToggleAnimations = "toggle_animations";
public const string EnableTempAnimations = "enable_temp_animations";
public const string ToggleGrid = "toggle_grid";
public const string ToggleCoordinates = "toggle_coordinates";
public const string ToggleZoom = "toggle_zoom";
public const string UnitBombard = "unit_bombard";
public const string UnitBuildCity = "unit_build_city";
Expand Down
10 changes: 10 additions & 0 deletions C7Engine/EntryPoints/MessageToEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ public override void process() {
}
}

public class MsgToggleAnimationsEnabled : MessageToEngine {

public MsgToggleAnimationsEnabled() {
}

public override void process() {
EngineStorage.animationsEnabled = !EngineStorage.animationsEnabled;
}
}

public class MsgBuildCity : MessageToEngine {
private MapUnit unit;
private string name;
Expand Down