/*---------------------------------------------\
        |/--------\2/---------------------------------\|^5
        ||        | | Take how many items?            ||
        ||ITEM PIC| |                                 ||
        ||1:1 size| |       151x30(inner)             ||
        |\--------/ |                                 ||
        |^6         \---------------------------------/|
        |                         ^5                 7^|
        |    [<] [=======[  3  ]==============] [>]    |
        |                   [    OK    ]   ^4          |
        \---------------------------------------------*///^5
        public ItemQuantityDialog(int depth, StringId stringId, AssetId id, int max, bool useTenths, Action <int> continuation)
            : base(DialogPositioning.Center, depth)
        {
            _continuation = continuation;
            IUiElement itemPic = new UiSpriteElement <AssetId>(id)
            {
                SubId = id.Type == AssetType.ItemGraphics ? id.Id : 0
            };

            var topStack = new HorizontalStack(
                new NonGreedy(new GroupingFrame(itemPic)),
                new Spacing(2, 0),
                new GroupingFrame(new FixedSize(151, 30, new UiTextBuilder(stringId)))
                );

            Func <int, string> formatFunc = useTenths ? (Func <int, string>)FormatTenths : FormatUnits;

            var stack = new VerticalStack(
                topStack,
                new Spacing(0, 5),
                new FixedSize(106, 14, new Slider(() => _quantity, x => _quantity = x, 0, max, formatFunc)),
                new Spacing(0, 4),
                new FixedSize(52, 13,
                              new Button(SystemTextId.MsgBox_OK)
            {
                DoubleFrame = true
            }.OnClick(Close))
                );

            AttachChild(new DialogFrame(new Padding(stack, 6))
            {
                Background = DialogFrameBackgroundStyle.MainMenuPattern
            });
        }
Beispiel #2
0
    public InventoryLockPane(ILockedInventoryEvent lockEvent)
    {
        On <PickLockEvent>(_ => PickLock());
        _lockEvent = lockEvent;
        bool isChest         = lockEvent is ChestEvent;
        var  background      = new UiSpriteElement(isChest ? Base.Picture.ClosedChest : Base.Picture.WoodenDoor);
        var  backgroundStack = new FixedPositionStack();

        backgroundStack.Add(background, 0, 0);
        AttachChild(backgroundStack);

        var lockButton =
            new Button(
                new Padding(
                    new UiSpriteElement(Base.CoreSprite.Lock),
                    4))
            .OnHover(LockHovered)
            .OnBlur(() =>
        {
            Raise(new HoverTextEvent(null));
            if (Resolve <IInventoryManager>().ItemInHand.Item == null)
            {
                Raise(new SetCursorEvent(Base.CoreSprite.Cursor));
            }
        })
            .OnClick(LockClicked)         // If holding key etc
            .OnRightClick(LockRightClicked)
        ;

        AttachChild(new FixedPosition(new Rectangle(50, isChest ? 50 : 112, 32, 32), lockButton));
    }
Beispiel #3
0
 protected override void Subscribed()
 {
     if (_sprite == null)
     {
         _sprite = AttachChild(new UiSpriteElement <CoreSpriteId>(CoreSpriteId.UiExitButton));
     }
 }
Beispiel #4
0
        // 70 * 128, 4 * 6

        // Tiles are 16x20 => 64x120
        // 1 pix grid between and around, double thick on right and bottom
        // 1 + 16 + 1 + 16 + 1 + 16 + 1 + 16 + 2
        // = 4*1 + 4*16 + 2 = 70
        // Height = 6 * (1+20) + 2 = 128

        // Button Frame @ (0,0): (70,128) border 1
        // Item0: (0,0):(16,20) border 1
        // Item1: (16,0):(16,20) border 1
        // Item5: (0,20):(16,20) border 1
        // ItemIJ: (16i, 20j):(16,20) border 1

        public InventoryBackpackSlot(PartyCharacterId activeCharacter, int slotNumber)
            : base(activeCharacter, BackpackHandlers)
        {
            _slotNumber = slotNumber;
            _sprite     = new UiSpriteElement <ItemSpriteId>(0)
            {
                SubId = (int)ItemSpriteId.Nothing
            };

            var amountSource = new DynamicText(() =>
            {
                GetSlot(out var slotInfo, out _);
                return(slotInfo == null || slotInfo.Amount < 2
                    ? new TextBlock[0]
                    : new[] { new TextBlock(slotInfo.Amount.ToString())
                              {
                                  Alignment = TextAlignment.Right
                              } });
            }, x => _version);

            var text = new Text(amountSource);

            Frame = new ButtonFrame(new FixedPositionStack()
                                    .Add(_sprite, 0, 0, 16, 16)
                                    .Add(text, 0, 20 - 9, 16, 9)
                                    )
            {
                Padding = -1,
                Theme   = new InventorySlotTheme(),
                State   = ButtonState.Pressed
            };

            Children.Add(Frame);
        }
Beispiel #5
0
 public StatusBarPortrait(int order) : base(Handlers)
 {
     _order    = order;
     _portrait = new UiSpriteElement <SmallPortraitId>(SmallPortraitId.Tom);
     _health   = new StatusBarHealthBar(order, true);
     _mana     = new StatusBarHealthBar(order, false);
     Children.Add(_portrait);
     Children.Add(_health);
     Children.Add(_mana);
 }
Beispiel #6
0
 // Inner area 16x16 w/ 1-pixel button frame
 public InventoryBodyPart(PartyCharacterId activeCharacter, ItemSlotId itemSlotId)
     : base(activeCharacter, SlotHandlers)
 {
     SlotId  = itemSlotId;
     _sprite = new UiSpriteElement <ItemSpriteId>(0)
     {
         SubId = (int)ItemSpriteId.Nothing
     };
     Frame = new ButtonFrame(new FixedSize(16, 16, _sprite))
     {
         Padding = -1
     };
     Children.Add(Frame);
 }
Beispiel #7
0
        public StatusBar() : base(Handlers, DialogPositioning.StatusBar, int.MaxValue)
        {
            _sprite = new UiSpriteElement <PictureId>(PictureId.StatusBar);
            Children.Add(_sprite);
            _portraits = new StatusBarPortrait[MaxPortraits];
            for (int i = 0; i < _portraits.Length; i++)
            {
                _portraits[i] = new StatusBarPortrait(i);
                Children.Add(_portraits[i]);
            }

            _hoverText                = new Text("").Center().NoWrap();
            _descriptionText          = new Text("").Center();
            _hoverTextContainer       = new FixedPosition(new Rectangle(181, 196, 177, 10), _hoverText);
            _descriptionTextContainer = new FixedPosition(new Rectangle(181, 208, 177, 30), _descriptionText);
            Children.Add(_hoverTextContainer);
            Children.Add(_descriptionTextContainer);
        }
Beispiel #8
0
        public StatusBar() : base(DialogPositioning.StatusBar)
        {
            On <HoverTextEvent>(e => _hoverSource.Source             = e.Source);
            On <DescriptionTextEvent>(e => _descriptionSource.Source = e.Source);

            _sprite       = AttachChild(new UiSpriteElement(Base.UiBackground.SLAB));
            _sprite.SubId = 1;
            _portraits    = new StatusBarPortrait[MaxPortraits];
            for (int i = 0; i < _portraits.Length; i++)
            {
                _portraits[i] = new StatusBarPortrait(i);
                AttachChild(_portraits[i]);
            }

            var hoverText       = new UiText(_hoverSource);
            var descriptionText = new UiText(_descriptionSource);

            _hoverTextContainer       = AttachChild(new FixedPosition(new Rectangle(181, 196, 177, 10), hoverText));
            _descriptionTextContainer = AttachChild(new FixedPosition(new Rectangle(181, 208, 177, 30), descriptionText));
        }
Beispiel #9
0
        public StatusBarPortrait(int order)
        {
            On <PartyChangedEvent>(e => LoadSprite());
            On <UiLeftClickEvent>(OnClick);
            On <UiRightClickEvent>(OnRightClick);
            On <HoverEvent>(Hover);
            On <BlurEvent>(e =>
            {
                _portrait.Flags = 0;
                Raise(new HoverTextEvent(null));
            });
            On <TimerElapsedEvent>(e =>
            {
                if (e.Id == TimerName)
                {
                    OnTimer();
                }
            });

            _order    = order;
            _portrait = AttachChild(new UiSpriteElement(Base.Portrait.Tom));
            _health   = AttachChild(new StatusBarHealthBar(order, true));
            _mana     = AttachChild(new StatusBarHealthBar(order, false));
        }
    public InventorySummaryPage(PartyMemberId activeMember)
    {
        _activeMember = activeMember;

        var summarySource       = new DynamicText(BuildSummary);
        var pointsSource        = new DynamicText(BuildPoints);
        var pointsHeadingSource = new DynamicText(BuildPointsHeadings);

        var stack =
            new HorizontalStack(
                new Spacing(4, 0),
                new VerticalStack(
                    new Spacing(0, 4),
                    new GroupingFrame(new FixedSize(125, 41, new UiText(summarySource))),
                    new Spacing(0, 80),
                    new GroupingFrame(
                        new FixedSize(125, 41,
                                      new HorizontalStack(
                                          new UiText(pointsHeadingSource),
                                          new Spacing(5, 0),
                                          new FixedSize(41, 41,
                                                        new UiText(pointsSource)
                                                        ))))
                    ),
                new Spacing(4, 0)
                );

        _portrait = new UiSpriteElement(SpriteId.None)
        {
            Flags = SpriteFlags.GradientPixels
        };

        AttachChild(new LayerStack(
                        new FixedPosition(new Rectangle(0, 25, 135, 145), _portrait),
                        stack));
    }
Beispiel #11
0
    public InventoryChestPane(ChestId id)
    {
        On <InventoryChangedEvent>(e =>
        {
            if (e.Id != new InventoryId(_id))
            {
                return;
            }

            UpdateBackground();
        });

        _id         = id;
        _background = new UiSpriteElement(Base.Picture.OpenChestWithGold);

        var backgroundStack = new FixedPositionStack();

        backgroundStack.Add(_background, 0, 0);
        AttachChild(backgroundStack);

        var slotSpans = new IUiElement[InventoryHeight];

        for (int j = 0; j < InventoryHeight; j++)
        {
            var slotsInRow = new IUiElement[InventoryWidth];
            for (int i = 0; i < InventoryWidth; i++)
            {
                int index = j * InventoryWidth + i;
                slotsInRow[i] = new LogicalInventorySlot(new InventorySlotId(_id, (ItemSlotId)((int)ItemSlotId.Slot0 + index)));
            }
            slotSpans[j] = new HorizontalStack(slotsInRow);
        }

        var slotStack     = new VerticalStack(slotSpans);
        var slotHalfFrame = new ButtonFrame(slotStack)
        {
            Theme = ButtonTheme.InventoryOuterFrame, Padding = -1
        };
        var goldButton = new LogicalInventorySlot(new InventorySlotId(_id, ItemSlotId.Gold));
        var foodButton = new LogicalInventorySlot(new InventorySlotId(_id, ItemSlotId.Rations));

        var takeAllButton =
            new Button(
                (UiElement) new UiTextBuilder(TextId.From(Base.UAlbionString.TakeAll)).Center()
                ).OnClick(() => Raise(new InventoryTakeAllEvent(_id)));

        var header            = new Header(Base.SystemText.Chest_Chest);
        var moneyAndFoodStack = new HorizontalStack(goldButton, takeAllButton, foodButton);

        var stack = new VerticalStack(
            header,
            slotHalfFrame,
            new Spacing(0, 78),
            moneyAndFoodStack
            )
        {
            Greedy = false
        };

        AttachChild(stack);
    }
    /*---------------- item name (yellow) ---------------\
    |/--------------\ Type        Normal                 |
    ||              | Weight      1100 g                 |
    ||              | Damage      0                      |
    ||   ITEM PIC   | Protection  1                      |
    ||              | -----------------------------------|
    ||              | Can be used by:                    |
    |\--------------/ Pilot               Oqulo Kamulos  |
    |                 Scientist           Warrior        |
    |                 Druid                              |
    |                 Enlightened One                    |
    |                 Technician                         |
    \---------------------------------------------------*/
    public InventoryDetailsDialog(ItemData item) : base(DialogPositioning.Center, 1)
    {
        if (item == null)
        {
            throw new ArgumentNullException(nameof(item));
        }

        var heading = new Header(item.Name);
        var itemPic = new UiSpriteElement(item.Icon)
        {
            SubId = item.IconSubId,
            Flags = SpriteFlags.GradientPixels
        };

        var picFrame = new FixedSize(64, 64, new GroupingFrame(itemPic))
        {
            Position = DialogPositioning.Top
        };

        var attribStack = new HorizontalStack(
            new VerticalStack(
                new UiTextBuilder(Base.SystemText.Examine1_Type).NoWrap(),
                new UiTextBuilder(Base.SystemText.Examine1_Weight).NoWrap(),
                new UiTextBuilder(Base.SystemText.Examine1_Damage).NoWrap(),
                new UiTextBuilder(Base.SystemText.Examine1_Protection).NoWrap()
                ),
            new Spacing(2, 0),
            new VerticalStack(
                new UiTextBuilder(Describe.DescribeItemType(item.TypeId)).NoWrap(),
                new SimpleText($"{item.Weight} g").NoWrap(),                                    // i18n Literal String
                new SimpleText(item.Damage.ToString(CultureInfo.InvariantCulture)).NoWrap(),    // i18n
                new SimpleText(item.Protection.ToString(CultureInfo.InvariantCulture)).NoWrap() // i18n
                )
            );

        var classElements =
            Enum.GetValues(typeof(PlayerClass))
            .Cast <PlayerClass>()
            .Where(x => item.Class.IsAllowed(x))
            .Select(x => (IUiElement) new UiTextBuilder(Describe.DescribePlayerClass(x)).NoWrap());

        var classStack = new HorizontalStack(
            new VerticalStack(classElements.Take(5).ToArray()),
            new Spacing(2, 0),
            new VerticalStack(classElements.Skip(5).ToArray())
            );

        var stack = new VerticalStack(
            heading,
            new Spacing(0, 2),
            new HorizontalStack(
                picFrame,
                new Spacing(4, 0),
                new VerticalStack(
                    attribStack,
                    new Spacing(0, 2),
                    new Divider(CommonColor.Yellow4),
                    new Spacing(0, 2),
                    new UiTextBuilder((TextId)Base.SystemText.Misc_CanBeUsedBy),
                    classStack
                    )
                ),
            new Spacing(0, 2),
            new FixedSize(52, 13,
                          new Button(Base.SystemText.MsgBox_OK)
        {
            DoubleFrame = true
        }.OnClick(Close))
            );

        AttachChild(new DialogFrame(new Padding(stack, 6))
        {
            Background = DialogFrameBackgroundStyle.MainMenuPattern
        });
    }
Beispiel #13
0
        public VisualInventorySlot(InventorySlotId slotId, IText amountSource, Func <IReadOnlyItemSlot> getSlot)
        {
            On <IdleClockEvent>(e => _frameNumber++);

            _slotId  = slotId;
            _getSlot = getSlot;
            _overlay = new UiSpriteElement(Base.CoreSprite.UiBroken)
            {
                IsActive = false
            };
            var text = new UiText(amountSource);

            if (!slotId.Slot.IsSpecial())
            {
                _size = slotId.Slot.IsBodyPart() ?
                        new Vector2(18, 18) : //16x16 surrounded by 1px borders
                        new Vector2(16, 20);
                _sprite = new UiSpriteElement(SpriteId.None);
                _button = AttachChild(new Button(new FixedPositionStack()
                                                 .Add(
                                                     new LayerStack(
                                                         _sprite,
                                                         _overlay),
                                                     1, 1, 16, 16) //16x16 surrounded by 1px borders
                                                 .Add(text, 0, 20 - 9, 16, 9))
                {
                    Padding = -1,
                    Margin  = 0,
                    Theme   = slotId.Slot.IsBodyPart()
                                ? (ButtonFrame.ThemeFunction)ButtonTheme.Default
                                : ButtonTheme.InventorySlot,

                    IsPressed = !slotId.Slot.IsBodyPart()
                }
                                      .OnHover(() => Hover?.Invoke())
                                      .OnBlur(() => Blur?.Invoke())
                                      .OnClick(() => Click?.Invoke())
                                      .OnRightClick(() => RightClick?.Invoke())
                                      .OnDoubleClick(() => DoubleClick?.Invoke())
                                      .OnButtonDown(() => ButtonDown?.Invoke()));
            }
            else
            {
                _sprite = new UiSpriteElement(
                    slotId.Slot == ItemSlotId.Gold
                        ? Base.CoreSprite.UiGold
                        : Base.CoreSprite.UiFood);

                _button = AttachChild(new Button(
                                          new VerticalStack(
                                              new Spacing(31, 0),
                                              _sprite,
                                              new UiText(amountSource)
                                              )
                {
                    Greedy = false
                })
                                      .OnHover(() => Hover?.Invoke())
                                      .OnBlur(() => Blur?.Invoke())
                                      .OnClick(() => Click?.Invoke())
                                      .OnRightClick(() => RightClick?.Invoke())
                                      .OnDoubleClick(() => DoubleClick?.Invoke())
                                      .OnButtonDown(() => ButtonDown?.Invoke()));
            }
        }