Example #1
0
    public KnownSpellButton(Rectangle rect,
                            bool spellOpposesAlignment,
                            SpellStoreData spell) : base(rect)
    {
        _spellOpposesAlignment = spellOpposesAlignment;
        _spell = spell;

        var spellName = GameSystems.Spell.GetSpellName(spell.spellEnum);

        if (GameSystems.Spell.IsDomainSpell(spell.classCode))
        {
            var domainName = GameSystems.Spell.GetSpellDomainName(spell.classCode);
            spellName += " (" + domainName + ")";
        }

        var style = spellOpposesAlignment ? "char-spell-grey" : "char-spell-body";

        _nameLabel = new WidgetText(spellName, style);
        AddContent(_nameLabel);

        OnMouseEnter += ShowSpellHelp;
        OnMouseExit  += HideSpellHelp;

        if (spellOpposesAlignment)
        {
            TooltipText = "#{char_ui_spells:12}";
        }
        else
        {
            TooltipText   = GameSystems.Spell.GetSpellName(_spell.spellEnum);
            OnRightClick += (x, y) => OnMemorizeSpell?.Invoke(_spell, null);
        }
    }
Example #2
0
    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);
        }
    }