private void LoadWorld(string worldDir)
        {
            LongEventHandler.QueueLongEvent(delegate
            {
                normalClose = false;

                var previousGame = Current.Game;

                var persistentWorld       = new PersistentWorld();
                persistentWorld.LoadSaver = new PersistentWorldLoadSaver(persistentWorld, worldDir);

                // TODO: HMM
                PersistentWorldManager.GetInstance().PersistentWorld = persistentWorld;

                persistentWorld.LoadSaver.LoadWorld();

                Current.Game = previousGame;

                this.next = new Page_PersistentWorlds_LoadWorld_ColonySelection(persistentWorld)
                {
                    prev = this
                };
                this.DoNext();
            }, "FilUnderscore.PersistentRimWorlds.Loading.World", true, null);
        }
        public PersistentWorldLoadSaver(PersistentWorld world, string worldFolderPath)
        {
            this.persistentWorld = world;
            this.ReferenceTable  = new ReferenceTable(this);

            this.ConfigurePaths(worldFolderPath);
        }
 private static IEnumerable <Widgets.DropdownMenuElement <ColonySortOption> > Button_GenerateMenu(
     PersistentWorld persistentWorld)
 {
     return(ColonySortOption.VALUES.Select(colonySortOption => new Widgets.DropdownMenuElement <ColonySortOption>()
     {
         option = new FloatMenuOption(colonySortOption.Name, () =>
         {
             persistentWorld.WorldData.ColonySortOption = colonySortOption;
         }),
         payload = colonySortOption
     }));
 }
        public Page_PersistentWorlds_LoadWorld_ColonySelection(PersistentWorld persistentWorld)
        {
            this.persistentWorld = persistentWorld;

            // Load colonies in a separate thread.
            LongEventHandler.SetCurrentEventText("FilUnderscore.PersistentRimWorlds.Loading.Colonies".Translate());
            new Thread(() => { persistentWorld.LoadSaver.LoadColonies(); }).Start();

            this.doCloseButton           = true;
            this.doCloseX                = true;
            this.forcePause              = true;
            this.absorbInputAroundWindow = true;
            this.closeOnAccept           = false;
        }
        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));
        }
        private static void DrawDynamicLeader(Rect rect, out Rect leaderRect, PersistentColony colony, PersistentWorld world,
                                              float widthMultiplier)
        {
            var portraitSize = new Vector2(rect.width / 2, rect.height);

            leaderRect = new Rect(rect.x + rect.width * widthMultiplier, rect.y, portraitSize.x, portraitSize.y);;

            if (colony.ColonyData.Leader != null && colony.ColonyData.Leader.Set &&
                (object)colony.ColonyData.Leader.Texture != null ||
                colony.ColonyData.Leader?.Reference != null)
            {
                if (colony.ColonyData.Leader.Reference != null)
                {
                    colony.ColonyData.Leader.Texture =
                        PortraitsCache.Get(colony.ColonyData.Leader.Reference, portraitSize, new Vector3(), 1f, true, true);
                }

                var leaderPortrait = colony.ColonyData.Leader.Texture;

                var canChangeLeader = CanChangeLeader(colony, world);

                if (canChangeLeader)
                {
                    if (WidgetExtensions.ButtonImage(leaderRect, leaderPortrait, Color.white, GenUI.MouseoverColor))
                    {
                        Find.WindowStack.Add(new Dialog_PersistentWorlds_LeaderPawnSelection(colony));
                    }
                }
                else
                {
                    GUI.DrawTexture(leaderRect, leaderPortrait);
                }

                TooltipHandler.TipRegion(leaderRect,
                                         canChangeLeader
                        ? "FilUnderscore.PersistentRimWorlds.Colony.ChangeLeader".Translate()
                        : "FilUnderscore.PersistentRimWorlds.Colony.ColonyLeader".Translate(colony.ColonyData.Leader
                                                                                            .Name.ToStringFull));
            }
            else
            {
                Text.Font = GameFont.Tiny;

                Widgets.Label(leaderRect, "FilUnderscore.PersistentRimWorlds.Colony.NoLeader".Translate());

                Text.Font = GameFont.Small;
            }
        }
 private static bool CanChangeLeader(PersistentColony colony, PersistentWorld world)
 {
     return(Equals(colony, world.Colony));
 }