mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-03 22:16:28 +00:00
Add NPC toggle & hideall/showall buttons to player list window
This commit is contained in:
1 parent
f3493776c8
commit
a23395d0a8
1 file changed
+77
-4
@@ -28,11 +28,14 @@ public class PlayerListWindow {
|
|||||||
|
|
||||||
private static String lastSearch = null;
|
private static String lastSearch = null;
|
||||||
private static long lastUpdate = 0;
|
private static long lastUpdate = 0;
|
||||||
private static ImString search = ImGuiHelper.createResizableImString("");
|
private static boolean includeNpcs = false;
|
||||||
private static List<PlayerInfo> searchedPlayers = new ArrayList<>();
|
private static boolean hasNpcs = false;
|
||||||
|
private static final ImString search = ImGuiHelper.createResizableImString("");
|
||||||
|
private static final List<PlayerInfo> searchedPlayers = new ArrayList<>();
|
||||||
|
|
||||||
private static void updatePlayerList() {
|
private static void updatePlayerList() {
|
||||||
searchedPlayers.clear();
|
searchedPlayers.clear();
|
||||||
|
hasNpcs = false;
|
||||||
|
|
||||||
ClientPacketListener connection = Minecraft.getInstance().getConnection();
|
ClientPacketListener connection = Minecraft.getInstance().getConnection();
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
@@ -52,7 +55,16 @@ public class PlayerListWindow {
|
|||||||
for (PlayerInfo playerInfo : connection.getOnlinePlayers()) {
|
for (PlayerInfo playerInfo : connection.getOnlinePlayers()) {
|
||||||
GameProfile profile = playerInfo.getProfile();
|
GameProfile profile = playerInfo.getProfile();
|
||||||
|
|
||||||
if (profile.getId().version() == 4) {
|
if (profile.getId().equals(Minecraft.getInstance().player.getUUID())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profile.getId().version() != 4) {
|
||||||
|
hasNpcs = true;
|
||||||
|
if (!includeNpcs) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double distanceSq = Double.MAX_VALUE;
|
double distanceSq = Double.MAX_VALUE;
|
||||||
|
|
||||||
@@ -75,7 +87,6 @@ public class PlayerListWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
searchEntries.sort(Comparator.comparingDouble(SearchEntry::distanceSq));
|
searchEntries.sort(Comparator.comparingDouble(SearchEntry::distanceSq));
|
||||||
searchEntriesLowPriority.sort(Comparator.comparingDouble(SearchEntry::distanceSq));
|
searchEntriesLowPriority.sort(Comparator.comparingDouble(SearchEntry::distanceSq));
|
||||||
@@ -109,8 +120,17 @@ public class PlayerListWindow {
|
|||||||
updatePlayerList();
|
updatePlayerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasNpcs || includeNpcs) {
|
||||||
|
if (ImGui.checkbox("Include NPCs", includeNpcs)) {
|
||||||
|
includeNpcs = !includeNpcs;
|
||||||
|
lastSearch = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EditorState editorState = EditorStateManager.getCurrent();
|
EditorState editorState = EditorStateManager.getCurrent();
|
||||||
|
|
||||||
|
ImGui.separator();
|
||||||
|
|
||||||
for (int i = 0; i < searchedPlayers.size(); i++) {
|
for (int i = 0; i < searchedPlayers.size(); i++) {
|
||||||
ImGui.pushID(i);
|
ImGui.pushID(i);
|
||||||
PlayerInfo playerInfo = searchedPlayers.get(i);
|
PlayerInfo playerInfo = searchedPlayers.get(i);
|
||||||
@@ -136,8 +156,61 @@ public class PlayerListWindow {
|
|||||||
}
|
}
|
||||||
ImGui.popID();
|
ImGui.popID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.separator();
|
||||||
|
|
||||||
|
if (editorState != null) {
|
||||||
|
if (ImGui.button("Hide All")) {
|
||||||
|
changeVisibilityOfAll(editorState, false);
|
||||||
|
lastUpdate = currentTime;
|
||||||
|
}
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button("Show All")) {
|
||||||
|
changeVisibilityOfAll(editorState, true);
|
||||||
|
lastUpdate = currentTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui.end();
|
ImGui.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void changeVisibilityOfAll(EditorState editorState, boolean visible) {
|
||||||
|
ClientPacketListener connection = Minecraft.getInstance().getConnection();
|
||||||
|
if (connection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String searchLower = lastSearch.toLowerCase(Locale.ROOT);
|
||||||
|
boolean blankSearch = lastSearch.isBlank();
|
||||||
|
|
||||||
|
for (PlayerInfo playerInfo : connection.getOnlinePlayers()) {
|
||||||
|
GameProfile profile = playerInfo.getProfile();
|
||||||
|
|
||||||
|
if (profile.getId().equals(Minecraft.getInstance().player.getUUID())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profile.getId().version() != 4 && !includeNpcs) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blankSearch) {
|
||||||
|
if (visible) {
|
||||||
|
editorState.hideDuringExport.remove(profile.getId());
|
||||||
|
} else {
|
||||||
|
editorState.hideDuringExport.add(profile.getId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String nameLower = profile.getName().toLowerCase(Locale.ROOT);
|
||||||
|
if (nameLower.contains(searchLower)) {
|
||||||
|
if (visible) {
|
||||||
|
editorState.hideDuringExport.remove(profile.getId());
|
||||||
|
} else {
|
||||||
|
editorState.hideDuringExport.add(profile.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user