GarminWatchfaces/KittieCats/source/ThemeManager.mc

172 lines
4.0 KiB
MonkeyC
Raw Normal View History

2024-11-15 14:02:03 +01:00
import Toybox.Lang;
class Theme
{
public var BackgroundHi;
public var BackgroundLo;
public var ArmHour;
public var ArmMinute;
public var ArmSecond;
2024-11-15 15:55:57 +01:00
public var MinuteOrnamentLo;
public var MinuteOrnamentOffset;
2024-11-15 14:02:03 +01:00
public var ArmHourTintHi;
public var ArmHourTintLo;
public var ArmHourTintSleep;
2024-11-15 14:02:03 +01:00
public var ArmMinuteTintHi;
public var ArmMinuteTintLo;
public var ArmMinuteTintSleep;
2024-11-15 14:02:03 +01:00
2024-11-15 15:55:57 +01:00
function initialize(backgroundHi, backgroundLo, armHour, armMinute, armSecond, minuteOrnamentLo, variablesJsonResource)
2024-11-15 14:02:03 +01:00
{
self.BackgroundHi = backgroundHi;
self.BackgroundLo = backgroundLo;
self.ArmHour = armHour;
self.ArmMinute = armMinute;
self.ArmSecond = armSecond;
2024-11-15 15:55:57 +01:00
self.MinuteOrnamentLo = minuteOrnamentLo;
2024-11-15 14:02:03 +01:00
var variables = Application.loadResource(variablesJsonResource) as Dictionary<String, Object>;
self.ArmHourTintHi = variables["ArmHourTintHi"];
self.ArmHourTintLo = variables["ArmHourTintLo"];
self.ArmHourTintSleep = variables["ArmHourTintSleep"];
2024-11-15 14:02:03 +01:00
self.ArmMinuteTintHi = variables["ArmMinuteTintHi"];
self.ArmMinuteTintLo = variables["ArmMinuteTintLo"];
self.ArmMinuteTintSleep = variables["ArmMinuteTintSleep"];
2024-11-15 15:55:57 +01:00
self.MinuteOrnamentOffset = variables["MinuteOrnamentOffset"];
2024-11-15 14:02:03 +01:00
}
}
class ThemeInfo
{
public var Id;
public var Name;
function initialize(id, name)
{
self.Id = id;
self.Name = name;
}
}
class ThemeManager
{
private static var instance = null;
private var currentThemeId = "default";
private var themes as Dictionary<String, Theme> = {};
private var localizedThemes as Array<ThemeInfo> or Null = null;
public function initialize()
{
self.themes["default"] = new Theme(
Rez.Drawables.Background,
Rez.Drawables.Ticks,
Rez.Drawables.ArmHour,
Rez.Drawables.ArmMinute,
Rez.Drawables.ArmSecond,
2024-11-15 15:55:57 +01:00
null,
2024-11-15 14:02:03 +01:00
Rez.JsonData.ThemeDefault
);
self.themes["xmas"] = new Theme(
Rez.Drawables.BackgroundXmas,
2024-11-15 15:55:57 +01:00
Rez.Drawables.TicksXmas,
2024-11-15 14:02:03 +01:00
Rez.Drawables.ArmHour,
Rez.Drawables.ArmMinute,
2024-11-15 15:55:57 +01:00
Rez.Drawables.ArmSecondXmas,
Rez.Drawables.Ball,
2024-11-15 14:02:03 +01:00
Rez.JsonData.ThemeXMas
);
var settingsThemeId = Application.Storage.getValue("theme");
if (settingsThemeId != null && self.themes.hasKey(settingsThemeId))
{
self.currentThemeId = settingsThemeId;
}
}
public function getCurrentThemeId() as Lang.String
{
return self.currentThemeId;
}
public function setCurrentThemeId(id as Lang.String) as Void
{
if (self.themes.hasKey(id))
{
self.currentThemeId = id;
Application.Storage.setValue("theme", id);
}
}
public function getCurrentTheme() as Theme
{
return self.themes[self.getCurrentThemeId()];
}
public function getLocalizedThemes() as Array<ThemeInfo>
{
if (self.localizedThemes == null)
{
var themes = Application.loadResource(Rez.JsonData.ThemeInfo) as Array<Dictionary<String, String>>;
self.localizedThemes = [];
for (var i = 0; i < themes.size(); i++)
{
self.localizedThemes.add(new ThemeInfo(themes[i]["id"], themes[i]["name"]));
}
}
return self.localizedThemes;
}
public function getLocalizedCurrentTheme() as ThemeInfo
{
var themes = self.getLocalizedThemes();
var currentThemeId = self.getCurrentThemeId();
for (var i = 0; i < themes.size(); i++)
{
if (themes[i].Id.equals(currentThemeId))
{
return themes[i];
}
}
return themes[0];
}
public static function getInstance()
{
if (instance == null)
{
instance = new ThemeManager();
}
return instance;
}
}