Skip to content

Commit

Permalink
- Convert to lowercase first before performing .contains for searching
Browse files Browse the repository at this point in the history
- Social Media buttons on config
  • Loading branch information
syeyoung committed Aug 3, 2021
1 parent 5f8c278 commit ecf7ff8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ public MCategory(NestedCategory nestedCategory, RootConfigPanel rootConfigPanel)

@Override
public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
Gui.drawRect(0,0,getBounds().width, getBounds().height, RenderUtils.blendAlpha(0x141414, 0.12f));
int border = RenderUtils.blendAlpha(0x141414, 0.12f);
if (!rootConfigPanel.getSearchWord().isEmpty() && (nestedCategory.categoryName().toLowerCase().contains(rootConfigPanel.getSearchWord()))) {
border = 0xFF02EE67;
}

Gui.drawRect(0,0,getBounds().width, getBounds().height,border);
if (getBounds().height >= 28)
Gui.drawRect(1,18,getBounds().width -1, getBounds().height-1, RenderUtils.blendAlpha(0x141414, 0.15f));
Gui.drawRect(0,17,getBounds().width, 18,RenderUtils.blendAlpha(0x141414, 0.12f));
Gui.drawRect(1,1,getBounds().width-1, 18, RenderUtils.blendAlpha(0x141414, 0.12f));


FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
Expand All @@ -75,7 +80,7 @@ public Dimension getPreferredSize() {
int descriptionHeight =
FeatureRegistry.getCategoryDescription().containsKey(nestedCategory.categoryFull()) ?
fr.listFormattedStringToWidth(FeatureRegistry.getCategoryDescription().get(nestedCategory.categoryFull()), Math.max(100, getBounds().width - 10)).size() * fr.FONT_HEIGHT
: -11;
: -9;

return new Dimension(100, descriptionHeight + 28);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void run() {
public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {

int border = RenderUtils.blendAlpha(0x141414, 0.12f);
if (!panel.getSearchWord().isEmpty() && (feature.getName().contains(panel.getSearchWord()) || feature.getDescription().contains(panel.getSearchWord()))) {
if (!panel.getSearchWord().isEmpty() && (feature.getName().toLowerCase().contains(panel.getSearchWord()) || feature.getDescription().toLowerCase().contains(panel.getSearchWord()))) {
border = 0xFF02EE67;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import net.minecraft.client.gui.Gui;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;

public class RootConfigPanel extends MPanelScaledGUI {
Expand All @@ -56,10 +59,12 @@ public class RootConfigPanel extends MPanelScaledGUI {
private MTextField search;
private MButton guiRelocate;

private MButton github, discord;

private final Stack<String> history = new Stack<String>();

public String getSearchWord() {
return search.getText().trim();
return search.getText().trim().toLowerCase();
}

public RootConfigPanel(GuiConfigV2 guiConfigV2) {
Expand Down Expand Up @@ -99,6 +104,26 @@ public void edit(String str) {
guiRelocate.setBorder(RenderUtils.blendTwoColors(0xFF141414,0x7702EE67));
add(guiRelocate);

discord = new MButton(); github = new MButton();
discord.setText("Discord"); github.setText("Github");
discord.setBorder(RenderUtils.blendTwoColors(0xFF141414,0x7702EE67));
github.setBorder(RenderUtils.blendTwoColors(0xFF141414,0x7702EE67));
github.setOnActionPerformed(() -> {
try {
Desktop.getDesktop().browse(new URI("https://github.com/Dungeons-Guide/Skyblock-Dungeons-Guide/"));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
});
discord.setOnActionPerformed(() -> {
try {
Desktop.getDesktop().browse(new URI("https://discord.gg/VuxayCWGE8"));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
});
add(discord); add(github);

navigationScroll = new MScrollablePanel(1);
navigationScroll.setHideScrollBarWhenNotNecessary(false);

Expand All @@ -114,7 +139,6 @@ public void edit(String str) {
navigation.setGap(0);
navigation.setDrawLine(false);


setCurrentPageAndPushHistory("ROOT");
rePlaceElements();
}
Expand All @@ -129,21 +153,21 @@ private void setupNavigation() {
}
NestedCategory root = new NestedCategory("ROOT");
Set<String> categoryAllowed = new HashSet<>();
String search = this.search.getText().trim();
String search = this.search.getText().trim().toLowerCase();
for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) {
if (search.isEmpty()) {
categoryAllowed.add("ROOT."+abstractFeature.getCategory());
} else if (abstractFeature.getName().contains(search)) {
categoryAllowed.add("ROOT."+abstractFeature.getCategory());
} else if (abstractFeature.getDescription().contains(search)) {
categoryAllowed.add("ROOT."+abstractFeature.getCategory());
categoryAllowed.add("ROOT."+abstractFeature.getCategory()+".");
} else if (abstractFeature.getName().toLowerCase().contains(search)) {
categoryAllowed.add("ROOT."+abstractFeature.getCategory()+".");
} else if (abstractFeature.getDescription().toLowerCase().contains(search)) {
categoryAllowed.add("ROOT."+abstractFeature.getCategory()+".");
}
}
for (AbstractFeature abstractFeature : FeatureRegistry.getFeatureList()) {
String category = abstractFeature.getCategory();
boolean test =false;
for (String s : categoryAllowed) {
if (("ROOT."+category).startsWith(s)) {
if (s.startsWith("ROOT."+category+".")) {
test = true;
break;
}
Expand Down Expand Up @@ -273,5 +297,7 @@ private void rePlaceElements() {
search.setBounds(new Rectangle(5,30,navBound.x + navBound.width - 10,15));

guiRelocate.setBounds(new Rectangle(5,5,100,15));
github.setBounds(new Rectangle(effectiveDim.width - 80,5,75,15));
discord.setBounds(new Rectangle(effectiveDim.width - 160,5,75,15));
}
}

0 comments on commit ecf7ff8

Please sign in to comment.