Example #1
0
        public static void Collisions(UIHelper helper)
        {
            try {
                Log.Debug(Environment.StackTrace);
                if (MainPanel.Instance is MainPanel mainPanel)
                {
                    var keys = new List <SavedInputKey>();
                    foreach (var b in mainPanel.ModButtons)
                    {
                        if (b.ActivationKey != null)
                        {
                            keys.Add(b.ActivationKey);
                        }
                    }
                    keys.AddRange(mainPanel.CustomHotkeys.Keys);

                    // clear group.
                    foreach (var c in (helper.self as UIPanel).components)
                    {
                        GameObject.Destroy(c.gameObject);
                    }

                    // add conflicts:
                    var keymappingsPanel = helper.AddKeymappingsPanel();
                    keymappingsPanel.component.name = CONFLICTS_PANEL_NAME;

                    for (int i1 = 0; i1 < keys.Count; ++i1)
                    {
                        for (int i2 = i1 + 1; i2 < keys.Count; ++i2)
                        {
                            var key1     = keys[i1];
                            var key2     = keys[i2];
                            var conflict = key1 != key2 && key1.value == key2.value;
                            if (conflict)
                            {
                                var file1 = (string)ReflectionHelpers.GetFieldValue(key1, "m_FileName");
                                var file2 = (string)ReflectionHelpers.GetFieldValue(key2, "m_FileName");
                                keymappingsPanel.AddKeymapping($"{file1}.{key1.name}", key1);
                                keymappingsPanel.AddKeymapping($"{file2}.{key2.name}", key2);
                                Log.Warning($"Collision Detected: " +
                                            $"{file1}.{key1.name}:'{key1}' collides with " +
                                            $"{file2}.{key2.name}:'{key2}'");
                            }
                        }
                    }

                    if (keymappingsPanel.GetComponentsInChildren <UIButton>().IsNullorEmpty())
                    {
                        keymappingsPanel.component.AddUIComponent <UILabel>().text = "None";
                    }
                }
            } catch (Exception ex) {
                Log.Exception(ex);
            }
        }
Example #2
0
 public static void OnSettingsUI(UIHelper helper)
 {
     try {
         Debug.Log(Environment.StackTrace);
         var keymappingsPanel = helper.AddKeymappingsPanel();
         keymappingsPanel.AddKeymapping("Hotkey", Hotkey);
     } catch (Exception ex) {
         Debug.LogException(ex);
         UIView.ForwardException(ex);
     }
 }