mirror of
https://github.com/yawaflua/Informatis.git
synced 2026-02-05 02:44:15 +02:00
refactoring
This commit is contained in:
200
src/informatis/ui/windows/CoreWindow.java
Normal file
200
src/informatis/ui/windows/CoreWindow.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import arc.*;
|
||||
import informatis.SUtils;
|
||||
import mindustry.game.*;
|
||||
import informatis.ui.*;
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
|
||||
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(() -> SUtils.moveCamera(core));
|
||||
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();
|
||||
if(itemData.get(team) == null) return;
|
||||
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))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
467
src/informatis/ui/windows/MapEditorWindow.java
Normal file
467
src/informatis/ui/windows/MapEditorWindow.java
Normal file
@@ -0,0 +1,467 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import arc.Events;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.struct.*;
|
||||
import informatis.core.EditorTool;
|
||||
import mindustry.editor.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.graphics.*;
|
||||
import informatis.ui.*;
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.input.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.scene.utils.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class MapEditorWindow extends Window implements Updatable {
|
||||
Vec2 scrollPos = new Vec2(0, 0);
|
||||
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, ()->{
|
||||
if(table.getChildren().size > 1) table.getChildren().get(table.getChildren().size-1).remove();
|
||||
table.add(display).grow();
|
||||
}).row();
|
||||
});
|
||||
}).growY();
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
118
src/informatis/ui/windows/PlayerWindow.java
Normal file
118
src/informatis/ui/windows/PlayerWindow.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import informatis.ui.*;
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.scene.utils.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.input.*;
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
71
src/informatis/ui/windows/ToolWindow.java
Normal file
71
src/informatis/ui/windows/ToolWindow.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import informatis.ui.*;
|
||||
import informatis.ui.draws.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
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"));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
260
src/informatis/ui/windows/UnitWindow.java
Normal file
260
src/informatis/ui/windows/UnitWindow.java
Normal file
@@ -0,0 +1,260 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import arc.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.*;
|
||||
import informatis.core.*;
|
||||
import informatis.ui.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.Bits;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.blocks.payloads.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static informatis.SVars.*;
|
||||
import static informatis.SUtils.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitWindow extends Window {
|
||||
int barSize = 6;
|
||||
float usedPayload;
|
||||
float barScrollPos;
|
||||
float lastWidth;
|
||||
final Seq<Color> lastColors = new Seq<>();
|
||||
final Bits statuses = new Bits();
|
||||
Teamc lastTarget;
|
||||
|
||||
public UnitWindow() { super(Icon.units, "unit"); }
|
||||
|
||||
@Override
|
||||
protected void build(Table table) {
|
||||
Image profileImage = new Image() {
|
||||
final int size = 8;
|
||||
@Override
|
||||
public void draw() {
|
||||
super.draw();
|
||||
|
||||
Draw.color(locked? Pal.accent:Pal.gray);
|
||||
Draw.alpha(parentAlpha);
|
||||
Lines.stroke(Scl.scl(3f));
|
||||
Lines.rect(x-size/2f, y-size/2f, width+size, height+size);
|
||||
Draw.reset();
|
||||
}
|
||||
};
|
||||
profileImage.update(() -> {
|
||||
TextureRegion region = clear;
|
||||
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
|
||||
else if (target instanceof Building b) {
|
||||
if (b instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon;
|
||||
else if (b.block != null) region = b.block.uiIcon;
|
||||
}
|
||||
profileImage.setDrawable(region);
|
||||
});
|
||||
profileImage.clicked(() -> {
|
||||
if (target == getTarget()) locked = !locked;
|
||||
target = getTarget();
|
||||
});
|
||||
Label profileLabel = new 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 "";
|
||||
});
|
||||
profileLabel.clicked(() -> moveCamera(target));
|
||||
|
||||
ScrollPane barPane = new ScrollPane(buildBarList(), Styles.noBarPane);
|
||||
barPane.update(() -> {
|
||||
if (lastTarget != target) {
|
||||
lastTarget = target;
|
||||
for (int i = 0; i < barSize; i++) {
|
||||
Color color = i >= BarInfo.data.size ? Color.clear : BarInfo.data.get(i).color;
|
||||
if (i >= lastColors.size) lastColors.add(color);
|
||||
else lastColors.set(i, color);
|
||||
}
|
||||
}
|
||||
|
||||
if (((Table) barPane.getWidget()).getChildren().size - 1 != barSize) {
|
||||
barPane.setWidget(buildBarList());
|
||||
}
|
||||
|
||||
if (barPane.hasScroll()) {
|
||||
Element result = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
|
||||
if (result == null || !result.isDescendantOf(barPane)) {
|
||||
Core.scene.setScrollFocus(null);
|
||||
}
|
||||
}
|
||||
barScrollPos = barPane.getScrollY();
|
||||
});
|
||||
barPane.setScrollingDisabledX(true);
|
||||
barPane.setScrollYForce(barScrollPos);
|
||||
|
||||
table.top().background(Styles.black8);
|
||||
table.table(profile -> profile
|
||||
.table(title -> {
|
||||
title.center();
|
||||
title.add(profileImage).size(iconMed);
|
||||
title.add(profileLabel).padLeft(12f).padRight(12f).color(Pal.accent);
|
||||
})
|
||||
.tooltip(tool -> {
|
||||
tool.background(Styles.black6);
|
||||
tool.label(() -> target instanceof Unit u ? u.isPlayer() ? u.getPlayer().name : "AI" : "").row();
|
||||
tool.label(() -> target.tileX() + ", " + target.tileY()).row();
|
||||
tool.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "");
|
||||
}).get()
|
||||
).margin(3f).growX().row();
|
||||
table.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];
|
||||
tt.table(ttt -> {
|
||||
ttt.left();
|
||||
ttt.stack(
|
||||
new Table(o -> {
|
||||
o.left();
|
||||
o.add(new Image(Core.atlas.isFound(weapon.region) ? weapon.region : u.type.uiIcon){
|
||||
@Override
|
||||
public void draw(){
|
||||
y -= (mount.reload) / weapon.reload * weapon.recoil;
|
||||
super.draw();
|
||||
}
|
||||
}).size(iconLarge).scaling(Scaling.bounded);
|
||||
}),
|
||||
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);
|
||||
if((r + 1) % 4 == 0) tt.row();
|
||||
}
|
||||
}
|
||||
}).margin(4f).growX().row();
|
||||
table.table(state -> {
|
||||
state.left();
|
||||
state.table().update(t -> {
|
||||
if (!(target instanceof Payloadc payloader)) {
|
||||
t.clear();
|
||||
usedPayload = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if(usedPayload == payloader.payloadUsed() && lastWidth == window.getWidth()) return;
|
||||
if(usedPayload != payloader.payloadUsed()) usedPayload = payloader.payloadUsed();
|
||||
if(lastWidth != window.getWidth()) lastWidth = window.getWidth();
|
||||
|
||||
t.clear();
|
||||
t.top().left();
|
||||
Seq<Payload> payloads = payloader.payloads();
|
||||
for (int i = 0, m = payloads.size; i < m; i++) {
|
||||
Payload payload = payloads.get(i);
|
||||
Image image = new Image(payload.icon());
|
||||
image.clicked(() -> ui.content.show(payload.content()));
|
||||
image.hovered(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.lightGray, Mathf.clamp(Time.delta))));
|
||||
image.exited(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.white, Mathf.clamp(Time.delta))));
|
||||
t.add(image).size(iconSmall).tooltip(l -> l.label(() -> payload.content().localizedName).style(Styles.outlineLabel));
|
||||
if ((i + 1) % Math.max(6, Math.round((window.getWidth() - 24) / iconSmall)) == 0) t.row();
|
||||
}
|
||||
});
|
||||
|
||||
state.table().update(t -> {
|
||||
if (!(target instanceof Statusc st)) {
|
||||
t.clear();
|
||||
statuses.clear();
|
||||
return;
|
||||
}
|
||||
Bits applied = st.statusBits();
|
||||
|
||||
if((applied == null || statuses.equals(st.statusBits())) && lastWidth == window.getWidth()) return;
|
||||
if(!statuses.equals(st.statusBits())) statuses.set(applied);
|
||||
if(lastWidth != window.getWidth()) lastWidth = window.getWidth();
|
||||
|
||||
t.clear();
|
||||
t.top().left();
|
||||
Seq<StatusEffect> contents = Vars.content.statusEffects();
|
||||
for (int i = 0, m = Vars.content.statusEffects().size; i < m; i++) {
|
||||
StatusEffect effect = contents.get(i);
|
||||
if (Objects.requireNonNull(applied).get(effect.id) && !effect.isHidden()) {
|
||||
Image image = new Image(effect.uiIcon);
|
||||
image.clicked(() -> ui.content.show(effect));
|
||||
image.hovered(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.lightGray, Mathf.clamp(Time.delta))));
|
||||
image.exited(() -> image.setColor(Tmp.c1.set(image.color).lerp(Color.white, Mathf.clamp(Time.delta))));
|
||||
t.add(image).size(iconSmall).tooltip(l -> l.label(() -> effect.localizedName + " [lightgray]" + UI.formatTime(st.getDuration(effect))).style(Styles.outlineLabel));
|
||||
if (i + 1 % Math.max(6, Math.round((window.getWidth() - 24) / iconSmall)) == 0) t.row();
|
||||
}
|
||||
}
|
||||
});
|
||||
}).growX().row();
|
||||
table.image().color((target == null ? player.unit() : target).team().color).height(4f).growX().row();
|
||||
table.add(barPane).grow().padTop(12f);
|
||||
}
|
||||
|
||||
boolean show;
|
||||
Table buildBarList() {
|
||||
show = false;
|
||||
return new Table(table -> {
|
||||
table.top();
|
||||
for (int i = 0; i < barSize; i++) {
|
||||
table.add(addBar(i)).growX().get();
|
||||
table.row();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Table addBar(int index) {
|
||||
return new Table(bar -> {
|
||||
bar.add(new SBar(
|
||||
() -> index >= BarInfo.data.size ? "[lightgray]<Empty>[]" : BarInfo.data.get(index).name,
|
||||
() -> index >= BarInfo.data.size ? Color.clear : BarInfo.data.get(index).color,
|
||||
() -> lastColors.get(index),
|
||||
() -> index >= BarInfo.data.size ? 0 : BarInfo.data.get(index).number)
|
||||
).height(4 * 8f).growX();
|
||||
if(index >= BarInfo.data.size) return;
|
||||
Image icon = new Image(){
|
||||
@Override
|
||||
public void draw() {
|
||||
validate();
|
||||
if(index >= BarInfo.data.size) return;
|
||||
float x = this.x + imageX;
|
||||
float y = this.y + imageY;
|
||||
float width = imageWidth * this.scaleX;
|
||||
float height = imageHeight * this.scaleY;
|
||||
Draw.color(Color.white);
|
||||
Draw.alpha(parentAlpha * color.a);
|
||||
BarInfo.BarData data = BarInfo.data.get(index);
|
||||
if(hasMouse()) getDrawable().draw(x, y, width, height);
|
||||
else {
|
||||
data.icon.draw(x, y, width, height);
|
||||
if(ScissorStack.push(Tmp.r1.set(ScissorStack.peek().x + x, ScissorStack.peek().y + y, width, height * data.number))) {
|
||||
Draw.color(data.color);
|
||||
data.icon.draw(x, y, width, height);
|
||||
ScissorStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
icon.setDrawable(BarInfo.data.get(index).icon);
|
||||
bar.add(icon).size(iconMed * 0.75f).padLeft(8f);
|
||||
});
|
||||
}
|
||||
}
|
||||
203
src/informatis/ui/windows/WaveWindow.java
Normal file
203
src/informatis/ui/windows/WaveWindow.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import mindustry.*;
|
||||
import mindustry.type.*;
|
||||
import informatis.ui.*;
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
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);
|
||||
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()/64)-5);
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
142
src/informatis/ui/windows/Window.java
Normal file
142
src/informatis/ui/windows/Window.java
Normal file
@@ -0,0 +1,142 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.input.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.Element;
|
||||
import arc.scene.event.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.*;
|
||||
import informatis.ui.*;
|
||||
|
||||
public class Window extends Table {
|
||||
public TextureRegionDrawable icon;
|
||||
public int id;
|
||||
public Cons<Table> content;
|
||||
public boolean shown = false;
|
||||
public Table window;
|
||||
|
||||
public float minWindowWidth = 160, minWindowHeight = 60;
|
||||
public float maxWindowWidth = Float.MAX_VALUE, maxWindowHeight = Float.MAX_VALUE;
|
||||
float topBarHeight = 48f;
|
||||
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;
|
||||
window = this;
|
||||
id = WindowManager.register(this);
|
||||
|
||||
titleBar();
|
||||
row();
|
||||
ScrollPane pane = new ScrollPane(new Table(t -> {
|
||||
t.setBackground(Styles.black5);
|
||||
t.top().left();
|
||||
build(t);
|
||||
}), Styles.noBarPane);
|
||||
pane.update(() -> {
|
||||
if(pane.hasScroll()){
|
||||
Element result = Core.scene.hit(Core.input.mouseX(), Core.input.mouseY(), true);
|
||||
if(result == null || !result.isDescendantOf(pane)){
|
||||
Core.scene.setScrollFocus(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
pane.setScrollingDisabled(true, true);
|
||||
add(pane).grow();
|
||||
row();
|
||||
bottomBar();
|
||||
|
||||
visible(() -> shown);
|
||||
update(() -> setPosition(
|
||||
Math.max(0, Math.min(Core.graphics.getWidth() - getWidth(), x)),
|
||||
Math.max(topBarHeight - getHeight(), Math.min(Core.graphics.getHeight() - getHeight(), y))
|
||||
));
|
||||
}
|
||||
|
||||
protected void build(Table t){
|
||||
if(content != null) content.get(t);
|
||||
}
|
||||
|
||||
protected void titleBar(){
|
||||
table(t -> {
|
||||
t.pane(b -> {
|
||||
b.left();
|
||||
b.setBackground(Tex.buttonEdge1);
|
||||
b.image(icon.getRegion()).size(20f).padLeft(15);
|
||||
b.add(Core.bundle.get("window."+name+".name")).padLeft(20);
|
||||
}).touchable(Touchable.disabled).grow();
|
||||
t.table(Tex.buttonEdge3, b -> b.button(Icon.cancel, Styles.emptyi, () -> shown = false).fill()).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;
|
||||
}
|
||||
});
|
||||
}).height(topBarHeight).growX();
|
||||
}
|
||||
|
||||
protected void bottomBar(){
|
||||
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/windows/Windows.java
Normal file
14
src/informatis/ui/windows/Windows.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package informatis.ui.windows;
|
||||
|
||||
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