예제 #1
0
 private void ConfigOptions_ButtonClicked(object sender, ButtonClickedEventArgs e)
 {
     if (e.Id == "OpenDecorationsModConfigurator")
     {
         ConfigSwitcher.OpenDecorationsModConfigurator = !ConfigSwitcher.OpenDecorationsModConfigurator;
         // If button state changed
         if (ConfigSwitcher.OpenConfiguratorLastState != ConfigSwitcher.OpenDecorationsModConfigurator)
         {
             // Update button state
             ConfigSwitcher.OpenConfiguratorLastState = ConfigSwitcher.OpenDecorationsModConfigurator;
             // Open configurator
             string configuratorPath = ConfiguratorPath();
             if (File.Exists(configuratorPath))
             {
                 // Try launch configurator
                 try { Configurator = Process.Start(new ProcessStartInfo {
                         Arguments = "/C \"" + configuratorPath + "\"", FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden
                     }); }
                 catch (Exception ex)
                 {
                     // Cleanup any running instance on failure
                     if (Configurator != null)
                     {
                         if (!Configurator.HasExited)
                         {
                             try { Configurator.CloseMainWindow(); }
                             catch { }
                         }
                         try { Configurator.Close(); }
                         catch { }
                     }
                     // Log error
                     Logger.Log("ERROR: Unable to open configurator. Exception=[" + ex.ToString() + "]");
                     MenuMessageHelper.AddMessage("Could not open configurator. Try to open it from DecorationsMod folder or edit Config text file manually.", "orange", 22);
                 }
             }
         }
     }
 }
예제 #2
0
        public void ConfigOptions_GameObjectCreated(object sender, GameObjectCreatedEventArgs e)
        {
            GameObject go = e.GameObject;

            if (e.Id == "OpenDecorationsModConfigurator" && go != null)
            {
                uGUI_TabbedControlsPanel tcp = null;
                try { tcp = go.transform.parent.parent.parent.parent.parent.GetComponent <uGUI_TabbedControlsPanel>(); }
                catch { tcp = null; }
                if (tcp != null)
                {
                    ICollection tabs = _tabsField.GetValue(tcp) as ICollection;
                    if (tabs != null)
                    {
                        IEnumerator enumerator = tabs.GetEnumerator();
                        if (enumerator != null)
                        {
                            int i = 0;
                            // Iterate through each panel tabs
                            while (enumerator.MoveNext())
                            {
                                object     currentTab = enumerator.Current;
                                GameObject pane       = (GameObject)_paneField.GetValue(currentTab);
                                GameObject tab        = (GameObject)_tabField.GetValue(currentTab);
                                OpenConfiguratorBtnContainer = (RectTransform)_containerField.GetValue(currentTab);
                                if (pane != null && tab != null && OpenConfiguratorBtnContainer != null)
                                {
                                    Text paneText = pane.GetComponentInChildren <Text>();
                                    Text tabText  = tab.GetComponentInChildren <Text>();
                                    // If current panel is "QModManager" and current tab is "Mods"
                                    if (paneText != null && string.Compare(paneText.text, "QModManager", false, CultureInfo.InvariantCulture) == 0 &&
                                        tabText != null && string.Compare(tabText.text, "Mods", false, CultureInfo.InvariantCulture) == 0)
                                    {
                                        // Detroy toggle
                                        GameObject.DestroyImmediate(go);
                                        // Add button
                                        tcp.AddButton(i, LanguageHelper.GetFriendlyWord("Config_OpenDecorationsModConfigurator"), new UnityEngine.Events.UnityAction(() => {
                                            ConfigSwitcher.OpenDecorationsModConfigurator = !ConfigSwitcher.OpenDecorationsModConfigurator;
                                            // If button state changed
                                            if (ConfigSwitcher.OpenConfiguratorLastState != ConfigSwitcher.OpenDecorationsModConfigurator)
                                            {
                                                // Update button state
                                                ConfigSwitcher.OpenConfiguratorLastState = ConfigSwitcher.OpenDecorationsModConfigurator;
                                                // Open configurator
                                                string configuratorPath = ConfiguratorPath();
                                                if (File.Exists(configuratorPath))
                                                {
                                                    // Try launch configurator
                                                    try { Configurator = Process.Start(new ProcessStartInfo {
                                                            Arguments = "/C \"" + configuratorPath + "\"", FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden
                                                        }); }
                                                    catch (Exception ex)
                                                    {
                                                        // Cleanup any running instance on failure
                                                        if (Configurator != null)
                                                        {
                                                            if (!Configurator.HasExited)
                                                            {
                                                                try { Configurator.CloseMainWindow(); }
                                                                catch { }
                                                            }
                                                            try { Configurator.Close(); }
                                                            catch { }
                                                        }
                                                        // Log error
                                                        Logger.Log("ERROR: Unable to open configurator. Exception=[" + ex.ToString() + "]");
                                                    }
                                                }
                                                // Apply "deselected" style to button
                                                foreach (Transform tr in OpenConfiguratorBtnContainer)
                                                {
                                                    // If current transform is GUI button
                                                    if (tr != null && !string.IsNullOrEmpty(tr.name) && tr.name.StartsWith("uGUI_OptionButton"))
                                                    {
                                                        Text btnText = tr.GetComponentInChildren <Text>();
                                                        if (btnText != null && !string.IsNullOrEmpty(btnText.text) &&
                                                            (string.Compare(btnText.text, "Cliquez ici pour configurer", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Haga clic aquí para configurar", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Yapılandırmak için burayı tıklayın", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Klicken Sie hier zum Konfigurieren", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Нажмите здесь, чтобы настроить", true, CultureInfo.InvariantCulture) == 0 ||
                                                             string.Compare(btnText.text, "Click here to configure", true, CultureInfo.InvariantCulture) == 0))
                                                        {
                                                            // Deselect button
                                                            Button btn = tr.GetComponentInChildren <Button>();
                                                            if (btn != null)
                                                            {
                                                                btn.OnDeselect(null);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }));
                                        break;
                                    }
                                }
                                ++i;
                            }
                        }
                    }
                }
            }
        }