time tracking: fix birdhouse notification buttons not doing anything

This commit is contained in:
Hydrox6
2021-04-12 14:47:30 +01:00
committed by Abex
parent 2eb5a8ce32
commit 66c9e5785f
3 changed files with 25 additions and 14 deletions

View File

@@ -42,6 +42,7 @@ public interface TimeTrackingConfig extends Config
String STOPWATCHES = "stopwatches";
String PREFER_SOONEST = "preferSoonest";
String NOTIFY = "notify";
String BIRDHOUSE_NOTIFY = "birdHouseNotification";
@ConfigItem(
keyName = "timeFormatMode",
@@ -65,17 +66,6 @@ public interface TimeTrackingConfig extends Config
return false;
}
@ConfigItem(
keyName = "birdHouseNotification",
name = "Bird house notification",
description = "Notify you when all bird houses are full",
position = 3
)
default boolean birdHouseNotification()
{
return false;
}
@ConfigItem(
keyName = "farmingContractInfoBox",
name = "Show farming contract infobox",

View File

@@ -31,24 +31,29 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import net.runelite.api.ItemID;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.timetracking.TabContentPanel;
import net.runelite.client.plugins.timetracking.TimeTrackingConfig;
import net.runelite.client.plugins.timetracking.TimeablePanel;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.DynamicGridLayout;
import javax.swing.JToggleButton;
public class BirdHouseTabPanel extends TabContentPanel
{
private static final Color COMPLETED_COLOR = ColorScheme.PROGRESS_COMPLETE_COLOR.darker();
private final ConfigManager configManager;
private final ItemManager itemManager;
private final BirdHouseTracker birdHouseTracker;
private final TimeTrackingConfig config;
private final List<TimeablePanel<BirdHouseSpace>> spacePanels;
BirdHouseTabPanel(ItemManager itemManager, BirdHouseTracker birdHouseTracker, TimeTrackingConfig config)
BirdHouseTabPanel(ConfigManager configManager, ItemManager itemManager, BirdHouseTracker birdHouseTracker,
TimeTrackingConfig config)
{
this.configManager = configManager;
this.itemManager = itemManager;
this.birdHouseTracker = birdHouseTracker;
this.config = config;
@@ -71,6 +76,17 @@ public class BirdHouseTabPanel extends TabContentPanel
first = false;
panel.setBorder(null);
}
JToggleButton toggleNotify = panel.getNotifyButton();
toggleNotify.addActionListener(e ->
{
if (configManager.getRSProfileKey() != null)
{
configManager.setRSProfileConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.BIRDHOUSE_NOTIFY, toggleNotify.isSelected());
}
spacePanels.forEach(p -> p.getNotifyButton().setSelected(toggleNotify.isSelected()));
});
}
}
@@ -85,6 +101,9 @@ public class BirdHouseTabPanel extends TabContentPanel
{
long unixNow = Instant.now().getEpochSecond();
boolean notifications = Boolean.TRUE
.equals(configManager.getRSProfileConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.BIRDHOUSE_NOTIFY, boolean.class));
for (TimeablePanel<BirdHouseSpace> panel : spacePanels)
{
BirdHouseSpace space = panel.getTimeable();
@@ -113,6 +132,8 @@ public class BirdHouseTabPanel extends TabContentPanel
panel.getProgress().setVisible(true);
}
panel.getNotifyButton().setSelected(notifications);
panel.getProgress().setForeground(state.getColor().darker());
switch (state)

View File

@@ -84,7 +84,7 @@ public class BirdHouseTracker
public BirdHouseTabPanel createBirdHouseTabPanel()
{
return new BirdHouseTabPanel(itemManager, this, config);
return new BirdHouseTabPanel(configManager, itemManager, this, config);
}
public void loadFromConfig()
@@ -180,7 +180,7 @@ public class BirdHouseTracker
summary = SummaryState.COMPLETED;
completionTime = 0;
if (config.birdHouseNotification())
if (Boolean.TRUE.equals(configManager.getRSProfileConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.BIRDHOUSE_NOTIFY, boolean.class)))
{
notifier.notify("Your bird houses are ready to be dismantled.");
}