mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 15:02:17 +00:00
Add Search to all Scroll Functionality in Global Tab
This commit is contained in:
1 parent
12d1702b2b
commit
ce6c396fe1
5 files changed
+168
-26
No files matched your search
@@ -16,6 +16,7 @@ import java.util.Vector;
|
||||
public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollData, ISubGuiListener{
|
||||
private GuiCustomScroll scroll;
|
||||
private List<String> data = new ArrayList<String>();
|
||||
private String search = "";
|
||||
|
||||
public static GuiScreen Instance;
|
||||
|
||||
@@ -34,14 +35,41 @@ public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollDa
|
||||
|
||||
if(scroll == null){
|
||||
scroll = new GuiCustomScroll(this,0);
|
||||
scroll.setSize(143, 208);
|
||||
scroll.setSize(143, 185);
|
||||
}
|
||||
scroll.guiLeft = guiLeft + 214;
|
||||
scroll.guiTop = guiTop + 4;
|
||||
scroll.setList(data);
|
||||
scroll.setList(getSearchList());
|
||||
this.addScroll(scroll);
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i)
|
||||
{
|
||||
super.keyTyped(c, i);
|
||||
if(getTextField(55) != null){
|
||||
if(getTextField(55).isFocused()){
|
||||
if(search.equals(getTextField(55).getText()))
|
||||
return;
|
||||
search = getTextField(55).getText().toLowerCase();
|
||||
scroll.setList(getSearchList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getSearchList(){
|
||||
if(search.isEmpty()){
|
||||
return new ArrayList<String>(this.data);
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
for(String name : this.data){
|
||||
if(name.toLowerCase().contains(search))
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton button){
|
||||
if(button.id == 1){
|
||||
@@ -65,6 +93,7 @@ public class GuiNPCManageLinkedNpc extends GuiNPCInterface2 implements IScrollDa
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data) {
|
||||
this.data = new ArrayList<String>(list);
|
||||
this.scroll.setList(getSearchList());
|
||||
initGui();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user