Пример #1
0
        /// <summary>
        /// Initialize our ThemeCreator by patching all Form constructors so that we can inject our colors changes.
        /// </summary>
        /// <param name="harmony"></param>
        protected override void Loaded(Harmony harmony)
        {
            LogInfo("Loading ThemeCreator...");
            HarmonyMethod formConstructorPostfixMethod = new HarmonyMethod(GetType().GetMethod("FormConstructorPostfix", AccessTools.all));

            foreach (var form in AuroraAssembly.GetTypes().Where(t => typeof(Form).IsAssignableFrom(t)))
            {
                try
                {
                    foreach (var ctor in form.GetConstructors())
                    {
                        harmony.Patch(ctor, postfix: formConstructorPostfixMethod);
                    }
                }
                catch (Exception e)
                {
                    LogError($"ThemeCreator failed to patch Form constructor {form.Name}, exception: {e}");
                }
            }
            HarmonyMethod graphicsDrawEllipsePrefixMethod = new HarmonyMethod(GetType().GetMethod("GraphicsDrawEllipsePrefix", AccessTools.all));
            HarmonyMethod graphicsFillEllipsePrefixMethod = new HarmonyMethod(GetType().GetMethod("GraphicsFillEllipsePrefix", AccessTools.all));
            HarmonyMethod graphicsDrawStringPrefixMethod  = new HarmonyMethod(GetType().GetMethod("GraphicsDrawStringPrefix", AccessTools.all));
            HarmonyMethod graphicsDrawLinePrefixMethod    = new HarmonyMethod(GetType().GetMethod("GraphicsDrawLinePrefix", AccessTools.all));

            foreach (var graphics in typeof(Graphics).Assembly.GetTypes().Where(t => typeof(Graphics).IsAssignableFrom(t)))
            {
                try
                {
                    foreach (var method in graphics.GetMethods(AccessTools.all))
                    {
                        if (method.Name == "DrawEllipse")
                        {
                            harmony.Patch(method, prefix: graphicsDrawEllipsePrefixMethod);
                        }
                        else if (method.Name == "FillEllipse")
                        {
                            harmony.Patch(method, prefix: graphicsFillEllipsePrefixMethod);
                        }
                        else if (method.Name == "DrawString")
                        {
                            harmony.Patch(method, prefix: graphicsDrawStringPrefixMethod);
                        }
                        else if (method.Name == "DrawLine")
                        {
                            harmony.Patch(method, prefix: graphicsDrawLinePrefixMethod);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogError($"ThemeCreator failed to patch graphics draw/fill ellipse methods for {graphics.Name}, exception: {e}");
                }
            }
            // Need a work-around for the toolbar buttons resetting colors every time increment.
            lib = GetDependency <Lib.Lib>("Lib");
            lib.RegisterEventHandler(AuroraType.TacticalMapForm, "Click", GetType().GetMethod("CustomButtonClickTacticalMap", AccessTools.all), control => typeof(Button).IsAssignableFrom(control.GetType()));
            lib.RegisterEventHandler(AuroraType.GalacticMapForm, "Click", GetType().GetMethod("CustomButtonClickGalacticMap", AccessTools.all), control => typeof(Button).IsAssignableFrom(control.GetType()));
        }
Пример #2
0
        protected override void Loaded(Harmony harmony)
        {
            LogInfo("Loading ResizeWindows...");
            HarmonyMethod formConstructorPostfixMethod = new HarmonyMethod(GetType().GetMethod("FormConstructorPostfix", AccessTools.all));

            foreach (var form in AuroraAssembly.GetTypes().Where(t => typeof(Form).IsAssignableFrom(t)))
            {
                try
                {
                    foreach (var ctor in form.GetConstructors())
                    {
                        harmony.Patch(ctor, postfix: formConstructorPostfixMethod);
                    }
                }
                catch (Exception e)
                {
                    LogError($"ResizeWindows failed to patch Form constructor {form.Name}, exception: {e}");
                }
            }
        }
Пример #3
0
        protected override void Loaded(Harmony harmony)
        {
            Instance         = this;
            KnowledgeBase    = new KnowledgeBase(this);
            SignatureManager = new SignatureManager(this);
            UIManager        = new UIManager(this);

            foreach (var form in AuroraAssembly.GetTypes().Where(t => typeof(Form).IsAssignableFrom(t)))
            {
                try
                {
                    var ctor   = (MethodBase)form.GetMember(".ctor", AccessTools.all)[0];
                    var method = new HarmonyMethod(GetType().GetMethod("PostfixFormConstructor", AccessTools.all));
                    harmony.Patch(ctor, null, method);
                }
                catch (Exception e)
                {
                    LogError($"Failed to patch Form constructor {form.Name}, exception: {e}");
                }
            }
        }
Пример #4
0
        protected override void Loaded(Harmony harmony)
        {
            lib = GetDependency <Lib.Lib>("Lib");

            // Buttons
            ThemeCreator.ThemeCreator.AddColorChange(
                typeof(Button),
                new ThemeCreator.ColorChange {
                BackgroundColor = buttonBackgroundColor
            }
                );

            lastActiveTimeIncrement = lib.KnowledgeBase.GetButtonName(AuroraButton.Increment);
            activeSubPulse          = lib.KnowledgeBase.GetButtonName(AuroraButton.SubPulse);

            ThemeCreator.ThemeCreator.AddFontChange(mainFont);
            ThemeCreator.ThemeCreator.AddFontChange(typeof(Button), buttonFont);

            // Use slightly different text box font size for better alignment and to fix some
            // overflow issues in System view form ("Specify Minerals" feature in SM mode).
            ThemeCreator.ThemeCreator.AddFontChange((Control control) =>
            {
                return(control.GetType() == typeof(TextBox) && !((TextBox)control).Multiline);
            }, singleLineTextBoxFont);

            ThemeCreator.ThemeCreator.SetCometTailColor(orbitColor);
            ThemeCreator.ThemeCreator.SetPlanetColor(planetColor);

            ThemeCreator.ThemeCreator.DrawEllipsePrefixAction((graphics, pen) =>
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;

                // Note that the same color circles are used to mark colonies as well, not just orbits
                if (pen.Color == oldOrbitColor)
                {
                    pen.Color = orbitColor;
                }
            });

            ThemeCreator.ThemeCreator.FillEllipsePrefixAction((graphics, brush) =>
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;

                if (brush.GetType() == typeof(SolidBrush))
                {
                    var solidBrush = brush as SolidBrush;

                    // This is being overriden by global color contructor hook, but we want to keep
                    // the old yellow color for player contacts, so restore.
                    if (solidBrush.Color == mainTextColor)
                    {
                        solidBrush.Color = oldPlayerContactColor;
                    }
                }
            });

            ThemeCreator.ThemeCreator.DrawLinePrefixAction((graphics, pen) =>
            {
                graphics.SmoothingMode = SmoothingMode.AntiAlias;

                // Movement tails
                if (pen.Color == oldCivilianContactColor || pen.Color == oldHostileContactColor ||
                    pen.Color == mainTextColor || pen.Color == oldNeutralContactColor)
                {
                    // Restore player contact movement tail color to the old yellow one (was overriden
                    // by global color contructor hook).
                    var newColor = pen.Color == mainTextColor ? oldPlayerContactColor : pen.Color;

                    pen.Color = ControlPaint.Dark(newColor, 0.5f);
                }
                // Comet path (distance ruler also uses the same color but has pen.Width > 1)
                else if (pen.Color == oldCometPathColor && pen.Width == 1)
                {
                    pen.Color = orbitColor;
                }
            });

            ThemeCreator.ThemeCreator.DrawStringPrefixAction((graphics, s, font, brush) =>
            {
                if (brush.GetType() == typeof(SolidBrush))
                {
                    var solidBrush = brush as SolidBrush;

                    if (solidBrush.Color == oldPlayerContactColor)
                    {
                        solidBrush.Color = mainTextColor;
                    }
                }
            });

            // Toolbar button images
            ChangeButtonStyle(AuroraButton.ZoomIn, Resources.Icon_ZoomIn, mainTextColor);
            ChangeButtonStyle(AuroraButton.ZoomOut, Resources.Icon_ZoomOut, mainTextColor);
            ChangeButtonStyle(AuroraButton.Up, Resources.Icon_Up, mainTextColor);
            ChangeButtonStyle(AuroraButton.Down, Resources.Icon_Down, mainTextColor);
            ChangeButtonStyle(AuroraButton.Left, Resources.Icon_Left, mainTextColor);
            ChangeButtonStyle(AuroraButton.Right, Resources.Icon_Right, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarColony, Resources.Icon_Colony, mainTextColor, economicsButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarIndustry, Resources.Icon_Industry, mainTextColor, economicsButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarMining, Resources.Icon_Mining, mainTextColor, economicsButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarResearch, Resources.Icon_Research, mainTextColor, economicsButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarWealth, Resources.Icon_Wealth, mainTextColor, economicsButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarClass, Resources.Icon_Class, mainTextColor, designButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarProject, Resources.Icon_Project, mainTextColor, designButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarFleet, Resources.Icon_Fleet, mainTextColor, fleetButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarMissileDesign, Resources.Icon_MissileDesign, mainTextColor, designButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarTurrent, Resources.Icon_Turrent, mainTextColor, designButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarGroundForces, Resources.Icon_GroundForces, mainTextColor, groundForcesButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarCommanders, Resources.Icon_Commanders, mainTextColor, personnelButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarMedals, Resources.Icon_Medals, mainTextColor, personnelButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarRace, Resources.Icon_Race, mainTextColor, intelligenceButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarSystem, Resources.Icon_System, mainTextColor, explorationButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarGalactic, Resources.Icon_Galactic, mainTextColor, explorationButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarHabitable, Resources.Icon_Galactic, mainTextColor, explorationButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarComparison, Resources.Icon_Comparison, mainTextColor, intelligenceButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarIntelligence, Resources.Icon_Intelligence, mainTextColor, intelligenceButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarTechnology, Resources.Icon_Technology, mainTextColor, technologyButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarSurvey, Resources.Icon_Survey, mainTextColor, surveyButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarSector, Resources.Icon_Sector, mainTextColor, sectorButtonBackgroundColor);
            ChangeButtonStyle(AuroraButton.ToolbarEvents, Resources.Icon_Events, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarRefreshTactical, Resources.Icon_Refresh, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarRefreshGalactic, Resources.Icon_Refresh, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarSave, Resources.Icon_Save, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarGame, Resources.Icon_Game, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarGrid, Resources.Icon_Grid, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarUndo, Resources.Icon_Undo, mainTextColor);
            ChangeButtonStyle(AuroraButton.ToolbarSavePositions, Resources.Icon_SavePositions, mainTextColor);

            var colorConstructorPostfix = new HarmonyMethod(GetType().GetMethod("ColorConstructorPostfix", AccessTools.all));

            // Patch all Color.FromArgb overloads for color overrides
            foreach (var method in typeof(Color).GetMethods(AccessTools.all))
            {
                if (method.Name == "FromArgb")
                {
                    harmony.Patch(method, postfix: colorConstructorPostfix);
                }
            }

            // Also hook into some predefined/named color properties
            harmony.Patch(typeof(Color).GetMethod("get_LightGray"), postfix: colorConstructorPostfix);

            // Hook into Aurora forms constructors for some more advanced overrides
            var formConstructorPostfix = new HarmonyMethod(GetType().GetMethod("FormConstructorPostfix", AccessTools.all));

            foreach (var form in AuroraAssembly.GetTypes().Where(t => typeof(Form).IsAssignableFrom(t)))
            {
                foreach (var ctor in form.GetConstructors())
                {
                    harmony.Patch(ctor, postfix: formConstructorPostfix);
                }
            }
        }