Exemplo n.º 1
0
 public static void PerformSaveFileLoad()
 {
     System.IO.File.WriteAllText(GenFilePaths.FilePathForSavedGame(m_sfd.partial_name), m_sfd.tcontext);
     ThingFilterPatch.avoidThingFilterUsage = true;
     GameDataSaveLoader.LoadGame(m_sfd.partial_name);
     ThingFilterPatch.avoidThingFilterUsage = false;
 }
Exemplo n.º 2
0
        public static void SaveTemplate(WorldTemplate template)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(WorldTemplate));

            string folderName = Path.Combine(TemplateFolder, template.WorldName);
            string infoFile   = Path.Combine(folderName, "info.xml");

            if (File.Exists(infoFile))
            {
                File.Delete(infoFile);
            }

            string saveName = $"{template.WorldName}";
            string savePath = Path.Combine(folderName, saveName);

            template.FilePath = $"{TemplateFolderName}\\{template.WorldName}\\{template.WorldName}";

            Directory.CreateDirectory(folderName);

            using (FileStream fs = new FileStream(infoFile, FileMode.OpenOrCreate))
            {
                serializer.Serialize(fs, template);
            }

            StartPawnsFromTemplate.StartPawns = template.StartPawns;

            GameDataSaveLoader.SaveGame(savePath);

            Messages.Message("Tempalte has been created", MessageTypeDefOf.PositiveEvent, false);
        }
Exemplo n.º 3
0
        public static void DeactivateMod()
        {
            _isDeactivating = true;

            ModsConfig.SetActive(Mod.ContentPack.Identifier, false);

            var runningMods = PrivateAccess.Verse_LoadedModManager_RunningMods();

            runningMods.Remove(Mod.ContentPack);

            var addonMods = new StringBuilder();

            foreach (var mod in AddonManager.Mods)
            {
                addonMods.AppendLine(mod.Name);
                ModsConfig.SetActive(mod.Identifier, false);
                runningMods.Remove(mod);
            }

            ModsConfig.Save();

            if (Find.WorldObjects.Contains(Instance))
            {
                Find.WorldObjects.Remove(Instance);
            }

            const string saveName = "PawnRules_Removed";

            GameDataSaveLoader.SaveGame(saveName);

            var message = addonMods.Length > 0 ? Lang.Get("Button.RemoveModAndAddonsComplete", saveName.Bold(), addonMods.ToString()) : Lang.Get("Button.RemoveModComplete", saveName.Bold());

            Find.WindowStack.Add(new Dialog_Alert(message, Dialog_Alert.Buttons.Ok, GenCommandLine.Restart));
        }
Exemplo n.º 4
0
        public static void RemoveZombieland(string filename)
        {
            if (Current.Game == null || Current.Game.Maps == null || Find.World == null)
            {
                return;
            }
            Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;

            var zlNamespace = typeof(Tools).Namespace;

            Current.Game.Maps.Do(map =>
            {
                // destroy any of our things (even implied like corpse and meat)
                var allThings = map.listerThings.AllThings.Where(thing => thing.GetType().Namespace == zlNamespace);
                allThings.Union(map.listerThings.AllThings.Where(thing => thing.def.defName.StartsWith("Zombie_")));
                allThings.ToList().Do(thing => thing.Destroy(DestroyMode.Vanish));

                // remove any defs in filters of stockpiles
                map.zoneManager.AllZones.OfType <Zone_Stockpile>().Select(pile => pile?.settings?.filter).ToList()
                .Do(filter => RemoveZombielandFromFilter(filter));

                // remove any defs in work tables
                map.listerThings.AllThings.OfType <Building_WorkTable>().SelectMany(table => table?.billStack?.Bills ?? new List <Bill>())
                .Select(bill => bill?.ingredientFilter).ToList()
                .Do(filter => RemoveZombielandFromFilter(filter));

                // remove any of our map components
                map.components.RemoveAll(component => component.GetType().Namespace == zlNamespace);

                // remove any of our hediffs
                map.mapPawns.AllPawns.Do(pawn => pawn.health.hediffSet.hediffs.RemoveAll(hediff => hediff.GetType().Namespace == zlNamespace));
            });

            // remove any of our world components
            Find.World.components.RemoveAll(component => component.GetType().Namespace == zlNamespace);

            // remove zombie faction
            var factionManager = Find.World.factionManager;
            var factions       = Traverse.Create(factionManager).Field("allFactions").GetValue <List <Faction> >();
            var zombieFaction  = factions.First(faction => faction.def == ZombieDefOf.Zombies);

            factions.Remove(zombieFaction);
            foreach (var faction in factions)
            {
                var relations = Traverse.Create(faction).Field("relations").GetValue <List <FactionRelation> >();
                relations.RemoveAll(relation => relation.other == zombieFaction);
            }

            // this is how we save a file without our mod reference
            var runningMods = Traverse.Create(typeof(LoadedModManager)).Field("runningMods").GetValue <List <ModContentPack> >();
            var me          = runningMods.First(mod => mod.Identifier == ZombielandMod.Identifier);
            var myIndex     = runningMods.IndexOf(me);

            runningMods.Remove(me);
            GameDataSaveLoader.SaveGame(filename);
            runningMods.Insert(myIndex, me);

            MemoryUtility.ClearAllMapsAndWorld();
            GenScene.GoToMainMenu();
        }
 private static void <DoMainMenuControls> m__F()
 {
     GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         Root.Shutdown();
     });
 }
 private static void <DoMainMenuControls> m__9()
 {
     LongEventHandler.QueueLongEvent(delegate()
     {
         GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
         MemoryUtility.ClearAllMapsAndWorld();
     }, "Entry", "SavingLongEvent", false, null);
 }
Exemplo n.º 7
0
 public void SetPublishedFileId(PublishedFileId_t newPfid)
 {
     publishedFileIdInt = newPfid;
     if (Category == ScenarioCategory.CustomLocal && !fileName.NullOrEmpty())
     {
         GameDataSaveLoader.SaveScenario(this, GenFilePaths.AbsPathForScenario(fileName));
     }
 }
 protected override void DoFileInteraction(string mapName)
 {
     LongEventHandler.QueueLongEvent(delegate {
         GameDataSaveLoader.SaveGame(mapName);
     }, "SavingLongEvent", false, null);
     Messages.Message("SavedAs".Translate(mapName), MessageTypeDefOf.SilentInput);
     PlayerKnowledgeDatabase.Save();
     this.Close(true);
 }
Exemplo n.º 9
0
 private void LoadScenario()
 {
     if (GameDataSaveLoader.TryLoadScenario((from fi in base.Directory.GetFiles("*.rsc")
                                             where fi.Extension == ".rsc"
                                             select fi).First().FullName, ScenarioCategory.SteamWorkshop, out cachedScenario))
     {
         cachedScenario.SetPublishedFileId(PublishedFileId);
     }
 }
Exemplo n.º 10
0
 private static void SaveGame(Action <byte[]> saved)
 {
     Loger.Log("Client SaveGame() " + SaveFullName);
     LongEventHandler.QueueLongEvent(() =>
     {
         GameDataSaveLoader.SaveGame(SaveName);
         var content = File.ReadAllBytes(SaveFullName);
         saved(content);
     }, "Autosaving", false, null);
 }
Exemplo n.º 11
0
        static void SaveGameWithoutZombieland(string filename)
        {
            var runningMods = LoadedModManager.RunningMods as List <ModContentPack>;
            var me          = runningMods.First(mod => mod.Identifier == ZombielandMod.Identifier);
            var myIndex     = runningMods.IndexOf(me);

            runningMods.Remove(me);
            GameDataSaveLoader.SaveGame(filename);
            runningMods.Insert(myIndex, me);
        }
Exemplo n.º 12
0
            internal void <> m__0()
            {
                Scenario obj = null;

                if (GameDataSaveLoader.TryLoadScenario(this.filePath, ScenarioCategory.CustomLocal, out obj))
                {
                    this.$this.scenarioReturner(obj);
                }
                this.$this.Close(true);
            }
Exemplo n.º 13
0
        /// <summary>
        /// Инициализация после получения всех данных и уже запущенной игре
        /// </summary>
        public static void InitGame()
        {
            try
            {
                Loger.Log("Client InitGame()");
                //Data.ChatsTime = DateTime.UtcNow + ServerTimeDelta; //без этого указания будут получены все сообщения с каналов

                MainButtonWorker_OC.ShowOnStart();
                UpdateWorldController.ClearWorld();
                UpdateWorldController.InitGame();
                Data.UpdateTime = DateTime.MinValue;
                UpdateWorld(true);

                Data.LastServerConnect = DateTime.MinValue;

                Timers.Add(500, UpdateChats);
                Timers.Add(5000, () => UpdateWorld(false));
                Timers.Add(60000 * 15, BackgroundSaveGame);

                //устанавливаем событие на выход из игры
                GameExit.BeforeExit = () =>
                {
                    Loger.Log("Client BeforeExit ");
                    GameExit.BeforeExit = null;
                    TimersStop();
                    if (Current.Game == null)
                    {
                        return;
                    }

                    Loger.Log("Client SaveGameBeforeExit " + SaveFullName);
                    GameDataSaveLoader.SaveGame(SaveName);
                    var content = File.ReadAllBytes(SaveFullName);
                    if (content.Length > 1024)
                    {
                        Data.SaveFileData = content;
                        UpdateWorld(false);

                        Loger.Log("Client SaveGameBeforeExit OK");
                    }
                    SessionClient.Get.Disconnect();
                };
            }
            catch (Exception e)
            {
                ExceptionUtil.ExceptionLog(e, "Client InitGame Error");
                GameExit.BeforeExit = null;
                TimersStop();
                if (Current.Game == null)
                {
                    return;
                }
                SessionClient.Get.Disconnect();
            }
        }
Exemplo n.º 14
0
        private void LoadScenario()
        {
            FileInfo fileInfo = (from fi in base.Directory.GetFiles("*.rsc")
                                 where fi.Extension == ".rsc"
                                 select fi).First <FileInfo>();

            if (GameDataSaveLoader.TryLoadScenario(fileInfo.FullName, ScenarioCategory.SteamWorkshop, out this.cachedScenario))
            {
                this.cachedScenario.SetPublishedFileId(this.PublishedFileId);
            }
        }
Exemplo n.º 15
0
 protected override void DoFileInteraction(string mapName)
 {
     mapName = GenFile.SanitizedFileName(mapName);
     LongEventHandler.QueueLongEvent(delegate
     {
         GameDataSaveLoader.SaveGame(mapName);
     }, "SavingLongEvent", doAsynchronously: false, null);
     Messages.Message("SavedAs".Translate(mapName), MessageTypeDefOf.SilentInput, historical: false);
     PlayerKnowledgeDatabase.Save();
     Close();
 }
        protected override void DoFileInteraction(string fileName)
        {
            string absPath = GenFilePaths.AbsPathForScenario(fileName);

            LongEventHandler.QueueLongEvent(delegate
            {
                GameDataSaveLoader.SaveScenario(this.savingScen, absPath);
            }, "SavingLongEvent", false, null);
            Messages.Message("SavedAs".Translate(fileName), MessageTypeDefOf.SilentInput);
            this.Close(true);
        }
Exemplo n.º 17
0
 public override void ClickAction()
 {
     LongEventHandler.QueueLongEvent(
         () =>
     {
         GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
         LongEventHandler.ExecuteWhenFinished(Root.Shutdown);
     },
         "SavingLongEvent",
         false,
         null
         );
 }
 public override void ClickAction()
 {
     LongEventHandler.QueueLongEvent(
         () =>
     {
         GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
         // A14 <= (A13) GameDataSaver.SaveGame( Find.Map, Find.Map.info.permadeathModeUniqueName );
     },
         "Entry",
         "SavingLongEvent",
         false,
         null
         );
 }
Exemplo n.º 19
0
        protected override void DoFileInteraction(string fileName)
        {
            string filePath = GenFilePaths.AbsPathForScenario(fileName);

            PreLoadUtility.CheckVersionAndLoad(filePath, ScribeMetaHeaderUtility.ScribeHeaderMode.Scenario, delegate
            {
                Scenario obj = null;
                if (GameDataSaveLoader.TryLoadScenario(filePath, ScenarioCategory.CustomLocal, out obj))
                {
                    this.scenarioReturner(obj);
                }
                this.Close(true);
            });
        }
Exemplo n.º 20
0
        public void DoAutosave()
        {
            string fileName;

            if (Current.Game.Info.permadeathMode)
            {
                fileName = Current.Game.Info.permadeathModeUniqueName;
            }
            else
            {
                fileName = this.NewAutosaveFileName();
            }
            GameDataSaveLoader.SaveGame(fileName);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Немедленно сохраняет игру и передает на сервер. Должно запускаться уже в потоке LongEventHandler.QueueLongEvent, ожидает окончания соханения
        /// </summary>
        /// <param name="single">Будут удалены остальные Варианты сохранений, кроме этого</param>
        public static void SaveGameNowInEvent(bool single = false)
        {
            Loger.Log($"Client {SessionClientController.My.Login} SaveGameNowInEvent single=" + single.ToString());

            GameDataSaveLoader.SaveGame(SaveName);
            var content = File.ReadAllBytes(SaveFullName);

            if (content.Length > 1024)
            {
                Data.SaveFileData = content;
                Data.SingleSave   = single;
                UpdateWorld(false);

                Loger.Log($"Client {SessionClientController.My.Login} SaveGameNowInEvent OK");
            }
        }
Exemplo n.º 22
0
        public void PrepareForWorkshopUpload()
        {
            string path = name + Rand.RangeInclusive(100, 999);

            tempUploadDir = Path.Combine(GenFilePaths.TempFolderPath, path);
            DirectoryInfo directoryInfo = new DirectoryInfo(tempUploadDir);

            if (directoryInfo.Exists)
            {
                directoryInfo.Delete();
            }
            directoryInfo.Create();
            string str = Path.Combine(tempUploadDir, name);

            str += ".rsc";
            GameDataSaveLoader.SaveScenario(this, str);
        }
        private void ConvertWorld(string filePath)
        {
            normalClose = false;

            var prevGame = Current.Game; // Fix UIRoot_Entry error.

            var persistentWorld = new PersistentWorld();

            Current.Game = prevGame; // Fix UIRoot_Entry error.

            persistentWorld.LoadSaver = new PersistentWorldLoadSaver(persistentWorld, filePath)
            {
                Status = PersistentWorldLoadSaver.PersistentWorldLoadStatus.Converting
            };

            PersistentWorldManager.GetInstance().PersistentWorld = persistentWorld;

            GameDataSaveLoader.LoadGame(Path.GetFileNameWithoutExtension(filePath));
        }
Exemplo n.º 24
0
 public static void RecacheData()
 {
     scenariosLocal.Clear();
     foreach (FileInfo allCustomScenarioFile in GenFilePaths.AllCustomScenarioFiles)
     {
         if (GameDataSaveLoader.TryLoadScenario(allCustomScenarioFile.FullName, ScenarioCategory.CustomLocal, out Scenario scen))
         {
             scenariosLocal.Add(scen);
         }
     }
     scenariosWorkshop.Clear();
     foreach (WorkshopItem allSubscribedItem in WorkshopItems.AllSubscribedItems)
     {
         WorkshopItem_Scenario workshopItem_Scenario = allSubscribedItem as WorkshopItem_Scenario;
         if (workshopItem_Scenario != null)
         {
             scenariosWorkshop.Add(workshopItem_Scenario.GetScenario());
         }
     }
 }
Exemplo n.º 25
0
 public static void RecacheData()
 {
     ScenarioFiles.scenariosLocal.Clear();
     foreach (FileInfo fileInfo in GenFilePaths.AllCustomScenarioFiles)
     {
         Scenario item;
         if (GameDataSaveLoader.TryLoadScenario(fileInfo.FullName, ScenarioCategory.CustomLocal, out item))
         {
             ScenarioFiles.scenariosLocal.Add(item);
         }
     }
     ScenarioFiles.scenariosWorkshop.Clear();
     foreach (WorkshopItem workshopItem in WorkshopItems.AllSubscribedItems)
     {
         WorkshopItem_Scenario workshopItem_Scenario = workshopItem as WorkshopItem_Scenario;
         if (workshopItem_Scenario != null)
         {
             ScenarioFiles.scenariosWorkshop.Add(workshopItem_Scenario.GetScenario());
         }
     }
 }
Exemplo n.º 26
0
        public static void DoMainMenuControls(Rect rect, bool anyMapFiles)
        {
            GUI.BeginGroup(rect);
            Rect rect2 = new Rect(0f, 0f, 170f, rect.height);
            Rect rect3 = new Rect(rect2.xMax + 17f, 0f, 145f, rect.height);

            Text.Font = GameFont.Small;
            List <ListableOption> list = new List <ListableOption>();

            if (Current.ProgramState == ProgramState.Entry)
            {
                string label = ("Tutorial".CanTranslate() ? ((string)"Tutorial".Translate()) : ((string)"LearnToPlay".Translate()));
                list.Add(new ListableOption(label, delegate
                {
                    InitLearnToPlay();
                }));
                list.Add(new ListableOption("NewColony".Translate(), delegate
                {
                    Find.WindowStack.Add(new Page_SelectScenario());
                }));
            }
            if (Current.ProgramState == ProgramState.Playing && !Current.Game.Info.permadeathMode)
            {
                list.Add(new ListableOption("Save".Translate(), delegate
                {
                    CloseMainTab();
                    Find.WindowStack.Add(new Dialog_SaveFileList_Save());
                }));
            }
            ListableOption item;

            if (anyMapFiles && (Current.ProgramState != ProgramState.Playing || !Current.Game.Info.permadeathMode))
            {
                item = new ListableOption("LoadGame".Translate(), delegate
                {
                    CloseMainTab();
                    Find.WindowStack.Add(new Dialog_SaveFileList_Load());
                });
                list.Add(item);
            }
            if (Current.ProgramState == ProgramState.Playing)
            {
                list.Add(new ListableOption("ReviewScenario".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_MessageBox(Find.Scenario.GetFullInformationText(), null, null, null, null, Find.Scenario.name));
                }));
            }
            item = new ListableOption("Options".Translate(), delegate
            {
                CloseMainTab();
                Find.WindowStack.Add(new Dialog_Options());
            }, "MenuButton-Options");
            list.Add(item);
            if (Current.ProgramState == ProgramState.Entry)
            {
                item = new ListableOption("Mods".Translate(), delegate
                {
                    Find.WindowStack.Add(new Page_ModsConfig());
                });
                list.Add(item);
                if (Prefs.DevMode && LanguageDatabase.activeLanguage == LanguageDatabase.defaultLanguage && LanguageDatabase.activeLanguage.anyError)
                {
                    item = new ListableOption("SaveTranslationReport".Translate(), delegate
                    {
                        LanguageReportGenerator.SaveTranslationReport();
                    });
                    list.Add(item);
                }
                item = new ListableOption("Credits".Translate(), delegate
                {
                    Find.WindowStack.Add(new Screen_Credits());
                });
                list.Add(item);
            }
            if (Current.ProgramState == ProgramState.Playing)
            {
                if (Current.Game.Info.permadeathMode)
                {
                    item = new ListableOption("SaveAndQuitToMainMenu".Translate(), delegate
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
                            MemoryUtility.ClearAllMapsAndWorld();
                        }, "Entry", "SavingLongEvent", doAsynchronously: false, null, showExtraUIInfo: false);
                    });
                    list.Add(item);
                    item = new ListableOption("SaveAndQuitToOS".Translate(), delegate
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
                            LongEventHandler.ExecuteWhenFinished(delegate
                            {
                                Root.Shutdown();
                            });
                        }, "SavingLongEvent", doAsynchronously: false, null, showExtraUIInfo: false);
                    });
                    list.Add(item);
                }
                else
                {
                    Action action = delegate
                    {
                        if (GameDataSaveLoader.CurrentGameStateIsValuable)
                        {
                            Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmQuit".Translate(), delegate
                            {
                                GenScene.GoToMainMenu();
                            }, destructive: true));
                        }
                        else
                        {
                            GenScene.GoToMainMenu();
                        }
                    };
                    item = new ListableOption("QuitToMainMenu".Translate(), action);
                    list.Add(item);
                    Action action2 = delegate
                    {
                        if (GameDataSaveLoader.CurrentGameStateIsValuable)
                        {
                            Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmQuit".Translate(), delegate
                            {
                                Root.Shutdown();
                            }, destructive: true));
                        }
                        else
                        {
                            Root.Shutdown();
                        }
                    };
                    item = new ListableOption("QuitToOS".Translate(), action2);
                    list.Add(item);
                }
            }
            else
            {
                item = new ListableOption("QuitToOS".Translate(), delegate
                {
                    Root.Shutdown();
                });
                list.Add(item);
            }
            OptionListingUtility.DrawOptionListing(rect2, list);
            Text.Font = GameFont.Small;
            List <ListableOption> list2 = new List <ListableOption>();
            ListableOption        item2 = new ListableOption_WebLink("FictionPrimer".Translate(), "https://rimworldgame.com/backstory", TexButton.IconBlog);

            list2.Add(item2);
            item2 = new ListableOption_WebLink("LudeonBlog".Translate(), "https://ludeon.com/blog", TexButton.IconBlog);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("Forums".Translate(), "https://ludeon.com/forums", TexButton.IconForums);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("OfficialWiki".Translate(), "https://rimworldwiki.com", TexButton.IconBlog);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("TynansTwitter".Translate(), "https://twitter.com/TynanSylvester", TexButton.IconTwitter);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("TynansDesignBook".Translate(), "https://tynansylvester.com/book", TexButton.IconBook);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("HelpTranslate".Translate(), TranslationsContributeURL, TexButton.IconForums);
            list2.Add(item2);
            item2 = new ListableOption_WebLink("BuySoundtrack".Translate(), "http://www.lasgameaudio.co.uk/#!store/t04fw", TexButton.IconSoundtrack);
            list2.Add(item2);
            float num = OptionListingUtility.DrawOptionListing(rect3, list2);

            GUI.BeginGroup(rect3);
            if (Current.ProgramState == ProgramState.Entry && Widgets.ButtonText(new Rect(0f, num + 10f, rect3.width, 50f), LanguageDatabase.activeLanguage.FriendlyNameNative))
            {
                List <FloatMenuOption> list3 = new List <FloatMenuOption>();
                foreach (LoadedLanguage allLoadedLanguage in LanguageDatabase.AllLoadedLanguages)
                {
                    LoadedLanguage localLang = allLoadedLanguage;
                    list3.Add(new FloatMenuOption(localLang.DisplayName, delegate
                    {
                        LanguageDatabase.SelectLanguage(localLang);
                        Prefs.Save();
                    }));
                }
                Find.WindowStack.Add(new FloatMenu(list3));
            }
            GUI.EndGroup();
            GUI.EndGroup();
        }
Exemplo n.º 27
0
        public static bool PreFDoMainMenuControls(Rect rect, bool anyMapFiles)
        {
            // Shape buttons
            float floButtonHeight  = rect.height / 8f;
            float floButtonPadding = floButtonHeight / 6f;
            float floButtonWidth   = rect.width / 2f;

            Rect rectButtonsFrame = new Rect(rect.x, rect.y, (rect.width / 2f) - rect.width * .05f, rect.height);
            Rect rectButtons      = new Rect(0f, 0f, rectButtonsFrame.width, rectButtonsFrame.height);

            GUI.BeginGroup(rectButtonsFrame);

            // make sure font is set to small
            Text.Font = GameFont.Small;

            // Menu Buttons are contained in this List
            List <ProListableOption> listableOptions = new List <ProListableOption>();

            // Tutorial Button and New Colony Button
            string str; // string needed because Tutorial doesn't exist in every language..

            if (Current.ProgramState == ProgramState.Entry)
            {
                str = ("Tutorial".CanTranslate() ? "Tutorial".Translate() : "LearnToPlay".Translate());
                listableOptions.Add(new ProListableOption(str, () => Traverse.Create(typeof(MainMenuDrawer)).Method("InitLearnToPlay"), null));
                listableOptions.Add(new ProListableOption("NewColony".Translate(), () => Find.WindowStack.Add(new ProCWP()), null));
            }

            // In-Game Save Button
            if (Current.ProgramState == ProgramState.Playing && !Current.Game.Info.permadeathMode)
            {
                listableOptions.Add(new ProListableOption("Save".Translate(), () => {
                    Traverse.Create(typeof(MainMenuDrawer)).Method("CloseMainTab");
                    Find.WindowStack.Add(new Dialog_SaveFileList_Save());
                }, null));
            }

            // Load Game Button
            if (anyMapFiles && (Current.ProgramState != ProgramState.Playing || !Current.Game.Info.permadeathMode))
            {
                listableOptions.Add(new ProListableOption("LoadGame".Translate(), () => {
                    Traverse.Create(typeof(MainMenuDrawer)).Method("CloseMainTab");
                    Find.WindowStack.Add(new Dialog_SaveFileList_Load());
                }, null));
            }

            // Review Scenario Button
            if (Current.ProgramState == ProgramState.Playing)
            {
                listableOptions.Add(new ProListableOption("ReviewScenario".Translate(), () => {
                    WindowStack windowStack = Find.WindowStack;
                    string scenario         = Find.Scenario.name;
                    windowStack.Add(new Dialog_MessageBox(Find.Scenario.GetFullInformationText(), null, null, null, null, scenario, false));
                }, null));
            }

            // Options Button
            listableOptions.Add(new ProListableOption("Options".Translate(), () => {
                Traverse.Create(typeof(MainMenuDrawer)).Method("CloseMainTab");
                Find.WindowStack.Add(new Dialog_Options());
            }, "MenuButton-Options"));

            // Mods Button and Credit Button
            if (Current.ProgramState == ProgramState.Entry)
            {
                listableOptions.Add(new ProListableOption("Mods".Translate(), () => Find.WindowStack.Add(new Page_ModsConfig()), null));
                listableOptions.Add(new ProListableOption("Credits".Translate(), () => Find.WindowStack.Add(new Screen_Credits()), null));
            }

            // Quit To OS Button
            if (Current.ProgramState != ProgramState.Playing)
            {
                listableOptions.Add(new ProListableOption("QuitToOS".Translate(), () => Root.Shutdown(), null));
            }

            // Quit Buttons depending on Permadeath setting
            else if (!Current.Game.Info.permadeathMode)
            {
                Action currentGameStateIsValuable = () => {
                    if (!GameDataSaveLoader.CurrentGameStateIsValuable)
                    {
                        GenScene.GoToMainMenu();
                    }
                    else
                    {
                        Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmQuit".Translate(), () => GenScene.GoToMainMenu(), true, null));
                    }
                };
                ProListableOption listableOption = new ProListableOption("QuitToMainMenu".Translate(), currentGameStateIsValuable, null);
                listableOptions.Add(listableOption);
                Action action = () => {
                    if (!GameDataSaveLoader.CurrentGameStateIsValuable)
                    {
                        Root.Shutdown();
                    }
                    else
                    {
                        Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmQuit".Translate(), () => Root.Shutdown(), true, null));
                    }
                };
                listableOption = new ProListableOption("QuitToOS".Translate(), action, null);
                listableOptions.Add(listableOption);
            }
            else
            {
                listableOptions.Add(new ProListableOption("SaveAndQuitToMainMenu".Translate(), () => LongEventHandler.QueueLongEvent(() => {
                    GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
                    MemoryUtility.ClearAllMapsAndWorld();
                }, "Entry", "SavingLongEvent", false, null), null));
                listableOptions.Add(new ProListableOption("SaveAndQuitToOS".Translate(), () => LongEventHandler.QueueLongEvent(() => {
                    GameDataSaveLoader.SaveGame(Current.Game.Info.permadeathModeUniqueName);
                    LongEventHandler.ExecuteWhenFinished(() => Root.Shutdown());
                }, "SavingLongEvent", false, null), null));
            }

            // Draw Menu Buttons
            ProOptionListingUtility.ProDrawOptionListing(rectButtons, listableOptions, UI.screenHeight / 100f);
            GUI.EndGroup();


            // Configure Links
            Text.Font = GameFont.Small;
            List <ProListableOption_WebLink> listableOptions1      = new List <ProListableOption_WebLink>();
            ProListableOption_WebLink        listableOptionWebLink = new ProListableOption_WebLink("FictionPrimer".Translate(), null, "https://docs.google.com/document/d/1pIZyKif0bFbBWten4drrm7kfSSfvBoJPgG9-ywfN8j8/pub", ProTBin.IconBlog);

            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("LudeonBlog".Translate(), null, "http://ludeon.com/blog", ProTBin.IconBlog);
            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("Forums".Translate(), null, "http://ludeon.com/forums", ProTBin.IconForums);
            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("OfficialWiki".Translate(), null, "http://rimworldwiki.com", ProTBin.IconBlog);
            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("TynansTwitter".Translate(), null, "https://twitter.com/TynanSylvester", ProTBin.IconTwitter);
            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("TynansDesignBook".Translate(), null, "http://tynansylvester.com/book", ProTBin.IconBook);
            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("HelpTranslate".Translate(), null, "http://ludeon.com/forums/index.php?topic=2933.0", ProTBin.IconForums);
            listableOptions1.Add(listableOptionWebLink);
            listableOptionWebLink = new ProListableOption_WebLink("BuySoundtrack".Translate(), null, "http://www.lasgameaudio.co.uk/#!store/t04fw", ProTBin.IconSoundtrack);
            listableOptions1.Add(listableOptionWebLink);

            // Shape Links
            Rect rectLinksFrame = new Rect(rect.x + (rect.width / 2f), rect.y, (rect.width / 2f), (rect.height / (listableOptions1.Count + 1)) * (listableOptions1.Count - 1));

            GUI.BeginGroup(rectLinksFrame);
            Rect rectLinks = new Rect(0f, 0f, rectLinksFrame.width, rectLinksFrame.height);

            // Draw Links
            ProOptionListingUtility.ProDrawOptionListing(rectLinks, listableOptions1, (rectLinks.height / 9f) / 7f);
            GUI.EndGroup();

            // Handle language button
            if (Current.ProgramState == ProgramState.Entry)
            {
                // Configure Language button.
                List <FloatMenuOption>       floatMenuOptions = new List <FloatMenuOption>();
                IEnumerator <LoadedLanguage> enumerator       = LanguageDatabase.AllLoadedLanguages.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        LoadedLanguage current = enumerator.Current;
                        floatMenuOptions.Add(new FloatMenuOption(current.FriendlyNameNative, () =>
                        {
                            LanguageDatabase.SelectLanguage(current);
                            Prefs.Save();
                        }, MenuOptionPriority.Default, null, null, 0f, null, null));
                    }
                }
                finally
                {
                    if (enumerator == null)
                    {
                    }
                    enumerator.Dispose();
                }

                // Shape language button
                Rect rectLanguageButtonFrame = new Rect(rect.x + (rect.width / 2f), rect.y + rectLinksFrame.height, (rect.width / 2f), (rect.height / (listableOptions1.Count + 1)) * 2f);
                GUI.BeginGroup(rectLanguageButtonFrame);
                float floLanguageButtonPadding = rectLanguageButtonFrame.height * .1f;
                Rect  rectLanguageButton       = new Rect(0f + floLanguageButtonPadding, 0f + floLanguageButtonPadding, rectLanguageButtonFrame.width - (floLanguageButtonPadding * 2f), rectLanguageButtonFrame.height - (floLanguageButtonPadding * 2f));

                // Draw language button
                if (Widgets.ButtonImage(rectLanguageButton, LanguageDatabase.activeLanguage.icon))
                {
                    Find.WindowStack.Add(new FloatMenu(floatMenuOptions));
                }
                GUI.EndGroup();
            }

            return(false);
        }
Exemplo n.º 28
0
        public static void NukeEverything(Game game)
        {
            ProfilerThreadCheck.BeginSample("CarnivaleNuke");

            var facList = game.World.factionManager.AllFactionsListForReading;

            for (int i = facList.Count - 1; i > 0; i--)
            {
                var fac = facList[i];
                if (fac.IsCarnival())
                {
                    foreach (var map in game.Maps)
                    {
                        var lord = map.lordManager.lords.FirstOrDefault(l => l.LordJob is LordJob_EntertainColony);

                        if (lord != null)
                        {
                            map.lordManager.RemoveLord(lord);
                        }

                        foreach (var pawn in map.mapPawns.AllPawns)
                        {
                            if (fac == pawn.Faction || pawn.IsCarny(false))
                            {
                                pawn.DeSpawn();
                                game.World.worldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                            }
                            else if (pawn.needs != null && pawn.needs.mood != null)
                            {
                                pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_AttendedShow);
                                pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_MissCarnival);
                            }
                        }

                        foreach (var thing in map.listerThings.AllThings.Where(t => fac == t.Faction))
                        {
                            thing.Destroy();
                        }
                    }

                    fac.RemoveAllRelations();
                    facList.RemoveAt(i);
                }
            }

            List <Pawn> tmpPawnsToRemove = new List <Pawn>();

            foreach (var pawn in game.World.worldPawns.AllPawnsAliveOrDead)
            {
                if (pawn.IsCarny(false))
                {
                    tmpPawnsToRemove.Add(pawn);
                }
                else if (pawn.needs != null && pawn.needs.mood != null)
                {
                    pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_AttendedShow);
                    pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(_DefOf.Thought_MissCarnival);
                }
            }

            foreach (var pawn in tmpPawnsToRemove)
            {
                game.World.worldPawns.RemovePawn(pawn);
            }

            foreach (var map in game.Maps)
            {
                var info = map.GetComponent <CarnivalInfo>();

                if (info != null)
                {
                    info.Cleanup();
                    map.components.Remove(info);
                }

                map.pawnDestinationManager = new PawnDestinationManager();
            }

            game.storyteller.incidentQueue.Clear();

            string fileName;

            if (game.Info.permadeathMode)
            {
                fileName = game.Info.permadeathModeUniqueName;
            }
            else
            {
                fileName = game.AnyPlayerHomeMap.info.parent.LabelCap;
            }

            GameDataSaveLoader.SaveGame(fileName + "_Nuked");

            ProfilerThreadCheck.EndSample();
        }
 protected override void DoFileInteraction(string saveFileName)
 {
     GameDataSaveLoader.CheckVersionAndLoadGame(saveFileName);
 }
Exemplo n.º 30
0
        public void DoAutosave()
        {
            string fileName = (!Current.Game.Info.permadeathMode) ? NewAutosaveFileName() : Current.Game.Info.permadeathModeUniqueName;

            GameDataSaveLoader.SaveGame(fileName);
        }