Example #1
0
        public async Task LoadAsync(IGame game)
        {
            _game = game;
            _game.Events.OnSavedGameLoad.Subscribe((sender, e) => onSaveGameLoaded());
            IGameFactory factory = game.Factory;

            _panel = await factory.UI.GetPanelAsync("Inventory Panel", "../../Assets/Gui/DialogBox/inventory.bmp", 160f, 100f);

            _panel.Anchor  = new PointF(0.5f, 0.5f);
            _panel.Visible = false;

            await loadButton("Inventory Look Button", factory, "magnify/", 5f, RotatingCursorScheme.LOOK_MODE);
            await loadButton("Invntory Point Button", factory, "upLeft/", 27f, MouseCursors.POINT_MODE);

            IButton okButton = await loadButton("Inventory Ok Button", factory, "ok/", 49f);

            IButton upButton = await loadButton("Inventory Up Button", factory, "up/", 93f);

            IButton downButton = await loadButton("Inventory Down Button", factory, "down/", 115f);

            okButton.OnMouseClick(Hide, _game);

            _invWindow = factory.Inventory.GetInventoryWindow("Inventory Window", 124f, 88f, 40f, 22f, 7f, 30f);
            _invWindow.TreeNode.SetParent(_panel.TreeNode);

            upButton.OnMouseClick(_invWindow.ScrollUp, _game);
            downButton.OnMouseClick(_invWindow.ScrollDown, _game);
        }
        public void FromItem(AGSSerializationContext context, IInventoryWindow item)
        {
            Object = new ContractObject();
            Object.FromItem(context, item);

            Inventory = item.Inventory == null ? null : context.GetContract(item.Inventory);

            ItemWidth  = item.ItemSize.Width;
            ItemHeight = item.ItemSize.Height;
        }
        public IInventoryWindow GetInventoryWindow(string id, IImage image, float itemWidth, float itemHeight, IInventory inventory)
        {
            TypedParameter   idParam         = new TypedParameter(typeof(string), id);
            TypedParameter   imageParam      = new TypedParameter(typeof(IImage), image);
            IInventoryWindow inventoryWindow = _resolver.Container.Resolve <IInventoryWindow>(idParam, imageParam);

            inventoryWindow.Tint      = Colors.Transparent;
            inventoryWindow.ItemSize  = new SizeF(itemWidth, itemHeight);
            inventoryWindow.Inventory = inventory ?? _gameState.Player.Inventory;
            return(inventoryWindow);
        }
Example #4
0
 public override Task OnActivateAsync()
 {
     _inventory   = GrainFactory.GetGrain <IInventoryWindow>(Guid.NewGuid());
     _currentExp  = 0;
     _totalExp    = 0;
     _level       = 0;
     _teleportId  = 0;
     _levelMaxExp = 7;
     _position    = default(Vector3);
     _pitch       = 0;
     _yaw         = 0;
     return(base.OnActivateAsync());
 }
        public IInventoryWindow GetInventoryWindow(string id, float width, float height, float itemWidth, float itemHeight, float x, float y,
                                                   IInventory inventory = null, bool addToUi = true)
        {
            IInventoryWindow inventoryWindow = GetInventoryWindow(id, new EmptyImage(width, height), itemWidth, itemHeight, inventory);

            inventoryWindow.X = x;
            inventoryWindow.Y = y;

            if (addToUi)
            {
                _gameState.UI.Add(inventoryWindow);
            }

            return(inventoryWindow);
        }
        public IInventoryWindow GetInventoryWindow(string id,
                                                   [MethodParam(Browsable = false, Default = 80f)] float width,
                                                   [MethodParam(Browsable = false, Default = 80f)] float height,
                                                   [MethodParam(Default = 25f)] float itemWidth,
                                                   [MethodParam(Default = 25)] float itemHeight, float x, float y,
                                                   IInventory inventory = null,
                                                   [MethodParam(Browsable = false, Default = false)] bool addToUi = true)
        {
            IInventoryWindow inventoryWindow = GetInventoryWindow(id, new EmptyImage(width, height), itemWidth, itemHeight, inventory);

            inventoryWindow.X = x;
            inventoryWindow.Y = y;

            if (addToUi)
            {
                _gameState.UI.Add(inventoryWindow);
            }

            return(inventoryWindow);
        }
Example #7
0
		public async Task LoadAsync(IGame game)
		{
			_game = game;
			_game.Events.OnSavedGameLoad.Subscribe((sender, e) => onSaveGameLoaded());
			IGameFactory factory = game.Factory;

			_panel = await factory.UI.GetPanelAsync("Inventory Panel", "../../Assets/Gui/DialogBox/inventory.bmp", 160f, 100f);
			_panel.Anchor = new PointF (0.5f, 0.5f);
			_panel.Visible = false;

			await loadButton("Inventory Look Button", factory, "magnify/", 5f, RotatingCursorScheme.LOOK_MODE);
			await loadButton("Invntory Point Button", factory, "upLeft/", 27f, MouseCursors.POINT_MODE);
			IButton okButton = await loadButton("Inventory Ok Button", factory, "ok/", 49f);
			IButton upButton = await loadButton("Inventory Up Button", factory, "up/", 93f);
			IButton downButton = await loadButton("Inventory Down Button", factory, "down/", 115f);

			okButton.OnMouseClick(Hide, _game);

			_invWindow = factory.Inventory.GetInventoryWindow("Inventory Window", 124f, 88f, 40f, 22f, 7f, 30f);
			_invWindow.TreeNode.SetParent(_panel.TreeNode);

			upButton.OnMouseClick(_invWindow.ScrollUp, _game);
			downButton.OnMouseClick(_invWindow.ScrollDown, _game);
		}
Example #8
0
        public async Task <string> Run()
        {
            IGameFactory factory       = _game.Factory;
            float        panelWidth    = _game.Settings.VirtualResolution.Width * 3 / 4f;
            float        panelHeight   = _game.Settings.VirtualResolution.Height * 3 / 4f;
            const float  labelHeight   = 20f;
            const float  textBoxHeight = 20f;
            const float  buttonHeight  = 20f;
            float        itemHeight    = panelHeight / 8f;

            ITEM_WIDTH = panelWidth / 10f;
            float       itemPaddingX        = panelWidth / 10f;
            float       itemPaddingY        = panelHeight / 12f;
            const float scrollButtonWidth   = 20f;
            const float scrollButtonHeight  = 20f;
            const float scrollButtonOffsetX = 5f;
            const float scrollButtonOffsetY = 5f;
            const float okButtonWidth       = 50f;
            const float okButtonHeight      = 20f;
            const float okButtonPaddingX    = 20f;
            const float okButtonPaddingY    = 20f;
            float       okCancelWidth       = okButtonWidth * 2 + okButtonPaddingX;
            float       okButtonX           = panelWidth / 2f - okCancelWidth / 2f;
            float       cancelButtonX       = okButtonX + okButtonWidth + okButtonPaddingX;
            float       panelX        = _game.Settings.VirtualResolution.Width / 2f - panelWidth / 2f;
            float       panelY        = _game.Settings.VirtualResolution.Height / 2f - panelHeight / 2f;
            ITextConfig textBoxConfig = factory.Fonts.GetTextConfig(alignment: Alignment.BottomLeft,
                                                                    autoFit: AutoFit.TextShouldCrop, font: _game.Factory.Fonts.LoadFont(_game.Settings.Defaults.TextFont.FontFamily, 10f));

            IPanel panel = factory.UI.GetPanel("SelectFilePanel", panelWidth, panelHeight, panelX, panelY);

            panel.RenderLayer = new AGSRenderLayer(AGSLayers.UI.Z - 1);
            panel.SkinTags.Add(AGSSkin.DialogBoxTag);
            panel.Skin?.Apply(panel);
            panel.AddComponent <IModalWindowComponent>().GrabFocus();
            factory.UI.GetLabel("SelectFileTitle", _title, panelWidth, labelHeight, 0f, panelHeight - labelHeight, panel, _buttonsTextConfig);
            _fileTextBox = factory.UI.GetTextBox("SelectFileTextBox", 0f, panelHeight - labelHeight - textBoxHeight, panel, _startPath, textBoxConfig, width: panelWidth, height: textBoxHeight);

            _inventory = new AGSInventory();
            IInventoryWindow invWindow = factory.Inventory.GetInventoryWindow("SelectFileInventory", panelWidth - scrollButtonWidth - scrollButtonOffsetX * 2,
                                                                              panelHeight - labelHeight - buttonHeight - textBoxHeight - okButtonPaddingY, ITEM_WIDTH + itemPaddingX, itemHeight + itemPaddingY, 0f, okButtonPaddingY + okButtonHeight, _inventory);

            invWindow.Z = 1;
            IButton okButton         = factory.UI.GetButton("SelectFileOkButton", (string)null, null, null, okButtonX, okButtonPaddingY, panel, "OK", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton cancelButton     = factory.UI.GetButton("SelectFileCancelButton", (string)null, null, null, cancelButtonX, okButtonPaddingY, panel, "Cancel", _buttonsTextConfig, width: okButtonWidth, height: okButtonHeight);
            IButton scrollDownButton = factory.UI.GetButton("SelectFileScrollDown", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, okButton.Y + okButtonHeight + scrollButtonOffsetY, panel, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);
            IButton scrollUpButton   = factory.UI.GetButton("SelectFileScrollUp", (string)null, null, null, panelWidth - scrollButtonWidth - scrollButtonOffsetX, panelHeight - labelHeight - textBoxHeight - scrollButtonHeight - scrollButtonOffsetY, panel, "", _buttonsTextConfig, width: scrollButtonWidth, height: scrollButtonHeight);

            invWindow.TreeNode.SetParent(panel.TreeNode);

            cancelButton.MouseClicked.Subscribe(onCancelClicked);
            okButton.MouseClicked.SubscribeToAsync(onOkClicked);

            scrollDownButton.MouseClicked.Subscribe(_ => invWindow.ScrollDown());
            scrollUpButton.MouseClicked.Subscribe(_ => invWindow.ScrollUp());

            var iconFactory = factory.Graphics.Icons;

            _fileIcon           = iconFactory.GetFileIcon();
            _fileIconSelected   = iconFactory.GetFileIcon(true);
            _folderIcon         = iconFactory.GetFolderIcon();
            _folderIconSelected = iconFactory.GetFolderIcon(true);

            var arrowDownIcon = getIcon("ArrowDown", factory, scrollButtonWidth, scrollButtonHeight,
                                        iconFactory.GetArrowIcon(ArrowDirection.Down), scrollDownButton.RenderLayer);

            arrowDownIcon.Pivot   = new PointF();
            arrowDownIcon.Enabled = false;
            arrowDownIcon.TreeNode.SetParent(scrollDownButton.TreeNode);
            _game.State.UI.Add(arrowDownIcon);

            var arrowUpIcon = getIcon("ArrowUp", factory, scrollButtonWidth, scrollButtonHeight,
                                      iconFactory.GetArrowIcon(ArrowDirection.Up), scrollUpButton.RenderLayer);

            arrowUpIcon.Pivot   = new PointF();
            arrowUpIcon.Enabled = false;
            arrowUpIcon.TreeNode.SetParent(scrollUpButton.TreeNode);
            _game.State.UI.Add(arrowUpIcon);

            _fileGraphics   = getIcon("FileGraphics", factory, ITEM_WIDTH, itemHeight, _fileIcon, scrollUpButton.RenderLayer);
            _folderGraphics = getIcon("FolderGraphics", factory, ITEM_WIDTH, itemHeight, _folderIcon, scrollUpButton.RenderLayer);

            fillAllFiles(_startPath);

            _fileTextBox.OnPressingKey.Subscribe(onTextBoxKeyPressed);

            bool okGiven = await _tcs.Task;

            clearInventory();
            panel.GetComponent <IModalWindowComponent>().LoseFocus();
            destroy(panel);
            destroy(_fileGraphics);
            destroy(_folderGraphics);
            destroy(_fileTextBox);
            var result = _fileTextBox.Text;

            if (!okGiven)
            {
                return(null);
            }
            return(result);
        }
Example #9
0
 private void onSaveGameLoaded()
 {
     _panel     = _game.Find <IPanel>(_panel.ID);
     _invWindow = _game.Find <IInventoryWindow>(_invWindow.ID);
 }
Example #10
0
        public virtual async Task <bool> PlaceBy(IPlayer player, IGrainFactory grainFactory, IWorld world, BlockWorldPos position, IInventoryWindow inventoryWindow, int slotIndex, PlayerDiggingFace face, Vector3 cursorPosition)
        {
            if (IsPlaceable)
            {
                AddFace(ref position, face);
                var blockState = await world.GetBlockState(grainFactory, position);

                if ((BlockId)blockState.Id == BlockId.Air)
                {
                    var slot = await inventoryWindow.GetSlot(player, slotIndex);

                    if (!slot.IsEmpty)
                    {
                        var newState = await ConvertToBlock(player, grainFactory, world, position, slot);

                        var blockHandler = BlockHandler.Create((BlockId)newState.Id);
                        if (await blockHandler.CanBeAt(position, grainFactory, world))
                        {
                            await world.SetBlockState(grainFactory, position, newState);

                            slot.ItemCount--;
                            slot.MakeEmptyIfZero();
                            await inventoryWindow.SetSlot(player, slotIndex, slot);

                            await blockHandler.OnPlaced(player, grainFactory, world, position, newState);

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #11
0
		private void onSaveGameLoaded()
		{
			_panel = _game.Find<IPanel>(_panel.ID);
			_invWindow = _game.Find<IInventoryWindow>(_invWindow.ID);
		}