Merge branch 'master' of https://github.com/Anuken/Mindustry into 7.0-features

 Conflicts:
	core/src/mindustry/ui/dialogs/PlanetDialog.java
This commit is contained in:
Anuken
2021-08-18 15:04:30 -04:00
86 changed files with 942 additions and 740 deletions

View File

@@ -62,6 +62,10 @@ public class Bar extends Element{
update(() -> this.name = name.get());
}
public void snap(){
lastValue = value = fraction.get();
}
public Bar outline(Color color, float stroke){
outlineColor.set(color);
outlineRadius = Scl.scl(stroke);

View File

@@ -74,19 +74,19 @@ public class Fonts{
largeIcons.clear();
FreeTypeFontParameter param = fontParameter();
Core.assets.load("default", Font.class, new FreeTypeFontLoaderParameter(mainFont, param)).loaded = f -> Fonts.def = (Font)f;
Core.assets.load("default", Font.class, new FreeTypeFontLoaderParameter(mainFont, param)).loaded = f -> Fonts.def = f;
Core.assets.load("icon", Font.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{
size = 30;
incremental = true;
characters = "\0";
}})).loaded = f -> Fonts.icon = (Font)f;
}})).loaded = f -> Fonts.icon = f;
Core.assets.load("iconLarge", Font.class, new FreeTypeFontLoaderParameter("fonts/icon.ttf", new FreeTypeFontParameter(){{
size = 48;
incremental = false;
characters = "\0" + Iconc.all;
borderWidth = 5f;
borderColor = Color.darkGray;
}})).loaded = f -> Fonts.iconLarge = (Font)f;
}})).loaded = f -> Fonts.iconLarge = f;
}
public static TextureRegion getLargeIcon(String name){

View File

@@ -50,7 +50,7 @@ public class ItemsDisplay extends Table{
label.actions(Actions.color(Color.white, 0.75f, Interp.fade));
}
}
}).get().setScrollingDisabled(true, false), false).setDuration(0.3f);
}).scrollX(false), false).setDuration(0.3f);
c.button("@globalitems", Icon.downOpen, Styles.clearTogglet, col::toggle).update(t -> {
t.setChecked(col.isCollapsed());

View File

@@ -1,59 +1,6 @@
package mindustry.ui;
import arc.func.*;
import arc.graphics.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import mindustry.gen.*;
//TODO remove, unlikely to be used anywhere else.
public class SearchBar{
public static <T> Table add(Table parent, Seq<T> list, Func<String, String> queryf,
Func<T, String> namef, Cons2<Table, T> itemc, boolean show){
Table[] pane = {null};
Cons<String> rebuild = str -> {
String query = queryf.get(str);
pane[0].clear();
boolean any = false;
for(T item : list){
if(query.isEmpty() || matches(query, namef.get(item))){
any = true;
itemc.get(pane[0], item);
}
}
if(!any){
pane[0].add("@none.found").color(Color.lightGray).pad(4);
}
};
if(show){
parent.table(search -> {
search.image(Icon.zoom).padRight(8f);
search.field("", rebuild).growX();
}).fillX().padBottom(4);
}
parent.row();
parent.pane(table -> {
pane[0] = table;
rebuild.get("");
}).get().setScrollingDisabled(true, false);
return pane[0];
}
public static <T> Table add(Table parent, Seq<T> list, Func<String, String> queryf, Func<T, String> namef, Cons2<Table, T> itemc){
return add(parent, list, queryf, namef, itemc, true);
}
public static <T> Table add(Table parent, Seq<T> list, Func<T, String> namef, Cons2<Table, T> itemc, boolean show){
return add(parent, list, String::toLowerCase, namef, itemc, show);
}
/** Match a list item with the search query, case insensitive */
public static boolean matches(String query, String name){
return name != null && !name.isEmpty() && name.toLowerCase().contains(query);
}
}

View File

@@ -126,7 +126,7 @@ public class CustomRulesDialog extends BaseDialog{
void setup(){
cont.clear();
cont.pane(m -> main = m).get().setScrollingDisabled(true, false);
cont.pane(m -> main = m).scrollX(false);
main.margin(10f);
main.button("@settings.reset", () -> {
rules = resetter.get();
@@ -273,7 +273,7 @@ public class CustomRulesDialog extends BaseDialog{
t.add(text).left().padRight(5);
t.field((prov.get()) + "", s -> cons.get(Strings.parseInt(s)))
.padRight(100f)
.valid(f -> Strings.parseInt(f) >= min && Strings.parseInt(f) <= max).width(120f).left().addInputDialog();
.valid(f -> Strings.parseInt(f) >= min && Strings.parseInt(f) <= max).width(120f).left();
}).padTop(0).row();
}
@@ -285,7 +285,7 @@ public class CustomRulesDialog extends BaseDialog{
t.field((integer ? (int)prov.get() : prov.get()) + "", s -> cons.get(Strings.parseFloat(s)))
.padRight(100f)
.update(a -> a.setDisabled(!condition.get()))
.valid(f -> Strings.canParsePositiveFloat(f) && Strings.parseFloat(f) >= min && Strings.parseFloat(f) <= max).width(120f).left().addInputDialog();
.valid(f -> Strings.canParsePositiveFloat(f) && Strings.parseFloat(f) >= min && Strings.parseFloat(f) <= max).width(120f).left();
}).padTop(0);
main.row();
}
@@ -309,7 +309,7 @@ public class CustomRulesDialog extends BaseDialog{
Cell<TextField> field(Table table, float value, Floatc setter){
return table.field(Strings.autoFixed(value, 2), v -> setter.get(Strings.parseFloat(v)))
.valid(Strings::canParsePositiveFloat)
.size(90f, 40f).pad(2f).addInputDialog();
.size(90f, 40f).pad(2f);
}
void weatherDialog(){

View File

@@ -67,7 +67,7 @@ public class JoinDialog extends BaseDialog{
TextField field = add.cont.field(Core.settings.getString("ip"), text -> {
Core.settings.put("ip", text);
}).size(320f, 54f).maxTextLength(100).addInputDialog().get();
}).size(320f, 54f).maxTextLength(100).get();
add.cont.row();
add.buttons.defaults().size(140f, 60f).pad(4f);
@@ -287,7 +287,7 @@ public class JoinDialog extends BaseDialog{
t.field(Core.settings.getString("name"), text -> {
player.name(text);
Core.settings.put("name", text);
}).grow().pad(8).addInputDialog(maxNameLength);
}).grow().pad(8).maxTextLength(maxNameLength);
ImageButton button = t.button(Tex.whiteui, Styles.clearFulli, 40, () -> {
new PaletteDialog().show(color -> {

View File

@@ -131,7 +131,7 @@ public class LaunchLoadoutDialog extends BaseDialog{
}
}).growX().get().setScrollingDisabled(true, false);
}).growX().scrollX(false);
cont.row();
cont.pane(items);

View File

@@ -69,7 +69,7 @@ public class ModsDialog extends BaseDialog{
browser.cont.pane(tablebrow -> {
tablebrow.margin(10f).top();
browserTable = tablebrow;
}).get().setScrollingDisabled(true, false);
}).scrollX(false);
browser.addCloseButton();
browser.onResize(this::rebuildBrowser);
@@ -208,90 +208,113 @@ public class ModsDialog extends BaseDialog{
if(!mods.list().isEmpty()){
boolean[] anyDisabled = {false};
SearchBar.add(cont, mods.list(),
mod -> mod.meta.displayName(),
(table, mod) -> {
if(!mod.enabled() && !anyDisabled[0] && mods.list().size > 0){
anyDisabled[0] = true;
table.row();
table.image().growX().height(4f).pad(6f).color(Pal.gray);
table.row();
}
Table[] pane = {null};
table.button(t -> {
t.top().left();
t.margin(12f);
Cons<String> rebuild = query -> {
pane[0].clear();
boolean any = false;
for(LoadedMod item : mods.list()){
if(Strings.matches(query, item.meta.displayName())){
any = true;
if(!item.enabled() && !anyDisabled[0] && mods.list().size > 0){
anyDisabled[0] = true;
pane[0].row();
pane[0].image().growX().height(4f).pad(6f).color(Pal.gray).row();
}
t.defaults().left().top();
t.table(title -> {
title.left();
pane[0].button(t -> {
t.top().left();
t.margin(12f);
title.add(new BorderImage(){{
if(mod.iconTexture != null){
setDrawable(new TextureRegion(mod.iconTexture));
}else{
setDrawable(Tex.nomap);
}
border(Pal.accent);
}}).size(h - 8f).padTop(-8f).padLeft(-8f).padRight(8f);
t.defaults().left().top();
t.table(title1 -> {
title1.left();
title.table(text -> {
boolean hideDisabled = !mod.isSupported() || mod.hasUnmetDependencies() || mod.hasContentErrors();
title1.add(new BorderImage(){{
if(item.iconTexture != null){
setDrawable(new TextureRegion(item.iconTexture));
}else{
setDrawable(Tex.nomap);
}
border(Pal.accent);
}}).size(h - 8f).padTop(-8f).padLeft(-8f).padRight(8f);
text.add("[accent]" + Strings.stripColors(mod.meta.displayName()) + "\n[lightgray]v" + Strings.stripColors(trimText(mod.meta.version)) + (mod.enabled() || hideDisabled ? "" : "\n" + Core.bundle.get("mod.disabled") + ""))
title1.table(text -> {
boolean hideDisabled = !item.isSupported() || item.hasUnmetDependencies() || item.hasContentErrors();
text.add("[accent]" + Strings.stripColors(item.meta.displayName()) + "\n[lightgray]v" + Strings.stripColors(trimText(item.meta.version)) + (item.enabled() || hideDisabled ? "" : "\n" + Core.bundle.get("mod.disabled") + ""))
.wrap().top().width(300f).growX().left();
text.row();
if(mod.isOutdated()){
text.labelWrap("@mod.outdated").growX();
text.row();
}else if(!mod.isSupported()){
text.labelWrap(Core.bundle.format("mod.requiresversion", mod.meta.minGameVersion)).growX();
text.row();
}else if(mod.hasUnmetDependencies()){
text.labelWrap(Core.bundle.format("mod.missingdependencies", mod.missingDependencies.toString(", "))).growX();
t.row();
}else if(mod.hasContentErrors()){
text.labelWrap("@mod.erroredcontent").growX();
text.row();
}else if(mod.meta.hidden){
text.labelWrap("@mod.multiplayer.compatible").growX();
text.row();
}
}).top().growX();
title.add().growX();
}).growX().growY().left();
if(item.isOutdated()){
text.labelWrap("@mod.outdated").growX();
text.row();
}else if(!item.isSupported()){
text.labelWrap(Core.bundle.format("mod.requiresversion", item.meta.minGameVersion)).growX();
text.row();
}else if(item.hasUnmetDependencies()){
text.labelWrap(Core.bundle.format("mod.missingdependencies", item.missingDependencies.toString(", "))).growX();
t.row();
}else if(item.hasContentErrors()){
text.labelWrap("@mod.erroredcontent").growX();
text.row();
}else if(item.meta.hidden){
text.labelWrap("@mod.multiplayer.compatible").growX();
text.row();
}
}).top().growX();
t.table(right -> {
right.right();
right.button(mod.enabled() ? Icon.downOpen : Icon.upOpen, Styles.clearPartiali, () -> {
mods.setEnabled(mod, !mod.enabled());
setup();
}).size(50f).disabled(!mod.isSupported());
title1.add().growX();
}).growX().growY().left();
right.button(mod.hasSteamID() ? Icon.link : Icon.trash, Styles.clearPartiali, () -> {
if(!mod.hasSteamID()){
ui.showConfirm("@confirm", "@mod.remove.confirm", () -> {
mods.removeMod(mod);
setup();
});
}else{
platform.viewListing(mod);
}
}).size(50f);
t.table(right -> {
right.right();
right.button(item.enabled() ? Icon.downOpen : Icon.upOpen, Styles.clearPartiali, () -> {
mods.setEnabled(item, !item.enabled());
setup();
}).size(50f).disabled(!item.isSupported());
if(steam && !mod.hasSteamID()){
right.row();
right.button(Icon.export, Styles.clearPartiali, () -> {
platform.publish(mod);
right.button(item.hasSteamID() ? Icon.link : Icon.trash, Styles.clearPartiali, () -> {
if(!item.hasSteamID()){
ui.showConfirm("@confirm", "@mod.remove.confirm", () -> {
mods.removeMod(item);
setup();
});
}else{
platform.viewListing(item);
}
}).size(50f);
}
}).growX().right().padRight(-8f).padTop(-8f);
}, Styles.clearPartialt, () -> showMod(mod)).size(w, h).growX().pad(4f);
table.row();
}, !mobile || Core.graphics.isPortrait()).margin(10f).top();
if(steam && !item.hasSteamID()){
right.row();
right.button(Icon.export, Styles.clearPartiali, () -> {
platform.publish(item);
}).size(50f);
}
}).growX().right().padRight(-8f).padTop(-8f);
}, Styles.clearPartialt, () -> showMod(item)).size(w, h).growX().pad(4f);
pane[0].row();
}
}
if(!any){
pane[0].add("@none.found").color(Color.lightGray).pad(4);
}
};
if(!mobile || Core.graphics.isPortrait()){
cont.table(search -> {
search.image(Icon.zoom).padRight(8f);
search.field("", rebuild).growX();
}).fillX().padBottom(4);
}
cont.row();
cont.pane(table1 -> {
pane[0] = table1.margin(10f).top();
rebuild.get("");
}).scrollX(false);
}else{
cont.table(Styles.black6, t -> t.add("@mods.none")).height(80f);
}

View File

@@ -27,7 +27,6 @@ import mindustry.graphics.*;
import mindustry.graphics.g3d.*;
import mindustry.graphics.g3d.PlanetGrid.*;
import mindustry.input.*;
import mindustry.io.legacy.*;
import mindustry.maps.*;
import mindustry.type.*;
import mindustry.ui.*;
@@ -65,7 +64,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
public boolean showed = false, sectorsShown;
public String searchText = "";
public Table sectorTop = new Table(), notifs;
public Table sectorTop = new Table(), notifs = new Table();
public Label hoverLabel = new Label("");
public PlanetDialog(){
@@ -131,7 +130,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY){
if(event.targetActor == PlanetDialog.this){
zoom = Mathf.clamp(zoom + y / 10f, planets.planet.minZoom, 2f);
zoom = Mathf.clamp(zoom + amountY / 10f, planets.planet.minZoom, 2f);
}
return true;
}
@@ -166,16 +165,6 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
return this;
}
//load legacy research
if(Core.settings.has("unlocks") && !Core.settings.has("junction-unlocked")){
Core.app.post(() -> {
ui.showCustomConfirm("@research", "@research.legacy", "@research.load", "@research.discard", () -> {
LegacyIO.readResearch();
Core.settings.remove("unlocks");
}, () -> Core.settings.remove("unlocks"));
});
}
rebuildButtons();
mode = look;
selected = hovered = launchSector = null;
@@ -545,7 +534,8 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
}),
new Table(c -> {
if(!(graphics.isPortrait() && mobile) && planets.planet.sectors.contains(Sector::hasBase)){
c.visible(() -> !(graphics.isPortrait() && mobile));
if(planets.planet.sectors.contains(Sector::hasBase)){
int attacked = planets.planet.sectors.count(Sector::isAttacked);
//sector notifications & search
@@ -571,8 +561,9 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
})).grow();
}
//TODO
void rebuildList(){
if(notifs == null) return;
notifs.clear();
var all = planets.planet.sectors.select(Sector::hasBase);
@@ -586,7 +577,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
s.field(searchText, t -> {
searchText = t;
readd[0].run();
}).growX().height(50f).addInputDialog();
}).growX().height(50f);
}).growX().row();
Table con = p.table().growX().get();
@@ -632,7 +623,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{
};
readd[0].run();
}).grow().get().setScrollingDisabled(true, false);
}).grow().scrollX(false);
}
@Override

View File

@@ -41,7 +41,7 @@ public class SchematicsDialog extends BaseDialog{
public SchematicsDialog(){
super("@schematics");
Core.assets.load("sprites/schematic-background.png", Texture.class).loaded = t -> ((Texture)t).setWrap(TextureWrap.repeat);
Core.assets.load("sprites/schematic-background.png", Texture.class).loaded = t -> t.setWrap(TextureWrap.repeat);
tags = Core.settings.getJson("schematic-tags", Seq.class, String.class, Seq::new);
@@ -69,7 +69,7 @@ public class SchematicsDialog extends BaseDialog{
searchField = s.field(search, res -> {
search = res;
rebuildPane.run();
}).growX().addInputDialog().get();
}).growX().get();
}).fillX().padBottom(4);
cont.row();
@@ -97,7 +97,7 @@ public class SchematicsDialog extends BaseDialog{
}
};
rebuildTags.run();
}).fillX().height(tagh).get().setScrollingDisabled(false, true);
}).fillX().height(tagh).scrollY(false);
in.button(Icon.pencilSmall, () -> {
showAllTags();
@@ -164,12 +164,12 @@ public class SchematicsDialog extends BaseDialog{
cont.table(tags -> buildTags(s, tags, false)).maxWidth(400f).fillX().left().row();
cont.margin(30).add("@name").padRight(6f);
TextField nameField = cont.field(s.name(), null).size(400f, 55f).addInputDialog().left().get();
TextField nameField = cont.field(s.name(), null).size(400f, 55f).left().get();
cont.row();
cont.margin(30).add("@editor.description").padRight(6f);
TextField descField = cont.area(s.description(), Styles.areaField, t -> {}).size(400f, 140f).left().addInputDialog().get();
TextField descField = cont.area(s.description(), Styles.areaField, t -> {}).size(400f, 140f).left().get();
Runnable accept = () -> {
s.tags.put("name", nameField.getText());
@@ -246,7 +246,7 @@ public class SchematicsDialog extends BaseDialog{
};
rebuildPane.run();
}).grow().get().setScrollingDisabled(true, false);
}).grow().scrollX(false);
}
public void showInfo(Schematic schematic){
@@ -573,7 +573,7 @@ public class SchematicsDialog extends BaseDialog{
});
}
}).fillX().left().height(tagh).get().setScrollingDisabled(false, true);
}).fillX().left().height(tagh).scrollY(false);
t.button(Icon.addSmall, () -> {
var dialog = new BaseDialog("@schematic.addtag");

View File

@@ -48,12 +48,12 @@ public class HintsFragment extends Fragment{
}else if(!current.show()){ //current became hidden
hide();
}
}else if(hints.size > 0 && !renderer.isCutscene()){
}else if(hints.size > 0){
//check one hint each frame to see if it should be shown.
Hint hint = hints.find(Hint::show);
if(hint != null && hint.complete()){
hints.remove(hint);
}else if(hint != null){
}else if(hint != null && !renderer.isCutscene() && state.isGame() && control.saves.getTotalPlaytime() > 8000){
display(hint);
}else{
//moused over a derelict structure
@@ -92,7 +92,7 @@ public class HintsFragment extends Fragment{
hints.sort(Hint::order);
Hint first = hints.find(Hint::show);
if(first != null){
if(first != null && !renderer.isCutscene() && state.isGame()){
hints.remove(first);
display(first);
}

View File

@@ -56,6 +56,10 @@ public class LoadingFragment extends Fragment{
bar.set(() -> ((int)(progress.get() * 100) + "%"), progress, Pal.accent);
}
public void snapProgress(){
bar.snap();
}
public void setProgress(float progress){
progValue = progress;
if(!bar.visible){

View File

@@ -52,7 +52,7 @@ public class PlayerListFragment extends Fragment{
search.setMessageText(Core.bundle.get("players.search"));
pane.row();
pane.pane(content).grow().get().setScrollingDisabled(true, false);
pane.pane(content).grow().scrollX(false);
pane.row();
pane.table(menu -> {