mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 03:59:26 +02:00
weapon
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package informatis;
|
||||
|
||||
import arc.Core;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Position;
|
||||
import arc.scene.style.*;
|
||||
import arc.struct.Seq;
|
||||
import arc.util.*;
|
||||
@@ -9,6 +11,7 @@ import mindustry.Vars;
|
||||
import mindustry.core.UI;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.input.DesktopInput;
|
||||
import mindustry.type.UnitType;
|
||||
import mindustry.type.weapons.*;
|
||||
import mindustry.world.Tile;
|
||||
@@ -17,9 +20,23 @@ import java.lang.reflect.*;
|
||||
|
||||
import static informatis.SVars.*;
|
||||
import static arc.Core.*;
|
||||
import static mindustry.Vars.control;
|
||||
import static mindustry.Vars.player;
|
||||
|
||||
public class SUtils {
|
||||
/**
|
||||
* move camera to given coordination
|
||||
* @param x - world unit x
|
||||
* @param y - world unit y
|
||||
*/
|
||||
public static void moveCamera(float x, float y) {
|
||||
if(control.input instanceof DesktopInput)
|
||||
((DesktopInput) control.input).panning = true;
|
||||
Core.camera.position.set(x, y);
|
||||
}
|
||||
public static void moveCamera(Position pos) {
|
||||
moveCamera(pos.getX(), pos.getY());
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Teamc> T getTarget(){
|
||||
if(locked && target != null) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package informatis.core;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.TextureRegion;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.Rect;
|
||||
import arc.scene.style.Drawable;
|
||||
import arc.scene.style.TextureRegionDrawable;
|
||||
import arc.struct.*;
|
||||
@@ -62,7 +61,7 @@ public class BarInfo {
|
||||
else if(target instanceof Building build){
|
||||
if(build.block.hasLiquids) data.add(new BarData(bundle.format("shar-stat.capacity", build.liquids.currentAmount() < 0.01f ? build.liquids.current().localizedName : bundle.get("bar.liquid"), formatNumber(build.liquids.currentAmount()), formatNumber(build.block.liquidCapacity)), build.liquids.current().color, build.liquids.currentAmount() / build.block.liquidCapacity, liquid));
|
||||
|
||||
if(build.block.hasPower && build.block.consumesPower){
|
||||
if(build.block.hasPower && build.block.consPower != null){
|
||||
ConsumePower cons = build.block.consPower;
|
||||
data.add(new BarData(bundle.format("shar-stat.power", formatNumber(build.power.status * 60f * (cons.buffered ? cons.capacity : cons.usage)), formatNumber(60f * (cons.buffered ? cons.capacity : cons.usage))), Pal.powerBar, Mathf.zero(cons.requestedPower(build)) && build.power.graph.getPowerProduced() + build.power.graph.getBatteryStored() > 0f ? 1f : build.power.status, power));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package informatis.ui.window;
|
||||
|
||||
import arc.*;
|
||||
import informatis.SUtils;
|
||||
import mindustry.game.*;
|
||||
import informatis.ui.*;
|
||||
import arc.graphics.*;
|
||||
@@ -94,11 +95,7 @@ public class CoreWindow extends Window implements Updatable {
|
||||
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);
|
||||
});
|
||||
image.clicked(() -> SUtils.moveCamera(core));
|
||||
HandCursorListener listener1 = new HandCursorListener();
|
||||
image.addListener(listener1);
|
||||
image.update(() -> {
|
||||
|
||||
@@ -136,7 +136,6 @@ public class MapEditorWindow extends Window implements Updatable {
|
||||
|
||||
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();
|
||||
|
||||
@@ -2,14 +2,12 @@ package informatis.ui.window;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.*;
|
||||
import arc.scene.*;
|
||||
import arc.scene.event.*;
|
||||
import informatis.core.*;
|
||||
import informatis.ui.*;
|
||||
import arc.graphics.Color;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.Bits;
|
||||
@@ -31,15 +29,14 @@ import static informatis.SUtils.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitWindow extends Window {
|
||||
int barSize = 6;
|
||||
float usedPayload;
|
||||
float barScrollPos;
|
||||
final Seq<Color> lastColors = new Seq<>();
|
||||
final Bits statuses = new Bits();
|
||||
Teamc latestTarget;
|
||||
ScrollPane barPane;
|
||||
|
||||
private int barSize = 6;
|
||||
private float usedPayload;
|
||||
private float barScrollPos;
|
||||
private final Bits statuses = new Bits();
|
||||
|
||||
public UnitWindow() {
|
||||
super(Icon.units, "unit");
|
||||
}
|
||||
@@ -48,41 +45,52 @@ public class UnitWindow extends Window {
|
||||
@Override
|
||||
protected void build(Table table) {
|
||||
table.top().background(Styles.black8);
|
||||
table.table(title -> {
|
||||
title.center();
|
||||
Image image = RectWidget.build();
|
||||
image.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;
|
||||
}
|
||||
image.setDrawable(region);
|
||||
table.table(profile -> {
|
||||
profile.table(title -> {
|
||||
title.center();
|
||||
Image image = RectWidget.build();
|
||||
image.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;
|
||||
}
|
||||
image.setDrawable(region);
|
||||
});
|
||||
image.clicked(()->{
|
||||
if(target == getTarget()) locked = !locked;
|
||||
target = getTarget();
|
||||
});
|
||||
title.add(image).size(iconMed).padRight(12f);
|
||||
Label label = title.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).get();
|
||||
label.clicked(() -> moveCamera(target));
|
||||
}).tooltip(tool -> {
|
||||
tool.table(Styles.black6, to -> {
|
||||
to.label(() -> target instanceof Unit u ? u.isPlayer() ? u.getPlayer().name : "AI" : "").visible(target instanceof Unit).row();
|
||||
to.label(() -> target.tileX() + ", " + target.tileY()).row();
|
||||
to.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "").visible(target instanceof Unit);
|
||||
});
|
||||
});
|
||||
image.clicked(()->{
|
||||
if(target == getTarget()) locked = !locked;
|
||||
target = getTarget();
|
||||
profile.table(weapon -> {
|
||||
weapon.add(new WeaponDisplay());
|
||||
});
|
||||
title.add(image).size(iconMed).padRight(12f);
|
||||
title.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(tool -> {
|
||||
tool.background(Styles.black6);
|
||||
tool.table(to -> {
|
||||
to.label(() -> target instanceof Unit u ? u.isPlayer() ? u.getPlayer().name : "AI" : "").row();
|
||||
to.label(() -> target.tileX() + ", " + target.tileY()).row();
|
||||
to.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "");
|
||||
}).margin(12f);
|
||||
}).margin(12f).row();
|
||||
|
||||
table.image().color((target == null ? player.unit() : target).team().color).visible(()->target instanceof Payloadc || target instanceof Statusc).height(4f).growX().row();
|
||||
table.image().color((target == null ? player.unit() : target).team().color).visible(()-> {
|
||||
if(target instanceof Payloadc payload) return payload.payloads().size > 0;
|
||||
if(target instanceof Statusc status) {
|
||||
Bits applied = status.statusBits();
|
||||
return applied == null || Vars.content.statusEffects().contains(effect -> applied.get(effect.id) && !effect.isHidden());
|
||||
}
|
||||
return false;
|
||||
}).height(4f).growX().row();
|
||||
|
||||
table.table(state -> {
|
||||
state.left();
|
||||
@@ -162,9 +170,9 @@ public class UnitWindow extends Window {
|
||||
rebuildStatus.get(t);
|
||||
}
|
||||
}).grow();
|
||||
}).pad(12f).growX().row();
|
||||
}).minHeight(0).growX().row();
|
||||
|
||||
table.image().color((target==null?player.unit():target).team().color).height(4f).growX().row();
|
||||
table.image().color((target == null ? player.unit() : target).team().color).height(4f).growX().row();
|
||||
|
||||
barPane = new ScrollPane(buildBarList(), Styles.noBarPane);
|
||||
barPane.update(() -> {
|
||||
@@ -191,20 +199,20 @@ public class UnitWindow extends Window {
|
||||
});
|
||||
barPane.setScrollingDisabledX(true);
|
||||
barPane.setScrollYForce(barScrollPos);
|
||||
|
||||
table.add(barPane).grow().padTop(12f);
|
||||
}
|
||||
|
||||
boolean show;
|
||||
Teamc targetCache;
|
||||
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.add(new SBar("+", Color.clear, 0)).height(4 * 8f).growX().get().clicked(()->{
|
||||
barSize++;
|
||||
barPane.setWidget(buildBarList());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -229,29 +237,17 @@ public class UnitWindow extends Window {
|
||||
Draw.color(Color.white);
|
||||
Draw.alpha(parentAlpha * color.a);
|
||||
BarInfo.BarData data = BarInfo.data.get(index);
|
||||
data.icon.draw(x, y, width, height);
|
||||
if (!hasMouse() && ScissorStack.push(Tmp.r1.set(ScissorStack.peek().x + x, ScissorStack.peek().y + y, width, height * data.number))) {
|
||||
Draw.color(data.color);
|
||||
if(hasMouse()) getDrawable().draw(x, y, width, height);
|
||||
else {
|
||||
data.icon.draw(x, y, width, height);
|
||||
ScissorStack.pop();
|
||||
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.addListener(new InputListener(){
|
||||
@Override
|
||||
public void enter(InputEvent event, float x, float y, int pointer, Element fromActor){
|
||||
icon.setDrawable(Icon.cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(InputEvent event, float x, float y, int pointer, Element fromActor){
|
||||
icon.setDrawable(BarInfo.data.size >= index ? Icon.none : BarInfo.data.get(index).icon);
|
||||
}
|
||||
});
|
||||
icon.clicked(()->{
|
||||
if(barSize > 0) barSize--;
|
||||
barPane.setWidget(buildBarList());
|
||||
});
|
||||
icon.setDrawable(BarInfo.data.get(index).icon);
|
||||
bar.add(icon).size(iconMed * 0.75f).padLeft(8f);
|
||||
});
|
||||
@@ -265,36 +261,18 @@ public class UnitWindow extends Window {
|
||||
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){
|
||||
o.add(new Image(weapon.region){
|
||||
@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);
|
||||
super.draw();
|
||||
}
|
||||
}).size(iconLarge);
|
||||
}).size(iconLarge).scaling(Scaling.bounded);
|
||||
}),
|
||||
new Table(h -> {
|
||||
h.defaults().growX().height(9f).width(iconLarge).padTop(18f);
|
||||
@@ -306,6 +284,7 @@ public class UnitWindow extends Window {
|
||||
})
|
||||
);
|
||||
}).pad(4);
|
||||
if(r % 4 == 0) tt.row();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,8 +4,10 @@ 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.*;
|
||||
@@ -21,7 +23,7 @@ public class Window extends Table {
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -31,27 +33,33 @@ public class Window extends Table {
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
window = this;
|
||||
id = WindowManager.register(this);
|
||||
|
||||
titleBar();
|
||||
pane(t -> {
|
||||
row();
|
||||
ScrollPane pane = new ScrollPane(new Table(t -> {
|
||||
t.setBackground(Styles.black5);
|
||||
t.top().left();
|
||||
build(t);
|
||||
}).grow().get().setScrollingDisabled(true, true);
|
||||
}), 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();
|
||||
|
||||
setPosition(Core.graphics.getWidth() / 2f - getWidth() / 2f, Core.graphics.getHeight() / 2f - getHeight() / 2f);
|
||||
id = WindowManager.register(this);
|
||||
|
||||
visible(() -> shown);
|
||||
|
||||
update(() -> {
|
||||
if(x > Core.graphics.getWidth() - getWidth()/2) setPosition(Core.graphics.getWidth() - getWidth()/2, y);
|
||||
else if(x < -getWidth()/2) setPosition(-getWidth()/2, y);
|
||||
|
||||
if(y > Core.graphics.getHeight() - getHeight()/2) setPosition(x, Core.graphics.getHeight() - getHeight()/2);
|
||||
else if(y < -getHeight()/2) setPosition(x, -getHeight()/2);
|
||||
});
|
||||
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){
|
||||
@@ -60,20 +68,13 @@ public class Window extends Table {
|
||||
|
||||
protected void titleBar(){
|
||||
table(t -> {
|
||||
// icon and title
|
||||
t.table(Tex.buttonEdge1, b -> {
|
||||
t.pane(b -> {
|
||||
b.left();
|
||||
b.setBackground(Tex.buttonEdge1);
|
||||
b.image(icon.getRegion()).size(20f).padLeft(15);
|
||||
b.pane(Styles.noBarPane, p -> {
|
||||
p.left();
|
||||
p.add(Core.bundle.get("window."+name+".name")).padLeft(20);
|
||||
}).grow().get().setScrollingDisabled(false, true);
|
||||
}).grow();
|
||||
|
||||
// exit button
|
||||
t.table(Tex.buttonEdge3, b -> {
|
||||
b.button(Icon.cancel, Styles.emptyi, () -> shown = false);
|
||||
}).width(80f).growY();
|
||||
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;
|
||||
@@ -91,18 +92,15 @@ public class Window extends Table {
|
||||
@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(48f).growX().row();
|
||||
}).height(topBarHeight).growX();
|
||||
}
|
||||
|
||||
protected void bottomBar(){
|
||||
row();
|
||||
table(Styles.black5, t -> {
|
||||
t.table().growX();
|
||||
t.table(Icon.resizeSmall, r -> {
|
||||
|
||||
Reference in New Issue
Block a user