예제 #1
0
            public override void Construct()
            {
                Root.RegisterForUpdate(this);

                OnUpdate = (sender, time) =>
                {
                    Rect.X = Root.MousePosition.X - (Rect.Width / 2);
                    Rect.Y = Root.MousePosition.Y - (Rect.Height / 2);
                    Invalidate();

                    if (Mouse.GetState().LeftButton == ButtonState.Released)
                    {
                        bool successfullyDropped = false;

                        if (CanDropHere != null)
                        {
                            var target = Root.RootItem.EnumerateWidgetsAt(Root.MousePosition.X, Root.MousePosition.Y)
                                         .Where(w => CanDropHere(this, w))
                                         .FirstOrDefault();

                            if (target != null)
                            {
                                if (OnDropped != null)
                                {
                                    OnDropped(this, target);
                                }
                                successfullyDropped = true;
                            }
                        }

                        Root.Dragging = false;
                        Root.DestroyWidget(this);

                        if (!successfullyDropped && OnDropCancelled != null)
                        {
                            OnDropCancelled(this);
                        }
                    }
                };

                base.Construct();
            }
예제 #2
0
        /// <summary>
        /// Called every frame
        /// </summary>
        /// <param name="gameTime">The current time</param>
        public void Update(DwarfTime gameTime)
        {
            foreach (var func in LazyActions)
            {
                if (func != null)
                {
                    func.Invoke();
                }
            }
            LazyActions.Clear();

            if (FastForwardToDay)
            {
                if (Time.IsDay())
                {
                    FastForwardToDay = false;
                    foreach (CreatureAI minion in Master.Faction.Minions)
                    {
                        minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue;
                    }
                    //Master.ToolBar.SpeedButton.SetSpeed(1);
                    Time.Speed = 100;
                }
                else
                {
                    //Master.ToolBar.SpeedButton.SetSpecialSpeed(3);
                    Time.Speed = 1000;
                }
            }
            //ParticleManager.Trigger("dice", CursorLightPos + Vector3.Up, Color.White, 1);

            FillClosestLights(gameTime);
            IndicatorManager.Update(gameTime);
            AspectRatio        = GraphicsDevice.Viewport.AspectRatio;
            Camera.AspectRatio = AspectRatio;

            Camera.Update(gameTime, ChunkManager);
            HandleAmbientSound();

            Master.Update(Game, gameTime);
            GoalManager.Update(this);
            Time.Update(gameTime);
            if (LastWorldPopup != null)
            {
                List <uint> removals = new List <uint>();
                foreach (var popup in LastWorldPopup)
                {
                    popup.Value.Update(gameTime, Camera, GraphicsDevice.Viewport);
                    if (popup.Value.Widget == null || !Gui.RootItem.Children.Contains(popup.Value.Widget) ||
                        popup.Value.BodyToTrack == null || popup.Value.BodyToTrack.IsDead)
                    {
                        removals.Add(popup.Key);
                    }
                }

                foreach (var removal in removals)
                {
                    if (LastWorldPopup[removal].Widget != null && Gui.RootItem.Children.Contains(LastWorldPopup[removal].Widget))
                    {
                        Gui.DestroyWidget(LastWorldPopup[removal].Widget);
                    }
                    LastWorldPopup.Remove(removal);
                }
            }

            if (Paused)
            {
                ComponentManager.UpdatePaused(gameTime, ChunkManager, Camera);
                TutorialManager.Update(Gui);
            }
            // If not paused, we want to just update the rest of the game.
            else
            {
                ParticleManager.Update(gameTime, this);
                TutorialManager.Update(Gui);

                Diplomacy.Update(gameTime, Time.CurrentDate, this);
                Factions.Update(gameTime);
                ComponentManager.Update(gameTime, ChunkManager, Camera);
                Sky.TimeOfDay           = Time.GetSkyLightness();
                Sky.CosTime             = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f);
                DefaultShader.TimeOfDay = Sky.TimeOfDay;
                MonsterSpawner.Update(gameTime);
                bool allAsleep = Master.AreAllEmployeesAsleep();

#if !UPTIME_TEST
                if (SleepPrompt == null && allAsleep && !FastForwardToDay && Time.IsNight())
                {
                    SleepPrompt = new QueuedAnnouncement()
                    {
                        Text        = "All your employees are asleep. Click here to skip to day.",
                        ClickAction = (sender, args) =>
                        {
                            FastForwardToDay = true;
                            SleepPrompt      = null;
                        },
                        ShouldKeep = () =>
                        {
                            return(FastForwardToDay == false && Time.IsNight() && Master.AreAllEmployeesAsleep());
                        }
                    };
                    MakeAnnouncement(SleepPrompt);
                }
                else if (!allAsleep)
                {
                    Time.Speed       = 100;
                    FastForwardToDay = false;
                    SleepPrompt      = null;
                }
#endif
            }

            // These things are updated even when the game is paused

            Splasher.Splash(gameTime, ChunkManager.Water.GetSplashQueue());

            ChunkManager.Update(gameTime, Camera, GraphicsDevice);
            ChunkRenderer.Update(gameTime, Camera, GraphicsDevice);
            SoundManager.Update(gameTime, Camera, Time);
            Weather.Update(this.Time.CurrentDate, this);

            if (gameFile != null)
            {
                // Cleanup game file.
                gameFile = null;
            }

#if DEBUG
            KeyboardState k = Keyboard.GetState();
            if (k.IsKeyDown(Keys.Home))
            {
                try
                {
                    GameState.Game.GraphicsDevice.Reset();
                }
                catch (Exception exception)
                {
                }
            }
#endif
        }