GuiSoundSelection Scroll with Search Bars and Buttons

This commit is contained in:
Kam committed 2024-03-12 21:03:08 -04:00
1 parent 4875123685
commit 14b430089e
2 files changed
+78 -19

No files matched your search

@@ -8,10 +8,7 @@ import net.minecraft.client.audio.SoundRegistry;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.client.gui.util.*;
import java.util.ArrayList;
import java.util.HashMap;
@@ -21,11 +18,14 @@ import java.util.Set;
public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollListener{
private GuiCustomScroll scrollCategories;
private GuiCustomScroll scrollQuests;
private GuiCustomScroll scrollSounds;
private String selectedDomain;
public ResourceLocation selectedResource;
private String catSearch = "";
private String soundSearch = "";
private HashMap<String,List<String>> domains = new HashMap<String,List<String>>();
public GuiSoundSelection(String sound){
@@ -58,13 +58,13 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
@Override
public void initGui(){
super.initGui();
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X"));
this.addButton(new GuiNpcButton(1, guiLeft + 160, guiTop + 212, 70, 20, "gui.play"));
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 45, guiTop + ySize - 35, 40, 20, "gui.done"));
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 70, 20, "gui.play"));
getButton(1).enabled = selectedResource != null;
if(scrollCategories == null){
scrollCategories = new GuiCustomScroll(this,0);
scrollCategories.setSize(90, 200);
scrollCategories = new GuiCustomScroll(this,0, 0);
scrollCategories.setSize(90, 163);
}
scrollCategories.setList(Lists.newArrayList(domains.keySet()));
if(selectedDomain != null) {
@@ -72,23 +72,25 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
}
scrollCategories.guiLeft = guiLeft + 4;
scrollCategories.guiTop = guiTop + 14;
scrollCategories.guiTop = guiTop + 4;
this.addScroll(scrollCategories);
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 169, 90, 20, catSearch));
if(scrollQuests == null){
scrollQuests = new GuiCustomScroll(this,1);
scrollQuests.setSize(250, 200);
if(scrollSounds == null){
scrollSounds = new GuiCustomScroll(this,1, 0);
scrollSounds.setSize(265, 163);
}
if(selectedDomain != null) {
scrollQuests.setList(domains.get(selectedDomain));
scrollSounds.setList(domains.get(selectedDomain));
}
if(selectedResource != null) {
scrollQuests.setSelected(selectedResource.getResourcePath());
scrollSounds.setSelected(selectedResource.getResourcePath());
}
scrollQuests.guiLeft = guiLeft + 95;
scrollQuests.guiTop = guiTop + 14;
this.addScroll(scrollQuests);
scrollSounds.guiLeft = guiLeft + 95;
scrollSounds.guiTop = guiTop + 4;
this.addScroll(scrollSounds);
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 95, guiTop + 169, 265, 20, soundSearch));
}
@Override
@@ -116,11 +118,64 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
if(guiCustomScroll.id == 0){
selectedDomain = guiCustomScroll.getSelected();
selectedResource = null;
scrollQuests.selected = -1;
scrollSounds.selected = -1;
scrollSounds.resetScroll();
getTextField(66).setText("");
soundSearch = "";
}
if(guiCustomScroll.id == 1){
selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected());
}
initGui();
}
@Override
public void keyTyped(char c, int i)
{
super.keyTyped(c, i);
if(getTextField(55) != null){
if(getTextField(55).isFocused()){
if(catSearch.equals(getTextField(55).getText()))
return;
catSearch = getTextField(55).getText().toLowerCase();
scrollCategories.setList(getCatSearch());
}
}
if(getTextField(66) != null){
if(getTextField(66).isFocused()){
if(soundSearch.equals(getTextField(66).getText()))
return;
soundSearch = getTextField(66).getText().toLowerCase();
scrollSounds.setList(getSoundSearch());
}
}
}
private List<String> getCatSearch(){
if(catSearch.isEmpty()){
return new ArrayList<String>(this.domains.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.domains.keySet()){
if(name.toLowerCase().contains(catSearch))
list.add(name);
}
return list;
}
private List<String> getSoundSearch(){
if(selectedDomain == null){
return new ArrayList<String>();
}
if(soundSearch.isEmpty()){
return new ArrayList<String>(this.domains.get(selectedDomain));
}
List<String> list = new ArrayList<String>();
for(String name : this.domains.get(selectedDomain)){
if(name.toLowerCase().contains(soundSearch))
list.add(name);
}
return list;
}
}
@@ -370,4 +370,8 @@ public class GuiCustomScroll extends GuiScreen
public boolean isMouseOver(int x, int y) {
return x >= this.guiLeft && x <= this.guiLeft + this.xSize && y >= this.guiTop && y <= this.guiTop + this.ySize;
}
public void resetScroll(){
scrollY = 0;
}
}