Allow saving selected theme in the prefs

This commit is contained in:
simon.kagstrom 2010-03-13 14:30:15 +00:00
parent 86750bfb5e
commit 322faaf28b
4 changed files with 15 additions and 3 deletions

View File

@ -118,6 +118,8 @@ Prefs::Prefs()
snprintf(this->NetworkServer, 64, "play.c64-network.org"); snprintf(this->NetworkServer, 64, "play.c64-network.org");
this->NetworkPort = 46214; this->NetworkPort = 46214;
this->NetworkRegion = REGION_UNKNOWN; this->NetworkRegion = REGION_UNKNOWN;
strcpy(this->Theme, "default");
} }
@ -315,6 +317,7 @@ bool Prefs::operator==(const Prefs &rhs) const
&& this->NetworkRegion == rhs.NetworkRegion && this->NetworkRegion == rhs.NetworkRegion
&& strcmp(this->NetworkServer, rhs.NetworkServer) == 0 && strcmp(this->NetworkServer, rhs.NetworkServer) == 0
&& strcmp(this->NetworkName, rhs.NetworkName) == 0 && strcmp(this->NetworkName, rhs.NetworkName) == 0
&& strcmp(this->Theme, rhs.Theme) == 0
&& this->NetworkAvatar == rhs.NetworkAvatar && this->NetworkAvatar == rhs.NetworkAvatar
); );
} }
@ -499,6 +502,8 @@ void Prefs::Load(const char *filename)
NetworkRegion = atoi(value); NetworkRegion = atoi(value);
else if (!strcmp(keyword, "NetworkAvatar")) else if (!strcmp(keyword, "NetworkAvatar"))
NetworkAvatar = atoi(value); NetworkAvatar = atoi(value);
else if (!strcmp(keyword, "Theme"))
strcpy(Theme, value);
} }
} }
fclose(file); fclose(file);
@ -610,6 +615,7 @@ bool Prefs::Save(const char *filename)
maybe_write(file, strcmp(NetworkServer, TheDefaultPrefs.NetworkServer) != 0, "NetworkServer = %s\n", NetworkServer); maybe_write(file, strcmp(NetworkServer, TheDefaultPrefs.NetworkServer) != 0, "NetworkServer = %s\n", NetworkServer);
maybe_write(file, NetworkPort != TheDefaultPrefs.NetworkPort, "NetworkPort = %d\n", NetworkPort); maybe_write(file, NetworkPort != TheDefaultPrefs.NetworkPort, "NetworkPort = %d\n", NetworkPort);
maybe_write(file, NetworkRegion != TheDefaultPrefs.NetworkRegion, "NetworkRegion = %d\n", NetworkRegion); maybe_write(file, NetworkRegion != TheDefaultPrefs.NetworkRegion, "NetworkRegion = %d\n", NetworkRegion);
maybe_write(file, strcmp(Theme, TheDefaultPrefs.Theme) != 0, "Theme = %s\n", Theme);
fclose(file); fclose(file);
ThePrefsOnDisk = *this; ThePrefsOnDisk = *this;
return true; return true;

View File

@ -171,6 +171,7 @@ public:
int NetworkKey; int NetworkKey;
uint16 NetworkAvatar; uint16 NetworkAvatar;
char Theme[128];
}; };

View File

@ -572,7 +572,10 @@ void Gui::init()
{ {
Gui::gui = new Gui(); Gui::gui = new Gui();
/* Set the default theme */ if (!Gui::gui->setTheme(ThePrefs.Theme))
panic_if(!Gui::gui->setTheme("default"), {
"Setting default theme failed\n"); /* Set the default theme */
panic_if (!Gui::gui->setTheme(ThePrefs.Theme),
"Setting default theme failed\n");
}
} }

View File

@ -43,11 +43,13 @@ public:
char *p = xstrdup(msg); char *p = xstrdup(msg);
p[strlen(p) - 1] = '\0'; p[strlen(p) - 1] = '\0';
strcpy(Gui::gui->np->Theme, p + 1);
if (!Gui::gui->setTheme(p + 1)) if (!Gui::gui->setTheme(p + 1))
{ {
/* Something is wrong, reset to default */ /* Something is wrong, reset to default */
Gui::gui->setTheme("default"); Gui::gui->setTheme("default");
Gui::gui->pushDialogueBox(new DialogueBox(broken_theme_dlg)); Gui::gui->pushDialogueBox(new DialogueBox(broken_theme_dlg));
strcpy(Gui::gui->np->Theme, "default");
} }
free(p); free(p);
} }