public static void ITab_Storage_Patch(ITab_Storage instance, StorageSettings settings) { //Log.Message("ITab_Storage_Patch was called"); //if (!logged) //{ // Log.Message($"ITab_Storage instance == null: {instance == null}"); // Log.Message($"StorageSettings settings == null: {settings == null}"); // logged = true; //} object o = AccessTools.Field(typeof(ITab_Storage), "size").GetValue(instance); Vector2 size = (Vector2)o; //Log.Message($"[NOTICE] ITab_Storage size -> x: {size.x} y: {size.y}"); Vector2 WinSize = new Vector2(300f, 575f); Text.Font = GameFont.Small; Rect rect = new Rect(0f, 35f, 160f, 35f - 6f); LazySettings stockpile = LazySettingsManager.AddOrGetSettings(settings); if (stockpile == null) { Log.ErrorOnce(string.Format($"Lazy Tab Error: Attempted to load settings as LazySettings, when it was of type {settings.GetType()}"), 0); } else { //Type Button if (Widgets.ButtonText(rect, "Type: " + stockpile.type.ToString(), true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (LazyType type in Enum.GetValues(typeof(LazyType))) { LazyType localTy = type; list.Add(new FloatMenuOption(type.ToString(), delegate { stockpile.type = type; }, MenuOptionPriority.Default, null, null, 0f, null, null)); Find.WindowStack.Add(new FloatMenu(list)); } } //Cache Threshold Slider if (stockpile.type == LazyType.Cache) { Rect sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f); Listing_Standard stand = new Listing_Standard(); stand.Begin(sliderRect); stand.Label(string.Format($"Cache Threshold: {stockpile.CacheThreshold * 100:0}%")); stockpile.CacheThreshold = stand.Slider(stockpile.CacheThreshold, 0f, 0.75f); stand.End(); } //Buffer Threshold Slider else if (stockpile.type == LazyType.Buffer) { Rect sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f); Listing_Standard stand = new Listing_Standard(); stand.Begin(sliderRect); stand.Label(string.Format($"Buffer Threshold: {stockpile.BufferThreshold * 100:0}%")); stockpile.BufferThreshold = stand.Slider(stockpile.BufferThreshold, 0.25f, 1f); stand.End(); } } }
public LazySettings(StorageSettings s) { settings = s; BufferThreshold = DefaultBuffer; CacheThreshold = DefaultCache; type = LazyType.Cache; }
private LazyType SetLazyType(IType columnType) { if(returnType == null) { returnType = new LazyType(); } returnType.RealType = columnType; return returnType; }
private LazyType SetLazyType(IType columnType) { if (returnType == null) { returnType = new LazyType(); } returnType.RealType = columnType; return(returnType); }
//private Dictionary<string, string> _extendDatabaseConnection = null; public DBInfo(string dbName, string connectionString, string dbType, LazyType allowLazy ) { _dbType = dbType; _connectionString = connectionString; _dbName = dbName; _cache = new QueryCache(this); _allowLazy = allowLazy; InitAdapters(); }
//When loading a save to override the default StorageSettings public LazySettings(StorageSettings settings, LazyType t = LazyType.Normal) { if (settings != null) { this.owner = settings.owner; this.filter = settings.filter; this.Priority = settings.Priority; } this.type = t; CacheThreshold = DefaultCache; BufferThreshold = DefaultBuffer; }
/// <summary> /// 加载数据库配置信息 /// </summary> /// <param name="doc"></param> /// <returns></returns> public static DBConfigInfo LoadInfo(XmlDocument doc) { XmlNodeList lstConfig = doc.GetElementsByTagName("config"); if (lstConfig.Count > 0) { DBConfigInfo info = new DBConfigInfo(); XmlNode config = lstConfig[0]; XmlAttribute att = config.Attributes["connectionString"]; if (att != null) { info.ConnectionString = att.InnerText; } att = config.Attributes["dbType"]; if (att != null) { info.DbType = att.InnerText; } att = config.Attributes["appnamespace"]; if (att != null) { info.AppNamespace = att.InnerText; } att = config.Attributes["assembly"]; if (att != null) { info.Assembly = att.InnerText; } att = config.Attributes["name"]; if (att != null) { info.DbName = att.InnerText; } att = config.Attributes["cache"]; if (att != null) { info.CacheType = att.InnerText; } att = config.Attributes["cacheConnString"]; if (att != null) { info.CacheConnString = att.InnerText; } att = config.Attributes["allCache"]; if (att != null) { info.IsAllTable = att.InnerText == "1"; } att = config.Attributes["lazy"]; if (att != null) { LazyType lazy = LazyType.User; int ilazy = 0; if (int.TryParse(att.InnerText, out ilazy)) { lazy = (LazyType)ilazy; } info.AllowLazy = lazy; } return(info); } return(null); }
protected override void FillTab() { IStoreSettingsParent selStoreSettingsParent = this.SelStoreSettingsParent; StorageSettings settings = selStoreSettingsParent.GetStoreSettings(); Rect position = new Rect(0f, 0f, ITab_Lazy.WinSize.x, ITab_Lazy.WinSize.y).ContractedBy(10f); GUI.BeginGroup(position); if (this.IsPrioritySettingVisible) { Text.Font = GameFont.Small; Rect rect = new Rect(0f, 0f, 160f, this.TopAreaHeight - 6f); if (Widgets.ButtonText(rect, "Priority".Translate() + ": " + settings.Priority.Label(), true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (StoragePriority storagePriority in Enum.GetValues(typeof(StoragePriority))) { if (storagePriority != StoragePriority.Unstored) { StoragePriority localPr = storagePriority; list.Add(new FloatMenuOption(localPr.Label().CapitalizeFirst(), delegate { settings.Priority = localPr; }, MenuOptionPriority.Default, null, null, 0f, null, null)); } } Find.WindowStack.Add(new FloatMenu(list)); } UIHighlighter.HighlightOpportunity(rect, "StoragePriority"); } //Lazy button & Threshold Sliders { Text.Font = GameFont.Small; Rect rect = new Rect(0f, 35f, 160f, this.TopAreaHeight - 6f); LazySettings stockpile = settings as LazySettings; if (stockpile == null) { Log.Error(string.Format($"Lazy Tab Error: Attempted to load {SelObject} settings as LazySettings, when it was of type {settings.GetType()}")); } else { //Type Button if (Widgets.ButtonText(rect, "Type: " + stockpile.type.ToString(), true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (LazyType type in Enum.GetValues(typeof(LazyType))) { LazyType localTy = type; list.Add(new FloatMenuOption(type.ToString(), delegate { stockpile.type = type; }, MenuOptionPriority.Default, null, null, 0f, null, null)); Find.WindowStack.Add(new FloatMenu(list)); } } //Cache Threshold Slider if (stockpile.type == LazyType.Cache) { Rect sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f); Listing_Standard stand = new Listing_Standard(); stand.Begin(sliderRect); stand.Label(string.Format($"Cache Threshold: {stockpile.CacheThreshold * 100:0}%")); stockpile.CacheThreshold = stand.Slider(stockpile.CacheThreshold, 0f, 0.75f); stand.End(); } //Buffer Threshold Slider else if (stockpile.type == LazyType.Buffer) { Rect sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f); Listing_Standard stand = new Listing_Standard(); stand.Begin(sliderRect); stand.Label(string.Format($"Buffer Threshold: {stockpile.BufferThreshold * 100:0}%")); stockpile.BufferThreshold = stand.Slider(stockpile.BufferThreshold, 0.25f, 1f); stand.End(); } } } ThingFilter parentFilter = null; if (selStoreSettingsParent.GetParentStoreSettings() != null) { parentFilter = selStoreSettingsParent.GetParentStoreSettings().filter; } Rect rect2 = new Rect(0f, (this.TopAreaHeight * 3) + 5, position.width, position.height - (this.TopAreaHeight * 2)); ThingFilterUI.DoThingFilterConfigWindow(rect2, ref this.scrollPosition, settings.filter, parentFilter, 8, null, null, null); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.StorageTab, KnowledgeAmount.FrameDisplayed); GUI.EndGroup(); }
protected override void FillTab() { IStoreSettingsParent selStoreSettingsParent = this.SelStoreSettingsParent; StorageSettings settings = selStoreSettingsParent.GetStoreSettings(); Rect position = new Rect(0f, 0f, ITab_Lazy.WinSize.x, ITab_Lazy.WinSize.y).ContractedBy(10f); GUI.BeginGroup(position); if (this.IsPrioritySettingVisible) { Text.Font = GameFont.Small; Rect rect = new Rect(0f, 0f, 160f, this.TopAreaHeight - 6f); if (Widgets.ButtonText(rect, "Priority".Translate() + ": " + settings.Priority.Label(), true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (StoragePriority storagePriority in Enum.GetValues(typeof(StoragePriority))) { if (storagePriority != StoragePriority.Unstored) { StoragePriority localPr = storagePriority; list.Add(new FloatMenuOption(localPr.Label().CapitalizeFirst(), delegate { settings.Priority = localPr; }, MenuOptionPriority.Default, null, null, 0f, null, null)); } } Find.WindowStack.Add(new FloatMenu(list)); } UIHighlighter.HighlightOpportunity(rect, "StoragePriority"); } //Lazy button & Threshold Sliders { Text.Font = GameFont.Small; Rect rect = new Rect(0f, 35f, 160f, this.TopAreaHeight - 6f); LazySettings stockpile = LazySettingsManager.AddOrGetSettings(settings); if (stockpile == null) { Log.Error(string.Format($"Lazy Tab Error: Attempted to load {SelObject} settings as LazySettings, when it was of type {settings.GetType()}")); } else { //Type Button if (Widgets.ButtonText(rect, "Type: " + stockpile.type.ToString(), true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (LazyType type in Enum.GetValues(typeof(LazyType))) { LazyType localTy = type; list.Add(new FloatMenuOption(type.ToString(), delegate { stockpile.type = type; }, MenuOptionPriority.Default, null, null, 0f, null, null)); Find.WindowStack.Add(new FloatMenu(list)); } } //Cache Threshold Slider if (stockpile.type == LazyType.Cache) { Rect sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f); Listing_Standard stand = new Listing_Standard(); stand.Begin(sliderRect); stand.Label(string.Format($"Cache Threshold: {stockpile.CacheThreshold * 100:0}%")); stockpile.CacheThreshold = stand.Slider(stockpile.CacheThreshold, 0f, 0.75f); stand.End(); } //Buffer Threshold Slider else if (stockpile.type == LazyType.Buffer) { Rect sliderRect = new Rect(0f, 66f, WinSize.x - 20f, 70f); Listing_Standard stand = new Listing_Standard(); stand.Begin(sliderRect); stand.Label(string.Format($"Buffer Threshold: {stockpile.BufferThreshold * 100:0}%")); stockpile.BufferThreshold = stand.Slider(stockpile.BufferThreshold, 0.25f, 1f); stand.End(); } } } ThingFilter parentFilter = null; if (selStoreSettingsParent.GetParentStoreSettings() != null) { parentFilter = selStoreSettingsParent.GetParentStoreSettings().filter; } Rect rect2 = new Rect(0f, (this.TopAreaHeight * 3) + 5, position.width, position.height - (this.TopAreaHeight * 2)); Bill[] first = (from b in BillUtility.GlobalBills() where b is Bill_Production && b.GetStoreZone() == selStoreSettingsParent && b.recipe.WorkerCounter.CanPossiblyStoreInStockpile((Bill_Production)b, b.GetStoreZone()) select b).ToArray(); ThingFilterUI.DoThingFilterConfigWindow(rect2, ref this.scrollPosition, settings.filter, parentFilter, 8, null, null, false, null, null); Bill[] second = (from b in BillUtility.GlobalBills() where b is Bill_Production && b.GetStoreZone() == selStoreSettingsParent && b.recipe.WorkerCounter.CanPossiblyStoreInStockpile((Bill_Production)b, b.GetStoreZone()) select b).ToArray(); IEnumerable <Bill> enumerable = first.Except(second); foreach (Bill item in enumerable) { Messages.Message("MessageBillValidationStoreZoneInsufficient".Translate(item.LabelCap, item.billStack.billGiver.LabelShort.CapitalizeFirst(), item.GetStoreZone().label), item.billStack.billGiver as Thing, MessageTypeDefOf.RejectInput, false); } PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.StorageTab, KnowledgeAmount.FrameDisplayed); GUI.EndGroup(); }
public TypedParameter(IParameter parameter, LazyType type) { _parameter = parameter; _type = type; }
/// <summary> /// 获取当前配置文件的数据库信息 /// </summary> /// <param name="doc"></param> /// <returns></returns> public static DBInfo GetDBInfo(XmlDocument doc) { string dbType = null; string connectionString = null; string name = null; //string output = null; string[] attNames = null; ICacheAdaper ica = null; string cacheType = null; string cacheConn = null; LazyType lazy = LazyType.Enable; //Dictionary<string, string> extendDatabaseConnection = new Dictionary<string,string>(); if (doc == null) { throw new Exception("找不到配置文件"); } bool isAlltable = false; XmlNodeList lstConfig = doc.GetElementsByTagName("config"); if (lstConfig.Count > 0) { XmlNode node = lstConfig[0]; foreach (XmlAttribute att in node.Attributes) { if (att.Name.Equals("dbType", StringComparison.CurrentCultureIgnoreCase)) { dbType = att.InnerText; } //else if (att.Name.Equals("output", StringComparison.CurrentCultureIgnoreCase)) //{ // output = att.InnerText; //} else if (att.Name.Equals("name", StringComparison.CurrentCultureIgnoreCase)) { name = att.InnerText; } else if (att.Name.Equals("connectionString", StringComparison.CurrentCultureIgnoreCase)) { connectionString = att.InnerText; } else if (att.Name.Equals("appnamespace", StringComparison.CurrentCultureIgnoreCase)) { string names = att.InnerText; if (!string.IsNullOrEmpty(names)) { attNames = names.Split(new char[] { '|' }); } for (int i = 0; i < attNames.Length; i++) { string attName = attNames[i]; if (!attName.EndsWith(".")) { attNames[i] = attName + "."; } } } else if (att.Name.Equals("cache", StringComparison.CurrentCultureIgnoreCase)) { cacheType = att.InnerText; } else if (att.Name.Equals("cacheConnString", StringComparison.CurrentCultureIgnoreCase)) { cacheConn = att.InnerText; } else if (att.Name.Equals("allCache", StringComparison.CurrentCultureIgnoreCase)) { isAlltable = att.InnerText == "1"; } else if (att.Name.Equals("lazy", StringComparison.CurrentCultureIgnoreCase)) { int ilazy = 0; if (int.TryParse(att.InnerText, out ilazy)) { lazy = (LazyType)ilazy; } } } } else { throw new Exception("配置文件没有config节点"); } DBInfo info = new DBInfo(name, connectionString, dbType, lazy); ica = QueryCache.GetCache(info, cacheType, cacheConn); info.SetQueryCache(ica, isAlltable); info.DataaccessNamespace = attNames; return(info); }