mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-06 08:57:45 +07:00
Bindings per command/stance
This commit is contained in:
parent
2286b54011
commit
d63133c720
@ -1173,11 +1173,23 @@ 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.unit_stance_1.name = Unit Stance 1
|
||||
keybind.unit_stance_2.name = Unit Stance 2
|
||||
keybind.unit_stance_3.name = Unit Stance 3
|
||||
keybind.unit_stance_4.name = Unit Stance 4
|
||||
keybind.unit_stance_5.name = Unit Stance 5
|
||||
|
||||
keybind.unit_stance_shoot.name = Unit Stance: Shoot
|
||||
keybind.unit_stance_hold_fire.name = Unit Stance: Hold Fire
|
||||
keybind.unit_stance_pursue_target.name = Unit Stance: Pursue Target
|
||||
keybind.unit_stance_patrol.name = Unit Stance: Patrol
|
||||
keybind.unit_stance_ram.name = Unit Stance: Ram
|
||||
|
||||
keybind.unit_command_move = Unit Command: Move
|
||||
keybind.unit_command_repair = Unit Command: Repair
|
||||
keybind.unit_command_rebuild = Unit Command: Rebuild
|
||||
keybind.unit_command_assist = Unit Command: Assist
|
||||
keybind.unit_command_mine = Unit Command: Mine
|
||||
keybind.unit_command_boost = Unit Command: Boost
|
||||
keybind.unit_command_load_units = Unit Command: Load Units
|
||||
keybind.unit_command_load_blocks = Unit Command: Load Blocks
|
||||
keybind.unit_command_unload_payload = Unit Command: Unload Payload
|
||||
|
||||
keybind.rebuild_select.name = Rebuild Region
|
||||
keybind.schematic_select.name = Select Region
|
||||
keybind.schematic_menu.name = Schematic Menu
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -44,21 +44,21 @@ public enum Binding implements KeyBind{
|
||||
|
||||
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),
|
||||
unit_stance_shoot(KeyCode.unset),
|
||||
unit_stance_hold_fire(KeyCode.unset),
|
||||
unit_stance_pursue_target(KeyCode.unset),
|
||||
unit_stance_patrol(KeyCode.unset),
|
||||
unit_stance_ram(KeyCode.unset),
|
||||
|
||||
unit_command_1(KeyCode.unset),
|
||||
unit_command_2(KeyCode.unset),
|
||||
unit_command_3(KeyCode.unset),
|
||||
unit_command_4(KeyCode.unset),
|
||||
unit_command_5(KeyCode.unset),
|
||||
unit_command_6(KeyCode.unset),
|
||||
unit_command_7(KeyCode.unset),
|
||||
unit_command_8(KeyCode.unset),
|
||||
unit_command_9(KeyCode.unset),
|
||||
unit_command_move(KeyCode.unset),
|
||||
unit_command_repair(KeyCode.unset),
|
||||
unit_command_rebuild(KeyCode.unset),
|
||||
unit_command_assist(KeyCode.unset),
|
||||
unit_command_mine(KeyCode.unset),
|
||||
unit_command_boost(KeyCode.unset),
|
||||
unit_command_load_units(KeyCode.unset),
|
||||
unit_command_load_blocks(KeyCode.unset),
|
||||
unit_command_unload_payload(KeyCode.unset),
|
||||
|
||||
category_prev(KeyCode.comma, "blocks"),
|
||||
category_next(KeyCode.period),
|
||||
|
@ -68,27 +68,6 @@ 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,
|
||||
};
|
||||
|
||||
Binding[] commandBindings = {
|
||||
Binding.unit_command_1,
|
||||
Binding.unit_command_2,
|
||||
Binding.unit_command_3,
|
||||
Binding.unit_command_4,
|
||||
Binding.unit_command_5,
|
||||
Binding.unit_command_6,
|
||||
Binding.unit_command_7,
|
||||
Binding.unit_command_8,
|
||||
Binding.unit_command_9,
|
||||
};
|
||||
|
||||
public PlacementFragment(){
|
||||
Events.on(WorldLoadEvent.class, event -> {
|
||||
Core.app.post(() -> {
|
||||
@ -607,17 +586,17 @@ public class PlacementFragment{
|
||||
}
|
||||
|
||||
//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++){
|
||||
for(UnitStance stance : stances){
|
||||
//first stance must always be the stop stance
|
||||
if(Core.input.keyTap(stanceBindings[i]) && (i != 0 || stances.get(0) == UnitStance.stop)){
|
||||
Call.setUnitStance(player, control.input.selectedUnits.mapInt(un -> un.id).toArray(), stances.get(i));
|
||||
if(stance.keybind != null && Core.input.keyTap(stance.keybind)){
|
||||
Call.setUnitStance(player, control.input.selectedUnits.mapInt(un -> un.id).toArray(), stance);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < Math.min(commandBindings.length, commands.size); i++){
|
||||
for(UnitCommand command : commands){
|
||||
//first stance must always be the stop stance
|
||||
if(Core.input.keyTap(commandBindings[i])){
|
||||
Call.setUnitCommand(player, control.input.selectedUnits.mapInt(un -> un.id).toArray(), commands.get(i));
|
||||
if(command.keybind != null && Core.input.keyTap(command.keybind)){
|
||||
Call.setUnitCommand(player, control.input.selectedUnits.mapInt(un -> un.id).toArray(), command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user