2024-03-13 18:40:40 -04:00
|
|
|
package noppes.npcs.client.gui.select;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
|
import noppes.npcs.client.gui.util.*;
|
|
|
|
|
import noppes.npcs.controllers.DialogController;
|
|
|
|
|
import noppes.npcs.controllers.data.Dialog;
|
|
|
|
|
import noppes.npcs.controllers.data.DialogCategory;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class GuiDialogSelection extends SubGuiInterface implements ICustomScrollListener {
|
2025-03-12 20:12:01 -04:00
|
|
|
private HashMap<String, DialogCategory> categoryData = new HashMap<String, DialogCategory>();
|
|
|
|
|
private HashMap<String, Dialog> dialogData = new HashMap<String, Dialog>();
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
private GuiCustomScroll scrollCategories;
|
|
|
|
|
private GuiCustomScroll scrollDialogs;
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
private DialogCategory selectedCategory;
|
|
|
|
|
public Dialog selectedDialog;
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
private GuiSelectionListener listener;
|
2024-03-13 18:40:40 -04:00
|
|
|
private String catSearch = "";
|
|
|
|
|
private String dialogSearch = "";
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
public GuiDialogSelection(int dialog) {
|
|
|
|
|
drawDefaultBackground = false;
|
|
|
|
|
title = "";
|
|
|
|
|
setBackground("menubg.png");
|
2024-03-13 18:40:40 -04:00
|
|
|
xSize = 366;
|
|
|
|
|
ySize = 226;
|
2025-03-12 20:12:01 -04:00
|
|
|
this.selectedDialog = DialogController.Instance.dialogs.get(dialog);
|
|
|
|
|
if (selectedDialog != null) {
|
|
|
|
|
selectedCategory = selectedDialog.category;
|
|
|
|
|
}
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public void initGui() {
|
2024-03-13 18:40:40 -04:00
|
|
|
super.initGui();
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (parent instanceof GuiSelectionListener) {
|
|
|
|
|
listener = (GuiSelectionListener) parent;
|
|
|
|
|
}
|
2024-03-13 18:40:40 -04:00
|
|
|
this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4));
|
|
|
|
|
this.addLabel(new GuiNpcLabel(1, "dialog.dialogs", guiLeft + 184, guiTop + 4));
|
|
|
|
|
|
|
|
|
|
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 56, guiTop + ySize - 35, 50, 20, "gui.done"));
|
|
|
|
|
this.addButton(new GuiNpcButton(3, guiLeft + xSize - 108, guiTop + ySize - 35, 50, 20, "gui.cancel"));
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
HashMap<String, DialogCategory> categoryData = new HashMap<String, DialogCategory>();
|
|
|
|
|
HashMap<String, Dialog> dialogData = new HashMap<String, Dialog>();
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
for (DialogCategory category : DialogController.Instance.categories.values()) {
|
|
|
|
|
categoryData.put(category.title, category);
|
|
|
|
|
}
|
|
|
|
|
this.categoryData = categoryData;
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (selectedCategory != null) {
|
|
|
|
|
for (Dialog dialog : selectedCategory.dialogs.values()) {
|
|
|
|
|
dialogData.put(dialog.title, dialog);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.dialogData = dialogData;
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (scrollCategories == null) {
|
|
|
|
|
scrollCategories = new GuiCustomScroll(this, 0, 0);
|
2024-03-13 18:40:40 -04:00
|
|
|
scrollCategories.setSize(177, 153);
|
|
|
|
|
}
|
|
|
|
|
scrollCategories.setList(getCatSearch());
|
2025-03-12 20:12:01 -04:00
|
|
|
if (selectedCategory != null) {
|
|
|
|
|
scrollCategories.setSelected(selectedCategory.title);
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
|
|
|
|
scrollCategories.guiLeft = guiLeft + 4;
|
|
|
|
|
scrollCategories.guiTop = guiTop + 14;
|
|
|
|
|
this.addScroll(scrollCategories);
|
|
|
|
|
addTextField(new GuiNpcTextField(33, this, fontRendererObj, guiLeft + 4, guiTop + 169, 177, 20, catSearch));
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (scrollDialogs == null) {
|
|
|
|
|
scrollDialogs = new GuiCustomScroll(this, 1, 0);
|
|
|
|
|
scrollDialogs.setSize(177, 153);
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
|
|
|
|
scrollDialogs.setList(getDialogSearch());
|
2025-03-12 20:12:01 -04:00
|
|
|
if (selectedDialog != null) {
|
|
|
|
|
scrollDialogs.setSelected(selectedDialog.title);
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
|
|
|
|
scrollDialogs.guiLeft = guiLeft + 182;
|
|
|
|
|
scrollDialogs.guiTop = guiTop + 14;
|
|
|
|
|
this.addScroll(scrollDialogs);
|
|
|
|
|
addTextField(new GuiNpcTextField(44, this, fontRendererObj, guiLeft + 182, guiTop + 169, 177, 20, dialogSearch));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public void keyTyped(char c, int i) {
|
2024-03-13 18:40:40 -04:00
|
|
|
super.keyTyped(c, i);
|
2025-03-12 20:12:01 -04:00
|
|
|
if (getTextField(33) != null) {
|
|
|
|
|
if (getTextField(33).isFocused()) {
|
|
|
|
|
if (catSearch.equals(getTextField(33).getText()))
|
2024-03-13 18:40:40 -04:00
|
|
|
return;
|
|
|
|
|
catSearch = getTextField(33).getText().toLowerCase();
|
2024-03-29 04:50:47 -04:00
|
|
|
scrollCategories.resetScroll();
|
2024-03-29 05:05:55 -04:00
|
|
|
scrollCategories.setList(getCatSearch());
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
|
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
if (getTextField(44) != null) {
|
|
|
|
|
if (getTextField(44).isFocused()) {
|
|
|
|
|
if (dialogSearch.equals(getTextField(44).getText()))
|
2024-03-13 18:40:40 -04:00
|
|
|
return;
|
|
|
|
|
dialogSearch = getTextField(44).getText().toLowerCase();
|
2024-03-29 04:50:47 -04:00
|
|
|
scrollDialogs.resetScroll();
|
2024-03-29 05:05:55 -04:00
|
|
|
scrollDialogs.setList(getDialogSearch());
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
private List<String> getCatSearch() {
|
|
|
|
|
if (catSearch.isEmpty()) {
|
2024-03-13 18:40:40 -04:00
|
|
|
return Lists.newArrayList(categoryData.keySet());
|
|
|
|
|
}
|
|
|
|
|
List<String> list = new ArrayList<String>();
|
2025-03-12 20:12:01 -04:00
|
|
|
for (String name : Lists.newArrayList(categoryData.keySet())) {
|
|
|
|
|
if (name.toLowerCase().contains(catSearch))
|
2024-03-13 18:40:40 -04:00
|
|
|
list.add(name);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
private List<String> getDialogSearch() {
|
|
|
|
|
if (selectedCategory == null) {
|
2024-03-13 18:40:40 -04:00
|
|
|
return Lists.newArrayList(dialogData.keySet());
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
if (dialogSearch.isEmpty()) {
|
2024-03-13 18:40:40 -04:00
|
|
|
return new ArrayList<String>(Lists.newArrayList(dialogData.keySet()));
|
|
|
|
|
}
|
|
|
|
|
List<String> list = new ArrayList<String>();
|
2025-03-12 20:12:01 -04:00
|
|
|
for (String name : Lists.newArrayList(dialogData.keySet())) {
|
|
|
|
|
if (name.toLowerCase().contains(dialogSearch))
|
2024-03-13 18:40:40 -04:00
|
|
|
list.add(name);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 20:12:01 -04:00
|
|
|
@Override
|
|
|
|
|
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
|
|
|
|
if (guiCustomScroll.id == 0) {
|
|
|
|
|
selectedCategory = categoryData.get(scrollCategories.getSelected());
|
|
|
|
|
selectedDialog = null;
|
|
|
|
|
scrollDialogs.selected = -1;
|
2024-03-13 18:40:40 -04:00
|
|
|
scrollDialogs.resetScroll();
|
|
|
|
|
getTextField(44).setText("");
|
|
|
|
|
dialogSearch = "";
|
2025-03-12 20:12:01 -04:00
|
|
|
}
|
|
|
|
|
if (guiCustomScroll.id == 1) {
|
|
|
|
|
selectedDialog = dialogData.get(scrollDialogs.getSelected());
|
|
|
|
|
}
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
2024-03-13 18:40:40 -04:00
|
|
|
|
|
|
|
|
@Override
|
2025-03-12 20:12:01 -04:00
|
|
|
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
|
|
|
|
if (selectedDialog == null)
|
|
|
|
|
return;
|
|
|
|
|
if (listener != null) {
|
|
|
|
|
listener.selected(selectedDialog.id, selectedDialog.title);
|
|
|
|
|
}
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void actionPerformed(GuiButton guibutton) {
|
|
|
|
|
int id = guibutton.id;
|
|
|
|
|
if (id == 2) {
|
|
|
|
|
if (selectedDialog != null) {
|
2024-03-13 18:40:40 -04:00
|
|
|
customScrollDoubleClicked(null, null);
|
2025-03-12 20:12:01 -04:00
|
|
|
} else {
|
2024-03-13 18:40:40 -04:00
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-12 20:12:01 -04:00
|
|
|
if (id == 3) {
|
2024-03-13 18:40:40 -04:00
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|