menu
This commit is contained in:
@@ -2,7 +2,9 @@ package io.anuke.mindustry.ui.fragments;
|
|||||||
|
|
||||||
import io.anuke.arc.*;
|
import io.anuke.arc.*;
|
||||||
import io.anuke.arc.scene.Group;
|
import io.anuke.arc.scene.Group;
|
||||||
|
import io.anuke.arc.scene.ui.Button;
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
|
import io.anuke.arc.util.Align;
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.core.Platform;
|
import io.anuke.mindustry.core.Platform;
|
||||||
import io.anuke.mindustry.game.EventType.ResizeEvent;
|
import io.anuke.mindustry.game.EventType.ResizeEvent;
|
||||||
@@ -12,7 +14,8 @@ import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
|||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
public class MenuFragment extends Fragment{
|
public class MenuFragment extends Fragment{
|
||||||
private Table container;
|
private Table container, submenu;
|
||||||
|
private Button currentMenu;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Group parent){
|
public void build(Group parent){
|
||||||
@@ -99,13 +102,27 @@ public class MenuFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildDesktop(){
|
private void buildDesktop(){
|
||||||
container.table("dialogDim", t -> {
|
float width = 230f;
|
||||||
float isize = iconsizesmall;
|
String background = "dialogDim";
|
||||||
float margin = 10f;
|
|
||||||
final String suffix = "-small";
|
|
||||||
|
|
||||||
t.left().defaults().width(230f).height(70f).left();
|
container.left();
|
||||||
|
container.table(background, t -> {
|
||||||
|
t.defaults().width(width).height(70f);
|
||||||
|
|
||||||
|
buttons(t,
|
||||||
|
new Buttoni("$play", "icon-play-2",
|
||||||
|
new Buttoni("$campaign", "icon-play-2", ui.deploy::show),
|
||||||
|
new Buttoni("$joingame", "icon-add", ui.join::show),
|
||||||
|
new Buttoni("$customgame", "icon-terrain", ui.custom::show),
|
||||||
|
new Buttoni("$loadgame", "icon-load", ui.load::show)
|
||||||
|
),
|
||||||
|
new Buttoni("$editor", "icon-editor", ui.maps::show),
|
||||||
|
new Buttoni("$settings", "icon-tools", ui.settings::show), //todo submenu
|
||||||
|
new Buttoni("$about.button", "icon-info", ui.about::show), //todo submenu
|
||||||
|
new Buttoni("$quit", "icon-exit", Core.app::exit)
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
t.addImageTextButton("$play", "icon-play-2" + suffix, "clear", isize, ui.deploy::show).marginLeft(margin);
|
t.addImageTextButton("$play", "icon-play-2" + suffix, "clear", isize, ui.deploy::show).marginLeft(margin);
|
||||||
t.row();
|
t.row();
|
||||||
|
|
||||||
@@ -113,24 +130,17 @@ public class MenuFragment extends Fragment{
|
|||||||
t.row();
|
t.row();
|
||||||
|
|
||||||
t.addImageTextButton("$customgame", "icon-play-custom" + suffix, "clear", isize, this::showCustomSelect).marginLeft(margin);
|
t.addImageTextButton("$customgame", "icon-play-custom" + suffix, "clear", isize, this::showCustomSelect).marginLeft(margin);
|
||||||
t.row();
|
t.row();*/
|
||||||
|
|
||||||
t.addImageTextButton("$editor", "icon-editor" + suffix, "clear", isize, ui.maps::show).marginLeft(margin);
|
}).width(width).growY();
|
||||||
t.row();
|
|
||||||
|
|
||||||
//t.addImageTextButton("$maps", "icon-map" + suffix, "clear", isize, ui.maps::show).marginLeft(margin);
|
container.table(background, t -> {
|
||||||
//t.row();
|
submenu = t;
|
||||||
|
t.top();
|
||||||
|
t.defaults().width(width).height(70f);
|
||||||
|
t.visible(() -> !t.getChildren().isEmpty());
|
||||||
|
|
||||||
t.addImageTextButton("$about.button", "icon-info" + suffix, "clear", isize, ui.about::show).marginLeft(margin);
|
}).width(width).growY();
|
||||||
t.row();
|
|
||||||
|
|
||||||
t.addImageTextButton("$settings", "icon-tools" + suffix, "clear", isize, ui.settings::show).marginLeft(margin);
|
|
||||||
t.row();
|
|
||||||
|
|
||||||
t.addImageTextButton("$quit", "icon-exit" + suffix, "clear", isize, Core.app::exit).marginLeft(margin);
|
|
||||||
t.row();
|
|
||||||
|
|
||||||
}).growY().margin(0f).expand().left().padLeft(200f);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
container.table(out -> {
|
container.table(out -> {
|
||||||
@@ -167,6 +177,34 @@ public class MenuFragment extends Fragment{
|
|||||||
});*/
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttons(Table t, Buttoni... buttons){
|
||||||
|
for(Buttoni b : buttons){
|
||||||
|
Button[] out = {null};
|
||||||
|
out[0] = t.addImageTextButton(b.text, b.icon + "-small", "clear-toggle",
|
||||||
|
iconsizesmall, () -> {
|
||||||
|
if(currentMenu == out[0]){
|
||||||
|
currentMenu = null;
|
||||||
|
submenu.clearChildren();
|
||||||
|
}else{
|
||||||
|
if(b.submenu != null){
|
||||||
|
currentMenu = out[0];
|
||||||
|
submenu.clearChildren();
|
||||||
|
//correctly offset the button
|
||||||
|
submenu.add().height(Core.graphics.getHeight() - out[0].getY(Align.topLeft));
|
||||||
|
submenu.row();
|
||||||
|
buttons(submenu, b.submenu);
|
||||||
|
}else{
|
||||||
|
currentMenu = null;
|
||||||
|
submenu.clearChildren();
|
||||||
|
b.runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).marginLeft(11f).get();
|
||||||
|
out[0].update(() -> out[0].setChecked(currentMenu == out[0]));
|
||||||
|
t.row();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void showCustomSelect(){
|
private void showCustomSelect(){
|
||||||
FloatingDialog dialog = new FloatingDialog("$play");
|
FloatingDialog dialog = new FloatingDialog("$play");
|
||||||
dialog.setFillParent(false);
|
dialog.setFillParent(false);
|
||||||
@@ -183,4 +221,25 @@ public class MenuFragment extends Fragment{
|
|||||||
}));
|
}));
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Buttoni{
|
||||||
|
final String icon;
|
||||||
|
final String text;
|
||||||
|
final Runnable runnable;
|
||||||
|
final Buttoni[] submenu;
|
||||||
|
|
||||||
|
public Buttoni(String text, String icon, Runnable runnable){
|
||||||
|
this.icon = icon;
|
||||||
|
this.text = text;
|
||||||
|
this.runnable = runnable;
|
||||||
|
this.submenu = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Buttoni(String text, String icon, Buttoni... buttons){
|
||||||
|
this.icon = icon;
|
||||||
|
this.text = text;
|
||||||
|
this.runnable = () -> {};
|
||||||
|
this.submenu = buttons;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user