Keybind search bar + modding support

This commit is contained in:
Anuken
2025-04-28 22:13:32 -04:00
parent ca550545bc
commit e414b02030
22 changed files with 326 additions and 421 deletions

View File

@@ -77,14 +77,14 @@ public class DesktopInput extends InputHandler{
if(!showHint()) return str;
str.setLength(0);
if(!isBuilding && !Core.settings.getBool("buildautopause") && !player.unit().isBuilding()){
str.append(Core.bundle.format("enablebuilding", Core.keybinds.get(Binding.pause_building).key.toString()));
str.append(Core.bundle.format("enablebuilding", Binding.pauseBuilding.value.key.toString()));
}else if(player.unit().isBuilding()){
str.append(Core.bundle.format(isBuilding ? "pausebuilding" : "resumebuilding", Core.keybinds.get(Binding.pause_building).key.toString()))
.append("\n").append(Core.bundle.format("cancelbuilding", Core.keybinds.get(Binding.clear_building).key.toString()))
.append("\n").append(Core.bundle.format("selectschematic", Core.keybinds.get(Binding.schematic_select).key.toString()));
str.append(Core.bundle.format(isBuilding ? "pausebuilding" : "resumebuilding", Binding.pauseBuilding.value.key.toString()))
.append("\n").append(Core.bundle.format("cancelbuilding", Binding.clearBuilding.value.key.toString()))
.append("\n").append(Core.bundle.format("selectschematic", Binding.schematicSelect.value.key.toString()));
}
if(!player.dead() && !player.unit().spawnedByCore()){
str.append(str.length() != 0 ? "\n" : "").append(Core.bundle.format("respawn", Core.keybinds.get(Binding.respawn).key.toString()));
str.append(str.length() != 0 ? "\n" : "").append(Core.bundle.format("respawn", Binding.respawn.value.key.toString()));
}
return str;
}).style(Styles.outlineLabel);
@@ -98,8 +98,8 @@ public class DesktopInput extends InputHandler{
t.table(Styles.black6, b -> {
b.defaults().left();
b.label(() -> Core.bundle.format("schematic.flip",
Core.keybinds.get(Binding.schematic_flip_x).key.toString(),
Core.keybinds.get(Binding.schematic_flip_y).key.toString())).style(Styles.outlineLabel).visible(() -> Core.settings.getBool("hints"));
Binding.schematicFlipX.value.key.toString(),
Binding.schematicFlipY.value.key.toString())).style(Styles.outlineLabel).visible(() -> Core.settings.getBool("hints"));
b.row();
b.table(a -> {
a.button("@schematic.add", Icon.save, this::showSchematicSave).colspan(2).size(250f, 50f).disabled(f -> lastSchematic == null || lastSchematic.file != null);
@@ -120,14 +120,14 @@ public class DesktopInput extends InputHandler{
//draw break selection
if(mode == breaking){
drawBreakSelection(selectX, selectY, cursorX, cursorY, !(Core.input.keyDown(Binding.schematic_select) && schemX != -1 && schemY != -1) ? maxLength : Vars.maxSchematicSize, false);
drawBreakSelection(selectX, selectY, cursorX, cursorY, !(Core.input.keyDown(Binding.schematicSelect) && schemX != -1 && schemY != -1) ? maxLength : Vars.maxSchematicSize, false);
}
if(!Core.scene.hasKeyboard() && mode != breaking){
if(Core.input.keyDown(Binding.schematic_select) && schemX != -1 && schemY != -1){
if(Core.input.keyDown(Binding.schematicSelect) && schemX != -1 && schemY != -1){
drawSelection(schemX, schemY, cursorX, cursorY, Vars.maxSchematicSize);
}else if(Core.input.keyDown(Binding.rebuild_select)){
}else if(Core.input.keyDown(Binding.rebuildSelect)){
drawRebuildSelection(schemX, schemY, cursorX, cursorY);
}
}
@@ -218,7 +218,7 @@ public class DesktopInput extends InputHandler{
public void update(){
super.update();
if(net.active() && Core.input.keyTap(Binding.player_list) && (scene.getKeyboardFocus() == null || scene.getKeyboardFocus().isDescendantOf(ui.listfrag.content) || scene.getKeyboardFocus().isDescendantOf(ui.minimapfrag.elem))){
if(net.active() && Core.input.keyTap(Binding.playerList) && (scene.getKeyboardFocus() == null || scene.getKeyboardFocus().isDescendantOf(ui.listfrag.content) || scene.getKeyboardFocus().isDescendantOf(ui.minimapfrag.elem))){
ui.listfrag.toggle();
}
@@ -228,7 +228,7 @@ public class DesktopInput extends InputHandler{
boolean detached = settings.getBool("detach-camera", false);
if(!scene.hasField() && !scene.hasDialog()){
if(input.keyTap(Binding.detach_camera)){
if(input.keyTap(Binding.detachCamera)){
settings.put("detach-camera", detached = !detached);
if(!detached){
panning = false;
@@ -242,7 +242,7 @@ public class DesktopInput extends InputHandler{
spectating = null;
}
if((Math.abs(Core.input.axis(Binding.move_x)) > 0 || Math.abs(Core.input.axis(Binding.move_y)) > 0 || input.keyDown(Binding.mouse_move))){
if((Math.abs(Core.input.axis(Binding.moveX)) > 0 || Math.abs(Core.input.axis(Binding.moveY)) > 0 || input.keyDown(Binding.mouseMove))){
panning = false;
spectating = null;
}
@@ -253,11 +253,11 @@ public class DesktopInput extends InputHandler{
if(!locked){
if(((player.dead() || state.isPaused() || detached) && !ui.chatfrag.shown()) && !scene.hasField() && !scene.hasDialog()){
if(input.keyDown(Binding.mouse_move)){
if(input.keyDown(Binding.mouseMove)){
panCam = true;
}
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.move_x), Core.input.axis(Binding.move_y)).nor().scl(camSpeed));
Core.camera.position.add(Tmp.v1.setZero().add(Core.input.axis(Binding.moveX), Core.input.axis(Binding.moveY)).nor().scl(camSpeed));
}else if((!player.dead() || spectating != null) && !panning){
//TODO do not pan
Team corePanTeam = state.won ? state.rules.waveTeam : player.team();
@@ -277,10 +277,10 @@ public class DesktopInput extends InputHandler{
if(!locked && block == null && !scene.hasField() && !scene.hasDialog() &&
//disable command mode when player unit can boost and command mode binding is the same
!(!player.dead() && player.unit().type.canBoost && keybinds.get(Binding.command_mode).key == keybinds.get(Binding.boost).key)){
!(!player.dead() && player.unit().type.canBoost && Binding.commandMode.value.key == Binding.boost.value.key)){
if(settings.getBool("commandmodehold")){
commandMode = input.keyDown(Binding.command_mode);
}else if(input.keyTap(Binding.command_mode)){
commandMode = input.keyDown(Binding.commandMode);
}else if(input.keyTap(Binding.commandMode)){
commandMode = !commandMode;
}
}else{
@@ -291,7 +291,7 @@ public class DesktopInput extends InputHandler{
selectedUnits.removeAll(u -> !u.allowCommand() || !u.isValid() || u.team != player.team());
if(commandMode && !scene.hasField() && !scene.hasDialog()){
if(input.keyTap(Binding.select_all_units)){
if(input.keyTap(Binding.selectAllUnits)){
selectedUnits.clear();
commandBuildings.clear();
for(var unit : player.team().data().units){
@@ -301,7 +301,7 @@ public class DesktopInput extends InputHandler{
}
}
if(input.keyTap(Binding.select_all_unit_factories)){
if(input.keyTap(Binding.selectAllUnitFactories)){
selectedUnits.clear();
commandBuildings.clear();
for(var build : player.team().data().buildings){
@@ -318,7 +318,7 @@ public class DesktopInput extends InputHandler{
if(controlGroups[i] == null) controlGroups[i] = new IntSeq();
IntSeq group = controlGroups[i];
boolean creating = input.keyDown(Binding.create_control_group);
boolean creating = input.keyDown(Binding.createControlGroup);
//clear existing if making a new control group
//if any of the control group edit buttons are pressed take the current selection
@@ -405,16 +405,16 @@ public class DesktopInput extends InputHandler{
if(state.isGame() && !scene.hasDialog() && !scene.hasField()){
if(Core.input.keyTap(Binding.minimap)) ui.minimapfrag.toggle();
if(Core.input.keyTap(Binding.planet_map) && state.isCampaign()) ui.planet.toggle();
if(Core.input.keyTap(Binding.planetMap) && state.isCampaign()) ui.planet.toggle();
if(Core.input.keyTap(Binding.research) && state.isCampaign()) ui.research.toggle();
}
if(state.isMenu() || Core.scene.hasDialog()) return;
//zoom camera
if((!Core.scene.hasScroll() || Core.input.keyDown(Binding.diagonal_placement)) && !ui.chatfrag.shown() && !ui.consolefrag.shown() && Math.abs(Core.input.axisTap(Binding.zoom)) > 0
&& !Core.input.keyDown(Binding.rotateplaced) && (Core.input.keyDown(Binding.diagonal_placement) ||
!keybinds.get(Binding.zoom).equals(keybinds.get(Binding.rotate)) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectPlans.isEmpty()))){
if((!Core.scene.hasScroll() || Core.input.keyDown(Binding.diagonalPlacement)) && !ui.chatfrag.shown() && !ui.consolefrag.shown() && Math.abs(Core.input.axisTap(Binding.zoom)) > 0
&& !Core.input.keyDown(Binding.rotatePlaced) && (Core.input.keyDown(Binding.diagonalPlacement) ||
!Binding.zoom.value.equals(Binding.rotate.value) || ((!player.isBuilder() || !isPlacing() || !block.rotate) && selectPlans.isEmpty()))){
renderer.scaleCamera(Core.input.axisTap(Binding.zoom));
}
@@ -451,7 +451,7 @@ public class DesktopInput extends InputHandler{
selectScale = 0f;
}
if(!Core.input.keyDown(Binding.diagonal_placement) && Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0){
if(!Core.input.keyDown(Binding.diagonalPlacement) && Math.abs((int)Core.input.axisTap(Binding.rotate)) > 0){
rotation = Mathf.mod(rotation + (int)Core.input.axisTap(Binding.rotate), 4);
if(splan != null){
@@ -500,7 +500,7 @@ public class DesktopInput extends InputHandler{
cursorType = ui.targetCursor;
}
if(input.keyTap(Binding.command_queue) && keybinds.get(Binding.command_queue).key.type != KeyType.mouse){
if(input.keyTap(Binding.commandQueue) && Binding.commandQueue.value.key.type != KeyType.mouse){
commandTap(input.mouseX(), input.mouseY(), true);
}
}
@@ -514,7 +514,7 @@ public class DesktopInput extends InputHandler{
}
if(cursor.build != null && cursor.interactable(player.team()) && !isPlacing() && Math.abs(Core.input.axisTap(Binding.rotate)) > 0 && Core.input.keyDown(Binding.rotateplaced) && cursor.block().rotate && cursor.block().quickRotate){
if(cursor.build != null && cursor.interactable(player.team()) && !isPlacing() && Math.abs(Core.input.axisTap(Binding.rotate)) > 0 && Core.input.keyDown(Binding.rotatePlaced) && cursor.block().rotate && cursor.block().quickRotate){
Call.rotateBlock(player, cursor.build, Core.input.axisTap(Binding.rotate) > 0);
}
}
@@ -593,16 +593,16 @@ public class DesktopInput extends InputHandler{
player.unit().mineTile = null;
}
if(Core.input.keyTap(Binding.clear_building) && !player.dead()){
if(Core.input.keyTap(Binding.clearBuilding) && !player.dead()){
player.unit().clearBuilding();
}
if((Core.input.keyTap(Binding.schematic_select) || Core.input.keyTap(Binding.rebuild_select)) && !Core.scene.hasKeyboard() && mode != breaking){
if((Core.input.keyTap(Binding.schematicSelect) || Core.input.keyTap(Binding.rebuildSelect)) && !Core.scene.hasKeyboard() && mode != breaking){
schemX = rawCursorX;
schemY = rawCursorY;
}
if(Core.input.keyTap(Binding.schematic_menu) && !Core.scene.hasKeyboard()){
if(Core.input.keyTap(Binding.schematicMenu) && !Core.scene.hasKeyboard()){
if(ui.schematics.isShown()){
ui.schematics.hide();
}else{
@@ -610,13 +610,13 @@ public class DesktopInput extends InputHandler{
}
}
if(Core.input.keyTap(Binding.clear_building) || isPlacing()){
if(Core.input.keyTap(Binding.clearBuilding) || isPlacing()){
lastSchematic = null;
selectPlans.clear();
}
if(!Core.scene.hasKeyboard() && selectX == -1 && selectY == -1 && schemX != -1 && schemY != -1){
if(Core.input.keyRelease(Binding.schematic_select)){
if(Core.input.keyRelease(Binding.schematicSelect)){
lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
useSchematic(lastSchematic);
if(selectPlans.isEmpty()){
@@ -624,7 +624,7 @@ public class DesktopInput extends InputHandler{
}
schemX = -1;
schemY = -1;
}else if(input.keyRelease(Binding.rebuild_select)){
}else if(input.keyRelease(Binding.rebuildSelect)){
rebuildArea(schemX, schemY, rawCursorX, rawCursorY);
schemX = -1;
@@ -633,11 +633,11 @@ public class DesktopInput extends InputHandler{
}
if(!selectPlans.isEmpty()){
if(Core.input.keyTap(Binding.schematic_flip_x)){
if(Core.input.keyTap(Binding.schematicFlipX)){
flipPlans(selectPlans, true);
}
if(Core.input.keyTap(Binding.schematic_flip_y)){
if(Core.input.keyTap(Binding.schematicFlipY)){
flipPlans(selectPlans, false);
}
}
@@ -656,7 +656,7 @@ public class DesktopInput extends InputHandler{
linePlans.clear();
}
if(Core.input.keyTap(Binding.pause_building)){
if(Core.input.keyTap(Binding.pauseBuilding)){
isBuilding = !isBuilding;
buildWasAutoPaused = false;
@@ -693,7 +693,7 @@ public class DesktopInput extends InputHandler{
tappedOne = false;
BuildPlan plan = getPlan(cursorX, cursorY);
if(Core.input.keyDown(Binding.break_block)){
if(Core.input.keyDown(Binding.breakBlock)){
mode = none;
}else if(!selectPlans.isEmpty()){
flushPlans(selectPlans);
@@ -732,7 +732,7 @@ public class DesktopInput extends InputHandler{
}else if(Core.input.keyTap(Binding.deselect) && !selectPlans.isEmpty()){
selectPlans.clear();
lastSchematic = null;
}else if(Core.input.keyTap(Binding.break_block) && !Core.scene.hasMouse() && player.isBuilder() && !commandMode){
}else if(Core.input.keyTap(Binding.breakBlock) && !Core.scene.hasMouse() && player.isBuilder() && !commandMode){
//is recalculated because setting the mode to breaking removes potential multiblock cursor offset
deleting = false;
mode = breaking;
@@ -752,7 +752,7 @@ public class DesktopInput extends InputHandler{
}
if(mode == placing && block != null){
if(!overrideLineRotation && !Core.input.keyDown(Binding.diagonal_placement) && (selectX != cursorX || selectY != cursorY) && ((int)Core.input.axisTap(Binding.rotate) != 0)){
if(!overrideLineRotation && !Core.input.keyDown(Binding.diagonalPlacement) && (selectX != cursorX || selectY != cursorY) && ((int)Core.input.axisTap(Binding.rotate) != 0)){
rotation = ((int)((Angles.angle(selectX, selectY, cursorX, cursorY) + 45) / 90f)) % 4;
overrideLineRotation = true;
}
@@ -760,13 +760,13 @@ public class DesktopInput extends InputHandler{
overrideLineRotation = false;
}
if(Core.input.keyRelease(Binding.break_block) && Core.input.keyDown(Binding.schematic_select) && mode == breaking){
if(Core.input.keyRelease(Binding.breakBlock) && Core.input.keyDown(Binding.schematicSelect) && mode == breaking){
lastSchematic = schematics.create(schemX, schemY, rawCursorX, rawCursorY);
schemX = -1;
schemY = -1;
}
if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){
if(Core.input.keyRelease(Binding.breakBlock) || Core.input.keyRelease(Binding.select)){
if(mode == placing && block != null){ //touch up while placing, place everything in selection
if(input.keyDown(Binding.boost)){
@@ -778,7 +778,7 @@ public class DesktopInput extends InputHandler{
linePlans.clear();
Events.fire(new LineConfirmEvent());
}else if(mode == breaking){ //touch up while breaking, break everything in selection
removeSelection(selectX, selectY, cursorX, cursorY, !Core.input.keyDown(Binding.schematic_select) ? maxLength : Vars.maxSchematicSize);
removeSelection(selectX, selectY, cursorX, cursorY, !Core.input.keyDown(Binding.schematicSelect) ? maxLength : Vars.maxSchematicSize);
if(lastSchematic != null){
useSchematic(lastSchematic);
lastSchematic = null;
@@ -808,11 +808,11 @@ public class DesktopInput extends InputHandler{
mode = none;
}
if(Core.input.keyTap(Binding.toggle_block_status)){
if(Core.input.keyTap(Binding.toggleBlockStatus)){
Core.settings.put("blockstatus", !Core.settings.getBool("blockstatus"));
}
if(Core.input.keyTap(Binding.toggle_power_lines)){
if(Core.input.keyTap(Binding.togglePowerLines)){
if(Core.settings.getInt("lasersopacity") == 0){
Core.settings.put("lasersopacity", Core.settings.getInt("preferredlaseropacity", 100));
}else{
@@ -849,7 +849,7 @@ public class DesktopInput extends InputHandler{
commandTap(x, y);
}
if(button == keybinds.get(Binding.command_queue).key){
if(button == Binding.commandQueue.value.key){
commandTap(x, y, true);
}
@@ -897,8 +897,8 @@ public class DesktopInput extends InputHandler{
boolean omni = unit.type.omniMovement;
float speed = unit.speed();
float xa = Core.input.axis(Binding.move_x);
float ya = Core.input.axis(Binding.move_y);
float xa = Core.input.axis(Binding.moveX);
float ya = Core.input.axis(Binding.moveY);
boolean boosted = (unit instanceof Mechc && unit.isFlying());
if(settings.getBool("detach-camera")){
@@ -912,7 +912,7 @@ public class DesktopInput extends InputHandler{
}
}else{
movement.set(xa, ya).nor().scl(speed);
if(Core.input.keyDown(Binding.mouse_move)){
if(Core.input.keyDown(Binding.mouseMove)){
movement.add(input.mouseWorld().sub(player).scl(1f / 25f * speed)).limit(speed);
}
}