Skip to content

Commit 4c15412

Browse files
committed
Fixed Pinning
1 parent 5b6bb69 commit 4c15412

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

src/main/java/net/wurstclient/clickgui/ClickGui.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,64 @@ public void init()
239239
window.setPinned(jsonPinned.getAsBoolean());
240240
}
241241

242+
// Recreate any pinned settings windows
243+
for(java.util.Map.Entry<String, JsonElement> e : json.entrySet())
244+
{
245+
String title = e.getKey();
246+
boolean exists = false;
247+
for(Window w : windows)
248+
if(w.getTitle().equals(title))
249+
{
250+
exists = true;
251+
break;
252+
}
253+
if(exists)
254+
continue;
255+
256+
final String suffix = " Settings";
257+
if(!title.endsWith(suffix))
258+
continue;
259+
String featName =
260+
title.substring(0, title.length() - suffix.length());
261+
Feature matched = null;
262+
for(Feature f : features)
263+
if(f.getName().equals(featName))
264+
{
265+
matched = f;
266+
break;
267+
}
268+
if(matched == null)
269+
continue;
270+
// Create a SettingsWindow for the feature and apply saved state.
271+
try
272+
{
273+
SettingsWindow sw =
274+
new SettingsWindow(matched, windows.get(0), 0);
275+
JsonObject jw = e.getValue().getAsJsonObject();
276+
JsonElement jx = jw.get("x");
277+
if(jx != null && jx.isJsonPrimitive()
278+
&& jx.getAsJsonPrimitive().isNumber())
279+
sw.setX(jx.getAsInt());
280+
JsonElement jy = jw.get("y");
281+
if(jy != null && jy.isJsonPrimitive()
282+
&& jy.getAsJsonPrimitive().isNumber())
283+
sw.setY(jy.getAsInt());
284+
JsonElement jm = jw.get("minimized");
285+
if(jm != null && jm.isJsonPrimitive()
286+
&& jm.getAsJsonPrimitive().isBoolean())
287+
sw.setMinimized(jm.getAsBoolean());
288+
JsonElement jp = jw.get("pinned");
289+
if(jp != null && jp.isJsonPrimitive()
290+
&& jp.getAsJsonPrimitive().isBoolean())
291+
sw.setPinned(jp.getAsBoolean());
292+
windows.add(sw);
293+
}catch(Throwable ignored)
294+
{
295+
// Best-effort: ignore any failure recreating saved settings
296+
// windows
297+
}
298+
}
299+
242300
saveWindows();
243301
}
244302

@@ -248,7 +306,12 @@ private void saveWindows()
248306

249307
for(Window window : windows)
250308
{
251-
if(window.isClosable())
309+
// Persist pinned/position/minimized state for non-closable windows
310+
// as before. Also persist closable windows only when they're pinned
311+
// so user-constructed settings/popups that they pinned survive UI
312+
// reloads. This fixes lost pin state for per-feature settings
313+
// windows.
314+
if(window.isClosable() && !window.isPinned())
252315
continue;
253316

254317
JsonObject jsonWindow = new JsonObject();

0 commit comments

Comments
 (0)