예제 #1
0
        private Task <InventoryItems> GetInventory(string weapons, string ammo, string armor)                                                                  //getting item info for every single one for user
        {
            AmmoReq req;

            return(Task.Run(() =>
            {
                req = new AmmoReq()
                {
                    weapon_ids = weapons, ammo_ids = ammo, armor_ids = armor
                };
                string post = JsonConvert.SerializeObject(req);
                items = JsonConvert.DeserializeObject <InventoryItems>(Methods.POST_request(post, "get-inventory"));
                return items;
            }));
        }
예제 #2
0
        private async Task DownloadInventoryItems(Player player, bool isReBuild)                                                                //main drawing item grid method
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                UserDialogs.Instance.ShowLoading("Загрузка...");
                InventoryItems itemList = await GetInventory(player.weapon_ids, player.ammo_ids, player.armor_ids);

                List <Uri> uriList = await GetImages(itemList);

                int num        = uriList.Count;
                int column_num = 3;

                CreateGrid(num, column_num, itemList, uriList, isReBuild);
                UserDialogs.Instance.HideLoading();
            });
        }
예제 #3
0
        private void CreateGrid(int num, int column_num, InventoryItems itemList, List <Uri> uriList, bool isReBuild)                           //building a grid
        {
            if (isReBuild)                                                                                                                      //if grid is now rebuilding, clear all grid cells
            {
                img_grid.ColumnDefinitions.Clear();
                img_grid.RowDefinitions.Clear();
                img_grid.Children.Clear();
            }
            for (int i = 0; i < column_num; i++)                                                                                                //adding columns
            {
                img_grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }


            int rows = (int)(((double)num / column_num) + 0.99);                                                                                //preliminary counting and adding rows

            for (int i = 0; i < rows; i++)
            {
                img_grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, HEIGHT)
                });
            }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////     VARIABLE DEFINITIONS     /////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


            List <int> free_column = new List <int>();                                                                                            //arrays for free cells
            List <int> free_row    = new List <int>();

            List <int> busy_column = new List <int>();                                                                                            // arrays for busy cells
            List <int> busy_row    = new List <int>();

            int count_col = 0, count_row = 0, item_id = 0;                                                                                      //current pos x, y and current item id
            int multislot_item = 0;


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////      CREATING FRAMES     /////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


            foreach (Uri uri in uriList)                                                                                                        //building an image
            {
                Image image = new Image()
                {
                    Scale = 1.5
                };
                image.Source = new UriImageSource
                {
                    CachingEnabled = true,
                    Uri            = uri,
                    AutomationId   = itemList.item[item_id].id
                };

                Frame frame = new Frame()                                                                                                       //building frames
                {
                    Content       = image,
                    OutlineColor  = Color.White,
                    HeightRequest = 20
                };

                var gestureRecognizer = new TapGestureRecognizer();                                                                             //Adding gesture recognizer for every single frame
                gestureRecognizer.Tapped += (o, e) => OnItemTapped(o, e);

                frame.GestureRecognizers.Add(gestureRecognizer);


                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ////////////////////////////////////////////////////////////////////////////      ITEMS DISTRIBUTION     /////////////////////////////////////////////////////////////////////////////////////////////////////////
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



                if (Convert.ToInt32(itemList.item[item_id].id) > 200 && Convert.ToInt32(itemList.item[item_id].id) < 300)                        //filling grid with "large" (2x3) items
                {
                    for (int i = 0; i < busy_row.Count; i++)
                    {
                        if ((busy_column[i] == count_col && busy_row[i] == count_row))
                        {
                            count_col++;
                            if (count_col == column_num)
                            {
                                count_col = 0;
                                count_row++;
                            }
                        }
                    }

                    img_grid.Children.Add(frame, count_col, count_row);
                    //Grid.SetColumnSpan(frame, 2);
                    frame.HeightRequest *= 4;
                    Grid.SetRowSpan(frame, 2);

                    bool exists = false;
                    for (int i = 0; i < busy_row.Count; i++)
                    {
                        if ((busy_row[i] == count_row + 1) && (busy_column[i] == count_col))
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (!exists)
                    {
                        busy_column.Add(count_col); busy_row.Add(count_row + 1);
                    }
                    exists = false;


                    multislot_item += 3;
                }
                else if (Convert.ToInt32(itemList.item[item_id].id) > 10 && Convert.ToInt32(itemList.item[item_id].id) < 100)                        //filling grid with "long" (2x1) items
                {
                    if (count_col == column_num - 1)
                    {
                        free_column.Add(count_col); free_row.Add(count_row); count_col = 0; count_row++;
                    }

                    for (int i = 0; i < busy_row.Count; i++)
                    {
                        if ((busy_column[i] == count_col && busy_row[i] == count_row) || (busy_column[i] == count_col + 1 && busy_row[i] == count_row))
                        {
                            count_col++;
                            if (count_col == column_num)
                            {
                                count_col = 0;
                                count_row++;
                            }
                        }
                    }

                    img_grid.Children.Add(frame, count_col, count_row);
                    Grid.SetColumnSpan(frame, 2);
                    count_col++;
                    multislot_item++;
                }
                else if (free_column.Count != 0)                                                                                                //filling free cells with "short" items
                {
                    for (int i = 0; i < busy_row.Count; i++)
                    {
                        if ((busy_column[i] == count_col && busy_row[i] == count_row))
                        {
                            count_col++;
                            if (count_col == column_num)
                            {
                                count_col = 0;
                                count_row++;
                            }
                        }
                    }
                    img_grid.Children.Add(frame, free_column[0], free_row[0]);
                    free_column.RemoveAt(0);
                    free_row.RemoveAt(0);
                    free_column.Add(count_col);
                    free_row.Add(count_row);
                }
                else
                {
                    for (int i = 0; i < busy_row.Count; i++)
                    {
                        if ((busy_column[i] == count_col && busy_row[i] == count_row))
                        {
                            count_col++;
                            if (count_col == column_num)
                            {
                                count_col = 0;
                                count_row++;
                            }
                        }
                    }
                    img_grid.Children.Add(frame, count_col, count_row);                                                                        //regular filling
                }
                count_col++;
                if (count_col == column_num)
                {
                    count_row++;
                    count_col = 0;
                }
                item_id++;
            }


            int rows_recount = (int)(((double)(num + multislot_item) / column_num) + 0.99);                                                     //recounting number of rows

            /*
             * while (count_col < column_num && count_col != 0)
             * {
             *  Label label = new Label();
             *  label.Text = Convert.ToString(count_col);
             *  Frame empty_frame = new Frame()
             *  {
             *      OutlineColor = Color.White,
             *      Content = label
             *  };
             *  img_grid.Children.Add(empty_frame, count_col++, count_row);
             * }
             */
            for (int i = 0; i < rows_recount - rows + 3; i++)
            {
                img_grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, HEIGHT)
                });                                                                                                                             //adding necessary rows
            }
        }