public LogicalInventorySlot(InventorySlotId id) { On <InventoryChangedEvent>(e => { if (e.Id == _id.Id) { _version++; } }); _id = id; IText amountSource; if (id.Slot == ItemSlotId.Gold) { amountSource = new DynamicText(() => { var gold = Inventory?.Gold.Amount ?? 0; return(new[] { new TextBlock($"{gold / 10}.{gold % 10}") }); // i18n: May need to vary based on the current game language }, x => _version); } else if (id.Slot == ItemSlotId.Rations) { amountSource = new DynamicText(() => { var food = Inventory?.Rations.Amount ?? 0; return(new[] { new TextBlock(food.ToString(CultureInfo.InvariantCulture)) }); // i18n: Will need to be changed if we support a language that doesn't use Hindu-Arabic numerals. }, x => _version); } else { amountSource = new DynamicText(() => { var slotInfo = Slot; return(slotInfo == null || slotInfo.Amount < 2 ? Array.Empty <TextBlock>() : new[] { new TextBlock(slotInfo.Amount.ToString(CultureInfo.InvariantCulture)) { Alignment = TextAlignment.Right } }); // i18n: Will need to be changed if we support a language that doesn't use Hindu-Arabic numerals. }, x => _version); } _visual = AttachChild(new VisualInventorySlot(_id, amountSource, () => Slot)) .OnButtonDown(() => { var im = Resolve <IInventoryManager>(); var inputBinder = Resolve <IInputBinder>(); if (im.ItemInHand.Item != null || inputBinder.IsCtrlPressed || inputBinder.IsShiftPressed || inputBinder.IsAltPressed) { _visual.SuppressNextDoubleClick = true; } }) .OnClick(() => { var inputBinder = Resolve <IInputBinder>(); if (inputBinder.IsCtrlPressed) { Raise(new InventoryPickupEvent(null, _id.Id, _id.Slot)); } else if (inputBinder.IsShiftPressed) { Raise(new InventoryPickupEvent(5, _id.Id, _id.Slot)); } else if (inputBinder.IsAltPressed) { Raise(new InventoryPickupEvent(1, _id.Id, _id.Slot)); } else { Raise(new InventorySwapEvent(_id.Id, _id.Slot)); } }) .OnDoubleClick(() => Raise(new InventoryPickupEvent(null, _id.Id, _id.Slot))) .OnRightClick(OnRightClick) .OnHover(Hover) .OnBlur(Blur); }
public LogicalInventorySlot(InventorySlotId id) { On <InventoryChangedEvent>(e => { if (e.InventoryType == _id.Type && e.InventoryId == _id.Id) { _version++; } }); _id = id; IText amountSource; if (id.Slot == ItemSlotId.Gold) { amountSource = new DynamicText(() => { var gold = Inventory?.Gold.Amount ?? 0; return(new[] { new TextBlock($"{gold / 10}.{gold % 10}") }); }, x => _version); } else if (id.Slot == ItemSlotId.Rations) { amountSource = new DynamicText(() => { var food = Inventory?.Rations.Amount ?? 0; return(new[] { new TextBlock(food.ToString()) }); }, x => _version); } else { amountSource = new DynamicText(() => { var slotInfo = Slot; return(slotInfo == null || slotInfo.Amount < 2 ? new TextBlock[0] : new[] { new TextBlock(slotInfo.Amount.ToString()) { Alignment = TextAlignment.Right } }); }, x => _version); } _visual = AttachChild(new VisualInventorySlot(_id, amountSource, () => Slot)) .OnButtonDown(() => { var im = Resolve <IInventoryManager>(); var inputBinder = Resolve <IInputBinder>(); if (im.ItemInHand.Item != null || inputBinder.IsCtrlPressed || inputBinder.IsShiftPressed || inputBinder.IsAltPressed) { _visual.SuppressNextDoubleClick = true; } }) .OnClick(() => { var inputBinder = Resolve <IInputBinder>(); if (inputBinder.IsCtrlPressed) { Raise(new InventoryPickupEvent(null, _id.Type, _id.Id, _id.Slot)); } else if (inputBinder.IsShiftPressed) { Raise(new InventoryPickupEvent(5, _id.Type, _id.Id, _id.Slot)); } else if (inputBinder.IsAltPressed) { Raise(new InventoryPickupEvent(1, _id.Type, _id.Id, _id.Slot)); } else { Raise(new InventorySwapEvent(_id.Type, _id.Id, _id.Slot)); } }) .OnDoubleClick(() => Raise(new InventoryPickupEvent(null, _id.Type, _id.Id, _id.Slot))) .OnRightClick(OnRightClick) .OnHover(Hover) .OnBlur(Blur); }