diff --git a/Source/Client/Dialogs/RT_Dialog_1Input.cs b/Source/Client/Dialogs/RT_Dialog_1Input.cs index 5afb62e3..a18b1bea 100644 --- a/Source/Client/Dialogs/RT_Dialog_1Input.cs +++ b/Source/Client/Dialogs/RT_Dialog_1Input.cs @@ -2,6 +2,7 @@ using RimWorld; using UnityEngine; using Verse; +using static GameClient.DialogManagerHelper; namespace GameClient { @@ -54,7 +55,7 @@ public override void DoWindowContents(Rect rect) float horizontalLineDif = Text.CalcSize(title).y + StandardMargin / 2; float inputOneLabelDif = Text.CalcSize(inputOneLabel).y + StandardMargin; - float inputOneDif = inputOneLabelDif + 30f; + float inputOneDif = inputOneLabelDif + 28f; Text.Font = GameFont.Medium; Widgets.Label(new Rect(centeredX - Text.CalcSize(title).x / 2, rect.y, Text.CalcSize(title).x, Text.CalcSize(title).y), title); @@ -62,17 +63,16 @@ public override void DoWindowContents(Rect rect) DrawInputOne(centeredX, inputOneLabelDif, inputOneDif); - if (Widgets.ButtonText(new Rect(new Vector2(rect.xMin, rect.yMax - buttonY), new Vector2(buttonX, buttonY)), "Confirm")) + if (Widgets.ButtonText(GetRectForLocation(rect, defaultButtonSize, RectLocation.BottomLeft), "Confirm")) { DialogManager.dialog1ResultOne = inputOneResult; - - if (actionYes != null) actionYes.Invoke(); + actionYes?.Invoke(); Close(); } - if (Widgets.ButtonText(new Rect(new Vector2(rect.xMax - buttonX, rect.yMax - buttonY), new Vector2(buttonX, buttonY)), "Cancel")) + if (Widgets.ButtonText(GetRectForLocation(rect, defaultButtonSize, RectLocation.BottomRight), "Cancel")) { - if (actionNo != null) actionNo.Invoke(); + actionNo?.Invoke(); Close(); } } diff --git a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs index fde9cbda..4b8edc35 100644 --- a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs +++ b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Linq; +using System.Reflection; using RimWorld; using Shared; using UnityEngine; @@ -13,7 +15,7 @@ public class RT_Dialog_MarketListing : Window { //UI - public override Vector2 InitialSize => new Vector2(400f, 400f); + public override Vector2 InitialSize => new Vector2(600f, 400f); private Vector2 scrollPosition = Vector2.zero; @@ -35,7 +37,7 @@ public class RT_Dialog_MarketListing : Window //Variables - private readonly ThingDataFile[] elements; + private readonly Thing[] elements; private readonly Map settlementMap; @@ -45,8 +47,17 @@ public RT_Dialog_MarketListing(ThingDataFile[] elements, Map settlementMap, Acti title = "Global Market"; description = $"Silver available for trade: {RimworldManager.GetSpecificThingCountInMap(ThingDefOf.Silver, settlementMap)}"; - - this.elements = elements; + List things = new List(); + foreach (var element in elements) + { + Thing thing = null; + try { thing = ThingScribeManager.StringToItem(element); } catch{ continue; } + if (thing != null) + { + things.Add(thing); + } + } + this.elements = things.ToArray(); this.actionClick = actionClick; this.actionCancel = actionCancel; this.settlementMap = settlementMap; @@ -124,11 +135,10 @@ private void FillMainRect(Rect mainRect) try { - Thing thing = ThingScribeManager.StringToItem(elements[i]); - if (thing.MarketValue > 0) DrawCustomRow(rect, thing, num4); + if (elements[i].MarketValue > 0) DrawCustomRow(rect, elements[i], num4); else continue; } - catch { continue; } + catch {; continue; } } num += 30f; @@ -143,8 +153,11 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) Text.Font = GameFont.Small; Rect fixedRect = new Rect(new Vector2(rect.x, rect.y + 5f), new Vector2(rect.width - 16f, rect.height - 5f)); if (index % 2 == 0) Widgets.DrawHighlight(fixedRect); - - Widgets.Label(fixedRect, $"{toDisplay.Label.CapitalizeFirst()} > ${toDisplay.MarketValue}/u"); + + string[] names = GetDisplayNames(toDisplay); + string displayName = names[0]; + string displaySimple = names[1]; + Widgets.Label(fixedRect, $"{displayName.CapitalizeFirst()}"); if (Widgets.ButtonText(new Rect(new Vector2(rect.xMax - selectButtonX, rect.yMax - selectButtonY), new Vector2(selectButtonX, selectButtonY)), "Select")) { DialogManager.dialogMarketListingResult = index; @@ -172,8 +185,99 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) else DialogManager.PushNewDialog(new RT_Dialog_Error("You do not have enough silver!")); } }; - DialogManager.PushNewDialog(new RT_Dialog_1Input("Quantity to request", "Type the quantity you want to request", toDo, null)); + + string title = $"{displaySimple} request"; + string description = $"Max ammount to request: {toDisplay.stackCount} | Price per unit: {toDisplay.MarketValue}"; + DialogManager.PushNewDialog(new RT_Dialog_1Input(title, description, toDo, null)); + } + } + + private string[] GetDisplayNames(Thing thing) + { + string text = thing.LabelCapNoCount.CapitalizeFirst() + $" x{thing.stackCount} "; + string textSimple = thing.LabelCapNoCount.CapitalizeFirst(); + + Type type; + FieldInfo fieldInfo; + ReadingOutcomeDoerGainResearch research; + QualityCategory qc; + + //Exceptions of things that must be handled differently + + switch (thing.def.defName) + { + case "TextBook": + Book book = (Book)thing; + text = book.def.defName + ": "; + book.BookComp.TryGetDoer(out BookOutcomeDoerGainSkillExp xp); + if (xp != null) + { + foreach (KeyValuePair pair in xp.Values) text += $"{pair.Key.defName}, "; + } + thing.TryGetQuality(out qc); + + text += QualityUtility.GetLabelShort(qc); + textSimple = thing.def.defName + " "; + break; + + case "Schematic": + book = (Book)thing; + text = book.def.defName + ": "; + book.BookComp.TryGetDoer(out research); + if (research != null) + { + type = research.GetType(); + fieldInfo = type.GetField("values", BindingFlags.NonPublic | BindingFlags.Instance); + Dictionary researchDict = (Dictionary)fieldInfo.GetValue(research); + foreach (ResearchProjectDef key in researchDict.Keys) text += $"{key.defName}, "; + } + thing.TryGetQuality(out qc); + + text += QualityUtility.GetLabelShort(qc); + textSimple = thing.def.defName + " "; + break; + + case "Novel": + book = (Book)thing; + text = book.def.defName + ": "; + type = book.GetType(); + fieldInfo = type.GetField("joyFactor", BindingFlags.NonPublic | BindingFlags.Instance); + text += (float)fieldInfo.GetValue(book) * 100 + "% recreation, "; + thing.TryGetQuality(out qc); + + text += QualityUtility.GetLabelShort(qc); + textSimple = thing.def.defName + " "; + break; + + case "Tome": + book = (Book)thing; + text = book.def.defName + ": "; + book.BookComp.TryGetDoer(out research); + if (research != null) + { + type = research.GetType(); + fieldInfo = type.GetField("values", BindingFlags.NonPublic | BindingFlags.Instance); + Dictionary researchDict = (Dictionary)fieldInfo.GetValue(research); + foreach (ResearchProjectDef key in researchDict.Keys) text += $"{key.defName}, "; + + type = book.GetType(); + fieldInfo = type.GetField("mentalBreakChancePerHour", BindingFlags.NonPublic | BindingFlags.Instance); + text += "mental break:"+ ((float)fieldInfo.GetValue(book) * 100).ToStringDecimalIfSmall() +"% "; + thing.TryGetQuality(out qc); + + text += QualityUtility.GetLabel(qc); + textSimple = thing.def.defName + " "; + } + break; + + case "Genepack": + Genepack pack = (Genepack)thing; + text = pack.def.defName + ": "; + foreach (GeneDef gene in pack.GeneSet.GenesListForReading) text += $"{gene.label}, "; + break; } + + return new string[] {text, textSimple}; } } } diff --git a/Source/Client/Managers/DeepScribeManager.cs b/Source/Client/Managers/DeepScribeManager.cs index 1ba33b49..a41c4cd8 100644 --- a/Source/Client/Managers/DeepScribeManager.cs +++ b/Source/Client/Managers/DeepScribeManager.cs @@ -983,8 +983,8 @@ public static Thing[] GetItemsFromString(TransferData transferData) public static ThingDataFile ItemToString(Thing thing, int thingCount) { ThingDataFile thingData = new ThingDataFile(); - Thing toUse = null; + if (GetItemMinified(thing, thingData)) toUse = thing.GetInnerIfMinified(); else toUse = thing; @@ -1010,6 +1010,7 @@ public static ThingDataFile ItemToString(Thing thing, int thingCount) public static Thing StringToItem(ThingDataFile thingData) { + Thing thing = SetItem(thingData); SetItemQuantity(thing, thingData); @@ -1137,6 +1138,7 @@ private static void GetBookDetails(Thing thing, ThingDataFile thingData) } thingData.BookData = bookData; + Logger.Warning(bookData.title); } catch (Exception e) { Logger.Warning(e.ToString()); } } @@ -1769,13 +1771,13 @@ public static bool CheckIfThingIsMinified(Thing thing) public static bool CheckIfThingIsBook(Thing thing) { - if (!ModsConfig.AnomalyActive) return false; if (thing.def.defName == ThingDefOf.TextBook.defName) return true; else if (thing.def.defName == ThingDefOf.Schematic.defName) return true; - else if (thing.def.defName == ThingDefOf.Tome.defName) return true; else if (thing.def.defName == ThingDefOf.Novel.defName) return true; - else return false; + if (!ModsConfig.AnomalyActive) return false; + if (thing.def.defName == ThingDefOf.Tome.defName) return true; + return false; } public static bool CheckIfThingIsGenepack(Thing thing) @@ -1783,7 +1785,7 @@ public static bool CheckIfThingIsGenepack(Thing thing) if (!ModsConfig.BiotechActive) return false; if (thing.def.defName == ThingDefOf.Genepack.defName) return true; - else return false; + return false; } public static bool CheckIfThingIsXenoGerm(Thing thing) diff --git a/Source/Server/Managers/MarketManager.cs b/Source/Server/Managers/MarketManager.cs index 2d1d8feb..64886d0b 100644 --- a/Source/Server/Managers/MarketManager.cs +++ b/Source/Server/Managers/MarketManager.cs @@ -55,7 +55,7 @@ private static void AddToMarket(ServerClient client, MarketData marketData) NetworkHelper.SendPacketToAllClients(packet, client); } - private static void RemoveFromMarket(ServerClient client, MarketData marketData) + private static void RemoveFromMarket(ServerClient client, MarketData marketData) { if (marketData._quantityToManage == 0) { @@ -99,22 +99,38 @@ private static void SendMarketStock(ServerClient client, MarketData marketData) private static void TryCombineStackIfAvailable(ServerClient client, ThingDataFile thingData) { - if (thingData.Quantity <= 0) + if (thingData.Quantity <= 0) ResponseShortcutManager.SendIllegalPacket(client, "Tried to sell illegal quantity at market"); + else { - ResponseShortcutManager.SendIllegalPacket(client, "Tried to sell illegal quantity at market"); - return; - } + //Check if thing is book to handle differently + if (thingData.BookData.title != "null") Master.marketValues.MarketStock.Add(thingData); - foreach (ThingDataFile stockedItem in Master.marketValues.MarketStock.ToArray()) - { - if (stockedItem.DefName == thingData.DefName && stockedItem.MaterialDefName == thingData.MaterialDefName) + //Check if thing is genepack to handle differently + else if (thingData.GenepackData.genepackDefs.Count != 0) Master.marketValues.MarketStock.Add(thingData); + + //Act as if normal thing + else { - stockedItem.Quantity += thingData.Quantity; - return; + foreach (ThingDataFile stockedItem in MarketManagerHelper.GetMarketStockSafe()) + { + if (stockedItem.DefName == thingData.DefName && stockedItem.MaterialDefName == thingData.MaterialDefName) + { + stockedItem.Quantity += thingData.Quantity; + return; + } + } + + Master.marketValues.MarketStock.Add(thingData); } } + } + } - Master.marketValues.MarketStock.Add(thingData); + public static class MarketManagerHelper + { + public static ThingDataFile[] GetMarketStockSafe() + { + return Master.marketValues.MarketStock.ToArray(); } } }