Beispiel #1
0
        //------------------------------------------------------------
        // Force to reload the locale manager
        //------------------------------------------------------------
        private void resetLocaleManager(String loc_name)
        {
            // Reload Locale Manager
            ColossalFramework.Globalization.LocaleManager.ForceReload();

            string[] locales = ColossalFramework.Globalization.LocaleManager.instance.supportedLocaleIDs;
            for (int i = 0; i < locales.Length; i++)
            {
                                #if (DEBUG)
                DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, String.Format("Locale index: {0}, ID: {1}", i, locales[i]));
                                #endif
                if (locales[i].Equals(loc_name))
                {
                                        #if (DEBUG)
                    DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, String.Format("Find locale {0} at index: {1}", loc_name, i));
                                        #endif
                    ColossalFramework.Globalization.LocaleManager.instance.LoadLocaleByIndex(i);

                    //thanks to: https://github.com/Mesoptier/SkylineToolkit/commit/d33f0bae67662df25bdf8ee2170d95a6999c3721
                    ColossalFramework.SavedString lang_setting = new ColossalFramework.SavedString("localeID", "gameSettings");
                                        #if (DEBUG)
                    DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, String.Format("Current Language Setting: {0}", lang_setting.value));
                                        #endif
                    lang_setting.value = locale_name;
                    ColossalFramework.GameSettings.SaveAll();
                    break;
                }
            }
        }
        /* Hi!  I commented the hell out of this, making sure it's as straightforward as I could muster.
         *
         * This is a very basic mod.  However, the locations for most of the methods used in this will be important
         * for quite a lot of things.  UIComponent and UIView in particular contain a whole hell of a lot of important things.
         *
         * This is over-documented to hell.  As I'm starting out, I'm trying to break things down as much as possible,
         * mostly for my own benefit.  I tend to go cross-eyed going back and forth between code.
         *
         * Most of this mod is making the button, and I used the following method to create the button:
         * http://www.reddit.com/r/CitiesSkylinesModding/comments/2ymwxe/example_code_using_the_colossal_ui_in_a_user_mod/
         * So don't give me credit for that, kay? Kay.
         *
         * The three lines of code that make the mod do the important thing took forever for me to track down. ;_;
         *
         * You're beautiful and I love you.
         */
        public override void OnLevelLoaded(LoadMode mode)
        {
            // Create the button and make it appear on the screen.
            // UIView seems to be what is used to enable whatever element should be appearing.
            // Without it, it seems like that element will never show up.

            var boxuiView = UIView.GetAView();
            var statButton = (UIButton)boxuiView.AddUIComponent(typeof(UIButton));

            // This does more stuff.  Y'know.  Stuuuuuff.

            var uiView = GameObject.FindObjectOfType<UIView>();
            if (uiView == null) return;

            // Define how big the button is!
            // It's come to my attention that this may not display correctly in non-16:9 resolutions.
            // I'll figure it out after I actually play video games for awhile.

            statButton.width = 125;
            statButton.height = 30;

            // Defines the colors and such of the button.  Fancy!
            // The color values for statButton.textColor are that blue-ish color used on the UI to show your cash and population.
            // Seemed right to also use that for my buttons.  Everything looking uniform is cool.

            statButton.normalBgSprite = "ButtonMenu";
            statButton.hoveredBgSprite = "ButtonMenuHovered";
            statButton.focusedBgSprite = "ButtonMenuFocused";
            statButton.pressedBgSprite = "ButtonMenuPressed";
            //statButton.textColor = new Color32(255, 255, 255, 255);
            statButton.textColor = new Color32(186, 217, 238, 0);
            statButton.disabledTextColor = new Color32(7, 7, 7, 255);
            statButton.hoveredTextColor = new Color32(7, 132, 255, 255);
            statButton.focusedTextColor = new Color32(255, 255, 255, 255);
            statButton.pressedTextColor = new Color32(30, 30, 44, 255);

            // .transformPosition places where the button will show up on the screen.  Vector3 uses x/y.  You can also set a Z coordinate but why would you do that here?
            // I am not terribly good at stuff like vectors, so honestly, I've just been punching in numbers until it looks right.
            // Look, I'm not here to judge.

            // BringToFront does exactly what you'd expect. It's part of the ColossalFramework.UI.UIComponent class.
            // Without it, the button would end up behind the rest of the UI.
            // Chances are when I go in to make sure buttons are displaying right at 16:10
            // I'll have to do something with that.

            statButton.transformPosition = new Vector3(1.2f, -0.93f);
            statButton.BringToFront();

            ColossalFramework.SavedString lang_setting = new ColossalFramework.SavedString("localeID", "gameSettings");
            // Mmhm.  You know what this does.
            switch (lang_setting.value) {
            case "bg":
                statButton.text = "Статистики за града";
                break;
            case "de":
                statButton.text = "Stadt-statistiken";
                break;
            case "es":
                statButton.text = "Estadísticas de la ciudad";
                break;
            case "fr":
                statButton.text = "Statistiques de la ville";
                break;
            case "it":
                statButton.text = "Statistiche della città";
                break;
            case "nl":
                statButton.text = "Stadsstatistieken";
                break;
            case "pl":
                statButton.text = "Statistiki miasta";
                break;
            case "pt":
                statButton.text = "Estatísicas da cidade";
                break;
            case "ru":
                statButton.text = "Показатели города";
                break;
            default:
                statButton.text = "City Statistics";
                break;
            }

            // Points the button towards the logic needed for the button to do stuff.

            statButton.eventClick += ButtonClick;
        }