public virtual void Clear() { Buttons = new WorkingDictionary<string, bool>(); Floats = new WorkingDictionary<string, float>(); }
private void LoadToPanel <T>(Control dest, string controllerName, IList <string> controllerButtons, Dictionary <string, string> categoryLabels, IDictionary <string, Dictionary <string, T> > settingsBlock, T defaultValue, PanelCreator <T> createPanel) { if (!settingsBlock.TryGetValue(controllerName, out var settings)) { settings = new Dictionary <string, T>(); settingsBlock[controllerName] = settings; } // check to make sure that the settings object has all of the appropriate bool buttons foreach (var button in controllerButtons) { if (!settings.Keys.Contains(button)) { settings[button] = defaultValue; } } if (controllerButtons.Count == 0) { return; } // split the list of all settings into buckets by player number var buckets = new List <string> [MaxPlayers + 1]; var categoryBuckets = new WorkingDictionary <string, List <string> >(); for (var i = 0; i < buckets.Length; i++) { buckets[i] = new List <string>(); } // by iterating through only the controller's active buttons, we're silently // discarding anything that's not on the controller right now. due to the way // saving works, those entries will still be preserved in the config file, tho foreach (var button in controllerButtons) { int i; for (i = MaxPlayers; i > 0; i--) { if (button.StartsWith($"P{i}")) { break; } } if (i > MaxPlayers) // couldn't find { i = 0; } if (categoryLabels.ContainsKey(button)) { categoryBuckets[categoryLabels[button]].Add(button); } else { buckets[i].Add(button); } } if (buckets[0].Count == controllerButtons.Count) { // everything went into bucket 0, so make no tabs at all dest.Controls.Add(createPanel(settings, controllerButtons.ToList(), dest.Size)); } else { // create multiple player tabs var tt = new TabControl { Dock = DockStyle.Fill }; dest.Controls.Add(tt); int pageIdx = 0; for (int i = 1; i <= MaxPlayers; i++) { if (buckets[i].Count > 0) { string tabName = _emulator.SystemId != "WSWAN" ? $"Player {i}" : i == 1 ? "Normal" : "Rotated"; // hack tt.TabPages.Add(tabName); tt.TabPages[pageIdx].Controls.Add(createPanel(settings, buckets[i], tt.Size)); pageIdx++; } } foreach (var cat in categoryBuckets) { string tabName = cat.Key; tt.TabPages.Add(tabName); tt.TabPages[pageIdx].Controls.Add(createPanel(settings, cat.Value, tt.Size)); // ZxHawk hack - it uses multiple categoryLabels if (_emulator.SystemId == "ZXSpectrum" || _emulator.SystemId == "AmstradCPC" || _emulator.SystemId == "ChannelF") { pageIdx++; } } if (buckets[0].Count > 0) { // ZXHawk needs to skip this bit if (_emulator.SystemId == "ZXSpectrum" || _emulator.SystemId == "AmstradCPC" || _emulator.SystemId == "ChannelF") { return; } string tabName = (_emulator.SystemId == "C64") ? "Keyboard" : (_emulator.SystemId == "MAME") ? "Misc" : "Console"; // hack tt.TabPages.Add(tabName); tt.TabPages[pageIdx].Controls.Add(createPanel(settings, buckets[0], tt.Size)); } } }
public void Clear() { Buttons = new WorkingDictionary <string, bool>(); Axes = new WorkingDictionary <string, int>(); }
public virtual void Clear() { Buttons = new WorkingDictionary <string, bool>(); Floats = new WorkingDictionary <string, float>(); }
private static void LoadToPanel <T>(Control dest, string controllerName, IList <string> controllerButtons, Dictionary <string, string> categoryLabels, IDictionary <string, Dictionary <string, T> > settingsblock, T defaultvalue, PanelCreator <T> createpanel) { Dictionary <string, T> settings; if (!settingsblock.TryGetValue(controllerName, out settings)) { settings = new Dictionary <string, T>(); settingsblock[controllerName] = settings; } // check to make sure that the settings object has all of the appropriate boolbuttons foreach (var button in controllerButtons) { if (!settings.Keys.Contains(button)) { settings[button] = defaultvalue; } } if (controllerButtons.Count == 0) { return; } // split the list of all settings into buckets by player number var buckets = new List <string> [MAXPLAYERS + 1]; var categoryBuckets = new WorkingDictionary <string, List <string> >(); for (var i = 0; i < buckets.Length; i++) { buckets[i] = new List <string>(); } // by iterating through only the controller's active buttons, we're silently // discarding anything that's not on the controller right now. due to the way // saving works, those entries will still be preserved in the config file, tho foreach (var button in controllerButtons) { int i; for (i = 1; i <= MAXPLAYERS; i++) { if (button.StartsWith("P" + i)) { break; } } if (i > MAXPLAYERS) // couldn't find { i = 0; } if (categoryLabels.ContainsKey(button)) { categoryBuckets[categoryLabels[button]].Add(button); } else { buckets[i].Add(button); } } if (buckets[0].Count == controllerButtons.Count) { // everything went into bucket 0, so make no tabs at all dest.Controls.Add(createpanel(settings, controllerButtons.ToList(), dest.Size)); } else { // create multiple player tabs var tt = new TabControl { Dock = DockStyle.Fill }; dest.Controls.Add(tt); int pageidx = 0; for (int i = 1; i <= MAXPLAYERS; i++) { if (buckets[i].Count > 0) { string tabname = Global.Emulator.SystemId == "WSWAN" ? i == 1 ? "Normal" : "Rotated" : "Player " + i; // hack tt.TabPages.Add(tabname); tt.TabPages[pageidx].Controls.Add(createpanel(settings, buckets[i], tt.Size)); pageidx++; } } foreach (var cat in categoryBuckets) { string tabname = cat.Key; tt.TabPages.Add(tabname); tt.TabPages[pageidx].Controls.Add(createpanel(settings, cat.Value, tt.Size)); } if (buckets[0].Count > 0) { string tabname = Global.Emulator.SystemId == "C64" ? "Keyboard" : "Console"; // hack tt.TabPages.Add(tabname); tt.TabPages[pageidx].Controls.Add(createpanel(settings, buckets[0], tt.Size)); } } }