Пример #1
0
        /// <summary>
        /// Swap <see cref="UIItem"/>s from one <see cref="UIInventory"/> to the other.
        /// </summary>
        private void SwapUIItems(UIItem uiItem, bool fromPlayer, EventArg3 <Item, Trader, Trader> tradeEvent)
        {
            // Check if the trade was successful:
            // (I know this is a very ugly way of doing it, but I don't want to introduce new EventArg(s) with boolean as their return type...)
            // If we are transfering the item FROM the player, then the player shouldn't have the item in the inventory if the trade was successful and vice versa for the merchant.
            if ((fromPlayer && !PlayerController.Player.Inventory.Items.Contains(uiItem.Item)) || (!fromPlayer && PlayerController.Player.Inventory.Items.Contains(uiItem.Item)))
            {
                //Remove the old UIItem:
                if (fromPlayer)
                {
                    uiPlayerInventory.ItemGrid.RemoveUIElement(uiItem);
                }
                else
                {
                    uiMerchantInventory.ItemGrid.RemoveUIElement(uiItem);
                }

                //Assign a new instance to the reference that looks the same etc.:
                uiItem = new UIItem(new Transform(uiItem.Transform.Size), uiItem.Sprite, screen, uiItem.Item);

                //Swap the Trader references in the EventArg:
                tradeEvent.SetArguments(
                    tradeEvent.Arg1,  //Keep the item reference
                    tradeEvent.Arg3,  //Switch reference
                    tradeEvent.Arg2); //Switch reference

                //Create a new event list where the new swapped trade event and an entirely new EventArg3 can be created.
                EventArgList onButtonClickEvents = new EventArgList(
                    tradeEvent,
                    new EventArg3 <UIItem, bool, EventArg3 <Item, Trader, Trader> >(SwapUIItems, uiItem, !fromPlayer /* We want to trigger the opposite reaction */, tradeEvent)
                    );

                //Create the purchase/sell button whether or not it came from the player's inventory.
                if (fromPlayer)
                {
                    uiItem.CreatePurchaseButton(onButtonClickEvents);
                }
                else if (uiItem.Item.CanSell)
                {
                    uiItem.CreateSellButton(onButtonClickEvents);
                }

                //Add the new UIItem to the right grid:
                if (fromPlayer)
                {
                    uiMerchantInventory.ItemGrid.AddUIElement(uiItem);
                }
                else
                {
                    uiPlayerInventory.ItemGrid.AddUIElement(uiItem);
                }
            }
        }
Пример #2
0
        private void SetupUIItemsInUIInventory()
        {
            foreach (UIItem uiItem in uiInventory.Items)
            {
                if (uiItem.Item.CanUse)
                {
                    var uiItemPointer = uiItem;
                    var itemPointer   = (StarChart)uiItem.Item;

                    var @event = new EventArgList(new EventArg0(itemPointer.Use), new EventArg1 <UIItem>(uiInventory.ItemGrid.RemoveUIElement, uiItemPointer));

                    uiItem.CreateUseButton(@event);
                }
            }
        }
Пример #3
0
        public Battlefield(PlayerShip player, EnemyShip enemy)
        {
            this.Player = player;
            this.Enemy  = enemy;

            Player.Transform.Position = new Vector2(GameUIController.WidthPercent(0.1f), GameUIController.HeightPercent(0.5f));
            Player.Transform.Rotation = MathHelper.PiOver2; /* 90 degrees in radians */
            Enemy.Transform.Position  = new Vector2(GameUIController.WidthPercent(0.9f), GameUIController.HeightPercent(0.5f));
            Enemy.Transform.Rotation  = MathHelper.ToRadians(270);

            playerShotEvent = new EventArgList(new EventArg1 <ShipEntity>(Player.Attack, Enemy), new EventArg0(() => AwaitEventCallbacks = false, EndTurn));
            enemyShotEvent  = new EventArgList(new EventArg1 <ShipEntity>(Enemy.Attack, Player), new EventArg0(() => AwaitEventCallbacks = false, EndTurn));

            playerShieldEffect = new UIElement(new Transform(Player.Transform.Position, Player.Transform.Size * 2), ContentHelper.Shield_Sprite, GameUIController.CurrentScreen);
            enemyShieldEffect  = new UIElement(new Transform(Enemy.Transform.Position, Enemy.Transform.Size * 2), ContentHelper.Shield_Sprite, GameUIController.CurrentScreen);

            playerShieldEffect.Visable = false;
            enemyShieldEffect.Visable  = false;
        }