mirror of
https://github.com/yawaflua/Informatis.git
synced 2026-02-05 02:44:15 +02:00
rename package
This commit is contained in:
206
src/informatis/ui/window/CoreWindow.java
Normal file
206
src/informatis/ui/window/CoreWindow.java
Normal file
@@ -0,0 +1,206 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import arc.Events;
|
||||
import mindustry.game.EventType;
|
||||
import informatis.ui.*;
|
||||
import arc.Core;
|
||||
import arc.graphics.Color;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.scene.event.HandCursorListener;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.struct.Seq;
|
||||
import arc.util.*;
|
||||
import mindustry.Vars;
|
||||
import mindustry.content.UnitTypes;
|
||||
import mindustry.core.UI;
|
||||
import mindustry.game.Team;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.input.DesktopInput;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.Styles;
|
||||
import mindustry.world.blocks.storage.CoreBlock;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class CoreWindow extends Window implements Updatable {
|
||||
Vec2 scrollPos = new Vec2(0, 0);
|
||||
Table window;
|
||||
float heat;
|
||||
ObjectMap<Team, ItemData> itemData = new ObjectMap<>();
|
||||
|
||||
public CoreWindow() {
|
||||
super(Icon.list, "core");
|
||||
resetUsed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Table table) {
|
||||
window = table;
|
||||
scrollPos = new Vec2(0, 0);
|
||||
|
||||
table.background(Styles.black8).top();
|
||||
table.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("core-pane");
|
||||
Events.on(EventType.WorldLoadEvent.class, e -> resetUsed());
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
return new Table(table -> {
|
||||
table.top();
|
||||
for(Team team : getTeams()) {
|
||||
table.table(row-> {
|
||||
row.center();
|
||||
row.add(setTable(team)).margin(8f).row();
|
||||
row.image().height(4f).color(team.color).growX();
|
||||
}).growX().row();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Seq<Team> getTeams(){
|
||||
return Seq.with(Team.all).filter(Team::active);
|
||||
}
|
||||
|
||||
public void resetUsed(){
|
||||
for(Team team : getTeams()) {
|
||||
itemData.put(team, new ItemData());
|
||||
}
|
||||
}
|
||||
|
||||
public Table setTable(Team team){
|
||||
return new Table(table -> {
|
||||
table.add(team.name).color(team.color).row();
|
||||
int max = Math.max(1, Math.round(window.getWidth()/2/60));
|
||||
table.table(coretable -> {
|
||||
int row = 0;
|
||||
|
||||
for(CoreBlock.CoreBuild core : team.cores()) {
|
||||
coretable.table(tt -> {
|
||||
tt.stack(
|
||||
new Table(s -> {
|
||||
s.center();
|
||||
Image image = new Image(core.block.uiIcon);
|
||||
image.clicked(() -> {
|
||||
if(control.input instanceof DesktopInput)
|
||||
((DesktopInput) control.input).panning = true;
|
||||
Core.camera.position.set(core.x, core.y);
|
||||
});
|
||||
HandCursorListener listener1 = new HandCursorListener();
|
||||
image.addListener(listener1);
|
||||
image.update(() -> {
|
||||
image.color.lerp(!listener1.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
|
||||
});
|
||||
Tooltip.Tooltips option = new Tooltip.Tooltips();
|
||||
option.animations=false;
|
||||
s.add(image).size(iconLarge).get().addListener(new Tooltip(tool -> {
|
||||
tool.background(Styles.black6).label(() -> "([#" + Tmp.c1.set(Color.green).lerp(Color.red, 1 - core.healthf()).toString() + "]" + Strings.fixed(core.health, 2) + "[]/" + Strings.fixed(core.block.health, 2) + ")");
|
||||
}, option));
|
||||
}),
|
||||
new Table(h -> {
|
||||
h.bottom().defaults().height(9f).width(iconLarge * 1.5f).growX();
|
||||
h.add(new SBar(() -> "", () -> Pal.health, () -> core.health / core.block.health).rect().init());
|
||||
h.pack();
|
||||
})
|
||||
).row();
|
||||
Label label = new Label(Strings.format("(@, @)",core.tileX(), core.tileY()));
|
||||
label.setFontScale(0.75f);
|
||||
tt.add(label);
|
||||
}).padTop(2).padLeft(4).padRight(4);
|
||||
if(row++ % max == max-1){
|
||||
coretable.row();
|
||||
}
|
||||
}
|
||||
}).row();
|
||||
|
||||
table.table(itemTable -> {
|
||||
int row = 0;
|
||||
|
||||
CoreBlock.CoreBuild core = team.core();
|
||||
for(int i = 0; i < Vars.content.items().size; i++){
|
||||
Item item = Vars.content.item(i);
|
||||
if(!team.items().has(item)) return;
|
||||
itemTable.stack(
|
||||
new Table(ttt -> {
|
||||
ttt.image(item.uiIcon).size(iconSmall).tooltip(tttt -> tttt.background(Styles.black6).add(item.localizedName).style(Styles.outlineLabel).margin(2f));
|
||||
ttt.add(UI.formatAmount(core.items.get(item))).minWidth(5 * 8f).left();
|
||||
}),
|
||||
new Table(ttt -> {
|
||||
ttt.bottom().right();
|
||||
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.setFontScale(0.65f);
|
||||
label.setColor(amount > 0 ? Color.green : amount == 0 ? Color.orange : Color.red);
|
||||
ttt.add(label).bottom().right().padTop(16f);
|
||||
ttt.pack();
|
||||
})).padRight(3).left();
|
||||
if(row++ % max == max-1){
|
||||
itemTable.row();
|
||||
}
|
||||
}
|
||||
}).row();
|
||||
|
||||
table.table(unitTable -> {
|
||||
int row = 0;
|
||||
|
||||
for(UnitType unit : Vars.content.units()){
|
||||
if(unit != UnitTypes.block && Groups.unit.contains(u -> u.type == unit && u.team == team)){
|
||||
unitTable.table(tt -> {
|
||||
tt.center();
|
||||
tt.image(unit.uiIcon).size(iconSmall).padRight(3).tooltip(ttt -> ttt.background(Styles.black6).add(unit.localizedName).style(Styles.outlineLabel).margin(2f));
|
||||
tt.add(UI.formatAmount(Groups.unit.count(u -> u.team == team && u.type == unit))).padRight(3).minWidth(5 * 8f).left();
|
||||
});
|
||||
if(row++ % max == max-1){
|
||||
unitTable.row();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static class ItemData {
|
||||
Seq<ItemStack> prevItems = new Seq<>();
|
||||
Seq<ItemStack> updateItems = new Seq<>();
|
||||
|
||||
ItemData() {
|
||||
resetItems();
|
||||
}
|
||||
|
||||
public void resetItems(){
|
||||
Seq<ItemStack> stacks = Vars.content.items().map(item -> new ItemStack(item, 0));
|
||||
updateItems.clear().addAll(stacks);
|
||||
prevItems.clear().addAll(stacks);
|
||||
}
|
||||
|
||||
public void updateItems(Team team){
|
||||
CoreBlock.CoreBuild core = team.core();
|
||||
if (core != null) {
|
||||
Seq<ItemStack> stack = updateItems;
|
||||
if(stack.isEmpty()) Vars.content.items().each(i -> stack.add(new ItemStack(i, 0)));
|
||||
for (Item item : Vars.content.items()) {
|
||||
stack.get(item.id).set(item, core.items.get(item) - (prevItems != null ? prevItems.get(item.id).amount : 0));
|
||||
if (prevItems != null) prevItems.get(item.id).set(item, core.items.get(item));
|
||||
}
|
||||
|
||||
if(prevItems != null) prevItems.clear().addAll(Vars.content.items().map(i -> new ItemStack(i, core.items.get(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
473
src/informatis/ui/window/MapEditorWindow.java
Normal file
473
src/informatis/ui/window/MapEditorWindow.java
Normal file
@@ -0,0 +1,473 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import arc.Events;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.geom.Geometry;
|
||||
import arc.scene.Element;
|
||||
import arc.scene.style.Drawable;
|
||||
import arc.struct.ObjectMap;
|
||||
import mindustry.editor.MapEditor;
|
||||
import mindustry.game.EventType;
|
||||
import mindustry.graphics.Layer;
|
||||
import informatis.core.EditorTool;
|
||||
import informatis.ui.*;
|
||||
import arc.Core;
|
||||
import arc.func.*;
|
||||
import arc.graphics.Color;
|
||||
import arc.input.KeyCode;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.scene.event.Touchable;
|
||||
import arc.scene.style.TextureRegionDrawable;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.scene.utils.Elem;
|
||||
import arc.struct.Seq;
|
||||
import arc.util.*;
|
||||
import mindustry.Vars;
|
||||
import mindustry.content.Blocks;
|
||||
import mindustry.game.Team;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.ui.Styles;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class MapEditorWindow extends Window implements Updatable {
|
||||
Vec2 scrollPos = new Vec2(0, 0);
|
||||
Table window;
|
||||
TextField search;
|
||||
EditorTool tool;
|
||||
final Vec2[][] brushPolygons = new Vec2[MapEditor.brushSizes.length][0];
|
||||
float heat;
|
||||
float brushSize = -1;
|
||||
|
||||
boolean drawing;
|
||||
int lastx, lasty;
|
||||
float lastw, lasth;
|
||||
|
||||
public static Team drawTeam = Team.sharded;
|
||||
public static Block drawBlock = Blocks.router;
|
||||
|
||||
public MapEditorWindow() {
|
||||
super(Icon.map, "editor");
|
||||
|
||||
for(int i = 0; i < MapEditor.brushSizes.length; i++){
|
||||
float size = MapEditor.brushSizes[i];
|
||||
float mod = size % 1f;
|
||||
brushPolygons[i] = Geometry.pixelCircle(size, (index, x, y) -> Mathf.dst(x, y, index - mod, index - mod) <= size - 0.5f);
|
||||
}
|
||||
|
||||
Events.run(EventType.Trigger.draw, ()->{
|
||||
float cx = Core.camera.position.x, cy = Core.camera.position.y;
|
||||
float scaling = 8;
|
||||
|
||||
Draw.z(Layer.max);
|
||||
|
||||
if(Core.settings.getBool("grid")){
|
||||
Lines.stroke(1f);
|
||||
Draw.color(Pal.accent);
|
||||
for(int i = (int)(-0.5f*Core.camera.height/8); i < (int)(0.5f*Core.camera.height/8); i++) {
|
||||
Lines.line(Mathf.floor((cx-0.5f*Core.camera.width)/8)*8+4, Mathf.floor((cy + i*8)/8)*8+4, Mathf.floor((cx+0.5f*Core.camera.width)/8)*8+4,Mathf.floor((cy + i*8)/8)*8+4);
|
||||
}
|
||||
for(int i = (int)(-0.5f*Core.camera.width/8); i < (int)(0.5f*Core.camera.width/8); i++) {
|
||||
Lines.line(Mathf.floor((cx + i*8)/8)*8+4, Mathf.floor((cy+0.5f*Core.camera.height)/8)*8+4, Mathf.floor((cx + i*8)/8)*8+4,Mathf.floor((cy-0.5f*Core.camera.height)/8)*8+4);
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
|
||||
if(tile == null || tool == null || brushSize < 1) return;
|
||||
|
||||
int index = 0;
|
||||
for(int i = 0; i < MapEditor.brushSizes.length; i++){
|
||||
if(brushSize == MapEditor.brushSizes[i]){
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Lines.stroke(Scl.scl(2f), Pal.accent);
|
||||
|
||||
if((!drawBlock.isMultiblock() || tool == EditorTool.eraser) && tool != EditorTool.fill){
|
||||
if(tool == EditorTool.line && drawing){
|
||||
Lines.poly(brushPolygons[index], lastx, lasty, scaling);
|
||||
Lines.poly(brushPolygons[index], tile.x*8, tile.y*8, scaling);
|
||||
}
|
||||
|
||||
if((tool.edit || (tool == EditorTool.line && !drawing)) && (!mobile || drawing)){
|
||||
if(tool == EditorTool.pencil && tool.mode == 1){
|
||||
Lines.square(tile.x*8, tile.y*8, scaling * (brushSize + 0.5f));
|
||||
}else{
|
||||
Lines.poly(brushPolygons[index], tile.x*8-4, tile.y*8-4, scaling);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if((tool.edit || tool == EditorTool.line) && (!mobile || drawing)){
|
||||
float offset = (drawBlock.size % 2 == 0 ? scaling / 2f : 0f);
|
||||
Lines.square(
|
||||
tile.x*8 + scaling / 2f + offset,
|
||||
tile.y*8 + scaling / 2f + offset,
|
||||
scaling * drawBlock.size / 2f);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Table table) {
|
||||
scrollPos = new Vec2(0, 0);
|
||||
search = Elem.newField(null, f->{});
|
||||
search.setMessageText(Core.bundle.get("players.search")+"...");
|
||||
window = table;
|
||||
|
||||
table.left();
|
||||
table.top().background(Styles.black8);
|
||||
|
||||
ObjectMap<Drawable, Element> displays = new ObjectMap<>();
|
||||
displays.put(Icon.map, new Table(display -> {
|
||||
display.table(t->{
|
||||
t.left().background(Tex.underline2);
|
||||
t.label(()-> drawBlock == null ? "[gray]None[]" : "[accent]" + drawBlock.localizedName + "[] "+ drawBlock.emoji());
|
||||
t.add(search).growX().pad(8).name("search");
|
||||
}).growX().row();
|
||||
display.add(new OverScrollPane(rebuildEditor(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("editor-pane").row();
|
||||
}));
|
||||
displays.put(Icon.settings, new Table(display -> {
|
||||
display.add(new OverScrollPane(rebuildRule(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("rule-pane").row();
|
||||
}));
|
||||
|
||||
table.table(buttons -> {
|
||||
buttons.top().left();
|
||||
|
||||
displays.each((icon, display) -> {
|
||||
buttons.button(icon, Styles.clearTogglei, ()->{
|
||||
Log.info(table.getChildren().get(table.getChildren().size-1));
|
||||
if(table.getChildren().size > 1) table.getChildren().get(table.getChildren().size-1).remove();
|
||||
table.add(display).grow();
|
||||
}).row();
|
||||
});
|
||||
}).growY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
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() {
|
||||
ScrollPane pane = find("editor-pane");
|
||||
if(pane != null) pane.setWidget(rebuildEditor());
|
||||
}
|
||||
|
||||
Table rebuildRule() {
|
||||
return new Table(table -> {
|
||||
table.top().left();
|
||||
|
||||
table.table(rules -> {
|
||||
rules.top().left();
|
||||
|
||||
Label label = rules.add("Block Health: ").get();
|
||||
Slider slider = new Slider(0, 100, 1, false);
|
||||
slider.changed(() -> {
|
||||
label.setText("Block Health: "+(int)slider.getValue()+"%");
|
||||
});
|
||||
slider.change();
|
||||
slider.moved(hp->Groups.build.each(b->b.health(b.block.health*hp/100)));
|
||||
rules.add(slider);
|
||||
}).grow();
|
||||
});
|
||||
}
|
||||
|
||||
Table rebuildEditor() {
|
||||
return new Table(table-> {
|
||||
table.top();
|
||||
Seq<Block> blocks = Vars.content.blocks().copy();
|
||||
if(search.getText().length() > 0){
|
||||
blocks.filter(p -> p.name.toLowerCase().contains(search.getText().toLowerCase())||p.localizedName.toLowerCase().contains(search.getText().toLowerCase()));
|
||||
}
|
||||
table.table(select-> this.buildBlockSelection(null, select, blocks, ()-> drawBlock, block-> drawBlock =block, false)).marginTop(16f).marginBottom(16f).row();
|
||||
table.image().height(4f).color(Pal.gray).growX().row();
|
||||
table.table(select-> this.buildTeamSelection(player.team(), select, Seq.with(Team.all), ()->drawTeam, block->drawTeam=block, false)).marginTop(16f).marginBottom(16f).row();
|
||||
table.image().height(4f).color(Pal.gray).growX().row();
|
||||
table.table(body-> {
|
||||
body.table(tools -> {
|
||||
tools.top().left();
|
||||
tools.table(title -> title.left().background(Tex.underline2).add("Tools [accent]"+(tool==null?"":tool.name())+"[]")).growX().row();
|
||||
tools.table(bt->{
|
||||
Cons<EditorTool> addTool = tool -> {
|
||||
ImageButton button = new ImageButton(ui.getIcon(tool.name()), Styles.clearTogglei);
|
||||
button.clicked(() -> {
|
||||
button.toggle();
|
||||
if(this.tool==tool) this.tool = null;
|
||||
else this.tool = tool;
|
||||
resetPane();
|
||||
});
|
||||
button.update(()->button.setChecked(this.tool == tool));
|
||||
|
||||
Label mode = new Label("");
|
||||
mode.setColor(Pal.remove);
|
||||
mode.update(() -> mode.setText(tool.mode == -1 ? "" : "M" + (tool.mode + 1) + " "));
|
||||
mode.setAlignment(Align.bottomRight, Align.bottomRight);
|
||||
mode.touchable = Touchable.disabled;
|
||||
|
||||
bt.stack(button, mode);
|
||||
};
|
||||
|
||||
addTool.get(EditorTool.line);
|
||||
addTool.get(EditorTool.pencil);
|
||||
addTool.get(EditorTool.eraser);
|
||||
addTool.get(EditorTool.fill);
|
||||
addTool.get(EditorTool.spray);
|
||||
|
||||
ImageButton grid = new ImageButton(Icon.grid, Styles.clearTogglei);
|
||||
grid.clicked(() -> {
|
||||
grid.toggle();
|
||||
Core.settings.put("grid", !Core.settings.getBool("grid"));
|
||||
});
|
||||
grid.update(()->grid.setChecked(Core.settings.getBool("grid")));
|
||||
bt.add(grid);
|
||||
});
|
||||
tools.row();
|
||||
Slider slider = new Slider(0, MapEditor.brushSizes.length - 1, 1, false);
|
||||
slider.moved(f -> brushSize = MapEditor.brushSizes[(int)f]);
|
||||
for(int j = 0; j < MapEditor.brushSizes.length; j++){
|
||||
if(MapEditor.brushSizes[j] == brushSize){
|
||||
slider.setValue(j);
|
||||
}
|
||||
}
|
||||
Label label = new Label("Brush: "+brushSize);
|
||||
label.touchable = Touchable.disabled;
|
||||
tools.stack(slider, label).width(getDisplayWidth()/5).center();
|
||||
}).left().width(getDisplayWidth() / 2).margin(8f).growY();
|
||||
body.image().width(4f).height(body.getHeight()).color(Pal.gray).growY();
|
||||
body.table(options -> {
|
||||
options.top().left();
|
||||
options.table(title -> title.left().background(Tex.underline2).add("Options [accent]"+(tool!=null&&tool.mode>=0&&tool.mode<tool.altModes.length?tool.altModes[tool.mode]:"")+"[]")).growX().row();
|
||||
options.table(option-> {
|
||||
if(tool==null) return;
|
||||
|
||||
option.top().left();
|
||||
for (int i = 0; i < tool.altModes.length; i++) {
|
||||
int mode = i;
|
||||
String name = tool.altModes[i];
|
||||
|
||||
option.button(b -> {
|
||||
b.left().marginLeft(6);
|
||||
b.setStyle(Styles.clearTogglei);
|
||||
b.add(Core.bundle.get("toolmode." + name)).left().row();
|
||||
b.add(Core.bundle.get("toolmode." + name + ".description")).color(Color.lightGray).left();
|
||||
}, () -> tool.mode = (tool.mode == mode ? -1 : mode)).update(b -> b.setChecked(tool.mode == mode)).margin(12f).growX().row();
|
||||
}
|
||||
}).grow();
|
||||
}).left().width(getDisplayWidth() / 2).margin(8f).growY();
|
||||
}).grow();
|
||||
});
|
||||
}
|
||||
|
||||
<T extends Block> void buildBlockSelection(@Nullable Block block, Table table, Seq<T> items, Prov<T> holder, Cons<T> consumer, boolean closeSelect){
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(40);
|
||||
|
||||
int i = 0;
|
||||
int row = 4;
|
||||
int max = Math.max(row, Math.round(getDisplayWidth()/2/8/row));
|
||||
|
||||
for(T item : items){
|
||||
if(!item.unlockedNow()) continue;
|
||||
|
||||
ImageButton button = cont.button(Tex.whiteui, Styles.clearTogglei, 24, () -> {
|
||||
if(closeSelect) control.input.config.hideConfig();
|
||||
}).group(group).tooltip(t->t.background(Styles.black8).add(item.localizedName.replace(search.getText(), "[accent]"+search.getText()+"[]"))).get();
|
||||
button.changed(() -> consumer.get(button.isChecked() ? item : null));
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(item.uiIcon);
|
||||
button.update(() -> button.setChecked(holder.get() == item));
|
||||
|
||||
if(i++ % max == max-1){
|
||||
cont.row();
|
||||
}
|
||||
}
|
||||
|
||||
//add extra blank spaces so it looks nice
|
||||
if(i % max != 0){
|
||||
int remaining = max - (i % max);
|
||||
for(int j = 0; j < remaining; j++){
|
||||
cont.image(Styles.black6);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setScrollYForce(blockScroll);
|
||||
pane.update(() -> blockScroll = pane.getScrollY());
|
||||
pane.setOverscroll(false, false);
|
||||
table.add(pane).maxHeight(Scl.scl(row * 10 * 5));
|
||||
}
|
||||
float blockScroll;
|
||||
|
||||
<T extends Team> void buildTeamSelection(@Nullable Team team, Table table, Seq<T> items, Prov<T> holder, Cons<T> consumer, boolean closeSelect){
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(40);
|
||||
|
||||
int i = 0;
|
||||
int row = 2;
|
||||
int max = Math.max(row, Math.round(getDisplayWidth()/2/8/row/2));
|
||||
|
||||
for(T item : items){
|
||||
ImageButton button = cont.button(Tex.whiteui, Styles.clearTogglei, 24, () -> {
|
||||
if(closeSelect) control.input.config.hideConfig();
|
||||
}).group(group).tooltip(t->t.background(Styles.black8).add(item.localized().replace(search.getText(), "[accent]"+search.getText()+"[]"))).with(img -> img.getStyle().imageUpColor = item.color).get();
|
||||
button.changed(() -> consumer.get(button.isChecked() ? item : null));
|
||||
button.update(() -> button.setChecked(holder.get() == item));
|
||||
|
||||
if(i++ % max == max-1){
|
||||
cont.row();
|
||||
}
|
||||
}
|
||||
|
||||
//add extra blank spaces so it looks nice
|
||||
if(i % max != 0){
|
||||
int remaining = max - (i % max);
|
||||
for(int j = 0; j < remaining; j++){
|
||||
cont.image(Styles.black6);
|
||||
}
|
||||
}
|
||||
|
||||
ScrollPane pane = new ScrollPane(cont, Styles.smallPane);
|
||||
pane.setScrollingDisabled(true, false);
|
||||
pane.setScrollYForce(teamScroll);
|
||||
pane.update(() -> teamScroll = pane.getScrollY());
|
||||
pane.setOverscroll(false, false);
|
||||
table.add(pane).maxHeight(Scl.scl(row * 10 * 5));
|
||||
}
|
||||
float teamScroll;
|
||||
|
||||
float getDisplayWidth() {
|
||||
return window.getWidth() - (window.find("buttons") == null ? 1 : window.find("buttons").getWidth());
|
||||
}
|
||||
|
||||
public void drawBlocksReplace(int x, int y){
|
||||
drawBlocks(x, y, tile -> tile.block() != Blocks.air || drawBlock.isFloor());
|
||||
}
|
||||
|
||||
public void drawBlocks(int x, int y){
|
||||
drawBlocks(x, y, false, tile -> true);
|
||||
}
|
||||
|
||||
public void drawBlocks(int x, int y, Boolf<Tile> tester){
|
||||
drawBlocks(x, y, false, tester);
|
||||
}
|
||||
|
||||
int rotation = 0;
|
||||
public void drawBlocks(int x, int y, boolean square, Boolf<Tile> tester){
|
||||
if(drawBlock.isMultiblock()){
|
||||
x = Mathf.clamp(x, (drawBlock.size - 1) / 2, world.width() - drawBlock.size / 2 - 1);
|
||||
y = Mathf.clamp(y, (drawBlock.size - 1) / 2, world.height() - drawBlock.size / 2 - 1);
|
||||
if(!hasOverlap(x, y)){
|
||||
world.tile(x, y).setBlock(drawBlock, drawTeam, rotation);
|
||||
}
|
||||
}else{
|
||||
boolean isFloor = drawBlock.isFloor() && drawBlock != Blocks.air;
|
||||
|
||||
Cons<Tile> drawer = tile -> {
|
||||
if(!tester.get(tile)) return;
|
||||
|
||||
if(isFloor){
|
||||
tile.setFloor(drawBlock.asFloor());
|
||||
}else if(!(tile.block().isMultiblock() && !drawBlock.isMultiblock())){
|
||||
tile.setBlock(drawBlock, drawTeam, rotation);
|
||||
}
|
||||
};
|
||||
|
||||
if(square){
|
||||
drawSquare(x, y, drawer);
|
||||
}else{
|
||||
drawCircle(x, y, drawer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawCircle(int x, int y, Cons<Tile> drawer){
|
||||
int clamped = (int)brushSize;
|
||||
for(int rx = -clamped; rx <= clamped; rx++){
|
||||
for(int ry = -clamped; ry <= clamped; ry++){
|
||||
if(Mathf.within(rx, ry, brushSize - 0.5f + 0.0001f)){
|
||||
int wx = x + rx, wy = y + ry;
|
||||
|
||||
if(wx < 0 || wy < 0 || wx >= world.width() || wy >= world.height()){
|
||||
continue;
|
||||
}
|
||||
|
||||
drawer.get(world.tile(wx, wy));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawSquare(int x, int y, Cons<Tile> drawer){
|
||||
int clamped = (int)brushSize;
|
||||
for(int rx = -clamped; rx <= clamped; rx++){
|
||||
for(int ry = -clamped; ry <= clamped; ry++){
|
||||
int wx = x + rx, wy = y + ry;
|
||||
|
||||
if(wx < 0 || wy < 0 || wx >= world.width() || wy >= world.height()){
|
||||
continue;
|
||||
}
|
||||
|
||||
drawer.get(world.tile(wx, wy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasOverlap(int x, int y){
|
||||
Tile tile = world.tile(x, y);
|
||||
//allow direct replacement of blocks of the same size
|
||||
if(tile != null && tile.isCenter() && tile.block() != drawBlock && tile.block().size == drawBlock.size && tile.x == x && tile.y == y){
|
||||
return false;
|
||||
}
|
||||
|
||||
//else, check for overlap
|
||||
int offsetx = -(drawBlock.size - 1) / 2;
|
||||
int offsety = -(drawBlock.size - 1) / 2;
|
||||
for(int dx = 0; dx < drawBlock.size; dx++){
|
||||
for(int dy = 0; dy < drawBlock.size; dy++){
|
||||
int worldx = dx + offsetx + x;
|
||||
int worldy = dy + offsety + y;
|
||||
Tile other = world.tile(worldx, worldy);
|
||||
|
||||
if(other != null && other.block().isMultiblock()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
121
src/informatis/ui/window/PlayerWindow.java
Normal file
121
src/informatis/ui/window/PlayerWindow.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import informatis.ui.OverScrollPane;
|
||||
import informatis.ui.Updatable;
|
||||
import arc.Core;
|
||||
import arc.graphics.Color;
|
||||
import arc.graphics.g2d.Draw;
|
||||
import arc.graphics.g2d.Lines;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.scene.utils.Elem;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.input.DesktopInput;
|
||||
import mindustry.ui.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
|
||||
public class PlayerWindow extends Window implements Updatable {
|
||||
Vec2 scrollPos = new Vec2(0, 0);
|
||||
TextField search;
|
||||
ImageButton.ImageButtonStyle ustyle;
|
||||
@Nullable Player target;
|
||||
float heat;
|
||||
|
||||
public PlayerWindow() {
|
||||
super(Icon.players, "player");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Table table) {
|
||||
scrollPos = new Vec2(0, 0);
|
||||
search = Elem.newField(null, f->{});
|
||||
search.setMessageText(Core.bundle.get("players.search"));
|
||||
|
||||
ustyle = new ImageButton.ImageButtonStyle(){{
|
||||
down = Styles.none;
|
||||
up = Styles.none;
|
||||
imageDownColor = Pal.accent;
|
||||
imageUpColor = Color.white;
|
||||
imageOverColor = Color.lightGray;
|
||||
}};
|
||||
|
||||
table.background(Styles.black8).top();
|
||||
table.label(()-> Core.bundle.format(Groups.player.size() == 1 ? "players.single" : "players", Groups.player.size())).row();
|
||||
table.add(search).growX().pad(8).name("search").maxTextLength(maxNameLength).row();
|
||||
table.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).grow().name("player-pane");
|
||||
}
|
||||
|
||||
@Override
|
||||
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(){
|
||||
return new Table(table -> {
|
||||
float h = 74f;
|
||||
|
||||
Seq<Player> players = Groups.player.copy(new Seq<>());
|
||||
|
||||
players.sort(Structs.comps(Structs.comparing(Player::team), Structs.comparingBool(p -> !p.admin)));
|
||||
if(search.getText().length() > 0){
|
||||
players.filter(p -> Strings.stripColors(p.name().toLowerCase()).contains(search.getText().toLowerCase()));
|
||||
}
|
||||
|
||||
if(players.isEmpty()){
|
||||
table.add(Core.bundle.format("players.notfound")).center();
|
||||
return;
|
||||
}
|
||||
|
||||
for(Player user : players){
|
||||
table.table(userTable-> {
|
||||
userTable.left().margin(5).marginBottom(10);
|
||||
|
||||
Table table1 = new Table(){
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
Draw.color(target==user?Pal.accent:Pal.gray);
|
||||
Draw.alpha(parentAlpha);
|
||||
Lines.stroke(Scl.scl(4f));
|
||||
Lines.rect(x, y, width, height);
|
||||
Draw.reset();
|
||||
}
|
||||
};
|
||||
table1.margin(8);
|
||||
table1.add(new Image(user.icon()).setScaling(Scaling.bounded)).grow();
|
||||
table1.clicked(() -> {
|
||||
if(target==user) target = null;
|
||||
else target = user;
|
||||
});
|
||||
|
||||
userTable.add(table1).size(h).name(user.name()); //unit icon
|
||||
userTable.labelWrap(user.name()).color(user.color()).width(170f).pad(10); //name
|
||||
userTable.image(Icon.admin).padRight(5).visible(()->user.admin); //admin
|
||||
userTable.button(Icon.hammer, ustyle, () -> { //vote kick
|
||||
ui.showConfirm("@confirm", Core.bundle.format("confirmvotekick", user.name()), () -> {
|
||||
Call.sendChatMessage("/votekick " + user.name());
|
||||
});
|
||||
}).right().visible(()->user.team()==player.team()&&user!=player&&!user.admin);
|
||||
}).padBottom(-6).maxHeight(h + 14).row();
|
||||
table.image().height(4f).color(state.rules.pvp ? user.team().color : Pal.gray).growX().row();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
74
src/informatis/ui/window/ToolWindow.java
Normal file
74
src/informatis/ui/window/ToolWindow.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import informatis.ui.OverScrollPane;
|
||||
import informatis.ui.Updatable;
|
||||
import informatis.ui.draws.OverDraw;
|
||||
import informatis.ui.draws.OverDraws;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.scene.ui.ScrollPane;
|
||||
import arc.scene.ui.layout.Table;
|
||||
import arc.util.Time;
|
||||
import mindustry.gen.Icon;
|
||||
import mindustry.gen.Tex;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.ui.Styles;
|
||||
|
||||
public class ToolWindow extends Window implements Updatable {
|
||||
Vec2 scrollPos = new Vec2(0, 0);
|
||||
OverDraw selected;
|
||||
float heat;
|
||||
|
||||
public ToolWindow() {
|
||||
super(Icon.edit, "tool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Table table) {
|
||||
scrollPos = new Vec2(0, 0);
|
||||
|
||||
table.background(Styles.black8).top().left();
|
||||
table.table(pane->{
|
||||
pane.add(new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false)).name("tool-pane");
|
||||
}).top().marginLeft(4f).marginRight(12f);
|
||||
table.table(stats->{
|
||||
stats.top();
|
||||
stats.add(rebuildStats()).name("tool-stats");
|
||||
}).growY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
heat += Time.delta;
|
||||
if(heat >= 60f) {
|
||||
heat = 0f;
|
||||
ScrollPane pane = find("tool-pane");
|
||||
pane.setWidget(rebuild());
|
||||
}
|
||||
}
|
||||
|
||||
Table rebuild() {
|
||||
return new Table(icons->{
|
||||
for(OverDraw draw : OverDraws.all) {
|
||||
icons.button(draw.icon, ()->{
|
||||
selected=draw;
|
||||
Table table = find("tool-stats");
|
||||
table.clearChildren();
|
||||
table.add(rebuildStats());
|
||||
}).grow().tooltip(t->t.background(Styles.black8).add(draw.name).color(Pal.accent)).row();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Table rebuildStats() {
|
||||
return new Table(tool->{
|
||||
if(selected==null) return;
|
||||
tool.top();
|
||||
tool.table(Tex.underline2, label->label.add(selected.name).color(Pal.accent)).row();
|
||||
tool.table(des-> selected.displayStats(des)).name("unit-stats").row();
|
||||
tool.check("enable", selected.enabled, c->{
|
||||
selected.enabled=c;
|
||||
selected.onEnabled(find("unit-stats"));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
253
src/informatis/ui/window/UnitWindow.java
Normal file
253
src/informatis/ui/window/UnitWindow.java
Normal file
@@ -0,0 +1,253 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import arc.math.Mathf;
|
||||
import informatis.core.*;
|
||||
import informatis.ui.*;
|
||||
import arc.graphics.Color;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.Bits;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.Vars;
|
||||
import mindustry.core.UI;
|
||||
import mindustry.entities.units.WeaponMount;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.type.StatusEffect;
|
||||
import mindustry.type.Weapon;
|
||||
import mindustry.ui.Styles;
|
||||
import mindustry.world.blocks.ConstructBlock;
|
||||
import mindustry.world.blocks.payloads.Payload;
|
||||
|
||||
import static informatis.SVars.*;
|
||||
import static informatis.SUtils.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
class UnitWindow extends Window {
|
||||
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
||||
final Rect scissor = new Rect();
|
||||
Seq<Table> bars = new Seq<>(); //temp
|
||||
Vec2 scrollPos = new Vec2(0, 0);
|
||||
|
||||
public UnitWindow() {
|
||||
super(Icon.units, "unit");
|
||||
for(int i = 0; i < 6; i++) addBar();
|
||||
}
|
||||
|
||||
//TODO: add new UnitInfoDisplay(), new WeaponDisplay();
|
||||
@Override
|
||||
protected void build(Table table) {
|
||||
scrollPos = new Vec2(0, 0);
|
||||
table.top().background(Styles.black8);
|
||||
table.table(tt -> {
|
||||
tt.center();
|
||||
Image image = new Image() {
|
||||
@Override
|
||||
public void draw() {
|
||||
super.draw();
|
||||
|
||||
int offset = 8;
|
||||
Draw.color(locked?Pal.accent:Pal.gray);
|
||||
Draw.alpha(parentAlpha);
|
||||
Lines.stroke(Scl.scl(3f));
|
||||
Lines.rect(x-offset/2f, y-offset/2f, width+offset, height+offset);
|
||||
Draw.reset();
|
||||
}
|
||||
};
|
||||
image.update(()->{
|
||||
TextureRegion region = clear;
|
||||
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
|
||||
else if (target instanceof Building b) {
|
||||
if (target instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon;
|
||||
else if (b.block != null) region = b.block.uiIcon;
|
||||
}
|
||||
image.setDrawable(region);
|
||||
});
|
||||
image.clicked(()->{
|
||||
if(target==getTarget()) locked = !locked;
|
||||
target = getTarget();
|
||||
});
|
||||
|
||||
tt.add(image).size(iconMed).padRight(12f);
|
||||
tt.label(() -> {
|
||||
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
|
||||
if (target instanceof Building b && b.block != null) {
|
||||
if (target instanceof ConstructBlock.ConstructBuild cb) return cb.current.localizedName;
|
||||
return b.block.localizedName;
|
||||
}
|
||||
return "";
|
||||
}).color(Pal.accent);
|
||||
}).tooltip((to -> {
|
||||
to.background(Styles.black6);
|
||||
to.label(() -> target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI").row();
|
||||
to.label(() -> target == null ? "(" + 0 + ", " + 0 + ")" : "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")").row();
|
||||
to.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "");
|
||||
})).margin(12f).row();
|
||||
table.image().height(4f).color((target==null?player.unit():target).team().color).growX().row();
|
||||
table.add(new OverScrollPane(new Table(bars -> {
|
||||
bars.top();
|
||||
bars.table().update(t->{
|
||||
t.clear();
|
||||
this.bars.clear();
|
||||
for(int i = 0; i < 6; i++) addBar();
|
||||
for (Table bar : this.bars) {
|
||||
t.add(bar).growX().row();
|
||||
}
|
||||
}).growX();
|
||||
}), Styles.noBarPane, scrollPos).disableScroll(true, false)).growX().padTop(12f);
|
||||
}
|
||||
|
||||
void addBar() {
|
||||
int index = this.bars.size;
|
||||
bars.add(new Table(bar -> {
|
||||
bar.add(new SBar(
|
||||
() -> {
|
||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
||||
return data == null ? "[lightgray]<Empty>[]" : data.name;
|
||||
},
|
||||
() -> {
|
||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
||||
if (index >= lastColors.size) lastColors.size = index+1;
|
||||
if (data == null) return lastColors.get(index);
|
||||
if (data.color != Color.clear) lastColors.set(index, data.color);
|
||||
return lastColors.get(index);
|
||||
},
|
||||
() -> {
|
||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
||||
return data == null ? 0 : data.number;
|
||||
}
|
||||
)).height(4 * 8f).growX();
|
||||
bar.add(new Image(){
|
||||
@Override
|
||||
public void draw() {
|
||||
validate();
|
||||
|
||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
||||
Draw.color(Color.white);
|
||||
Draw.alpha(parentAlpha * color.a);
|
||||
if(data == null) {
|
||||
new TextureRegionDrawable(clear).draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
return;
|
||||
}
|
||||
TextureRegionDrawable region = new TextureRegionDrawable(data.icon);
|
||||
region.draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
Draw.color(data.color);
|
||||
if(ScissorStack.push(scissor.set(x, y, imageWidth * scaleX, imageHeight * scaleY * data.number))){
|
||||
region.draw(x, y, imageWidth * scaleX, imageHeight * scaleY);
|
||||
ScissorStack.pop();
|
||||
}
|
||||
}
|
||||
}).size(iconMed * 0.75f).padLeft(8f);
|
||||
}));
|
||||
}
|
||||
|
||||
static class WeaponDisplay extends Table {
|
||||
WeaponDisplay() {
|
||||
table().update(tt -> {
|
||||
tt.clear();
|
||||
if(getTarget() instanceof Unit u && u.type != null && u.hasWeapons()) {
|
||||
for(int r = 0; r < u.type.weapons.size; r++){
|
||||
Weapon weapon = u.type.weapons.get(r);
|
||||
WeaponMount mount = u.mounts[r];
|
||||
int finalR = r;
|
||||
tt.table(ttt -> {
|
||||
ttt.left();
|
||||
if((1 + finalR) % 4 == 0) ttt.row();
|
||||
ttt.stack(
|
||||
new Table(o -> {
|
||||
o.left();
|
||||
o.add(new Image(!weapon.name.equals("") && weapon.outlineRegion.found() ? weapon.outlineRegion : u.type.uiIcon){
|
||||
@Override
|
||||
public void draw(){
|
||||
validate();
|
||||
float x = this.x;
|
||||
float y = this.y;
|
||||
float scaleX = this.scaleX;
|
||||
float scaleY = this.scaleY;
|
||||
Draw.color(color);
|
||||
Draw.alpha(parentAlpha * color.a);
|
||||
|
||||
if(getDrawable() instanceof TransformDrawable){
|
||||
float rotation = getRotation();
|
||||
if(scaleX != 1 || scaleY != 1 || rotation != 0){
|
||||
getDrawable().draw(x + imageX, y + imageY, originX - imageX, originY - imageY, imageWidth, imageHeight, scaleX, scaleY, rotation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
y -= (mount.reload) / weapon.reload * weapon.recoil;
|
||||
if(getDrawable() != null)
|
||||
getDrawable().draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
|
||||
}
|
||||
}).size(iconLarge);
|
||||
}),
|
||||
new Table(h -> {
|
||||
h.defaults().growX().height(9f).width(iconLarge).padTop(18f);
|
||||
h.add(new SBar(
|
||||
() -> "",
|
||||
() -> Pal.accent.cpy().lerp(Color.orange, mount.reload / weapon.reload),
|
||||
() -> mount.reload / weapon.reload).rect().init());
|
||||
h.pack();
|
||||
})
|
||||
);
|
||||
}).pad(4);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
static class UnitInfoDisplay extends Table {
|
||||
UnitInfoDisplay() {
|
||||
top();
|
||||
float[] count = new float[]{-1};
|
||||
table().update(t -> {
|
||||
if(getTarget() instanceof Payloadc payload){
|
||||
if(count[0] != payload.payloadUsed()){
|
||||
t.clear();
|
||||
t.top().left();
|
||||
|
||||
float pad = 0;
|
||||
float items = payload.payloads().size;
|
||||
if(8 * 2 * items + pad * items > 275f){
|
||||
pad = (275f - (8 * 2) * items) / items;
|
||||
}
|
||||
int i = 0;
|
||||
for(Payload p : payload.payloads()){
|
||||
t.image(p.icon()).size(8 * 2).padRight(pad);
|
||||
if(++i % 12 == 0) t.row();
|
||||
}
|
||||
|
||||
count[0] = payload.payloadUsed();
|
||||
}
|
||||
}else{
|
||||
count[0] = -1;
|
||||
t.clear();
|
||||
}
|
||||
}).growX().visible(() -> getTarget() instanceof Payloadc p && p.payloadUsed() > 0).colspan(2).row();
|
||||
|
||||
Bits statuses = new Bits();
|
||||
table().update(t -> {
|
||||
t.left();
|
||||
if(getTarget() instanceof Statusc st){
|
||||
Bits applied = st.statusBits();
|
||||
if(!statuses.equals(applied)){
|
||||
t.clear();
|
||||
|
||||
if(applied != null){
|
||||
for(StatusEffect effect : Vars.content.statusEffects()){
|
||||
if(applied.get(effect.id) && !effect.isHidden()){
|
||||
t.image(effect.uiIcon).size(iconSmall).get()
|
||||
.addListener(new Tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel)));
|
||||
}
|
||||
}
|
||||
statuses.set(applied);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).left();
|
||||
}
|
||||
}
|
||||
}
|
||||
207
src/informatis/ui/window/WaveWindow.java
Normal file
207
src/informatis/ui/window/WaveWindow.java
Normal file
@@ -0,0 +1,207 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import mindustry.Vars;
|
||||
import mindustry.type.UnitType;
|
||||
import informatis.ui.OverScrollPane;
|
||||
import arc.Events;
|
||||
import arc.graphics.Color;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.scene.event.Touchable;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.StatusEffects;
|
||||
import mindustry.game.EventType;
|
||||
import mindustry.game.SpawnGroup;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.ui.*;
|
||||
import informatis.ui.Updatable;
|
||||
|
||||
import static arc.Core.*;
|
||||
import static arc.Core.settings;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
|
||||
public class WaveWindow extends Window implements Updatable {
|
||||
static Vec2 scrollPos = new Vec2(0, 0);
|
||||
Table window;
|
||||
float heat;
|
||||
|
||||
public WaveWindow() {
|
||||
super(Icon.waves, "wave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Table table) {
|
||||
window = table;
|
||||
|
||||
table.top().background(Styles.black8);
|
||||
ScrollPane pane = new OverScrollPane(rebuild(), Styles.noBarPane, scrollPos).disableScroll(true, false);
|
||||
table.add(pane).grow().name("wave-pane").row();
|
||||
table.table(total -> {
|
||||
total.left();
|
||||
total.label(()->"~"+state.wave+"+");
|
||||
total.field(""+settings.getInt("wavemax"), f->{
|
||||
String str = f.replaceAll("\\D", "");
|
||||
if(str.isEmpty()) settings.put("wavemax", 0);
|
||||
else settings.put("wavemax", Integer.parseInt(str));
|
||||
});
|
||||
total.table().update(units->{
|
||||
units.clear();
|
||||
units.center();
|
||||
|
||||
if(Groups.unit.count(u->u.team==state.rules.waveTeam) <= 0) {
|
||||
units.add("[lightgray]<Empty>[]");
|
||||
return;
|
||||
}
|
||||
|
||||
int row = 0;
|
||||
int max = Math.max(1, Math.round(window.getWidth()/2/8/2));
|
||||
for (UnitType unit : Vars.content.units()) {
|
||||
int amount = Groups.unit.count(u->u.type==unit&&u.team==state.rules.waveTeam);
|
||||
if(amount<=0) continue;
|
||||
units.stack(
|
||||
new Table(ttt -> {
|
||||
ttt.center();
|
||||
ttt.image(unit.uiIcon).size(iconMed);
|
||||
ttt.pack();
|
||||
}),
|
||||
|
||||
new Table(ttt -> {
|
||||
ttt.bottom().left();
|
||||
ttt.add(amount + "").padTop(2f).fontScale(0.9f);
|
||||
ttt.pack();
|
||||
})
|
||||
).pad(2f);
|
||||
if(row++ % max == max-1){
|
||||
units.row();
|
||||
}
|
||||
}
|
||||
}).growX();
|
||||
}).growX().row();
|
||||
table.image().height(4f).color(Pal.gray).growX().row();
|
||||
table.table(option->{
|
||||
option.check("Show empty wave", settings.getBool("emptywave"), b->settings.put("emptywave", b)).margin(4f);
|
||||
option.check("Show previous wave", settings.getBool("pastwave"), b->settings.put("pastwave", b)).margin(4f);
|
||||
});
|
||||
Events.on(EventType.WorldLoadEvent.class, e -> {
|
||||
pane.clearChildren();
|
||||
pane.setWidget(rebuild());
|
||||
});
|
||||
Events.on(EventType.WaveEvent.class, e -> {
|
||||
pane.clearChildren();
|
||||
pane.setWidget(rebuild());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
ObjectIntMap<SpawnGroup> groups = new ObjectIntMap<>();
|
||||
for (SpawnGroup group : state.rules.spawns) {
|
||||
if (group.getSpawned(index) <= 0) continue;
|
||||
SpawnGroup sameTypeKey = groups.keys().toArray().find(g -> g.type == group.type && g.effect != StatusEffects.boss);
|
||||
if (sameTypeKey != null) groups.increment(sameTypeKey, sameTypeKey.getSpawned(index));
|
||||
else groups.put(group, group.getSpawned(index));
|
||||
}
|
||||
Seq<SpawnGroup> groupSorted = groups.keys().toArray().copy().sort((g1, g2) -> {
|
||||
int boss = Boolean.compare(g1.effect != StatusEffects.boss, g2.effect != StatusEffects.boss);
|
||||
if (boss != 0) return boss;
|
||||
int hitSize = Float.compare(-g1.type.hitSize, -g2.type.hitSize);
|
||||
if (hitSize != 0) return hitSize;
|
||||
return Integer.compare(-g1.type.id, -g2.type.id);
|
||||
});
|
||||
ObjectIntMap<SpawnGroup> groupsTmp = new ObjectIntMap<>();
|
||||
groupSorted.each(g -> groupsTmp.put(g, groups.get(g)));
|
||||
|
||||
return groupsTmp;
|
||||
}
|
||||
|
||||
Table rebuild(){
|
||||
return new Table(table -> {
|
||||
table.touchable = Touchable.enabled;
|
||||
table.table(body->{
|
||||
body.center();
|
||||
for (int i = settings.getBool("pastwave") ? 1 : state.wave; i <= Math.min(state.wave + settings.getInt("wavemax"), (state.isCampaign() && state.rules.winWave > 0 ? state.rules.winWave : Integer.MAX_VALUE)); i++) {
|
||||
final int index = i;
|
||||
|
||||
if (state.rules.spawns.find(g -> g.getSpawned(index-1) > 0) == null && !settings.getBool("emptywave")) continue;
|
||||
|
||||
body.table(waveRow -> {
|
||||
waveRow.left();
|
||||
|
||||
waveRow.add(index+"").update(label -> {
|
||||
Color color = Pal.accent;
|
||||
if (state.wave == index) color = Color.red;
|
||||
else if (state.wave - 1 == index && state.enemies > 0) color = Color.red.cpy().shiftHue(Time.time);
|
||||
|
||||
label.setColor(color);
|
||||
});
|
||||
waveRow.table(unitTable -> {
|
||||
unitTable.center();
|
||||
|
||||
if (state.rules.spawns.find(g -> g.getSpawned(index-1) > 0) == null) {
|
||||
if (settings.getBool("emptywave")) unitTable.add(bundle.get("empty"));
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectIntMap<SpawnGroup> groups = getWaveGroup(index-1);
|
||||
|
||||
int row = 0;
|
||||
int max = Math.max(1, Math.round(window.getWidth()/2/8));
|
||||
for (SpawnGroup group : groups.keys()) {
|
||||
int spawners = state.rules.waveTeam.cores().size + (group.type.flying ? spawner.countFlyerSpawns() : spawner.countGroundSpawns());
|
||||
int amount = groups.get(group);
|
||||
unitTable.stack(
|
||||
new Table(ttt -> {
|
||||
ttt.center();
|
||||
ttt.image(group.type.uiIcon).size(iconMed);
|
||||
ttt.pack();
|
||||
}),
|
||||
|
||||
new Table(ttt -> {
|
||||
ttt.bottom().left();
|
||||
ttt.add(amount + "").padTop(2f).fontScale(0.9f);
|
||||
ttt.add("[gray]x" + spawners).padTop(10f).fontScale(0.7f);
|
||||
ttt.pack();
|
||||
}),
|
||||
|
||||
new Table(ttt -> {
|
||||
ttt.top().right();
|
||||
ttt.image(Icon.warning.getRegion()).update(img -> img.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)))).size(12f);
|
||||
ttt.visible(() -> group.effect == StatusEffects.boss);
|
||||
ttt.pack();
|
||||
})
|
||||
).pad(2f).get().addListener(new Tooltip(to -> {
|
||||
to.background(Styles.black6);
|
||||
to.margin(4f).left();
|
||||
to.add("[stat]" + group.type.localizedName + "[]").row();
|
||||
to.row();
|
||||
to.add(bundle.format("shar-stat-waveAmount", amount + " [lightgray]x" + spawners + "[]")).row();
|
||||
to.add(bundle.format("shar-stat-waveShield", group.getShield(index-1))).row();
|
||||
if (group.effect != null && group.effect != StatusEffects.none)
|
||||
to.add(bundle.get("shar-stat.waveStatus") + group.effect.emoji() + "[stat]" + group.effect.localizedName).row();
|
||||
}));
|
||||
if(row++ % max == max-1){
|
||||
unitTable.row();
|
||||
}
|
||||
}
|
||||
}).growX().margin(12f);
|
||||
}).growX().row();
|
||||
body.image().height(4f).color(Pal.gray).growX().row();
|
||||
}
|
||||
}).grow().margin(40f);
|
||||
});
|
||||
}
|
||||
}
|
||||
135
src/informatis/ui/window/Window.java
Normal file
135
src/informatis/ui/window/Window.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.input.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.*;
|
||||
import informatis.ui.WindowManager;
|
||||
|
||||
public class Window extends Table{
|
||||
public TextureRegionDrawable icon;
|
||||
public int id;
|
||||
public Cons<Table> content;
|
||||
public boolean shown = false;
|
||||
|
||||
public float minWindowWidth = 160, minWindowHeight = 60;
|
||||
public float maxWindowWidth = Float.MAX_VALUE, maxWindowHeight = Float.MAX_VALUE;
|
||||
|
||||
public Window(TextureRegionDrawable icon, String name){
|
||||
this(icon, name, null);
|
||||
}
|
||||
|
||||
public Window(TextureRegionDrawable icon, String name, Cons<Table> content){
|
||||
this.content = content;
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
|
||||
titleBar();
|
||||
pane(t -> {
|
||||
t.setBackground(Styles.black5);
|
||||
t.top().left();
|
||||
build(t);
|
||||
}).grow().top().left().get().setScrollingDisabled(true, true);
|
||||
bottomBar();
|
||||
|
||||
setPosition(Core.graphics.getWidth() / 2f - getWidth() / 2f, Core.graphics.getHeight() / 2f - getHeight() / 2f);
|
||||
id = WindowManager.register(this);
|
||||
|
||||
visible(() -> shown);
|
||||
}
|
||||
|
||||
protected void build(Table t){
|
||||
if(content != null) content.get(t);
|
||||
}
|
||||
|
||||
protected void titleBar(){
|
||||
table(t -> {
|
||||
// icon and title
|
||||
t.table(Tex.buttonEdge1, b -> {
|
||||
b.top().left();
|
||||
b.image(() -> icon == null ? Icon.none.getRegion() : icon.getRegion()).size(20f).padLeft(15).top().left();
|
||||
b.pane(Styles.noBarPane, p -> {
|
||||
p.top().left();
|
||||
p.labelWrap(() -> Core.bundle.get("window."+name+".name")).padLeft(20).top().left().get().setAlignment(Align.topLeft);
|
||||
}).left().height(40f).growX().get().setScrollingDisabled(true, true);
|
||||
}).maxHeight(40f).grow();
|
||||
|
||||
// exit button
|
||||
t.table(Tex.buttonEdge3, b -> {
|
||||
b.button(Icon.cancel, Styles.emptyi, () -> shown = false);
|
||||
}).maxHeight(40f).width(80f).growY();
|
||||
|
||||
// handles the dragging.
|
||||
t.touchable = Touchable.enabled;
|
||||
t.addListener(new InputListener(){
|
||||
float lastX, lastY;
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button) {
|
||||
Vec2 v = t.localToStageCoordinates(Tmp.v1.set(x, y));
|
||||
lastX = v.x;
|
||||
lastY = v.y;
|
||||
toFront();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchDragged(InputEvent event, float dx, float dy, int pointer) {
|
||||
Vec2 v = t.localToStageCoordinates(Tmp.v1.set(dx, dy));
|
||||
|
||||
setPosition( x + (v.x - lastX), y + (v.y - lastY));
|
||||
|
||||
lastX = v.x;
|
||||
lastY = v.y;
|
||||
}
|
||||
});
|
||||
}).top().height(40f).growX();
|
||||
row();
|
||||
}
|
||||
|
||||
protected void bottomBar(){
|
||||
row();
|
||||
table(Styles.black5, t -> {
|
||||
t.table().growX();
|
||||
t.table(Icon.resizeSmall, r -> {
|
||||
r.bottom().left();
|
||||
r.touchable = Touchable.enabled;
|
||||
r.addListener(new InputListener(){
|
||||
float lastX, lastY;
|
||||
@Override
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button) {
|
||||
Vec2 v = r.localToStageCoordinates(Tmp.v1.set(x, y));
|
||||
lastX = v.x;
|
||||
lastY = v.y;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchDragged(InputEvent event, float x, float y, int pointer) {
|
||||
Vec2 v = r.localToStageCoordinates(Tmp.v1.set(x, y));
|
||||
float w = v.x - lastX;
|
||||
float h = v.y - lastY;
|
||||
|
||||
// will softlock if initial size is smaller than minimum
|
||||
// so don't do that!
|
||||
if(getWidth() + w < minWindowWidth || getWidth() + w > maxWindowWidth) w = 0;
|
||||
if(getHeight() - h < minWindowHeight || getHeight() - h > maxWindowHeight) h = 0;
|
||||
sizeBy(w, -h);
|
||||
moveBy(0, h);
|
||||
lastX = v.x;
|
||||
lastY = v.y;
|
||||
}
|
||||
});
|
||||
}).size(20f).left();
|
||||
}).height(20f).growX();
|
||||
}
|
||||
|
||||
public void toggle(){
|
||||
shown = !shown;
|
||||
}
|
||||
}
|
||||
14
src/informatis/ui/window/Windows.java
Normal file
14
src/informatis/ui/window/Windows.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
public class Windows {
|
||||
public static MapEditorWindow editorTable;
|
||||
|
||||
public static void load(){
|
||||
new UnitWindow();
|
||||
new WaveWindow();
|
||||
new CoreWindow();
|
||||
new PlayerWindow();
|
||||
new ToolWindow();
|
||||
editorTable = new MapEditorWindow();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user