More character support, made menus collapsible

This commit is contained in:
Anuken
2017-12-27 23:05:10 -05:00
parent c693674ac6
commit b25c611c33
35 changed files with 569 additions and 343 deletions

View File

@@ -10,8 +10,10 @@ import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.resource.Section;
@@ -28,11 +30,14 @@ import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.*;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.scene.ui.layout.Value;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
public class BlocksFragment implements Fragment{
private Table desctable;
private Table desctable, itemtable, blocks;
private Stack stack = new Stack();
private Array<String> statlist = new Array<>();
private boolean shown = true;
@@ -42,15 +47,25 @@ public class BlocksFragment implements Fragment{
abottom();
aright();
visible(() -> !GameState.is(State.menu));
visible(() -> !GameState.is(State.menu) && shown);
Table blocks = new table(){{
blocks = new table(){{
new table("button") {{
visible(() -> player.recipe != null);
desctable = get();
fillX();
}}.end().uniformX();
itemtable = new Table("button");
itemtable.setVisible(() -> player.recipe == null);
desctable = new Table("button");
desctable.setVisible(() -> player.recipe != null);
desctable.update(() -> {
if(player.recipe == null && desctable.getChildren().size != 0){
desctable.clear();
}
});
stack.add(itemtable);
stack.add(desctable);
add(stack).fillX().uniformX();
row();
@@ -83,7 +98,7 @@ public class BlocksFragment implements Fragment{
}
});
button.setName("sectionbutton" + sec.name());
add(button).growX().height(54).padTop(sec.ordinal() <= 2 ? -10 : -5);
add(button).growX().height(54).padRight(-1).padTop(sec.ordinal() <= 2 ? -10 : -5);
button.getImageCell().size(40).padBottom(4).padTop(2);
group.add(button);
@@ -110,7 +125,7 @@ public class BlocksFragment implements Fragment{
}
});
table.add(image).size(size + 8).pad(2);
table.add(image).size(size + 8);
image.getImageCell().size(size);
image.update(() -> {
@@ -146,35 +161,17 @@ public class BlocksFragment implements Fragment{
visible(() -> !GameState.is(State.menu) && shown);
}}.end().get();
row();
ImageButton buttons[] = new ImageButton[2];
float size = 46f;
float t = 0.2f;
Interpolation ip = Interpolation.pow3Out;
//TODO fix glitch when resizing
buttons[0] = new imagebutton("icon-arrow-down", 10*2, () -> {
if(blocks.getActions().size != 0) return;
blocks.actions(Actions.translateBy(0, -blocks.getHeight(), t, ip), Actions.call(() -> shown = false));
buttons[0].actions(Actions.fadeOut(t));
buttons[1].actions(Actions.fadeIn(t));
}).padBottom(-5).visible(() -> shown).height(size).uniformX().fillX()
.update(i -> i.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-down" : "icon-arrow-up")).get();
buttons[1] = new imagebutton("icon-arrow-up", 10*2, () -> {
if(blocks.getActions().size != 0) return;
blocks.actions(Actions.translateBy(0, blocks.getHeight(), t, ip));
shown = true;
buttons[0].actions(Actions.fadeIn(t));
buttons[1].actions(Actions.fadeOut(t));
}).touchable(() -> shown ? Touchable.disabled : Touchable.enabled).size(size).padBottom(-5).padLeft(-size).get();
buttons[1].getColor().a = 0f;
}}.end();
}
public void toggle(boolean show, float t, Interpolation ip){
if(!show){
blocks.actions(Actions.translateBy(0, -blocks.getHeight() - stack.getHeight(), t, ip), Actions.call(() -> shown = false));
}else{
shown = true;
blocks.actions(Actions.translateBy(0, -blocks.getTranslation().y, t, ip));
}
}
void updateRecipe(){
Recipe recipe = player.recipe;
@@ -197,7 +194,7 @@ public class BlocksFragment implements Fragment{
header.addImage(region).size(8*5).padTop(4);
Label nameLabel = new Label(recipe.result.formalName);
nameLabel.setWrap(true);
header.add(nameLabel).padLeft(2).width(130f);
header.add(nameLabel).padLeft(2).width(120f);
//extra info
if(recipe.result.fullDescription != null){
@@ -288,4 +285,40 @@ public class BlocksFragment implements Fragment{
desctable.add(label).width(200).padTop(4).padBottom(2);
}
public void updateItems(){
itemtable.clear();
itemtable.left();
if(control.getMode().infiniteResources){
return;
}
Item[] items = Item.values();
for(int i = 0; i < control.getItems().length; i ++){
int amount = control.getItems()[i];
if(amount == 0) continue;
String formatted = amount > 99999999 ? "inf" : format(amount);
Image image = new Image(Draw.region("icon-" + items[i].name()));
Label label = new Label(formatted);
label.setFontScale(fontscale*1.5f);
itemtable.add(image).size(8*3);
itemtable.add(label).expandX().left();
if(i % 2 == 1 && i > 0) itemtable.row();
}
}
String format(int number){
if(number > 1000000) {
return Strings.toFixed(number/1000000f, 1) + "[gray]mil";
}else if(number > 10000){
return number/1000 + "[gray]k";
}else if(number > 1000){
return Strings.toFixed(number/1000f, 1) + "[gray]k";
}else{
return number + "";
}
}
}

View File

@@ -5,12 +5,14 @@ import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.GameMode;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Settings;
@@ -20,16 +22,21 @@ import io.anuke.ucore.scene.builders.label;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.Label;
import io.anuke.ucore.scene.ui.layout.Cell;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
public class HudFragment implements Fragment{
private Table itemtable, respawntable;
private Cell<Table> itemcell;
private ImageButton menu, flip, pause;
private Table respawntable;
private Table wavetable;
private boolean shown = true;
private BlocksFragment blockfrag = new BlocksFragment();
public void build(){
//menu at top left
new table(){{
atop();
@@ -37,41 +44,50 @@ public class HudFragment implements Fragment{
new table(){{
left();
defaults().size(68).left();
float dsize = 58;
defaults().size(dsize).left();
float isize = 40;
new imagebutton("icon-menu", isize, ()->{
ui.showMenu();
});
new imagebutton("icon-settings", isize, ()->{
ui.showPrefs();
});
new imagebutton("icon-pause", isize, ()->{
menu = new imagebutton("icon-menu", isize, ()->{
ui.showMenu();
}).get();
flip = new imagebutton("icon-arrow-up", isize, ()->{
if(wavetable.getActions().size != 0) return;
float dur = 0.3f;
Interpolation in = Interpolation.pow3Out;
flip.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-down" : "icon-arrow-up");
if(shown){
blockfrag.toggle(false, dur, in);
wavetable.actions(Actions.translateBy(0, wavetable.getHeight() + dsize, dur, in), Actions.call(() -> shown = false));
}else{
shown = true;
blockfrag.toggle(true, dur, in);
wavetable.actions(Actions.translateBy(0, -wavetable.getTranslation().y, dur, in));
}
}).get();
pause = new imagebutton("icon-pause", isize, ()->{
GameState.set(GameState.is(State.paused) ? State.playing : State.paused);
}){{
get().update(()->{
get().getStyle().imageUp = Core.skin.getDrawable(GameState.is(State.paused) ? "icon-play" : "icon-pause");
});
}};
}).update(i -> i.getStyle().imageUp = Core.skin.getDrawable(GameState.is(State.paused) ? "icon-play" : "icon-pause")).get();
}}.end();
row();
new table(){{
get().setTouchable(Touchable.enabled);
touchable(Touchable.enabled);
visible(() -> shown);
addWaveTable();
}}.fillX().end();
row();
itemtable = new table("button").end().top().left().fillX().size(-1).get();
itemtable.setTouchable(Touchable.enabled);
itemtable.setVisible(()-> !control.getMode().infiniteResources);
itemcell = get().getCell(itemtable);
get().setVisible(()->!GameState.is(State.menu));
visible(()->!GameState.is(State.menu));
Label fps = new Label(()->(Settings.getBool("fps") ? (Gdx.graphics.getFramesPerSecond() + " FPS") : ""));
row();
@@ -79,7 +95,7 @@ public class HudFragment implements Fragment{
}}.end();
//ui table
//tutorial ui table
new table(){{
control.getTutorial().buildUI(this);
@@ -95,28 +111,11 @@ public class HudFragment implements Fragment{
new label("[orange]< "+ Bundles.get("text.paused") + " >").scale(0.75f).pad(6);
}}.end();
}}.end();
//wave table...
new table(){{
if(!Vars.android){
atop();
aright();
}else{
abottom();
aleft();
}
//addWaveTable();
visible(()->!GameState.is(State.menu));
}}.end();
//respawn background table
new table("white"){{
respawntable = get();
respawntable.setColor(Color.CLEAR);
}}.end();
//respawn table
@@ -148,6 +147,8 @@ public class HudFragment implements Fragment{
new label("[red]DEBUG MODE").scale(0.5f).left();
}}.end();
}
blockfrag.build();
}
private String getEnemiesRemaining() {
@@ -159,12 +160,12 @@ public class HudFragment implements Fragment{
private void addWaveTable(){
float uheight = 66f;
new table("button"){{
wavetable = new table("button"){{
aleft();
new table(){{
aleft();
new label(() -> Bundles.format("text.wave", control.getWave())).scale(fontscale*1.5f).left();
new label(() -> Bundles.format("text.wave", control.getWave())).scale(fontscale*1.5f).left().padLeft(-6);
row();
@@ -172,15 +173,15 @@ public class HudFragment implements Fragment{
getEnemiesRemaining() :
(control.getTutorial().active() || Vars.control.getMode().toggleWaves) ? "$text.waiting"
: Bundles.format("text.wave.waiting", (int) (control.getWaveCountdown() / 60f)))
.minWidth(140).left();
.minWidth(140).padLeft(-6).padRight(-12).left();
margin(12f);
margin(10f);
get().marginLeft(6);
}}.left().end();
playButton(uheight);
}}.height(uheight).fillX().expandX().end();
}}.height(uheight).fillX().expandX().end().get();
wavetable.getParent().getParent().swapActor(wavetable.getParent(), menu.getParent());
}
private void playButton(float uheight){
@@ -196,36 +197,12 @@ public class HudFragment implements Fragment{
l.setTouchable(!paused ? Touchable.enabled : Touchable.disabled);
});
}
public void updateItems(){
itemtable.clear();
itemtable.left();
if(control.getMode().infiniteResources){
return;
}
Item[] items = Item.values();
for(int i = 0; i < control.getItems().length; i ++){
int amount = control.getItems()[i];
if(amount == 0) continue;
String formatted = Mindustry.platforms.format(amount);
if(amount > 99999999){
formatted = "inf";
}
Image image = new Image(Draw.region("icon-" + items[i].name()));
Label label = new Label(formatted);
label.setFontScale(fontscale*1.5f);
itemtable.add(image).size(8*3);
itemtable.add(label).left();
itemtable.row();
}
public void updateItems(){
blockfrag.updateItems();
}
public void fadeRespawn(boolean in){
respawntable.addAction(Actions.color(in ? new Color(0, 0, 0, 0.3f) : Color.CLEAR, 0.3f));
}
}

View File

@@ -3,105 +3,141 @@ package io.anuke.mindustry.ui.fragments;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Align;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.input.PlaceMode;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.*;
import io.anuke.ucore.scene.event.Touchable;
import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Mathf;
public class PlacementFragment implements Fragment{
boolean shown = false;
Table breaktable, next;
public void build(){
if(android){
//placement table
float s = 50f;
new table(){{
visible(()->player.recipe != null && !GameState.is(State.menu));
visible(() -> !GameState.is(State.menu));
abottom();
aleft();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
new table(){{
visible(() -> player.recipe != null);
touchable(Touchable.enabled);
aleft();
new label("$text.placemode");
row();
new table("pane"){{
margin(5f);
aleft();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
defaults().size(54, 58).pad(0);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || mode.delete) continue;
defaults().padBottom(-5.5f);
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
player.placeMode = mode;
}).group(group);
}
row();
Color color = Color.GRAY;//Colors.get("accent"); //Color.valueOf("4d4d4d")
defaults().size(s, s + 4).padBottom(-5.5f);
Color color = Color.GRAY;
new imagebutton("icon-cancel", 14*3, ()->{
player.recipe = null;
}).imageColor(color)
.visible(()->player.recipe != null);
new button("", ()->{}).get().setTouchable(Touchable.disabled);;
.visible(()->player.recipe != null);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || mode.delete) continue;
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
player.placeMode = mode;
}).group(group);
}
new imagebutton("icon-arrow", 14*3, ()->{
player.rotation = Mathf.mod(player.rotation + 1, 4);
}).imageColor(color).visible(() -> player.recipe != null).update(image ->{
image.getImage().setRotation(player.rotation*90);
image.getImage().setOrigin(Align.center);
});
}}.left().end();
}}.end();
}}.end();
new table(){{
visible(()->player.recipe == null && !GameState.is(State.menu));
abottom();
aleft();
new label("$text.breakmode");
}}.padBottom(-5).left().end();
}}.left().end();
row();
new table("pane"){{
margin(5f);
touchable(Touchable.enabled);
aleft();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
defaults().size(54, 58).pad(0);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || !mode.delete) continue;
defaults().padBottom(-5.5f);
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
player.breakMode = mode;
}){{
group.add(get());
}};
}
}}.end();
}}.end();
new table(){{
abottom();
aleft();
height(s+5+4);
next = new table("pane"){{
margin(5f);
defaults().padBottom(-5.5f);
new imagebutton("icon-arrow-right", 10 * 3, () -> {
float dur = 0.3f;
Interpolation in = Interpolation.pow3Out;
if(breaktable.getActions().size != 0) return;
breaktable.getParent().swapActor(breaktable, next);
if(shown){
breaktable.actions(Actions.translateBy(-breaktable.getWidth() - 5, 0, dur, in), Actions.call(() -> shown = false));
}else{
shown = true;
breaktable.actions(Actions.translateBy(-breaktable.getTranslation().x - 5, 0, dur, in));
}
}).size(s, s+4);
}}.end().get();
breaktable = new table("pane"){{
visible(() -> shown);
margin(5f);
marginLeft(0f);
touchable(Touchable.enabled);
aleft();
defaults().size(s, s+4);
for(PlaceMode mode : PlaceMode.values()){
if(!mode.shown || !mode.delete) continue;
defaults().padBottom(-5.5f);
new imagebutton("icon-" + mode.name(), "toggle", 10*3, ()->{
control.getInput().resetCursor();
player.breakMode = mode;
player.placeMode = mode;
}).group(group);
}
}}.end().get();
breaktable.getParent().swapActor(breaktable, next);
breaktable.getTranslation().set(-breaktable.getPrefWidth(), 0);
}}.end().get();
//one.getParent().swapActor(one, two);
}}.end();
}
}
}

View File

@@ -52,7 +52,7 @@ public class WeaponFragment implements Fragment{
String description = weapon.description;
tiptable.background("button");
tiptable.add("weapon."+weapon.name()+".name", 0.5f).left().padBottom(3f);
tiptable.add("$weapon."+weapon.name()+".name", 0.5f).left().padBottom(3f);
tiptable.row();
tiptable.row();