Пример #1
0
            /// <summary>
            /// A dictionary of all buttons.  When a new button is found on the toolbar, the dictionary is searched, first
            /// for the button itself,  and then the hash.  If neither is found, then it is added here.  If the hash is found on a
            /// different button, the old button is deleted and the new one is added
            /// </summary>
            void updateButtonDictionary(List <ApplicationLauncherButton> appListMod)
            {
                int cnt = 0;

                if (appListMod == null)
                {
                    Log.Info("appListMod == null");
                    return;
                }
                foreach (var a1 in appListMod)
                {
                    cnt++;
                    if (a1 == null)
                    {
                        Log.Info("a1 == null");
                        continue;
                    }
                    if (a1.gameObject == null)
                    {
                        Log.Info("gameObject == null");
                        continue;
                    }
                    var o = a1.gameObject.GetComponent <ReplacementToolbarClickHandler>();

                    if (o == null)
                    {
                        Log.Info("button missing ReplacementToolbarClickHandler");
                        return;
                    }


                    if (!JanitorsCloset.buttonDictionary.ContainsKey(a1))
                    {
                        Log.Info("Not in buttonDictionary");
                        string hash = JanitorsCloset.Instance.buttonId(a1);
                        ButtonDictionaryItem bdi = new ButtonDictionaryItem();
                        bdi.buttonHash = hash;

                        bool doThisOne = true;
                        Log.Info("Checking buttonBarList");
                        foreach (var z in JanitorsCloset.buttonBarList)
                        {
                            if (z.ContainsKey(hash))
                            {
                                doThisOne = false;
                                break;
                            }
                        }

                        if (doThisOne)
                        {
                            //  if (JanitorsCloset.buttonDictionary.Select(i => i.Value.buttonHash == hash).Count() > 0)
                            {
                                Log.Info("hash found, deleting entry, hash: " + hash);
                                foreach (var i in JanitorsCloset.buttonDictionary)
                                {
                                    Log.Info("buttonDictionaryHash: " + i.Value.buttonHash);
                                }
                                var key = JanitorsCloset.buttonDictionary.Where(m => m.Value.buttonHash == hash);

                                if (key != null && key.Count() > 0)
                                {
                                    Log.Info("deleting key from buttonDictionary");
                                    var k = key.First().Key;
                                    // Log.Info("k: " + k.name);
                                    bdi.identifier = JanitorsCloset.buttonDictionary[k].identifier;
                                    JanitorsCloset.buttonDictionary.Remove(k);
                                }
                            }
                            bdi.button = a1;
                            JanitorsCloset.buttonDictionary.Add(a1, bdi);
                        }
                    }
                }
            }
Пример #2
0
        void loadButtonData()
        {
            loadedCfgs       = new Dictionary <string, Cfg>();
            loadedHiddenCfgs = new Dictionary <string, ButtonSceneBlock>();
            Cfg cfg;

            foreach (string cfgFile in new List <string> {
                JC_DEFAULT_CFG_FILE, JC_CFG_FILE
            })
            {
                if (File.Exists(cfgFile))
                {
                    configFile = ConfigNode.Load(cfgFile);
                    ConfigNode janitorsClosetNode = configFile.GetNode(JC_NODE);
                    if (janitorsClosetNode != null)
                    {
                        foreach (ConfigNode n in janitorsClosetNode.GetNodes())  // n = scenes
                        {
                            Log.Info("Node.name: " + n.name);
                            if (n.name != "Hidden" && n.name != "ButtonIDs")
                            {
                                foreach (var n1 in n.GetNodes())
                                {
                                    foreach (var n2 in n1.GetNodes())
                                    {
                                        cfg            = new Cfg();
                                        cfg.scene      = (GameScenes)Enum.Parse(typeof(GameScenes), n2.GetValue("scene"));
                                        cfg.blocktype  = (Blocktype)Enum.Parse(typeof(Blocktype), n2.GetValue("blocktype"));
                                        cfg.buttonHash = n2.GetValue("buttonHash");
                                        cfg.folderIcon = System.Int32.Parse(n1.GetValue("folderIcon"));

                                        cfg.toolbarButtonHash  = n1.name;
                                        cfg.toolbarButtonIndex = cfg.folderIcon;
                                        loadedCfgs.Add(cfg.scene + cfg.buttonHash, cfg);
                                    }
                                }
                            }
                            else
                            {
                                if (n.name == "ButtonIDs")
                                {
                                    Log.Info("Loading ButtonIDs");
                                    // int cnt = 1;
                                    foreach (ConfigNode.Value n2 in n.values)
                                    {
                                        string hash = n2.name;
                                        string data = n2.value;
                                        Log.Info("hash: " + hash + "   data: " + data);
                                        var b = JanitorsCloset.Instance.buttonIdBDI(hash);
                                        if (b != null)
                                        {
                                            b.identifier = data;
                                        }
                                        else
                                        {
                                            b            = new ButtonDictionaryItem();
                                            b.identifier = data;
                                            b.buttonHash = hash;
                                            b.button     = new ApplicationLauncherButton();
                                            // b.button.name = cnt.ToString();
                                            //   cnt++;
                                            JanitorsCloset.buttonDictionary.Add(b.button, b);
                                        }
                                    }
                                }
                                if (n.name == "Hidden")
                                {
                                    // Hidden

                                    ButtonSceneBlock bsb;
                                    Log.Info("Loading Hidden");

                                    foreach (var n2 in n.GetNodes())
                                    {
                                        bsb            = new ButtonSceneBlock();
                                        bsb.scene      = (GameScenes)Enum.Parse(typeof(GameScenes), n2.GetValue("scene"));
                                        bsb.blocktype  = (Blocktype)Enum.Parse(typeof(Blocktype), n2.GetValue("blocktype"));
                                        bsb.buttonHash = n2.GetValue("buttonHash");
                                        bsb.active     = Boolean.Parse(n2.GetValue("active"));
                                        Log.Info("hidden button: " + bsb.buttonHash + "  blocktype: " + bsb.blocktype.ToString());
                                        if (bsb.blocktype == Blocktype.hideHere)
                                        {
                                            loadedHiddenCfgs.Add(bsb.buttonHash + bsb.scene.ToString(), bsb);
                                        }
                                        else
                                        {
                                            loadedHiddenCfgs.Add(bsb.buttonHash, bsb);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }