Exemplo n.º 1
0
        private Task <bool> preloadImages()
        {
            var tcs = new TaskCompletionSource <bool>();

            Task.Run(() => {
#if !HIDE_MAP_SCREENS
                LevelImagePanel.preload();
                MapScreen.preload(); //This takes a while
#endif
                InventoryScreen.preload();
                SelectionWindow.preload();
                ItemControl.preload();
                tcs.SetResult(true);
            });
            return(tcs.Task);
        }
Exemplo n.º 2
0
        private void updateGridItemsUI(IEnumerable <Item>?items)
        {
            itemsGrid.RowDefinitions.Clear();
            itemsGrid.Children.Clear();

            if (_model == null || items == null)
            {
                inventoryCountLabel.Content = string.Empty;
                return;
            }

            int itemCount = 0;

            foreach (var item in items !)
            {
                var itemControl = new ItemControl();
                itemControl.item   = item;
                itemControl.Height = 100;
                itemControl.Width  = 100;

                var itemButton = new Button();
                itemButton.Background          = null;
                itemButton.HorizontalAlignment = HorizontalAlignment.Center;
                itemButton.VerticalAlignment   = VerticalAlignment.Center;
                itemButton.Height           = 100;
                itemButton.Width            = 100;
                itemButton.Margin           = new Thickness(0);
                itemButton.Content          = itemControl;
                itemButton.Command          = new RelayCommand <Item>(_model !.selectItem);
                itemButton.CommandParameter = item;

                if (itemCount % 3 == 0)
                {
                    var rowDef = new RowDefinition();
                    rowDef.Height = new GridLength(100);
                    itemsGrid.RowDefinitions.Add(rowDef);
                }

                itemsGrid.Children.Add(itemButton);
                Grid.SetRow(itemButton, itemCount / 3);
                Grid.SetColumn(itemButton, itemCount % 3);

                itemCount++;
            }

            inventoryCountLabel.Content = R.formatITEMS_COUNT_LABEL(itemCount);
        }
Exemplo n.º 3
0
        private void updateGridItemsUI(IEnumerable <Item>?items)
        {
            itemsGrid.RowDefinitions.Clear();
            itemsGrid.Children.Clear();

            if (_model == null || items == null)
            {
                inventoryCountLabel.Content = string.Empty;
                return;
            }

            int itemCount = 0;

            foreach (var item in items !)
            {
                var itemControl = new ItemControl();
                itemControl.item   = item;
                itemControl.Height = 100;
                itemControl.Width  = 100;

                var itemButton = new Button();
                itemButton.Background          = null;
                itemButton.HorizontalAlignment = HorizontalAlignment.Center;
                itemButton.VerticalAlignment   = VerticalAlignment.Center;
                itemButton.Height           = 100;
                itemButton.Width            = 100;
                itemButton.Margin           = new Thickness(0);
                itemButton.Content          = itemControl;
                itemButton.Command          = new RelayCommand <Item>(_model !.selectItem);
                itemButton.CommandParameter = item;

                if (itemCount % ITEMS_PER_ROW == 0)
                {
                    var rowDef = new RowDefinition();
                    rowDef.Height = new GridLength(100);
                    itemsGrid.RowDefinitions.Add(rowDef);
                }

                itemsGrid.Children.Add(itemButton);
                Grid.SetRow(itemButton, itemCount / ITEMS_PER_ROW);
                Grid.SetColumn(itemButton, itemCount % ITEMS_PER_ROW);

                itemCount++;
            }

            var currentFilter = _model?.filter.value;

            if (currentFilter != null && currentFilter != ItemFilterEnum.Enchanted && currentFilter != ItemFilterEnum.All)
            {
                var newItemButton = new Button();
                newItemButton.HorizontalAlignment = HorizontalAlignment.Center;
                newItemButton.VerticalAlignment   = VerticalAlignment.Center;
                newItemButton.Height  = 100;
                newItemButton.Width   = 100;
                newItemButton.Margin  = new Thickness(0);
                newItemButton.Content = "+";
                newItemButton.Command = new RelayCommand <object>(_ => { this.addNewItemButton_Click(_model?.filter.value); });

                if (itemCount % ITEMS_PER_ROW == 0)
                {
                    var rowDef = new RowDefinition();
                    rowDef.Height = new GridLength(100);
                    itemsGrid.RowDefinitions.Add(rowDef);
                }

                itemsGrid.Children.Add(newItemButton);
                Grid.SetRow(newItemButton, itemCount / ITEMS_PER_ROW);
                Grid.SetColumn(newItemButton, itemCount % ITEMS_PER_ROW);
            }

            string?gameContentString = R.getString("inventory_count");

            if (gameContentString != null)
            {
                gameContentString = gameContentString
                                    .Replace("{current}", itemCount.ToString())
                                    .Replace("{max}", Constants.MAXIMUM_INVENTORY_ITEM_COUNT.ToString());
            }
            else
            {
                gameContentString = R.formatITEMS_COUNT_LABEL(itemCount, Constants.MAXIMUM_INVENTORY_ITEM_COUNT);
            }
            inventoryCountLabel.Content = gameContentString;
        }