Skip to content

Commit

Permalink
Allow build plans to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
7003Mars committed Dec 10, 2023
1 parent a325dd2 commit 06d8355
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/src/mindustry/core/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ public void showLaunch(CoreBlock coreType){
Vars.ui.hudfrag.showLaunch();
Vars.control.input.config.hideConfig();
Vars.control.input.inv.hide();
Vars.control.input.planConfig.hide();
launchCoreType = coreType;
launching = true;
landCore = player.team().core();
Expand Down
9 changes: 8 additions & 1 deletion core/src/mindustry/input/DesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,14 @@ else if (Core.input.ctrl()) {
if(getPlan(splan.x, splan.y, splan.block.size, splan) != null){
player.unit().plans().remove(splan, true);
}
if(!splanMoved) player.unit().addBuild(splan, false); // Add the plan to the top of the queue
if(!splanMoved && input.ctrl()) {
inv.hide();
config.hideConfig();
planConfig.showConfig(splan);
} else {
planConfig.hide();
if (!splanMoved) player.unit().addBuild(splan, false); // Add the plan to the top of the queue
}
splan = null;
splanMoved = false;
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/mindustry/input/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{

public final BlockInventoryFragment inv;
public final BlockConfigFragment config;
public final PlanConfigFragment planConfig;

private WidgetGroup group = new WidgetGroup();

Expand All @@ -130,6 +131,7 @@ public InputHandler(){
group.touchable = Touchable.childrenOnly;
inv = new BlockInventoryFragment();
config = new BlockConfigFragment();
planConfig = new PlanConfigFragment();

Events.on(UnitDestroyEvent.class, e -> {
if(e.unit != null && e.unit.isPlayer() && e.unit.getPlayer().isLocal() && e.unit.type.weapons.contains(w -> w.bullet.killShooter)){
Expand Down Expand Up @@ -1666,6 +1668,8 @@ boolean checkConfigTap(){

/** Handles tile tap events that are not platform specific. */
boolean tileTapped(@Nullable Building build){
// Should hide plan config regardless of what was tapped
planConfig.hide();
if(build == null){
inv.hide();
config.hideConfig();
Expand Down Expand Up @@ -1943,6 +1947,7 @@ public void add(){

inv.build(group);
config.build(group);
planConfig.build(group);
}
}

Expand Down
84 changes: 84 additions & 0 deletions core/src/mindustry/ui/fragments/PlanConfigFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package mindustry.ui.fragments;

import arc.Core;
import arc.Events;
import arc.math.Interp;
import arc.math.geom.Vec2;
import arc.scene.Group;
import arc.scene.actions.Actions;
import arc.scene.ui.layout.Table;
import arc.struct.Seq;
import arc.util.Align;
import mindustry.ctype.UnlockableContent;
import mindustry.entities.units.BuildPlan;
import mindustry.game.EventType;
import mindustry.type.Item;
import mindustry.type.Liquid;
import mindustry.world.Block;
import mindustry.world.blocks.ItemSelection;

import static mindustry.Vars.*;

public class PlanConfigFragment {
Table table = new Table();
BuildPlan selected;

public void build(Group parent){
table.visible = false;
parent.addChild(table);

Events.on(EventType.ResetEvent.class, e -> forceHide());
}

public void showConfig(BuildPlan plan) {
if (this.selected == plan) {
hide();
return;
}
Block block = plan.block;
if (!block.configurable) return;
selected = plan;
table.clear();
Seq<UnlockableContent> items = new Seq<>();
if (block.configurations.containsKey(Item.class)) {
items.add(content.items());
} else if (block.configurations.containsKey(Liquid.class)) {
items.add(content.liquids());
}
if (items.isEmpty()) return;
ItemSelection.buildTable(table, items, () -> selected != null ? (selected.config instanceof UnlockableContent c ? c : null) : null,
content -> {
selected.config = content;
hide();
}, block.selectionRows, block.selectionColumns);
table.pack();
table.setTransform(true);
table.visible = true;
table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true),
Actions.scaleTo(1f, 1f, 0.07f, Interp.pow3Out));
table.update(() -> {
table.setOrigin(Align.center);
if (plan.isDone()) {
this.hide();
return;
}
boolean planExists = control.input.selectPlans.contains(plan) || player.unit().plans.contains(plan);
if (!planExists) {
this.hide();
return;
}
Vec2 pos = Core.input.mouseScreen(plan.drawx(), plan.drawy() - block.size * tilesize / 2.0F - 1);
table.setPosition(pos.x, pos.y, Align.top);
});
}

public void forceHide() {
table.visible = false;
selected = null;
}

public void hide() {
selected = null;
table.actions(Actions.scaleTo(0f, 1f, 0.06f, Interp.pow3Out), Actions.visible(false));
}
}

0 comments on commit 06d8355

Please sign in to comment.