Esempio n. 1
0
        private void CreateUI()
        {
            Style.PushStyle("mapMain");
            Layout.PushLayout("mapMain");

            Style.PushStyle("panelSpriteOn");
            VerticalLayout main = new VerticalLayout();

            main.SetFixedWidth(250);
            Style.PopStyle("panelSpriteOn");

            KeyValueText currSeedLabel = new KeyValueText("currSeed", "123456789");

            currSeedLabel.SetValueTextUpdate(() => { return(mapParameter.randomSeed.ToString()); });
            Checkbox keepOldSeedCheck = new Checkbox("keepCurrSeed", (val) => keepCurrentSeed = val, false, keepCurrentSeed);

            //Slider values: 0 -> Map Size 32, Slider 4 -> Map Size 512
            KeyValueText xDesc = new KeyValueText("mapWidth", "128");

            xDesc.SetValueTextUpdate(() => { return($"{mapParameter.size.X}"); });
            Slider sizeX = new Slider((xVal) => SetMapSize(xVal, true), 0, 4, 1, GetMapSizeSliderVal(mapParameter.size.X));

            KeyValueText yDesc = new KeyValueText("mapHeight", "512");

            yDesc.SetValueTextUpdate(() => { return($"{mapParameter.size.Y}"); });
            Slider sizeY = new Slider((yVal) => SetMapSize(yVal, false), 0, 4, 1, GetMapSizeSliderVal(mapParameter.size.Y));

            /*Text terrainLabel = new Text("terrain");
             *
             * KeyValueText minHeightDesc = new KeyValueText("minHeight", "");
             * minHeightDesc.SetValueTextUpdate(() => $"{mapParameter.minHeight}");
             * Slider minHeight = new Slider((val) => mapParameter.minHeight = val, 6, 12, 1, mapParameter.minHeight);
             *
             * KeyValueText maxHeightDesc = new KeyValueText("maxHeight", "");
             * maxHeightDesc.SetValueTextUpdate(() => $"{mapParameter.maxHeight}");
             * Slider maxHeight = new Slider((val) => mapParameter.maxHeight = val, 12, 20, 1, mapParameter.maxHeight);
             *
             * KeyValueText waterDiffDesc = new KeyValueText("waterDiff", "");
             * waterDiffDesc.SetValueTextUpdate(() => $"{mapParameter.waterMinDiff}");
             * Slider waterDiff = new Slider((val) => mapParameter.waterMinDiff = val, 0, 6, 1, mapParameter.waterMinDiff);*/

            Checkbox checkWater = new Checkbox("hasWater", (val) => { mapParameter.hasWater = val; }, startValue: mapParameter.hasWater);

            Checkbox checkRivers = new Checkbox("hasRivers", (val) => { mapParameter.hasRivers = val; }, startValue: mapParameter.hasRivers);

            Checkbox checkCitiesConnect = new Checkbox("hasCityConnections", (val) => mapParameter.hasCityConnections = val, false, mapParameter.hasCityConnections);

            KeyValueText cityNumText = new KeyValueText("cityNum", "100%");

            cityNumText.SetValueTextUpdate(() => { return($"{(int)(mapParameter.citiesNumber * 100f)}%"); });
            Slider cityNumSlider = new Slider((val) => mapParameter.citiesNumber = val / 100f, 0, 100, 5, (int)(mapParameter.citiesNumber * 100f));

            KeyValueText forestText = new KeyValueText("forestSize", $"{100}%");

            forestText.SetValueTextUpdate(() => { return($"{(int)(mapParameter.forestSize * 100)}%"); });
            Slider forestSlider = new Slider((val) => mapParameter.forestSize = val / 100f, 0, 100, 10, (int)(mapParameter.forestSize * 100));

            KeyValueText resourceText = new KeyValueText("resourceSize", $"{100}%");

            resourceText.SetValueTextUpdate(() => { return($"{(int)(mapParameter.resourceSize * 100)}%"); });
            Slider resourceSlider = new Slider((val) => mapParameter.resourceSize = val / 100f, 0, 100, 10, (int)(mapParameter.resourceSize * 100));

            KeyValueText citySizeText = new KeyValueText("citySize", $"{100}%");

            citySizeText.SetValueTextUpdate(() => { return($"{mapParameter.citySize}"); });
            Slider citySizeSlider = new Slider((val) => { mapParameter.citySize = citySizeBaseValue + (val / 100f * citySizeRange - citySizeRange / 2); }, 0, 100, 5, 50);

            KeyValueText citySizeOffsetText = new KeyValueText("citySizeRandomOffset", $"{100}%");

            citySizeOffsetText.SetValueTextUpdate(() => { return($"{mapParameter.citySizeRandomOffset}"); });
            Slider citySizeOffsetSlider = new Slider((val) => { mapParameter.citySizeRandomOffset = val / 100f * citySizeOffsetMax; }, 0, 100, 5, 50);

            Text mouseOverText = new Text("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa").SetTextUpdateFunction(UpdateMouseOverTileText);

            mapGenButton = new GeneratingButton();
            mapGenButton.OnMouseClick = GenerateNewMap;

            cancelButton = new GeneratingCancelButton();
            cancelButton.OnMouseClick = CancelMapGeneration;

            Button exitButton = new Button("exit");

            exitButton.OnMouseClick = game.Exit;

            main.AddChild(mouseOverText, new Space(6), currSeedLabel, keepOldSeedCheck, new Space(6),
                          xDesc, sizeX, yDesc, sizeY, new Space(6),
                          //minHeightDesc, minHeight, maxHeightDesc, maxHeight, waterDiffDesc, waterDiff , new Space(6),
                          checkWater, checkRivers, checkCitiesConnect, cityNumText, cityNumSlider, new Space(6),
                          citySizeText, citySizeSlider, new Space(6),
                          citySizeOffsetText, citySizeOffsetSlider, new Space(6),
                          forestText, forestSlider, resourceText, resourceSlider, new Space(6),
                          mapGenButton, cancelButton, exitButton);

            uiCanvas.AddChild(main);

            Style.PopStyle("mapMain");
            Layout.PopLayout("mapMain");

            uiCanvas.FinishCreation();
        }
Esempio n. 2
0
        private void CreateUI()
        {
            mainMenu = new MainMenu(Content, StartNewGame, game.Exit);
            mainMenuCanvas.AddChild(mainMenu);
            mainMenuCanvas.Finish();

            Dictionary <string, SoundEffect> sounds = new Dictionary <string, SoundEffect>()
            {
                { "level0Intro", Content.Load <SoundEffect>("Sounds/level0Intro") },
                { "level1Intro", Content.Load <SoundEffect>("Sounds/level1Intro") },
                { "level2Intro", Content.Load <SoundEffect>("Sounds/level2Intro") },
                { "gameFinished", Content.Load <SoundEffect>("Sounds/gameFinished") },
                { "gameOver", Content.Load <SoundEffect>("Sounds/gameOver") },
            };

            transitionText = new MapTransitionText(TransitionContinueClicked, BackToMenu, game.Exit, sounds);
            transitionCanvas.AddChild(transitionText);
            transitionCanvas.Finish();


            mapCanvas.AddChild(new UnitPanel(() => { if (currentMap != null)
                                                     {
                                                         return(currentMap.GetSelectedUnit());
                                                     }
                                                     else
                                                     {
                                                         return(null);
                                                     } }, mapCanvas.sprites));
            mapCanvas.AddChild(new EnemyInfoPanel(() => { if (currentMap != null)
                                                          {
                                                              return(currentMap.GetMouseOverEnemy());
                                                          }
                                                          else
                                                          {
                                                              return(null);
                                                          } }));

            damagePopup     = new DamagePopup(camera);
            Map.damagePopup = damagePopup;
            mapCanvas.AddChild(damagePopup);


            HorizontalLayout mainButtons = new HorizontalLayout();

            mainButtons.SetMargin(6).Padding = new Point(6, 6);
            mainButtons.SetLayoutSize(LayoutSize.WrapContent, LayoutSize.FixedSize);
            mainButtons.SetFixedHeight(44);
            mainButtons.SetFixedWidth(270);
            mainButtons.sprite = mapCanvas.sprites["panel"];

            Button menuButton = new Button(mapCanvas.sprites["menu"]);

            menuButton.SetFixedSize(32, 32);

            Button musicButton = new Button(Config.musicPlaying ? mapCanvas.sprites["musicOn"] : mapCanvas.sprites["musicOff"]);

            musicButton.SetFixedSize(32, 32);
            musicButton.OnMouseClick = () => {
                Config.musicPlaying = !Config.musicPlaying;
                if (Config.musicPlaying)
                {
                    musicButton.sprite = mapCanvas.sprites["musicOn"];
                }
                else
                {
                    musicButton.sprite = mapCanvas.sprites["musicOff"];
                }
            };

            Button nextTurnButton = new Button(mapCanvas.sprites["nextTurn"]);

            nextTurnButton.SetFixedSize(32, 32);
            nextTurnButton.OnMouseClick = () => { if (currentMap != null)
                                                  {
                                                      currentMap.EndTurn();
                                                  }
            };

            KeyValueText turnText = new KeyValueText("turns", "12");

            turnText.SetLayoutSizeForBoth(LayoutSize.MatchParent);
            turnText.SetValueTextUpdate(() => { return(currentMap != null ? currentMap.turnCounter.ToString() : ""); });
            mainButtons.AddChild(menuButton, musicButton, nextTurnButton, turnText);

            mapCanvas.AddChild(mainButtons);


            EnemyTurnSign enemyTurnSign = new EnemyTurnSign(() => { return(currentMap); });

            mapCanvas.AddChild(enemyTurnSign);

            ControlsPanel controls = new ControlsPanel(mapCanvas.sprites);

            mapCanvas.AddChild(controls);

            mapCanvas.Finish();
        }