Added item names and descriptions, better unlock menu

This commit is contained in:
Anuken
2018-06-30 00:09:16 -04:00
parent bebc1a22f3
commit c0a649ffcb
12 changed files with 156 additions and 12 deletions

View File

@@ -20,6 +20,7 @@ import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.io.Map;
import io.anuke.mindustry.io.Saves;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.ucore.core.*;
@@ -250,12 +251,21 @@ public class Control extends Module{
return hiscore;
}
private void checkUnlockableBlocks(){
TileEntity entity = players[0].getClosestCore();
if(entity == null) return;
for (int i = 0; i < entity.items.items.length; i++) {
if(entity.items.items[i] <= 0) continue;
Item item = Item.getByID(i);
control.database().unlockContent(item);
}
if(players[0].inventory.hasItem()){
control.database().unlockContent(players[0].inventory.getItem().item);
}
for(int i = 0 ; i < Recipe.all().size; i ++){
Recipe recipe = Recipe.all().get(i);
if(!recipe.debugOnly && entity.items.hasItems(recipe.requirements)){

View File

@@ -19,4 +19,7 @@ public interface UnlockableContent extends Content{
/**This should show all necessary info about this content in the specified table.*/
void displayInfo(Table table);
/**Called when this content is unlocked. Use this to unlock other related content.*/
default void onUnlock(){}
}

View File

@@ -10,12 +10,15 @@ import io.anuke.mindustry.ui.ContentDisplay;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
public class Item implements Comparable<Item>, UnlockableContent{
private static final Array<Item> items = new Array<>();
public final int id;
public final String name;
public final String description;
public final Color color;
public TextureRegion region;
@@ -41,8 +44,14 @@ public class Item implements Comparable<Item>, UnlockableContent{
this.id = items.size;
this.name = name;
this.color = color;
this.description = Bundles.getOrNull("item." + this.name + ".description");
items.add(this);
if(!Bundles.has("item." + this.name + ".name")){
Log.err("Warning: item '" + name + "' is missing a localized name. Add the follow to bundle.properties:");
Log.err("item." + this.name + ".name=" + Strings.capitalize(name.replace('-', '_')));
}
}
public void load(){

View File

@@ -3,11 +3,15 @@ package io.anuke.mindustry.type;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.OrderedMap;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.ui.ContentDisplay;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.ContentStatValue;
import io.anuke.mindustry.world.meta.StatValue;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Log;
@@ -15,6 +19,7 @@ import io.anuke.ucore.util.Strings;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.debug;
import static io.anuke.mindustry.Vars.headless;
@@ -95,6 +100,21 @@ public class Recipe implements UnlockableContent{
return "recipe";
}
@Override
public void onUnlock() {
for(OrderedMap<BlockStat, StatValue> map : result.stats.toMap().values()){
for(StatValue value : map.values()){
if(value instanceof ContentStatValue){
ContentStatValue stat = (ContentStatValue)value;
UnlockableContent[] content = stat.getValueContent();
for(UnlockableContent c : content){
control.database().unlockContent(c);
}
}
}
}
}
@Override
public Array<? extends Content> getAll() {
return allRecipes;

View File

@@ -8,7 +8,6 @@ import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.type.Mech;
import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.blocks.defense.turrets.Turret;
import io.anuke.mindustry.world.meta.BlockStat;
@@ -17,15 +16,13 @@ import io.anuke.mindustry.world.meta.StatCategory;
import io.anuke.mindustry.world.meta.StatValue;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.ucore.util.Bundles;
public class ContentDisplay {
public static void displayRecipe(Table table, Recipe recipe){
Block block = recipe.result;
FloatingDialog dialog = new FloatingDialog("$text.blocks.blockinfo");
dialog.addCloseButton();
table.table(title -> {
int size = 8*6;
@@ -74,6 +71,37 @@ public class ContentDisplay {
public static void displayItem(Table table, Item item){
table.table(title -> {
title.addImage(item.getContentIcon()).size(8 * 6);
title.add("[accent]" + item.localizedName()).padLeft(5);
});
table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row();
if(item.description != null){
table.add(item.description).padLeft(5).padRight(5).width(400f).wrap().fillX();
table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row();
}
table.left().defaults().fillX();
table.add(Bundles.format("text.item.explosiveness", (int)(item.explosiveness * 100)));
table.row();
table.add(Bundles.format("text.item.flammability", (int)(item.flammability * 100)));
table.row();
table.add(Bundles.format("text.item.radioactivity", (int)(item.radioactivity * 100)));
table.row();
table.add(Bundles.format("text.item.fluxiness", (int)(item.fluxiness * 100)));
table.row();
table.add(Bundles.format("text.item.hardness", item.hardness));
table.row();
}
public static void displayLiquid(Table table, Liquid liquid){

View File

@@ -13,7 +13,7 @@ public class ItemImage extends Stack {
public ItemImage(TextureRegion region, Supplier<CharSequence> text) {
Table t = new Table().left().bottom();
t.label(text).color(Color.DARK_GRAY).padBottom(-60).get().setFontScale(0.5f);
t.label(text).color(Color.DARK_GRAY).padBottom(-22).get().setFontScale(0.5f);
t.row();
t.label(text).get().setFontScale(0.5f);

View File

@@ -21,6 +21,9 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.headless;
public class Drill extends Block{
protected final static float hardnessDrillMultiplier = 50f;
protected final int timerDump = timers++;
@@ -205,6 +208,11 @@ public class Drill extends Block{
int index = entity.index % toAdd.size;
offloadNear(tile, toAdd.get(index));
//unlock item content
if(!headless){
control.database().unlockContent(toAdd.get(index));
}
entity.index ++;
entity.progress = 0f;

View File

@@ -0,0 +1,7 @@
package io.anuke.mindustry.world.meta;
import io.anuke.mindustry.game.UnlockableContent;
public interface ContentStatValue extends StatValue {
UnlockableContent[] getValueContent();
}

View File

@@ -1,12 +1,13 @@
package io.anuke.mindustry.world.meta.values;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.ui.ItemImage;
import io.anuke.mindustry.world.meta.StatValue;
import io.anuke.mindustry.world.meta.ContentStatValue;
import io.anuke.ucore.scene.ui.layout.Table;
public class ItemListValue implements StatValue{
public class ItemListValue implements ContentStatValue{
private final Item[] items;
private final ItemStack[] stacks;
@@ -20,6 +21,19 @@ public class ItemListValue implements StatValue{
this.items = null;
}
@Override
public UnlockableContent[] getValueContent() {
if(items != null){
return items;
}else {
Item[] res = new Item[stacks.length];
for (int i = 0; i < res.length; i++) {
res[i] = stacks[i].item;
}
return res;
}
}
@Override
public void display(Table table) {
if(items != null){

View File

@@ -1,17 +1,24 @@
package io.anuke.mindustry.world.meta.values;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.ui.ItemImage;
import io.anuke.mindustry.world.meta.StatValue;
import io.anuke.mindustry.world.meta.ContentStatValue;
import io.anuke.ucore.scene.ui.layout.Table;
public class ItemValue implements StatValue {
public class ItemValue implements ContentStatValue {
private final ItemStack item;
public ItemValue(ItemStack item) {
this.item = item;
}
@Override
public UnlockableContent[] getValueContent() {
return new Item[]{item.item};
}
@Override
public void display(Table table) {
//TODO better implementation, quantity support

View File

@@ -1,16 +1,22 @@
package io.anuke.mindustry.world.meta.values;
import io.anuke.mindustry.game.UnlockableContent;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.meta.StatValue;
import io.anuke.mindustry.world.meta.ContentStatValue;
import io.anuke.ucore.scene.ui.layout.Table;
public class LiquidValue implements StatValue {
public class LiquidValue implements ContentStatValue {
private final Liquid liquid;
public LiquidValue(Liquid liquid) {
this.liquid = liquid;
}
@Override
public UnlockableContent[] getValueContent() {
return new UnlockableContent[]{liquid};
}
@Override
public void display(Table table) {
table.addImage("liquid-icon").color(liquid.color).size(8*3);