-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
217 additions
and
51 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
common/src/main/java/dev/norbiros/emojitype/config/EmojiListWidget.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,123 @@ | ||
package dev.norbiros.emojitype.config; | ||
|
||
import dev.norbiros.emojitype.emoji.EmojiCode; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.Element; | ||
import net.minecraft.client.gui.Selectable; | ||
import net.minecraft.client.gui.tooltip.Tooltip; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.gui.widget.ClickableWidget; | ||
import net.minecraft.client.gui.widget.EditBoxWidget; | ||
import net.minecraft.client.gui.widget.ElementListWidget; | ||
import net.minecraft.text.Text; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class EmojiListWidget extends ElementListWidget<EmojiListWidget.EmojiWidgetEntry> { | ||
public EmojiListWidget(MinecraftClient client, int width, int height, int top, int itemHeight) { | ||
super(client, width, height, top, itemHeight); | ||
} | ||
|
||
public void addEntry(EmojiCode emoji) { | ||
this.addEntry(new EmojiListWidget.EmojiWidgetEntry(width, emoji, this)); | ||
} | ||
|
||
public void addEntryAfter(EmojiCode emoji, EmojiWidgetEntry element) { | ||
var index = this.children().indexOf(element); | ||
this.children().add(index + 1, new EmojiListWidget.EmojiWidgetEntry(width, emoji, this)); | ||
} | ||
|
||
public List<String> getCurrentCodes() { | ||
List<String> codes = new ArrayList<>(); | ||
for (EmojiWidgetEntry entry : this.children()) { | ||
codes.add(entry.getEmojiCode().toString()); | ||
} | ||
return codes; | ||
} | ||
|
||
@Override | ||
public int getRowWidth() { | ||
return width - 40; | ||
} | ||
|
||
@Override | ||
protected int getScrollbarX() { | ||
return width - 12; | ||
} | ||
|
||
public static class EmojiWidgetEntry extends ElementListWidget.Entry<EmojiWidgetEntry> { | ||
|
||
private final EmojiListWidget parent; | ||
List<ClickableWidget> elements = new ArrayList<>(); | ||
|
||
public EmojiWidgetEntry(int entryWidth, EmojiCode emoji, EmojiListWidget parent) { | ||
this.parent = parent; | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
|
||
var editBoxWidgetEmoji = new EditBoxWidget(client.textRenderer, | ||
entryWidth / 2 - 200, | ||
0, | ||
110, | ||
18, | ||
Text.empty(), | ||
Text.empty() | ||
); | ||
editBoxWidgetEmoji.setText(emoji.getEmoji()); | ||
this.elements.add(editBoxWidgetEmoji); | ||
|
||
var editBoxWidgetCode = new EditBoxWidget(client.textRenderer, | ||
entryWidth / 2 - 85, | ||
0, | ||
235, | ||
18, | ||
Text.empty(), | ||
Text.empty() | ||
); | ||
var emojiCode = emoji.getCode(); | ||
editBoxWidgetCode.setText(emojiCode.substring(1, emojiCode.length() - 1)); | ||
this.elements.add(editBoxWidgetCode); | ||
|
||
this.elements.add(ButtonWidget | ||
.builder(Text.literal("➕"), button -> this.parent.addEntryAfter(EmojiCode.EMPTY, this)) | ||
.dimensions(entryWidth / 2 + 157, 0, 20, 20) | ||
.tooltip(Tooltip.of(Text.translatable("config.emojitype.add_entry_below_tooltip"))) | ||
.build() | ||
); | ||
this.elements.add(ButtonWidget | ||
.builder(Text.literal("❌"), button -> this.parent.removeEntry(this)) | ||
.dimensions(entryWidth / 2 + 180, 0, 20, 20) | ||
.tooltip(Tooltip.of(Text.translatable("config.emojitype.remove_entry_tooltip"))) | ||
.build() | ||
); | ||
} | ||
|
||
public EmojiCode getEmojiCode() { | ||
EditBoxWidget emoji = (EditBoxWidget) this.elements.get(0); | ||
EditBoxWidget key = (EditBoxWidget) this.elements.get(1); | ||
|
||
return new EmojiCode(":" + key.getText() + ":", emoji.getText()); | ||
} | ||
|
||
public List<? extends Element> children() { | ||
return this.elements; | ||
} | ||
|
||
public List<? extends Selectable> selectableChildren() { | ||
return this.elements; | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { | ||
for (ClickableWidget element : this.elements) { | ||
if (element instanceof ButtonWidget) { | ||
element.setY(y - 1); | ||
} else { | ||
element.setY(y); | ||
} | ||
element.render(context, mouseX, mouseY, tickDelta); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"config.emojitype.title": "Emoji Type Config", | ||
"config.emojitype.category": "Emoji Type Category", | ||
"config.emojitype.codes": "Emoji Codes", | ||
"config.emojitype.cancel": "Cancel", | ||
"config.emojitype.reset_all": "Reset config", | ||
"config.emojitype.save_and_quit": "Save & Quit", | ||
"config.emojitype.add_entry_below_tooltip": "Add below", | ||
"config.emojitype.remove_entry_tooltip": "Remove", | ||
"modmenu.descriptionTranslation.emojitype": "A mod that lets you type minecraft emojis easier!" | ||
} |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"config.emojitype.title": "Konfiguracja Emoji Type", | ||
"config.emojitype.category": "Kategoria Emoji Type", | ||
"config.emojitype.codes": "Kody Emotikonów", | ||
"config.emojitype.cancel": "Anuluj", | ||
"config.emojitype.reset_all": "Zresetuj konfigurację", | ||
"config.emojitype.save_and_quit": "Zapisz i wyjdź", | ||
"config.emojitype.add_entry_below_tooltip": "Dodaj poniżej", | ||
"config.emojitype.remove_entry_tooltip": "Usuń", | ||
"modmenu.descriptionTranslation.emojitype": "Mod ułatwiający wpisywanie emotek w Minecraft!" | ||
} |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{ | ||
"config.emojitype.title": "表情符號輸入設定", | ||
"config.emojitype.category": "表情符號類別", | ||
"config.emojitype.codes": "表情符號代碼", | ||
"modmenu.descriptionTranslation.emojitype": "一個讓你更容易輸入 Minecraft 表情符號的模組!" | ||
} |
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