UI refactoring, new save dialog

This commit is contained in:
Anuken
2017-12-22 18:10:34 -05:00
parent cbcdc96aaa
commit 60216b45f9
26 changed files with 144 additions and 77 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.anuke.mindustry"
android:versionCode="43"
android:versionName="3.2b2" >
android:versionCode="44"
android:versionName="3.2b3" >
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

View File

@ -21,7 +21,7 @@ allprojects {
appName = "Mindustry"
gdxVersion = '1.9.8'
aiVersion = '1.8.1'
uCoreVersion = '4434f35';
uCoreVersion = 'd239170bc0';
}
repositories {
@ -36,11 +36,11 @@ allprojects {
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-lwjgl3:$gdxVersion"
}
}
@ -51,11 +51,14 @@ project(":html") {
dependencies {
compile project(":core")
compile fileTree(dir: '../core/lib', include: '*.jar')
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion:sources"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion:sources"
}
}
@ -73,6 +76,7 @@ project(":android") {
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
}
}
@ -90,6 +94,7 @@ project(":core") {
}
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
}
}

View File

@ -2,6 +2,6 @@
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "https://raw.githubusercontent.com/gwtproject/gwt/master/distro-source/core/src/gwt-module.dtd">
<module>
<source path="io/anuke/mindustry" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.enemies" />
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.Tile" />
</module>

View File

@ -7,6 +7,7 @@ import java.util.Arrays;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.reflect.ClassReflection;
@ -423,7 +424,7 @@ public class Control extends Module{
@Override
public void init(){
Musics.shuffleAll();
Timers.run(1f, Musics::shuffleAll);
Entities.initPhysics();

View File

@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.FloatArray;
import io.anuke.mindustry.Vars;
@ -27,6 +28,7 @@ import io.anuke.ucore.core.*;
import io.anuke.ucore.entities.DestructibleEntity;
import io.anuke.ucore.entities.EffectEntity;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.function.Callable;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.graphics.Surface;
import io.anuke.ucore.modules.RendererModule;
@ -43,6 +45,7 @@ public class Renderer extends RendererModule{
private int targetscale = baseCameraScale;
private FloatArray shieldHits = new FloatArray();
private Array<Callable> shieldDraws = new Array<>();
private BlockRenderer blocks = new BlockRenderer();
public Renderer() {
@ -251,7 +254,6 @@ public class Renderer extends RendererModule{
void drawEnemyMarkers(){
Graphics.surface(indicatorSurface);
Draw.color(Color.RED);
//Draw.alpha(0.6f);
for(Enemy enemy : control.enemyGroup.all()){
if(Tmp.r1.setSize(camera.viewportWidth, camera.viewportHeight).setCenter(camera.position.x, camera.position.y).overlaps(enemy.hitbox.getRect(enemy.x, enemy.y))){
@ -269,11 +271,14 @@ public class Renderer extends RendererModule{
}
void drawShield(){
if(control.shieldGroup.amount() == 0) return;
if(control.shieldGroup.amount() == 0 && shieldDraws.size == 0) return;
Graphics.surface(Vars.renderer.shieldSurface, false);
Draw.color(Color.ROYAL);
Entities.draw(control.shieldGroup);
for(Callable c : shieldDraws){
c.run();
}
Draw.reset();
Graphics.surface();
@ -315,6 +320,7 @@ public class Renderer extends RendererModule{
Graphics.beginCam();
Draw.color();
shieldDraws.clear();
}
public BlockRenderer getBlocks() {
@ -325,6 +331,10 @@ public class Renderer extends RendererModule{
shieldHits.addAll(x, y, 0f);
}
public void addShield(Callable call){
shieldDraws.add(call);
}
void drawOverlay(){
//draw tutorial placement point
@ -394,7 +404,7 @@ public class Renderer extends RendererModule{
}
}
if(!Vars.debug || Vars.showUI){
if((!Vars.debug || Vars.showUI) && Settings.getBool("healthbars")){
//draw entity health bars
for(Enemy entity : control.enemyGroup.all()){

View File

@ -61,8 +61,8 @@ public class Tutorial{
}}.end();
prev.pad(16);
next.pad(16);
prev.margin(16);
next.margin(16);
prev.setDisabled(()->!canMove(false) || !stage.canBack);
next.setDisabled(()->!stage.canForward);

View File

@ -167,7 +167,7 @@ public class UI extends SceneModule{
settingserror = new Dialog("Warning", "dialog");
settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved.");
settingserror.content().pad(10f);
settingserror.content().margin(10f);
settingserror.getButtonTable().addButton("OK", ()->{
settingserror.hide();
}).size(80f, 55f).pad(4);
@ -181,7 +181,7 @@ public class UI extends SceneModule{
gameerror.buttons().addButton("OK", gameerror::hide).size(200f, 50);
discord = new Dialog("Discord", "dialog");
discord.content().pad(12f);
discord.content().margin(12f);
discord.content().add("Join the mindustry discord!\n[orange]" + Vars.discordURL);
discord.buttons().defaults().size(200f, 50);
discord.buttons().addButton("Open link", () -> Mindustry.platforms.openLink(Vars.discordURL));
@ -197,20 +197,20 @@ public class UI extends SceneModule{
prefs.setStyle(Core.skin.get("dialog", WindowStyle.class));
menu = new MenuDialog();
prefs.sound.volumePrefs();
prefs.sliderPref("difficulty", "Difficulty", 1, 0, 2, i -> i == 0 ? "Easy" : i == 1 ? "Normal" : "Hard");
prefs.screenshakePref();
prefs.volumePrefs();
prefs.checkPref("fps", "Show FPS", false);
prefs.checkPref("vsync", "VSync", true, b -> Gdx.graphics.setVSync(b));
//prefs.checkPref("noshadows", "Disable shadows", false);
//prefs.checkPref("drawblocks", "Draw Blocks", true);
prefs.checkPref("smoothcam", "Smooth Camera", true);
prefs.checkPref("indicators", "Enemy Indicators", true);
prefs.checkPref("effects", "Display Effects", true);
prefs.checkPref("pixelate", "Pixelate Screen", true, b->{
prefs.game.sliderPref("difficulty", "Difficulty", 1, 0, 2, i -> i == 0 ? "Easy" : i == 1 ? "Normal" : "Hard");
prefs.game.screenshakePref();
prefs.game.checkPref("smoothcam", "Smooth Camera", true);
prefs.game.checkPref("indicators", "Enemy Indicators", true);
prefs.game.checkPref("effects", "Display Effects", true);
prefs.graphics.checkPref("fps", "Show FPS", false);
prefs.graphics.checkPref("vsync", "VSync", true, b -> Gdx.graphics.setVSync(b));
prefs.graphics.checkPref("lasers", "Show Power Lasers", true);
prefs.graphics.checkPref("healthbars", "Show Entity Health bars", true);
prefs.graphics.checkPref("pixelate", "Pixelate Screen", true, b->{
if(b){
Vars.renderer.pixelSurface.setScale(Core.cameraScale);
Vars.renderer.shadowSurface.setScale(Core.cameraScale);
@ -241,13 +241,6 @@ public class UI extends SceneModule{
menu.hide();
}
});
if(!android){
prefs.content().row();
prefs.content().addButton("Controls", () -> {
keys.show(scene);
}).size(300f, 50f).pad(5f);
}
keys = new MindustryKeybindDialog();
@ -358,7 +351,7 @@ public class UI extends SceneModule{
public void showError(String text){
new Dialog("[crimson]An error has occured", "dialog"){{
content().pad(15);
content().margin(15);
content().add(text);
getButtonTable().addButton("OK", this::hide).size(90, 50).pad(4);
}}.show();
@ -366,7 +359,7 @@ public class UI extends SceneModule{
public void showErrorClose(String text){
new Dialog("[crimson]A critical error has occured", "dialog"){{
content().pad(15);
content().margin(15);
content().add(text);
getButtonTable().addButton("Exit", Gdx.app::exit).size(90, 50).pad(4);
}}.show();

View File

@ -2,7 +2,6 @@ package io.anuke.mindustry.mapeditor;
import java.util.Arrays;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
@ -126,7 +125,7 @@ public class MapEditorDialog extends Dialog{
setFillParent(true);
clearChildren();
pad(0);
margin(0);
build.begin(this);
build();
build.end();
@ -224,7 +223,7 @@ public class MapEditorDialog extends Dialog{
new table(){{
Table tools = new Table("button");
tools.top();
tools.padTop(0).padBottom(6);
tools.marginTop(0).marginBottom(6);
ButtonGroup<ImageButton> group = new ButtonGroup<>();
int i = 1;

View File

@ -47,7 +47,7 @@ public class MapGenerateDialog extends FloatingDialog{
image.setScaling(Scaling.fit);
Table preft = new Table();
preft.left();
preft.pad(4f).padRight(25f);
preft.margin(4f).marginRight(25f);
for(GenPref pref : editor.getFilter().getPrefs().values()){
CheckBox box = new CheckBox(pref.name);

View File

@ -45,7 +45,7 @@ public class MapLoadDialog extends FloatingDialog{
Table table = new Table();
table.defaults().size(200f, 90f).pad(4f);
table.pad(10f);
table.margin(10f);
ScrollPane pane = new ScrollPane(table, "horizontal");
pane.setFadeScrollBars(false);

View File

@ -292,7 +292,7 @@ public class MapView extends Element implements GestureListener{
public boolean zoom(float initialDistance, float distance){
if(!active()) return false;
float nzoom = distance - initialDistance;
zoom += nzoom / 5000f / Unit.dp.scl(1f) * zoom;
zoom += nzoom / 10000f / Unit.dp.scl(1f) * zoom;
clampZoom();
return false;
}

View File

@ -51,7 +51,7 @@ public class FileChooser extends FloatingDialog{
private void setupWidgets(){
getCell(content()).maxWidth(Gdx.graphics.getWidth()/Unit.dp.scl(2f));
content().pad(-10);
content().margin(-10);
Table content = new Table();
@ -139,7 +139,7 @@ public class FileChooser extends FloatingDialog{
content.add(icontable).expandX().fillX();
content.row();
//content.add(navigation).colspan(3).left().padBottom(10f).expandX().fillX().height(40f);
//content.add(navigation).colspan(3).left().marginBottom(10f).expandX().fillX().height(40f);
//content.row();
content.center().add(pane).width(Gdx.graphics.getWidth()/Unit.dp.scl(2)).colspan(3).grow();

View File

@ -117,7 +117,7 @@ public class LevelDialog extends FloatingDialog{
maps.add(stack).width(170).top().pad(4f);
maps.padRight(26);
maps.marginRight(26);
i ++;
}

View File

@ -42,12 +42,12 @@ public class LoadDialog extends FloatingDialog{
pane = new ScrollPane(slots);
pane.setFadeScrollBars(false);
slots.padRight(24);
slots.marginRight(24);
for(int i = 0; i < Vars.saveSlots; i++){
TextButton button = new TextButton("[accent]Slot " + (i + 1));
button.pad(12);
button.margin(12);
button.getLabelCell().top().left().growX();
button.row();

View File

@ -21,9 +21,7 @@ public class MindustryKeybindDialog extends KeybindDialog{
@Override
public void addCloseButton(){
buttons().addImageTextButton("Back", "icon-arrow-left", 30f, ()->{
hide();
}).size(230f, 64f);
buttons().addImageTextButton("Back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
keyDown(key->{
if(key == Keys.ESCAPE || key == Keys.BACK)

View File

@ -4,11 +4,23 @@ import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.utils.Align;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.SettingsDialog;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.UCore;
import io.anuke.ucore.scene.builders.table;
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.util.Mathf;
public class MindustrySettingsDialog extends SettingsDialog{
public SettingsTable graphics;
public SettingsTable game;
public SettingsTable sound;
private Table prefs;
private Table menu;
private boolean built = false;
public MindustrySettingsDialog(){
setFillParent(true);
@ -16,24 +28,71 @@ public class MindustrySettingsDialog extends SettingsDialog{
getTitleTable().row();
getTitleTable().add(new Image("white"))
.growX().height(3f).pad(4f).get().setColor(Colors.get("accent"));
content().clearChildren();
content().remove();
buttons().remove();
ScrollPane pane = new ScrollPane(content(), "clear");
menu = new Table();
game = new SettingsTable();
graphics = new SettingsTable();
sound = new SettingsTable();
prefs = new Table();
prefs.top();
prefs.margin(14f);
menu.defaults().size(300f, 60f).pad(3f);
menu.addButton("Game", () -> visible(0));
menu.row();
menu.addButton("Graphics", () -> visible(1));
menu.row();
menu.addButton("Sound", () -> visible(2));
if(!Vars.android) {
menu.row();
menu.addButton("Controls", () -> Vars.ui.showControls());
}
prefs.clearChildren();
prefs.add(menu);
ScrollPane pane = new ScrollPane(prefs, "clear");
pane.setFadeScrollBars(false);
row();
add(pane).expand().fill();
add(pane).grow().top();
row();
add(buttons()).fillX();
hidden(this::back);
shown(() -> {
if(built) return;
built = true;
Mathf.each(table -> {
table.row();
table.addImageTextButton("Back", "icon-arrow-left", 10*3, this::back).size(240f, 60f).colspan(2).padTop(15f);
}, game, graphics, sound);
});
}
private void back(){
prefs.clearChildren();
prefs.add(menu);
}
private void visible(int index){
prefs.clearChildren();
Table table = Mathf.select(index, game, graphics, sound);
prefs.add(table);
}
@Override
public void addCloseButton(){
buttons().addImageTextButton("Back", "icon-arrow-left", 30f, ()->{
hide();
}).size(230f, 64f);
buttons().addImageTextButton("Menu", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
keyDown(key->{
if(key == Keys.ESCAPE || key == Keys.BACK)

View File

@ -1,6 +1,5 @@
package io.anuke.mindustry.ui;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import io.anuke.mindustry.Vars;
@ -24,7 +23,7 @@ public class SaveDialog extends LoadDialog{
save(slot);
}){
{
content().pad(16);
content().margin(16);
for(Cell<?> cell : getButtonTable().getCells())
cell.size(110, 45).pad(4);
}

View File

@ -38,7 +38,7 @@ public class UpgradeDialog extends FloatingDialog{
});
Table weptab = new Table();
weptab.pad(20);
weptab.margin(20);
int i = 0;
for(Weapon weapon : Weapon.values()){
@ -48,7 +48,7 @@ public class UpgradeDialog extends FloatingDialog{
button.add(img).size(8*5);
button.getCells().reverse();
button.row();
button.pad(14);
button.margin(14);
button.getLabelCell().left();
button.pack();
@ -109,7 +109,7 @@ public class UpgradeDialog extends FloatingDialog{
if(control.hasWeapon(weapon)){
tiptable.add("[LIME]Purchased!").padTop(6).left();
}
tiptable.pad(14f);
tiptable.margin(14f);
};
run.listen();

View File

@ -76,7 +76,7 @@ public class BlocksFragment implements Fragment{
row();
}
table.pad(4);
table.margin(4);
table.top().left();
int i = 0;
@ -124,8 +124,8 @@ public class BlocksFragment implements Fragment{
add(stack).colspan(Section.values().length);
margin(10f);
get().padLeft(0f);
get().padRight(0f);
get().marginLeft(0f);
get().marginRight(0f);
end();
}}.right().bottom().uniformX();
@ -142,7 +142,7 @@ public class BlocksFragment implements Fragment{
desctable.defaults().left();
desctable.left();
desctable.pad(12);
desctable.margin(12);
Table header = new Table();

View File

@ -173,7 +173,7 @@ public class HudFragment implements Fragment{
.minWidth(140).left();
margin(12f);
get().padLeft(6);
get().marginLeft(6);
}}.left().end();
playButton(uheight);

View File

@ -45,7 +45,7 @@ public class MenuFragment implements Fragment{
if(!gwt){
add(new MenuButton("text-exit", group, Gdx.app::exit));
}
get().pad(16);
get().margin(16);
}}.end();
visible(()->GameState.is(State.menu));

View File

@ -57,7 +57,7 @@ public class WeaponFragment implements Fragment{
tiptable.row();
tiptable.row();
tiptable.add("[GRAY]" + description).left();
tiptable.pad(14f);
tiptable.margin(14f);
Tooltip tip = new Tooltip(tiptable);

View File

@ -48,10 +48,7 @@ public class ShieldedWallBlock extends PowerBlock{
ShieldedWallEntity entity = tile.entity();
if(entity.power > powerToDamage){
Graphics.surface(Vars.renderer.shieldSurface, false);
Draw.color(Color.ROYAL);
Draw.rect("blank", tile.worldx(), tile.worldy(), Vars.tilesize, Vars.tilesize);
Graphics.surface();
Vars.renderer.addShield(() -> Draw.rect("blank", tile.worldx(), tile.worldy(), Vars.tilesize, Vars.tilesize));
}
Draw.color(hitColor);

View File

@ -15,6 +15,7 @@ import io.anuke.mindustry.world.blocks.types.PowerAcceptor;
import io.anuke.mindustry.world.blocks.types.PowerBlock;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.*;
@ -127,6 +128,8 @@ public class Generator extends PowerBlock{
@Override
public void drawLayer(Tile tile){
if(!Settings.getBool("lasers")) return;
PowerEntity entity = tile.entity();
for(int i = 0; i < laserDirections; i++){

View File

@ -56,6 +56,8 @@ draftWar {
task addSource{
doLast{
sourceSets.main.compileClasspath += files(project(':core').sourceSets.main.allJava.srcDirs)
//this WILL fail if uCore is not a module
sourceSets.main.compileClasspath += files(project(':uCore').sourceSets.main.allJava.srcDirs)
}
}

View File

@ -3,6 +3,7 @@
<module rename-to="html">
<inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />
<inherits name='com.badlogic.gdx.ai' />
<inherits name='com.badlogic.gdx.controllers.controllers-gwt' />
<inherits name='Mindustry' />
<inherits name='uCore' />