Scrapped current place menu

This commit is contained in:
Anuken
2018-05-28 16:23:23 -04:00
parent ce68c2a3e9
commit 2bf7d06a91
14 changed files with 67 additions and 439 deletions

View File

@@ -50,7 +50,7 @@ public class Vars{
//how far away from spawn points the player can't place blocks
public static final float enemyspawnspace = 65;
public static final float coreBuildRange = 1000f;
public static final float coreBuildRange = 400f;
//discord group URL
public static final String discordURL = "https://discord.gg/BKADYds";

View File

@@ -47,7 +47,7 @@ public class AmmoTypes {
smokeEffect = ShootFx.shootSmallSmoke;
}},
flakExplosive = new AmmoType(Items.rdx, FlakBullets.explosive, 5){{
flakExplosive = new AmmoType(Items.blastCompound, FlakBullets.explosive, 5){{
shootEffect = ShootFx.shootSmall;
smokeEffect = ShootFx.shootSmallSmoke;
}},
@@ -69,7 +69,7 @@ public class AmmoTypes {
smokeEffect = ShootFx.shootBigSmoke2;
}},
shellExplosive = new AmmoType(Items.rdx, ShellBullets.explosive, 1){{
shellExplosive = new AmmoType(Items.blastCompound, ShellBullets.explosive, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
}},
@@ -86,7 +86,7 @@ public class AmmoTypes {
//missiles
missileExplosive = new AmmoType(Items.rdx, MissileBullets.explosive, 1){{
missileExplosive = new AmmoType(Items.blastCompound, MissileBullets.explosive, 1){{
shootEffect = ShootFx.shootBig2;
smokeEffect = ShootFx.shootBigSmoke2;
}},

View File

@@ -38,6 +38,7 @@ public class Items {
}},
thorium = new Item("thorium", Color.valueOf("f9a3c7")) {{
type = ItemType.material;
explosiveness = 0.1f;
hardness = 4;
}},
@@ -52,12 +53,11 @@ public class Items {
explosiveness = 0.1f;
}},
surgealloy = new Item("surgealloy", Color.valueOf("b4d5c7")){{
surgealloy = new Item("surge-alloy", Color.valueOf("b4d5c7")){{
type = ItemType.material;
}},
biomatter = new Item("biomatter", Color.valueOf("648b55")) {{
type = ItemType.material;
flammability = 0.4f;
fluxiness = 0.2f;
}},
@@ -66,7 +66,7 @@ public class Items {
fluxiness = 0.5f;
}},
rdx = new Item("rdx", Color.valueOf("ff795e")){{
blastCompound = new Item("blast-compound", Color.valueOf("ff795e")){{
flammability = 0.2f;
explosiveness = 0.6f;
}},

View File

@@ -1,12 +1,21 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectMap.Entry;
import com.badlogic.gdx.utils.ObjectSet;
import io.anuke.ucore.core.Settings;
import static io.anuke.mindustry.Vars.debug;
public class ContentDatabase {
private ObjectMap<String, ObjectSet<String>> unlocked = new ObjectMap<>();
public boolean isUnlocked(Content content){
if(debug){
return true;
}
if(!unlocked.containsKey(content.getContentTypeName())){
unlocked.put(content.getContentTypeName(), new ObjectSet<>());
}
@@ -17,11 +26,23 @@ public class ContentDatabase {
}
private void load(){
ObjectMap<String, Array<String>> result = Settings.getJson("content-database", ObjectMap.class);
for(Entry<String, Array<String>> entry : result.entries()){
ObjectSet<String> set = new ObjectSet<>();
set.addAll(entry.value);
unlocked.put(entry.key, set);
}
}
private void save(){
ObjectMap<String, Array<String>> write = new ObjectMap<>();
for(Entry<String, ObjectSet<String>> entry : unlocked.entries()){
write.put(entry.key, entry.value.iterator().toArray());
}
Settings.putJson("content-database", write);
}
}

View File

@@ -24,8 +24,6 @@ public class Maps implements Disposable{
private Array<Map> allMaps = new Array<>();
/**Temporary array used for returning things.*/
private Array<Map> returnArray = new Array<>();
/**Used for writing a list of custom map names on GWT.*/
private Json json = new Json();
/**Used for storing a list of custom map names for GWT.*/
private Array<String> customMapNames;
@@ -87,7 +85,7 @@ public class Maps implements Disposable{
Settings.putString("map-data-" + name, new String(Base64Coder.encode(stream.toByteArray())));
if(!customMapNames.contains(name, false)){
customMapNames.add(name);
Settings.putString("custom-maps", json.toJson(customMapNames));
Settings.putJson("custom-maps", customMapNames);
}
Settings.save();
}
@@ -127,7 +125,7 @@ public class Maps implements Disposable{
} else {
customMapNames.removeValue(map.name, false);
Settings.putString("map-data-" + map.name, "");
Settings.putString("custom-maps", json.toJson(customMapNames));
Settings.putJson("custom-maps", customMapNames);
Settings.save();
}
}
@@ -159,7 +157,7 @@ public class Maps implements Disposable{
}
}else{
customMapNames = json.fromJson(Array.class, Settings.getString("custom-maps", "{}"));
customMapNames = Settings.getJson("custom-maps", Array.class);
for(String name : customMapNames){
try{

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.net;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.ucore.core.Settings;
@@ -10,7 +9,6 @@ public class Administration {
public static final int defaultMaxBrokenBlocks = 15;
public static final int defaultBreakCooldown = 1000*15;
private Json json = new Json();
/**All player info. Maps UUIDs to info. This persists throughout restarts.*/
private ObjectMap<String, PlayerInfo> playerInfo = new ObjectMap<>();
/**Maps UUIDs to trace infos. This is wiped when a player logs off.*/
@@ -19,8 +17,6 @@ public class Administration {
public Administration(){
Settings.defaultList(
"playerInfo", "{}",
"bannedIPs", "{}",
"antigrief", false,
"antigrief-max", defaultMaxBrokenBlocks,
"antigrief-cooldown", defaultBreakCooldown
@@ -289,14 +285,14 @@ public class Administration {
}
public void save(){
Settings.putString("playerInfo", json.toJson(playerInfo));
Settings.putString("bannedIPs", json.toJson(bannedIPs));
Settings.putJson("player-info", playerInfo);
Settings.putJson("banned-ips", bannedIPs);
Settings.save();
}
private void load(){
playerInfo = json.fromJson(ObjectMap.class, Settings.getString("playerInfo"));
bannedIPs = json.fromJson(Array.class, Settings.getString("bannedIPs"));
playerInfo = Settings.getJson("player-info", ObjectMap.class);
bannedIPs = Settings.getJson("banned-ips", Array.class);
}
public static class PlayerInfo{

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.Platform;
import io.anuke.mindustry.entities.Player;
@@ -33,7 +32,6 @@ public class JoinDialog extends FloatingDialog {
Table local = new Table();
Table remote = new Table();
Table hosts = new Table();
Json json = new Json();
float w = 500;
public JoinDialog(){
@@ -309,12 +307,11 @@ public class JoinDialog extends FloatingDialog {
}
private void loadServers(){
String h = Settings.getString("serverlist","{}");
servers = json.fromJson(Array.class, h);
servers = Settings.getJson("server-list", Array.class);
}
private void saveServers(){
Settings.putString("serverlist", json.toJson(servers));
Settings.putJson("server-list", servers);
Settings.save();
}

View File

@@ -1,406 +1,11 @@
package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntSet;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.type.Section;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.BlockStats;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.actions.Actions;
import io.anuke.ucore.scene.builders.table;
import io.anuke.ucore.scene.event.ClickListener;
import io.anuke.ucore.scene.event.InputEvent;
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.util.Bundles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.*;
public class BlocksFragment implements Fragment{
private Table desctable, itemtable, blocks;
private Stack stack = new Stack();
private boolean shown = true;
private Recipe hoveredDescriptionRecipe;
private IntSet itemset = new IntSet();
private int[] tmpItems;
{
int size = 0;
for(Item ignored : Item.all()){
size ++;
}
tmpItems = new int[size];
}
@Override
public void build(Group parent){
InputHandler input = control.input(0);
new table(){{
abottom();
aright();
visible(() -> !state.is(State.menu) && shown);
blocks = new table(){{
itemtable = new Table("button");
itemtable.setVisible(() -> false);
itemtable.update(() -> {
int[] items = tmpItems;
for(int i = 0; i < items.length; i ++){
if(itemset.contains(items[i]) != (items[i] > 0)){
updateItems();
break;
}
}
});
desctable = new Table("button");
desctable.setVisible(() -> hoveredDescriptionRecipe != null || input.recipe != null);
desctable.update(() -> {
// note: This is required because there is no direct connection between
// input.recipe and the description ui. If input.recipe gets set to null
// a proper cleanup of the ui elements is required.
boolean anyRecipeShown = input.recipe != null || hoveredDescriptionRecipe != null;
boolean descriptionTableClean = desctable.getChildren().size == 0;
boolean cleanupRequired = !anyRecipeShown && !descriptionTableClean;
if(cleanupRequired){
desctable.clear();
}
});
stack.add(itemtable);
stack.add(desctable);
add(stack).fillX().uniformX();
row();
new table("pane") {{
touchable(Touchable.enabled);
int rows = 4;
int maxcol = 0;
float size = 48;
Stack stack = new Stack();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Array<Recipe> recipes = new Array<>();
for (Section sec : Section.values()) {
recipes.clear();
Recipe.getBySection(sec, recipes);
maxcol = Math.max((int) ((float) recipes.size / rows + 1), maxcol);
}
for (Section sec : Section.values()) {
int secrows = 4;
recipes.clear();
Recipe.getBySection(sec, recipes);
Table table = new Table();
ImageButton button = new ImageButton("icon-" + sec.name(), "toggle");
button.clicked(() -> {
if (!table.isVisible() && input.recipe != null) {
input.recipe = null;
}
});
button.setName("sectionbutton" + sec.name());
add(button).growX().height(54).padLeft(-1).padTop(sec.ordinal() <= secrows-1 ? -10 : -5);
button.getImageCell().size(40).padBottom(4).padTop(2);
group.add(button);
if (sec.ordinal() % secrows == secrows-1) {
row();
}
table.margin(4);
table.top().left();
int i = 0;
for (Recipe r : recipes) {
ImageButton image = new ImageButton(new TextureRegion(), "select");
TextureRegion[] regions = r.result.getCompactIcon();
Stack istack = new Stack();
for(TextureRegion region : regions){
istack.add(new Image(region));
}
image.getImageCell().setActor(istack).size(size);
image.addChild(istack);
image.getImage().remove();
image.addListener(new ClickListener(){
@Override
public void enter(InputEvent event, float x, float y, int pointer, Element fromActor) {
super.enter(event, x, y, pointer, fromActor);
if (hoveredDescriptionRecipe != r) {
hoveredDescriptionRecipe = r;
updateRecipe(r);
}
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Element toActor) {
super.exit(event, x, y, pointer, toActor);
hoveredDescriptionRecipe = null;
updateRecipe(input.recipe);
}
});
image.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
// note: input.recipe only gets set here during a click.
// during a hover only the visual description will be updated.
InputHandler handler = mobile ? input : control.input(event.getPointer());
boolean nothingSelectedYet = handler.recipe == null;
boolean selectedSomethingElse = !nothingSelectedYet && handler.recipe != r;
boolean shouldMakeSelection = nothingSelectedYet || selectedSomethingElse;
if (shouldMakeSelection) {
handler.recipe = r;
hoveredDescriptionRecipe = r;
updateRecipe(r);
} else {
handler.recipe = null;
hoveredDescriptionRecipe = null;
updateRecipe(null);
}
}
});
table.add(image).size(size + 8);
image.update(() -> {
image.setTouchable(Touchable.enabled);
for(Element e : istack.getChildren()){
e.setColor(Color.WHITE);
}
for(Player player : players){
if(control.input(player.playerIndex).recipe == r){
image.setChecked(true);
return;
}
}
image.setChecked(false);
});
if (i % rows == rows - 1)
table.row();
i++;
}
table.setVisible(button::isChecked);
stack.add(table);
}
row();
add(stack).colspan(Section.values().length);
margin(10f);
marginLeft(1f);
marginRight(1f);
end();
}}.right().bottom().uniformX();
visible(() -> !state.is(State.menu) && shown);
}}.end().get();
}}.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){
if (recipe == null) {
desctable.clear();
return;
}
desctable.clear();
desctable.setTouchable(Touchable.enabled);
desctable.defaults().left();
desctable.left();
desctable.margin(12);
Table header = new Table();
desctable.add(header).left();
desctable.row();
TextureRegion[] regions = recipe.result.getCompactIcon();
Stack istack = new Stack();
for(TextureRegion region : regions) istack.add(new Image(region));
header.add(istack).size(8*5).padTop(4);
Label nameLabel = new Label(recipe.result.formalName);
nameLabel.setWrap(true);
header.add(nameLabel).padLeft(2).width(120f);
//extra info
if(recipe.result.fullDescription != null){
header.addButton("?", () -> showBlockInfo(recipe.result)).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
}
desctable.add().pad(2);
Table requirements = new Table();
desctable.row();
desctable.add(requirements);
desctable.left();
for(ItemStack stack : recipe.requirements){
requirements.addImage(stack.item.region).size(8*3);
Label reqlabel = new Label("");
reqlabel.update(()->{
int current = stack.amount;
String text = Mathf.clamp(current, 0, stack.amount) + "/" + stack.amount;
reqlabel.setColor(current < stack.amount ? Palette.missingitems : Color.WHITE);
reqlabel.setText(text);
});
requirements.add(reqlabel).left();
requirements.row();
}
desctable.row();
Label label = new Label("[health]"+ Bundles.get("text.health")+": " + recipe.result.health);
label.setWrap(true);
desctable.add(label).width(200).padTop(4).padBottom(2);
}
public void showBlockInfo(Block block){
Array<String> statlist = new Array<String>();
BlockStats stats = block.stats;
for(String s : stats.getMap().orderedKeys()){
statlist.add(Bundles.get("text.blocks." + s) + ": []" + stats.getMap().get(s));
}
Label desclabel = new Label(block.fullDescription);
desclabel.setWrap(true);
boolean wasPaused = state.is(State.paused);
state.set(State.paused);
FloatingDialog d = new FloatingDialog("$text.blocks.blockinfo");
Table table = new Table();
table.defaults().pad(1f);
ScrollPane pane = new ScrollPane(table, "clear");
pane.setFadeScrollBars(false);
Table top = new Table();
top.left();
top.add(new Image(Draw.region(block.name))).size(8*5 * block.size);
top.add("[accent]"+block.formalName).padLeft(6f);
table.add(top).fill().left();
table.row();
table.add(desclabel).width(600);
table.row();
d.content().add(pane).grow();
if(statlist.size > 0){
table.add("$text.blocks.extrainfo").padTop(6).padBottom(5).left();
table.row();
}
for(String s : statlist){
table.add(s).left();
table.row();
}
d.buttons().addButton("$text.ok", ()->{
if(!wasPaused) state.set(State.playing);
d.hide();
}).size(110, 50).pad(10f);
d.show();
}
private void updateItems(){
itemtable.clear();
itemtable.left();
if(state.mode.infiniteResources){
return;
};
int index = 0;
int[] items = tmpItems;
for(int i = 0; i < items.length; i ++){
int amount = items[i];
if(amount == 0){
itemset.remove(i);
continue;
}
itemset.add(i);
Image image = new Image(Item.getByID(i).region);
Label label = new Label(() -> format(amount));
label.setFontScale(fontscale*1.5f);
itemtable.add(image).size(8*3);
itemtable.add(label).expandX().left();
if(index++ % 2 == 1 && index > 0) itemtable.row();
}
}
String format(int number){
if(number > 99999999){
return "inf";
}else 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

@@ -188,12 +188,12 @@ public class HudFragment implements Fragment{
flip.getStyle().imageUp = Core.skin.getDrawable(shown ? "icon-arrow-down" : "icon-arrow-up");
if (shown) {
blockfrag.toggle(false, dur, in);
//blockfrag.toggle(false, dur, in);
wavetable.actions(Actions.translateBy(0, wavetable.getHeight() + dsize, dur, in), Actions.call(() -> shown = false));
infolabel.actions(Actions.translateBy(0, wavetable.getHeight(), dur, in), Actions.call(() -> shown = false));
} else {
shown = true;
blockfrag.toggle(true, dur, in);
//blockfrag.toggle(true, dur, in);
wavetable.actions(Actions.translateBy(0, -wavetable.getTranslation().y, dur, in));
infolabel.actions(Actions.translateBy(0, -infolabel.getTranslation().y, dur, in));
}

View File

@@ -13,6 +13,7 @@ import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.effect.DamageArea;
import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.entities.effect.Rubble;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.graphics.CacheLayer;
import io.anuke.mindustry.graphics.Layer;
import io.anuke.mindustry.graphics.Palette;
@@ -32,7 +33,7 @@ import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.*;
public class Block extends BaseBlock {
public class Block extends BaseBlock implements Content{
private static int lastid;
private static Array<Block> blocks = new Array<>();
private static ObjectMap<String, Block> map = new ObjectMap<>();
@@ -444,6 +445,16 @@ public class Block extends BaseBlock {
);
}
@Override
public String getContentName() {
return name;
}
@Override
public String getContentTypeName() {
return "block";
}
@Override
public String toString(){
return name;