This repository has been archived by the owner on Jun 10, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a super simple libGDX-like TextureAtlas (based on gdx-textu…
…repacker) to make handling GUI graphics easier.
- Loading branch information
1 parent
5844222
commit ead0b66
Showing
47 changed files
with
506 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
/*.iml | ||
/out | ||
/gradle.properties | ||
/gdx-texturepacker.jar |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name=eiragui | ||
filename= | ||
input=assets-raw | ||
output=src\main\resources\assets\eirairc\gfx | ||
|
||
alias=true | ||
alphaThreshold=0 | ||
debug=false | ||
duplicatePadding=true | ||
edgePadding=true | ||
fast=false | ||
filterMag=Nearest | ||
filterMin=Nearest | ||
format=RGBA8888 | ||
ignoreBlankImages=true | ||
jpegQuality=1.0 | ||
maxHeight=256 | ||
maxWidth=256 | ||
minHeight=256 | ||
minWidth=256 | ||
outputFormat=png | ||
paddingX=0 | ||
paddingY=0 | ||
pot=true | ||
rotation=false | ||
stripWhitespaceX=false | ||
stripWhitespaceY=false | ||
wrapX=ClampToEdge | ||
wrapY=ClampToEdge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/net/blay09/mods/eirairc/client/graphics/AtlasRegion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package net.blay09.mods.eirairc.client.graphics; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.Tessellator; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
/** | ||
* Created by Blay09 on 20.02.2015. | ||
*/ | ||
public class AtlasRegion { | ||
|
||
public final ResourceLocation texture; | ||
public final String name; | ||
private int regionX; | ||
private int regionY; | ||
private int regionWidth; | ||
private int regionHeight; | ||
private final int textureWidth = 256; | ||
private final int textureHeight = 256; | ||
|
||
public AtlasRegion(ResourceLocation texture, String name) { | ||
this.texture = texture; | ||
this.name = name; | ||
} | ||
|
||
public void setRegionX(int regionX) { | ||
this.regionX = regionX; | ||
} | ||
|
||
public int getRegionX() { | ||
return regionX; | ||
} | ||
|
||
public void setRegionY(int regionY) { | ||
this.regionY = regionY; | ||
} | ||
|
||
public int getRegionY() { | ||
return regionY; | ||
} | ||
|
||
public void setRegionWidth(int regionWidth) { | ||
this.regionWidth = regionWidth; | ||
} | ||
|
||
public int getRegionWidth() { | ||
return regionWidth; | ||
} | ||
|
||
public void setRegionHeight(int regionHeight) { | ||
this.regionHeight = regionHeight; | ||
} | ||
|
||
public int getRegionHeight() { | ||
return regionHeight; | ||
} | ||
|
||
public void draw(int x, int y) { | ||
draw(x, y, regionWidth, regionHeight); | ||
} | ||
|
||
public void draw(int x, int y, int width, int height) { | ||
Minecraft.getMinecraft().renderEngine.bindTexture(texture); | ||
|
||
float u = (float) regionX / (float) textureWidth; | ||
float v = (float) regionY / (float) textureHeight; | ||
float u2 = (float) (regionX + regionWidth) / (float) textureWidth; | ||
float v2 = (float) (regionY + regionHeight) / (float) textureHeight; | ||
|
||
Tessellator tessellator = Tessellator.instance; | ||
tessellator.startDrawingQuads(); | ||
tessellator.addVertexWithUV(x, y + height, 0, u, v2); | ||
tessellator.addVertexWithUV(x + width, y + height, 0, u2, v2); | ||
tessellator.addVertexWithUV(x + width, y, 0, u2, v); | ||
tessellator.addVertexWithUV(x, y, 0, u, v); | ||
tessellator.draw(); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/net/blay09/mods/eirairc/client/graphics/TextureAtlas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package net.blay09.mods.eirairc.client.graphics; | ||
|
||
import net.minecraft.client.resources.IResourceManager; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import java.io.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Blay09 on 20.02.2015. | ||
*/ | ||
public class TextureAtlas { | ||
|
||
private final List<TextureAtlasPage> pages = new ArrayList<TextureAtlasPage>(); | ||
|
||
public TextureAtlas(IResourceManager resourceManager, ResourceLocation resourceLocation) throws IOException { | ||
String resourcePath = resourceLocation.getResourcePath(); | ||
resourcePath = resourcePath.substring(0, resourcePath.lastIndexOf('/') + 1); | ||
InputStream in = resourceManager.getResource(resourceLocation).getInputStream(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); | ||
String line; | ||
TextureAtlasPage currentPage = null; | ||
AtlasRegion currentRegion = null; | ||
while((line = reader.readLine()) != null) { | ||
line = line.trim(); | ||
if(line.isEmpty()) { | ||
currentPage = null; | ||
continue; | ||
} | ||
if(currentPage == null) { | ||
currentPage = new TextureAtlasPage(line, new ResourceLocation(resourceLocation.getResourceDomain(), resourcePath + line)); | ||
pages.add(currentPage); | ||
} else { | ||
int sepIdx = line.indexOf(':'); | ||
if(sepIdx == -1) { | ||
currentRegion = new AtlasRegion(currentPage.texture, line); | ||
currentPage.addRegion(currentRegion); | ||
} else { | ||
String key = line.substring(0, sepIdx); | ||
String value = line.substring(sepIdx + 1); | ||
if(currentRegion != null) { | ||
if(key.equals("xy")) { | ||
String[] xy = value.split(","); | ||
currentRegion.setRegionX(Integer.parseInt(xy[0].trim())); | ||
currentRegion.setRegionY(Integer.parseInt(xy[1].trim())); | ||
} else if(key.equals("size")) { | ||
String[] size = value.split(","); | ||
currentRegion.setRegionWidth(Integer.parseInt(size[0].trim())); | ||
currentRegion.setRegionHeight(Integer.parseInt(size[1].trim())); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
reader.close(); | ||
in.close(); | ||
} | ||
|
||
public AtlasRegion findRegion(String name) { | ||
for(TextureAtlasPage page : pages) { | ||
AtlasRegion region = page.getRegion(name); | ||
if(region != null) { | ||
return region; | ||
} | ||
} | ||
throw new RuntimeException("Could not find EiraIRC atlas region '" + name + "'"); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/net/blay09/mods/eirairc/client/graphics/TextureAtlasPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.blay09.mods.eirairc.client.graphics; | ||
|
||
import net.minecraft.util.ResourceLocation; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by Blay09 on 20.02.2015. | ||
*/ | ||
public class TextureAtlasPage { | ||
|
||
private final Map<String, AtlasRegion> regionMap = new HashMap<String, AtlasRegion>(); | ||
public final String fileName; | ||
public final ResourceLocation texture; | ||
|
||
public TextureAtlasPage(String fileName, ResourceLocation texture) { | ||
this.fileName = fileName; | ||
this.texture = texture; | ||
} | ||
|
||
public void addRegion(AtlasRegion region) { | ||
regionMap.put(region.name, region); | ||
} | ||
|
||
public AtlasRegion getRegion(String name) { | ||
return regionMap.get(name); | ||
} | ||
|
||
} |
16 changes: 15 additions & 1 deletion
16
src/main/java/net/blay09/mods/eirairc/client/gui/EiraGui.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.