More workshop implementation
This commit is contained in:
@@ -37,6 +37,18 @@ public class Bar extends Element{
|
||||
});
|
||||
}
|
||||
|
||||
public Bar(){
|
||||
|
||||
}
|
||||
|
||||
public void set(Supplier<String> name, FloatProvider fraction, Color color){
|
||||
this.fraction = fraction;
|
||||
this.lastValue = fraction.get();
|
||||
this.blinkColor.set(color);
|
||||
setColor(color);
|
||||
update(() -> this.name = name.get());
|
||||
}
|
||||
|
||||
public Bar blink(Color color){
|
||||
blinkColor.set(color);
|
||||
return this;
|
||||
@@ -44,6 +56,8 @@ public class Bar extends Element{
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
if(fraction == null) return;
|
||||
|
||||
float computed = Mathf.clamp(fraction.get());
|
||||
if(!Mathf.isEqual(lastValue, computed)){
|
||||
blink = 1f;
|
||||
@@ -73,7 +87,7 @@ public class Bar extends Element{
|
||||
|
||||
Draw.color();
|
||||
|
||||
BitmapFont font = Fonts.def;
|
||||
BitmapFont font = Fonts.outline;
|
||||
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
|
||||
lay.setText(font, name);
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.assets.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.scene.ui.*;
|
||||
import io.anuke.arc.scene.ui.layout.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.core.Platform.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.platform;
|
||||
|
||||
public class BrowseMapsDialog extends FloatingDialog{
|
||||
|
||||
public BrowseMapsDialog(){
|
||||
super("$maps.browse");
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
void setup(){
|
||||
cont.clear();
|
||||
|
||||
cont.addImage(Icon.refresh);
|
||||
platform.findMaps("", list -> {
|
||||
Table maps = new Table();
|
||||
maps.marginRight(24);
|
||||
|
||||
ScrollPane pane = new ScrollPane(maps);
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
int maxwidth = Mathf.clamp((int)(Core.graphics.getWidth() / Scl.scl(230)), 1, 8);
|
||||
float mapsize = 200f;
|
||||
|
||||
int i = 0;
|
||||
for(PostedMap map : list){
|
||||
|
||||
if(i % maxwidth == 0){
|
||||
maps.row();
|
||||
}
|
||||
|
||||
TextButton button = maps.addButton("", Styles.cleart, map::openPage).width(mapsize).pad(8).get();
|
||||
button.clearChildren();
|
||||
button.margin(9);
|
||||
button.add(map.name()).width(mapsize - 18f).center().get().setEllipsis(true);
|
||||
button.row();
|
||||
button.addImage().growX().pad(4).color(Pal.gray);
|
||||
button.row();
|
||||
Stack stack = button.stack(new Image(Icon.refresh)).size(mapsize - 20f).get();
|
||||
map.preview(file -> {
|
||||
Core.assets.load(new AssetDescriptor<>(file, Texture.class)).loaded = ct -> {
|
||||
Texture tex = (Texture)ct;
|
||||
stack.clearChildren();
|
||||
stack.add(new Image(tex).setScaling(Scaling.fit));
|
||||
stack.add(new BorderImage(tex).setScaling(Scaling.fit));
|
||||
};
|
||||
});
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(Vars.maps.all().size == 0){
|
||||
maps.add("$maps.none");
|
||||
}
|
||||
|
||||
cont.add(buttons).growX();
|
||||
cont.row();
|
||||
cont.add(pane).uniformX();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.scene.Group;
|
||||
import io.anuke.arc.scene.actions.*;
|
||||
import io.anuke.arc.scene.event.Touchable;
|
||||
@@ -12,6 +13,7 @@ import io.anuke.mindustry.ui.*;
|
||||
public class LoadingFragment extends Fragment{
|
||||
private Table table;
|
||||
private TextButton button;
|
||||
private Bar bar;
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
@@ -27,23 +29,35 @@ public class LoadingFragment extends Fragment{
|
||||
t.addImage().growX().height(3f).pad(4f).growX().get().setColor(Pal.accent);
|
||||
t.row();
|
||||
|
||||
button = t.addButton("$cancel", () -> {
|
||||
}).pad(20).size(250f, 70f).visible(false).get();
|
||||
bar = t.add(new Bar()).pad(3).size(500f, 40f).visible(false).get();
|
||||
t.row();
|
||||
button = t.addButton("$cancel", () -> {}).pad(20).size(250f, 70f).visible(false).get();
|
||||
table = t;
|
||||
});
|
||||
}
|
||||
|
||||
public void setProgress(FloatProvider progress){
|
||||
bar.visible(true);
|
||||
bar.set(() -> ((int)(progress.get() * 100) + "%"), progress, Pal.accent);
|
||||
}
|
||||
|
||||
public void setButton(Runnable listener){
|
||||
button.visible(true);
|
||||
button.getListeners().remove(button.getListeners().size - 1);
|
||||
button.clicked(listener);
|
||||
}
|
||||
|
||||
public void setText(String text){
|
||||
table.<Label>find("namelabel").setText(text);
|
||||
table.<Label>find("namelabel").setColor(Pal.accent);
|
||||
}
|
||||
|
||||
public void show(){
|
||||
show("$loading");
|
||||
}
|
||||
|
||||
public void show(String text){
|
||||
bar.visible(false);
|
||||
table.clearActions();
|
||||
table.touchable(Touchable.enabled);
|
||||
table.<Label>find("namelabel").setText(text);
|
||||
|
||||
@@ -162,6 +162,7 @@ public class MenuFragment extends Fragment{
|
||||
new Buttoni("$loadgame", Icon.loadSmall, ui.load::show),
|
||||
new Buttoni("$tutorial", Icon.infoSmall, control::playTutorial)
|
||||
),
|
||||
steam ? new Buttoni("$maps.browse", Icon.saveSmall, ui.browse::show) : null,
|
||||
new Buttoni("$editor", Icon.editorSmall, ui.maps::show),
|
||||
new Buttoni("$settings", Icon.toolsSmall, ui.settings::show),
|
||||
new Buttoni("$about.button", Icon.infoSmall, ui.about::show),
|
||||
@@ -197,6 +198,7 @@ public class MenuFragment extends Fragment{
|
||||
|
||||
private void buttons(Table t, Buttoni... buttons){
|
||||
for(Buttoni b : buttons){
|
||||
if(b == null) continue;
|
||||
Button[] out = {null};
|
||||
out[0] = t.addImageTextButton(b.text, b.icon, Styles.clearToggleMenut, () -> {
|
||||
if(currentMenu == out[0]){
|
||||
|
||||
Reference in New Issue
Block a user