From 8598eedd6f6424a37c3660b02424fdf8eac215ba Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 21 Sep 2023 10:40:44 -0400 Subject: [PATCH] Keybind tweaks --- core/assets/bundles/bundle.properties | 2 ++ core/src/mindustry/game/Teams.java | 2 +- core/src/mindustry/input/Binding.java | 24 ++++++++++---- .../ui/fragments/PlacementFragment.java | 32 +++++++++++-------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index ca8a6683ac..8ad40e5b63 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -1149,6 +1149,7 @@ keybind.title = Rebind Keys keybinds.mobile = [scarlet]Most keybinds here are not functional on mobile. Only basic movement is supported. category.general.name = General category.view.name = View +category.command.name = Unit Command category.multiplayer.name = Multiplayer category.blocks.name = Block Select placement.blockselectkeys = \n[lightgray]Key: [{0}, @@ -1168,6 +1169,7 @@ keybind.boost.name = Boost keybind.command_mode.name = Command Mode keybind.command_queue.name = Queue Unit Command keybind.create_control_group.name = Create Control Group +keybind.cancel_orders.name = Cancel Orders keybind.rebuild_select.name = Rebuild Region keybind.schematic_select.name = Select Region keybind.schematic_menu.name = Schematic Menu diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index 8e37437883..9abcf0b4e5 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -333,7 +333,7 @@ public class Teams{ } for(var build : builds){ - if(build.within(x, y, range)){ + if(build.within(x, y, range) && !build.block.privileged){ scheduleDerelict(build); } } diff --git a/core/src/mindustry/input/Binding.java b/core/src/mindustry/input/Binding.java index e26c517e2f..9cc1a323f7 100644 --- a/core/src/mindustry/input/Binding.java +++ b/core/src/mindustry/input/Binding.java @@ -12,18 +12,12 @@ public enum Binding implements KeyBind{ pan(KeyCode.mouseForward), boost(KeyCode.shiftLeft), - command_mode(KeyCode.shiftLeft), - command_queue(KeyCode.mouseMiddle), - create_control_group(KeyCode.controlLeft), - control(KeyCode.controlLeft), respawn(KeyCode.v), + control(KeyCode.controlLeft), select(KeyCode.mouseLeft), deselect(KeyCode.mouseRight), break_block(KeyCode.mouseRight), - select_all_units(KeyCode.g), - select_all_unit_factories(KeyCode.h), - pickupCargo(KeyCode.leftBracket), dropCargo(KeyCode.rightBracket), @@ -40,6 +34,22 @@ public enum Binding implements KeyBind{ schematic_flip_y(KeyCode.x), schematic_menu(KeyCode.t), + + command_mode(KeyCode.shiftLeft, "command"), + command_queue(KeyCode.mouseMiddle), + create_control_group(KeyCode.controlLeft), + + select_all_units(KeyCode.g), + select_all_unit_factories(KeyCode.h), + + cancel_orders(KeyCode.unset), + + unit_stance_1(KeyCode.unset), + unit_stance_2(KeyCode.unset), + unit_stance_3(KeyCode.unset), + unit_stance_4(KeyCode.unset), + unit_stance_5(KeyCode.unset), + category_prev(KeyCode.comma, "blocks"), category_next(KeyCode.period), diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index 9f03e527f4..7794713629 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -11,7 +11,6 @@ import arc.scene.ui.*; import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; -import mindustry.*; import mindustry.ai.*; import mindustry.content.*; import mindustry.core.*; @@ -69,6 +68,15 @@ public class PlacementFragment{ Binding.block_select_down }; + Binding[] stanceBindings = { + Binding.cancel_orders, + Binding.unit_stance_1, + Binding.unit_stance_2, + Binding.unit_stance_3, + Binding.unit_stance_4, + Binding.unit_stance_5, + }; + public PlacementFragment(){ Events.on(WorldLoadEvent.class, event -> { Core.app.post(() -> { @@ -513,12 +521,7 @@ public class PlacementFragment{ int scol = 0; for(var command : commands){ coms.button(Icon.icons.get(command.icon, Icon.cancel), Styles.clearNoneTogglei, () -> { - IntSeq ids = new IntSeq(); - for(var unit : units){ - ids.add(unit.id); - } - - Call.setUnitCommand(Vars.player, ids.toArray(), command); + Call.setUnitCommand(player, units.mapInt(un -> un.id).toArray(), command); }).checked(i -> currentCommand[0] == command).size(50f).tooltip(command.localized()); if(++scol % 6 == 0) coms.row(); @@ -537,12 +540,7 @@ public class PlacementFragment{ for(var stance : stances){ coms.button(Icon.icons.get(stance.icon, Icon.cancel), Styles.clearNoneTogglei, () -> { - IntSeq ids = new IntSeq(); - for(var unit : units){ - ids.add(unit.id); - } - - Call.setUnitStance(Vars.player, ids.toArray(), stance); + Call.setUnitStance(player, units.mapInt(un -> un.id).toArray(), stance); }).checked(i -> currentStance[0] == stance).size(50f).tooltip(stance.localized()); if(++scol % 6 == 0) coms.row(); @@ -595,6 +593,14 @@ public class PlacementFragment{ curCount[0] = size; rebuildCommand.run(); } + + //not a huge fan of running input logic here, but it's convenient as the stance arrays are all here... + for(int i = 0; i < Math.min(stanceBindings.length, stances.size); i++){ + //first stance must always be the stop stance + if(Core.input.keyTap(stanceBindings[i]) && (i != 0 || stances.get(0) == UnitStance.stopStance)){ + Call.setUnitStance(player, control.input.selectedUnits.mapInt(un -> un.id).toArray(), stances.get(i)); + } + } } }); rebuildCommand.run();