Esempio n. 1
0
        void SwapBuildings(int index)
        {
            if (selectedBuilding.name.Length > 0)
            {
                tempHolding                  = selectedBuilding;
                selectedBuilding             = null;
                tempPlanetBuildingName.Text  = "";
                tempPlanetBuildingLevel.Text = "";
                tempBuildingImage.Source     = null;
            }
            if (buildingImages[index].name.Length > 0)
            {
                selectedBuilding             = buildingImages[index];
                buildingImages[index].Source = null;
                tempPlanetBuildingName.Text  = selectedBuilding.name;
                tempPlanetBuildingLevel.Text = selectedBuilding.level;
                tempBuildingImage.Source     = ImageSource.FromResource(selectedBuilding.imageString);
            }

            if (tempHolding.name.Length > 0)
            {
                buildingImages[index].level       = tempHolding.level;
                buildingImages[index].x           = tempHolding.x;
                buildingImages[index].y           = tempHolding.y;
                buildingImages[index].name        = tempHolding.name;
                buildingImages[index].id          = tempHolding.id;
                buildingImages[index].imageString = tempHolding.imageString;
                buildingImages[index].Source      = ImageSource.FromResource(tempHolding.imageString);

                tempHolding = null;
            }
        }
        public PlanetMap(AccountModel account, string planetName)
        {
            OuterBuilding.Children.Add(tempBuildingImage);
            OuterBuilding.Children.Add(InnerBuilding);
            InnerBuilding.Children.Add(tempPlanetBuildingName);
            InnerBuilding.Children.Add(tempPlanetBuildingLevel);
            OuterBuilding.Children.Add(submitArrangement);

            planetlbl.Text = planetName;
            ScrollView scrollMap = new ScrollView
            {
                HorizontalOptions = LayoutOptions.Fill,
                Orientation = ScrollOrientation.Horizontal,

                Content = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    Children = {
                                     grid
                                },                    
                }
            };
            int left = 0;
            int top = 1;
            int xcounter = -5;
            int ycounter = 5;
            for (int i = 0; i <= 120; i++)
            {
                var b = new BuildingImage { PLOTNUMBER = i, x = Convert.ToString(xcounter), y = Convert.ToString(ycounter), Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png") };
                xcounter++;
                if(xcounter > 5)
                {
                    xcounter = -5;
                    ycounter--;
                }
                //b.buildingImage.Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png");
                b.GestureRecognizers.Add((new TapGestureRecognizer
                {
                    Command = new Command(o =>
                    {
                        
                        var index = b.PLOTNUMBER;
                        if(index != 60) //that's the center building of the map and it's not allowed to move
                        {
                            if (selectedBuilding.name.Length > 0)
                            {
                                tempHolding.id = selectedBuilding.id;
                                tempHolding.imageString = selectedBuilding.imageString;
                                tempHolding.level = selectedBuilding.level;
                                tempHolding.name = selectedBuilding.name;

                                selectedBuilding.id = "";
                                selectedBuilding.imageString = "";
                                selectedBuilding.level = "";
                                selectedBuilding.name = "";

                                tempPlanetBuildingName.Text = "No Building Selected";
                                tempPlanetBuildingLevel.Text = "0";
                                tempBuildingImage.Source = null;
                                tempBuildingImage.Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png");
                            }
                            if (buildingImages[index].name.Length > 0)
                            {
                                selectedBuilding.id = buildingImages[index].id;
                                selectedBuilding.imageString = buildingImages[index].imageString;
                                selectedBuilding.level = buildingImages[index].level;
                                selectedBuilding.name = buildingImages[index].name;

                                buildingImages[index].Source = null;
                                buildingImages[index].Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png");
                                buildingImages[index].name = "";
                                buildingImages[index].level = "";
                                buildingImages[index].imageString = "";
                                buildingImages[index].id = "";

                                tempPlanetBuildingName.Text = selectedBuilding.name;
                                tempPlanetBuildingLevel.Text = selectedBuilding.level;
                                tempBuildingImage.Source = ImageSource.FromResource(selectedBuilding.imageString);
                            }

                            if (tempHolding.name.Length > 0)
                            {
                                buildingImages[index].level = tempHolding.level;
                                buildingImages[index].name = tempHolding.name;
                                buildingImages[index].id = tempHolding.id;
                                buildingImages[index].imageString = tempHolding.imageString;
                                buildingImages[index].Source = ImageSource.FromResource(tempHolding.imageString);

                                tempHolding.id = "";
                                tempHolding.imageString = "";
                                tempHolding.level = "";
                                tempHolding.x = "";
                                tempHolding.y = "";
                                tempHolding.name = "";
                            }
                        }
                        //SwapBuildings(b.PLOTNUMBER);
                        

                    })
                }));
                buildingImages.Add(b);
                grid.Children.Add(b, left, top);
                left++;
                
                if (left == 11)
                {
                    left = 0;
                    top++;
                }
            }

			var mainLayout = new StackLayout
            {
                Children = {
                    planetlbl,
                    scrollMap,
                    OuterBuilding
                }

            };

			Content = mainLayout;
			if (Device.OS == TargetPlatform.iOS)
			{
				mainLayout.Padding = new Thickness (0, 20, 0, 0);
			}

            this.Appearing += (sender, e) =>
            {

                planetID = (from b in account.Colonies
                            where b.Value.Equals(planetName)
                            select b.Key).First();
                LoadBuildingsAsync(account, planetID);
            };
            submitArrangement.Clicked += async (sender, e) =>
            {
                List<BuildingArrangement> movedBuildings = new List<BuildingArrangement>();
                foreach(var b in buildingImages)
                {
                    if(b.name.Length > 0)
                    {
                        movedBuildings.Add(new BuildingArrangement(b.x, b.y, b.id));
                        
                    }
                }
                string json = Body.RearrangeBuildings(1, account.SessionID, planetID, movedBuildings);
                var server = new Data.Server();
                string response = await server.GetHttpResultStringAsyncAsString(account.Server, Body.url, json);
                string s = response;
            };

        }
        void SwapBuildings(int index)
        {
            
            if (selectedBuilding.name.Length > 0)
            {
                tempHolding = selectedBuilding;
                selectedBuilding = null;
                tempPlanetBuildingName.Text = "";
                tempPlanetBuildingLevel.Text = "";
                tempBuildingImage.Source = null;
            }
            if (buildingImages[index].name.Length > 0)
            {
                selectedBuilding = buildingImages[index];
                buildingImages[index].Source = null;
                tempPlanetBuildingName.Text = selectedBuilding.name;
                tempPlanetBuildingLevel.Text = selectedBuilding.level;
                tempBuildingImage.Source = ImageSource.FromResource(selectedBuilding.imageString);
            }
            
            if(tempHolding.name.Length > 0)
            {
                buildingImages[index].level = tempHolding.level;
                buildingImages[index].x = tempHolding.x;
                buildingImages[index].y = tempHolding.y;
                buildingImages[index].name = tempHolding.name;
                buildingImages[index].id = tempHolding.id;
                buildingImages[index].imageString = tempHolding.imageString;
                buildingImages[index].Source = ImageSource.FromResource(tempHolding.imageString);

                tempHolding = null;
            }                    
        }
Esempio n. 4
0
        public PlanetMap(AccountModel account, string planetName)
        {
            OuterBuilding.Children.Add(tempBuildingImage);
            OuterBuilding.Children.Add(InnerBuilding);
            InnerBuilding.Children.Add(tempPlanetBuildingName);
            InnerBuilding.Children.Add(tempPlanetBuildingLevel);
            OuterBuilding.Children.Add(submitArrangement);

            planetlbl.Text = planetName;
            ScrollView scrollMap = new ScrollView
            {
                HorizontalOptions = LayoutOptions.Fill,
                Orientation       = ScrollOrientation.Horizontal,

                Content = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        grid
                    },
                }
            };
            int left     = 0;
            int top      = 1;
            int xcounter = -5;
            int ycounter = 5;

            for (int i = 0; i <= 120; i++)
            {
                var b = new BuildingImage {
                    PLOTNUMBER = i, x = Convert.ToString(xcounter), y = Convert.ToString(ycounter), Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png")
                };
                xcounter++;
                if (xcounter > 5)
                {
                    xcounter = -5;
                    ycounter--;
                }
                //b.buildingImage.Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png");
                b.GestureRecognizers.Add((new TapGestureRecognizer
                {
                    Command = new Command(o =>
                    {
                        var index = b.PLOTNUMBER;
                        if (index != 60) //that's the center building of the map and it's not allowed to move
                        {
                            if (selectedBuilding.name.Length > 0)
                            {
                                tempHolding.id = selectedBuilding.id;
                                tempHolding.imageString = selectedBuilding.imageString;
                                tempHolding.level = selectedBuilding.level;
                                tempHolding.name = selectedBuilding.name;

                                selectedBuilding.id = "";
                                selectedBuilding.imageString = "";
                                selectedBuilding.level = "";
                                selectedBuilding.name = "";

                                tempPlanetBuildingName.Text = "No Building Selected";
                                tempPlanetBuildingLevel.Text = "0";
                                tempBuildingImage.Source = null;
                                tempBuildingImage.Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png");
                            }
                            if (buildingImages[index].name.Length > 0)
                            {
                                selectedBuilding.id = buildingImages[index].id;
                                selectedBuilding.imageString = buildingImages[index].imageString;
                                selectedBuilding.level = buildingImages[index].level;
                                selectedBuilding.name = buildingImages[index].name;

                                buildingImages[index].Source = null;
                                buildingImages[index].Source = ImageSource.FromResource("LacunaExpress.Images.Demolish.png");
                                buildingImages[index].name = "";
                                buildingImages[index].level = "";
                                buildingImages[index].imageString = "";
                                buildingImages[index].id = "";

                                tempPlanetBuildingName.Text = selectedBuilding.name;
                                tempPlanetBuildingLevel.Text = selectedBuilding.level;
                                tempBuildingImage.Source = ImageSource.FromResource(selectedBuilding.imageString);
                            }

                            if (tempHolding.name.Length > 0)
                            {
                                buildingImages[index].level = tempHolding.level;
                                buildingImages[index].name = tempHolding.name;
                                buildingImages[index].id = tempHolding.id;
                                buildingImages[index].imageString = tempHolding.imageString;
                                buildingImages[index].Source = ImageSource.FromResource(tempHolding.imageString);

                                tempHolding.id = "";
                                tempHolding.imageString = "";
                                tempHolding.level = "";
                                tempHolding.x = "";
                                tempHolding.y = "";
                                tempHolding.name = "";
                            }
                        }
                        //SwapBuildings(b.PLOTNUMBER);
                    })
                }));
                buildingImages.Add(b);
                grid.Children.Add(b, left, top);
                left++;

                if (left == 11)
                {
                    left = 0;
                    top++;
                }
            }

            var mainLayout = new StackLayout
            {
                Children =
                {
                    planetlbl,
                    scrollMap,
                    OuterBuilding
                }
            };

            Content = mainLayout;
            if (Device.OS == TargetPlatform.iOS)
            {
                mainLayout.Padding = new Thickness(0, 20, 0, 0);
            }

            this.Appearing += (sender, e) =>
            {
                planetID = (from b in account.Colonies
                            where b.Value.Equals(planetName)
                            select b.Key).First();
                LoadBuildingsAsync(account, planetID);
            };
            submitArrangement.Clicked += async(sender, e) =>
            {
                List <BuildingArrangement> movedBuildings = new List <BuildingArrangement>();
                foreach (var b in buildingImages)
                {
                    if (b.name.Length > 0)
                    {
                        movedBuildings.Add(new BuildingArrangement(b.x, b.y, b.id));
                    }
                }
                string json     = Body.RearrangeBuildings(1, account.SessionID, planetID, movedBuildings);
                var    server   = new Data.Server();
                string response = await server.GetHttpResultStringAsyncAsString(account.Server, Body.url, json);

                string s = response;
            };
        }