Skip to content
Closed
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
1 change: 1 addition & 0 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mapInfo.buttons.bannedBlocks = Banned Blocks
mapInfo.buttons.bannedUnits = Banned Units
mapInfo.buttons.hiddenBuildItems = Hidden Build Items
mapInfo.buttons.revealedBlocks = Revealed Blocks
mapInfo.buttons.objectives = Map Objectives
mapInfo.buttons.objectiveFlags = Objective Flags
mapInfo.buttons.mapTags = Map Tags
mapInfo.buttons.expand = Expand
Expand Down
1 change: 1 addition & 0 deletions assets/bundles/bundle_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mapInfo.buttons.bannedBlocks = 禁用的建筑
mapInfo.buttons.bannedUnits = 禁用的单位
mapInfo.buttons.hiddenBuildItems = 隐藏的建材
mapInfo.buttons.revealedBlocks = 显示的建筑
mapInfo.buttons.objectives = 地图游戏目标
mapInfo.buttons.objectiveFlags = 地图目标Flag
mapInfo.buttons.mapTags = 地图Tag
mapInfo.buttons.expand = 展开
Expand Down
26 changes: 26 additions & 0 deletions src/mi2u/MI2UVars.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package mi2u;

import arc.Core;
import arc.func.*;
import arc.math.geom.QuadTree;
import arc.math.geom.Rect;
import arc.scene.style.*;
import arc.scene.ui.*;
import arc.scene.ui.TextButton.*;
Expand All @@ -9,8 +12,12 @@
import mi2u.ai.*;
import mi2u.ui.*;
import mi2u.ui.elements.*;
import mi2u.uiExtend.*;
import mindustry.ui.*;

import static mindustry.Vars.state;
import static mindustry.Vars.ui;

public class MI2UVars{
public static float titleButtonSize = 32f;
public static TextButtonStyle textb = Styles.flatt, textbtoggle = Styles.flatTogglet;
Expand All @@ -23,6 +30,7 @@ public class MI2UVars{
public static Drawable fadeBackground;

public static Seq<Mindow2> mindow2s = new Seq<>();
public static QuadTree<SnapElement> snapTables = new QuadTree<>(new Rect(0, 0, Core.scene.getWidth(), Core.scene.getHeight()));

public static FullAI fullAI = new FullAI();

Expand All @@ -31,4 +39,22 @@ public class MI2UVars{
public static CoreInfoMindow coreInfo = new CoreInfoMindow();
public static LogicHelperMindow logicHelper = new LogicHelperMindow();
public static MinimapMindow mindowmap = new MinimapMindow();

public static Seq<SnapWindow> windows = new Seq<>();
public static TestTable1 testTable1 = new TestTable1();
public static TestTable2 testTable2 = new TestTable2();
public static TestTable3 testTable3 = new TestTable3();
public static TestTable4 testTable4 = new TestTable4();


public static void initTables(){
testTable1.addTo(Core.scene.root);
testTable1.visible(() -> state.isGame() && ui.hudfrag.shown);
testTable2.addTo(Core.scene.root);
testTable2.visible(() -> state.isGame() && ui.hudfrag.shown);
testTable3.addTo(Core.scene.root);
testTable3.visible(() -> state.isGame() && ui.hudfrag.shown);
testTable4.addTo(Core.scene.root);
testTable4.visible(() -> state.isGame() && ui.hudfrag.shown);
}
}
9 changes: 9 additions & 0 deletions src/mi2u/MI2Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import mi2u.input.*;
import mi2u.ui.*;
import mi2u.ui.elements.*;
import mindustry.core.Logic;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.maps.Map;
import mindustry.mod.*;
import mindustry.ui.*;

Expand Down Expand Up @@ -75,6 +77,8 @@ public MI2Utilities(){
mindowmap.visible(() -> state.isGame() && ui.hudfrag.shown);
if(mi2ui.settings.getBool("showLogicHelper")) logicHelper.addTo(logicHelper.hasParent() ? logicHelper.parent : ui.logic);

MI2UVars.initTables();

RendererExt.initBase();
ModifyFuncs.modifyVanilla();
BuildingStatsPopup.init();
Expand All @@ -84,6 +88,11 @@ public MI2Utilities(){
Time.runTask(140f, () -> {
if(mi2ui.settings.getBool("enableUpdate")) checkUpdate();
});

Time.runTask(200f, () -> {
Map map = maps.loadInternalMap("caldera");
control.playMap(map, map.rules());
});
});

Events.on(FileTreeInitEvent.class, e -> Core.app.post(MI2UShaders::load));
Expand Down
35 changes: 28 additions & 7 deletions src/mi2u/ui/MapInfoTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import mindustry.ui.dialogs.*;
import mindustry.world.*;

import java.util.Arrays;

import static mi2u.MI2UVars.*;
import static mi2u.struct.UnitsData.*;
import static mindustry.Vars.*;
Expand Down Expand Up @@ -411,18 +413,33 @@ public void setupDetailAttsInfo(){
});
}).with(funcSetTextb).disabled(b -> state.rules.bannedUnits.isEmpty());

tt.row();

tt.button("@mapInfo.buttons.revealedBlocks", textb, () -> {
showIterable("@mapInfo.buttons.revealedBlocks", state.rules.revealedBlocks, null, (block, table) -> {
table.image(block.uiIcon).size(32f);
});
}).with(funcSetTextb).disabled(b -> state.rules.revealedBlocks.isEmpty());

tt.row();

tt.button("@mapInfo.buttons.objectives", textb, () -> {
showIterable("@mapInfo.buttons.objectives", state.rules.objectives, null, (objective, table) -> {
table.table(obj -> {
int idx = state.rules.objectives.all.indexOf(objective);
obj.left().label(() -> "[" + idx + "]" + objective.typeName()).growX().row();
obj.table(info -> {
info.label(() -> (objective.hidden? "": "[lightgray]") + "Hidden: " + objective.hidden).growX().row();
info.label(() -> (objective.qualified()? "": "[lightgray]") + "Qualified: " + objective.qualified()).growX().row();
if (objective.flagsAdded.length != 0) info.label(() -> "Added Flags: " + Arrays.toString(objective.flagsAdded)).growX().row();
if (objective.flagsRemoved.length != 0) info.label(() -> "Removed Flags: " + Arrays.toString(objective.flagsRemoved)).growX().row();
}).growX().padLeft(8f);
}).left().growX().padTop(4f).padBottom(4f);
}, 1);
}).with(funcSetTextb).disabled(b -> state.rules.objectives.all.isEmpty());

tt.button("@mapInfo.buttons.objectiveFlags", textb, () -> {
showIterable("@mapInfo.buttons.objectiveFlags", state.rules.objectiveFlags, null, (str, table) -> {
table.add(str).size(48f);
});
table.add(str).size(0, 32f);
}, 1);
}).with(funcSetTextb).disabled(b -> state.rules.objectiveFlags.isEmpty());

tt.button("@mapInfo.buttons.mapTags", textb, () -> {
Expand Down Expand Up @@ -504,7 +521,7 @@ public void setupDetailAttsInfo(){
});
}

public <T> void showIterable(String title, Iterable<T> array, Boolf<T> boolf, Cons2<T, Table> cons){
public <T> void showIterable(String title, Iterable<T> array, Boolf<T> boolf, Cons2<T, Table> cons, int itemPerRow){
attrsListPopup.clear();
attrsListPopup.setBackground(Styles.black3);
attrsListPopup.touchable = Touchable.enabled;
Expand All @@ -519,8 +536,8 @@ public <T> void showIterable(String title, Iterable<T> array, Boolf<T> boolf, Co
int index = 0;
for(T item : array){
if(boolf != null && !boolf.get(item)) continue;
cont.table(t -> cons.get(item, t));
if(++index >= 8){
cont.table(t -> cons.get(item, t)).growX();
if(++index >= itemPerRow){
index = 0;
cont.row();
}
Expand All @@ -538,6 +555,10 @@ public <T> void showIterable(String title, Iterable<T> array, Boolf<T> boolf, Co
attrsListPopup.toFront();
}

public <T> void showIterable(String title, Iterable<T> array, Boolf<T> boolf, Cons2<T, Table> cons){
showIterable(title, array, boolf, cons, 8);
}

public class WaveBar extends Table{
MI2Bar bar;
Table table;
Expand Down
193 changes: 193 additions & 0 deletions src/mi2u/uiExtend/SnapElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package mi2u.uiExtend;

import arc.input.KeyCode;
import arc.math.geom.QuadTree;
import arc.math.geom.Rect;
import arc.scene.Element;
import arc.scene.ui.layout.Table;
import arc.struct.Queue;
import arc.struct.Seq;
import arc.util.Align;
import arc.util.Log;
import arc.util.Tmp;
import mi2u.MI2UVars;

import java.util.Arrays;

import static arc.Core.input;
import static arc.util.Align.*;
import static arc.util.Align.bottom;

public class SnapElement extends Table implements QuadTree.QuadTreeObject {
public static final float snapRange = 32f;

public boolean dragging = false;
public float snapX = -1, snapY = -1;
public float hoverTime = 0f;
/**
* Returns the X position of the specified {@link Align alignment}.
*/
@Override
public float getX(int alignment){
float x = this.x;
if((alignment & right) != 0)
x += width * scaleX;
else if((alignment & left) == 0) //
x += width * scaleX / 2;
return x;
}

/**
* Returns the Y position of the specified {@link Align alignment}.
*/
@Override
public float getY(int alignment){
float y = this.y;
if((alignment & top) != 0)
y += height * scaleY;
else if((alignment & bottom) == 0) //
y += height * scaleY / 2;
return y;
}

@Override
public void setPosition(float x, float y, int alignment){
if((alignment & right) != 0)
x -= width * scaleX;
else if((alignment & left) == 0) //
x -= width * scaleX / 2;

if((alignment & top) != 0)
y -= height * scaleY;
else if((alignment & bottom) == 0) //
y -= height * scaleY / 2;

if(this.x != x || this.y != y){
this.x = x;
this.y = y;
}
}

public void innerElementSnap(Element element){
if (element == null) return;
if (Math.abs(leftBound(this) - leftBound(element)) < snapRange) snapX = leftBound(element);
if (Math.abs(bottomBound(this) - bottomBound(element)) < snapRange) snapY = bottomBound(element);
if (Math.abs(topBound(this) - topBound(element)) < snapRange) snapY = topBound(element) - height(this);
if (Math.abs(rightBound(this) - rightBound(element)) < snapRange) snapX = rightBound(element) - width(this);
}

public void outerElementSnap(Element element){
if (element == null) return;
if (!element.visible) return;
Tmp.r1.set(x, y, width(this), height(this)).grow(snapRange/2f);
Tmp.r2.set(element.x, element.y, width(element), height(element)).grow(snapRange/2f);
if (!Tmp.r1.overlaps(Tmp.r2)) return;

//todo check on both dst
if (Math.abs(leftBound(this) - rightBound(element)) < snapRange) {
snapX = rightBound(element);
if (Math.abs(topBound(this) - topBound(element)) < snapRange) snapY = topBound(element) - height(this);
if (Math.abs(bottomBound(this) - bottomBound(element)) < snapRange) snapY = bottomBound(element);
}
if (Math.abs(rightBound(this) - leftBound(element)) < snapRange) {
snapX = leftBound(element) - width(this);
if (Math.abs(topBound(this) - topBound(element)) < snapRange) snapY = topBound(element) - height(this);
if (Math.abs(bottomBound(this) - bottomBound(element)) < snapRange) snapY = bottomBound(element);
}
if (Math.abs(bottomBound(this) - topBound(element)) < snapRange) {
snapY = topBound(element);
if (Math.abs(rightBound(this) - rightBound(element)) < snapRange) snapX = rightBound(element) - width(this);
if (Math.abs(leftBound(this) - leftBound(element)) < snapRange) snapX = leftBound(element);
}
if (Math.abs(topBound(this) - bottomBound(element)) < snapRange) {
snapY = bottomBound(element) - height(this);
if (Math.abs(rightBound(this) - rightBound(element)) < snapRange) snapX = rightBound(element) - width(this);
if (Math.abs(leftBound(this) - leftBound(element)) < snapRange) snapX = leftBound(element);
}
}

public boolean isElementSnapped(Element self, Element element){
if (element == null) return false;
if (!element.visible) return false;
Tmp.r1.set(self.x, self.y, width(self), height(self)).grow(snapRange/2f);
Tmp.r2.set(element.x, element.y, width(element), height(element)).grow(snapRange/2f);
if (!Tmp.r1.overlaps(Tmp.r2)) return false;

return Math.abs(topBound(self) - bottomBound(element)) < snapRange/4f ||
Math.abs(leftBound(self) - rightBound(element)) < snapRange/4f ||
Math.abs(rightBound(self) - leftBound(element)) < snapRange/4f ||
Math.abs(bottomBound(self) - topBound(element)) < snapRange/4f;
}

public boolean isElementSnapped(Element element){
return isElementSnapped(this, element);
}

public Seq<Element> getAllElements() {
Seq<Element> elements = new Seq<>();
elements.add(MI2UVars.mindow2s);
elements.add(MI2UVars.windows);
return elements;
}

public Seq<Element> getProxySnappedElements(Element self, Seq<Element> check){
//todo replace check with quadtree
Seq<Element> tmp = new Seq<>();
check.each(e -> {
if (isElementSnapped(self, e)){
tmp.add(e);
}
});
return tmp;
}

public void getSnappedElements(Seq<Element> out){
Queue<Element> queue = new Queue<>();

out.add(this);
queue.addLast(this);

while (!queue.isEmpty()){
Element element = queue.removeFirst();
for (Element proxy: getProxySnappedElements(element, getAllElements())){
if (isElementSnapped(element, proxy) && !out.contains(proxy)){
out.add(proxy);
queue.addLast(proxy);
}
}
}
}

public float leftBound(Element element){
return element.x;
}

public float bottomBound(Element element){
return element.y;
}

public float rightBound(Element element){
return element.x + element.getWidth() * element.scaleX;
}

public float topBound(Element element){
return element.y + element.getHeight() * element.scaleY;
}

public float width(Element element){
return element.getWidth() * element.scaleX;
}

public float height(Element element){
return element.getHeight() * element.scaleY;
}

public void updateDragging(){
dragging = hasMouse() && input.keyDown(KeyCode.controlLeft);
}

@Override
public void hitbox(Rect out) {
out.set(x, y, width, hoverTime);
}
}
Loading
Loading