Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 69 additions & 12 deletions runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class ClientUI
private static final String CONFIG_CLIENT_BOUNDS = "clientBounds";
private static final String CONFIG_CLIENT_MAXIMIZED = "clientMaximized";
private static final String CONFIG_CLIENT_SIDEBAR_CLOSED = "clientSidebarClosed";
private static final String CONFIG_CLIENT_SIDEBAR_TAB = "clientSidebarTab";
private static final String CONFIG_CLIENT_CONSOLE_OPEN = "clientConsoleOpen";
public static final BufferedImage ICON_128 = ImageUtil.loadImageResource(Microbot.class, "microbot_logo.png");
public static final BufferedImage ICON_16 = ImageUtil.loadImageResource(Microbot.class, "microbot_logo.png");
public static String proxyMessage = "";
Expand Down Expand Up @@ -164,6 +166,8 @@ public class ClientUI
private BufferedImage consoleIconOpen;
private BufferedImage consoleIconClosed;
private boolean consoleVisible;
private boolean sidebarTabRestored;
private boolean updatingNavigation;

@RequiredArgsConstructor
private static class HistoryEntry
Expand Down Expand Up @@ -202,7 +206,9 @@ private void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals(CONFIG_GROUP) ||
event.getKey().equals(CONFIG_CLIENT_MAXIMIZED) ||
event.getKey().equals(CONFIG_CLIENT_BOUNDS))
event.getKey().equals(CONFIG_CLIENT_BOUNDS) ||
event.getKey().equals(CONFIG_CLIENT_SIDEBAR_TAB) ||
event.getKey().equals(CONFIG_CLIENT_CONSOLE_OPEN))
{
return;
}
Expand All @@ -226,12 +232,28 @@ void addNavigation(NavigationButton navBtn)
final int TAB_SIZE = 16;
Icon icon = new ImageIcon(ImageUtil.resizeImage(navBtn.getIcon(), TAB_SIZE, TAB_SIZE));

sidebar.insertTab(null, icon, navBtn.getPanel().getWrappedPanel(), navBtn.getTooltip(),
sidebarEntries.headSet(navBtn).size());
// insertTab changes the selected index when the first tab is inserted, avoid this
if (sidebar.getTabCount() == 1)
updatingNavigation = true;
try
{
sidebar.setSelectedIndex(-1);
sidebar.insertTab(null, icon, navBtn.getPanel().getWrappedPanel(), navBtn.getTooltip(),
sidebarEntries.headSet(navBtn).size());
// insertTab changes the selected index when the first tab is inserted, avoid this
if (sidebar.getTabCount() == 1)
{
sidebar.setSelectedIndex(-1);
}

if (!sidebarTabRestored
&& sidebar.getSelectedIndex() < 0
&& navBtn.getTooltip().equals(configManager.getConfiguration(CONFIG_GROUP, CONFIG_CLIENT_SIDEBAR_TAB)))
{
sidebarTabRestored = true;
sidebar.setSelectedIndex(sidebarEntries.headSet(navBtn).size());
}
}
finally
{
updatingNavigation = false;
}
}

Expand All @@ -245,14 +267,22 @@ void removeNavigation(NavigationButton navBtn)
{
boolean closingOpenTab = !selectedTabHistory.isEmpty() && selectedTabHistory.getLast().navBtn == navBtn;
selectedTabHistory.removeIf(it -> it.navBtn == navBtn);
sidebar.remove(navBtn.getPanel().getWrappedPanel());
if (closingOpenTab)
updatingNavigation = true;
try
{
HistoryEntry entry = selectedTabHistory.isEmpty()
? new HistoryEntry(true, null)
: selectedTabHistory.removeLast();
sidebar.remove(navBtn.getPanel().getWrappedPanel());
if (closingOpenTab)
{
HistoryEntry entry = selectedTabHistory.isEmpty()
? new HistoryEntry(true, null)
: selectedTabHistory.removeLast();

openPanel(entry.navBtn, entry.sidebarOpen);
openPanel(entry.navBtn, entry.sidebarOpen);
}
}
finally
{
updatingNavigation = false;
}
}

Expand Down Expand Up @@ -420,6 +450,19 @@ public void componentMoved(ComponentEvent e)

selectedTab = newSelectedTab;

if (!updatingNavigation)
{
sidebarTabRestored = true;
if (newSelectedTab == null)
{
configManager.unsetConfiguration(CONFIG_GROUP, CONFIG_CLIENT_SIDEBAR_TAB);
}
else
{
configManager.setConfiguration(CONFIG_GROUP, CONFIG_CLIENT_SIDEBAR_TAB, newSelectedTab.getTooltip());
}
}

if (sidebar.isVisible())
{
pushHistory();
Expand Down Expand Up @@ -630,6 +673,12 @@ else if (OSType.getOSType() == OSType.MacOS && SystemInfo.isMacFullWindowContent
// Update config
updateFrameConfig(false);

// Reopen the console if it was open when the client was last closed
if (configManager.getConfiguration(CONFIG_GROUP, CONFIG_CLIENT_CONSOLE_OPEN, Boolean.class) == Boolean.TRUE)
{
setConsoleVisible(true);
}

// Close sidebar if the config closed state is set
if (configManager.getConfiguration(CONFIG_GROUP, CONFIG_CLIENT_SIDEBAR_CLOSED, Boolean.class) == Boolean.TRUE)
{
Expand Down Expand Up @@ -1187,6 +1236,14 @@ private void setConsoleVisible(boolean visible)
}

consoleVisible = visible;
if (visible)
{
configManager.setConfiguration(CONFIG_GROUP, CONFIG_CLIENT_CONSOLE_OPEN, true);
}
else
{
configManager.unsetConfiguration(CONFIG_GROUP, CONFIG_CLIENT_CONSOLE_OPEN);
}
clientPanel.setConsoleVisible(visible);
updateConsoleToggleButton();

Expand Down
Loading
Loading