public Designator ReplaceDesignator(Type searchingFor, Designator replacement) { DesignationCategoryDef designationCategoryDef = null; Designator designator = null; foreach (DesignationCategoryDef current in from dc in DefDatabase <DesignationCategoryDef> .AllDefs orderby dc.order descending select dc) { foreach (Designator current2 in current.resolvedDesignators) { if (current2.GetType().Equals(searchingFor)) { designator = current2; designationCategoryDef = current; break; } } if (designator != null) { break; } } if (designator == null) { return(null); } int index = designationCategoryDef.resolvedDesignators.IndexOf(designator); designationCategoryDef.resolvedDesignators[index] = replacement; return(designator); }
static void Postfix(ref IEnumerable <Designator> __result, ref DesignationCategoryDef __instance) { if (!Main.Instance.IsModAcitve()) { return; } if (ordersCategoryDef == null) { if ("Orders" == __instance.defName) { ordersCategoryDef = __instance; } } if (__instance != ordersCategoryDef || __result == null) { return; } var ourGizmo = new Designator_Rename(); var newList = __result.ToList(); newList.Add(ourGizmo); __result = newList; }
public static void MergeDesignationCategories(DesignationCategoryDef target, DesignationCategoryDef source) { // change designation category for all build designators in source foreach (var terrain in DefDatabase <TerrainDef> .AllDefs) { if (terrain.designationCategory == source) { terrain.designationCategory = target; } } // add specials that don't exist in target yet foreach (var designator in source.specialDesignatorClasses) { if (!target.specialDesignatorClasses.Contains(designator)) { target.specialDesignatorClasses.Add(designator); } } // recache target RecacheDesignationCategory(target); // remove source RemoveDesignationCategory(source); }
// TODO: Call from bootstrap public static void Initialize() { if (_initialized) { return; } // start blueprints list _blueprints = new List <Blueprint>(); // find our designation category. DesignationCategoryDef desCatDef = DefDatabase <DesignationCategoryDef> .GetNamed("Blueprints"); if (desCatDef == null) { throw new Exception("Blueprints designation category not found"); } // create internal designators list as a reference to list in the category def. FieldInfo _designatorsFI = typeof(DesignationCategoryDef).GetField("resolvedDesignators", BindingFlags.NonPublic | BindingFlags.Instance); _designators = _designatorsFI.GetValue(desCatDef) as List <Designator>; // done! _initialized = true; }
public Designator_PlanMine() { this.defaultLabel = "Plan to Mine"; this.icon = ContentFinder <Texture2D> .Get(itemPath : "MTP/PlanMine"); this.defaultDesc = "Quickly change planning to mining designations"; this.soundDragSustain = SoundDefOf.Designate_DragStandard; this.soundDragChanged = SoundDefOf.Designate_DragStandard_Changed; this.useMouseIcon = true; this.soundSucceeded = SoundDefOf.Designate_Haul; DesignationCategoryDef named = DefDatabase <DesignationCategoryDef> .GetNamed(defName : "Orders"); Type type = named.specialDesignatorClasses.Find(match: x => x == this.GetType()); if (type != null) { return; } named.specialDesignatorClasses.Add(item: this.GetType()); named.ResolveReferences(); DesignationCategoryDef named2 = DefDatabase <DesignationCategoryDef> .GetNamed(defName : "OrdersPlanMine"); List <DesignationCategoryDef> allDefsListForReading = DefDatabase <DesignationCategoryDef> .AllDefsListForReading; allDefsListForReading.Remove(item: named2); DefDatabase <DesignationCategoryDef> .ResolveAllReferences(); }
public static void RemoveDesignationCategory(DesignationCategoryDef category) { // todo; why doesn't this work? //// clean up source category //// check we got the field info //if ( _desPanelCacheFieldinfo == null ) // throw new Exception( "Could not get MainTabWindow_Architect.desPanelsCached FieldInfo" ); //// check if we're actually getting anything //List<ArchitectCategoryTab> tabs = _desPanelCacheFieldinfo.GetValue( MainTabDefOf.Architect.Window ) as List<ArchitectCategoryTab>; //if ( tabs == null ) // throw new Exception( "Could not get list of cached designation panels " ); //// find our source tab and remove it //var sourceTab = tabs.Find( tab => tab.def == source ); //if ( sourceTab == null ) // throw new Exception( "Could not find cached panel for category" ); //tabs.Remove( sourceTab ); //// if it was selected, unselect it (this should really never happen, but whatever) //if ( ( MainTabDefOf.Architect.Window as MainTabWindow_Architect )?.selectedDesPanel == sourceTab ) // ( MainTabDefOf.Architect.Window as MainTabWindow_Architect ).selectedDesPanel = null; //// assign the new cached list back //_desPanelCacheFieldinfo.SetValue( MainTabDefOf.Architect.Window, tabs ); // the subtle solution didn't seem to work, so let's get nuclear (DefDatabase <DesignationCategoryDef> .AllDefs as List <DesignationCategoryDef>)?.Remove(category); typeof(MainTabWindow_Architect).GetMethod("CacheDesPanels", (BindingFlags)60) .Invoke(MainButtonDefOf.Architect.TabWindow, null); }
static NewThingReplacement() { replacements = new List <Replacement>(); //--------------------------------------------- //--------------------------------------------- //Here are valid replacements: replacements.Add(new Replacement(d => d.IsWall() || typeof(Building_Door).IsAssignableFrom(d.thingClass))); replacements.Add(new Replacement(d => typeof(Building_Cooler).IsAssignableFrom(d.thingClass), postAction: (n, o) => { Building_Cooler newCooler = n as Building_Cooler; Building_Cooler oldCooler = o as Building_Cooler; //newCooler.compPowerTrader.PowerOn = oldCooler.compPowerTrader.PowerOn; //should be flickable newCooler.compTempControl.targetTemperature = oldCooler.compTempControl.targetTemperature; } )); replacements.Add(new Replacement(d => typeof(Building_Bed).IsAssignableFrom(d.thingClass), preAction: (n, o) => { Building_Bed newBed = n as Building_Bed; Building_Bed oldBed = o as Building_Bed; newBed.ForPrisoners = oldBed.ForPrisoners; newBed.Medical = oldBed.Medical; oldBed.OwnersForReading.ListFullCopy().ForEach(p => p.ownership.ClaimBedIfNonMedical(newBed)); } )); DesignationCategoryDef fencesDef = DefDatabase <DesignationCategoryDef> .GetNamed("Fences", false); if (fencesDef != null) { replacements.Add(new Replacement(d => d.designationCategory == fencesDef)); } Action <Thing, Thing> transferBills = (n, o) => { Building_WorkTable newTable = n as Building_WorkTable; Building_WorkTable oldTable = o as Building_WorkTable; foreach (Bill bill in oldTable.BillStack) { newTable.BillStack.AddBill(bill); } }; replacements.Add(new Replacement(d => d == NewThingDefOf.ElectricStove, n => n == NewThingDefOf.FueledStove, transferBills)); replacements.Add(new Replacement(d => d == NewThingDefOf.ElectricTailoringBench, n => n == NewThingDefOf.HandTailoringBench, transferBills)); replacements.Add(new Replacement(d => d.IsTable)); replacements.Add(new Replacement(d => d.thingClass == FridgeCompat.fridgeType, postAction: (n, o) => { FridgeCompat.DesiredTempInfo.SetValue(n, FridgeCompat.DesiredTempInfo.GetValue(o)); })); replacements.Add(new Replacement(d => d.building?.isSittable ?? false)); //--------------------------------------------- //--------------------------------------------- }
public override void ResolveReferences() { base.ResolveReferences(); resolvedCategory = DefDatabase<DesignationCategoryDef>.GetNamed(category); // load textures in main thread LongEventHandler.ExecuteWhenFinished(() => { resolvedIconTex = ContentFinder<Texture2D>.Get(iconTex); resolvedDragHighlightTex = ContentFinder<Texture2D>.Get(dragHighlightTex); }); }
public override void ResolveReferences() { base.ResolveReferences(); this.resolvedCategory = DefDatabase <DesignationCategoryDef> .GetNamed(this.category, true); LongEventHandler.ExecuteWhenFinished(delegate { this.resolvedIconTex = ContentFinder <Texture2D> .Get(this.iconTex, true); this.resolvedHighlightTex = MaterialPool.MatFrom(this.highlightTex); }); }
public override void ResolveReferences() { base.ResolveReferences(); resolvedCategory = DefDatabase <DesignationCategoryDef> .GetNamed(category); // load textures in main thread LongEventHandler.ExecuteWhenFinished(() => { resolvedIconTex = ContentFinder <Texture2D> .Get(iconTex); resolvedDragHighlightTex = ContentFinder <Texture2D> .Get(dragHighlightTex); }); }
static void CategorizeBuildings(DesignationCategoryDef cat) { foreach (var def in Core.ContentPack.AllDefs) { if (def is ThingDef td && typeof(Building).IsAssignableFrom(td.thingClass)) { if (td.designationCategory != null) { td.designationCategory = cat; } } } }
public static bool ChangeDesignationCategory(this ThingDef thingDef, string newCategory) { if (string.IsNullOrEmpty(newCategory)) { // Invalid category return(false); } if (thingDef.designationCategory == newCategory) { // Already this category return(true); } DesignationCategoryDef newCategoryDef = newCategory == "None" ? null : DefDatabase <DesignationCategoryDef> .GetNamed(newCategory, false); DesignationCategoryDef oldCategory = null; Designator_Build oldDesignator = null; if ( (!thingDef.designationCategory.NullOrEmpty()) && (thingDef.designationCategory != "None") ) { oldCategory = DefDatabase <DesignationCategoryDef> .GetNamed(thingDef.designationCategory); oldDesignator = (Designator_Build)oldCategory._resolvedDesignators().FirstOrDefault(d => ( (d is Designator_Build) && ((d as Designator_Build).PlacingDef == (BuildableDef)thingDef) )); } if (oldCategory != null) { oldCategory._resolvedDesignators().Remove(oldDesignator); } if (newCategoryDef != null) { Designator_Build newDesignator = null; if (oldDesignator != null) { newDesignator = oldDesignator; } else { newDesignator = (Designator_Build)Activator.CreateInstance(typeof(Designator_Build), new System.Object[] { (BuildableDef)thingDef }); } newCategoryDef._resolvedDesignators().Add(newDesignator); } thingDef.designationCategory = newCategory; return(true); }
public static void HideDesignator(Designator_Build des, DesignationCategoryDef cat = null) { if (des == null) { throw new ArgumentNullException(nameof(des)); } // get the entity def BuildableDef def = des.PlacingDef; // check for null if (def == null) { throw new Exception($"Tried to hide designator with NULL entDef ({des.Label}). Such designators should not exist."); } // if category wasn't explicitly set, assume it is the same as the def's if (cat == null) { cat = def.designationCategory; } // if still null, there's nothing to hide. if (cat == null) { throw new Exception($"Tried to hide designator from NULL category. That makes little sense."); } // make sure the designator is cached so we can still get it later if (!_designators.ContainsKey(def)) { _designators.Add(def, des); } // get the categories designators var resolved = cat.AllResolvedDesignators; // remove our designator if it was in there, throw a warning if it was not if (resolved.Contains(des)) { resolved.Remove(des); } else { Log.Warning($"Tried to remove designator {des.Label} from category {cat.label}, but it was not included in the categories' resolved designators."); } }
public static void MergeDesignationCategories(DesignationCategoryDef target, DesignationCategoryDef source) { Log.Warning($"ArchitectSense :: Merging {source.defName} with {target.defName}..."); // get both lists of resolved designators var sourceDesignators = source.AllResolvedDesignators; var targetDesignators = target.AllResolvedDesignators; // merge designators that did not yet exist into the target category foreach (Designator sourceDesignator in sourceDesignators) { if (!targetDesignators.Contains(sourceDesignator)) { targetDesignators.Add(sourceDesignator); } } RemoveDesignationCategory(source); }
public static void DefsLoaded() { // Log.Warning("LWM.deepstorag - defs loaded"); // Todo? If settings are different from defaults, then: // Def-related changes: //TODO: this should probably have an option.... if (defaultStoragePriority != StoragePriority.Important) { foreach (ThingDef d in AllDeepStorageUnits) { d.building.defaultStorageSettings.Priority = defaultStoragePriority; } } // Re-read Mod Settings - some won't have been read because Defs weren't loaded: // (do this after priority changes above to allow user to override changes) //todo: Utils.Mess(Utils.DBF.Settings, "Defs Loaded. About to re-load settings"); // NOTE/WARNING: the mod's settings' FolderName will be different for non-steam and steam versions. // Internally, they are loaded using: // this.modSettings = LoadedModManager // .ReadModSettings<T>(this.intContent.FolderName, base.GetType().Name); // So don't do this: // var s = LoadedModManager.ReadModSettings<Settings>("LWM.DeepStorage", "DeepStorageMod"); // Do this instead: var mod = LoadedModManager.GetMod(typeof(LWM.DeepStorage.DeepStorageMod)); Utils.Warn(Utils.DBF.Settings, "About to re-read mod settings from: " + GenText .SanitizeFilename(string.Format("Mod_{0}_{1}.xml", mod.Content.FolderName, "DeepStorageMod"))); var s = LoadedModManager.ReadModSettings <Settings>(mod.Content.FolderName, "DeepStorageMod"); // Architect Menu: if (architectMenuActualDef == null) { architectMenuActualDef = DefDatabase <DesignationCategoryDef> .GetNamed(architectMenuDefaultDesigCatDef); } if (architectMenuDesigCatDef != architectMenuDefaultDesigCatDef || architectMenuMoveALLStorageItems) // in which case, we need to redo menu anyway { ArchitectMenu_ChangeLocation(architectMenuDesigCatDef, true); } }
internal static Designator_Build FindDesignator(BuildableDef def, out DesignationCategoryDef cat_out) { #if DEBUG_HIDE_DEFS Controller.Logger.Message($"Trying to find {def.defName}"); #endif // cycle through all categories to try and find our designator foreach (DesignationCategoryDef cat in DefDatabase <DesignationCategoryDef> .AllDefsListForReading) { #if DEBUG_HIDE_DEFS Controller.Logger.Message($"Checking {cat.defName}, {cat.AllResolvedDesignators.Count} designators found."); #endif // check vanilla designators foreach (Designator_Build des in cat.AllResolvedDesignators.OfType <Designator_Build>()) { #if DEBUG_HIDE_DEFS Controller.Logger.Message($"Checking {des.Label}, for {des.PlacingDef.defName}"); #endif if (isForDef(des, def)) { cat_out = cat; return(des); } } // check our designation subcategories foreach ( Designator_SubCategory subcat in cat.AllResolvedDesignators.OfType <Designator_SubCategory>()) { foreach (Designator_SubCategoryItem subdes in subcat.SubDesignators) { if (isForDef(subdes, def)) { cat_out = cat; return(subdes); } } } } cat_out = null; return(null); }
// Setup stuff that needs to be run before settings can be used. // I don't risk using a static constructor because I must make sure defs have been finished loading. // (testing shows this is VERY correct!!) // There's probably some rimworld annotation that I could use, but this works: private static void Setup() { if (architectMenuActualDef == null) //Log.Message("LWM.DeepStorage Settings Setup() called first time"); { architectMenuActualDef = DefDatabase <DesignationCategoryDef> .GetNamed(architectMenuDefaultDesigCatDef); } if (!allDeepStorageUnits.NullOrEmpty()) { return; } allDeepStorageUnits = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(x => x.HasComp(typeof(CompDeepStorage))); Utils.Mess(Utils.DBF.Settings, " allDeepStorageUnits initialized: " + allDeepStorageUnits.Count + " units"); /* if (architectLWM_DS_Storage_DesignationCatDef==null) { * architectLWM_DS_Storage_DesignationCatDef=DefDatabase<DesignationCategoryDef>.GetNamed("LWM_DS_Storage"); * Utils.Mess(Utils.DBF.Settings, " Designation Category Def loaded: "+architectLWM_DS_Storage_DesignationCatDef); * }*/ }
/// <summary> /// Creates a subcategory based on subcategoryDef in categoryDef at position, containing elements buildableDefs. /// Position defaults to adding on the right. /// /// Note that if designators for the buildables in buildableDefs already exist, they will NOT be removed - this method /// creates NEW designators, and is primarily meant for mods that programatically generate defs. /// </summary> /// <param name="categoryDef"></param> /// <param name="subcategoryDef"></param> /// <param name="buildableDefs"></param> /// <param name="position"></param> public static void AddSubCategory(DesignationCategoryDef categoryDef, DesignationSubCategoryDef subcategoryDef, List <BuildableDef> buildableDefs, int position = -1) { // cop out on null if (categoryDef == null) { throw new ArgumentNullException(nameof(categoryDef)); } // get designation category's resolved designators List <Designator> resolvedDesignators = categoryDef.AllResolvedDesignators; // check position argument if (position > resolvedDesignators.Count) { throw new ArgumentOutOfRangeException(nameof(position)); } // hide existing designators foreach (BuildableDef def in buildableDefs) { HideDesignator(def); } // create subcategory var subcategory = new Designator_SubCategory(subcategoryDef, buildableDefs.Select(bd => new Designator_Build(bd)) .ToList()); // if no position is specified, add it at the end if (position < 0) { resolvedDesignators.Add(subcategory); } else { resolvedDesignators.Insert(position, subcategory); } }
public override void DefsLoaded() { LoadPlanDesDefs(); ModSettings = ModSettings.CreateModSettings(Settings); PlanColorManager.Load(Settings); SettingsChanged(); DesignationCategoryDef desCatDef = DefDatabase <DesignationCategoryDef> .GetNamed("Planning"); if (desCatDef == null) { throw new Exception("Planning designation category not found"); } FieldInfo designatorsFi = typeof(DesignationCategoryDef).GetField("resolvedDesignators", BindingFlags.NonPublic | BindingFlags.Instance); var designators = designatorsFi.GetValue(desCatDef) as List <Designator>; for (int i = 0; i < PlanColorManager.NumPlans; i++) { designators.Add(new SelectColorDesignator(i)); } }
/// <summary> /// Creates a subcategory based on subcategoryDef in categoryDef at position, containing elements thingDefs. /// Position defaults to adding on the right. /// /// Note that if designators for the things in thingDefs already exist, they will NOT be removed - this method /// creates NEW designators, and is primarily meant for mods that programatically generate defs. /// </summary> /// <param name="categoryDef"></param> /// <param name="subcategoryDef"></param> /// <param name="thingDefs"></param> /// <param name="position"></param> public static void AddSubCategory(DesignationCategoryDef categoryDef, DesignationSubCategoryDef subcategoryDef, List <ThingDef> thingDefs, int position = -1) { AddSubCategory(categoryDef, subcategoryDef, thingDefs.Select(def => def as BuildableDef).ToList(), position); }
public static List <Designator> _resolvedDesignators(this DesignationCategoryDef category) { return(_resolvedDesignatorsField.GetValue(category) as List <Designator>); }
public RA_ArchitectCategoryTab(DesignationCategoryDef def) : base(def) { }
private static int <CacheDesPanels> m__0(DesignationCategoryDef dc) { return(dc.order); }
private static void RemoveDesignationCategory(DesignationCategoryDef category) { (DefDatabase <DesignationCategoryDef> .AllDefs as List <DesignationCategoryDef>)?.Remove(category); RecacheDesignationCategories(); }
private static void RecacheDesignationCategory(DesignationCategoryDef category) { category.ResolveReferences(); // calls ResolveDesignators, recreating cache; }
/* * //MOVED TO STEADYATMOSPHEREEFFECTS * public void checkRandomTerrain() { * int num = Mathf.RoundToInt((float)this.map.Area * 0.0001f); * int area = this.map.Area; * for (int i = 0; i < num; i++) * { * if (this.cycleIndex >= area) * { * this.cycleIndex = 0; * } * IntVec3 c = this.map.cellsInRandomOrder.Get(this.cycleIndex); * this.doCellEnvironment(c); * * this.cycleIndex++; * } * * } */ public void doCellEnvironment(IntVec3 c) { if (!this.cellWeatherAffects.ContainsKey(c)) { return; } cellData cell = this.cellWeatherAffects[c]; TerrainDef currentTerrain = c.GetTerrain(this.map); Room room = c.GetRoom(this.map, RegionType.Set_All); bool roofed = this.map.roofGrid.Roofed(c); bool flag2 = room != null && room.UsesOutdoorTemperature; bool gettingWet = false; bool isMelt = false; //check if the terrain has been floored DesignationCategoryDef cats = currentTerrain.designationCategory; if (cats != null) { if (cats.defName == "Floors") { cell.baseTerrain = currentTerrain; } } //spawn special things if (Rand.Value < .0001f) { if (c.InBounds(this.map)) { string defName = ""; if (currentTerrain.defName == "TKKN_Lava") { defName = "TKKN_LavaRock"; } else if (currentTerrain.defName == "TKKN_LavaRock_RoughHewn" && this.map.Biome.defName == "TKKN_VolcanicFlow") { defName = "TKKN_SteamVent"; } if (defName != "") { Thing check = (Thing)(from t in c.GetThingList(this.map) where t.def.defName == defName select t).FirstOrDefault <Thing>(); if (check == null) { Thing thing = (Thing)ThingMaker.MakeThing(ThingDef.Named(defName), null); GenSpawn.Spawn(thing, c, map); } } } } #region Rain if (Settings.showRain && !roofed && this.map.weatherManager.curWeather.rainRate > .001f) { if (this.floodThreat < 1090000) { this.floodThreat += 1 + 2 * (int)Math.Round(this.map.weatherManager.curWeather.rainRate); } gettingWet = true; cell.setTerrain("wet"); } else { if (this.map.weatherManager.curWeather.rainRate == 0) { this.floodThreat--; } //DRY GROUND cell.setTerrain("dry"); } #endregion #region Cold bool isCold = this.checkIfCold(c); if (isCold) { cell.setTerrain("frozen"); } else { cell.setTerrain("thaw"); } #region Frost // if (c.x == 140) // { // Log.Error("Cell temp " + cell.temperature.ToString() + " frosty: " + (cell.temperature + -.025f).ToString() + " current depth" +this.map.GetComponent<FrostGrid>().GetDepth(c).ToString()); // } // Log.Error(c.ToString() + " ...... roofed:" + roofed.ToString() + " isCold:" + isCold.ToString() + " temp: " + this.map.mapTemperature.OutdoorTemp.ToString()); if (isCold) { //handle frost based on snowing if (!roofed && this.map.weatherManager.SnowRate > 0.001f) { this.map.GetComponent <FrostGrid>().AddDepth(c, this.map.weatherManager.SnowRate * -.01f); } else { CreepFrostAt(c, 0.46f * .3f, map); } } else { float frosty = cell.temperature * -.025f; // float frosty = this.map.mapTemperature.OutdoorTemp * -.03f; this.map.GetComponent <FrostGrid>().AddDepth(c, frosty); if (this.map.GetComponent <FrostGrid>().GetDepth(c) > .3f) { // cell.isMelt = true; } } #endregion /* MAKE THIS A WEATHER #region heat * Thing overlayHeat = (Thing)(from t in c.GetThingList(this.map) * where t.def.defName == "TKKN_HeatWaver" * select t).FirstOrDefault<Thing>(); * if (this.checkIfHot(c)) * { * if (overlayHeat == null && Settings.showHot) * { * Thing heat = ThingMaker.MakeThing(ThingDefOf.TKKN_HeatWaver, null); * GenSpawn.Spawn(heat, c, map); * } * } * else * { * if (overlayHeat != null) * { * overlayHeat.Destroy(); * } * } #endregion */ #region Puddles if (cell.howWet < 3 && Settings.showRain && (cell.isMelt || gettingWet)) { cell.howWet += 2; } else if (cell.howWet > -1) { cell.howWet--; } //PUDDLES Thing puddle = (Thing)(from t in c.GetThingList(this.map) where t.def.defName == "TKKN_FilthPuddle" select t).FirstOrDefault <Thing>(); if (cell.howWet == 3 && !isCold && this.MaxPuddles > this.totalPuddles && cell.currentTerrain.defName != "TKKN_SandBeachWetSalt") { if (puddle == null) { FilthMaker.MakeFilth(c, this.map, ThingDef.Named("TKKN_FilthPuddle"), 1); this.totalPuddles++; } } else if (cell.howWet <= 0 && puddle != null) { puddle.Destroy(); this.totalPuddles--; } cell.isMelt = false; #endregion /*CELL SHOULD BE HANDLING THIS NOW: * //since it changes, make sure the lava list is still good: * * if (currentTerrain.defName == "TKKN_Lava") { * this.lavaCellsList.Add(c); * } else { * this.lavaCellsList.Remove(c); * } */ this.cellWeatherAffects[c] = cell; }
public ArchitectCategoryTabCustomOffset(DesignationCategoryDef def) : base(def) { }
// Architect Menu: public static void ArchitectMenu_ChangeLocation(string newDefName, bool loadingOnStartup = false) { // Utils.Warn(Utils.DBF.Settings, "SettingsChanged()"); DesignationCategoryDef prevDesignationCatDef; if (loadingOnStartup) { prevDesignationCatDef = DefDatabase <DesignationCategoryDef> .GetNamed(architectMenuDefaultDesigCatDef); } else { prevDesignationCatDef = DefDatabase <DesignationCategoryDef> .GetNamed(architectMenuDesigCatDef, false); } // If switching to default, put default into def database. if (newDefName == architectMenuDefaultDesigCatDef) { ArchitectMenu_Show(); } // Compatibility Logic: // If certain mods are loaded and all storage units are to go in one menu, // maybe we want to remove the other menu? Or maybe we want to use that // one by default: // For Deep Storage, if the player also has Quantum Storage, use their menu insead: if (architectMenuMoveALLStorageItems && !architectMenuAlwaysShowCategory && newDefName == architectMenuDefaultDesigCatDef && ModLister.GetActiveModWithIdentifier("Cheetah.QuantumStorageRedux") != null) { newDefName = "QSRStorage"; } DesignationCategoryDef newDesignationCatDef = DefDatabase <DesignationCategoryDef> .GetNamed(newDefName); if (newDesignationCatDef == null) { Log.Warning("LWM.DeepStorage: Failed to find menu category " + newDefName + " - reverting to default"); newDefName = architectMenuDefaultDesigCatDef; ArchitectMenu_Show(); newDesignationCatDef = DefDatabase <DesignationCategoryDef> .GetNamed(newDefName); } // Architect Menu: Specify all your buildings/etc: // var allMyBuildings=DefDatabase<ThingDef>.AllDefsListForReading.FindAll(x=>x.HasComp(etc))); List <ThingDef> itemsToMove = LoadedDeepStorageUnits.ToList(); // We can move ALL the storage buildings! If the player wants. I do. List <DesignationCategoryDef> desigsToNotMove = new List <DesignationCategoryDef>(); List <DesignationCategoryDef> desigsToOnlyCopy = new List <DesignationCategoryDef>(); if (architectMenuMoveALLStorageItems) { // Log.Error("Trying to mvoe everythign:"); // Don't move hoppers, etc: desigsToNotMove.Add(DefDatabase <DesignationCategoryDef> .GetNamed("Production")); // Don't move Replimat either: // (hoppers, etc.) // Note that it's possible the ReplimatFeedTank should be copied to Storage, // but I think it's okay to leave it in Replimat. DesignationCategoryDef tmp = DefDatabase <DesignationCategoryDef> .GetNamed("Replimat_Replimat", false); if (tmp != null) { desigsToNotMove.Add(tmp); } // TODO: get these categories in a more flexible way! // ProjectRimFactory has several subclasses of Building_Storage that are in the Industrial category. // Several users of PRF have gotten confused when they couldn't find the storage things. DesignationCategoryDef industrialCategory = DefDatabase <DesignationCategoryDef> .GetNamed("Industrial", false); // So we COULD remove those storage buildings from our list too: // if (industrialCategory!=null) desigsToNotMove.Add(industrialCategory); // But, let's just copy them: if (industrialCategory != null) { desigsToOnlyCopy.Add(industrialCategory); } // Bonus PRF: DocWorld changes the designation from Industrial to DZ_Industrial. // Get them both: industrialCategory = DefDatabase <DesignationCategoryDef> .GetNamed("DZ_Industrial", false); if (industrialCategory != null) { desigsToOnlyCopy.Add(industrialCategory); } // Interesting detail: apparently it IS possible to have thingDefs with null thingClass... weird. itemsToMove = DefDatabase <ThingDef> .AllDefsListForReading .FindAll(x => ((x?.thingClass != null) && (x.thingClass == typeof(Building_Storage) || x.thingClass.IsSubclassOf(typeof(Building_Storage))) && x.designationCategory != null && !desigsToNotMove.Contains(x.designationCategory) //&& !toCopy.Contains(x.designationCategory) )); /*if (ModLister.GetActiveModWithIdentifier("spdskatr.projectrimfactory")!=null) { * if (industrialCategory==null) { * Log.Warning("LWM.DeepStorage: menu compatibility with Project RimFactory failed: could not find Industrial cat"); * } else { * * } * }*/ // testing: // itemsToMove.AddRange(DefDatabase<ThingDef>.AllDefsListForReading.FindAll(x=>x.defName.Contains("MURWallLight"))); } Utils.Mess(Utils.DBF.Settings, "Moving these units to 'Storage' menu: " + string.Join(", ", itemsToMove)); // get access to a DesignationCategoryDef's resolvedDesignators: var _resolvedDesignatorsField = typeof(DesignationCategoryDef) .GetField("resolvedDesignators", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); foreach (var d in itemsToMove) { if (d.designationCategory == null) { continue; // very very possible } // Log.Error("Moving item "+d.defName+" (category: "+(d.designationCategory!=null?d.designationCategory.ToString():"NONE")); List <Designator> resolvedDesignators = (List <Designator>)_resolvedDesignatorsField.GetValue(d.designationCategory); if (d.designatorDropdown == null) { // Log.Message("No dropdown"); // easy case: // Old menu location: if (!desigsToOnlyCopy.Contains(d.designationCategory)) { // Log.Message(" Removed this many entries in "+d.designationCategory+": "+ resolvedDesignators.RemoveAll(x => ((x is Designator_Build) && ((Designator_Build)x).PlacingDef == d)); } // ); // Now do new: resolvedDesignators = (List <Designator>)_resolvedDesignatorsField.GetValue(newDesignationCatDef); // To make sure there are no duplicates: resolvedDesignators.RemoveAll(x => ((x is Designator_Build) && ((Designator_Build)x).PlacingDef == d)); resolvedDesignators.Add(new Designator_Build(d)); } else { // Log.Warning("LWM.DeepStorage: ThingDef "+d.defName+" has a dropdown Designator."); // Hard case: Designator_Dropdowns! Designator_Dropdown dd = (Designator_Dropdown)resolvedDesignators.Find(x => (x is Designator_Dropdown) && ((Designator_Dropdown)x).Elements .Find(y => (y is Designator_Build) && ((Designator_Build)y).PlacingDef == d) != null); if (dd != null) { // Log.Message("Found dropdown designator for "+d.defName); if (!desigsToOnlyCopy.Contains(d.designationCategory)) { resolvedDesignators.Remove(dd); } // Switch to new category: resolvedDesignators = (List <Designator>)_resolvedDesignatorsField.GetValue(newDesignationCatDef); if (!resolvedDesignators.Contains(dd)) { // Log.Message(" Adding to new category "+newDesignationCatDef); resolvedDesignators.Add(dd); } // } else { //debug // Log.Message(" ThingDef "+d.defName+" has designator_dropdown "+d.designatorDropdown.defName+ // ", but cannot find it in "+d.designationCategory+" - this is okay if something else added it."); } } d.designationCategory = newDesignationCatDef; } // Flush designation category defs:.....dammit // foreach (var x in DefDatabase<DesignationCategoryDef>.AllDefs) { // x.ResolveReferences(); // } // prevDesignationCatDef?.ResolveReferences(); // newDesignationCatDef.ResolveReferences(); //ArchitectMenu_ClearCache(); // we do this later one way or another // To remove the mod's DesignationCategoryDef from Architect menu: // remove it from RimWorld.MainTabWindow_Architect's desPanelsCached. // To do that, we remove it from the DefDatabase and then rebuild the cache. // Removing only the desPanelsCached entry does work: the entry is // recreated when a new game is started. So if the options are changed // and then a new game started...the change gets lost. // So we have to update the DefsDatabase. // This is potentially difficult: the .index can get changed, and that // can cause problems. But nothing seems to use the .index for any // DesignationCategoryDef except for the menu, so manually adjusting // the DefsDatabase is safe enough: if (!architectMenuAlwaysShowCategory && newDefName != architectMenuDefaultDesigCatDef) { ArchitectMenu_Hide(); // ArchitectMenu_ClearCache(); //hide flushes cache // if (tmp.AllResolvedDesignators.Count <= tmp.specialDesignatorClasses.Count) // isCategoryEmpty=false; /* * // Log.Message("Removing old menu!"); * // DefDatabase<DesignationCategoryDef>.Remove(tmp); * if (!tmp.AllResolvedDesignators.NullOrEmpty()) { * foreach (var d in tmp.AllResolvedDesignators) { * if (!tmp.specialDesignatorClasses.Contains(d)) { * isCategoryEmpty=false; * break; * } * } * } */ // if (isCategoryEmpty) } else { // Simply flush cache: ArchitectMenu_ClearCache(); } // Note that this is not perfect: if the default menu was already open, it will still be open (and // empty) when the settings windows are closed. Whatever. // Oh, and actually change the setting that's stored: architectMenuDesigCatDef = newDefName; // Finally, if Extended Storage(!) is loaded, and we took all their // storage items, remove their menu as well: DesignationCategoryDef tmpD; if (ModLister.HasActiveModWithName("Extended Storage") && ((tmpD = DefDatabase <DesignationCategoryDef> .GetNamed("FurnitureStorage", false)) != null) && !architectMenuAlwaysShowCategory && architectMenuDesigCatDef != "FurnitureStorage") { // DefDatabase<DesignationCategoryDef>.Remove(tmpD); typeof(DefDatabase <>).MakeGenericType(new Type[] { typeof(DesignationCategoryDef) }) .GetMethod("Remove", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) .Invoke(null, new object [] { tmpD }); } /* List<ArchitectCategoryTab> archMenu=(List<ArchitectCategoryTab>)Harmony.AccessTools * .Field(typeof(RimWorld.MainTabWindow_Architect), "desPanelsCached") * .GetValue((MainTabWindow_Architect)MainButtonDefOf.Architect.TabWindow); * archMenu.RemoveAll(t=>t.def.defName==architectMenuDefaultDesigCatDef); * * archMenu.Add(new ArchitectCategoryTab(newDesignationCatDef)); * archMenu.Sort((a,b)=>a.def.order.CompareTo(b.def.order)); * archMenu.SortBy(a=>a.def.order, b=>b.def.order); // May need (type of var a)=>... * */ /* Harmony.AccessTools.Method(typeof(RimWorld.MainTabWindow_Architect), "CacheDesPanels") * .Invoke(((MainTabWindow_Architect)MainButtonDefOf.Architect.TabWindow), null);*/ /* * * if (architectMenuDesignationCatDefDefName=="LWM_DS_Storage") { // default * if (DefDatabase<DesignationCategoryDef>.GetNamedSilentFail("LWM_DS_Storage") == null) { * Utils.Mess(Utils.DBF.Settings,"Adding 'Storage' to the architect menu."); * DefDatabase<DesignationCategoryDef>.Add(architectLWM_DS_Storage_DesignationCatDef); * } else { * Utils.Mess(Utils.DBF.Settings, "No need to add 'Storage' to the architect menu."); * } * architectCurrentDesignationCatDef=architectLWM_DS_Storage_DesignationCatDef; * } else { * // remove our "Storage" from the architect menu: * Utils.Mess(Utils.DBF.Settings,"Removing 'Storage' from the architect menu."); * DefDatabase<DesignationCategoryDef>.AllDefsListForReading.Remove(architectLWM_DS_Storage_DesignationCatDef); * if (DefDatabase<DesignationCategoryDef>.GetNamedSilentFail("LWM_DS_Storage") != null) { * Log.Error("Failed to remove LWM_DS_Storage :("+DefDatabase<DesignationCategoryDef>.GetNamedSilentFail("LWM_DS_Storage")); * } * * architectCurrentDesignationCatDef=DefDatabase<DesignationCategoryDef>.GetNamed(architectMenuDesignationCatDefDefName); * } * prevDesignationCatDef?.ResolveReferences(); * architectCurrentDesignationCatDef.ResolveReferences(); * * Harmony.AccessTools.Method(typeof(RimWorld.MainTabWindow_Architect), "CacheDesPanels") * .Invoke((), null); */ Utils.Warn(Utils.DBF.Settings, "Settings changed architect menu"); }
public Dialog_RenameTab(DesignationCategoryDef designationTab) { tab = designationTab; curName = designationTab.label; }
public ArchitectCategoryTab(DesignationCategoryDef def) { this.def = def; }
public void doCellEnvironment(IntVec3 c) { if (!this.cellWeatherAffects.ContainsKey(c)) { return; } cellData cell = this.cellWeatherAffects[c]; cell.DoCellSteadyEffects(); if (this.ticks % 2 == 0) { cell.unpack(); } TerrainDef currentTerrain = c.GetTerrain(this.map); Room room = c.GetRoom(this.map, RegionType.Set_All); bool roofed = this.map.roofGrid.Roofed(c); bool flag2 = room != null && room.UsesOutdoorTemperature; bool gettingWet = false; cell.gettingWet = false; //check if the terrain has been floored DesignationCategoryDef cats = currentTerrain.designationCategory; if (cats != null) { if (cats.defName == "Floors") { cell.baseTerrain = currentTerrain; } } //spawn special things if (Rand.Value < .0001f) { if (c.InBounds(this.map)) { string defName = ""; if (currentTerrain.defName == "TKKN_Lava") { defName = "TKKN_LavaRock"; } else if (currentTerrain.defName == "TKKN_LavaRock_RoughHewn" && this.map.Biome.defName == "TKKN_VolcanicFlow") { defName = "TKKN_SteamVent"; } if (defName != "") { Thing check = (Thing)(from t in c.GetThingList(this.map) where t.def.defName == defName select t).FirstOrDefault <Thing>(); if (check == null) { Thing thing = (Thing)ThingMaker.MakeThing(ThingDef.Named(defName), null); GenSpawn.Spawn(thing, c, map); } } } } #region Rain if (Settings.showRain && !cell.currentTerrain.HasTag("TKKN_Wet")) { //if it's raining in this cell: if (!roofed && this.map.weatherManager.curWeather.rainRate > .0001f) { if (this.floodThreat < 1090000) { this.floodThreat += 1 + 2 * (int)Math.Round(this.map.weatherManager.curWeather.rainRate); } gettingWet = true; cell.gettingWet = true; cell.setTerrain("wet"); } else if (Settings.showRain && !roofed && this.map.weatherManager.curWeather.snowRate > .001f) { gettingWet = true; cell.gettingWet = true; cell.setTerrain("wet"); } else { if (this.map.weatherManager.curWeather.rainRate == 0) { this.floodThreat--; } //DRY GROUND cell.setTerrain("dry"); } } #endregion #region Cold bool isCold = this.checkIfCold(c); if (isCold) { cell.setTerrain("frozen"); } else { cell.setTerrain("thaw"); } #region Frost if (isCold) { //handle frost based on snowing if (!roofed && this.map.weatherManager.SnowRate > 0.001f) { this.map.GetComponent <FrostGrid>().AddDepth(c, this.map.weatherManager.SnowRate * -.01f); } else { CreepFrostAt(c, 0.46f * .3f, map); } } else { float frosty = cell.temperature * -.025f; // float frosty = this.map.mapTemperature.OutdoorTemp * -.03f; this.map.GetComponent <FrostGrid>().AddDepth(c, frosty); if (this.map.GetComponent <FrostGrid>().GetDepth(c) > .3f) { // cell.isMelt = true; } } #endregion #region plant damage //HANDLE PLANT DAMAGES: if (gettingWet) { //note - removed ismelt because the dirt shouldn't dry out in winter, and snow wets the ground then. if (cell.howWetPlants < (float)100) { if (this.map.weatherManager.curWeather.rainRate > 0) { cell.howWetPlants += this.map.weatherManager.curWeather.rainRate * 2; } else if (this.map.weatherManager.curWeather.snowRate > 0) { cell.howWetPlants += this.map.weatherManager.curWeather.snowRate * 2; } } } else { if (this.map.mapTemperature.OutdoorTemp > 20) { cell.howWetPlants += -1 * ((this.map.mapTemperature.OutdoorTemp / humidity) / 10); if (cell.howWetPlants <= 0) { if (cell.currentTerrain.HasModExtension <TerrainWeatherReactions>()) { TerrainWeatherReactions weather = cell.currentTerrain.GetModExtension <TerrainWeatherReactions>(); if (weather.dryTerrain == null) { //only hurt plants on terrain that's not wet. this.hurtPlants(c, false, true); } } else { this.hurtPlants(c, false, true); } } } } #endregion /* MAKE THIS A WEATHER #region heat * Thing overlayHeat = (Thing)(from t in c.GetThingList(this.map) * where t.def.defName == "TKKN_HeatWaver" * select t).FirstOrDefault<Thing>(); * if (this.checkIfHot(c)) * { * if (overlayHeat == null && Settings.showHot) * { * Thing heat = ThingMaker.MakeThing(ThingDefOf.TKKN_HeatWaver, null); * GenSpawn.Spawn(heat, c, map); * } * } * else * { * if (overlayHeat != null) * { * overlayHeat.Destroy(); * } * } #endregion */ #region Puddles if (cell.howWet < 3 && Settings.showRain && (cell.isMelt || gettingWet)) { cell.howWet += 2; } else if (cell.howWet > -1) { cell.howWet--; } //PUDDLES Thing puddle = (Thing)(from t in c.GetThingList(this.map) where t.def.defName == "TKKN_FilthPuddle" select t).FirstOrDefault <Thing>(); if (cell.howWet == 3 && !isCold && this.MaxPuddles > this.totalPuddles && cell.currentTerrain.defName != "TKKN_SandBeachWetSalt") { if (puddle == null) { FilthMaker.MakeFilth(c, this.map, ThingDef.Named("TKKN_FilthPuddle"), 1); this.totalPuddles++; } } else if (cell.howWet <= 0 && puddle != null) { puddle.Destroy(); this.totalPuddles--; } cell.isMelt = false; #endregion /*CELL SHOULD BE HANDLING THIS NOW: * //since it changes, make sure the lava list is still good: * * if (currentTerrain.defName == "TKKN_Lava") { * this.lavaCellsList.Add(c); * } else { * this.lavaCellsList.Remove(c); * } */ this.cellWeatherAffects[c] = cell; }