コード例 #1
0
ファイル: GUIManager.cs プロジェクト: charbean/StrategyClean
        public void Update(GameTime theTime, SaveGameData Data, StrategyGame game, ResourceManager manager,
            Overview overview, int elapsedHours, int elapsedDays)
        {
            model.UpdateUI(manager.money, manager.income, manager.deductions, manager.net,
                elapsedHours, elapsedDays);

            mouseOverHUD = IsMouseOver();

            if (needZoomIn)
            {
                ZoomIn.Invoke(this, new EventArgs());
                zoom = systemZoom;
                needZoomIn = false;
            }

            if (NeedZoomOut)
            {
                ZoomOut.Invoke(this, new EventArgs());
                model.OnSystemZoomedOut();
                NeedZoomOut = false;
            }

            data = Data;

            mousePos = mouseState.X.ToString() + " " + mouseState.Y.ToString();
            keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            UserInterface.UpdateInput(theTime.ElapsedGameTime.TotalMilliseconds);

            debug.Update();

            UserInterface.UpdateLayout(theTime.ElapsedGameTime.TotalMilliseconds);

            if (!pause)
            {
                #region Map Move & Zoom Controls

                if (moveEnabled)
                {
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        TempCentre = new Vector2(centre.X - cameraSpeed, centre.Y);
                        if (ValidMove(TempCentre, data.MapSize, 'L'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.X += (cameraSpeed / 50f);
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        TempCentre = new Vector2(centre.X + cameraSpeed, centre.Y);
                        if (ValidMove(TempCentre, data.MapSize, 'R'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.X -= (cameraSpeed / 50f);
                        }
                    }

                    if (keyboardState.IsKeyDown(Keys.Up))
                    {
                        TempCentre = new Vector2(centre.X, centre.Y - cameraSpeed);
                        if (ValidMove(TempCentre, data.MapSize, 'U'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.Y += (cameraSpeed / 50f);
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        TempCentre = new Vector2(centre.X, centre.Y + cameraSpeed);
                        if (ValidMove(TempCentre, data.MapSize, 'D'))
                        {
                            centre = TempCentre;
                            BackgroundPosition.Y -= (cameraSpeed / 50f);
                        }
                    }
                }

                if (!mouseOverHUD)
                {

                    if (oldScrollValue != mouseState.ScrollWheelValue)
                    {
                        if (mouseState.ScrollWheelValue > oldScrollValue)
                        {
                            if (zoom >= 0.95 && zoomedIn == false)
                            {
                                zoomedIn = true;
                                needZoomIn = true;
                                systemZoom = 1;
                            }
                        }

                        if (mouseState.ScrollWheelValue > oldScrollValue)
                        {
                            if (zoom < 0.95)
                            {
                                zoom += 0.1;
                            }
                        }

                        if (mouseState.ScrollWheelValue < oldScrollValue)
                        {
                            if (zoom > 0.55)
                            {
                                zoom -= 0.1;
                                if (zoom > 0.5)
                                {
                                    if (centre.X > (data.MapSize.X - Graphics.PreferredBackBufferWidth * 1.5))
                                    {
                                        centre = new Vector2(centre.X - (Graphics.PreferredBackBufferWidth / 2f), centre.Y);
                                    }
                                }
                            }

                            if (zoomedIn)
                            {
                                zoomedIn = false;
                                NeedZoomOut = true;
                            }
                        }
                    }
                }



                currentTime += (float)theTime.ElapsedGameTime.TotalSeconds; //Time passed since last Update() 

                if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.Right))
                {
                    if (currentTime >= countDuration)
                    {
                        currentTime -= countDuration; // "use up" the time
                        cameraSpeed = 5;
                    }
                }
                else if (keyboardState.IsKeyUp(Keys.Down) || keyboardState.IsKeyUp(Keys.Up) || keyboardState.IsKeyUp(Keys.Left) || keyboardState.IsKeyUp(Keys.Right))
                {
                    cameraSpeed = 1;
                }
                #endregion
            }

            oldMouseState = mouseState;
            oldKeyboardState = keyboardState;
            oldScrollValue = mouseState.ScrollWheelValue;
        }
コード例 #2
0
        protected override void LoadContent()
        {
            rectangledraw = Content.Load<Texture2D>("white");

            account = new Account();
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteBatch2 = new SpriteBatch(GraphicsDevice);
            sf = Content.Load<SpriteFont>("Segoe_UI_9_Regular");
            glowEffect = Content.Load<Effect>("effect1");
            //glowEffect.CurrentTechnique.Passes[0].Apply();


            titlescreen = new Title(this.Content, new System.EventHandler(TitleScreenEvent));

            menuscreen = new Menu(this, graphics, this.Content,
                new System.EventHandler(MenuScreenEvent), account, GraphicsDevice,
                new System.EventHandler(ExitGamePressed));

            overviewScreen = new Overview(this.graphics, this.Content,
                new System.EventHandler(OverviewEscapeToMenu), new System.EventHandler(gamePaused),
                account, new Vector2(0, 0), new EventHandler(SystemSelected), new EventHandler(DayPassed),
                new EventHandler(SystemHovered), new EventHandler(RemoveSystemHovered),
                new EventHandler(UpdateBuildQueue), new EventHandler(UpdatePlanetResources),
                GraphicsDevice, spriteBatch);

            loadingScreen = new Loading(Content, graphics);
            camera = new Camera(GraphicsDevice.Viewport);

            DGUI = new GUIManager(graphics, Content, new EventHandler(ExitGamePressed),
                new EventHandler(OverviewEscapeToMenu), new EventHandler(SaveGamePressed),
                new EventHandler(LoadGamePressed), new EventHandler(overviewScreen.Button1Pressed),
                new EventHandler(ZoomIn), new EventHandler(overviewScreen.ZoomOut),
                new EventHandler(gamePaused), new EventHandler(planetHighlighted),
                new EventHandler(PlanetslistToggled), new EventHandler(SectorChanged),
                new EventHandler(PlanetInfoPressed), account.SaveData,
                new EventHandler(MapSystemSelected), new EventHandler(JumpToSystem),
                new EventHandler(JumpToPlanet), new EventHandler(TaxRateChanged),
                new EventHandler(GameSpeedChanged), new EventHandler(BuildingUpgraded),
                new EventHandler(BuildingDismantled), new EventHandler(AddBuildQueueItem),
                new EventHandler(RemoveBuildQueueItem), GraphicsDevice);

            //account.SaveData.Score = 6;
            //account.SaveData.MapSize = new Vector2(2000, 2000);
            currentscreen = titlescreen; // <= SETTING FIRST SCREEN TO BE SHOWN
                                         //overviewScreen.LoadContent(account, gameDetails);
                                         //DGUI.Init(this, new Point(0,0));
                                         //DGUI.StartKeyBindings();
                                         // REMOVE WHEN REVERTING BACK TO TITLE SCREEN FIRST ^^

            centre.X = 0;
            centre.Y = 0;
            zoom = 1.0f;

            FramesCounter = new FPSCounter(this, spriteBatch, sf);
        }