/// <summary> /// область снизу слева - добавляемые в ордер вещи /// </summary> /// <param name="inRect"></param> public void DoWindowAddThingList(Rect inRect) { if (!ShowAddThingList) { return; } if (AddThingGrid == null) { //инициализация AddThingGrid = new GridBox <TransferableOneWay>(); Transferables = GameUtils.DistinctThings(AllThings); var dicMaxCount = Transferables.ToDictionary(t => t, t => t.MaxCount); AddThingGrid.DataSource = Transferables; AddThingGrid.LineHeight = 24f; AddThingGrid.Tooltip = null; AddThingGrid.OnDrawLine = (int line, TransferableOneWay item, Rect rectLine) => { try { if (!item.HasAnyThing) { return; } float currentWidth = rectLine.width; //ввод кол-во и кнопки < > currentWidth -= 60f + rectLine.height * 2f; Rect rect3 = new Rect(rectLine.width - 60f - rectLine.height, 0f, 60f, rectLine.height); int num2 = GenUI.CurrentAdjustmentMultiplier(); //зажали кнопку для прибавления по 10/100 if (item.CanAdjustBy(-1 * num2).Accepted) { Rect rect4 = new Rect(rect3.x - rectLine.height, 0f, rectLine.height, rectLine.height).ContractedBy(1f); if (Widgets.ButtonText(rect4, "<", true, false, true)) { item.AdjustBy(-1 * num2); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } } int countToTransfer = item.CountToTransfer; string editBuffer = item.EditBuffer; Widgets.TextFieldNumeric <int>(rect3.ContractedBy(2f), ref countToTransfer, ref editBuffer, 0f, (float)dicMaxCount[item]); item.AdjustTo(countToTransfer); item.EditBuffer = editBuffer; if (item.CanAdjustBy(1 * num2).Accepted) { Rect rect4 = new Rect(rect3.xMax, 0f, rectLine.height, rectLine.height).ContractedBy(1f); if (Widgets.ButtonText(rect4, ">", true, false, true)) { item.AdjustBy(1 * num2); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); } } //кол-во rect3 = new Rect(currentWidth - 60f, 0f, 60f, rectLine.height); Text.WordWrap = false; Text.Anchor = TextAnchor.MiddleRight; Widgets.Label(rect3, dicMaxCount[item].ToString()); currentWidth -= 60f; //цена rect3 = new Rect(currentWidth - 60f, 0f, 80f, rectLine.height); Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(rect3, item.AnyThing.MarketValue.ToStringMoney()); Text.WordWrap = true; currentWidth -= 60f; //Иконка i и описание GameUtils.DravLineThing(new Rect(0f, 0f, currentWidth, rectLine.height), item.AnyThing, Color.white); } catch (Exception e) { Log.Error(e.ToString()); } }; } //заголовок Rect rect = new Rect(0f, 0f, inRect.width, 24); inRect.yMin += rect.height; Text.Font = GameFont.Tiny; // высота Tiny 18 Text.Anchor = TextAnchor.UpperCenter; Widgets.Label(rect, "OCity_Dialog_Exchenge_Select_For_Sale".Translate(PlaceCurrent.Name)); //кнопка "Выбрать" rect.xMin += inRect.width - 150f; Text.Anchor = TextAnchor.MiddleCenter; if (Widgets.ButtonText(rect.ContractedBy(1f), "OCity_Dialog_Exchenge_Choose".Translate(), true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); AddThingListApply(); return; } Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.MiddleLeft; AddThingGrid.Area = inRect; AddThingGrid.Drow(); }
/// <summary> /// область сверху - ордера /// </summary> /// <param name="inRect"></param> public void DoWindowOrders(Rect inRect) { if (OrdersGrid == null && Orders != null && Orders.Count > 0) { //инициализация OrdersGrid = new GridBox <OrderTrade>(); //Transferables = GameUtils.DistinctThings(AllThings); //var dicMaxCount = Transferables.ToDictionary(t => t, t => t.MaxCount); OrdersGrid.DataSource = Orders; OrdersGrid.LineHeight = 24f; OrdersGrid.ShowSelected = true; OrdersGrid.Tooltip = null; OrdersGrid.OnClick += (int line, OrderTrade item) => { SetEditOrder(item); if (EditOrderIsMy) { EditOrderTitle = "OCity_Dialog_Exchenge_Edit".Translate(); } else { EditOrderTitle = "OCity_Dialog_Exchenge_Viewing_Orders".Translate() + item.Owner.Login; } }; OrdersMenu = null; OrdersGrid.OnDrawLine = (int line, OrderTrade item, Rect rectLine) => { bool showTop = line == 0; //при выводе таблицы, рисуем с первой же строкой Text.WordWrap = false; Text.Anchor = TextAnchor.MiddleLeft; try { float currentWidth = rectLine.width; //Галочка частное var rect2 = new Rect(rectLine.x + rectLine.width - 24f, rectLine.y, 24f, rectLine.height); currentWidth -= 24f; var flag = item.PrivatPlayers == null || item.PrivatPlayers.Count == 0; TooltipHandler.TipRegion(rect2, flag ? "OCity_Dialog_Exchenge_Deal_Open_Everyone".Translate() : "OCity_Dialog_Exchenge_Deal_Open_Specific".Translate(string.Join(", ", item.PrivatPlayers.Select(p => p.Login).ToArray()))); Widgets.Checkbox(rect2.position, ref flag, 24f, false); //Ник продавца rect2 = new Rect(rectLine.x + currentWidth - 200f, rectLine.y, 200f, rectLine.height); if (showTop) { OrdersMenu = new Dictionary <Rect, string>(); var rect2t = new Rect(rect2.x, 0f, rect2.width, rect2.height); OrdersMenu.Add(rect2t, "OCity_Dialog_Exchenge_Seller".Translate()); } currentWidth -= 200f; TooltipHandler.TipRegion(rect2, item.Owner.Login + Environment.NewLine + "OCity_Dialog_Exchenge_BeenOnline".Translate() + item.Owner.LastSaveTime.ToGoodUtcString()); Widgets.Label(rect2, item.Owner.Login); //Расстояние где торгуют (todo), название места rect2 = new Rect(rectLine.x + currentWidth - 200f, rectLine.y, 200f, rectLine.height); if (showTop) { var rect2t = new Rect(rect2.x, 0f, rect2.width, rect2.height); OrdersMenu.Add(rect2t, "OCity_Dialog_Exchenge_Location".Translate()); } currentWidth -= 200f; string text = ""; if (item.Place.DayPath > 0) { text = item.Place.DayPath.ToStringDecimalIfSmall() + "OCity_Dialog_Exchenge_Days".Translate(); } text += "OCity_Dialog_Exchenge_In".Translate() + item.Place.Name; TooltipHandler.TipRegion(rect2, "OCity_Dialog_Exchenge_Location_Goods".Translate() + Environment.NewLine + text); Widgets.Label(rect2, text); //Кол-во повторов rect2 = new Rect(rectLine.x + currentWidth - 60f, rectLine.y, 60f, rectLine.height); if (showTop) { var rect2t = new Rect(rect2.x, 0f, rect2.width, rect2.height); OrdersMenu.Add(rect2t, "OCity_Dialog_Exchenge_Number".Translate()); } currentWidth -= 60f; text = item.CountReady.ToString(); TooltipHandler.TipRegion(rect2, "OCity_Dialog_Exchenge_Max_Repetition_Transaction".Translate() + Environment.NewLine + text); Widgets.Label(rect2, text); //Иконки и перечень (описание в подсказке) rect2 = new Rect(rectLine.x, rectLine.y, currentWidth / 2f, rectLine.height); //от 0 до половины остатка if (showTop) { var rect2t = new Rect(rect2.x, 0f, rect2.width, rect2.height); OrdersMenu.Add(rect2t, "OCity_Dialog_Exchenge_Acquire".Translate()); } var rect3 = new Rect(rect2.x, rect2.y, rectLine.height, rectLine.height); for (int i = 0; i < item.SellThings.Count; i++) { var th = item.SellThings[i]; GameUtils.DravLineThing(rect3, th, false); var textCnt = item.SellThings[i].Count.ToString(); var textCntW = Text.CalcSize(textCnt).x; Widgets.Label(new Rect(rect3.xMax, rect3.y, textCntW, rect3.height), textCnt); TooltipHandler.TipRegion(new Rect(rect3.x, rect3.y, rect3.width + textCntW, rect3.height), th.LabelText); rect3.x += rectLine.height + textCntW + 2f; } //"-" Иконки и перечень что просят rect2 = new Rect(rectLine.x + rect2.width, rectLine.y, currentWidth - rect2.width, rectLine.height); //от конца прошлого до остатка if (showTop) { var rect2t = new Rect(rect2.x, 0f, rect2.width, rect2.height); OrdersMenu.Add(rect2t, "OCity_Dialog_Exchenge_GiveTo".Translate()); } //Дальше отличается от блока выше только SellThings -> BuyThings rect3 = new Rect(rect2.x, rect2.y, rectLine.height, rectLine.height); for (int i = 0; i < item.BuyThings.Count; i++) { var th = item.BuyThings[i]; GameUtils.DravLineThing(rect3, th, false); var textCnt = item.BuyThings[i].Count.ToString(); var textCntW = Text.CalcSize(textCnt).x; Widgets.Label(new Rect(rect3.xMax, rect3.y, textCntW, rect3.height), textCnt); TooltipHandler.TipRegion(new Rect(rect3.x, rect3.y, rect3.width + textCntW, rect3.height), th.LabelText); rect3.x += rectLine.height + textCntW + 2f; } } catch (Exception e) { Log.Error(e.ToString()); } Text.WordWrap = true; }; } //заголовок Rect rect = new Rect(inRect.x, inRect.y, inRect.width, 24f); inRect.yMin += rect.height; Text.Font = GameFont.Tiny; // высота Tiny 18 Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(rect, (Orders == null || Orders.Count == 0) ? "OCity_Dialog_Exchenge_No_Warrants".Translate() : "OCity_Dialog_Exchenge_Active_Orders".Translate(Orders.Count.ToString())); //кнопка "Выбрать" rect.xMin += inRect.width - 140f; Text.Anchor = TextAnchor.MiddleCenter; if (Widgets.ButtonText(rect.ContractedBy(1f), "OCity_Dialog_Exchenge_Update".Translate(), true, false, true)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); UpdateOrders(); return; } //заголовок таблицы var rectTop = new Rect(inRect.x, inRect.y, inRect.width, 18f); inRect.yMin += rectTop.height; if (OrdersMenu != null) { Text.Anchor = TextAnchor.MiddleCenter; foreach (var om in OrdersMenu) { var rect2t = new Rect(om.Key.x, rectTop.y, om.Key.width, rectTop.height); Widgets.Label(rect2t, om.Value); } } //всё что ниже это грид Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.MiddleLeft; Widgets.DrawMenuSection(inRect); if (OrdersGrid == null) { return; } OrdersGrid.Area = inRect.ContractedBy(5f); OrdersGrid.Drow(); }