@@ -42,7 +42,7 @@ local RageFile =
|
||||
IniFile =
|
||||
{
|
||||
StrToKeyVal = function( str )
|
||||
local _, _, key, value = str:find( "(.+)=(.*)" )
|
||||
local key, value = str:match( "(.+)=(.*)" )
|
||||
|
||||
-- key is always a string, but value may be num, bool, or nil.
|
||||
-- do a few quick checks to see which one it is.
|
||||
@@ -80,7 +80,7 @@ IniFile =
|
||||
--ignore comments.
|
||||
if not str:find("^%s*#") then
|
||||
-- is this a section?
|
||||
local _, _, sec = str:find( "%[(.+)%]" )
|
||||
local sec = str:match( "%[(.+)%]" )
|
||||
|
||||
-- if so, set focus there; otherwise, try to
|
||||
-- read a key/value pair (ignore blank lines)
|
||||
@@ -91,7 +91,7 @@ IniFile =
|
||||
--Warn( "Switching section to " .. sec )
|
||||
else
|
||||
local k, v = IniFile.StrToKeyVal( str )
|
||||
if k and v then current[k] = v end
|
||||
if k and v ~= nil then current[k] = v end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,6 +79,7 @@ ThemePrefs =
|
||||
-- Only read from disk once, when _fallback calls this; we just
|
||||
-- need the base set once to add prefs onto.
|
||||
Init = function( prefs, bLoadFromDisk )
|
||||
|
||||
-- If we don't have IniFile, we can't read/write from/to disk
|
||||
if not IniFile then Warn( GetString("IniFileMissing") ) end
|
||||
|
||||
@@ -99,7 +100,7 @@ ThemePrefs =
|
||||
|
||||
-- if the key doesn't exist, add it with our default value
|
||||
for k, tbl in pairs(prefs) do
|
||||
if not PrefsTable[section][k] then
|
||||
if PrefsTable[section][k] == nil then
|
||||
Trace( k .. " doesn't exist, creating" )
|
||||
PrefsTable[section][k] = tbl.Default
|
||||
end
|
||||
@@ -116,16 +117,17 @@ ThemePrefs =
|
||||
|
||||
Save = function()
|
||||
-- Trace( "ThemePrefs.Save" )
|
||||
if not IniFile then return false end
|
||||
if not NeedsSaved then return end
|
||||
NeedsSaved = false
|
||||
IniFile.WriteFile( ThemePrefsPath, PrefsTable )
|
||||
if IniFile and ThemePrefs.NeedsSaved then
|
||||
IniFile.WriteFile( ThemePrefsPath, PrefsTable )
|
||||
ThemePrefs.NeedsSaved = false
|
||||
return
|
||||
end
|
||||
end,
|
||||
|
||||
-- for when you absolutely have to save, no matter what NeedsSaved says.
|
||||
ForceSave = function()
|
||||
if not IniFile then return false end
|
||||
NeedsSaved = false
|
||||
ThemePrefs.NeedsSaved = false
|
||||
IniFile.WriteFile( ThemePrefsPath, PrefsTable )
|
||||
end,
|
||||
|
||||
@@ -140,7 +142,11 @@ ThemePrefs =
|
||||
Set = function( name, value )
|
||||
--Trace( ("ThemePrefs.Set(%s, %s)"):format(name, tostring(value)) )
|
||||
local tbl = ResolveTable(name)
|
||||
if tbl then tbl[name] = value; NeedsSaved = true; return end
|
||||
if tbl then
|
||||
ThemePrefs.NeedsSaved = true
|
||||
tbl[name] = value
|
||||
return
|
||||
end
|
||||
Warn( "Set: "..GetString("UnknownPreference"):format(name) )
|
||||
end,
|
||||
};
|
||||
|
||||
@@ -57,8 +57,11 @@ local function DefaultSave( pref, choices, values )
|
||||
|
||||
return function(self, list, pn)
|
||||
for i=1, #choices do
|
||||
if list[i] then ThemePrefs.Set( pref, values[i] ) break end
|
||||
MESSAGEMAN:Broadcast( msg, params )
|
||||
if list[i] then
|
||||
ThemePrefs.Set( pref, values[i] )
|
||||
MESSAGEMAN:Broadcast( msg, params )
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
return Def.Actor{
|
||||
StartTransitioningCommand=function(self)
|
||||
ThemePrefs.Save()
|
||||
end
|
||||
}
|
||||
@@ -2,17 +2,6 @@ InitUserPrefs();
|
||||
|
||||
local t = Def.ActorFrame {}
|
||||
|
||||
t[#t+1] = Def.ActorFrame {
|
||||
OnCommand=function(self)
|
||||
if not FILEMAN:DoesFileExist("Save/ThemePrefs.ini") then
|
||||
Trace("ThemePrefs doesn't exist; creating file")
|
||||
ThemePrefs.ForceSave()
|
||||
end
|
||||
|
||||
ThemePrefs.Save()
|
||||
end;
|
||||
};
|
||||
|
||||
t[#t+1] = StandardDecorationFromFileOptional("Footer","Footer");
|
||||
t[#t+1] = StandardDecorationFromFileOptional("Logo","Logo");
|
||||
t[#t+1] = StandardDecorationFromFileOptional("VersionInfo","VersionInfo");
|
||||
|
||||
Reference in New Issue
Block a user