Bindings per command/stance

This commit is contained in:
Anuken
2023-09-23 12:02:06 -04:00
parent 2286b54011
commit d63133c720
5 changed files with 67 additions and 62 deletions
+18 -9
View File
@@ -4,9 +4,11 @@ import arc.*;
import arc.func.*;
import arc.scene.style.*;
import arc.struct.*;
import arc.util.*;
import mindustry.ai.types.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.input.*;
/** Defines a pattern of behavior that an RTS-controlled unit should follow. Shows up in the command UI. */
public class UnitCommand{
@@ -15,34 +17,34 @@ public class UnitCommand{
public static final UnitCommand
moveCommand = new UnitCommand("move", "right", null){{
moveCommand = new UnitCommand("move", "right", Binding.unit_command_move, null){{
drawTarget = true;
resetTarget = false;
}},
repairCommand = new UnitCommand("repair", "modeSurvival", u -> new RepairAI()),
rebuildCommand = new UnitCommand("rebuild", "hammer", u -> new BuilderAI()),
assistCommand = new UnitCommand("assist", "players", u -> {
repairCommand = new UnitCommand("repair", "modeSurvival", Binding.unit_command_repair, u -> new RepairAI()),
rebuildCommand = new UnitCommand("rebuild", "hammer", Binding.unit_command_rebuild, u -> new BuilderAI()),
assistCommand = new UnitCommand("assist", "players", Binding.unit_command_assist, u -> {
var ai = new BuilderAI();
ai.onlyAssist = true;
return ai;
}),
mineCommand = new UnitCommand("mine", "production", u -> new MinerAI()),
boostCommand = new UnitCommand("boost", "up", u -> new BoostAI()){{
mineCommand = new UnitCommand("mine", "production", Binding.unit_command_mine, u -> new MinerAI()),
boostCommand = new UnitCommand("boost", "up", Binding.unit_command_boost, u -> new BoostAI()){{
switchToMove = false;
drawTarget = true;
resetTarget = false;
}},
loadUnitsCommand = new UnitCommand("loadUnits", "download", null){{
loadUnitsCommand = new UnitCommand("loadUnits", "download", Binding.unit_command_load_units, null){{
switchToMove = false;
drawTarget = true;
resetTarget = false;
}},
loadBlocksCommand = new UnitCommand("loadBlocks", "down", null){{
loadBlocksCommand = new UnitCommand("loadBlocks", "down", Binding.unit_command_load_blocks, null){{
switchToMove = false;
drawTarget = true;
resetTarget = false;
}},
unloadPayloadCommand = new UnitCommand("unloadPayload", "upload", null){{
unloadPayloadCommand = new UnitCommand("unloadPayload", "upload", Binding.unit_command_unload_payload, null){{
switchToMove = false;
drawTarget = true;
resetTarget = false;
@@ -62,6 +64,8 @@ public class UnitCommand{
public boolean drawTarget = false;
/** Whether to reset targets when switching to or from this command. */
public boolean resetTarget = true;
/** Key to press for this command. */
public @Nullable Binding keybind = null;
public UnitCommand(String name, String icon, Func<Unit, AIController> controller){
this.name = name;
@@ -72,6 +76,11 @@ public class UnitCommand{
all.add(this);
}
public UnitCommand(String name, String icon, Binding keybind, Func<Unit, AIController> controller){
this(name, icon, controller);
this.keybind = keybind;
}
public String localized(){
return Core.bundle.get("command." + name);
}
+12 -7
View File
@@ -3,7 +3,9 @@ package mindustry.ai;
import arc.*;
import arc.scene.style.*;
import arc.struct.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.input.*;
public class UnitStance{
/** List of all stances by ID. */
@@ -11,12 +13,12 @@ public class UnitStance{
public static final UnitStance
stop = new UnitStance("stop", "cancel"), //not a real stance, cannot be selected, just cancels ordewrs
shoot = new UnitStance("shoot", "commandAttack"),
holdFire = new UnitStance("holdfire", "none"),
pursueTarget = new UnitStance("pursuetarget", "right"),
patrol = new UnitStance("patrol", "refresh"),
ram = new UnitStance("ram", "rightOpen");
stop = new UnitStance("stop", "cancel", Binding.cancel_orders), //not a real stance, cannot be selected, just cancels ordewrs
shoot = new UnitStance("shoot", "commandAttack", Binding.unit_stance_shoot),
holdFire = new UnitStance("holdfire", "none", Binding.unit_stance_hold_fire),
pursueTarget = new UnitStance("pursuetarget", "right", Binding.unit_stance_pursue_target),
patrol = new UnitStance("patrol", "refresh", Binding.unit_stance_patrol),
ram = new UnitStance("ram", "rightOpen", Binding.unit_stance_ram);
/** Unique ID number. */
public final int id;
@@ -24,10 +26,13 @@ public class UnitStance{
public final String name;
/** Name of UI icon (from Icon class). */
public final String icon;
/** Key to press for this stance. */
public @Nullable Binding keybind = null;
public UnitStance(String name, String icon){
public UnitStance(String name, String icon, Binding keybind){
this.name = name;
this.icon = icon;
this.keybind = keybind;
id = all.size;
all.add(this);