public InventoryMerchantPane(MerchantId id) { 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( InventoryType.Merchant, (ushort)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 header = new Header(new StringId(AssetType.SystemText, 0, (int)SystemTextId.Shop_Merchant)); var stack = new VerticalStack(header, slotHalfFrame) { Greedy = false }; AttachChild(stack); }
// 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 UiItemSprite(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); }
public Slider(Func <int> getter, Action <int> setter, int min, int max, Func <int, string> format = null) { _getter = getter; _setter = setter; _min = min; _max = max; _decrement = new Button("<") { Typematic = true }.OnClick(Decrement); _increment = new Button(">") { Typematic = true }.OnClick(Increment); var track = new SliderTrack(getter, x => _setter(Math.Clamp(x, _min, _max)), min, max, format); _frame = new ButtonFrame(track) { State = ButtonState.Pressed, Padding = 0 }; AttachChild(_decrement); AttachChild(_frame); AttachChild(_increment); }
public FixedSizePanel(int width, int height, IUiElement content) : base(null) { var frame = new ButtonFrame(content) { State = ButtonState.Pressed }; Children.Add(new Padding(width, height)); Children.Add(frame); }
public FixedSizePanel(int width, int height, IUiElement content) { var frame = new ButtonFrame(content) { State = ButtonState.Pressed }; AttachChild(new Spacing(width, height)); AttachChild(frame); }
// Inner area 16x16 w/ 1-pixel button frame public InventoryBodyPart(PartyCharacterId activeCharacter, ItemSlotId itemSlotId) : base(activeCharacter, SlotHandlers) { SlotId = itemSlotId; _sprite = new UiItemSprite(ItemSpriteId.Nothing); Frame = new ButtonFrame(new FixedSize(16, 16, _sprite)) { Padding = -1 }; Children.Add(Frame); }
public InventoryMidPane(PartyCharacterId activeCharacter, InventoryConfig.PlayerInventory config) { var background = new FixedPositionStack(); background.Add(new UiSprite <FullBodyPictureId>((FullBodyPictureId)activeCharacter), 1, -3); Children.Add(background); var bodyStack = new FixedPositionStack(); foreach (var bodyPart in config) { var itemSlotId = bodyPart.Key; var position = bodyPart.Value; bodyStack.Add(new InventoryBodyPart(activeCharacter, itemSlotId), (int)position.X, (int)position.Y); } var frame = new ButtonFrame(bodyStack) { Theme = new FrameTheme() }; var labelStack = new HorizontalStack( new InventoryOffensiveLabel(activeCharacter), new InventoryWeightLabel(activeCharacter), new InventoryDefensiveLabel(activeCharacter) ); var mainStack = new VerticalStack( new Header(new DynamicText(() => { var member = Resolve <IParty>()[activeCharacter]; var settings = Resolve <ISettings>(); if (member == null) { return(new TextBlock[0]); } var name = member.Apparent.GetName(settings.Gameplay.Language); return(new[] { new TextBlock(name) { Alignment = TextAlignment.Center } }); })), new HorizontalStack( new Padding(3, 0), frame, new Padding(3, 0)), labelStack ); Children.Add(mainStack); }
public ProgressBar(ITextSource hover, Func <int> getValue, Func <int> getMax, int absoluteMax) : base(Handlers) { _hover = hover; _getValue = getValue; _getMax = getMax; _absoluteMax = absoluteMax; _bar = new UiRectangle(CommonColor.Blue4); _frame = new ButtonFrame(_bar) { State = ButtonState.Pressed, Padding = 0 }; Children.Add(_frame); }
public SliderThumb(Func <int> getter, Func <int, string> format = null) { On <HoverEvent>(e => _frame.State = ButtonState.Hover); On <BlurEvent>(e => _frame.State = ButtonState.Normal); _getter = getter; _format = format; _text = new SimpleText("").Center(); _frame = new ButtonFrame(_text) { Theme = ButtonTheme.SliderThumb }; AttachChild(_frame); }
private async void SignIn_Button_Clicked(object sender, EventArgs e) { List <Task> tasks = new List <Task>(); tasks.Add(Task.Run(async() => { await ButtonFrame.ScaleTo(1.025, 150, Easing.CubicInOut); await ButtonFrame.ScaleTo(1.0, 150, Easing.CubicInOut); })); Preferences.Set("WatchedTutorial", true); await Task.WhenAll(tasks); MessagingCenter.Send <Onboarding>(this, "GetStarted"); }
public ProgressBar(IText hover, Func <int> getValue, Func <int> getMax, int absoluteMax) { On <HoverEvent>(e => Hover()); On <BlurEvent>(e => Raise(new HoverTextEvent(null))); _hover = hover; _getValue = getValue; _getMax = getMax; _absoluteMax = absoluteMax; _bar = new UiRectangle(CommonColor.Blue4); _frame = AttachChild(new ButtonFrame(_bar) { State = ButtonState.Pressed, Padding = 0 }); }
public StatusBarHealthBar(int order, bool isHealth) { On <PostUpdateEvent>(e => Update()); _order = order; _isHealth = isHealth; _bar = new UiRectangle(isHealth ? CommonColor.Green5 : CommonColor.Teal3) { MeasureSize = new Vector2(20, 2) }; _frame = AttachChild(new ButtonFrame(_bar) { Theme = isHealth ? (ButtonFrame.ThemeFunction)HealthIndicatorTheme : ManaIndicatorTheme, Padding = 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); }
public InventoryRightPane(PartyCharacterId activeCharacter, bool showTotalPartyGold) { var header = new Header(new StringId(AssetType.SystemText, 0, (int)SystemTextId.Inv_Backpack)); 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( InventoryType.Player, (ushort)activeCharacter, (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 }; HorizontalStack moneyAndFoodStack; if (showTotalPartyGold) { var tf = Resolve <ITextFormatter>(); int total = Resolve <IParty>().StatusBarOrder.Sum(x => x.Apparent.Inventory.Gold.Amount); var money = new Button( new VerticalStack( new Spacing(64, 0), new UiSpriteElement <CoreSpriteId>(CoreSpriteId.UiGold) { Flags = SpriteFlags.Highlight }, new UiText(tf.Format(SystemTextId.Shop_GoldAll)), new SimpleText($"{total / 10}.{total % 10}") ) { Greedy = false }) { IsPressed = true }; moneyAndFoodStack = new HorizontalStack(money); } else { var goldButton = new LogicalInventorySlot(new InventorySlotId( InventoryType.Player, (ushort)activeCharacter, ItemSlotId.Gold)); var foodButton = new LogicalInventorySlot(new InventorySlotId( InventoryType.Player, (ushort)activeCharacter, ItemSlotId.Rations)); moneyAndFoodStack = new HorizontalStack(goldButton, foodButton); } var stack = new VerticalStack( new Spacing(0, 1), header, new Spacing(0, 1), slotHalfFrame, new Spacing(0, 2), moneyAndFoodStack, new Spacing(0, 9), new InventoryExitButton().OnClick(() => Raise(new InventoryCloseEvent())) ) { Greedy = false }; AttachChild(stack); }
public Button(IUiElement content) { On <HoverEvent>(_ => { IsHovered = true; Hover?.Invoke(); }); On <BlurEvent>(_ => { IsHovered = false; Blur?.Invoke(); }); On <UiLeftClickEvent>(e => { if (!IsHovered) { return; } if (!IsClicked) { ButtonDown?.Invoke(); } IsClicked = true; if (Typematic) { Click?.Invoke(); } e.Propagating = false; }); On <UiLeftReleaseEvent>(e => { if (!IsClicked) { return; } IsClicked = false; if (Typematic) { _typematicAccrual = 0; return; } if (!IsHovered) { return; } if (DoubleClick == null || !AllowDoubleClick || SuppressNextDoubleClick) // Simple single click only button { Click?.Invoke(); SuppressNextDoubleClick = false; return; } if (ClickTimerPending) // If they double-clicked... { DoubleClick?.Invoke(); ClickTimerPending = false; // Ensure the single-click behaviour doesn't happen. } else // For the first click, just start the double-click timer. { var config = Resolve <GameConfig>(); Raise(new StartTimerEvent(TimerName, config.UI.ButtonDoubleClickIntervalSeconds, this)); ClickTimerPending = true; } }); On <UiRightClickEvent>(e => { e.Propagating = false; IsRightClicked = true; }); On <UiRightReleaseEvent>(e => { if (IsRightClicked && IsHovered) { RightClick?.Invoke(); } IsRightClicked = false; }); On <TimerElapsedEvent>(e => { if (e.Id != TimerName) { return; } if (!ClickTimerPending) // They've already double-clicked { return; } Click?.Invoke(); ClickTimerPending = false; }); On <EngineUpdateEvent>(e => { if (!Typematic || !IsClicked) { return; } var oldAccrual = _typematicAccrual; _typematicAccrual += e.DeltaSeconds; var rate = 8 * (int)(2 * oldAccrual); var oldAmount = (int)(oldAccrual * rate); var newAmount = (int)(_typematicAccrual * rate); var delta = newAmount - oldAmount; for (int i = 0; i < delta; i++) { Click?.Invoke(); } }); _id = Interlocked.Increment(ref _nextId); _frame = AttachChild(new ButtonFrame(content)); }