private void SaveColony(ref PersistentColony colony) { Log.Message("Saving colony data..."); //var oldColonySaveFile = colony.FileInfo ?? new FileInfo(GetColonySaveFilePath(colony)); colony = PersistentColony.Convert(this.persistentWorld, this.persistentWorld.Game, colony.ColonyData); var colonySaveFile = GetColonySaveFilePath(colony); var colonyFile = new FileInfo(colonySaveFile); /* * if (!oldColonySaveFile.FullName.EqualsIgnoreCase(colonyFile.FullName)) * { * // It could only be here? * //File.Delete(oldColonySaveFile.FullName); * } */ this.SetCurrentFile(colonyFile); ReferenceTable.ClearReferencesFor(colonySaveFile, true); var @ref = colony; SafeSaver.Save(colonySaveFile, "colonyfile", delegate { Scribe_Deep.Look(ref @ref, "colony"); }); colony = @ref; colony.FileInfo = colonyFile; Log.Message("Saved colony data."); }
private static void DrawFavouriteStar(Rect rect, PersistentColony colony) { var favoured = colony.ColonyData.Favoured; var size = rect.size.x; var starRect = new Rect(rect.x, rect.y, size, size); var starImageRect = new Rect(starRect.x + size * 0.1f, starRect.y + size * 0.05f, starRect.width * 0.9f, starRect.height * 0.9f); if (!favoured) { Widgets.DrawAltRect(starRect); } else { Widgets.DrawHighlight(starRect); } Widgets.DrawHighlightIfMouseover(starRect); if (ButtonTextureHover(starRect, starImageRect, FavouriteStar, FavouriteStarToBe, Color.gray, favoured ? Color.red : Color.green, GenUI.MouseoverColor, favoured)) { colony.ColonyData.Favoured = !favoured; _sorted = null; // Reset favourites list } TooltipHandler.TipRegion(starRect, !favoured ? "FilUnderscore.PersistentRimWorlds.Colony.Favourite.Add".Translate() : "FilUnderscore.PersistentRimWorlds.Colony.Favourite.Remove".Translate()); }
private void SaveColonyMapData(PersistentColony colony) { Log.Message("Saving colony map data..."); var maps = Current.Game.Maps; for (var i = 0; i < maps.Count; i++) { var map = maps[i]; if (!persistentWorld.LoadedMaps.ContainsKey(map.Tile)) { continue; } var set = persistentWorld.LoadedMaps[map.Tile]; if (!set.Contains(colony) || set.Count != 1) { continue; } var mapSaveFile = mapsDirectory + "/" + map.Tile + PersistentWorldMapFileExtension; this.SetCurrentFile(mapSaveFile); ReferenceTable.ClearReferencesFor(mapSaveFile, true); SafeSaver.Save(mapSaveFile, "mapfile", delegate { Scribe_Deep.Look(ref map, "map"); }); } Log.Message("Saved colony map data."); }
public Dialog_PersistentWorlds_LeaderPawnSelection(PersistentColony colony) { this.colony = colony; this.doCloseButton = true; this.doCloseX = true; }
private static void DrawLeader(Rect rect, PersistentColony colony, float margin, float widthMultiplier) { Rect leaderRect; if ((object)colony.ColonyData.Leader?.Texture != null) { var leaderPortrait = colony.ColonyData.Leader.Texture; leaderRect = new Rect(rect.x + rect.width * widthMultiplier, rect.y + rect.height / 2 - leaderPortrait.height / 2f, leaderPortrait.width, leaderPortrait.height); GUI.DrawTexture(leaderRect, leaderPortrait); TooltipHandler.TipRegion(leaderRect, "FilUnderscore.PersistentRimWorlds.Colony.ColonyLeader".Translate(colony.ColonyData.Leader.Name .ToStringFull)); } else { leaderRect = new Rect(rect.x + rect.width / 2 + margin, rect.y + margin, rect.width - rect.width * widthMultiplier - margin, rect.height); Text.Font = GameFont.Tiny; Widgets.Label(leaderRect, "FilUnderscore.PersistentRimWorlds.Colony.NoLeader".Translate()); } }
/// <summary> /// Loads some colony information for loading screens. /// </summary> public void LoadColonies() { if (Scribe.mode != LoadSaveMode.LoadingVars || ScribeMultiLoader.Empty()) { this.PreloadWorldColoniesMaps(); } var colonyFiles = new DirectoryInfo(this.coloniesDirectory).GetFiles("*" + PersistentWorldColonyFileExtension); Log.Message("Loading colonies..."); foreach (var colonyFile in colonyFiles) { this.SetCurrentFile(colonyFile); ScribeMultiLoader.SetScribeCurXmlParentByFilePath(colonyFile.FullName); var colony = new PersistentColony() { FileInfo = colonyFile }; if (Scribe.EnterNode("colony")) { Scribe_Deep.Look(ref colony.ColonyData, "data"); Scribe.ExitNode(); } this.persistentWorld.Colonies.Add(colony); } Log.Message("Loaded colony data..."); }
public static void UnloadColonyMaps(PersistentColony colony) { var maps = PersistentWorld.GetMapsForColony(colony); // Check to make sure we only unload maps we are sure aren't being used by any colony. var tilesToRemove = new HashSet <int>(); foreach (var map in maps) { var tile = map.Tile; var set = PersistentWorld.LoadedMaps[tile]; if (!set.Contains(colony) || set.Count != 1) { continue; } tilesToRemove.Add(tile); UnloadReferences(map, true); UnloadMap(map); } tilesToRemove.Do(tile => PersistentWorld.LoadedMaps.Remove(tile)); tilesToRemove.Clear(); }
public void SaveColonyAndColonyMapsData(ref PersistentColony colony) { Log.Message("Saving colony and colony maps data..."); SaveColony(ref colony); SaveColonyMapData(colony); Log.Message("Saved colony and colony maps data."); }
public static IEnumerable <Map> LoadColonyMaps(PersistentColony colony) { var maps = LoadMaps(colony.ColonyData.ActiveWorldTiles.ToArray()); foreach (var map in maps) { PersistentWorld.LoadedMaps.Add(map.Tile, new HashSet <PersistentColony>() { colony }); yield return(map); } }
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 void DrawNameLabel(Rect rect, PersistentColony colony, Faction faction) { if (!ScrollPositions.ContainsKey(colony)) { ScrollPositions.Add(colony, new Vector2()); } var labelScrollPosition = ScrollPositions[colony]; Text.Font = GameFont.Tiny; WidgetExtensions.LabelScrollable(rect, faction.Name, ref labelScrollPosition, false, true, false); Text.Font = GameFont.Small; ScrollPositions[colony] = labelScrollPosition; }
private static void DrawAbandonColony(Rect rect, PersistentColony colony) { // Delete button. var size = rect.size.x; var abandonRect = new Rect(rect.x, rect.height - size, size, size); Widgets.DrawAltRect(abandonRect); Widgets.DrawHighlightIfMouseover(abandonRect); // Draw delete button first. if (ButtonTextureHover(abandonRect, abandonRect, AbandonHomeButton, AbandonButton, Color.white, GenUI.MouseoverColor)) { ColonyUI.ShowAbandonColonyConfirmationDialog(colony, (colony) => { var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld; persistentWorld.DeleteColony(colony); }); } TooltipHandler.TipRegion(abandonRect, "FilUnderscore.PersistentRimWorlds.Colony.Abandon".Translate()); }
/// <summary> /// Loads all colony data for a specific colony. Fully loads the referenced colony. /// </summary> /// <param name="colony"></param> public void LoadColony(ref PersistentColony colony) { if (Scribe.mode != LoadSaveMode.LoadingVars || ScribeMultiLoader.Empty()) { this.PreloadWorldColoniesMaps(); } var file = colony.FileInfo ?? new FileInfo(GetColonySaveFilePath(colony)); SetCurrentFile(file); Log.Message("Loading colony... " + Path.GetFileNameWithoutExtension(file.FullName)); ScribeMultiLoader.SetScribeCurXmlParentByFilePath(file.FullName); Scribe_Deep.Look(ref colony, "colony"); this.persistentWorld.Colony = colony; colony.FileInfo = file; Log.Message("Loaded colony."); }
private static bool CanChangeLeader(PersistentColony colony, PersistentWorld world) { return(Equals(colony, world.Colony)); }
static bool Prefix(Game __instance) { if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull()) { return(true); } var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld; var game = __instance; MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; var mapSize = new IntVec3(__instance.InitData.mapSize, 1, __instance.InitData.mapSize); var settlement = (Settlement)null; var settlements = Find.WorldObjects.Settlements; foreach (var t in settlements) { if (t.Faction != Faction.OfPlayer) { continue; } settlement = t; break; } if (settlement == null) { Log.Error("Could not generate starting map because there is no player faction base."); GenScene.GoToMainMenu(); return(false); } var map = MapGenerator.GenerateMap(mapSize, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs, null); game.CurrentMap = map; // TODO: Implement permanent death mode for colonies. if (__instance.InitData.permadeath) { __instance.Info.permadeathMode = true; } PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism); __instance.FinalizeInit(); Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot); Find.CameraDriver.ResetSize(); persistentWorld.SchedulePause(); Find.Scenario.PostGameStart(); /* * Complete research needed depending if PlayerFaction is PlayerColony or PlayerTribe. */ if (Faction.OfPlayer.def.startingResearchTags != null) { foreach (var startingResearchTag in Faction.OfPlayer.def.startingResearchTags) { foreach (var allDef in DefDatabase <ResearchProjectDef> .AllDefs) { if (allDef.HasTag(startingResearchTag)) { game.researchManager.FinishProject(allDef, false, null); } } } } GameComponentUtility.StartedNewGame(); persistentWorld.LoadSaver.Status = PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame; var colony = PersistentColony.Convert(persistentWorld, Current.Game); colony.ColonyData.UniqueId = ++PersistentWorldManager.GetInstance().PersistentWorld.WorldData.NextColonyId; colony.ColonyData.ActiveWorldTiles.Add(map.Tile); colony.GameData.MapSize = __instance.InitData.mapSize; game.InitData = null; persistentWorld.Colony = colony; persistentWorld.CheckAndSetColonyData(); persistentWorld.Colonies.Add(colony); persistentWorld.LoadedMaps.Add(map.Tile, new HashSet <PersistentColony>() { colony }); return(false); }
private void DeleteColony(PersistentColony colony) { this.persistentWorld.DeleteColony(colony); }
private string GetColonySaveFilePath(PersistentColony colony) { return(coloniesDirectory + "/" + colony.ColonyData.ColonyFaction.Name + "_" + colony.ColonyData.UniqueId + PersistentWorldColonyFileExtension); }
public Dialog_PersistentWorlds_LeaderPawnSelection(PersistentColony colony) { this.colony = colony; }
private static void ShowAbandonColonyConfirmationDialog(PersistentColony colony, Action <PersistentColony> onDelete) { var dialogBox = new Dialog_MessageBox("FilUnderscore.PersistentRimWorlds.Colony.Abandon.Desc".Translate(colony.ColonyData.ColonyFaction.Name), "Delete".Translate(), () => onDelete(colony), "FilUnderscore.PersistentRimWorlds.Cancel".Translate(), null, "FilUnderscore.PersistentRimWorlds.Colony.Abandon".Translate()); Find.WindowStack.Add(dialogBox); }
private void ConvertColonyToAIColony(PersistentColony colony) { Log.Error("This feature has not currently been implemented, stay tuned for updates."); // TODO... }