Skip to content

Commit

Permalink
Icons
Browse files Browse the repository at this point in the history
  • Loading branch information
KosmX committed Aug 10, 2020
1 parent 40ecaa1 commit 14181c4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings = 1.16.1+build.21
loader_version = 0.8.9+build.203

#Mod properties
mod_version = 0.11.6
mod_version = 0.12.0
maven_group = com.kosmx.emotecraft
archives_base_name = emotecraft

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public SerializableConfig deserialize(JsonElement json, Type typeOfT, JsonDeseri
JsonObject node = json.getAsJsonObject();
SerializableConfig config = new SerializableConfig();
if(node.has("showDebug"))config.showDebug = node.get("showDebug").getAsBoolean();
if(node.has("validate"))config.showDebug = node.get("validate").getAsBoolean();
if(node.has("validate"))config.validateEmote = node.get("validate").getAsBoolean();
if(node.has("enablequark"))config.enableQuark = node.get("enablequark").getAsBoolean();
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)clientDeserialize(node, config);
return config;
Expand All @@ -25,6 +25,7 @@ public SerializableConfig deserialize(JsonElement json, Type typeOfT, JsonDeseri
@Environment(EnvType.CLIENT)
private void clientDeserialize(JsonObject node, SerializableConfig config){
if(node.has("dark"))config.dark = node.get("dark").getAsBoolean();
if(node.has("showIcon"))config.showIcons = node.get("showIcon").getAsBoolean();
if(node.has("fastmenu"))fastMenuDeserializer(node.get("fastmenu").getAsJsonObject(), config);
if(node.has("keys"))keyBindsDeserializer(node.get("keys").getAsJsonArray(), config);
}
Expand Down Expand Up @@ -71,7 +72,7 @@ private void keyBindDeserializer(JsonObject node){
public JsonElement serialize(SerializableConfig config, Type typeOfSrc, JsonSerializationContext context) {
JsonObject node = new JsonObject();
node.addProperty("showDebug", config.showDebug);
node.addProperty("validate", config.showDebug);
node.addProperty("validate", config.validateEmote);
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) clientSerialize(config, node);
return node;
}
Expand All @@ -80,6 +81,7 @@ public JsonElement serialize(SerializableConfig config, Type typeOfSrc, JsonSeri
private void clientSerialize(SerializableConfig config, JsonObject node){
node.addProperty("dark", config.dark);
if(Main.config.enableQuark)node.addProperty("enablequark", true);
node.addProperty("showIcon", config.showIcons);
node.add("fastmenu", fastMenuSerializer(config));
node.add("keys", keyBindsSerializer(config));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class SerializableConfig {
public boolean dark = false;
@Environment(EnvType.CLIENT)
public boolean enableQuark = false;
@Environment(EnvType.CLIENT)
public boolean showIcons = true;

public int[] fastMenuHash = new int[8];
public List<Pair<Integer, String>> emotesWithHash = new ArrayList<>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/kosmx/emotecraft/gui/ClothConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static Screen getConfigScreen(Screen parent){
}
Main.config.enableQuark = newValue;
}).build());
general.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("emotecraft.otherconfig.showicon"), Main.config.showIcons)
.setDefaultValue(true)
.setTooltip(new TranslatableText("emotecraft.otherconfig.showicon.tooltip"))
.setSaveConsumer(newValue -> Main.config.showIcons = newValue).build());
return builder.build();
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/kosmx/emotecraft/gui/EmoteMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void init() {
this.emoteList = new EmoteListWidget(this.client, (int) (this.width / 2.2 - 16), this.height, this);
this.emoteList.setLeftPos(this.width/2-(int)(this.width/2.2-16)-12);
this.children.add(this.emoteList);
int x = Math.min(this.width/4, this.height/2);
int x = Math.min(this.width/4, (int)(this.height/2.5));
this.fastMenu = new FastChooseWidget(this.width/2 + 2, this.height/2 - 8, x-7);
this.children.add(fastMenu);
this.buttons.add(new ButtonWidget(this.width - 100, 4, 96, 20, new TranslatableText("emotecraft.options.options"), (button -> this.client.openScreen(ClothConfigScreen.getConfigScreen(this)))));
Expand All @@ -94,9 +94,9 @@ protected void init() {
super.init();
this.setInitialFocus(this.searchBox);
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.keybind"), this.width/2 +115, 40));
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.fastmenu"), this.width/2 + 2 + x/2, height/2 - 54));
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.fastmenu2"), this.width/2 + 2 + x/2, height/2 - 40));
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.fastmenu3"), this.width/2 + 2 + x/2, height/2 - 26));
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.fastmenu"), this.width/2 + 10 + x/2, height/2 - 54));
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.fastmenu2"), this.width/2 + 10 + x/2, height/2 - 40));
this.texts.add(new PositionedText(new TranslatableText("emotecraft.options.fastmenu3"), this.width/2 + 10 + x/2, height/2 - 26));
}

private void activateKey(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
}
}
for(FastChooseElement f:elements){
if(f.hasEmote()) f.renderText(matrices, textRenderer);
if(f.hasEmote()) f.render(matrices, textRenderer);
}
}

Expand Down Expand Up @@ -169,12 +169,22 @@ public void clearEmote(){
this.setEmote(null);
}

public void renderText(MatrixStack matrices, TextRenderer textRenderer) {
if (Main.config.fastMenuEmotes[id] != null) {
drawCenteredText(matrices, textRenderer, Main.config.fastMenuEmotes[id].name, this.angle);
public void render(MatrixStack matrices, TextRenderer textRenderer) {
Identifier identifier = Main.config.fastMenuEmotes[id] != null ? Main.config.fastMenuEmotes[id].getIcon() : null;
if(identifier != null && Main.config.showIcons){
int s = size / 10;
int iconX = (int) (((float)(x + size/2)) + size*0.4*Math.sin(this.angle * 0.0174533)) - s;
int iconY = (int) (((float)(y + size/2)) + size*0.4*Math.cos(this.angle * 0.0174533)) - s;
MinecraftClient.getInstance().getTextureManager().bindTexture(identifier);
drawTexture(matrices, iconX, iconY, s*2, s*2, 0, 0, 256, 256, 256, 256);
}
else {
Main.log(Level.ERROR, "Tried to render non-existing name", true);
if (Main.config.fastMenuEmotes[id] != null) {
drawCenteredText(matrices, textRenderer, Main.config.fastMenuEmotes[id].name, this.angle);
}
else {
Main.log(Level.ERROR, "Tried to render non-existing name", true);
}
}
}
public void renderHover(MatrixStack matrices){
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/emotecraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"emotecraft.otherconfig.validate": "Validate emote",
"emotecraft.otherconfig.validate.tooltip": "Only for PvP worlds, where somebody want to cheat. It creates a limitation, make impossible to play some emotes",
"emotecraft.otherconfig.dark": "Dark fast-menu",
"emotecraft.otherconfig.showicon": "Show icons instead of emote names",
"emotecraft.otherconfig.showicon.tooltip": "If available",
"emotecraft.emotelist": "All emote",
"key.emotecraft.fastchoose": "Fastmenu",
"key.emotecraft.debug": "play 'debug' emote",
Expand Down

0 comments on commit 14181c4

Please sign in to comment.