public static void Look <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs) { if (lookMode == LookMode.Undefined) { if (ParseHelper.HandlesType(typeof(T))) { lookMode = LookMode.Value; } else if (typeof(T) == typeof(LocalTargetInfo)) { lookMode = LookMode.LocalTargetInfo; } else if (typeof(T) == typeof(TargetInfo)) { lookMode = LookMode.TargetInfo; } else if (typeof(T) == typeof(GlobalTargetInfo)) { lookMode = LookMode.GlobalTargetInfo; } else if (typeof(Def).IsAssignableFrom(typeof(T))) { lookMode = LookMode.Def; } else if (typeof(T) == typeof(BodyPartRecord)) { lookMode = LookMode.BodyPart; } else { if (!typeof(IExposable).IsAssignableFrom(typeof(T)) || typeof(ILoadReferenceable).IsAssignableFrom(typeof(T))) { Log.Error("LookList call with a list of " + typeof(T) + " must have lookMode set explicitly."); return; } lookMode = LookMode.Deep; } } if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving) { if (list == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { foreach (T item8 in list) { switch (lookMode) { case LookMode.Value: { T value5 = item8; Scribe_Values.Look(ref value5, "li", default(T), forceSave: true); break; } case LookMode.LocalTargetInfo: { LocalTargetInfo value4 = (LocalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value4, saveDestroyedThings, "li"); break; } case LookMode.TargetInfo: { TargetInfo value3 = (TargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value3, saveDestroyedThings, "li"); break; } case LookMode.GlobalTargetInfo: { GlobalTargetInfo value2 = (GlobalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value2, saveDestroyedThings, "li"); break; } case LookMode.Def: { Def value = (Def)(object)item8; Scribe_Defs.Look(ref value, "li"); break; } case LookMode.BodyPart: { BodyPartRecord part = (BodyPartRecord)(object)item8; Scribe_BodyParts.Look(ref part, "li"); break; } case LookMode.Deep: { T target = item8; Scribe_Deep.Look(ref target, saveDestroyedThings, "li", ctorArgs); break; } case LookMode.Reference: { ILoadReferenceable refee = (ILoadReferenceable)(object)item8; Scribe_References.Look(ref refee, "li", saveDestroyedThings); break; } } } } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlNode curXmlParent = Scribe.loader.curXmlParent; XmlAttribute xmlAttribute = curXmlParent.Attributes["IsNull"]; if (xmlAttribute == null || !(xmlAttribute.Value.ToLower() == "true")) { switch (lookMode) { case LookMode.Value: { list = new List <T>(curXmlParent.ChildNodes.Count); IEnumerator enumerator3 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator3.MoveNext()) { XmlNode subNode = (XmlNode)enumerator3.Current; T item = ScribeExtractor.ValueFromNode(subNode, default(T)); list.Add(item); } } finally { IDisposable disposable2; if ((disposable2 = (enumerator3 as IDisposable)) != null) { disposable2.Dispose(); } } break; } case LookMode.Deep: { list = new List <T>(curXmlParent.ChildNodes.Count); IEnumerator enumerator9 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator9.MoveNext()) { XmlNode subNode3 = (XmlNode)enumerator9.Current; T item7 = ScribeExtractor.SaveableFromNode <T>(subNode3, ctorArgs); list.Add(item7); } } finally { IDisposable disposable8; if ((disposable8 = (enumerator9 as IDisposable)) != null) { disposable8.Dispose(); } } break; } case LookMode.Def: { list = new List <T>(curXmlParent.ChildNodes.Count); IEnumerator enumerator8 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator8.MoveNext()) { XmlNode subNode2 = (XmlNode)enumerator8.Current; T item6 = ScribeExtractor.DefFromNodeUnsafe <T>(subNode2); list.Add(item6); } } finally { IDisposable disposable7; if ((disposable7 = (enumerator8 as IDisposable)) != null) { disposable7.Dispose(); } } break; } case LookMode.BodyPart: { list = new List <T>(curXmlParent.ChildNodes.Count); int num4 = 0; IEnumerator enumerator7 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator7.MoveNext()) { XmlNode node4 = (XmlNode)enumerator7.Current; T item5 = (T)(object)ScribeExtractor.BodyPartFromNode(node4, num4.ToString(), null); list.Add(item5); num4++; } } finally { IDisposable disposable6; if ((disposable6 = (enumerator7 as IDisposable)) != null) { disposable6.Dispose(); } } break; } case LookMode.LocalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num3 = 0; IEnumerator enumerator6 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator6.MoveNext()) { XmlNode node3 = (XmlNode)enumerator6.Current; LocalTargetInfo localTargetInfo = ScribeExtractor.LocalTargetInfoFromNode(node3, num3.ToString(), LocalTargetInfo.Invalid); T item4 = (T)(object)localTargetInfo; list.Add(item4); num3++; } } finally { IDisposable disposable5; if ((disposable5 = (enumerator6 as IDisposable)) != null) { disposable5.Dispose(); } } break; } case LookMode.TargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num2 = 0; IEnumerator enumerator5 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator5.MoveNext()) { XmlNode node2 = (XmlNode)enumerator5.Current; TargetInfo targetInfo = ScribeExtractor.TargetInfoFromNode(node2, num2.ToString(), TargetInfo.Invalid); T item3 = (T)(object)targetInfo; list.Add(item3); num2++; } } finally { IDisposable disposable4; if ((disposable4 = (enumerator5 as IDisposable)) != null) { disposable4.Dispose(); } } break; } case LookMode.GlobalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num = 0; IEnumerator enumerator4 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator4.MoveNext()) { XmlNode node = (XmlNode)enumerator4.Current; GlobalTargetInfo globalTargetInfo = ScribeExtractor.GlobalTargetInfoFromNode(node, num.ToString(), GlobalTargetInfo.Invalid); T item2 = (T)(object)globalTargetInfo; list.Add(item2); num++; } } finally { IDisposable disposable3; if ((disposable3 = (enumerator4 as IDisposable)) != null) { disposable3.Dispose(); } } break; } case LookMode.Reference: { List <string> list2 = new List <string>(curXmlParent.ChildNodes.Count); IEnumerator enumerator2 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator2.MoveNext()) { XmlNode xmlNode = (XmlNode)enumerator2.Current; list2.Add(xmlNode.InnerText); } } finally { IDisposable disposable; if ((disposable = (enumerator2 as IDisposable)) != null) { disposable.Dispose(); } } Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(list2, string.Empty); break; } } } else { list = null; } } else if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { switch (lookMode) { case LookMode.Reference: list = Scribe.loader.crossRefs.TakeResolvedRefList <T>(string.Empty); break; case LookMode.LocalTargetInfo: if (list != null) { for (int j = 0; j < list.Count; j++) { list[j] = (T)(object)ScribeExtractor.ResolveLocalTargetInfo((LocalTargetInfo)(object)list[j], j.ToString()); } } break; case LookMode.TargetInfo: if (list != null) { for (int k = 0; k < list.Count; k++) { list[k] = (T)(object)ScribeExtractor.ResolveTargetInfo((TargetInfo)(object)list[k], k.ToString()); } } break; case LookMode.GlobalTargetInfo: if (list != null) { for (int i = 0; i < list.Count; i++) { list[i] = (T)(object)ScribeExtractor.ResolveGlobalTargetInfo((GlobalTargetInfo)(object)list[i], i.ToString()); } } break; } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, label); } list = null; } }
public static bool ShouldCheckMissingInjection(string str, FieldInfo fi, Def def) { return(!def.generated && !str.NullOrEmpty() && !fi.HasAttribute <NoTranslateAttribute>() && !fi.HasAttribute <UnsavedAttribute>() && !fi.HasAttribute <MayTranslateAttribute>() && (fi.HasAttribute <MustTranslateAttribute>() || str.Contains(' '))); }
private static void ForEachPossibleDefInjectionInDefRecursive(object obj, string curNormalizedPath, string curSuggestedPath, HashSet <object> visited, bool translationAllowed, Def def, PossibleDefInjectionTraverser action) { if (obj != null && (obj.GetType().IsValueType || !visited.Contains(obj))) { visited.Add(obj); foreach (FieldInfo item in FieldsInDeterministicOrder(obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))) { object value = item.GetValue(obj); bool flag = translationAllowed && !item.HasAttribute <NoTranslateAttribute>() && !item.HasAttribute <UnsavedAttribute>(); if (!(value is Def)) { if (typeof(string).IsAssignableFrom(item.FieldType)) { string currentValue = (string)value; string text = curNormalizedPath + "." + item.Name; string suggestedPath = curSuggestedPath + "." + item.Name; if (TKeySystem.TrySuggestTKeyPath(text, out string tKeyPath)) { suggestedPath = tKeyPath; } action(suggestedPath, text, isCollection: false, currentValue, null, flag, fullListTranslationAllowed: false, item, def); } else if (value is IEnumerable <string> ) { IEnumerable <string> currentValueCollection = (IEnumerable <string>)value; bool flag2 = item.HasAttribute <TranslationCanChangeCountAttribute>(); string text2 = curNormalizedPath + "." + item.Name; string suggestedPath2 = curSuggestedPath + "." + item.Name; if (TKeySystem.TrySuggestTKeyPath(text2, out string tKeyPath2)) { suggestedPath2 = tKeyPath2; } action(suggestedPath2, text2, isCollection: true, null, currentValueCollection, flag, flag && flag2, item, def); } else if (value is IEnumerable) { IEnumerable enumerable = (IEnumerable)value; int num = 0; foreach (object item2 in enumerable) { if (item2 != null && !(item2 is Def) && GenTypes.IsCustomType(item2.GetType())) { string text3 = TranslationHandleUtility.GetBestHandleWithIndexForListElement(enumerable, item2); if (text3.NullOrEmpty()) { text3 = num.ToString(); } string curNormalizedPath2 = curNormalizedPath + "." + item.Name + "." + num; string curSuggestedPath2 = curSuggestedPath + "." + item.Name + "." + text3; ForEachPossibleDefInjectionInDefRecursive(item2, curNormalizedPath2, curSuggestedPath2, visited, flag, def, action); } num++; } } else if (value != null && GenTypes.IsCustomType(value.GetType())) { string curNormalizedPath3 = curNormalizedPath + "." + item.Name; string curSuggestedPath3 = curSuggestedPath + "." + item.Name; ForEachPossibleDefInjectionInDefRecursive(value, curNormalizedPath3, curSuggestedPath3, visited, flag, def, action); } } } } }
public static void ParseAndProcessXML(XmlDocument xmlDoc, Dictionary <XmlNode, LoadableXmlAsset> assetlookup) { XmlNodeList childNodes = xmlDoc.DocumentElement.ChildNodes; List <XmlNode> list = new List <XmlNode>(); foreach (object item in childNodes) { list.Add(item as XmlNode); } DeepProfiler.Start("Loading asset nodes " + list.Count); try { for (int i = 0; i < list.Count; i++) { if (list[i].NodeType == XmlNodeType.Element) { LoadableXmlAsset value = null; DeepProfiler.Start("assetlookup.TryGetValue"); try { assetlookup.TryGetValue(list[i], out value); } finally { DeepProfiler.End(); } DeepProfiler.Start("XmlInheritance.TryRegister"); try { XmlInheritance.TryRegister(list[i], value?.mod); } finally { DeepProfiler.End(); } } } } finally { DeepProfiler.End(); } DeepProfiler.Start("XmlInheritance.Resolve()"); try { XmlInheritance.Resolve(); } finally { DeepProfiler.End(); } runningMods.FirstOrDefault(); DeepProfiler.Start("Loading defs for " + list.Count + " nodes"); try { foreach (XmlNode item2 in list) { LoadableXmlAsset loadableXmlAsset = assetlookup.TryGetValue(item2); Def def = DirectXmlLoader.DefFromNode(item2, loadableXmlAsset); if (def != null) { ModContentPack modContentPack = loadableXmlAsset?.mod; if (modContentPack != null) { modContentPack.AddDef(def, loadableXmlAsset.name); } else { patchedDefs.Add(def); } } } } finally { DeepProfiler.End(); } }
public Dialog_InfoCard(ThingDef thingDef, ThingDef stuff) { this.def = thingDef; this.stuff = stuff; this.Setup(); }
public static void Look <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs) { if (lookMode == LookMode.Undefined && !Scribe_Universal.TryResolveLookMode(typeof(T), out lookMode)) { Log.Error("LookList call with a list of " + typeof(T) + " must have lookMode set explicitly."); } else if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving) { if (list == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { foreach (T item8 in list) { switch (lookMode) { case LookMode.Value: { T value5 = item8; Scribe_Values.Look(ref value5, "li", default(T), forceSave: true); break; } case LookMode.LocalTargetInfo: { LocalTargetInfo value4 = (LocalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value4, saveDestroyedThings, "li"); break; } case LookMode.TargetInfo: { TargetInfo value3 = (TargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value3, saveDestroyedThings, "li"); break; } case LookMode.GlobalTargetInfo: { GlobalTargetInfo value2 = (GlobalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value2, saveDestroyedThings, "li"); break; } case LookMode.Def: { Def value = (Def)(object)item8; Scribe_Defs.Look(ref value, "li"); break; } case LookMode.BodyPart: { BodyPartRecord part = (BodyPartRecord)(object)item8; Scribe_BodyParts.Look(ref part, "li"); break; } case LookMode.Deep: { T target = item8; Scribe_Deep.Look(ref target, saveDestroyedThings, "li", ctorArgs); break; } case LookMode.Reference: { ILoadReferenceable refee = (ILoadReferenceable)(object)item8; Scribe_References.Look(ref refee, "li", saveDestroyedThings); break; } } } } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlNode curXmlParent = Scribe.loader.curXmlParent; XmlAttribute xmlAttribute = curXmlParent.Attributes["IsNull"]; if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true") { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, null); } list = null; } else { switch (lookMode) { case LookMode.Value: list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode in curXmlParent.ChildNodes) { T item = ScribeExtractor.ValueFromNode(childNode, default(T)); list.Add(item); } break; case LookMode.Deep: list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode2 in curXmlParent.ChildNodes) { T item7 = ScribeExtractor.SaveableFromNode <T>(childNode2, ctorArgs); list.Add(item7); } break; case LookMode.Def: list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode3 in curXmlParent.ChildNodes) { T item6 = ScribeExtractor.DefFromNodeUnsafe <T>(childNode3); list.Add(item6); } break; case LookMode.BodyPart: { list = new List <T>(curXmlParent.ChildNodes.Count); int num4 = 0; foreach (XmlNode childNode4 in curXmlParent.ChildNodes) { T item5 = (T)(object)ScribeExtractor.BodyPartFromNode(childNode4, num4.ToString(), null); list.Add(item5); num4++; } break; } case LookMode.LocalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num3 = 0; foreach (XmlNode childNode5 in curXmlParent.ChildNodes) { T item4 = (T)(object)ScribeExtractor.LocalTargetInfoFromNode(childNode5, num3.ToString(), LocalTargetInfo.Invalid); list.Add(item4); num3++; } break; } case LookMode.TargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num2 = 0; foreach (XmlNode childNode6 in curXmlParent.ChildNodes) { T item3 = (T)(object)ScribeExtractor.TargetInfoFromNode(childNode6, num2.ToString(), TargetInfo.Invalid); list.Add(item3); num2++; } break; } case LookMode.GlobalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num = 0; foreach (XmlNode childNode7 in curXmlParent.ChildNodes) { T item2 = (T)(object)ScribeExtractor.GlobalTargetInfoFromNode(childNode7, num.ToString(), GlobalTargetInfo.Invalid); list.Add(item2); num++; } break; } case LookMode.Reference: { List <string> list2 = new List <string>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode8 in curXmlParent.ChildNodes) { list2.Add(childNode8.InnerText); } Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(list2, ""); break; } } } } else if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { switch (lookMode) { case LookMode.Reference: list = Scribe.loader.crossRefs.TakeResolvedRefList <T>(""); break; case LookMode.LocalTargetInfo: if (list != null) { for (int j = 0; j < list.Count; j++) { list[j] = (T)(object)ScribeExtractor.ResolveLocalTargetInfo((LocalTargetInfo)(object)list[j], j.ToString()); } } break; case LookMode.TargetInfo: if (list != null) { for (int k = 0; k < list.Count; k++) { list[k] = (T)(object)ScribeExtractor.ResolveTargetInfo((TargetInfo)(object)list[k], k.ToString()); } } break; case LookMode.GlobalTargetInfo: if (list != null) { for (int i = 0; i < list.Count; i++) { list[i] = (T)(object)ScribeExtractor.ResolveGlobalTargetInfo((GlobalTargetInfo)(object)list[i], i.ToString()); } } break; } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, label); } list = null; } }
public static IEnumerable <Def> AllDefsFromAsset(LoadableXmlAsset asset) { if (DirectXmlLoader.loadingAsset != null) { Log.Error("Tried to load " + asset + " while loading " + DirectXmlLoader.loadingAsset + ". This will corrupt the internal state of DataLoader."); } if (asset.xmlDoc != null) { DirectXmlLoader.loadingAsset = asset; XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.ChildNodes; bool gotData = false; IEnumerator enumerator = assetNodes.GetEnumerator(); try { while (enumerator.MoveNext()) { XmlNode node = (XmlNode)enumerator.Current; if (node.NodeType == XmlNodeType.Element) { XmlAttribute abstractAtt = node.Attributes["Abstract"]; if (abstractAtt != null && abstractAtt.Value.ToLower() == "true") { gotData = true; } else { Type defType = GenTypes.GetTypeInAnyAssembly(node.Name); if (defType != null && typeof(Def).IsAssignableFrom(defType)) { MethodInfo method = typeof(DirectXmlToObject).GetMethod("ObjectFromXml"); MethodInfo gen = method.MakeGenericMethod(defType); Def def = null; try { def = (Def)gen.Invoke(null, new object[2] { node, true }); gotData = true; } catch (Exception ex) { Log.Error("Exception loading def from file " + asset.name + ": " + ex); } if (def != null) { yield return(def); /*Error: Unable to find new state assignment for yield return*/; } } } } } } finally { IDisposable disposable; IDisposable disposable2 = disposable = (enumerator as IDisposable); if (disposable != null) { disposable2.Dispose(); } } if (!gotData) { Log.Error("Found no usable data when trying to get defs from file " + asset.name); } DirectXmlLoader.loadingAsset = null; } yield break; IL_02e2: /*Error near IL_02e3: Unexpected return in MoveNext()*/; }
public override void DoWindowContents(Rect selectorInner) { Text.Font = GameFont.Tiny; float width = (selectorInner.width - 4f) / 2f; Rect rect = new Rect(0f, 0f, width, 24f); string str = this.curMod.ToString(); if (Widgets.ButtonText(rect, "Editing: " + str, true, false, true)) { Messages.Message("Mod changing not implemented - it's always Core for now.", MessageTypeDefOf.RejectInput, false); } TooltipHandler.TipRegion(rect, "Change the mod being edited."); Rect rect2 = new Rect(rect.xMax + 4f, 0f, width, 24f); string label = "No package loaded"; if (this.curPackage != null) { label = this.curPackage.fileName; } if (Widgets.ButtonText(rect2, label, true, false, true)) { Find.WindowStack.Add(new Dialog_PackageSelector(delegate(DefPackage pack) { if (pack != this.curPackage) { this.curPackage = pack; } }, this.curMod, this.relFolder)); } TooltipHandler.TipRegion(rect2, "Open a Def package for editing."); WidgetRow widgetRow = new WidgetRow(0f, 28f, UIDirection.RightThenUp, 99999f, 4f); if (widgetRow.ButtonIcon(TexButton.NewFile, "Create a new Def package.", null)) { string name = DefPackage.UnusedPackageName(this.relFolder, this.curMod); DefPackage defPackage = new DefPackage(name, this.relFolder); this.curMod.AddDefPackage(defPackage); this.curPackage = defPackage; } if (this.curPackage != null) { if (widgetRow.ButtonIcon(TexButton.Save, "Save the current Def package.", null)) { this.curPackage.SaveIn(this.curMod); } if (widgetRow.ButtonIcon(TexButton.RenameDev, "Rename the current Def package.", null)) { Find.WindowStack.Add(new Dialog_RenamePackage(this.curPackage)); } } float num = 56f; Rect rect3 = new Rect(0f, num, selectorInner.width, selectorInner.height - num); Rect rect4 = new Rect(0f, 0f, rect3.width - 16f, this.viewHeight); Widgets.DrawMenuSection(rect3); Widgets.BeginScrollView(rect3, ref this.scrollPosition, rect4, true); Rect rect5 = rect4.ContractedBy(4f); rect5.height = 9999f; Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(rect5); Text.Font = GameFont.Tiny; if (this.curPackage == null) { listing_Standard.Label("(no package open)", -1f, null); } else { if (this.curPackage.defs.Count == 0) { listing_Standard.Label("(package is empty)", -1f, null); } else { Def deletingDef = null; foreach (Def def in this.curPackage) { if (listing_Standard.SelectableDef(def.defName, false, delegate { deletingDef = def; })) { bool flag = false; WindowStack windowStack = Find.WindowStack; for (int i = 0; i < windowStack.Count; i++) { EditWindow_DefEditor editWindow_DefEditor = windowStack[i] as EditWindow_DefEditor; if (editWindow_DefEditor != null && editWindow_DefEditor.def == def) { flag = true; } } if (!flag) { Find.WindowStack.Add(new EditWindow_DefEditor(def)); } } } if (deletingDef != null) { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("Really delete Def " + deletingDef.defName + "?", delegate { this.curPackage.RemoveDef(deletingDef); }, true, null)); } } if (listing_Standard.ButtonImage(TexButton.Add, 24f, 24f)) { Def def2 = Activator.CreateInstance <TNewDef>(); def2.defName = "New" + typeof(TNewDef).Name; this.curPackage.AddDef(def2); } } if (Event.current.type == EventType.Layout) { this.viewHeight = listing_Standard.CurHeight; } listing_Standard.End(); Widgets.EndScrollView(); }
public Dialog_InfoCard(Def onlyDef) { def = onlyDef; Setup(); }
private void OverrideDataFromXml(XmlNode xmlRoot, Verse.Def destinationDef, bool debug) { Type destinationType = destinationDef.GetType(); string prefix = "Override :: " + destinationDef + " :: "; foreach (XmlNode node in xmlRoot.ChildNodes) { // field we are about to change string name = node.Name; if (name == null // may cause save issues if these change || name == "shortHash" || name == "index" || name == "debugRandomId") { continue; } string text = node.InnerText; Mode mode = getMode(node); if (string.IsNullOrEmpty(text) && mode != Mode.Clear) { // removal must be explicit replace or it's ignored continue; } if (name == "defName") { // not allowed to change target defName // we use it for tracking if (debug) { Log.Message(prefix + text); } prefix = "Override :: " + text + " :: "; continue; } FieldInfo destinationField = destinationType.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (destinationField == null) { Log.Warning(prefix + "\"" + name + "\" not found in target"); continue; } Type destinationFieldType = destinationField.FieldType; object destinationValue; if (mode == Mode.Clear && !destinationFieldType.IsPrimitive) { // we are clearing // primitives can't be null, set to 0 ? destinationValue = null; destinationField.SetValue(destinationDef, destinationValue); if (debug) { Log.Message(prefix + "\"" + name + "\" has been set to null"); } } else { destinationValue = destinationField.GetValue(destinationDef); } if (destinationFieldType.HasGenericDefinition(typeof(List <>))) { // its a list, search the source and queue or insert Type[] genericArguments = destinationFieldType.GetGenericArguments(); // Is it a def or derivate? Type targetDefType = null; foreach (Type t in genericArguments) { if (typeof(Verse.Def).IsAssignableFrom(t)) { targetDefType = t; break; } } // sometimes, they don't exist. Don't worry, no one will interfere. if (destinationValue == null) { destinationValue = Activator.CreateInstance(destinationFieldType); destinationField.SetValue(destinationDef, destinationValue); if (debug) { Log.Message(prefix + "\"" + name + "\" has been set to \"" + destinationValue + "\""); } } FieldParser parserFactory = getParserFactory(node); Func <XmlNode, object> parser = parserFactory.makeParser(genericArguments); // compares destination and result. Only available for Replace mode FieldComparer comparer = mode == Mode.Replace ? getComparer(node, genericArguments) : null; if (targetDefType != null) { // Crossreferencing a List needs the generic method MethodInfo crossRefLoader_RegisterListWantsCrossRef_generic = crossRefLoader_RegisterListWantsCrossRef.MakeGenericMethod(targetDefType); foreach (XmlNode child in node.ChildNodes) { object[] parameters = new object[] { destinationValue, child.InnerText }; crossRefLoader_RegisterListWantsCrossRef_generic.Invoke(null, parameters); if (debug) { Log.Message(prefix + "Registered into \"" + name + "\" the value \"" + child.InnerText + "\" of type \"" + targetDefType + "\""); } } } else { if (parser == null) { Log.Warning(prefix + "Parser is null"); continue; } IList destinationList = (IList)destinationValue; foreach (XmlNode child in node.ChildNodes) { object result = parser(child); if (result == null) { // no nulls allowed, they are troublemakers Log.Warning(prefix + "Can't Add null into \"" + name + "\""); continue; } if (mode == Mode.Replace) { if (comparer == null) { Log.Warning(prefix + "No known comparer for \"" + name + "\""); break; } Action findAndReplace = delegate { bool found = false; int index; for (index = 0; index < destinationList.Count; index++) { if (comparer.Compare(result, destinationList [index])) { destinationList [index] = result; found = true; break; } } if (found) { if (debug) { Log.Message(prefix + "Replaced into postion " + index + " at \"" + name + "\" the value \"" + result + "\""); } } else { destinationList.Add(result); if (debug) { Log.Message(prefix + "Added into \"" + name + "\" the value \"" + result + "\""); } } }; if (comparer.delay) { resolveReferencesActionQueue.Enqueue(findAndReplace); if (debug) { Log.Message(prefix + "Delaying Replace of element in \"" + name + "\" list"); } } else { findAndReplace(); } } else if (mode == Mode.Append) { destinationList.Add(result); if (debug) { Log.Message(prefix + "Added into \"" + name + "\" the value \"" + result + "\""); } } else { int index = mode == Mode.Insert ? getIndex(child, destinationList) : 0; destinationList.Insert(index, result); if (debug) { Log.Message(prefix + "Inserted into position " + index + " at \"" + destinationField.Name + "\" the value \"" + result + "\""); } } } } } else if (destinationFieldType.HasGenericDefinition(typeof(Dictionary <, >))) { // its a dict, what do we do? Log.Warning(prefix + "We don't know how to override Dictionary yet..."); } else if (typeof(Verse.Def).IsAssignableFrom(destinationFieldType)) { // its a Def, queue CrossRefLoader.RegisterObjectWantsCrossRef(destinationDef, destinationField, text); if (debug) { Log.Message(prefix + "Registered \"" + name + "\" with value \"" + destinationValue + "\" of type \"" + destinationFieldType.Name + "\" into \"" + text + "\""); } } else if (ParseHelper.HandlesType(destinationFieldType)) { // it can be handled by ParserHelper object result = ParseHelper.FromString(text, destinationFieldType); destinationField.SetValue(destinationDef, result); if (debug) { Log.Message(prefix + "Set \"" + name + "\" with value \"" + destinationValue + "\" of type \"" + destinationFieldType.Name + "\" into \"" + text + "\""); } } else { // it's most likely an object, try XmlToObject. FieldParser parserFactory = getParserFactory(node); Func <XmlNode, object> parser = parserFactory.makeParser(destinationFieldType); object result = null; if (parser != null) { result = parser(node); } if (result != null) { // this may fail, try catch? destinationField.SetValue(destinationDef, result); if (debug) { Log.Message(prefix + "Set \"" + name + "\" with value \"" + destinationValue + "\" of type \"" + destinationFieldType.Name + "\" into \"" + result + "\""); } } else { // user entered null Log.Warning(prefix + "Can't Set \"" + name + "\""); } } } }
public void AddDef(Def def, string source = "Unknown") { def.modContentPack = this; def.fileName = source; defs.Add(def); }
public void AddDef(Def def) { this.defs.Add(def); }
private static void ForEachPossibleDefInjectionInDef(Def def, PossibleDefInjectionTraverser action) { HashSet <object> visited = new HashSet <object>(); ForEachPossibleDefInjectionInDefRecursive(def, def.defName, def.defName, visited, translationAllowed: true, def, action); }
private static void ForEachPossibleDefInjectionInDef(Def def, DefInjectionUtility.PossibleDefInjectionTraverser action) { HashSet <object> visited = new HashSet <object>(); DefInjectionUtility.ForEachPossibleDefInjectionInDefRecursive(def, def.defName, def.defName, visited, true, def, action); }
public void AddDef(Def def) { def.defPackage = this; defs.Add(def); }
private static void ForEachPossibleDefInjectionInDefRecursive(object obj, string curNormalizedPath, string curSuggestedPath, HashSet <object> visited, bool translationAllowed, Def def, DefInjectionUtility.PossibleDefInjectionTraverser action) { if (obj == null) { return; } if (visited.Contains(obj)) { return; } visited.Add(obj); foreach (FieldInfo fieldInfo in DefInjectionUtility.FieldsInDeterministicOrder(obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))) { object value = fieldInfo.GetValue(obj); bool flag = translationAllowed && !fieldInfo.HasAttribute <NoTranslateAttribute>() && !fieldInfo.HasAttribute <UnsavedAttribute>(); if (!(value is Def)) { if (typeof(string).IsAssignableFrom(fieldInfo.FieldType)) { string currentValue = (string)value; string normalizedPath = curNormalizedPath + "." + fieldInfo.Name; string suggestedPath = curSuggestedPath + "." + fieldInfo.Name; action(suggestedPath, normalizedPath, false, currentValue, null, flag, false, fieldInfo, def); } else if (value is IEnumerable <string> ) { IEnumerable <string> currentValueCollection = (IEnumerable <string>)value; bool flag2 = fieldInfo.HasAttribute <TranslationCanChangeCountAttribute>(); string normalizedPath2 = curNormalizedPath + "." + fieldInfo.Name; string suggestedPath2 = curSuggestedPath + "." + fieldInfo.Name; action(suggestedPath2, normalizedPath2, true, null, currentValueCollection, flag, flag && flag2, fieldInfo, def); } else if (value is IEnumerable) { IEnumerable enumerable = (IEnumerable)value; int num = 0; IEnumerator enumerator2 = enumerable.GetEnumerator(); try { while (enumerator2.MoveNext()) { object obj2 = enumerator2.Current; if (obj2 != null && !(obj2 is Def) && GenTypes.IsCustomType(obj2.GetType())) { string text = TranslationHandleUtility.GetBestHandleWithIndexForListElement(enumerable, obj2); if (text.NullOrEmpty()) { text = num.ToString(); } string curNormalizedPath2 = string.Concat(new object[] { curNormalizedPath, ".", fieldInfo.Name, ".", num }); string curSuggestedPath2 = string.Concat(new string[] { curSuggestedPath, ".", fieldInfo.Name, ".", text }); DefInjectionUtility.ForEachPossibleDefInjectionInDefRecursive(obj2, curNormalizedPath2, curSuggestedPath2, visited, flag, def, action); } num++; } } finally { IDisposable disposable; if ((disposable = (enumerator2 as IDisposable)) != null) { disposable.Dispose(); } } } else if (value != null && GenTypes.IsCustomType(value.GetType())) { string curNormalizedPath3 = curNormalizedPath + "." + fieldInfo.Name; string curSuggestedPath3 = curSuggestedPath + "." + fieldInfo.Name; DefInjectionUtility.ForEachPossibleDefInjectionInDefRecursive(value, curNormalizedPath3, curSuggestedPath3, visited, flag, def, action); } } } }
private static bool TryResolveSymbol(object obj, string subSymbol, string symbolArgs, out TaggedString resolvedStr, string fullStringForReference) { Pawn pawn = obj as Pawn; if (pawn != null) { switch (subSymbol) { case "": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Name.ToStringShort, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelIndefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "nameFull": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Name.ToStringFull, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelIndefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "nameFullDef": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.Name.ToStringFull, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelDefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "label": resolvedStr = pawn.LabelNoCountColored; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelShort": resolvedStr = ((pawn.Name != null) ? pawn.Name.ToStringShort.ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabel)); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "definite": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.Name.ToStringShort, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelDefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "nameDef": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.Name.ToStringShort, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelDefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "indefinite": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Name.ToStringShort, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelIndefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "nameIndef": resolvedStr = ((pawn.Name != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Name.ToStringShort, pawn.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)pawn.KindLabelIndefinite())); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pronoun": resolvedStr = pawn.gender.GetPronoun(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "possessive": resolvedStr = pawn.gender.GetPossessive(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "objective": resolvedStr = pawn.gender.GetObjective(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionName": resolvedStr = ((pawn.Faction != null) ? pawn.Faction.Name.ApplyTag(pawn.Faction) : ((TaggedString)"")); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionPawnSingular": resolvedStr = ((pawn.Faction != null) ? pawn.Faction.def.pawnSingular : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionPawnSingularDef": resolvedStr = ((pawn.Faction != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.Faction.def.pawnSingular) : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionPawnSingularIndef": resolvedStr = ((pawn.Faction != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Faction.def.pawnSingular) : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionPawnsPlural": resolvedStr = ((pawn.Faction != null) ? pawn.Faction.def.pawnsPlural : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionPawnsPluralDef": resolvedStr = ((pawn.Faction != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.Faction.def.pawnsPlural, LanguageDatabase.activeLanguage.ResolveGender(pawn.Faction.def.pawnsPlural, pawn.Faction.def.pawnSingular), plural: true) : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionPawnsPluralIndef": resolvedStr = ((pawn.Faction != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.Faction.def.pawnsPlural, LanguageDatabase.activeLanguage.ResolveGender(pawn.Faction.def.pawnsPlural, pawn.Faction.def.pawnSingular), plural: true) : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionRoyalFavorLabel": resolvedStr = ((pawn.Faction != null) ? pawn.Faction.def.royalFavorLabel : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kind": resolvedStr = pawn.KindLabel; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindDef": resolvedStr = pawn.KindLabelDefinite(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindIndef": resolvedStr = pawn.KindLabelIndefinite(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindPlural": resolvedStr = pawn.GetKindLabelPlural(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindPluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.GetKindLabelPlural(), pawn.gender, plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindPluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.GetKindLabelPlural(), pawn.gender, plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindBase": resolvedStr = pawn.kindDef.label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindBaseDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.kindDef.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindBaseIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.kindDef.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindBasePlural": resolvedStr = pawn.kindDef.GetLabelPlural(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindBasePluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.kindDef.GetLabelPlural(), LanguageDatabase.activeLanguage.ResolveGender(pawn.kindDef.GetLabelPlural(), pawn.kindDef.label), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "kindBasePluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.kindDef.GetLabelPlural(), LanguageDatabase.activeLanguage.ResolveGender(pawn.kindDef.GetLabelPlural(), pawn.kindDef.label), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "race": resolvedStr = pawn.def.label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "raceDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.def.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "raceIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.def.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "lifeStage": resolvedStr = pawn.ageTracker.CurLifeStage.label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "lifeStageDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.ageTracker.CurLifeStage.label, pawn.gender); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "lifeStageIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.ageTracker.CurLifeStage.label, pawn.gender); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "lifeStageAdjective": resolvedStr = pawn.ageTracker.CurLifeStage.Adjective; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "title": resolvedStr = ((pawn.story != null) ? pawn.story.Title : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "titleDef": resolvedStr = ((pawn.story != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(pawn.story.Title, pawn.gender) : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "titleIndef": resolvedStr = ((pawn.story != null) ? Find.ActiveLanguageWorker.WithIndefiniteArticle(pawn.story.Title, pawn.gender) : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "bestRoyalTitle": resolvedStr = PawnResolveBestRoyalTitle(pawn); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "bestRoyalTitleIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(PawnResolveBestRoyalTitle(pawn)); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "bestRoyalTitleDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(PawnResolveBestRoyalTitle(pawn)); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "royalTitleInCurrentFaction": resolvedStr = PawnResolveRoyalTitleInCurrentFaction(pawn); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "royalTitleInCurrentFactionIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(PawnResolveRoyalTitleInCurrentFaction(pawn)); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "royalTitleInCurrentFactionDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(PawnResolveRoyalTitleInCurrentFaction(pawn)); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "age": resolvedStr = pawn.ageTracker.AgeBiologicalYears.ToString(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "chronologicalAge": resolvedStr = pawn.ageTracker.AgeChronologicalYears.ToString(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "ageFull": resolvedStr = pawn.ageTracker.AgeNumberString; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "relationInfo": { resolvedStr = ""; TaggedString text = resolvedStr; PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, pawn); resolvedStr = text.RawText; return(true); } case "relationInfoInParentheses": resolvedStr = ""; PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref resolvedStr, pawn); if (!resolvedStr.NullOrEmpty()) { resolvedStr = "(" + resolvedStr + ")"; } return(true); case "gender": resolvedStr = ResolveGenderSymbol(pawn.gender, pawn.RaceProps.Animal, symbolArgs, fullStringForReference); return(true); case "humanlike": resolvedStr = ResolveHumanlikeSymbol(pawn.RaceProps.Humanlike, symbolArgs, fullStringForReference); return(true); default: resolvedStr = ""; return(false); } } Thing thing = obj as Thing; if (thing != null) { switch (subSymbol) { case "": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(thing.Label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "label": resolvedStr = thing.Label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPlural": resolvedStr = Find.ActiveLanguageWorker.Pluralize(thing.LabelNoCount); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(Find.ActiveLanguageWorker.Pluralize(thing.LabelNoCount), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(thing.LabelNoCount), thing.LabelNoCount), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(Find.ActiveLanguageWorker.Pluralize(thing.LabelNoCount), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(thing.LabelNoCount), thing.LabelNoCount), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelShort": resolvedStr = thing.LabelShort; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "definite": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(thing.Label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "indefinite": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(thing.Label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pronoun": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(thing.LabelNoCount).GetPronoun(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "possessive": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(thing.LabelNoCount).GetPossessive(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "objective": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(thing.LabelNoCount).GetObjective(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionName": resolvedStr = ((thing.Faction != null) ? thing.Faction.Name : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "gender": resolvedStr = ResolveGenderSymbol(LanguageDatabase.activeLanguage.ResolveGender(thing.LabelNoCount), animal: false, symbolArgs, fullStringForReference); return(true); default: resolvedStr = ""; return(false); } } Hediff hediff = obj as Hediff; if (hediff != null) { if (subSymbol == "label") { resolvedStr = hediff.Label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } if (subSymbol == "labelNoun") { resolvedStr = ((!hediff.def.labelNoun.NullOrEmpty()) ? hediff.def.labelNoun : hediff.Label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } } WorldObject worldObject = obj as WorldObject; if (worldObject != null) { switch (subSymbol) { case "": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(worldObject.Label, plural: false, worldObject.HasName); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "label": resolvedStr = worldObject.Label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPlural": resolvedStr = Find.ActiveLanguageWorker.Pluralize(worldObject.Label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(Find.ActiveLanguageWorker.Pluralize(worldObject.Label), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(worldObject.Label), worldObject.Label), plural: true, worldObject.HasName); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(Find.ActiveLanguageWorker.Pluralize(worldObject.Label), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(worldObject.Label), worldObject.Label), plural: true, worldObject.HasName); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "definite": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(worldObject.Label, plural: false, worldObject.HasName); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "indefinite": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(worldObject.Label, plural: false, worldObject.HasName); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pronoun": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(worldObject.Label).GetPronoun(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "possessive": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(worldObject.Label).GetPossessive(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "objective": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(worldObject.Label).GetObjective(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "factionName": resolvedStr = ((worldObject.Faction != null) ? worldObject.Faction.Name.ApplyTag(worldObject.Faction) : ((TaggedString)"")); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "gender": resolvedStr = ResolveGenderSymbol(LanguageDatabase.activeLanguage.ResolveGender(worldObject.Label), animal: false, symbolArgs, fullStringForReference); return(true); default: resolvedStr = ""; return(false); } } Faction faction = obj as Faction; if (faction != null) { switch (subSymbol) { case "": resolvedStr = faction.Name.ApplyTag(faction); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "name": resolvedStr = faction.Name.ApplyTag(faction); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pawnSingular": resolvedStr = faction.def.pawnSingular; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pawnSingularDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(faction.def.pawnSingular); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pawnSingularIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(faction.def.pawnSingular); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pawnsPlural": resolvedStr = faction.def.pawnsPlural; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pawnsPluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(faction.def.pawnsPlural, LanguageDatabase.activeLanguage.ResolveGender(faction.def.pawnsPlural, faction.def.pawnSingular), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pawnsPluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(faction.def.pawnsPlural, LanguageDatabase.activeLanguage.ResolveGender(faction.def.pawnsPlural, faction.def.pawnSingular), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "royalFavorLabel": resolvedStr = faction.def.royalFavorLabel; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "leaderNameDef": resolvedStr = ((faction.leader != null && faction.leader.Name != null) ? Find.ActiveLanguageWorker.WithDefiniteArticle(faction.leader.Name.ToStringShort, faction.leader.gender, plural: false, name: true).ApplyTag(TagType.Name) : ((TaggedString)"")); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "leaderPossessive": resolvedStr = ((faction.leader != null) ? faction.leader.gender.GetPossessive() : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "leaderObjective": resolvedStr = ((faction.leader != null) ? faction.leader.gender.GetObjective() : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "leaderPronoun": resolvedStr = ((faction.leader != null) ? faction.leader.gender.GetPronoun() : ""); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); default: resolvedStr = ""; return(false); } } Def def = obj as Def; if (def != null) { PawnKindDef pawnKindDef = def as PawnKindDef; if (pawnKindDef != null) { switch (subSymbol) { case "labelPlural": resolvedStr = pawnKindDef.GetLabelPlural(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(pawnKindDef.GetLabelPlural(), LanguageDatabase.activeLanguage.ResolveGender(pawnKindDef.GetLabelPlural(), pawnKindDef.label), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(pawnKindDef.GetLabelPlural(), LanguageDatabase.activeLanguage.ResolveGender(pawnKindDef.GetLabelPlural(), pawnKindDef.label), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } } switch (subSymbol) { case "": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(def.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "label": resolvedStr = def.label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPlural": resolvedStr = Find.ActiveLanguageWorker.Pluralize(def.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(Find.ActiveLanguageWorker.Pluralize(def.label), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(def.label), def.label), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "labelPluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(Find.ActiveLanguageWorker.Pluralize(def.label), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(def.label), def.label), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "definite": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(def.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "indefinite": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(def.label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pronoun": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(def.label).GetPronoun(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "possessive": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(def.label).GetPossessive(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "objective": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(def.label).GetObjective(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "gender": resolvedStr = ResolveGenderSymbol(LanguageDatabase.activeLanguage.ResolveGender(def.label), animal: false, symbolArgs, fullStringForReference); return(true); default: resolvedStr = ""; return(false); } } RoyalTitle royalTitle = obj as RoyalTitle; if (royalTitle != null) { if (subSymbol == null || subSymbol.Length != 0) { if (!(subSymbol == "label")) { if (subSymbol == "indefinite") { resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticlePostProcessed(royalTitle.Label); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } resolvedStr = ""; return(false); } resolvedStr = royalTitle.Label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } resolvedStr = royalTitle.Label; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } string text2 = obj as string; if (text2 != null) { switch (subSymbol) { case "": resolvedStr = text2; EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "plural": resolvedStr = Find.ActiveLanguageWorker.Pluralize(text2); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pluralDef": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(Find.ActiveLanguageWorker.Pluralize(text2), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(text2), text2), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pluralIndef": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(Find.ActiveLanguageWorker.Pluralize(text2), LanguageDatabase.activeLanguage.ResolveGender(Find.ActiveLanguageWorker.Pluralize(text2), text2), plural: true); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "definite": resolvedStr = Find.ActiveLanguageWorker.WithDefiniteArticle(text2); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "indefinite": resolvedStr = Find.ActiveLanguageWorker.WithIndefiniteArticle(text2); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "pronoun": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(text2).GetPronoun(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "possessive": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(text2).GetPossessive(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "objective": resolvedStr = LanguageDatabase.activeLanguage.ResolveGender(text2).GetObjective(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); case "gender": resolvedStr = ResolveGenderSymbol(LanguageDatabase.activeLanguage.ResolveGender(text2), animal: false, symbolArgs, fullStringForReference); return(true); default: resolvedStr = ""; return(false); } } if (obj is int || obj is long) { int num = (int)((obj is int) ? ((int)obj) : ((long)obj)); if (subSymbol == null || subSymbol.Length != 0) { if (!(subSymbol == "ordinal")) { if (subSymbol == "multiple") { resolvedStr = ResolveMultipleSymbol(num, symbolArgs, fullStringForReference); return(true); } resolvedStr = ""; return(false); } resolvedStr = Find.ActiveLanguageWorker.OrdinalNumber(num).ToString(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } resolvedStr = num.ToString(); EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); return(true); } if (obj is TaggedString) { EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); resolvedStr = ((TaggedString)obj).RawText; } if (subSymbol.NullOrEmpty()) { EnsureNoArgs(subSymbol, symbolArgs, fullStringForReference); if (obj == null) { resolvedStr = ""; } else { resolvedStr = obj.ToString(); } return(true); } resolvedStr = ""; return(false); }
public Dialog_InfoCard(Def onlyDef) { this.def = onlyDef; this.Setup(); }
public DefHyperlink(Def def) { this.def = def; }
private static string <GiveAllShortHashes> m__0(Def d) { return(d.defName); }
public DefHyperlink(RoyalTitleDef def, Faction faction) { this.def = def; this.faction = faction; }
public static void Look <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs) { if (lookMode == LookMode.Undefined) { if (ParseHelper.HandlesType(typeof(T))) { lookMode = LookMode.Value; } else if (typeof(T) == typeof(LocalTargetInfo)) { lookMode = LookMode.LocalTargetInfo; } else if (typeof(T) == typeof(TargetInfo)) { lookMode = LookMode.TargetInfo; } else if (typeof(T) == typeof(GlobalTargetInfo)) { lookMode = LookMode.GlobalTargetInfo; } else if (typeof(Def).IsAssignableFrom(typeof(T))) { lookMode = LookMode.Def; } else if (typeof(T) == typeof(BodyPartRecord)) { lookMode = LookMode.BodyPart; } else { if (!typeof(IExposable).IsAssignableFrom(typeof(T)) || typeof(ILoadReferenceable).IsAssignableFrom(typeof(T))) { Log.Error("LookList call with a list of " + typeof(T) + " must have lookMode set explicitly.", false); return; } lookMode = LookMode.Deep; } } if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving) { if (list == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { foreach (T current in list) { if (lookMode == LookMode.Value) { T t = current; Scribe_Values.Look <T>(ref t, "li", default(T), true); } else if (lookMode == LookMode.LocalTargetInfo) { LocalTargetInfo localTargetInfo = (LocalTargetInfo)((object)current); Scribe_TargetInfo.Look(ref localTargetInfo, saveDestroyedThings, "li"); } else if (lookMode == LookMode.TargetInfo) { TargetInfo targetInfo = (TargetInfo)((object)current); Scribe_TargetInfo.Look(ref targetInfo, saveDestroyedThings, "li"); } else if (lookMode == LookMode.GlobalTargetInfo) { GlobalTargetInfo globalTargetInfo = (GlobalTargetInfo)((object)current); Scribe_TargetInfo.Look(ref globalTargetInfo, saveDestroyedThings, "li"); } else if (lookMode == LookMode.Def) { Def def = (Def)((object)current); Scribe_Defs.Look <Def>(ref def, "li"); } else if (lookMode == LookMode.BodyPart) { BodyPartRecord bodyPartRecord = (BodyPartRecord)((object)current); Scribe_BodyParts.Look(ref bodyPartRecord, "li", null); } else if (lookMode == LookMode.Deep) { T t2 = current; Scribe_Deep.Look <T>(ref t2, saveDestroyedThings, "li", ctorArgs); } else if (lookMode == LookMode.Reference) { ILoadReferenceable loadReferenceable = (ILoadReferenceable)((object)current); Scribe_References.Look <ILoadReferenceable>(ref loadReferenceable, "li", saveDestroyedThings); } } } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlNode curXmlParent = Scribe.loader.curXmlParent; XmlAttribute xmlAttribute = curXmlParent.Attributes["IsNull"]; if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true") { list = null; } else if (lookMode == LookMode.Value) { list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode subNode in curXmlParent.ChildNodes) { T item = ScribeExtractor.ValueFromNode <T>(subNode, default(T)); list.Add(item); } } else if (lookMode == LookMode.Deep) { list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode subNode2 in curXmlParent.ChildNodes) { T item2 = ScribeExtractor.SaveableFromNode <T>(subNode2, ctorArgs); list.Add(item2); } } else if (lookMode == LookMode.Def) { list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode subNode3 in curXmlParent.ChildNodes) { T item3 = ScribeExtractor.DefFromNodeUnsafe <T>(subNode3); list.Add(item3); } } else if (lookMode == LookMode.BodyPart) { list = new List <T>(curXmlParent.ChildNodes.Count); int num = 0; foreach (XmlNode node in curXmlParent.ChildNodes) { T item4 = (T)((object)ScribeExtractor.BodyPartFromNode(node, num.ToString(), null)); list.Add(item4); num++; } } else if (lookMode == LookMode.LocalTargetInfo) { list = new List <T>(curXmlParent.ChildNodes.Count); int num2 = 0; foreach (XmlNode node2 in curXmlParent.ChildNodes) { LocalTargetInfo localTargetInfo2 = ScribeExtractor.LocalTargetInfoFromNode(node2, num2.ToString(), LocalTargetInfo.Invalid); T item5 = (T)((object)localTargetInfo2); list.Add(item5); num2++; } } else if (lookMode == LookMode.TargetInfo) { list = new List <T>(curXmlParent.ChildNodes.Count); int num3 = 0; foreach (XmlNode node3 in curXmlParent.ChildNodes) { TargetInfo targetInfo2 = ScribeExtractor.TargetInfoFromNode(node3, num3.ToString(), TargetInfo.Invalid); T item6 = (T)((object)targetInfo2); list.Add(item6); num3++; } } else if (lookMode == LookMode.GlobalTargetInfo) { list = new List <T>(curXmlParent.ChildNodes.Count); int num4 = 0; foreach (XmlNode node4 in curXmlParent.ChildNodes) { GlobalTargetInfo globalTargetInfo2 = ScribeExtractor.GlobalTargetInfoFromNode(node4, num4.ToString(), GlobalTargetInfo.Invalid); T item7 = (T)((object)globalTargetInfo2); list.Add(item7); num4++; } } else if (lookMode == LookMode.Reference) { List <string> list2 = new List <string>(curXmlParent.ChildNodes.Count); foreach (XmlNode xmlNode in curXmlParent.ChildNodes) { list2.Add(xmlNode.InnerText); } Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(list2, string.Empty); } } else if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { if (lookMode == LookMode.Reference) { list = Scribe.loader.crossRefs.TakeResolvedRefList <T>(string.Empty); } else if (lookMode == LookMode.LocalTargetInfo) { if (list != null) { for (int i = 0; i < list.Count; i++) { list[i] = (T)((object)ScribeExtractor.ResolveLocalTargetInfo((LocalTargetInfo)((object)list[i]), i.ToString())); } } } else if (lookMode == LookMode.TargetInfo) { if (list != null) { for (int j = 0; j < list.Count; j++) { list[j] = (T)((object)ScribeExtractor.ResolveTargetInfo((TargetInfo)((object)list[j]), j.ToString())); } } } else if (lookMode == LookMode.GlobalTargetInfo && list != null) { for (int k = 0; k < list.Count; k++) { list[k] = (T)((object)ScribeExtractor.ResolveGlobalTargetInfo((GlobalTargetInfo)((object)list[k]), k.ToString())); } } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, label); } list = null; } }
public EditWindow_DefEditor(Def def) { this.def = def; base.optionalTitle = def.ToString(); }