public LogbookKeyButton(LogbookKeyTranslations translations, Rectangle rect) : base(rect) { AddStyle("logbook-key-button"); _translations = translations; _title = new WidgetText(); _title.Text = " "; _title.X = 5; _title.Y = 2; _title.FixedSize = new Size(rect.Width, _title.GetPreferredSize().Height); AddContent(_title); var currentY = _title.GetPreferredSize().Height + 1; _acquiredLabel = new WidgetText(); _acquiredLabel.X = 5; _acquiredLabel.Y = currentY; AddContent(_acquiredLabel); var innerRectangle = new WidgetRectangle(); innerRectangle.X = 1; innerRectangle.Y = 1; innerRectangle.FixedSize = new Size(rect.Width - 2, rect.Height - 2); innerRectangle.Pen = new PackedLinearColorA(0xFF909090); AddContent(innerRectangle); _outerRectangle = new WidgetRectangle(); _outerRectangle.Pen = PackedLinearColorA.White; AddContent(_outerRectangle); }
private void AddRollCountLabel() { var rollCount = CurrentCritter.GetInt32(obj_f.pc_roll_count); string rollCountText; if (rollCount == -25) { rollCountText = _pointBuyLabel; } else if (rollCount < 1 || Globals.GameLib.IsIronmanGame) { rollCountText = "-"; } else { rollCountText = rollCount.ToString(CultureInfo.InvariantCulture); } _attributeRollCountLabel.Text = rollCountText; _attributeRollCountLabel.Y = 11; // Right-align _attributeRollCountLabel.X = GetContentArea().Width - _attributeRollCountLabel.GetPreferredSize().Width - 28; _attributeRollModeLabel.Y = 11; // Right-align _attributeRollModeLabel.X = _attributeRollCountLabel.X - _attributeRollModeLabel.GetPreferredSize().Width - 2; AddContent(_attributeRollCountLabel); AddContent(_attributeRollModeLabel); }
public SliderOption(string label, Func <int> getter, Action <int> setter, int minValue, int maxValue) : base(label) { _getter = getter; _setter = setter; _slider = new WidgetSlider(399, 9); _slider.SetMin(minValue); _slider.SetMax(maxValue); _slider.X = 178; _slider.Y = 2; Globals.UiManager.RemoveWindow(_slider); // Otherwise it'll show up as a top-level widget // Display the slider's min value to the left of the slider _minLabel = new WidgetText(_slider.GetMin().ToString(), "options-label-muted"); _minLabel.X = _slider.X - _minLabel.GetPreferredSize().Width - 5; _minLabel.SetCenterVertically(true); // Display the slider's max value to the left of the slider _maxLabel = new WidgetText(_slider.GetMax().ToString(), "options-label-muted"); _maxLabel.X = _slider.X + _slider.Width + 5; _maxLabel.SetCenterVertically(true); // Display the current value to the far right _valueLabel = new WidgetText(_slider.GetValue().ToString(), "options-label"); _valueLabel.X = _slider.X + _slider.Width + 40; _valueLabel.SetCenterVertically(true); _slider.SetValueChangeHandler(ValueChanged); }
private void UpdateModelScale() { var race = _pkt.raceId.GetValueOrDefault(RaceId.human); var gender = _pkt.genderId.GetValueOrDefault(Gender.Male); var raceModelScale = D20RaceSystem.GetModelScale(race, gender); var height = (int)Math.Round(_minHeightInches + _slider.Value * (_maxHeightInches - _minHeightInches)); _pkt.height = Math.Clamp(height, _minHeightInches, _maxHeightInches); _pkt.modelScale = _pkt.height * raceModelScale / _maxHeightInches; _currentHeightLabel.Text = FormatHeight(_pkt.height); // Center the text vertically at the current slider's Y position var textHeight = _currentHeightLabel.GetPreferredSize().Height; _currentHeightLabel.Y = _slider.ThumbCenterY - textHeight / 2 + 5; var heightFactor = (_pkt.height - _minHeightInches) / (float)(_maxHeightInches - _minHeightInches); _pkt.weight = (int)(_minWeight + heightFactor * (_maxWeight - _minWeight)); // Update the model scale for preview purposes var editedChar = UiSystems.PCCreation.EditedChar; editedChar?.SetInt32(obj_f.model_scale, (int)(_pkt.modelScale * 100.0)); }
private void SetHeightRange(int minHeightInches, int maxHeightInches) { _minHeightInches = minHeightInches; _maxHeightInches = maxHeightInches; _minHeightLabel.Text = FormatHeight(minHeightInches); _minHeightLabel.X = _slider.X - _minHeightLabel.GetPreferredSize().Width; _maxHeightLabel.Text = FormatHeight(maxHeightInches); _maxHeightLabel.X = _slider.X - _maxHeightLabel.GetPreferredSize().Width; _pkt.height = Math.Clamp(_pkt.height, minHeightInches, maxHeightInches); _slider.Value = (_pkt.height - minHeightInches) / (float)(maxHeightInches - minHeightInches); }
public LogbookKeyAcquiredPopup(LogbookKeyTranslations translations) { var doc = WidgetDoc.Load("ui/key_acquired_popup.json"); _window = doc.GetRootContainer(); doc.GetTextContent("title").Text = translations.NotificationPopupTitle; var textContainer = doc.GetContainer("textContainer"); var text = new WidgetText(); text.FixedWidth = 237; text.Text = translations.NotificationPopupText; textContainer.AddContent(text); var prompt = new WidgetText(); prompt.FixedWidth = 237; prompt.Text = translations.NotificationPopupPrompt; prompt.Y = text.GetPreferredSize().Height + 13; textContainer.AddContent(prompt); // Created @ 0x1019727c // _window.OnHandleMessage += 0x101f5850; // _window.OnBeforeRender += 0x10196a10; _window.ZIndex = 100051; _window.Name = "logbook_ui_keys_key_entry_window"; _window.Visible = false; // Created @ 0x10197385 var acceptButton = doc.GetButton("accept"); // logbook_ui_key_entry_accept_butn1.OnHandleMessage += 0x10197070; // logbook_ui_key_entry_accept_butn1.OnBeforeRender += 0x10196d70; acceptButton.Text = translations.NotificationPopupYes; acceptButton.Name = "logbook_ui_key_entry_accept_butn"; acceptButton.SetClickHandler(() => { OnChangeNotificationSetting?.Invoke(false); Hide(); }); // Created @ 0x101974c2 var declineButton = doc.GetButton("decline"); // logbook_ui_key_entry_decline_butn1.OnHandleMessage += 0x10197070; // logbook_ui_key_entry_decline_butn1.OnBeforeRender += 0x10196d70; declineButton.Text = translations.NotificationPopupNo; declineButton.Name = "logbook_ui_key_entry_decline_butn"; declineButton.SetClickHandler(Hide); }
public override void Render() { WidgetImage renderImage = null; if (ButtonState == LgcyButtonState.Hovered) { renderImage = _hoverImage; } else if (ButtonState == LgcyButtonState.Down) { renderImage = _downImage; } var contentArea = GetContentArea(); if (renderImage != null) { renderImage.SetBounds( new Rectangle( contentArea.X, contentArea.Y - 1, renderImage.GetPreferredSize().Width, renderImage.GetPreferredSize().Height ) ); renderImage.Render(); } var labelSize = _label.GetPreferredSize(); // Center horizontally and vertically within the content area var labelArea = new Rectangle( contentArea.X + (contentArea.Width - labelSize.Width) / 2, contentArea.Y + (contentArea.Height - labelSize.Height) / 2, contentArea.Width = labelSize.Width, contentArea.Height = labelSize.Height ); // Special cases for certain labels if (_stat == Stat.level) { labelArea.X = contentArea.X + 2; } else if (_stat == Stat.initiative_bonus) { labelArea.X = contentArea.X + 1; } _label.SetBounds(labelArea); _label.Render(); }
private void UpdateInput(string text) { _currentInput = text; _caretPosition = Math.Clamp(_caretPosition, 0, _currentInput.Length); // Insert the caret var displayedText = text.Insert(_caretPosition, "|"); _currentInputLabel.Text = displayedText; // This is _incredibly_ bad, but it's what vanilla ToEE did :-( while (_currentInputLabel.GetPreferredSize().Width >= _currentInputLabel.FixedWidth) { displayedText = displayedText.Substring(1); _currentInputLabel.Text = displayedText; } }
public override void Render() { WidgetImage renderImage = null; if (ButtonState == LgcyButtonState.Hovered) { renderImage = _hoverImage; } else if (ButtonState == LgcyButtonState.Down) { renderImage = _downImage; } var contentArea = GetContentArea(); if (renderImage != null) { renderImage.SetBounds( new Rectangle( contentArea.X, contentArea.Y - 1, renderImage.GetPreferredSize().Width, renderImage.GetPreferredSize().Height ) ); renderImage.Render(); } var critter = UiSystems.CharSheet.CurrentCritter; _label.Content = critter != null?_valueSupplier(critter) : null; var labelSize = _label.GetPreferredSize(); // Center horizontally and vertically within the content area var labelArea = new Rectangle( contentArea.X + (contentArea.Width - labelSize.Width) / 2, contentArea.Y + (contentArea.Height - labelSize.Height) / 2, contentArea.Width = labelSize.Width, contentArea.Height = labelSize.Height ); _label.SetBounds(labelArea); _label.Render(); }
public void RenderObjectTooltip(IGameViewport viewport, GameObject obj, GameObject observer = null) { var content = UiSystems.Tooltip.GetObjectDescriptionContent(obj, observer); if (content != null) { using var tooltipLabel = new WidgetText(content, "default-tooltip"); tooltipLabel.SetBounds(new Rectangle(0, 0, 300, 300)); var size = tooltipLabel.GetPreferredSize(); var objRect = GameSystems.MapObject.GetObjectRect(viewport, obj); var extents = new Rectangle( objRect.X + (objRect.Width - size.Width) / 2, objRect.Y - size.Height, size.Width, size.Height ); UiSystems.Tooltip.ClampTooltipToScreen(ref extents); tooltipLabel.SetBounds(extents); tooltipLabel.Render(); } }
public KnownSpellsList(Rectangle rectangle, GameObject critter, int classCode) : base(rectangle) { var spellsKnown = critter.GetSpellArray(obj_f.critter_spells_known_idx); var domainSpells = GameSystems.Spell.IsDomainSpell(classCode); // Try scrolling one spell per scrollbar-tick var buttonHeight = 10; var currentY = 0; for (var level = 0; level <= 9; level++) { var headerAdded = false; foreach (var spell in spellsKnown) { if (domainSpells != GameSystems.Spell.IsDomainSpell(spell.classCode) || !domainSpells && spell.classCode != classCode || spell.spellLevel != level) { continue; } if (!headerAdded) { var levelHeader = new WidgetText($"#{{char_ui_spells:3}} {level}", "char-spell-level"); levelHeader.Y = currentY; currentY += levelHeader.GetPreferredSize().Height; AddContent(levelHeader); headerAdded = true; } var spellOpposesAlignment = GameSystems.Spell.SpellOpposesAlignment(critter, spell.classCode, spell.spellEnum); var spellButton = new KnownSpellButton( new Rectangle(8, currentY, Width - 8, 12), spellOpposesAlignment, spell ); spellButton.Y = currentY; spellButton.OnMemorizeSpell += (spell, button) => OnMemorizeSpell?.Invoke(spell, button); currentY += spellButton.Height; Add(spellButton); buttonHeight = Math.Max(buttonHeight, spellButton.Height); } } var overscroll = currentY - Height; if (overscroll > 0) { var lines = (int)MathF.Ceiling(overscroll / (float)buttonHeight); _scrollbar = new WidgetScrollBar(); _scrollbar.X = Width - _scrollbar.Width; _scrollbar.Height = Height; // Clip existing items that overlap the scrollbar foreach (var widgetBase in GetChildren()) { if (widgetBase.X + widgetBase.Width >= _scrollbar.X) { var remainingWidth = Math.Max(0, _scrollbar.X - widgetBase.X); widgetBase.Width = remainingWidth; } } _scrollbar.SetMin(0); _scrollbar.Max = lines; _scrollbar.SetValueChangeHandler(value => { SetScrollOffsetY(value * buttonHeight); _scrollbar.Y = value * buttonHeight; // Horrible fakery, moving the scrollbar along }); Add(_scrollbar); } }