mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 12:09:27 +02:00
fixed pane focus issue
This commit is contained in:
@@ -3,6 +3,7 @@ package informatis.ui;
|
|||||||
import arc.math.geom.Vec2;
|
import arc.math.geom.Vec2;
|
||||||
import arc.scene.Element;
|
import arc.scene.Element;
|
||||||
import arc.scene.ui.ScrollPane;
|
import arc.scene.ui.ScrollPane;
|
||||||
|
import arc.util.Log;
|
||||||
|
|
||||||
import static arc.Core.input;
|
import static arc.Core.input;
|
||||||
import static arc.Core.scene;
|
import static arc.Core.scene;
|
||||||
@@ -14,22 +15,24 @@ public class OverScrollPane extends ScrollPane {
|
|||||||
public OverScrollPane(Element widget, ScrollPaneStyle style, Vec2 scrollPos){
|
public OverScrollPane(Element widget, ScrollPaneStyle style, Vec2 scrollPos){
|
||||||
super(widget, style);
|
super(widget, style);
|
||||||
this.scrollPos = scrollPos;
|
this.scrollPos = scrollPos;
|
||||||
|
|
||||||
update(() -> {
|
|
||||||
if (hasScroll()) {
|
|
||||||
Element result = scene.hit(input.mouseX(), input.mouseY(), true);
|
|
||||||
if (result == null || !result.isDescendantOf(this)) {
|
|
||||||
scene.setScrollFocus(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
scrollPos.x = getScrollX();
|
|
||||||
scrollPos.y = getScrollY();
|
|
||||||
});
|
|
||||||
setOverscroll(false, false);
|
|
||||||
setScrollYForce(scrollPos.x);
|
setScrollYForce(scrollPos.x);
|
||||||
setScrollYForce(scrollPos.y);
|
setScrollYForce(scrollPos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Element update(Runnable r) {
|
||||||
|
Element result = hit(input.mouseX(), input.mouseY(), true);
|
||||||
|
if (result == null || !result.isDescendantOf(this)) {
|
||||||
|
//scene.setScrollFocus(null);
|
||||||
|
cancelTouchFocus();
|
||||||
|
}
|
||||||
|
Log.info(result);
|
||||||
|
scrollPos.x = getScrollX();
|
||||||
|
scrollPos.y = getScrollY();
|
||||||
|
|
||||||
|
return super.update(r);
|
||||||
|
}
|
||||||
|
|
||||||
public OverScrollPane disableScroll(boolean x, boolean y) {
|
public OverScrollPane disableScroll(boolean x, boolean y) {
|
||||||
setScrollingDisabled(x, y);
|
setScrollingDisabled(x, y);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
30
src/informatis/ui/widgets/RectWidget.java
Normal file
30
src/informatis/ui/widgets/RectWidget.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package informatis.ui.widgets;
|
||||||
|
|
||||||
|
import arc.graphics.g2d.Draw;
|
||||||
|
import arc.graphics.g2d.Lines;
|
||||||
|
import arc.scene.ui.Image;
|
||||||
|
import arc.scene.ui.layout.Scl;
|
||||||
|
import mindustry.graphics.Pal;
|
||||||
|
|
||||||
|
import static informatis.SVars.locked;
|
||||||
|
|
||||||
|
public class RectWidget {
|
||||||
|
public static Image build() {
|
||||||
|
return build(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image build(float size) {
|
||||||
|
return new Image() {
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package informatis.ui.window;
|
package informatis.ui.window;
|
||||||
|
|
||||||
import arc.math.Mathf;
|
import arc.Core;
|
||||||
|
import arc.scene.Element;
|
||||||
import informatis.core.*;
|
import informatis.core.*;
|
||||||
import informatis.ui.*;
|
import informatis.ui.*;
|
||||||
import arc.graphics.Color;
|
import arc.graphics.Color;
|
||||||
@@ -12,6 +13,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.Bits;
|
import arc.struct.Bits;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import informatis.ui.widgets.RectWidget;
|
||||||
import mindustry.Vars;
|
import mindustry.Vars;
|
||||||
import mindustry.core.UI;
|
import mindustry.core.UI;
|
||||||
import mindustry.entities.units.WeaponMount;
|
import mindustry.entities.units.WeaponMount;
|
||||||
@@ -23,15 +25,24 @@ import mindustry.ui.Styles;
|
|||||||
import mindustry.world.blocks.ConstructBlock;
|
import mindustry.world.blocks.ConstructBlock;
|
||||||
import mindustry.world.blocks.payloads.Payload;
|
import mindustry.world.blocks.payloads.Payload;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static informatis.SVars.*;
|
import static informatis.SVars.*;
|
||||||
import static informatis.SUtils.*;
|
import static informatis.SUtils.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UnitWindow extends Window {
|
class UnitWindow extends Window {
|
||||||
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
final Seq<Color> lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear);
|
||||||
final Rect scissor = new Rect();
|
final Rect scissor = new Rect();
|
||||||
Seq<Table> bars = new Seq<>(); //temp
|
Seq<Table> bars = new Seq<>(); //temp
|
||||||
Vec2 scrollPos = new Vec2(0, 0);
|
Vec2 scrollPos = new Vec2(0, 0);
|
||||||
|
Teamc latestTarget = getTarget();
|
||||||
|
int barSize = 6;
|
||||||
|
ScrollPane barPane;
|
||||||
|
|
||||||
|
private float barScrollPos;
|
||||||
|
|
||||||
public UnitWindow() {
|
public UnitWindow() {
|
||||||
super(Icon.units, "unit");
|
super(Icon.units, "unit");
|
||||||
@@ -42,27 +53,17 @@ class UnitWindow extends Window {
|
|||||||
@Override
|
@Override
|
||||||
protected void build(Table table) {
|
protected void build(Table table) {
|
||||||
scrollPos = new Vec2(0, 0);
|
scrollPos = new Vec2(0, 0);
|
||||||
|
bars = new Seq<>();
|
||||||
|
|
||||||
table.top().background(Styles.black8);
|
table.top().background(Styles.black8);
|
||||||
table.table(tt -> {
|
table.table(tt -> {
|
||||||
tt.center();
|
tt.center();
|
||||||
Image image = new Image() {
|
Image image = RectWidget.build();
|
||||||
@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(()->{
|
image.update(()->{
|
||||||
TextureRegion region = clear;
|
TextureRegion region = clear;
|
||||||
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
|
if (target instanceof Unit u && u.type != null) region = u.type.uiIcon;
|
||||||
else if (target instanceof Building b) {
|
else if (target instanceof Building b) {
|
||||||
if (target instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon;
|
if (b instanceof ConstructBlock.ConstructBuild cb) region = cb.current.uiIcon;
|
||||||
else if (b.block != null) region = b.block.uiIcon;
|
else if (b.block != null) region = b.block.uiIcon;
|
||||||
}
|
}
|
||||||
image.setDrawable(region);
|
image.setDrawable(region);
|
||||||
@@ -71,7 +72,6 @@ class UnitWindow extends Window {
|
|||||||
if(target == getTarget()) locked = !locked;
|
if(target == getTarget()) locked = !locked;
|
||||||
target = getTarget();
|
target = getTarget();
|
||||||
});
|
});
|
||||||
|
|
||||||
tt.add(image).size(iconMed).padRight(12f);
|
tt.add(image).size(iconMed).padRight(12f);
|
||||||
tt.label(() -> {
|
tt.label(() -> {
|
||||||
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
|
if (target instanceof Unit u && u.type != null) return u.type.localizedName;
|
||||||
@@ -81,24 +81,54 @@ class UnitWindow extends Window {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}).color(Pal.accent);
|
}).color(Pal.accent);
|
||||||
}).tooltip((to -> {
|
}).tooltip(tool -> {
|
||||||
to.background(Styles.black6);
|
tool.background(Styles.black6);
|
||||||
to.label(() -> target instanceof Unit u && u.isPlayer() ? u.getPlayer().name() : "AI").row();
|
tool.table().update(to -> {
|
||||||
to.label(() -> target == null ? "(" + 0 + ", " + 0 + ")" : "(" + Strings.fixed(target.x() / tilesize, 2) + ", " + Strings.fixed(target.y() / tilesize, 2) + ")").row();
|
to.clear();
|
||||||
to.label(() -> target instanceof Unit u ? "[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor" : "");
|
if(target instanceof Unit u) {
|
||||||
})).margin(12f).row();
|
to.add(u.isPlayer() ? u.getPlayer().name : "AI").row();
|
||||||
table.image().height(4f).color((target==null?player.unit():target).team().color).growX().row();
|
to.add(target.tileX() + ", " + target.tileY()).row();
|
||||||
table.add(new OverScrollPane(new Table(bars -> {
|
to.add("[accent]"+ Strings.fixed(u.armor, 0) + "[] Armor");
|
||||||
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();
|
}).margin(12f);
|
||||||
}), Styles.noBarPane, scrollPos).disableScroll(true, false)).growX().padTop(12f);
|
}).margin(12f).row();
|
||||||
|
table.image().height(4f).color((target==null?player.unit():target).team().color).growX().row();
|
||||||
|
barPane = new ScrollPane(buildBarList(), Styles.noBarPane);
|
||||||
|
barPane.update(() -> {
|
||||||
|
if(latestTarget != target) {
|
||||||
|
latestTarget = target;
|
||||||
|
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.add(barPane).growX().padTop(12f);
|
||||||
|
}
|
||||||
|
|
||||||
|
Table buildBarList() {
|
||||||
|
return new Table(table -> {
|
||||||
|
table.top();
|
||||||
|
bars.clear();
|
||||||
|
for(int i = 0; i < barSize; i++) addBar();
|
||||||
|
bars.each(bar -> {
|
||||||
|
table.add(bar).growX().get().clicked(()->{
|
||||||
|
if(barSize>0) barSize--;
|
||||||
|
barPane.setWidget(buildBarList());
|
||||||
|
});
|
||||||
|
table.row();
|
||||||
|
});
|
||||||
|
table.add(new SBar(() -> "+", () -> Color.clear, () -> 0)).height(4 * 8f).growX().get().clicked(()->{
|
||||||
|
barSize++;
|
||||||
|
barPane.setWidget(buildBarList());
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void addBar() {
|
void addBar() {
|
||||||
@@ -106,18 +136,18 @@ class UnitWindow extends Window {
|
|||||||
bars.add(new Table(bar -> {
|
bars.add(new Table(bar -> {
|
||||||
bar.add(new SBar(
|
bar.add(new SBar(
|
||||||
() -> {
|
() -> {
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
||||||
return data == null ? "[lightgray]<Empty>[]" : data.name;
|
return data == null ? "[lightgray]<Empty>[]" : data.name;
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
||||||
if (index >= lastColors.size) lastColors.size = index+1;
|
if (index >= lastColors.size) lastColors.size = index+1;
|
||||||
if (data == null) return lastColors.get(index);
|
if (data == null) return lastColors.get(index);
|
||||||
if (data.color != Color.clear) lastColors.set(index, data.color);
|
if (data.color != Color.clear) lastColors.set(index, data.color);
|
||||||
return lastColors.get(index);
|
return lastColors.get(index);
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
||||||
return data == null ? 0 : data.number;
|
return data == null ? 0 : data.number;
|
||||||
}
|
}
|
||||||
)).height(4 * 8f).growX();
|
)).height(4 * 8f).growX();
|
||||||
@@ -126,7 +156,7 @@ class UnitWindow extends Window {
|
|||||||
public void draw() {
|
public void draw() {
|
||||||
validate();
|
validate();
|
||||||
|
|
||||||
BarInfo.BarData data = index >= BarInfo.data.size ? null : BarInfo.data.get(index);
|
BarInfo.BarData data = index >= BarInfo.data.size || index >= barSize ? null : BarInfo.data.get(index);
|
||||||
Draw.color(Color.white);
|
Draw.color(Color.white);
|
||||||
Draw.alpha(parentAlpha * color.a);
|
Draw.alpha(parentAlpha * color.a);
|
||||||
if(data == null) {
|
if(data == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user