Search in sources :

Example 1 with Texture

use of binnie.core.gui.resource.textures.Texture in project Binnie by ForestryMC.

the class StyleSheetParser method parseTextures.

private static Map<String, Texture> parseTextures(JsonObject jsonObject, Map<String, ParsedTextureSheet> textureSheets) {
    JsonArray texturesJson = JsonUtils.getJsonArray(jsonObject, TEXTURES_KEY);
    if (texturesJson == null) {
        return Collections.emptyMap();
    }
    Map<String, Texture> textures = new HashMap<>();
    for (JsonElement element : texturesJson) {
        if (!element.isJsonObject()) {
            continue;
        }
        try {
            JsonObject sheetJson = element.getAsJsonObject();
            String name = JsonUtils.getString(sheetJson, NAME_KEY);
            String sheet = JsonUtils.getString(sheetJson, SHEET_KEY);
            JsonArray uvArray = JsonUtils.getJsonArray(sheetJson, UV_KEY);
            IBinnieTexture textureSheet = textureSheets.get(sheet);
            Area uv = parseArea(uvArray);
            Border border = Border.ZERO;
            Border padding = Border.ZERO;
            if (sheetJson.has(BORDER_KEY)) {
                JsonArray array = JsonUtils.getJsonArray(sheetJson, BORDER_KEY);
                border = parseBorder(array);
            }
            if (sheetJson.has(PADDING_KEY)) {
                JsonArray array = JsonUtils.getJsonArray(sheetJson, PADDING_KEY);
                padding = parseBorder(array);
            }
            Texture texture = new Texture(uv, padding, border, textureSheet);
            textures.put(name, texture);
        } catch (Exception e) {
            Log.warning("Failed to load stylesheet for Binnie's Mods.", e);
        }
    }
    return textures;
}
Also used : JsonArray(com.google.gson.JsonArray) Area(binnie.core.gui.geometry.Area) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) IBinnieTexture(binnie.core.resource.IBinnieTexture) IBinnieTexture(binnie.core.resource.IBinnieTexture) Texture(binnie.core.gui.resource.textures.Texture) Border(binnie.core.gui.geometry.Border) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

Example 2 with Texture

use of binnie.core.gui.resource.textures.Texture in project Binnie by ForestryMC.

the class ControlChromoPicker method onRenderBackground.

@Override
@SideOnly(Side.CLIENT)
public void onRenderBackground(int guiWidth, int guiHeight) {
    super.onRenderBackground(guiWidth, guiHeight);
    boolean selected = isMouseOver();
    Texture text = selected ? this.selected : texture;
    CraftGUI.RENDER.texture(text, Point.ZERO);
}
Also used : Texture(binnie.core.gui.resource.textures.Texture) StandardTexture(binnie.core.gui.resource.textures.StandardTexture) BinnieCoreTexture(binnie.core.texture.BinnieCoreTexture) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with Texture

use of binnie.core.gui.resource.textures.Texture in project Binnie by ForestryMC.

the class StyleSheetParser method parseSheet.

@SideOnly(Side.CLIENT)
public static StyleSheet parseSheet(IResourceManager manager, ResourceLocation location) {
    try {
        IResource res = manager.getResource(location);
        BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(res.getInputStream(), Charsets.UTF_8));
        JsonParser jsonParser = new JsonParser();
        JsonObject jsonObject = jsonParser.parse(bufferedreader).getAsJsonObject();
        Map<String, ParsedTextureSheet> textureSheets = parseTextureSheets(jsonObject);
        Map<String, Texture> textures = parseTextures(jsonObject, textureSheets);
        IOUtils.closeQuietly(bufferedreader);
        return new StyleSheet(textures);
    } catch (IOException e) {
        throw new RuntimeException("Failed to load default stylesheet for Binnie's Mods.", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) IBinnieTexture(binnie.core.resource.IBinnieTexture) Texture(binnie.core.gui.resource.textures.Texture) BufferedReader(java.io.BufferedReader) IResource(net.minecraft.client.resources.IResource) JsonParser(com.google.gson.JsonParser) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Texture (binnie.core.gui.resource.textures.Texture)3 IBinnieTexture (binnie.core.resource.IBinnieTexture)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 Area (binnie.core.gui.geometry.Area)1 Border (binnie.core.gui.geometry.Border)1 StandardTexture (binnie.core.gui.resource.textures.StandardTexture)1 BinnieCoreTexture (binnie.core.texture.BinnieCoreTexture)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonParseException (com.google.gson.JsonParseException)1 JsonParser (com.google.gson.JsonParser)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 IResource (net.minecraft.client.resources.IResource)1