public UIBindingRow(ViewModel model, Command command) { using (var tracker = TimingLogger.Track("UIBindingRow.ctor()")) { _model = model; _command = command; ActionName = command.Name; var binding = _model.GetKeyBinding(ActionName); tracker.Log("... after binding"); // checkbox on the left _checkboxStorable = new JSONStorableBool(ActionName, binding == null ? false : binding.Enabled, OnCheckboxHandler); _checkboxUi = _model.Plugin.CreateToggle(_checkboxStorable); _checkboxUi.labelText.text = command.DisplayName; _checkboxUi.labelText.resizeTextMaxSize = _checkboxUi.labelText.fontSize; _checkboxUi.labelText.resizeTextForBestFit = true; _checkboxUi.backgroundColor = Color.clear; tracker.Log("... after checkbox create"); var shortcutText = binding == null ? "" : binding.KeyChord.ToString(); _shortcutButtonUi = _model.Plugin.CreateButton(shortcutText, rightSide: true); _shortcutButtonUi.height = _checkboxUi.height; _shortcutButtonUi.button.onClick.AddListener(OnShortcutHandler); tracker.Log("... after button create"); } }
public List <KeyValuePair <string, KeyBinding> > GetShownBindings() { using (TimingLogger.Track("GetShowBindings()")) { var shown = new List <KeyValuePair <string, KeyBinding> >(); foreach (var item in _bindings) { var actionName = item.Key; Command command = _commandsByName.ContainsKey(actionName) ? _commandsByName[actionName] : null; if (command == null) { continue; } if (!ActionCategory.Equals(command.Group)) { continue; } if (!ActionSubCategory.Equals(command.SubGroup)) { continue; } shown.Add(item); } return(shown); } }
private void InitUI() { using (TimingLogger.Track("InitUI()")) { InitUIHeader(); InitUIBindings(); } }
public void Initialize() { using (var timing = TimingLogger.Track("Initialize()")) { _actionController = new CommandFactory(Plugin); InitBindings(); InitializeUI(); } }
private void InitUIBindings() { var shownBindings = GetShownBindings(); using (TimingLogger.Track($"InitUIBindings() [count: {shownBindings.Count}]")) { // show ui elements based on filters foreach (var item in shownBindings) { var actionName = item.Key; var command = _commandsByName[actionName]; _uiBindings.Add(new UIBindingRow(this, command)); } } }
private void InitUIHeader() { using (TimingLogger.Track("InitUIHeader()")) { // add the action filter using (TimingLogger.Track("... setup category dropdown")) { var groupNames = GetGroupNames().OrderBy((x) => x).ToList(); if (_actionFilterStorable == null) { _actionFilterStorable = new JSONStorableStringChooser("category", groupNames, ActionCategory, ""); _actionFilterUi = Plugin.CreateScrollablePopup(_actionFilterStorable); _actionFilterUi.labelWidth = 0f; _actionFilterUi.popup.onValueChangeHandlers += (newValue) => { var currentSubCategory = ActionSubCategory; ActionCategory = newValue; var subCategories = GetSubGroupNames(newValue).ToList(); if (subCategories.Count == 0) { ActionSubCategory = ""; } else if (!subCategories.Any((c) => c.Equals(currentSubCategory))) { ActionSubCategory = subCategories[0]; } InitializeUI(); // TODO: figure out how to actually get this UI element to // show up on top of the UI elements just below it instead // of behind _actionFilterUi.popup.Toggle(); _actionFilterUi.popup.Toggle(); }; } else { _actionFilterStorable.choices = groupNames; } } using (TimingLogger.Track("... setup subcategory dropdown")) { // add the subcategory filter var subCategories = GetSubGroupNames(ActionCategory).OrderBy((x) => x).ToList(); if (_actionSubCatFilterStorable == null) { _actionSubCatFilterStorable = new JSONStorableStringChooser("subcategory", subCategories, ActionSubCategory, ""); _actionSubCatFilterUi = Plugin.CreateScrollablePopup(_actionSubCatFilterStorable, rightSide: true); _actionSubCatFilterUi.height = _actionFilterUi.height; _actionSubCatFilterUi.labelWidth = 0f; _actionSubCatFilterUi.popup.onValueChangeHandlers += (newValue) => { ActionSubCategory = newValue; InitializeUI(); // TODO: figure out how to actually get this UI element to // show up on top of the UI elements just below it instead // of behind _actionSubCatFilterUi.popup.Toggle(); _actionSubCatFilterUi.popup.Toggle(); }; } else { _actionSubCatFilterStorable.choices = subCategories; _actionSubCatFilterUi.popup.currentValueNoCallback = ActionSubCategory; } } } }