Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions GameMod/ExtendedConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ static void Prefix()
"[SECTION: AUDIOTAUNT_KEYBINDS]",
"[SECTION: AUDIOTAUNT_MUTED_PLAYERS]",
"[SECTION: AUDIOTAUNT_SELECTED_TAUNTS]",
"[SECTION: HOTKEYS]",
//...
};

Expand Down Expand Up @@ -348,6 +349,11 @@ private static void PassSectionToFunction(List<string> section, string section_n
Section_AudiotauntSelectedTaunts.Load(section);
return;
}
if (section_name.Equals(known_sections[6]))
{
Section_Hotkeys.Load(section);
return;
}
//...

}
Expand Down Expand Up @@ -388,6 +394,10 @@ public static void SaveActivePilot()
Section_AudiotauntSelectedTaunts.Save(w);
w.WriteLine("[/END]");

w.WriteLine("[SECTION: HOTKEYS]");
Section_Hotkeys.Save(w);
w.WriteLine("[/END]");

//...

if (unknown_sections != null)
Expand Down Expand Up @@ -416,12 +426,14 @@ public static void SetDefaultConfig()
Section_JoystickCurve.SetDefault();
Section_WeaponCycling.Set();
Section_AudiotauntKeybinds.SetDefaultKeybinds();
Section_Hotkeys.Set();
}

public static void ApplyConfigData()
{
Section_AutoSelect.ApplySettings();
Section_WeaponCycling.ApplySettings();
Section_Hotkeys.ApplySettings();
}


Expand Down Expand Up @@ -1099,6 +1111,82 @@ public static void Save(StreamWriter w){
}
}

internal class Section_Hotkeys
{
public static Dictionary<string, string> settings;

public static void Load(List<string> section)
{
settings = new Dictionary<string, string>();
foreach (string line in section)
{
string l = RemoveWhitespace(line);
string[] res = l.Split(':');
if (res.Length == 2)
{
settings.Add(res[0], res[1]);
}
else
{
Debug.Log("Error in ExtendedConfig.Section_Hotkeys.Load: unexpected line split: " + line + ", Setting Default Values.");
Set();
return;
}
}
ApplySettings();
}

public static void Save(StreamWriter w)
{
if (settings != null)
{
foreach (var setting in settings)
{
if (setting.Key != null && setting.Value != null)
{
w.WriteLine(" " + setting.Key + ": " + setting.Value);
}
}
}
}

// sets the values of the hotkeys dictionary
// mirror = false sets the default bindings
// mirror = true sets the current Hotkeys bindings
public static void Set(bool mirror = false)
{
settings = new Dictionary<string, string>();
foreach (Hotkeys.Hotkey h in Hotkeys.hotkeys)
{
settings.Add(h.name, mirror ? Hotkeys.FormatBinding(h.keys) : h.defaultBinding);
}
}

public static void ApplySettings()
{
if (settings == null)
{
return;
}
foreach (var setting in settings)
{
if (!Hotkeys.SetBinding(setting.Key, setting.Value))
{
Debug.Log("[HOTKEYS] ignoring config entry '" + setting.Key + ": " + setting.Value + "'");
}
}
// hotkeys added after the config file was written keep their default
// binding and get included on the next save
foreach (Hotkeys.Hotkey h in Hotkeys.hotkeys)
{
if (!settings.ContainsKey(h.name))
{
settings.Add(h.name, Hotkeys.FormatBinding(h.keys));
}
}
}
}

internal class Section_AudiotauntMutedPlayers
{
public static HashSet<string> ids = new HashSet<string>();
Expand Down
1 change: 1 addition & 0 deletions GameMod/GameMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="FrameTime.cs" />
<Compile Include="GameMod.cs" />
<Compile Include="GSyncFix.cs" />
<Compile Include="Hotkeys.cs" />
<Compile Include="JoystickCurveEditor.cs" />
<Compile Include="JoystickRotationFix.cs" />
<Compile Include="LevelError.cs" />
Expand Down
Loading