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

View File

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

View File

@ -572,7 +572,10 @@ void Gui::init()
{
Gui::gui = new Gui();
/* Set the default theme */
panic_if(!Gui::gui->setTheme("default"),
"Setting default theme failed\n");
if (!Gui::gui->setTheme(ThePrefs.Theme))
{
/* 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);
p[strlen(p) - 1] = '\0';
strcpy(Gui::gui->np->Theme, p + 1);
if (!Gui::gui->setTheme(p + 1))
{
/* Something is wrong, reset to default */
Gui::gui->setTheme("default");
Gui::gui->pushDialogueBox(new DialogueBox(broken_theme_dlg));
strcpy(Gui::gui->np->Theme, "default");
}
free(p);
}