Clean Up Stylesheet loading

This commit is contained in:
Nedelosk committed 2017-08-13 14:43:52 +02:00
1 parent fdb9a14962
commit fab5b82cbe
7 files changed
+205 -163

No files matched your search

@@ -19,8 +19,8 @@ import binnie.core.gui.resource.minecraft.StandardTexture;
import binnie.core.util.I18N;
public class ControlColorMixSymbol extends Control implements ITooltip {
static Texture MutationPlus = new StandardTexture(2, 94, 16, 16, CraftGUITextureSheet.CONTROLS_2);
static Texture MutationArrow = new StandardTexture(20, 94, 32, 16, CraftGUITextureSheet.CONTROLS_2);
static Texture MutationPlus = new StandardTexture(2, 94, 16, 16, CraftGUITextureSheet.CONTROLS);
static Texture MutationArrow = new StandardTexture(20, 94, 32, 16, CraftGUITextureSheet.CONTROLS);
IColorMix value;
int type;
@@ -1,10 +1,10 @@
package binnie.core.gui.database;
import binnie.core.api.genetics.IBreedingSystem;
import binnie.core.api.gui.IArea;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import binnie.core.api.genetics.IBreedingSystem;
import binnie.core.api.gui.IArea;
import binnie.core.gui.CraftGUI;
import binnie.core.gui.IWidget;
import binnie.core.gui.controls.core.Control;
@@ -16,7 +16,7 @@ import binnie.core.gui.resource.minecraft.CraftGUITextureSheet;
import binnie.core.gui.resource.minecraft.StandardTexture;
class ControlBreedingProgress extends Control {
private static Texture Progress = new StandardTexture(80, 22, 4, 4, CraftGUITextureSheet.CONTROLS_2);
private static Texture Progress = new StandardTexture(80, 22, 4, 4, CraftGUITextureSheet.CONTROLS);
private float percentage;
private int colour;
@@ -1,13 +1,14 @@
package binnie.core.gui.database;
import binnie.core.api.genetics.IBreedingSystem;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IMutation;
import binnie.core.api.genetics.IBreedingSystem;
import binnie.core.gui.Attribute;
import binnie.core.gui.CraftGUI;
import binnie.core.gui.ITooltip;
@@ -22,8 +23,8 @@ import binnie.core.gui.resource.minecraft.StandardTexture;
import binnie.core.util.I18N;
class ControlMutationSymbol extends Control implements ITooltip {
private static Texture MutationPlus = new StandardTexture(2, 94, 16, 16, CraftGUITextureSheet.CONTROLS_2);
private static Texture MutationArrow = new StandardTexture(20, 94, 32, 16, CraftGUITextureSheet.CONTROLS_2);
private static Texture MutationPlus = new StandardTexture(2, 94, 16, 16, CraftGUITextureSheet.CONTROLS);
private static Texture MutationArrow = new StandardTexture(20, 94, 32, 16, CraftGUITextureSheet.CONTROLS);
private IMutation value;
private boolean discovered;
private int type;
@@ -1,6 +1,7 @@
package binnie.core.gui.resource.minecraft;
import com.google.common.base.Charsets;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
@@ -9,9 +10,7 @@ import com.google.gson.JsonParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
@@ -19,19 +18,33 @@ import org.apache.commons.io.IOUtils;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import binnie.core.Constants;
import binnie.core.gui.CraftGUI;
import binnie.core.gui.geometry.Area;
import binnie.core.gui.geometry.Border;
import binnie.core.gui.resource.Texture;
import binnie.core.resource.IBinnieTexture;
import binnie.core.util.Log;
@SideOnly(Side.CLIENT)
public class CraftGUIResourceManager implements IResourceManagerReloadListener {
public static final ResourceLocation SHEET_LOCATION = new ResourceLocation(Constants.CORE_MOD_ID, "gui/stylesheet.json");
public static final String SHEETS_KEY = "texture-sheets";
public static final String NAME_KEY = "name";
public static final String MODID_KEY = "modid";
public static final String PATH_KEY = "path";
public static final String SHEET_KEY = "sheet";
public static final String UV_KEY = "uv";
public static final String BORDER_KEY = "border";
public static final String PADDING_KEY = "padding";
public static final String TEXTURES_KEY = "textures";
private Map<String, ParsedTextureSheet> textureSheets;
private Map<String, Texture> textures;
@@ -41,103 +54,135 @@ public class CraftGUIResourceManager implements IResourceManagerReloadListener {
CraftGUI.resourceManager = this;
}
//TODO: Clean Up
@Override
public void onResourceManagerReload(final IResourceManager manager) {
this.textureSheets.clear();
try {
final IResource res = manager.getResource(new ResourceLocation("binniecore", "gui/stylesheet.json"));
JsonObject jsonobject = null;
IResource res = manager.getResource(SHEET_LOCATION);
BufferedReader bufferedreader = null;
try {
bufferedreader = new BufferedReader(new InputStreamReader(res.getInputStream(), Charsets.UTF_8));
jsonobject = new JsonParser().parse(bufferedreader).getAsJsonObject();
for (final JsonElement el : jsonobject.get("texture-sheets").getAsJsonArray()) {
if (el instanceof JsonObject) {
final JsonObject sheet = (JsonObject) el;
final String name = sheet.get("name").getAsString();
final String modid = sheet.get("modid").getAsString();
final String path = sheet.get("path").getAsString();
this.textureSheets.put(name, new ParsedTextureSheet(name, modid, path));
}
}
for (final JsonElement el : jsonobject.get("textures").getAsJsonArray()) {
if (el instanceof JsonObject) {
final JsonObject sheet = (JsonObject) el;
final String name = sheet.get("name").getAsString();
final IBinnieTexture textureSheet = this.getTextureSheet(sheet.get("sheet").getAsString());
final Area uv = this.getArea(sheet.get("uv").getAsString());
Border border = Border.ZERO;
Border padding = Border.ZERO;
if (sheet.has("border")) {
border = this.getBorder(sheet.get("border").getAsString());
}
if (sheet.has("padding")) {
padding = this.getBorder(sheet.get("padding").getAsString());
}
this.textures.put(name, new Texture(uv, padding, border, textureSheet));
}
}
} catch (RuntimeException runtimeexception) {
throw new JsonParseException("Failed to parse stylesheet for Binnie's Mods", runtimeexception);
} finally {
IOUtils.closeQuietly(bufferedreader);
}
bufferedreader = new BufferedReader(new InputStreamReader(res.getInputStream(), Charsets.UTF_8));
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(bufferedreader).getAsJsonObject();
parseTextureSheets(jsonObject);
parseTextures(jsonObject);
IOUtils.closeQuietly(bufferedreader);
} catch (IOException e) {
throw new RuntimeException("Failed to load default stylesheet for Binnie's Mods.", e);
}
}
public Area getArea(final String name) {
final String[] split = name.split(" ");
if (split.length < 1 || split.length > 4) {
throw new RuntimeException("Parameter must have between one and four numbers");
private void parseTextureSheets(JsonObject jsonObject){
JsonArray textureSheets = JsonUtils.getJsonArray(jsonObject, SHEETS_KEY);
if(textureSheets == null){
return;
}
final List<Integer> i = new ArrayList<>();
for (final String string : split) {
i.add(Integer.parseInt(string));
for (JsonElement element : textureSheets) {
if(!element.isJsonObject()){
continue;
}
try {
JsonObject sheetJson = (JsonObject) element;
String name = JsonUtils.getString(sheetJson, NAME_KEY);
String modid = JsonUtils.getString(sheetJson, MODID_KEY);
String path = JsonUtils.getString(sheetJson, PATH_KEY);
ParsedTextureSheet textureSheet = new ParsedTextureSheet(name, modid, path);
this.textureSheets.put(name, textureSheet);
}catch(Exception e){
Log.warning("Failed to load stylesheet for Binnie's Mods.", e);
}
}
if (i.size() == 1) {
return new Area(i.get(0));
}
if (i.size() == 2) {
return new Area(i.get(0), i.get(1));
}
if (i.size() == 3) {
return new Area(i.get(0), i.get(1), i.get(2));
}
return new Area(i.get(0), i.get(1), i.get(2), i.get(3));
}
public Border getBorder(final String name) {
final String[] split = name.split(" ");
if (split.length < 1 || split.length > 4) {
throw new RuntimeException("Parameter must have between one and four numbers");
private void parseTextures(JsonObject jsonObject){
JsonArray textures = JsonUtils.getJsonArray(jsonObject, TEXTURES_KEY);
if(textures == null){
return;
}
final List<Integer> i = new ArrayList<>();
for (final String string : split) {
i.add(Integer.parseInt(string));
for (JsonElement element : textures) {
if(!element.isJsonObject()){
continue;
}
try {
JsonObject sheetJson = element.getAsJsonObject();
parseTexture(sheetJson);
}catch(Exception e){
Log.warning("Failed to load stylesheet for Binnie's Mods.", e);
}
}
if (i.size() == 1) {
return new Border(i.get(0));
}
if (i.size() == 2) {
return new Border(i.get(0), i.get(1));
}
if (i.size() == 3) {
return new Border(i.get(0), i.get(1), i.get(2));
}
return new Border(i.get(0), i.get(1), i.get(2), i.get(3));
}
public IBinnieTexture getTextureSheet(final String name) {
private void parseTexture(JsonObject sheetJson){
String name = JsonUtils.getString(sheetJson, NAME_KEY);
String sheet = JsonUtils.getString(sheetJson, SHEET_KEY);
JsonArray uvArray = JsonUtils.getJsonArray(sheetJson, UV_KEY);
IBinnieTexture textureSheet = this.getTextureSheet(sheet);
Area uv = this.parseArea(uvArray);
Border border = Border.ZERO;
Border padding = Border.ZERO;
if (sheetJson.has(BORDER_KEY)) {
JsonArray array = JsonUtils.getJsonArray(sheetJson, BORDER_KEY);
border = this.parseBorder(array);
}
if (sheetJson.has(PADDING_KEY)) {
JsonArray array = JsonUtils.getJsonArray(sheetJson, PADDING_KEY);
padding = this.parseBorder(array);
}
Texture texture = new Texture(uv, padding, border, textureSheet);
this.textures.put(name, texture);
}
public Area parseArea(JsonArray uvArray) {
int[] ints = new int[uvArray.size()];
if (ints.length < 1 || ints.length > 4) {
throw new JsonParseException("Parameter must have between one and four numbers");
}
for(int i = 0;i < uvArray.size();i++){
JsonElement object = uvArray.get(i);
ints[i] = JsonUtils.getInt(object, "uv" + i);
}
if (ints.length == 1) {
return new Area(ints[0]);
}
if (ints.length == 2) {
return new Area(ints[0], ints[1]);
}
if (ints.length == 3) {
return new Area(ints[0], ints[1], ints[2]);
}
return new Area(ints[0], ints[1], ints[2], ints[3]);
}
public Border parseBorder(JsonArray array) {
int[] ints = new int[array.size()];
if (ints.length < 1 || ints.length > 4) {
throw new JsonParseException("Parameter must have between one and four numbers");
}
for(int i = 0;i < array.size();i++){
JsonElement object = array.get(i);
ints[i] = JsonUtils.getInt(object, UV_KEY + i);
}
if (ints.length == 1) {
return new Border(ints[0]);
}
if (ints.length == 2) {
return new Border(ints[0], ints[1]);
}
if (ints.length == 3) {
return new Border(ints[0], ints[1], ints[2]);
}
return new Border(ints[0], ints[1], ints[2], ints[3]);
}
public IBinnieTexture getTextureSheet(String name) {
if (!this.textureSheets.containsKey(name)) {
throw new RuntimeException("Missing GUI texture sheet for Binnie Mods: " + name);
}
return this.textureSheets.get(name);
}
public Texture getTexture(final String name) {
public Texture getTexture(String name) {
if (!this.textures.containsKey(name)) {
throw new RuntimeException("Missing GUI texture Binnie Mods: " + name);
}
@@ -10,8 +10,8 @@ import binnie.core.resource.BinnieResource;
import binnie.core.resource.IBinnieTexture;
public enum CraftGUITextureSheet implements IBinnieTexture {
CONTROLS_2("controls"),
PANEL_2("panels"),
CONTROLS("controls"),
PANEL("panels"),
SLOTS("slots");
private final String name;
@@ -20,7 +20,7 @@ public enum CraftGUITextureSheet implements IBinnieTexture {
@Nullable
private BinnieResource resource;
CraftGUITextureSheet(final String name) {
private CraftGUITextureSheet(final String name) {
this.name = name;
}
@@ -24,250 +24,250 @@
{
"name": "window",
"sheet": "panels",
"uv": "6 6 64 64",
"padding": "8"
"uv": [6, 6, 64, 64],
"padding": [8]
},
{
"name": "panel.gray",
"sheet": "panels",
"uv": "78 4 32 32",
"padding": "2"
"uv": [78, 4, 32, 32],
"padding": [2]
},
{
"name": "panel.black",
"sheet": "panels",
"uv": "116 4 32 32",
"padding": "2"
"uv": [116, 4, 32, 32],
"padding": [2]
},
{
"name": "panel.tinted",
"sheet": "panels",
"uv": "154 4 32 32",
"padding": "2"
"uv": [154, 4, 32, 32],
"padding": [2]
},
{
"name": "button",
"sheet": "controls",
"uv": "30 4 20 20",
"padding": "4"
"uv": [30, 4, 20, 20],
"padding": [4]
},
{
"name": "button.highlighted",
"sheet": "controls",
"uv": "56 4 20 20",
"padding": "4"
"uv": [56, 4, 20, 20],
"padding": [4]
},
{
"name": "button.disabled",
"sheet": "controls",
"uv": "4 4 20 20",
"padding": "4"
"uv": [4, 4, 20, 20],
"padding": [4]
},
{
"name": "slot",
"sheet": "slots",
"uv": "4 4 18 18",
"padding": "2"
"uv": [4, 4, 18, 18],
"padding": [2]
},
{
"name": "slot.border",
"sheet": "slots",
"uv": "28 4 18 18",
"padding": "2"
"uv": [28, 4, 18, 18],
"padding": [2]
},
{
"name": "slot.overlay",
"sheet": "slots",
"uv": "52 4 18 18",
"padding": "2"
"uv": [52, 4, 18, 18],
"padding": [2]
},
{
"name": "slot.charge",
"sheet": "slots",
"uv": "2 26 2 16",
"padding": "0"
"uv": [2, 26, 2, 16],
"padding": [0]
},
{
"name": "liquidtank",
"sheet": "slots",
"uv": "8 28 18 60",
"padding": "1"
"uv": [8, 28, 18, 60],
"padding": [1]
},
{
"name": "liquidtank.overlay",
"sheet": "slots",
"uv": "32 28 18 60",
"padding": "1"
"uv": [32, 28, 18, 60],
"padding": [1]
},
{
"name": "errorstate.none",
"sheet": "controls",
"uv": "44 30 14 14"
"uv": [44, 30, 14, 14]
},
{
"name": "errorstate.warning",
"sheet": "controls",
"uv": "24 30 14 14"
"uv": [24, 30, 14, 14]
},
{
"name": "errorstate.error",
"sheet": "controls",
"uv": "4 30 14 14"
"uv": [4, 30, 14, 14]
},
{
"name": "errorstate.error",
"sheet": "controls",
"uv": "4 30 14 14"
"uv": [4, 30, 14, 14]
},
{
"name": "energybar.back",
"sheet": "controls",
"uv": "40 50 12 14",
"padding": "1"
"uv": [40, 50, 12, 14],
"padding": [1]
},
{
"name": "energybar.glow",
"sheet": "controls",
"uv": "4 50 12 14",
"padding": "1"
"uv": [4, 50, 12, 14],
"padding": [1]
},
{
"name": "energybar.glass",
"sheet": "controls",
"uv": "22 50 12 14",
"padding": "1"
"uv": [22, 50, 12, 14],
"padding": [1]
},
{
"name": "tab",
"sheet": "controls",
"uv": "30 70 20 20",
"padding": "6"
"uv": [30, 70, 20, 20],
"padding": [6]
},
{
"name": "tab.highlighted",
"sheet": "controls",
"uv": "56 70 20 20",
"padding": "6"
"uv": [56, 70, 20, 20],
"padding": [6]
},
{
"name": "tab.disabled",
"sheet": "controls",
"uv": "4 70 20 20",
"padding": "6"
"uv": [4, 70, 20, 20],
"padding": [6]
},
{
"name": "tab.outline",
"sheet": "controls",
"uv": "56 96 20 20",
"padding": "6"
"uv": [56, 96, 20, 20],
"padding": [6]
},
{
"name": "tab.solid",
"sheet": "controls",
"uv": "82 96 20 20",
"padding": "6"
"uv": [82, 96, 20, 20],
"padding": [6]
},
{
"name": "scroll",
"sheet": "controls",
"uv": "64 30 11 14",
"padding": "2"
"uv": [64, 30, 11, 14],
"padding": [2]
},
{
"name": "scroll.highlighted",
"sheet": "controls",
"uv": "82 30 11 14",
"padding": "2"
"uv": [82, 30, 11, 14],
"padding": [2]
},
{
"name": "scroll.disabled",
"sheet": "controls",
"uv": "100 30 11 14",
"padding": "2"
"uv": [100, 30, 11, 14],
"padding": [2]
},
{
"name": "outline",
"sheet": "panels",
"uv": "76 40 16 16",
"padding": "2"
"uv": [76, 40, 16, 16],
"padding": [2]
},
{
"name": "button.help",
"sheet": "controls",
"uv": "88 4 16 16",
"padding": "2"
"uv": [88, 4, 16, 16],
"padding": [2]
},
{
"name": "button.info",
"sheet": "controls",
"uv": "110 4 16 16",
"padding": "2"
"uv": [110, 4, 16, 16],
"padding": [2]
},
{
"name": "button.user",
"sheet": "controls",
"uv": "132 4 16 16",
"padding": "2"
"uv": [132, 4, 16, 16],
"padding": [2]
},
{
"name": "button.power",
"sheet": "controls",
"uv": "154 4 16 16",
"padding": "2"
"uv": [154, 4, 16, 16],
"padding": [2]
},
{
"name": "horizontalliquidtank",
"sheet": "slots",
"uv": "56 28 60 18"
"uv": [56, 28, 60, 18]
},
{
"name": "horizontalliquidtank.overlay",
"sheet": "slots",
"uv": "56 52 60 18"
"uv": [56, 52, 60, 18]
},
{
"name": "slide.up",
"sheet": "panels",
"uv": "0 76 16 16"
"uv": [0, 76, 16, 16]
},
{
"name": "slide.down",
"sheet": "panels",
"uv": "16 76 16 16"
"uv": [16, 76, 16, 16]
},
{
"name": "slide.left",
"sheet": "panels",
"uv": "0 92 16 16"
"uv": [0, 92, 16, 16]
},
{
"name": "slide.right",
"sheet": "panels",
"uv": "16 92 16 16"
"uv": [16, 92, 16, 16]
},
{
"name": "checkbox",
"sheet": "controls",
"uv": "0 112 16 16"
"uv": [0, 112, 16, 16]
},
{
"name": "checkbox.checked",
"sheet": "controls",
"uv": "16 112 16 16"
"uv": [16, 112, 16, 16]
},
{
"name": "checkbox.highlighted",
"sheet": "controls",
"uv": "0 128 16 16"
"uv": [0, 128, 16, 16]
},
{
"name": "checkbox.checked.highlighted",
"sheet": "controls",
"uv": "16 128 16 16"
"uv": [16, 128, 16, 16]
}
]
@@ -110,8 +110,7 @@ public class BlockShrubLog extends Block implements IWoodTyped, IStateMapperRegi
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
if (!p_185477_7_) {
state = state.getActualState(worldIn, pos);
}
@@ -229,9 +228,6 @@ public class BlockShrubLog extends Block implements IWoodTyped, IStateMapperRegi
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
int i = 4;
int j = 5;
if (worldIn.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5))) {
for (BlockPos blockpos : BlockPos.getAllInBox(pos.add(-4, -4, -4), pos.add(4, 4, 4))) {
IBlockState iblockstate = worldIn.getBlockState(blockpos);