public void Draw(Rect rect, int value) { GUI.color = Style.ColorText; Text.Font = GameFont.Small; bool dragging = false; string currentControl = GUI.GetNameOfFocusedControl(); if (currentControl != focusedControl) { if (focusedControl == id && currentControl != id) { if (newValue != null) { if (newValue == value) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); } else if (newValue >= minValue && newValue <= maxValue) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); Update(newValue.Value); } else { SoundDefOf.TickLow.PlayOneShotOnCamera(); Update(newValue.Value); } } showTextField = false; } focusedControl = currentControl; } if (showTextField) { if (textFieldStyle == null) { textFieldStyle = new GUIStyle(Verse.Text.CurTextFieldStyle); textFieldStyle.alignment = TextAnchor.MiddleCenter; } if (shouldFocusField) { newValue = value; } GUI.SetNextControlName(id); string previousText = newValue == null ? "" : newValue.Value + ""; string text = GUI.TextField(rect, previousText, textFieldStyle); if (shouldFocusField) { shouldFocusField = false; GUI.FocusControl(id); } if (previousText != text) { if (string.IsNullOrEmpty(text)) { newValue = null; } else { try { newValue = int.Parse(text); } catch (Exception) { } } } if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.Tab || Event.current.keyCode == KeyCode.KeypadEnter) { GUI.FocusControl(null); } if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.Ignore) { if (!rect.Contains(Event.current.mousePosition)) { GUI.FocusControl(null); } } } else { Widgets.DrawAtlas(rect, Textures.TextureFieldAtlas); dragSlider.OnGUI(rect, value, (int v) => { Update(v); }); if (rect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseDown) { ticksSinceClick = Environment.TickCount; } else if (Event.current.type == EventType.MouseUp) { int newTicks = Environment.TickCount; if (newTicks - ticksSinceClick < ClickDelay) { showTextField = true; shouldFocusField = true; } ticksSinceClick = 0; } } dragging = DragSlider.IsDragging(); } // Draw the decrement button. Rect buttonRect = new Rect(rect.x - 17, rect.y + 6, 16, 16); if (value == minValue) { GUI.color = Style.ColorButtonDisabled; } else { if (!dragging && !showTextField) { Style.SetGUIColorForButton(buttonRect); } else { GUI.color = Style.ColorButton; } } GUI.DrawTexture(buttonRect, Textures.TextureButtonPrevious); if (value != minValue) { if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; int newValue = value - amount; Update(newValue); } } // Draw the increment button. buttonRect = new Rect(rect.x + rect.width + 1, rect.y + 6, 16, 16); if (value == maxValue) { GUI.color = Style.ColorButtonDisabled; } else { if (!dragging && !showTextField) { Style.SetGUIColorForButton(buttonRect); } else { GUI.color = Style.ColorButton; } } if (value != maxValue) { GUI.DrawTexture(buttonRect, Textures.TextureButtonNext); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; int newValue = value + amount; Update(newValue); } } GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; }
protected void DrawSelectedEquipmentList() { if (destSelection >= PrepareCarefully.Instance.Equipment.Count) { destSelection = PrepareCarefully.Instance.Equipment.Count - 1; } GUI.color = ColorBoxBackground; GUI.DrawTexture(RectDestBox, BaseContent.WhiteTex); GUI.color = ColorBoxOutline; Widgets.DrawBox(RectDestBox, 1); try { GUI.color = Color.white; GUI.BeginGroup(RectDestContent); Rect scrollRect = new Rect(0, 0, RectDestContent.width, RectDestContent.height); Rect viewRect = new Rect(scrollRect.x, scrollRect.y, scrollRect.width - 16, destScrollViewHeight); Widgets.BeginScrollView(scrollRect, ref destScrollPosition, viewRect); Rect rectEntry = RectDestEntry; Rect rectText = RectDestEntry; rectText.x += 65; rectText.width = 320; Rect rectCost = RectDestEntry; rectCost.x += 352; rectCost.y += 7; rectCost.height -= 14; rectCost.width = 60; Rect rectItem = RectDestItem; Rect rectEntryButton = RectDestEntry; rectEntryButton.width = 320; bool alternateBackground = false; float top = destScrollPosition.y - rectEntry.height; float bottom = destScrollPosition.y + RectDestBox.height; int index = -1; foreach (SelectedEquipment customPawn in PrepareCarefully.Instance.Equipment) { index++; ThingDef def = customPawn.def; EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]; if (entry == null) { string thing = def != null ? def.defName : "null"; string stuff = customPawn.stuffDef != null ? customPawn.stuffDef.defName : "null"; Log.Warning(string.Format("Could not draw unrecognized resource/equipment. Invalid item was removed. This may have been caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff)); PrepareCarefully.Instance.RemoveEquipment(customPawn); continue; } SelectedEquipment loadoutRecord = PrepareCarefully.Instance.Find(entry); if (alternateBackground) { GUI.color = ColorEntryBackground; alternateBackground = false; } else { GUI.color = ColorBoxBackground; alternateBackground = true; } if (destSelection == index) { GUI.color = ColorSelectedEntry; } GUI.DrawTexture(rectEntry, BaseContent.WhiteTex); GUI.color = ColorText; Text.Font = GameFont.Small; Text.Anchor = TextAnchor.MiddleLeft; Widgets.Label(rectText, entry.LabelNoCount); DrawEquipmentIcon(rectItem, entry); Rect fieldRect = rectCost; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); equipmentDragSlider.OnGUI(fieldRect, loadoutRecord.count, (int value) => { var record = loadoutRecord; record.count = value; }); bool dragging = DragSlider.IsDragging(); Rect buttonRect = new Rect(fieldRect.x - 17, fieldRect.y + 6, 16, 16); if (!dragging && buttonRect.Contains(Event.current.mousePosition)) { GUI.color = ButtonHighlightColor; } else { GUI.color = ButtonColor; } GUI.DrawTexture(buttonRect, Textures.TextureButtonPrevious); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; loadoutRecord.count -= amount; if (loadoutRecord.count < 0) { loadoutRecord.count = 0; } } buttonRect = new Rect(fieldRect.x + fieldRect.width + 1, fieldRect.y + 6, 16, 16); if (!dragging && buttonRect.Contains(Event.current.mousePosition)) { GUI.color = ButtonHighlightColor; } else { GUI.color = ButtonColor; } GUI.DrawTexture(buttonRect, Textures.TextureButtonNext); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; loadoutRecord.count += amount; } if (rectEntry.y > top && rectEntry.y < bottom) { if (Event.current.type == EventType.MouseDown && rectEntryButton.Contains(Event.current.mousePosition)) { if (Event.current.clickCount == 1) { if (Event.current.button == 1) { if (destSelection != index) { destSelection = index; } List <FloatMenuOption> list = new List <FloatMenuOption>(); ThingDef thingDef = customPawn.def; ThingDef stuffDef = customPawn.stuffDef; list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate { Find.WindowStack.Add(new Dialog_InfoCard(thingDef, stuffDef)); }, MenuOptionPriority.Default, null, null, 0, null, null)); Find.WindowStack.Add(new FloatMenu(list, null, false)); } else { destSelection = index; SoundDefOf.TickHigh.PlayOneShotOnCamera(); } } else if (Event.current.clickCount == 2) { if (customPawn.count > 0) { SoundDefOf.TickHigh.PlayOneShotOnCamera(); int amount = Event.current.shift ? 10 : 1; loadoutRecord.count -= amount; if (loadoutRecord.count < 0) { loadoutRecord.count = 0; } } else { SoundDefOf.TickLow.PlayOneShotOnCamera(); PrepareCarefully.Instance.RemoveEquipment(PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]); } } } } rectEntry.y += rectEntry.height; rectText.y += rectEntry.height; rectCost.y += rectEntry.height; rectItem.y += rectEntry.height; rectEntryButton.y += rectEntry.height; } if (Event.current.type == EventType.Layout) { destScrollViewHeight = rectEntry.y; } } catch (Exception e) { FatalError("Could not draw selected resources", e); } finally { Widgets.EndScrollView(); GUI.EndGroup(); } if (newDestScrollPosition >= 0) { destScrollPosition.y = newDestScrollPosition; newDestScrollPosition = -1; } GUI.color = Color.white; if (destSelection != -1) { if (Widgets.ButtonText(RectDestButton, "EdB.RemoveButton".Translate(), true, false, true)) { var customPawn = PrepareCarefully.Instance.Equipment[destSelection]; SoundDefOf.TickLow.PlayOneShotOnCamera(); PrepareCarefully.Instance.RemoveEquipment(PrepareCarefully.Instance.EquipmentEntries[customPawn.EquipmentKey]); } } }