Merge
This commit is contained in:
@@ -11,7 +11,7 @@ public class ItemImage extends Stack{
|
||||
|
||||
public ItemImage(TextureRegion region, Supplier<CharSequence> text){
|
||||
Table t = new Table().left().bottom();
|
||||
t.label(text);
|
||||
t.label(text).name("item-label");
|
||||
|
||||
add(new Image(region));
|
||||
add(t);
|
||||
@@ -22,7 +22,7 @@ public class ItemImage extends Stack{
|
||||
|
||||
if(stack.amount != 0){
|
||||
Table t = new Table().left().bottom();
|
||||
t.add(stack.amount + "");
|
||||
t.add(stack.amount + "").name("item-label");
|
||||
add(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,21 +12,15 @@ public class MenuButton extends TextButton{
|
||||
|
||||
public MenuButton(String icon, String text, String description, Runnable clicked){
|
||||
super("default");
|
||||
float s = 66f;
|
||||
|
||||
clicked(clicked);
|
||||
|
||||
clearChildren();
|
||||
|
||||
margin(0);
|
||||
|
||||
table(t -> {
|
||||
t.addImage(icon).size(14 * 3);
|
||||
t.update(() -> t.setBackground(getClickListener().isVisualPressed() ? "button-down" : getClickListener().isOver() ? "button-over" : "button"));
|
||||
}).size(s - 5, s);
|
||||
t.addImage(icon).size(14 * 3).padLeft(6);
|
||||
|
||||
|
||||
table(t -> {
|
||||
t.add(text).wrap().growX().get().setAlignment(Align.center, Align.left);
|
||||
if(description != null){
|
||||
t.row();
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.event.InputEvent;
|
||||
import io.anuke.ucore.scene.event.InputListener;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.scene.ui.layout.Container;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
public class Minimap extends Table{
|
||||
public class Minimap extends Container<Element>{
|
||||
|
||||
public Minimap(){
|
||||
super("pane");
|
||||
super(new Element(){
|
||||
TextureRegion r = new TextureRegion();
|
||||
|
||||
margin(5);
|
||||
|
||||
Element elem = new Element(){
|
||||
@Override
|
||||
public void draw(){
|
||||
if(renderer.minimap.getRegion() == null) return;
|
||||
@@ -28,7 +27,12 @@ public class Minimap extends Table{
|
||||
renderer.minimap.drawEntities(x, y, width, height);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
background("pane");
|
||||
|
||||
size(140f);
|
||||
margin(5f);
|
||||
|
||||
addListener(new InputListener(){
|
||||
public boolean scrolled(InputEvent event, float x, float y, int amount){
|
||||
@@ -37,7 +41,7 @@ public class Minimap extends Table{
|
||||
}
|
||||
});
|
||||
|
||||
elem.update(() -> {
|
||||
update(() -> {
|
||||
|
||||
Element e = Core.scene.hit(Graphics.mouse().x, Graphics.mouse().y, true);
|
||||
if(e != null && e.isDescendantOf(this)){
|
||||
@@ -46,7 +50,5 @@ public class Minimap extends Table{
|
||||
Core.scene.setScrollFocus(null);
|
||||
}
|
||||
});
|
||||
|
||||
add(elem).size(140f, 140f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,9 +279,7 @@ public class JoinDialog extends FloatingDialog{
|
||||
button.left();
|
||||
button.row();
|
||||
button.add("[lightgray]" + (host.players != 1 ? Bundles.format("text.players", host.players) :
|
||||
Bundles.format("text.players.single", host.players)));
|
||||
button.row();
|
||||
button.add("[lightgray]" + host.address).pad(4).left();
|
||||
Bundles.format("text.players.single", host.players))).padBottom(5);
|
||||
}
|
||||
|
||||
void connect(String ip, int port){
|
||||
@@ -310,6 +308,7 @@ public class JoinDialog extends FloatingDialog{
|
||||
return UIUtils.portrait() ? 350f : 500f;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void loadServers(){
|
||||
servers = Settings.getObject("server-list", Array.class, Array::new);
|
||||
}
|
||||
|
||||
@@ -159,6 +159,26 @@ public class SectorsDialog extends FloatingDialog{
|
||||
});
|
||||
|
||||
clicked(() -> clicked = true);
|
||||
|
||||
this.focus();
|
||||
}
|
||||
|
||||
private void focus(){
|
||||
Sector focusSector = null;
|
||||
long newestTimestamp = 0;
|
||||
for(Sector sector : world.sectors.getSectors()){
|
||||
if(sector.hasSave()){
|
||||
long timestamp = sector.getSave().getTimestamp();
|
||||
if(timestamp > newestTimestamp){
|
||||
focusSector = sector;
|
||||
newestTimestamp = timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(focusSector != null) {
|
||||
panX = (focusSector.x + 0.5f) * sectorSize;
|
||||
panY = (focusSector.y + 0.5f) * sectorSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -109,7 +109,7 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
|
||||
cont.update(() -> {
|
||||
if(Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||
if(!Inputs.keyDown("gridMode") && Inputs.keyTap("toggle_menus") && !ui.chatfrag.chatOpen()){
|
||||
toggleMenus();
|
||||
}
|
||||
});
|
||||
@@ -139,7 +139,7 @@ public class HudFragment extends Fragment{
|
||||
if(Net.hasClient()){
|
||||
t.label(() -> ping.get(Net.getPing())).visible(Net::client).colspan(2);
|
||||
}
|
||||
}).size(-1).visible(() -> Settings.getBool("fps")).update(t -> t.setTranslation(0, (!waves.isVisible() ? wavetable.getHeight() : Math.min(wavetable.getTranslation().y, wavetable.getHeight())) )).get();
|
||||
}).size(-1).visible(() -> Settings.getBool("fps")).update(t -> t.setTranslation(0, (!waves.isVisible() ? wavetable.getHeight() : Math.min(wavetable.getTranslation().y, wavetable.getHeight())))).get();
|
||||
|
||||
//make wave box appear below rest of menu
|
||||
if(mobile){
|
||||
@@ -149,7 +149,7 @@ public class HudFragment extends Fragment{
|
||||
|
||||
//minimap
|
||||
parent.fill(t -> t.top().right().add(new Minimap())
|
||||
.visible(() -> !state.is(State.menu) && Settings.getBool("minimap")));
|
||||
.visible(() -> !state.is(State.menu) && Settings.getBool("minimap")));
|
||||
|
||||
//paused table
|
||||
parent.fill(t -> {
|
||||
@@ -198,7 +198,7 @@ public class HudFragment extends Fragment{
|
||||
return coreAttackOpacity > 0;
|
||||
});
|
||||
t.table("button", top -> top.add("$text.coreattack").pad(2)
|
||||
.update(label -> label.setColor(Hue.mix(Color.ORANGE, Color.SCARLET, Mathf.absin(Timers.time(), 2f, 1f)))));
|
||||
.update(label -> label.setColor(Hue.mix(Color.ORANGE, Color.SCARLET, Mathf.absin(Timers.time(), 2f, 1f)))));
|
||||
});
|
||||
|
||||
//'saving' indicator
|
||||
@@ -218,7 +218,7 @@ public class HudFragment extends Fragment{
|
||||
}
|
||||
});
|
||||
table.margin(12);
|
||||
table.addImage("icon-check").size(16*2).pad(3);
|
||||
table.addImage("icon-check").size(16 * 2).pad(3);
|
||||
table.add(text).wrap().width(280f).get().setAlignment(Align.center, Align.center);
|
||||
table.pack();
|
||||
|
||||
@@ -231,7 +231,7 @@ public class HudFragment extends Fragment{
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.removeActor())));
|
||||
}
|
||||
|
||||
/**Show unlock notification for a new recipe.*/
|
||||
/** Show unlock notification for a new recipe. */
|
||||
public void showUnlock(Recipe recipe){
|
||||
|
||||
//if there's currently no unlock notification...
|
||||
@@ -268,11 +268,11 @@ public class HudFragment extends Fragment{
|
||||
container.top().add(table);
|
||||
container.setTranslation(0, table.getPrefHeight());
|
||||
container.actions(Actions.translateBy(0, -table.getPrefHeight(), 1f, Interpolation.fade), Actions.delay(4f),
|
||||
//nesting actions() calls is necessary so the right prefHeight() is used
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
|
||||
lastUnlockTable = null;
|
||||
lastUnlockLayout = null;
|
||||
}), Actions.removeActor())));
|
||||
//nesting actions() calls is necessary so the right prefHeight() is used
|
||||
Actions.run(() -> container.actions(Actions.translateBy(0, table.getPrefHeight(), 1f, Interpolation.fade), Actions.run(() -> {
|
||||
lastUnlockTable = null;
|
||||
lastUnlockLayout = null;
|
||||
}), Actions.removeActor())));
|
||||
|
||||
lastUnlockTable = container;
|
||||
lastUnlockLayout = in;
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent;
|
||||
@@ -17,6 +18,8 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.OreBlock;
|
||||
import io.anuke.ucore.core.Events;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.input.Input;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.actions.Actions;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
@@ -38,6 +41,19 @@ public class PlacementFragment extends Fragment{
|
||||
boolean shown = true;
|
||||
boolean lastGround;
|
||||
|
||||
//TODO make this configurable
|
||||
final Input[] inputGrid = {
|
||||
Input.NUM_1, Input.NUM_2, Input.NUM_3, Input.NUM_4,
|
||||
Input.Q, Input.W, Input.E, Input.R,
|
||||
Input.A, Input.S, Input.D, Input.F,
|
||||
Input.Z, Input.X, Input.C, Input.V
|
||||
}, inputCatGrid = {
|
||||
Input.NUM_1, Input.NUM_2,
|
||||
Input.Q, Input.W,
|
||||
Input.A, Input.S,
|
||||
Input.Z, Input.X, Input.C, Input.V
|
||||
};
|
||||
|
||||
public PlacementFragment(){
|
||||
Events.on(WorldLoadGraphicsEvent.class, event -> {
|
||||
currentCategory = Category.turret;
|
||||
@@ -47,6 +63,42 @@ public class PlacementFragment extends Fragment{
|
||||
});
|
||||
}
|
||||
|
||||
boolean gridUpdate(InputHandler input){
|
||||
if(!Inputs.keyDown("gridMode") || ui.chatfrag.chatOpen()) return false;
|
||||
if(Inputs.keyDown("gridModeShift")){ //select category
|
||||
int i = 0;
|
||||
for(Input key : inputCatGrid){
|
||||
if(Inputs.keyDown(key)){
|
||||
input.recipe = Recipe.getByCategory(Category.values()[i]).first();
|
||||
currentCategory = input.recipe.category;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
}else if(Inputs.keyDown("select")){ //mouse eyedropper select
|
||||
Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y);
|
||||
|
||||
if(tile != null){
|
||||
tile = tile.target();
|
||||
Recipe tryRecipe = Recipe.getByResult(tile.block());
|
||||
if(tryRecipe != null && control.unlocks.isUnlocked(tryRecipe)){
|
||||
input.recipe = tryRecipe;
|
||||
currentCategory = input.recipe.category;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}else{ //select block
|
||||
int i = 0;
|
||||
Array<Recipe> recipes = Recipe.getByCategory(currentCategory);
|
||||
for(Input key : inputGrid){
|
||||
if(Inputs.keyDown(key))
|
||||
input.recipe = (i < recipes.size && control.unlocks.isUnlocked(recipes.get(i))) ? recipes.get(i) : null;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
parent.fill(full -> {
|
||||
@@ -74,7 +126,7 @@ public class PlacementFragment extends Fragment{
|
||||
|
||||
boolean[] unlocked = {false};
|
||||
|
||||
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8*4, () -> {
|
||||
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8 * 4, () -> {
|
||||
if(control.unlocks.isUnlocked(recipe)){
|
||||
input.recipe = input.recipe == recipe ? null : recipe;
|
||||
}
|
||||
@@ -111,8 +163,8 @@ public class PlacementFragment extends Fragment{
|
||||
frame.table("button-edge-2", top -> {
|
||||
topTable = top;
|
||||
top.add(new Table()).growX().update(topTable -> {
|
||||
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) ||
|
||||
(tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround)) return;
|
||||
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) || (tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround))
|
||||
return;
|
||||
|
||||
topTable.clear();
|
||||
topTable.top().left().margin(5);
|
||||
@@ -123,14 +175,14 @@ public class PlacementFragment extends Fragment{
|
||||
if(lastDisplay != null){ //show selected recipe
|
||||
topTable.table(header -> {
|
||||
header.left();
|
||||
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8*4);
|
||||
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8 * 4);
|
||||
header.labelWrap(() ->
|
||||
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName)
|
||||
.left().width(190f).padLeft(5);
|
||||
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName)
|
||||
.left().width(190f).padLeft(5);
|
||||
header.add().growX();
|
||||
if(control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay))){
|
||||
header.addButton("?", "clear-partial", () -> ui.content.show(Recipe.getByResult(lastDisplay)))
|
||||
.size(8 * 5).padTop(-5).padRight(-5).right().grow();
|
||||
.size(8 * 5).padTop(-5).padRight(-5).right().grow();
|
||||
}
|
||||
}).growX().left();
|
||||
topTable.row();
|
||||
@@ -141,7 +193,7 @@ public class PlacementFragment extends Fragment{
|
||||
for(ItemStack stack : Recipe.getByResult(lastDisplay).requirements){
|
||||
req.table(line -> {
|
||||
line.left();
|
||||
line.addImage(stack.item.region).size(8*2);
|
||||
line.addImage(stack.item.region).size(8 * 2);
|
||||
line.add(stack.item.localizedName()).color(Color.LIGHT_GRAY).padLeft(2).left();
|
||||
line.labelWrap(() -> {
|
||||
TileEntity core = players[0].getClosestCore();
|
||||
@@ -159,13 +211,13 @@ public class PlacementFragment extends Fragment{
|
||||
|
||||
}else if(tileDisplayBlock() != null){ //show selected tile
|
||||
lastDisplay = tileDisplayBlock();
|
||||
topTable.add(new ImageStack(lastDisplay.getDisplayIcon(hoverTile))).size(8*4);
|
||||
topTable.add(new ImageStack(lastDisplay.getDisplayIcon(hoverTile))).size(8 * 4);
|
||||
topTable.labelWrap(lastDisplay.getDisplayName(hoverTile)).left().width(190f).padLeft(5);
|
||||
}
|
||||
});
|
||||
}).colspan(3).fillX().visible(() -> getSelected() != null || tileDisplayBlock() != null).touchable(Touchable.enabled);
|
||||
frame.row();
|
||||
frame.addImage("blank").color(Palette.accent).colspan(3).height(3*2).growX();
|
||||
frame.addImage("blank").color(Palette.accent).colspan(3).height(3 * 2).growX();
|
||||
frame.row();
|
||||
frame.table("pane-2", blocksSelect -> {
|
||||
blocksSelect.margin(4).marginTop(0);
|
||||
@@ -181,21 +233,24 @@ public class PlacementFragment extends Fragment{
|
||||
for(Category cat : Category.values()){
|
||||
if(Recipe.getByCategory(cat).isEmpty()) continue;
|
||||
|
||||
categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16*2, () -> {
|
||||
categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16 * 2, () -> {
|
||||
currentCategory = cat;
|
||||
rebuildCategory.run();
|
||||
}).group(group).update(i -> i.setChecked(currentCategory == cat));
|
||||
|
||||
if(cat.ordinal() %2 == 1) categories.row();
|
||||
if(cat.ordinal() % 2 == 1) categories.row();
|
||||
}
|
||||
}).touchable(Touchable.enabled);
|
||||
|
||||
rebuildCategory.run();
|
||||
frame.update(() -> {
|
||||
if(gridUpdate(input)) rebuildCategory.run();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**Returns the currently displayed block in the top box.*/
|
||||
/** Returns the currently displayed block in the top box. */
|
||||
Block getSelected(){
|
||||
Block toDisplay = null;
|
||||
|
||||
@@ -226,12 +281,12 @@ public class PlacementFragment extends Fragment{
|
||||
return toDisplay;
|
||||
}
|
||||
|
||||
/**Returns the block currently being hovered over in the world.*/
|
||||
/** Returns the block currently being hovered over in the world. */
|
||||
Block tileDisplayBlock(){
|
||||
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.floor() instanceof OreBlock ? hoverTile.floor() : null;
|
||||
}
|
||||
|
||||
/**Show or hide the placement menu.*/
|
||||
/** Show or hide the placement menu. */
|
||||
void toggle(float t, Interpolation ip){
|
||||
toggler.clearActions();
|
||||
if(shown){
|
||||
|
||||
Reference in New Issue
Block a user