-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathSettings.cs
89 lines (79 loc) · 3.27 KB
/
Settings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/***************************************************************************
* Settings.cs
* Copyright (c) 2015 UltimaXNA Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
***************************************************************************/
#region usings
using System;
using UltimaXNA.Configuration;
using UltimaXNA.Core.Configuration;
#endregion
namespace UltimaXNA
{
public class Settings
{
// === Instance ===============================================================================================
readonly DebugSettings m_Debug;
readonly EngineSettings m_Engine;
readonly GumpSettings m_Gumps;
readonly UserInterfaceSettings m_UI;
readonly LoginSettings m_Login;
readonly UltimaOnlineSettings m_UltimaOnline;
readonly AudioSettings m_Audio;
Settings()
{
m_Debug = CreateOrOpenSection<DebugSettings>();
m_Login = CreateOrOpenSection<LoginSettings>();
m_UltimaOnline = CreateOrOpenSection<UltimaOnlineSettings>();
m_Engine = CreateOrOpenSection<EngineSettings>();
m_UI = CreateOrOpenSection<UserInterfaceSettings>();
m_Gumps = CreateOrOpenSection<GumpSettings>();
m_Audio = CreateOrOpenSection<AudioSettings>();
}
// === Static Settings properties =============================================================================
public static DebugSettings Debug => s_Instance.m_Debug;
public static LoginSettings Login => s_Instance.m_Login;
public static UltimaOnlineSettings UltimaOnline => s_Instance.m_UltimaOnline;
public static EngineSettings Engine => s_Instance.m_Engine;
public static GumpSettings Gumps => s_Instance.m_Gumps;
public static UserInterfaceSettings UserInterface => s_Instance.m_UI;
public static AudioSettings Audio => s_Instance.m_Audio;
static readonly Settings s_Instance;
static readonly SettingsFile s_File;
static Settings()
{
s_File = new SettingsFile("settings.cfg");
s_Instance = new Settings();
s_File.Load();
}
public static void Save()
{
s_File.Save();
}
public static T CreateOrOpenSection<T>()
where T : ASettingsSection, new()
{
string sectionName = typeof(T).Name;
T section = s_File.CreateOrOpenSection<T>(sectionName);
// Resubscribe incase this is called for a section 2 times.
section.Invalidated -= OnSectionInvalidated;
section.Invalidated += OnSectionInvalidated;
section.PropertyChanged -= OnSectionPropertyChanged;
section.PropertyChanged += OnSectionPropertyChanged;
return section;
}
static void OnSectionPropertyChanged(object sender, EventArgs e)
{
s_File.InvalidateDirty();
}
static void OnSectionInvalidated(object sender, EventArgs e)
{
s_File.InvalidateDirty();
}
}
}