mirror of
https://github.com/yawaflua/Informatis.git
synced 2026-02-04 02:14:17 +02:00
multi window go brr
This commit is contained in:
@@ -3,7 +3,6 @@ package informatis;
|
|||||||
import arc.input.KeyCode;
|
import arc.input.KeyCode;
|
||||||
import informatis.core.OverDrawer;
|
import informatis.core.OverDrawer;
|
||||||
import informatis.core.Setting;
|
import informatis.core.Setting;
|
||||||
import informatis.ui.*;
|
|
||||||
import informatis.draws.OverDraws;
|
import informatis.draws.OverDraws;
|
||||||
import informatis.ui.fragments.FragmentManager;
|
import informatis.ui.fragments.FragmentManager;
|
||||||
import informatis.ui.windows.*;
|
import informatis.ui.windows.*;
|
||||||
@@ -15,7 +14,7 @@ import mindustry.mod.*;
|
|||||||
import static informatis.SVars.*;
|
import static informatis.SVars.*;
|
||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
import static informatis.SUtils.*;
|
import static informatis.SUtils.*;
|
||||||
import static informatis.ui.WindowManager.windows;
|
import static informatis.ui.windows.WindowManager.windows;
|
||||||
|
|
||||||
public class Informatis extends Mod {
|
public class Informatis extends Mod {
|
||||||
@Override
|
@Override
|
||||||
@@ -28,17 +27,9 @@ public class Informatis extends Mod {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Events.run(Trigger.update, () -> {
|
Events.run(Trigger.update, () -> {
|
||||||
//TODO: why not just use Events in its own class constructor?
|
|
||||||
for (Window window : windows) {
|
|
||||||
window.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: target should be not global variable anymore for multiple window system
|
|
||||||
target = getTarget();
|
|
||||||
if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))) {
|
if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))) {
|
||||||
if(input.keyTap(KeyCode.r)) {
|
if(input.keyTap(KeyCode.r)) {
|
||||||
if(target == getTarget()) locked = !locked;
|
windows.get(UnitWindow.class).each(window -> ((UnitWindow) window).locked = !((UnitWindow) window).locked);
|
||||||
target = getTarget();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,27 +26,23 @@ import static mindustry.Vars.player;
|
|||||||
public class SUtils {
|
public class SUtils {
|
||||||
/**
|
/**
|
||||||
* move camera to given coordination
|
* move camera to given coordination
|
||||||
* @param x - world unit x
|
* @param x world unit x
|
||||||
* @param y - world unit y
|
* @param y world unit y
|
||||||
*/
|
*/
|
||||||
public static void moveCamera(float x, float y) {
|
public static void moveCamera(float x, float y) {
|
||||||
if(control.input instanceof DesktopInput)
|
if(control.input instanceof DesktopInput)
|
||||||
((DesktopInput) control.input).panning = true;
|
((DesktopInput) control.input).panning = true;
|
||||||
Core.camera.position.set(x, y);
|
Core.camera.position.set(x, y);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* move camera to given coordination
|
||||||
|
* @param pos world unit coordination
|
||||||
|
*/
|
||||||
public static void moveCamera(Position pos) {
|
public static void moveCamera(Position pos) {
|
||||||
moveCamera(pos.getX(), pos.getY());
|
moveCamera(pos.getX(), pos.getY());
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Teamc> T getTarget(){
|
public static <T extends Teamc> T getTarget(){
|
||||||
if(locked && target != null) {
|
|
||||||
if(settings.getBool("deadTarget") && !Groups.all.contains(e -> e == target)) {
|
|
||||||
target = player.unit();
|
|
||||||
locked = false;
|
|
||||||
}
|
|
||||||
else return (T) target; //if there is locked target, return it first.
|
|
||||||
}
|
|
||||||
|
|
||||||
Seq<Unit> units = Groups.unit.intersect(input.mouseWorldX(), input.mouseWorldY(), 4, 4); // well, 0.5tile is enough to search them
|
Seq<Unit> units = Groups.unit.intersect(input.mouseWorldX(), input.mouseWorldY(), 4, 4); // well, 0.5tile is enough to search them
|
||||||
if(units.size > 0)
|
if(units.size > 0)
|
||||||
return (T) units.peek(); //if there is unit, return it.
|
return (T) units.peek(); //if there is unit, return it.
|
||||||
@@ -109,11 +105,6 @@ public class SUtils {
|
|||||||
return field.get(ut);
|
return field.get(ut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isOutCamera(float x, float y) {
|
|
||||||
return !isInCamera(x, y, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isInCamera(float x, float y, float size) {
|
public static boolean isInCamera(float x, float y, float size) {
|
||||||
Tmp.r2.setCentered(x, y, size);
|
Tmp.r2.setCentered(x, y, size);
|
||||||
return Tmp.r1.overlaps(Tmp.r2);
|
return Tmp.r1.overlaps(Tmp.r2);
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ import mindustry.gen.Teamc;
|
|||||||
import static arc.Core.atlas;
|
import static arc.Core.atlas;
|
||||||
|
|
||||||
public class SVars {
|
public class SVars {
|
||||||
public static TextureRegion clear = atlas.find("clear");
|
public static TextureRegion
|
||||||
public static TextureRegion error = atlas.find("error");
|
clear = atlas.find("clear"),
|
||||||
|
error = atlas.find("error");
|
||||||
public static RangeShader turretRange = new RangeShader();
|
public static RangeShader turretRange = new RangeShader();
|
||||||
public static informatis.core.Pathfinder pathfinder;
|
public static informatis.core.Pathfinder pathfinder;
|
||||||
public static Teamc target;
|
|
||||||
public static boolean locked;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import informatis.ui.windows.UnitWindow;
|
||||||
|
import informatis.ui.windows.WindowManager;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
|
|
||||||
|
import static informatis.SUtils.getTarget;
|
||||||
import static informatis.SVars.*;
|
import static informatis.SVars.*;
|
||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
@@ -32,18 +35,22 @@ public class OverDrawer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(settings.getBool("select")) {
|
if(settings.getBool("select")) {
|
||||||
Draw.color(Tmp.c1.set(locked ? Color.orange : Color.darkGray).lerp(locked ? Color.scarlet : Color.gray, Mathf.absin(Time.time, 3f, 1f)).a(settings.getInt("selectopacity") / 100f));
|
WindowManager.windows.get(UnitWindow.class).each(w -> {
|
||||||
float length = (target instanceof Unit u ? u.hitSize : target instanceof Building b ? b.block.size * tilesize : 0) * 1.5f + 2.5f;
|
UnitWindow window = (UnitWindow) w;
|
||||||
for(int i = 0; i < 4; i++){
|
Draw.color(Tmp.c1.set(window.locked ? Color.orange : Color.darkGray).lerp(window.locked ? Color.scarlet : Color.gray, Mathf.absin(Time.time, 3f, 1f)).a(settings.getInt("selectopacity") / 100f));
|
||||||
float rot = i * 90f + 45f + (-Time.time) % 360f;
|
float length = (window.target instanceof Unit u ? u.hitSize : window.target instanceof Building b ? b.block.size * tilesize : 0) * 1.5f + 2.5f;
|
||||||
Draw.rect("select-arrow", target.x() + Angles.trnsx(rot, length), target.y() + Angles.trnsy(rot, length), length / 1.9f, length / 1.9f, rot - 135f);
|
for(int i = 0; i < 4; i++){
|
||||||
}
|
float rot = i * 90f + 45f + (-Time.time) % 360f;
|
||||||
|
Draw.rect("select-arrow", window.target.x() + Angles.trnsx(rot, length), window.target.y() + Angles.trnsy(rot, length), length / 1.9f, length / 1.9f, rot - 135f);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Draw.color();
|
Draw.color();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings.getBool("distanceLine")) {
|
if(settings.getBool("distanceLine")) {
|
||||||
Posc from = player;
|
Posc from = player;
|
||||||
Position to = target;
|
Position to = getTarget();
|
||||||
if(to == from || to == null) to = input.mouseWorld();
|
if(to == from || to == null) to = input.mouseWorld();
|
||||||
if(player.unit() instanceof BlockUnitUnit bu) Tmp.v1.set(bu.x() + bu.tile().block.offset, bu.y() + bu.tile().block.offset).sub(to.getX(), to.getY()).limit(bu.tile().block.size * tilesize + sin + 0.5f);
|
if(player.unit() instanceof BlockUnitUnit bu) Tmp.v1.set(bu.x() + bu.tile().block.offset, bu.y() + bu.tile().block.offset).sub(to.getX(), to.getY()).limit(bu.tile().block.size * tilesize + sin + 0.5f);
|
||||||
else Tmp.v1.set(from.x(), from.y()).sub(to.getX(), to.getY()).limit((player.unit()==null?0:player.unit().hitSize) + sin + 0.5f);
|
else Tmp.v1.set(from.x(), from.y()).sub(to.getX(), to.getY()).limit((player.unit()==null?0:player.unit().hitSize) + sin + 0.5f);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import arc.util.Tmp;
|
|||||||
import mindustry.core.Renderer;
|
import mindustry.core.Renderer;
|
||||||
import mindustry.gen.Building;
|
import mindustry.gen.Building;
|
||||||
import mindustry.gen.Groups;
|
import mindustry.gen.Groups;
|
||||||
|
import mindustry.gen.Teamc;
|
||||||
import mindustry.graphics.Drawf;
|
import mindustry.graphics.Drawf;
|
||||||
import mindustry.graphics.Layer;
|
import mindustry.graphics.Layer;
|
||||||
import mindustry.graphics.Pal;
|
import mindustry.graphics.Pal;
|
||||||
@@ -21,6 +22,7 @@ import mindustry.world.blocks.payloads.PayloadMassDriver;
|
|||||||
|
|
||||||
import static arc.Core.atlas;
|
import static arc.Core.atlas;
|
||||||
import static arc.Core.settings;
|
import static arc.Core.settings;
|
||||||
|
import static informatis.SUtils.getTarget;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
import static informatis.SVars.*;
|
import static informatis.SVars.*;
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ public class LinkDraw extends OverDraw {
|
|||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
if(!enabled) return;
|
if(!enabled) return;
|
||||||
|
Teamc target = getTarget();
|
||||||
Draw.z(Layer.max);
|
Draw.z(Layer.max);
|
||||||
if(target instanceof Building b){
|
if(target instanceof Building b){
|
||||||
if(settings.getBool("powerNode") && enabled) {
|
if(settings.getBool("powerNode") && enabled) {
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package informatis.ui;
|
|
||||||
|
|
||||||
import arc.*;
|
|
||||||
import arc.struct.*;
|
|
||||||
import mindustry.*;
|
|
||||||
import mindustry.ui.*;
|
|
||||||
import informatis.ui.windows.*;
|
|
||||||
|
|
||||||
public class WindowManager {
|
|
||||||
public static Seq<Window> windows = new Seq<>();
|
|
||||||
|
|
||||||
public static void init(){
|
|
||||||
Vars.ui.hudGroup.fill(t -> {
|
|
||||||
t.name = "Windows";
|
|
||||||
for(Window window : windows){
|
|
||||||
t.add(window).height(window.getHeight()).width(window.getWidth());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Vars.ui.hudGroup.fill(t -> {
|
|
||||||
t.center().left();
|
|
||||||
t.table(Core.atlas.drawable("informatis-sidebar"), b -> {
|
|
||||||
b.name = "Window Buttons";
|
|
||||||
b.left();
|
|
||||||
|
|
||||||
for(Window window : windows){
|
|
||||||
b.button(window.icon, Styles.emptyi, () -> {
|
|
||||||
window.toggle();
|
|
||||||
|
|
||||||
// Disabling the parent's layout fixes issues with updating elements inside windows.
|
|
||||||
// However, it also disables the layout of all its children, so we need to re-enable them.
|
|
||||||
window.parent.setLayoutEnabled(false);
|
|
||||||
window.setLayoutEnabled(true);
|
|
||||||
for(Window w : windows){
|
|
||||||
w.setLayoutEnabled(true);
|
|
||||||
}
|
|
||||||
}).disabled(window.shown)
|
|
||||||
.size(40f)
|
|
||||||
.tooltip(tt -> {
|
|
||||||
tt.setBackground(Styles.black6);
|
|
||||||
tt.label(() -> Core.bundle.get("window."+window.name+".name")).pad(2f);
|
|
||||||
});
|
|
||||||
b.row();
|
|
||||||
}
|
|
||||||
}).left();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int register(Window window){
|
|
||||||
windows.add(window);
|
|
||||||
return windows.size - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -32,6 +32,20 @@ public class CoreWindow extends Window {
|
|||||||
public CoreWindow() {
|
public CoreWindow() {
|
||||||
super(Icon.list, "core");
|
super(Icon.list, "core");
|
||||||
resetUsed();
|
resetUsed();
|
||||||
|
only = true;
|
||||||
|
|
||||||
|
Events.run(EventType.Trigger.update, () -> {
|
||||||
|
heat += Time.delta;
|
||||||
|
if(heat >= 60f) {
|
||||||
|
heat = 0f;
|
||||||
|
ScrollPane pane = find("core-pane");
|
||||||
|
pane.setWidget(rebuild());
|
||||||
|
for(Team team : getTeams()) {
|
||||||
|
if(!itemData.containsKey(team)) itemData.put(team, new ItemData());
|
||||||
|
itemData.get(team).updateItems(team);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,19 +58,6 @@ public class CoreWindow extends Window {
|
|||||||
Events.on(EventType.WorldLoadEvent.class, e -> resetUsed());
|
Events.on(EventType.WorldLoadEvent.class, e -> resetUsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
heat += Time.delta;
|
|
||||||
if(heat >= 60f) {
|
|
||||||
heat = 0f;
|
|
||||||
ScrollPane pane = find("core-pane");
|
|
||||||
pane.setWidget(rebuild());
|
|
||||||
for(Team team : getTeams()) {
|
|
||||||
if(!itemData.containsKey(team)) itemData.put(team, new ItemData());
|
|
||||||
itemData.get(team).updateItems(team);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Table rebuild() {
|
Table rebuild() {
|
||||||
return new Table(table -> {
|
return new Table(table -> {
|
||||||
table.top();
|
table.top();
|
||||||
@@ -135,7 +136,7 @@ public class CoreWindow extends Window {
|
|||||||
}),
|
}),
|
||||||
new Table(ttt -> {
|
new Table(ttt -> {
|
||||||
ttt.bottom().right();
|
ttt.bottom().right();
|
||||||
if(itemData.get(team) == null) return;
|
if(itemData == null || itemData.get(team) == null) return;
|
||||||
int amount = itemData.get(team).updateItems.isEmpty()?0:Mathf.floor(itemData.get(team).updateItems.get(item.id).amount);
|
int amount = itemData.get(team).updateItems.isEmpty()?0:Mathf.floor(itemData.get(team).updateItems.get(item.id).amount);
|
||||||
Label label = new Label(amount + "/s");
|
Label label = new Label(amount + "/s");
|
||||||
label.setFontScale(0.65f);
|
label.setFontScale(0.65f);
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import mindustry.gen.*;
|
|||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
|
||||||
import static informatis.ui.windows.MapEditorWindow.drawBlock;
|
|
||||||
import static informatis.ui.windows.MapEditorWindow.drawTeam;
|
|
||||||
import static informatis.ui.windows.Windows.editorTable;
|
import static informatis.ui.windows.Windows.editorTable;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -49,8 +47,9 @@ public class MapEditorWindow extends Window {
|
|||||||
public MapEditorWindow() {
|
public MapEditorWindow() {
|
||||||
super(Icon.map, "editor");
|
super(Icon.map, "editor");
|
||||||
|
|
||||||
height = 800;
|
width = 800;
|
||||||
width = 600;
|
height = 600;
|
||||||
|
only = true;
|
||||||
|
|
||||||
for(int i = 0; i < MapEditor.brushSizes.length; i++){
|
for(int i = 0; i < MapEditor.brushSizes.length; i++){
|
||||||
float size = MapEditor.brushSizes[i];
|
float size = MapEditor.brushSizes[i];
|
||||||
@@ -111,6 +110,35 @@ public class MapEditorWindow extends Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Events.run(EventType.Trigger.update, () -> {
|
||||||
|
|
||||||
|
//TODO make it more responsive, time -> width delta detect
|
||||||
|
heat += Time.delta;
|
||||||
|
if(heat >= 60f) {
|
||||||
|
heat = 0f;
|
||||||
|
|
||||||
|
if(lastw != window.getWidth() || lasth != window.getHeight()) resetPane();
|
||||||
|
lastw = width;
|
||||||
|
lasth = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
|
||||||
|
if(tile == null || tool == null || brushSize < 1 || drawBlock == null || hasMouse()) return;
|
||||||
|
if(Core.input.isTouched()) {
|
||||||
|
if((tool == EditorTool.line && drawing) || (!mobile && !Core.input.keyDown(KeyCode.mouseLeft))) return;
|
||||||
|
drawing = true;
|
||||||
|
lastx = tile.x;
|
||||||
|
lasty = tile.y;
|
||||||
|
tool.touched(lastx, lasty);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(tool == EditorTool.line && drawing) tool.touchedLine(lastx, lasty, tile.x, tile.y);
|
||||||
|
drawing = false;
|
||||||
|
lastx = -1;
|
||||||
|
lasty = -1;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -148,34 +176,6 @@ public class MapEditorWindow extends Window {
|
|||||||
}).growY();
|
}).growY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
//TODO make it more responsive, time -> width delta detect
|
|
||||||
heat += Time.delta;
|
|
||||||
if(heat >= 60f) {
|
|
||||||
heat = 0f;
|
|
||||||
|
|
||||||
if(lastw != window.getWidth() || lasth != window.getHeight()) resetPane();
|
|
||||||
lastw = width;
|
|
||||||
lasth = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
|
|
||||||
if(tile == null || tool == null || brushSize < 1 || drawBlock == null || hasMouse()) return;
|
|
||||||
if(Core.input.isTouched()) {
|
|
||||||
if((tool == EditorTool.line && drawing) || (!mobile && !Core.input.keyDown(KeyCode.mouseLeft))) return;
|
|
||||||
drawing = true;
|
|
||||||
lastx = tile.x;
|
|
||||||
lasty = tile.y;
|
|
||||||
tool.touched(lastx, lasty);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(tool == EditorTool.line && drawing) tool.touchedLine(lastx, lasty, tile.x, tile.y);
|
|
||||||
drawing = false;
|
|
||||||
lastx = -1;
|
|
||||||
lasty = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetPane() {
|
void resetPane() {
|
||||||
ScrollPane pane = find("editor-pane");
|
ScrollPane pane = find("editor-pane");
|
||||||
if(pane != null) pane.setWidget(rebuildEditor());
|
if(pane != null) pane.setWidget(rebuildEditor());
|
||||||
@@ -465,255 +465,254 @@ public class MapEditorWindow extends Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
enum EditorTool{
|
enum EditorTool{
|
||||||
zoom(KeyCode.v),
|
zoom(KeyCode.v),
|
||||||
pick(KeyCode.i){
|
pick(KeyCode.i){
|
||||||
public void touched(int x, int y){
|
public void touched(int x, int y){
|
||||||
if(!Structs.inBounds(x, y, world.width(), world.height())) return;
|
if(!Structs.inBounds(x, y, world.width(), world.height())) return;
|
||||||
|
|
||||||
Tile tile = world.tile(x, y);
|
Tile tile = world.tile(x, y);
|
||||||
drawBlock = tile.block() == Blocks.air || !tile.block().inEditor ? tile.overlay() == Blocks.air ? tile.floor() : tile.overlay() : tile.block();
|
drawBlock = tile.block() == Blocks.air || !tile.block().inEditor ? tile.overlay() == Blocks.air ? tile.floor() : tile.overlay() : tile.block();
|
||||||
}
|
|
||||||
},
|
|
||||||
line(KeyCode.l, "replace", "orthogonal"){
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void touchedLine(int x1, int y1, int x2, int y2){
|
|
||||||
//straight
|
|
||||||
if(mode == 1){
|
|
||||||
if(Math.abs(x2 - x1) > Math.abs(y2 - y1)){
|
|
||||||
y2 = y1;
|
|
||||||
}else{
|
|
||||||
x2 = x1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
line(KeyCode.l, "replace", "orthogonal"){
|
||||||
|
|
||||||
Bresenham2.line(x1, y1, x2, y2, (x, y) -> {
|
@Override
|
||||||
if(mode == 0){
|
public void touchedLine(int x1, int y1, int x2, int y2){
|
||||||
//replace
|
//straight
|
||||||
editorTable.drawBlocksReplace(x, y);
|
if(mode == 1){
|
||||||
}else{
|
if(Math.abs(x2 - x1) > Math.abs(y2 - y1)){
|
||||||
//normal
|
y2 = y1;
|
||||||
editorTable.drawBlocks(x, y);
|
}else{
|
||||||
}
|
x2 = x1;
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
pencil(KeyCode.b, "replace", "square", "drawteams"){
|
|
||||||
{
|
|
||||||
edit = true;
|
|
||||||
draggable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void touched(int x, int y){
|
|
||||||
if(mode == -1){
|
|
||||||
//normal mode
|
|
||||||
editorTable.drawBlocks(x, y);
|
|
||||||
}else if(mode == 0){
|
|
||||||
//replace mode
|
|
||||||
editorTable.drawBlocksReplace(x, y);
|
|
||||||
}else if(mode == 1){
|
|
||||||
//square mode
|
|
||||||
editorTable.drawBlocks(x, y, true, tile -> true);
|
|
||||||
}else if(mode == 2){
|
|
||||||
//draw teams
|
|
||||||
editorTable.drawCircle(x, y, tile -> tile.setTeam(drawTeam));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
eraser(KeyCode.e, "eraseores"){
|
|
||||||
{
|
|
||||||
edit = true;
|
|
||||||
draggable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void touched(int x, int y){
|
|
||||||
editorTable.drawCircle(x, y, tile -> {
|
|
||||||
if(mode == -1){
|
|
||||||
//erase block
|
|
||||||
tile.remove();
|
|
||||||
}else if(mode == 0){
|
|
||||||
//erase ore
|
|
||||||
tile.clearOverlay();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fill(KeyCode.g, "replaceall", "fillteams"){
|
|
||||||
{
|
|
||||||
edit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
IntSeq stack = new IntSeq();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void touched(int x, int y){
|
|
||||||
if(!Structs.inBounds(x, y, world.width(), world.height()) || world.tile(x, y).block()!=null&&world.tile(x, y).block().isMultiblock()) return;
|
|
||||||
Tile tile = world.tile(x, y);
|
|
||||||
|
|
||||||
//mode 0 or 1, fill everything with the floor/tile or replace it
|
|
||||||
if(mode == 0 || mode == -1){
|
|
||||||
if(tile.block().isMultiblock()) return;
|
|
||||||
|
|
||||||
Boolf<Tile> tester;
|
|
||||||
Cons<Tile> setter;
|
|
||||||
Block drawBlock = MapEditorWindow.drawBlock;
|
|
||||||
|
|
||||||
if(drawBlock.isOverlay()){
|
|
||||||
Block dest = tile.overlay();
|
|
||||||
if(dest == drawBlock) return;
|
|
||||||
tester = t -> t.overlay() == dest && (t.floor().hasSurface() || !t.floor().needsSurface);
|
|
||||||
setter = t -> t.setOverlay(drawBlock);
|
|
||||||
}else if(drawBlock.isFloor()){
|
|
||||||
Block dest = tile.floor();
|
|
||||||
if(dest == drawBlock) return;
|
|
||||||
tester = t -> t.floor() == dest;
|
|
||||||
setter = t -> t.setFloorUnder(drawBlock.asFloor());
|
|
||||||
}else{
|
|
||||||
Block dest = tile.block();
|
|
||||||
if(dest == drawBlock) return;
|
|
||||||
tester = t -> t.block() == dest;
|
|
||||||
setter = t -> t.setBlock(drawBlock, drawTeam);
|
|
||||||
}
|
|
||||||
|
|
||||||
//replace only when the mode is 0 using the specified functions
|
|
||||||
fill(x, y, mode == 0, tester, setter);
|
|
||||||
}else if(mode == 1){ //mode 1 is team fill
|
|
||||||
//only fill synthetic blocks, it's meaningless otherwise
|
|
||||||
if(tile.synthetic()){
|
|
||||||
Team dest = tile.team();
|
|
||||||
if(dest == drawTeam) return;
|
|
||||||
fill(x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(drawTeam));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void fill(int x, int y, boolean replace, Boolf<Tile> tester, Cons<Tile> filler){
|
|
||||||
int width = world.width(), height = world.height();
|
|
||||||
|
|
||||||
if(replace){
|
|
||||||
//just do it on everything
|
|
||||||
for(int cx = 0; cx < width; cx++){
|
|
||||||
for(int cy = 0; cy < height; cy++){
|
|
||||||
Tile tile = world.tile(cx, cy);
|
|
||||||
if(tester.get(tile)){
|
|
||||||
filler.get(tile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
Bresenham2.line(x1, y1, x2, y2, (x, y) -> {
|
||||||
//perform flood fill
|
if(mode == 0){
|
||||||
int x1;
|
//replace
|
||||||
|
editorTable.drawBlocksReplace(x, y);
|
||||||
stack.clear();
|
}else{
|
||||||
stack.add(Point2.pack(x, y));
|
//normal
|
||||||
|
editorTable.drawBlocks(x, y);
|
||||||
try{
|
|
||||||
while(stack.size > 0 && stack.size < width*height){
|
|
||||||
int popped = stack.pop();
|
|
||||||
x = Point2.x(popped);
|
|
||||||
y = Point2.y(popped);
|
|
||||||
|
|
||||||
x1 = x;
|
|
||||||
while(x1 >= 0 && tester.get(world.tile(x1, y))) x1--;
|
|
||||||
x1++;
|
|
||||||
boolean spanAbove = false, spanBelow = false;
|
|
||||||
while(x1 < width && tester.get(world.tile(x1, y))){
|
|
||||||
filler.get(world.tile(x1, y));
|
|
||||||
|
|
||||||
if(!spanAbove && y > 0 && tester.get(world.tile(x1, y - 1))){
|
|
||||||
stack.add(Point2.pack(x1, y - 1));
|
|
||||||
spanAbove = true;
|
|
||||||
}else if(spanAbove && !tester.get(world.tile(x1, y - 1))){
|
|
||||||
spanAbove = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!spanBelow && y < height - 1 && tester.get(world.tile(x1, y + 1))){
|
|
||||||
stack.add(Point2.pack(x1, y + 1));
|
|
||||||
spanBelow = true;
|
|
||||||
}else if(spanBelow && y < height - 1 && !tester.get(world.tile(x1, y + 1))){
|
|
||||||
spanBelow = false;
|
|
||||||
}
|
|
||||||
x1++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stack.clear();
|
|
||||||
}catch(OutOfMemoryError e){
|
|
||||||
//hack
|
|
||||||
stack = null;
|
|
||||||
System.gc();
|
|
||||||
e.printStackTrace();
|
|
||||||
stack = new IntSeq();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
spray(KeyCode.r, "replace"){
|
|
||||||
final double chance = 0.012;
|
|
||||||
|
|
||||||
{
|
|
||||||
edit = true;
|
|
||||||
draggable = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void touched(int x, int y){
|
|
||||||
//floor spray
|
|
||||||
if(drawBlock.isFloor()){
|
|
||||||
editorTable.drawCircle(x, y, tile -> {
|
|
||||||
if(Mathf.chance(chance)){
|
|
||||||
tile.setFloor(drawBlock.asFloor());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else if(mode == 0){ //replace-only mode, doesn't affect air
|
|
||||||
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance) && tile.block() != Blocks.air);
|
|
||||||
}else{
|
|
||||||
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance));
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
pencil(KeyCode.b, "replace", "square", "drawteams"){
|
||||||
|
{
|
||||||
|
edit = true;
|
||||||
|
draggable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touched(int x, int y){
|
||||||
|
if(mode == -1){
|
||||||
|
//normal mode
|
||||||
|
editorTable.drawBlocks(x, y);
|
||||||
|
}else if(mode == 0){
|
||||||
|
//replace mode
|
||||||
|
editorTable.drawBlocksReplace(x, y);
|
||||||
|
}else if(mode == 1){
|
||||||
|
//square mode
|
||||||
|
editorTable.drawBlocks(x, y, true, tile -> true);
|
||||||
|
}else if(mode == 2){
|
||||||
|
//draw teams
|
||||||
|
editorTable.drawCircle(x, y, tile -> tile.setTeam(drawTeam));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
eraser(KeyCode.e, "eraseores"){
|
||||||
|
{
|
||||||
|
edit = true;
|
||||||
|
draggable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touched(int x, int y){
|
||||||
|
editorTable.drawCircle(x, y, tile -> {
|
||||||
|
if(mode == -1){
|
||||||
|
//erase block
|
||||||
|
tile.remove();
|
||||||
|
}else if(mode == 0){
|
||||||
|
//erase ore
|
||||||
|
tile.clearOverlay();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fill(KeyCode.g, "replaceall", "fillteams"){
|
||||||
|
{
|
||||||
|
edit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntSeq stack = new IntSeq();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touched(int x, int y){
|
||||||
|
if(!Structs.inBounds(x, y, world.width(), world.height()) || world.tile(x, y).block()!=null&&world.tile(x, y).block().isMultiblock()) return;
|
||||||
|
Tile tile = world.tile(x, y);
|
||||||
|
|
||||||
|
//mode 0 or 1, fill everything with the floor/tile or replace it
|
||||||
|
if(mode == 0 || mode == -1){
|
||||||
|
if(tile.block().isMultiblock()) return;
|
||||||
|
|
||||||
|
Boolf<Tile> tester;
|
||||||
|
Cons<Tile> setter;
|
||||||
|
Block drawBlock = MapEditorWindow.drawBlock;
|
||||||
|
|
||||||
|
if(drawBlock.isOverlay()){
|
||||||
|
Block dest = tile.overlay();
|
||||||
|
if(dest == drawBlock) return;
|
||||||
|
tester = t -> t.overlay() == dest && (t.floor().hasSurface() || !t.floor().needsSurface);
|
||||||
|
setter = t -> t.setOverlay(drawBlock);
|
||||||
|
}else if(drawBlock.isFloor()){
|
||||||
|
Block dest = tile.floor();
|
||||||
|
if(dest == drawBlock) return;
|
||||||
|
tester = t -> t.floor() == dest;
|
||||||
|
setter = t -> t.setFloorUnder(drawBlock.asFloor());
|
||||||
|
}else{
|
||||||
|
Block dest = tile.block();
|
||||||
|
if(dest == drawBlock) return;
|
||||||
|
tester = t -> t.block() == dest;
|
||||||
|
setter = t -> t.setBlock(drawBlock, drawTeam);
|
||||||
|
}
|
||||||
|
|
||||||
|
//replace only when the mode is 0 using the specified functions
|
||||||
|
fill(x, y, mode == 0, tester, setter);
|
||||||
|
}else if(mode == 1){ //mode 1 is team fill
|
||||||
|
//only fill synthetic blocks, it's meaningless otherwise
|
||||||
|
if(tile.synthetic()){
|
||||||
|
Team dest = tile.team();
|
||||||
|
if(dest == drawTeam) return;
|
||||||
|
fill(x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(drawTeam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill(int x, int y, boolean replace, Boolf<Tile> tester, Cons<Tile> filler){
|
||||||
|
int width = world.width(), height = world.height();
|
||||||
|
|
||||||
|
if(replace){
|
||||||
|
//just do it on everything
|
||||||
|
for(int cx = 0; cx < width; cx++){
|
||||||
|
for(int cy = 0; cy < height; cy++){
|
||||||
|
Tile tile = world.tile(cx, cy);
|
||||||
|
if(tester.get(tile)){
|
||||||
|
filler.get(tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//perform flood fill
|
||||||
|
int x1;
|
||||||
|
|
||||||
|
stack.clear();
|
||||||
|
stack.add(Point2.pack(x, y));
|
||||||
|
|
||||||
|
try{
|
||||||
|
while(stack.size > 0 && stack.size < width*height){
|
||||||
|
int popped = stack.pop();
|
||||||
|
x = Point2.x(popped);
|
||||||
|
y = Point2.y(popped);
|
||||||
|
|
||||||
|
x1 = x;
|
||||||
|
while(x1 >= 0 && tester.get(world.tile(x1, y))) x1--;
|
||||||
|
x1++;
|
||||||
|
boolean spanAbove = false, spanBelow = false;
|
||||||
|
while(x1 < width && tester.get(world.tile(x1, y))){
|
||||||
|
filler.get(world.tile(x1, y));
|
||||||
|
|
||||||
|
if(!spanAbove && y > 0 && tester.get(world.tile(x1, y - 1))){
|
||||||
|
stack.add(Point2.pack(x1, y - 1));
|
||||||
|
spanAbove = true;
|
||||||
|
}else if(spanAbove && !tester.get(world.tile(x1, y - 1))){
|
||||||
|
spanAbove = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!spanBelow && y < height - 1 && tester.get(world.tile(x1, y + 1))){
|
||||||
|
stack.add(Point2.pack(x1, y + 1));
|
||||||
|
spanBelow = true;
|
||||||
|
}else if(spanBelow && y < height - 1 && !tester.get(world.tile(x1, y + 1))){
|
||||||
|
spanBelow = false;
|
||||||
|
}
|
||||||
|
x1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stack.clear();
|
||||||
|
}catch(OutOfMemoryError e){
|
||||||
|
//hack
|
||||||
|
stack = null;
|
||||||
|
System.gc();
|
||||||
|
e.printStackTrace();
|
||||||
|
stack = new IntSeq();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spray(KeyCode.r, "replace"){
|
||||||
|
final double chance = 0.012;
|
||||||
|
|
||||||
|
{
|
||||||
|
edit = true;
|
||||||
|
draggable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touched(int x, int y){
|
||||||
|
//floor spray
|
||||||
|
if(drawBlock.isFloor()){
|
||||||
|
editorTable.drawCircle(x, y, tile -> {
|
||||||
|
if(Mathf.chance(chance)){
|
||||||
|
tile.setFloor(drawBlock.asFloor());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else if(mode == 0){ //replace-only mode, doesn't affect air
|
||||||
|
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance) && tile.block() != Blocks.air);
|
||||||
|
}else{
|
||||||
|
editorTable.drawBlocks(x, y, tile -> Mathf.chance(chance));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final EditorTool[] all = values();
|
||||||
|
|
||||||
|
/** All the internal alternate placement modes of this tool. */
|
||||||
|
public final String[] altModes;
|
||||||
|
/** Key to activate this tool. */
|
||||||
|
public KeyCode key = KeyCode.unset;
|
||||||
|
/** The current alternate placement mode. -1 is the standard mode, no changes.*/
|
||||||
|
public int mode = -1;
|
||||||
|
/** Whether this tool causes canvas changes when touched.*/
|
||||||
|
public boolean edit;
|
||||||
|
/** Whether this tool should be dragged across the canvas when the mouse moves.*/
|
||||||
|
public boolean draggable;
|
||||||
|
|
||||||
|
EditorTool(){
|
||||||
|
this(new String[]{});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public static final EditorTool[] all = values();
|
EditorTool(KeyCode code){
|
||||||
|
this(new String[]{});
|
||||||
|
this.key = code;
|
||||||
|
}
|
||||||
|
|
||||||
/** All the internal alternate placement modes of this tool. */
|
EditorTool(String... altModes){
|
||||||
public final String[] altModes;
|
this.altModes = altModes;
|
||||||
/** Key to activate this tool. */
|
}
|
||||||
public KeyCode key = KeyCode.unset;
|
|
||||||
/** The current alternate placement mode. -1 is the standard mode, no changes.*/
|
|
||||||
public int mode = -1;
|
|
||||||
/** Whether this tool causes canvas changes when touched.*/
|
|
||||||
public boolean edit;
|
|
||||||
/** Whether this tool should be dragged across the canvas when the mouse moves.*/
|
|
||||||
public boolean draggable;
|
|
||||||
|
|
||||||
EditorTool(){
|
EditorTool(KeyCode code, String... altModes){
|
||||||
this(new String[]{});
|
this.altModes = altModes;
|
||||||
|
this.key = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void touched(int x, int y){}
|
||||||
|
|
||||||
|
public void touchedLine(int x1, int y1, int x2, int y2){}
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorTool(KeyCode code){
|
|
||||||
this(new String[]{});
|
|
||||||
this.key = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorTool(String... altModes){
|
|
||||||
this.altModes = altModes;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorTool(KeyCode code, String... altModes){
|
|
||||||
this.altModes = altModes;
|
|
||||||
this.key = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void touched(int x, int y){}
|
|
||||||
|
|
||||||
public void touchedLine(int x1, int y1, int x2, int y2){}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.scene.utils.*;
|
import arc.scene.utils.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import mindustry.game.EventType;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.input.*;
|
import mindustry.input.*;
|
||||||
@@ -26,6 +27,20 @@ public class PlayerWindow extends Window {
|
|||||||
|
|
||||||
public PlayerWindow() {
|
public PlayerWindow() {
|
||||||
super(Icon.players, "player");
|
super(Icon.players, "player");
|
||||||
|
only = true;
|
||||||
|
|
||||||
|
Events.run(EventType.Trigger.update, () -> {
|
||||||
|
heat += Time.delta;
|
||||||
|
if(heat >= 60f) {
|
||||||
|
heat = 0f;
|
||||||
|
ScrollPane pane = find("player-pane");
|
||||||
|
pane.setWidget(rebuild());
|
||||||
|
}
|
||||||
|
if(target != null) {
|
||||||
|
if(control.input instanceof DesktopInput desktopInput) desktopInput.panning = true;
|
||||||
|
Core.camera.position.set(target.x, target.y);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,20 +63,6 @@ public class PlayerWindow extends Window {
|
|||||||
table.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("player-pane");
|
table.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("player-pane");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
heat += Time.delta;
|
|
||||||
if(heat >= 60f) {
|
|
||||||
heat = 0f;
|
|
||||||
ScrollPane pane = find("player-pane");
|
|
||||||
pane.setWidget(rebuild());
|
|
||||||
}
|
|
||||||
if(target!=null) {
|
|
||||||
if(control.input instanceof DesktopInput)
|
|
||||||
((DesktopInput) control.input).panning = true;
|
|
||||||
Core.camera.position.set(target.x, target.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Table rebuild(){
|
public Table rebuild(){
|
||||||
return new Table(table -> {
|
return new Table(table -> {
|
||||||
float h = 74f;
|
float h = 74f;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package informatis.ui.windows;
|
package informatis.ui.windows;
|
||||||
|
|
||||||
|
import arc.Events;
|
||||||
import informatis.ui.*;
|
import informatis.ui.*;
|
||||||
import informatis.draws.*;
|
import informatis.draws.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import mindustry.game.EventType;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
@@ -17,6 +19,15 @@ public class ToolWindow extends Window {
|
|||||||
|
|
||||||
public ToolWindow() {
|
public ToolWindow() {
|
||||||
super(Icon.edit, "tool");
|
super(Icon.edit, "tool");
|
||||||
|
only = true;
|
||||||
|
|
||||||
|
Events.run(EventType.Trigger.update, () -> {
|
||||||
|
heat += Time.delta;
|
||||||
|
if(heat >= 60f) {
|
||||||
|
heat = 0f;
|
||||||
|
((ScrollPane) find("tool-pane")).setWidget(rebuild());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,15 +44,6 @@ public class ToolWindow extends Window {
|
|||||||
}).growY();
|
}).growY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
heat += Time.delta;
|
|
||||||
if(heat >= 60f) {
|
|
||||||
heat = 0f;
|
|
||||||
ScrollPane pane = find("tool-pane");
|
|
||||||
pane.setWidget(rebuild());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Table rebuild() {
|
Table rebuild() {
|
||||||
return new Table(icons->{
|
return new Table(icons->{
|
||||||
for(OverDraw draw : OverDraws.all) {
|
for(OverDraw draw : OverDraws.all) {
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ package informatis.ui.windows;
|
|||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.scene.*;
|
import arc.scene.*;
|
||||||
import arc.scene.style.Drawable;
|
import arc.scene.style.*;
|
||||||
import arc.scene.style.TextureRegionDrawable;
|
|
||||||
import informatis.core.*;
|
|
||||||
import informatis.ui.*;
|
import informatis.ui.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
@@ -16,39 +14,27 @@ import arc.struct.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.ctype.UnlockableContent;
|
import mindustry.ctype.*;
|
||||||
import mindustry.entities.Units;
|
import mindustry.entities.Units;
|
||||||
import mindustry.entities.abilities.ShieldRegenFieldAbility;
|
import mindustry.entities.abilities.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.game.EventType;
|
import mindustry.game.EventType;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.logic.LAccess;
|
import mindustry.logic.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.world.blocks.*;
|
import mindustry.world.blocks.*;
|
||||||
import mindustry.world.blocks.defense.ForceProjector;
|
import mindustry.world.blocks.defense.*;
|
||||||
import mindustry.world.blocks.defense.MendProjector;
|
import mindustry.world.blocks.defense.turrets.*;
|
||||||
import mindustry.world.blocks.defense.OverdriveProjector;
|
import mindustry.world.blocks.distribution.*;
|
||||||
import mindustry.world.blocks.defense.turrets.ItemTurret;
|
import mindustry.world.blocks.environment.*;
|
||||||
import mindustry.world.blocks.defense.turrets.LiquidTurret;
|
|
||||||
import mindustry.world.blocks.defense.turrets.PowerTurret;
|
|
||||||
import mindustry.world.blocks.defense.turrets.ReloadTurret;
|
|
||||||
import mindustry.world.blocks.distribution.MassDriver;
|
|
||||||
import mindustry.world.blocks.environment.Floor;
|
|
||||||
import mindustry.world.blocks.payloads.*;
|
import mindustry.world.blocks.payloads.*;
|
||||||
import mindustry.world.blocks.power.PowerGenerator;
|
import mindustry.world.blocks.power.*;
|
||||||
import mindustry.world.blocks.power.PowerNode;
|
import mindustry.world.blocks.production.*;
|
||||||
import mindustry.world.blocks.power.ThermalGenerator;
|
import mindustry.world.blocks.storage.*;
|
||||||
import mindustry.world.blocks.production.AttributeCrafter;
|
import mindustry.world.blocks.units.*;
|
||||||
import mindustry.world.blocks.production.Drill;
|
import mindustry.world.consumers.*;
|
||||||
import mindustry.world.blocks.production.GenericCrafter;
|
|
||||||
import mindustry.world.blocks.production.SolidPump;
|
|
||||||
import mindustry.world.blocks.storage.CoreBlock;
|
|
||||||
import mindustry.world.blocks.storage.StorageBlock;
|
|
||||||
import mindustry.world.blocks.units.Reconstructor;
|
|
||||||
import mindustry.world.blocks.units.UnitFactory;
|
|
||||||
import mindustry.world.consumers.ConsumePower;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -67,14 +53,17 @@ public class UnitWindow extends Window {
|
|||||||
float lastWidth;
|
float lastWidth;
|
||||||
final Seq<Color> lastColors = new Seq<>();
|
final Seq<Color> lastColors = new Seq<>();
|
||||||
final Bits statuses = new Bits();
|
final Bits statuses = new Bits();
|
||||||
Teamc lastTarget;
|
public Teamc lastTarget, target;
|
||||||
|
public boolean locked;
|
||||||
|
Seq<BarInfo.BarData> data = new Seq<>();
|
||||||
|
|
||||||
public UnitWindow() {
|
public UnitWindow() {
|
||||||
super(Icon.units, "unit");
|
super(Icon.units, "unit");
|
||||||
|
|
||||||
Events.run(EventType.Trigger.update, () -> {
|
Events.run(EventType.Trigger.update, () -> {
|
||||||
|
if(!locked) target = getTarget();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BarInfo.getInfo(getTarget());
|
data = BarInfo.getInfo(target);
|
||||||
} catch (IllegalAccessException | NoSuchFieldException err) {
|
} catch (IllegalAccessException | NoSuchFieldException err) {
|
||||||
err.printStackTrace();
|
err.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -89,7 +78,7 @@ public class UnitWindow extends Window {
|
|||||||
public void draw() {
|
public void draw() {
|
||||||
super.draw();
|
super.draw();
|
||||||
|
|
||||||
Draw.color(locked? Pal.accent:Pal.gray);
|
Draw.color(locked ? Pal.accent : Pal.gray);
|
||||||
Draw.alpha(parentAlpha);
|
Draw.alpha(parentAlpha);
|
||||||
Lines.stroke(Scl.scl(3f));
|
Lines.stroke(Scl.scl(3f));
|
||||||
Lines.rect(x-size/2f, y-size/2f, width+size, height+size);
|
Lines.rect(x-size/2f, y-size/2f, width+size, height+size);
|
||||||
@@ -105,10 +94,7 @@ public class UnitWindow extends Window {
|
|||||||
}
|
}
|
||||||
profileImage.setDrawable(region);
|
profileImage.setDrawable(region);
|
||||||
});
|
});
|
||||||
profileImage.clicked(() -> {
|
profileImage.clicked(() -> locked = !locked);
|
||||||
if (target == getTarget()) locked = !locked;
|
|
||||||
target = getTarget();
|
|
||||||
});
|
|
||||||
Label profileLabel = new Label(() -> {
|
Label profileLabel = new Label(() -> {
|
||||||
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
|
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
|
||||||
if (target instanceof Building b && b.block != null) {
|
if (target instanceof Building b && b.block != null) {
|
||||||
@@ -124,7 +110,7 @@ public class UnitWindow extends Window {
|
|||||||
if (lastTarget != target) {
|
if (lastTarget != target) {
|
||||||
lastTarget = target;
|
lastTarget = target;
|
||||||
for (int i = 0; i < barSize; i++) {
|
for (int i = 0; i < barSize; i++) {
|
||||||
Color color = i >= BarInfo.data.size ? Color.clear : BarInfo.data.get(i).color;
|
Color color = i >= data.size ? Color.clear : data.get(i).color;
|
||||||
if (i >= lastColors.size) lastColors.add(color);
|
if (i >= lastColors.size) lastColors.add(color);
|
||||||
else lastColors.set(i, color);
|
else lastColors.set(i, color);
|
||||||
}
|
}
|
||||||
@@ -161,7 +147,7 @@ public class UnitWindow extends Window {
|
|||||||
).margin(3f).growX().row();
|
).margin(3f).growX().row();
|
||||||
table.table().update(tt -> {
|
table.table().update(tt -> {
|
||||||
tt.clear();
|
tt.clear();
|
||||||
if(getTarget() instanceof Unit u && u.type != null && u.hasWeapons()) {
|
if(target instanceof Unit u && u.type != null && u.hasWeapons()) {
|
||||||
for(int r = 0; r < u.type.weapons.size; r++){
|
for(int r = 0; r < u.type.weapons.size; r++){
|
||||||
Weapon weapon = u.type.weapons.get(r);
|
Weapon weapon = u.type.weapons.get(r);
|
||||||
WeaponMount mount = u.mounts[r];
|
WeaponMount mount = u.mounts[r];
|
||||||
@@ -266,45 +252,43 @@ public class UnitWindow extends Window {
|
|||||||
Table addBar(int index) {
|
Table addBar(int index) {
|
||||||
return new Table(bar -> {
|
return new Table(bar -> {
|
||||||
bar.add(new SBar(
|
bar.add(new SBar(
|
||||||
() -> index >= BarInfo.data.size ? "[lightgray]<Empty>[]" : BarInfo.data.get(index).name,
|
() -> index >= data.size ? "[lightgray]<Empty>[]" : data.get(index).name,
|
||||||
() -> index >= BarInfo.data.size ? Color.clear : BarInfo.data.get(index).color,
|
() -> index >= data.size ? Color.clear : data.get(index).color,
|
||||||
() -> lastColors.get(index),
|
() -> lastColors.get(index),
|
||||||
() -> index >= BarInfo.data.size ? 0 : BarInfo.data.get(index).number)
|
() -> index >= data.size ? 0 : data.get(index).number)
|
||||||
).height(4 * 8f).growX();
|
).height(4 * 8f).growX();
|
||||||
if(index >= BarInfo.data.size) return;
|
if(index >= data.size) return;
|
||||||
Image icon = new Image(){
|
Image icon = new Image(){
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
validate();
|
validate();
|
||||||
if(index >= BarInfo.data.size) return;
|
if(index >= data.size) return;
|
||||||
float x = this.x + imageX;
|
float x = this.x + imageX;
|
||||||
float y = this.y + imageY;
|
float y = this.y + imageY;
|
||||||
float width = imageWidth * this.scaleX;
|
float width = imageWidth * this.scaleX;
|
||||||
float height = imageHeight * this.scaleY;
|
float height = imageHeight * this.scaleY;
|
||||||
Draw.color(Color.white);
|
Draw.color(Color.white);
|
||||||
Draw.alpha(parentAlpha * color.a);
|
Draw.alpha(parentAlpha * color.a);
|
||||||
BarInfo.BarData data = BarInfo.data.get(index);
|
BarInfo.BarData da = data.get(index);
|
||||||
if(hasMouse()) getDrawable().draw(x, y, width, height);
|
if(hasMouse()) getDrawable().draw(x, y, width, height);
|
||||||
else {
|
else {
|
||||||
data.icon.draw(x, y, width, height);
|
da.icon.draw(x, y, width, height);
|
||||||
if(ScissorStack.push(Tmp.r1.set(ScissorStack.peek().x + x, ScissorStack.peek().y + y, width, height * data.number))) {
|
if(ScissorStack.push(Tmp.r1.set(ScissorStack.peek().x + x, ScissorStack.peek().y + y, width, height * da.number))) {
|
||||||
Draw.color(data.color);
|
Draw.color(da.color);
|
||||||
data.icon.draw(x, y, width, height);
|
da.icon.draw(x, y, width, height);
|
||||||
ScissorStack.pop();
|
ScissorStack.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
icon.setDrawable(BarInfo.data.get(index).icon);
|
icon.setDrawable(data.get(index).icon);
|
||||||
bar.add(icon).size(iconMed * 0.75f).padLeft(8f);
|
bar.add(icon).size(iconMed * 0.75f).padLeft(8f);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class BarInfo {
|
class BarInfo {
|
||||||
public static Seq<BarData> data = new Seq<>();
|
public static <T extends Teamc> Seq<BarData> getInfo(T target) throws IllegalAccessException, NoSuchFieldException {
|
||||||
|
Seq<BarData> data = new Seq<>();
|
||||||
public static <T extends Teamc> void getInfo(T target) throws IllegalAccessException, NoSuchFieldException {
|
|
||||||
data.clear();
|
|
||||||
|
|
||||||
if(target instanceof Healthc healthc){
|
if(target instanceof Healthc healthc){
|
||||||
data.add(new BarData(bundle.format("shar-stat.health", formatNumber(healthc.health())), Pal.health, healthc.healthf(), health));
|
data.add(new BarData(bundle.format("shar-stat.health", formatNumber(healthc.health())), Pal.health, healthc.healthf(), health));
|
||||||
@@ -473,6 +457,8 @@ class BarInfo {
|
|||||||
|
|
||||||
data.add(new BarData(bundle.format("shar-stat.attr", Mathf.round(display)), Pal.ammo, pro));
|
data.add(new BarData(bundle.format("shar-stat.attr", Mathf.round(display)), Pal.ammo, pro));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class BarData {
|
static class BarData {
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ public class WaveWindow extends Window {
|
|||||||
super(Icon.waves, "wave");
|
super(Icon.waves, "wave");
|
||||||
height = 500;
|
height = 500;
|
||||||
width = 450;
|
width = 450;
|
||||||
|
only = true;
|
||||||
|
|
||||||
|
Events.run(EventType.Trigger.update, () -> {
|
||||||
|
heat += Time.delta;
|
||||||
|
if(heat >= 60f) {
|
||||||
|
heat = 0f;
|
||||||
|
((ScrollPane) find("wave-pane")).setWidget(rebuild());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,15 +102,6 @@ public class WaveWindow extends Window {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
heat += Time.delta;
|
|
||||||
if(heat >= 60f) {
|
|
||||||
heat = 0f;
|
|
||||||
ScrollPane pane = find("wave-pane");
|
|
||||||
pane.setWidget(rebuild());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectIntMap<SpawnGroup> getWaveGroup(int index) {
|
public ObjectIntMap<SpawnGroup> getWaveGroup(int index) {
|
||||||
ObjectIntMap<SpawnGroup> groups = new ObjectIntMap<>();
|
ObjectIntMap<SpawnGroup> groups = new ObjectIntMap<>();
|
||||||
for (SpawnGroup group : state.rules.spawns) {
|
for (SpawnGroup group : state.rules.spawns) {
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import informatis.ui.*;
|
|
||||||
|
|
||||||
public class Window extends Table {
|
public class Window extends Table {
|
||||||
public TextureRegionDrawable icon;
|
public TextureRegionDrawable icon;
|
||||||
public int id;
|
|
||||||
public Cons<Table> content;
|
public Cons<Table> content;
|
||||||
public boolean shown = false;
|
public boolean shown = false, only = false;
|
||||||
public Table window;
|
public Table window;
|
||||||
|
|
||||||
public float minWindowWidth = 160, minWindowHeight = 60;
|
public float minWindowWidth = 160, minWindowHeight = 60;
|
||||||
@@ -33,7 +31,7 @@ public class Window extends Table {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
window = this;
|
window = this;
|
||||||
id = WindowManager.register(this);
|
WindowManager.register(this);
|
||||||
|
|
||||||
titleBar();
|
titleBar();
|
||||||
row();
|
row();
|
||||||
@@ -74,7 +72,10 @@ public class Window extends Table {
|
|||||||
b.image(icon.getRegion()).size(20f).padLeft(15);
|
b.image(icon.getRegion()).size(20f).padLeft(15);
|
||||||
b.add(Core.bundle.get("window."+name+".name")).padLeft(20);
|
b.add(Core.bundle.get("window."+name+".name")).padLeft(20);
|
||||||
}).touchable(Touchable.disabled).grow();
|
}).touchable(Touchable.disabled).grow();
|
||||||
t.table(Tex.buttonEdge3, b -> b.button(Icon.cancel, Styles.emptyi, () -> shown = false).fill()).width(80f).growY();
|
t.table(Tex.buttonEdge3, b -> b.button(Icon.cancel, Styles.emptyi, () -> {
|
||||||
|
shown = false;
|
||||||
|
if(!only) WindowManager.windows.get(getClass()).remove(this);
|
||||||
|
}).fill()).width(80f).growY();
|
||||||
|
|
||||||
// handles the dragging.
|
// handles the dragging.
|
||||||
t.touchable = Touchable.enabled;
|
t.touchable = Touchable.enabled;
|
||||||
|
|||||||
77
src/informatis/ui/windows/WindowManager.java
Normal file
77
src/informatis/ui/windows/WindowManager.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package informatis.ui.windows;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
|
import arc.scene.ui.layout.Table;
|
||||||
|
import arc.struct.*;
|
||||||
|
import mindustry.*;
|
||||||
|
import mindustry.graphics.Pal;
|
||||||
|
import mindustry.ui.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
public class WindowManager {
|
||||||
|
public static ObjectMap<Class<? extends Window>, Seq<Window>> windows = new ObjectMap<>();
|
||||||
|
|
||||||
|
public static void init(){
|
||||||
|
Vars.ui.hudGroup.fill(t -> {
|
||||||
|
t.name = "Windows";
|
||||||
|
|
||||||
|
for(Seq<Window> windows : windows.values()){
|
||||||
|
for(Window window : windows) {
|
||||||
|
t.add(window).height(window.getHeight()).width(window.getWidth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Vars.ui.hudGroup.fill(t -> {
|
||||||
|
t.name = "window sidebar";
|
||||||
|
t.center().left();
|
||||||
|
t.table(Core.atlas.drawable("informatis-sidebar"), b -> {
|
||||||
|
b.name = "Window Buttons";
|
||||||
|
b.left();
|
||||||
|
|
||||||
|
for(ObjectMap.Entry<Class<? extends Window>, Seq<Window>> windows : windows){
|
||||||
|
Class<? extends Window> key = windows.key;
|
||||||
|
Seq<Window> value = windows.value;
|
||||||
|
Window window = value.peek();
|
||||||
|
b.stack(
|
||||||
|
new Table(bt -> {
|
||||||
|
bt.button(window.icon, Styles.emptyi, () -> {
|
||||||
|
Window window1 = window;
|
||||||
|
window1.parent.setLayoutEnabled(false);
|
||||||
|
if(!window.only) {
|
||||||
|
try {
|
||||||
|
window1 = key.getConstructor().newInstance();
|
||||||
|
window1.setPosition(value.peek().x + 50, value.peek().y + 50);
|
||||||
|
window1.sizeBy(200, 200);
|
||||||
|
} catch (InstantiationException | IllegalAccessException |
|
||||||
|
InvocationTargetException | NoSuchMethodException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window1.toggle();
|
||||||
|
for (Seq<Window> ws : WindowManager.windows.values()) {
|
||||||
|
ws.each(w -> w.setLayoutEnabled(true));
|
||||||
|
}
|
||||||
|
}).size(40f).tooltip(tt -> {
|
||||||
|
tt.setBackground(Styles.black6);
|
||||||
|
tt.label(() -> Core.bundle.get("window."+window.name+".name")).pad(2f);
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
new Table(bt -> {
|
||||||
|
bt.right().bottom();
|
||||||
|
if(!window.only) bt.label(() -> String.valueOf(value.size)).get().setColor(Pal.accent);
|
||||||
|
})
|
||||||
|
).row();
|
||||||
|
}
|
||||||
|
}).left();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register(Window window){
|
||||||
|
Table table = Vars.ui.hudGroup.find("Windows");
|
||||||
|
if(table != null) table.add(window).height(window.getHeight()).width(window.getWidth());
|
||||||
|
if(!windows.containsKey(window.getClass())) windows.put(window.getClass(), Seq.with(window));
|
||||||
|
else windows.get(window.getClass()).add(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user