Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added schematic offset via arrow keys & submit schematic via modifier #228

Open
wants to merge 3 commits into
base: v7
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions core/assets/features
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* Click Assist - Shift (Regular), Shift + Alt (Free Move), Ctrl (Follow Cursor), Ctrl + Alt (BuildPath)
* Shift {schematic_menu} - Schematic browser
* {force_place_modifier} {select} - Force places selection/schematics by marking overlapping buildings for deconstruction and placing overlapped plans into frozen queue.
* {schematic_submit_modifier} {schematic_submit} - Submit/place schematic
* {schematic_offset_modifier} {schematic_offset_y_up} / {schematic_offset_y_down} / {schematic_offset_x_left} / {schematic_offset_x_right} - Offset schematic one tile at a time

# Commands
* If you're unfamiliar with mindustry command syntax, <name> indicates a required argument, and [name] an optional one
Expand Down
8 changes: 7 additions & 1 deletion core/src/mindustry/input/Binding.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public enum Binding implements KeyBind{
schematic_flip_x(KeyCode.z),
schematic_flip_y(KeyCode.x),
schematic_menu(KeyCode.t),

schematic_offset_modifier(KeyCode.altLeft),
schematic_offset_y_up(KeyCode.up),
schematic_offset_y_down(KeyCode.down),
schematic_offset_x_left(KeyCode.left),
schematic_offset_x_right(KeyCode.right),
schematic_submit(KeyCode.enter),
schematic_submit_modifier(KeyCode.altLeft),
category_prev(KeyCode.comma, "blocks"),
category_next(KeyCode.period),

Expand Down
39 changes: 39 additions & 0 deletions core/src/mindustry/input/DesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class DesktopInput extends InputHandler{
/** Previously selected tile. */
public Tile prevSelected;
private long lastShiftZ;
/** Cardinality to shift schema from plan's current coordinates */
private int schemaYOffset = 0;
private int schemaXOffset = 0;
/** If offset needs to be calculated */
private boolean updateOffset = false;

@Override
public void buildUI(Group group){
Expand Down Expand Up @@ -223,10 +228,20 @@ public void drawBottom(){
//draw schematic plans
for(int i = 0; i < size; i++){
var plan = items[i];

if (updateOffset){
plan.x = plan.x + schemaXOffset;
plan.y = plan.y + schemaYOffset;
}

plan.animScale = 1f;
drawPlan(plan, plan.cachedValid = validPlace(plan.x, plan.y, plan.block, plan.rotation), alpha);
}

schemaXOffset = 0;
schemaYOffset = 0;
updateOffset = false;

//draw schematic plans - over version, cached results
for(int i = 0; i < size; i++){
var plan = items[i];
Expand Down Expand Up @@ -902,6 +917,30 @@ else if (Core.input.ctrl()) {
selectUnitsRect();
}

if(Core.input.keyDown(Binding.schematic_offset_modifier)){
if(Core.input.keyTap(Binding.schematic_offset_y_up)){
updateOffset = true;
schemaYOffset = 1;
}
if(Core.input.keyTap(Binding.schematic_offset_y_down)){
updateOffset = true;
schemaYOffset = -1;
}
if(Core.input.keyTap(Binding.schematic_offset_x_right)){
updateOffset = true;
schemaXOffset = 1;
}
if(Core.input.keyTap(Binding.schematic_offset_x_left)){
updateOffset = true;
schemaXOffset = -1;
}
}

// only "submit" / flush schematic something doesn't have keyboard focus (like chat/console)
if(Core.input.keyDown(Binding.schematic_submit_modifier) && Core.input.keyTap(Binding.schematic_submit) && scene.getKeyboardFocus() == null && selectPlans.any()){
flushPlans(selectPlans, isFreezeQueueing, Core.input.keyDown(Binding.force_place_modifier), isFreezeQueueing);
}

if(Core.input.keyTap(Binding.select) && !Core.scene.hasMouse()){
tappedOne = false;
BuildPlan plan = getPlan(cursorX, cursorY);
Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/ui/fragments/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public ChatFragment(){

update(() -> {

if(input.keyTap(Binding.chat) && (scene.getKeyboardFocus() == chatfield || scene.getKeyboardFocus() == null || ui.minimapfrag.shown()) && !ui.consolefrag.shown()){
// don't get chat focus if modifier to "submit" schematic is held
if(input.keyTap(Binding.chat) && (scene.getKeyboardFocus() == chatfield || scene.getKeyboardFocus() == null || ui.minimapfrag.shown()) && !ui.consolefrag.shown() && !input.keyDown(Binding.schematic_submit_modifier)){
toggle();
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/ui/fragments/ConsoleFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public ConsoleFragment(){
});

update(() -> {
if(input.keyTap(Binding.chat) && settings.getBool("console") && (scene.getKeyboardFocus() == chatfield || scene.getKeyboardFocus() == null)){
// don't get console focus if modifier to "submit" schematic is held
if(input.keyTap(Binding.chat) && settings.getBool("console") && (scene.getKeyboardFocus() == chatfield || scene.getKeyboardFocus() == null) && !input.keyDown(Binding.schematic_submit_modifier)){
toggle();
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/mindustry/ui/fragments/PlacementFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ boolean gridUpdate(InputHandler input){
if(ui.chatfrag.shown() || ui.consolefrag.shown() || Core.scene.hasKeyboard()) return false;

for(int i = 0; i < blockSelect.length; i++){
if(Core.input.keyTap(blockSelect[i])){
// don't listen to arrow keys for block selection
// if we are listening to arrow keys for schematic offset
if(Core.input.keyTap(blockSelect[i]) && !Core.input.keyDown(Binding.schematic_offset_modifier)){
if(i > 9){ //select block directionally
Seq<Block> blocks = getUnlockedByCategory(currentCategory);
Block currentBlock = getSelectedBlock(currentCategory);
Expand Down