Exemplo n.º 1
0
        private void MoveDown()
        {
            if (currentActMods != -1 && currentActMods != m_ActivatedMods.Count - 1)
            {
                m_ActivatedMods.Insert(currentActMods + 1, m_ActivatedMods[currentActMods]);
                m_ActivatedMods.RemoveAt(currentActMods);

                ModManager.ModsConfig ModsConfig = (ModManager.ModsConfig)ModsConfig_FieldInfo.GetValue(new ModManager());
                ModsConfig.EnabledMod.Insert(currentActMods + 1, ModsConfig.EnabledMod[currentActMods]);
                ModsConfig.EnabledMod.RemoveAt(currentActMods);
                ModsConfig_FieldInfo.SetValue(null, ModsConfig);
                currentActMods++;
            }
        }
Exemplo n.º 2
0
        private void MoveUp()
        {
            if (currentActMods > 0)
            {
                m_ActivatedMods.Insert(currentActMods - 1, m_ActivatedMods[currentActMods]);
                m_ActivatedMods.RemoveAt(currentActMods + 1);

                ModManager.ModsConfig ModsConfig = (ModManager.ModsConfig)ModsConfig_FieldInfo.GetValue(new ModManager());
                ModsConfig.EnabledMod.Insert(currentActMods - 1, ModsConfig.EnabledMod[currentActMods]);
                ModsConfig.EnabledMod.RemoveAt(currentActMods + 1);
                ModsConfig_FieldInfo.SetValue(null, ModsConfig);
                currentActMods--;
            }
        }
Exemplo n.º 3
0
        public void Save()
        {
            IsChange = false;
            Saved    = true;

            ModManager.ModsConfig ModsConfig = (ModManager.ModsConfig)ModsConfig_FieldInfo.GetValue(new ModManager());
            ModsConfig.Save();
            foreach (var i in ModManager.EnabledModEntries)
            {
                if (i.SaveMethod != null)
                {
                    i.SaveMethod(i, null);
                }
            }
            ScreenManager.AddScreen(MessageBox_NeedClosedGame, ScreenManager.controllingPlayer);
        }
Exemplo n.º 4
0
        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            PostProcessor.begin();
            ScreenManager.FadeBackBufferToBlack(255);
            GuiData.startDraw();
            PatternDrawer.draw(new Rectangle(0, 0, ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height), 0.5f, Color.Black, new Color(2, 2, 2), GuiData.spriteBatch);
            if (Button.doButton("Back".GetHashCode(), 10, 10, 220, 30, "<- " + LocaleTerms.Loc("Back"), Color.Gray))
            {
                if (IsChange && !Saved)
                {
                    ScreenManager.AddScreen(MessageBox_NeedSave, ScreenManager.controllingPlayer);
                }
                SettingsLoader.writeStatusFile();
                ExitScreen();
            }
            if (Button.doButton("Save".GetHashCode(), 10, 45, 220, 30, "ModsCore.Mods.Save".Translate(), Color.Blue))
            {
                Save();
            }

            TextItem.doLabel(new Vector2(75, 100), $"Mods ({"ModsCore.Mods.Activate".Translate()})", null, 300);

            //打开了Setting界面不允许修改选定的Mod
            if (OpenSettingUI)
            {
                SelectableTextList.doFancyList(25, 50, 140, 300, ScreenManager.GraphicsDevice.Viewport.Height - 190, m_ActivatedMods.ToArray(), currentActMods, Color.White);
            }
            else
            {
                currentActMods = SelectableTextList.doFancyList(25, 50, 140, 300, ScreenManager.GraphicsDevice.Viewport.Height - 50, m_ActivatedMods.ToArray(), currentActMods, Color.White);
            }

            if (OpenSettingUI && Button.doButton("CloseSettingUI".GetHashCode(), 400, 210, 150, 30, "ModsCore.Mods.CloseSettingUI".Translate(), Color.BlueViolet))
            {
                OpenSettingUI = false;
            }
            if (currentActMods > 0 && Button.doButton("Up".GetHashCode(), 400, 250, 150, 30, "ModsCore.Mods.Up".Translate(), Color.BlueViolet))
            {
                MoveUp();
                IsChange = true;
                Saved    = false;
            }
            if (currentActMods >= 0 && currentActMods != m_ActivatedMods.Count - 1 && Button.doButton("Down".GetHashCode(), 400, 290, 150, 30, "ModsCore.Mods.Down".Translate(), Color.BlueViolet))
            {
                MoveDown();
                IsChange = true;
                Saved    = false;
            }
            if (!OpenSettingUI && currentActMods != -1 && Button.doButton("OpenSettingUI".GetHashCode(), 400, 210, 150, 30, "ModsCore.Mods.OpenSettingUI".Translate(), Color.BlueViolet))
            {
                OpenSettingUI = true;
            }

            if (currentActMods >= 0 && Button.doButton("DeactivateMod".GetHashCode(), 400, 330, 150, 30, "ModsCore.Mods.DeactivateMod".Translate(), Color.BlueViolet))
            {
                IsChange = true;
                Saved    = false;
                m_DeactivatedMods.Add(m_ActivatedMods[currentActMods]);
                m_DeactDicModModEntries.Add(m_ActivatedMods[currentActMods].GetHashCode(), m_ActDicModEntries[m_ActivatedMods[currentActMods].GetHashCode()]);
                m_ActDicModEntries.Remove(m_ActivatedMods[currentActMods].GetHashCode());
                m_ActivatedMods.RemoveAt(currentActMods);

                ModManager.ModsConfig ModsConfig = (ModManager.ModsConfig)ModsConfig_FieldInfo.GetValue(new ModManager());
                ModsConfig.EnabledMod.RemoveAt(currentActMods);
                ModsConfig_FieldInfo.SetValue(null, ModsConfig);
                currentDeactMods = m_DeactivatedMods.Count - 1;
                currentActMods   = -1;
            }

            if (!OpenSettingUI && currentDeactMods >= 0 && Button.doButton("ActivateMod".GetHashCode(), 400, 370, 150, 30, "ModsCore.Mods.ActivateMod".Translate(), Color.BlueViolet))
            {
                IsChange = true;
                Saved    = false;
                m_ActivatedMods.Add(m_DeactivatedMods[currentDeactMods]);
                m_ActDicModEntries.Add(m_DeactivatedMods[currentDeactMods].GetHashCode(), m_DeactDicModModEntries[m_DeactivatedMods[currentDeactMods].GetHashCode()]);


                ModManager.ModsConfig ModsConfig = (ModManager.ModsConfig)ModsConfig_FieldInfo.GetValue(new ModManager());
                ModsConfig.EnabledMod.Add(Path.GetFileName(m_DeactDicModModEntries[m_DeactivatedMods[currentDeactMods].GetHashCode()].Path));
                ModsConfig_FieldInfo.SetValue(null, ModsConfig);

                m_DeactDicModModEntries.Remove(m_DeactivatedMods[currentDeactMods].GetHashCode());
                m_DeactivatedMods.RemoveAt(currentDeactMods);
                currentActMods   = m_ActivatedMods.Count - 1;
                currentDeactMods = -1;
            }

            if (OpenSettingUI && m_ActDicModEntries[m_ActivatedMods[currentActMods].GetHashCode()].Started && m_ActDicModEntries[m_ActivatedMods[currentActMods].GetHashCode()].DrawSettingUIMethod != null)
            {
                RenderedRectangle.doRectangleOutline(570, 100, ScreenManager.GraphicsDevice.Viewport.Width - 50 - 570, ScreenManager.GraphicsDevice.Viewport.Height - 100 - 50, 2, Color.White);
                m_ActDicModEntries[m_ActivatedMods[currentActMods].GetHashCode()].DrawSettingUIMethod(m_ActDicModEntries[m_ActivatedMods[currentActMods].GetHashCode()], new object[] { ScreenManager, 575, 100, ScreenManager.GraphicsDevice.Viewport.Width - 50 - 570, ScreenManager.GraphicsDevice.Viewport.Height - 100 - 50 });
            }
            else
            {
                TextItem.doLabel(new Vector2(600, 100), $"Mods ({"ModsCore.Mods.Deactivate".Translate()})", null, 300);
                currentDeactMods = SelectableTextList.doFancyList(25, 575, 140, 300, ScreenManager.GraphicsDevice.Viewport.Height - 50, m_DeactivatedMods.ToArray(), currentDeactMods, null);
            }
            GuiData.endDraw();
            PostProcessor.end();
        }
Exemplo n.º 5
0
        public ModsMenu()
        {
            //初始化 m_ActivatedMods 与 dicModEntries
            if (m_ActivatedMods == null || m_ActDicModEntries == null)
            {
                m_ActivatedMods    = new List <string>();
                m_ActDicModEntries = new Dictionary <int, ModManager.ModEntry>();
                foreach (var i in ModManager.EnabledModEntries)
                {
                    m_ActivatedMods.Add($"{i.Info.DisplayName} (Id:{i.Info.Id})");
                    m_ActDicModEntries.Add($"{i.Info.DisplayName} (Id:{i.Info.Id})".GetHashCode(), i);
                }
            }

            //初始化 MessageBox_NeedSave
            if (MessageBox_NeedSave == null)
            {
                MessageBox_NeedSave = Main.ShowMessageBox("ModsCore.Mods.EscMes".Translate(),
                                                          "ModsCore.Mods.Save".Translate(), "ModsCore.Mods.Cancel".Translate(),
                                                          Save);
            }

            //初始化 MessageBox_ClosedGame
            if (MessageBox_NeedClosedGame == null)
            {
                MessageBox_NeedClosedGame = Main.ShowMessageBox("ModsCore.Mods.ClosedGame".Translate(),
                                                                "ModsCore.Mods.Closed".Translate(), "ModsCore.Mods.Cancel".Translate(), delegate {
                    MusicManager.stop();
                    Game1.threadsExiting = true;
                    Game1.getSingleton().Exit();
                });
            }

            //初始化 ModsConfig_FieldInfo
            if (ModsConfig_FieldInfo == null)
            {
                ModsConfig_FieldInfo = typeof(ModManager).GetField("m_ModsConfig", BindingFlags.NonPublic | BindingFlags.Static);
            }

            //初始化 m_DeactivatedMods
            try
            {
                if (m_DeactivatedMods == null || m_DeactDicModModEntries == null)
                {
                    ModManager.ModsConfig ModsConfig = (ModManager.ModsConfig)ModsConfig_FieldInfo.GetValue(new ModManager());
                    m_DeactivatedMods       = new List <string>();
                    m_DeactDicModModEntries = new Dictionary <int, ModManager.ModEntry>();

                    DirectoryInfo      directoryInfo = new DirectoryInfo(ModManager.ModsPath);
                    ModManager.ModInfo modInfo;
                    foreach (var i in directoryInfo.GetDirectories())
                    {
                        foreach (var path in ModsConfig.EnabledMod)
                        {
                            if (path == i.Name)
                            {
                                goto Continue_End;
                            }
                        }

                        modInfo = JsonConvert.DeserializeObject <ModManager.ModInfo>(File.ReadAllText(Path.Combine(i.FullName, "Info.json")));
                        if (string.IsNullOrEmpty(modInfo.Id))
                        {
                            goto Continue_End;
                        }

                        m_DeactivatedMods.Add($"{modInfo.DisplayName} (Id:{modInfo.Id})");
                        m_DeactDicModModEntries.Add($"{modInfo.DisplayName} (Id:{modInfo.Id})".GetHashCode(), new ModManager.ModEntry(modInfo, i.FullName));

                        Continue_End :;
                    }
                }
            }
            catch (Exception ex)
            {
                Main.Logger.Error(ex.ToString());
            }
        }