Contains common information used in the update loop
        private void OnMouseEvent(UIMouseEventType type, UpdateState state)
        {
            switch (type)
            {
                case UIMouseEventType.MouseOver:
                    //m_isOver = true;
                    break;

                case UIMouseEventType.MouseOut:
                    //m_isOver = false;
                    break;

                case UIMouseEventType.MouseDown:
                    m_isDown = true;
                    break;

                case UIMouseEventType.MouseUp:
                    if (m_isDown)
                    {
                        if (OnButtonClick != null)
                        {
                            OnButtonClick(this);
                            //GameFacade.SoundManager.PlayUISound(1);
                        }
                    }
                    m_isDown = false;
                    break;
            }
        }
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

            base.Update(state);

            if (CityRenderer != null)
            {
                if (ZoomLevel > 3 && CityRenderer.m_Zoomed != (ZoomLevel == 4))
                {
                    ZoomLevel = (CityRenderer.m_Zoomed) ? 4 : 5;
                }

                if (InLot) //if we're in a lot, use the VM's more accurate time!
                {
                    CityRenderer.SetTimeOfDay((vm.Context.Clock.Hours / 24.0) + (vm.Context.Clock.Minutes / 1440.0) + (vm.Context.Clock.Seconds / 86400.0));
                }
            }

            lock (StateChanges)
            {
                while (StateChanges.Count > 0)
                {
                    var e = StateChanges.Dequeue();
                    ClientStateChangeProcess(e.State, e.Progress);
                }
            }

            if (vm != null)
            {
                vm.Update();
            }
        }
        public UIExternalContainer(int width, int height)
        {
            _Width = width;
            _Height = height;
            inputManager = new InputManager();
            State = new UpdateState();
            mouse = new MouseState();

            WidthHeightChange(width, height);
        }
Exemple #4
0
 public void Update(Model.UpdateState state)
 {
     foreach (var scene in Scenes)
     {
         scene.Update(state);
     }
     foreach (var scene in External)
     {
         scene.Update(state);
     }
 }
Exemple #5
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     var perm = ((VMTSOAvatarState)Avatar.TSOState).Permissions;
     if (perm != LastPermissions)
     {
         UpdateAvatarState(perm);
     }
     RMB = state.MouseState.RightButton == ButtonState.Pressed;
     if (RMB && Hovered) CenterPerson(this);
 }
Exemple #6
0
        public void MouseUp(UpdateState state)
        {
            HITVM.Get().PlaySoundEvent(UISounds.BuildDragToolUp);

            vm.SendCommand(new VMNetArchitectureCmd
            {
                Commands = new List<VMArchitectureCommand>(Commands)
            });

            Commands.Clear();
            Drawing = false;
        }
Exemple #7
0
        /// <summary>
        /// Handle mouse events for dragging
        /// </summary>
        /// <param name="evt"></param>
        private void DragMouseEvents(UIMouseEventType evt, UpdateState state)
        {
            switch (evt)
            {
                case UIMouseEventType.MouseDown:
                    /** Start drag **/
                    m_doDrag = true;
                    DragControl.AddUpdateHook(UpdateHook);

                    var position = DragControl.GetMousePosition(state.MouseState);
                    m_dragOffsetX = position.X;
                    m_dragOffsetY = position.Y;
                    break;

                case UIMouseEventType.MouseUp:
                    /** Stop drag **/
                    m_doDrag = false;
                    DragControl.RemoveUpdateHook(UpdateHook);
                    break;
            }
        }
        public override void Update(UpdateState state)
        {
            base.Update(state);
            lock (AnimationRequests)
            {
                while (TargetTile != null && AnimationRequests.Count > 0)
                {
                    var anim = AnimationRequests.Dequeue();

                    var animation = FSO.Content.Content.Get().AvatarAnimations.Get(anim + ".anim");
                    if (animation != null)
                    {
                        var astate = new VMAnimationState(animation, false);
                        astate.Loop = true;
                        ((VMAvatar)TargetTile).Animations.Clear();
                        ((VMAvatar)TargetTile).Animations.Add(astate);
                    }
                }
            }

            state.SharedData["ExternalDraw"] = true;
        }
Exemple #9
0
 private void OnMouse(UIMouseEventType type, UpdateState state)
 {
     if (type == UIMouseEventType.MouseOver)
     {
         if (isDown) { return; }
         color = Color.Red;
     }
     else if (type == UIMouseEventType.MouseOut)
     {
         if (isDown) { return; }
         color = Color.White;
     }
     else if (type == UIMouseEventType.MouseDown)
     {
         color = Color.Blue;
         isDown = true;
     }
     else if (type == UIMouseEventType.MouseUp)
     {
         isDown = false;
         color = Color.Green;
     }
 }
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

            base.Update(state);


            lock (StateChanges)
            {
                while (StateChanges.Count > 0)
                {
                    var e = StateChanges.Dequeue();
                    ClientStateChangeProcess(e.State, e.Progress);
                }
            }

            if (vm != null)
            {
                vm.Update();
            }

            if (!Visible)
            {
                CityRenderer.Visible = false;
            }

            if (ZoomLevel < 4)
            {
                CreateChar.Visible      = false;
                SaveHouseButton.Visible = true;
            }
            else if (ZoomLevel >= 4)
            {
                CreateChar.Visible      = true;
                SaveHouseButton.Visible = false;
            }
        }
        public override void Update(UpdateState state)
        {
            base.Update(state);
            if (TempVM == null && GUID != 0)
            {
                var world = new ExternalWorld(GameFacade.GraphicsDevice);
                world.Initialize(GameFacade.Scenes);
                var context = new VMContext(world);

                TempVM = new VM(context, new VMServerDriver(37565, null), new VMNullHeadlineProvider());
                TempVM.Init();

                var blueprint = new Blueprint(1, 1);
                world.InitBlueprint(blueprint);
                context.Blueprint = blueprint;
                context.Architecture = new VMArchitecture(1, 1, blueprint, TempVM.Context);
            }

            if (GUID != oldGUID)
            {
                SetGUIDLocal(GUID);
                state.SharedData["ExternalDraw"] = true;
            }
        }
Exemple #12
0
        public override void Update(UpdateState state)
        {
            base.Update(state);
            lock (this) {
                if (QueuedChange != null) {
                    CurrentText = QueuedChange;
                    QueuedChange = null;
                }
            }
            if (FSOEnvironment.SoftwareKeyboard && state.InputManager.GetFocus() == this) state.InputManager.SetFocus(null);
            if (IsFocused)
            {
                /**
                 * TODO: Selection management
                 */
                var now = state.Time.TotalGameTime.Ticks;
                if (now - m_cursorBlinkLastTime > 5000000)
                {
                    m_cursorBlinkLastTime = now;
                    m_cursorBlink = !m_cursorBlink;
                }

                var inputResult = state.InputManager.ApplyKeyboardInput(m_SBuilder, state, SelectionStart, SelectionEnd, true);
                if (inputResult != null)
                {
                    if (inputResult.ContentChanged)
                    {
                        m_cursorBlink = true;
                        m_cursorBlinkLastTime = now;

                        /** We need to recompute the drawing commands **/
                        m_DrawDirty = true;

                        if (SelectionStart != -1)
                        {
                            SelectionStart += inputResult.NumInsertions;
                            SelectionStart -= inputResult.NumDeletes;
                        }
                    }

                    /**
                     * Selection?
                     */
                    foreach (var key in inputResult.UnhandledKeys)
                    {
                        switch (key)
                        {
                            case Keys.Left:
                                if (inputResult.ShiftDown)
                                {
                                    /** SelectionEnd**/
                                    if (SelectionEnd == -1)
                                    {
                                        if (SelectionStart != -1)
                                        {
                                            SelectionEnd = SelectionStart;
                                        }
                                        else
                                        {
                                            SelectionEnd = m_SBuilder.Length;
                                        }
                                    }
                                    SelectionEnd--;
                                    SelectionEnd = Math.Max(SelectionEnd, 0);
                                    if (SelectionEnd > m_SBuilder.Length) { SelectionEnd = m_SBuilder.Length; }

                                    /** Selection size = 0, act as if there is no selection **/
                                    if (SelectionEnd == SelectionStart)
                                    {
                                        SelectionEnd = -1;
                                    }
                                }
                                else
                                {
                                    if (SelectionEnd != -1)
                                    {
                                        SelectionStart = SelectionEnd;
                                        SelectionEnd = -1;
                                    }
                                    if (SelectionStart == -1)
                                    {
                                        SelectionStart = m_SBuilder.Length - 1;
                                    }
                                    else
                                    {
                                        SelectionStart--;
                                    }
                                    if (SelectionStart < 0) { SelectionStart = 0; }
                                }
                                m_DrawDirty = true;
                                break;

                            case Keys.Right:
                                if (inputResult.ShiftDown)
                                {
                                    /** SelectionEnd**/
                                    if (SelectionEnd == -1)
                                    {
                                        if (SelectionStart != -1)
                                        {
                                            SelectionEnd = SelectionStart;
                                        }
                                        else
                                        {
                                            SelectionEnd = m_SBuilder.Length;
                                        }
                                    }
                                    SelectionEnd++;
                                    if (SelectionEnd > m_SBuilder.Length) { SelectionEnd = m_SBuilder.Length; }

                                    /** Selection size = 0, act as if there is no selection **/
                                    if (SelectionEnd == SelectionStart)
                                    {
                                        SelectionEnd = -1;
                                    }
                                }
                                else
                                {
                                    if (SelectionEnd != -1)
                                    {
                                        SelectionStart = SelectionEnd;
                                        SelectionEnd = -1;
                                    }

                                    if (SelectionStart != -1)
                                    {
                                        SelectionStart++;
                                        if (SelectionStart >= m_SBuilder.Length)
                                        {
                                            SelectionStart = -1;
                                        }
                                    }
                                }
                                m_DrawDirty = true;
                                break;
                        }
                    }
                    if (inputResult.EnterPressed && OnEnterPress != null) OnEnterPress(this);
                    if (inputResult.TabPressed && OnTabPress != null) OnTabPress(this);
                }
            }
        }
Exemple #13
0
 public void MouseDown(UpdateState state)
 {
     if (!Drawing)
     {
         HITVM.Get().PlaySoundEvent(UISounds.BuildDragToolDown);
         Drawing = true;
         var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor);
         StartPosition = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y));
     }
 }
Exemple #14
0
        public void Update(UpdateState state, bool scrolled)
        {
            var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor);
            Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y));

            var cmds = vm.Context.Architecture.Commands;
            cmds.Clear();
            if (Drawing)
            {
                var diff = cursor - StartPosition;
                DrawLength = (int)Math.Round(Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y));
                DrawDir = (int)DirectionUtils.PosMod(Math.Round(Math.Atan2(diff.Y, diff.X) / (Math.PI / 4)), 8);

                if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
                {
                    EndPosition = cursor;
                    int smallX = Math.Min(StartPosition.X, EndPosition.X);
                    int smallY = Math.Min(StartPosition.Y, EndPosition.Y);
                    int bigX = Math.Max(StartPosition.X, EndPosition.X);
                    int bigY = Math.Max(StartPosition.Y, EndPosition.Y);
                    cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.WALL_RECT, level = World.State.Level, pattern = DrawPattern, style = DrawStyle,
                        x = smallX, y = smallY,
                        x2 = bigX-smallX, y2 = bigY-smallY
                    });
                }
                else
                {
                    cursor = StartPosition + new Point(DirUnits[DrawDir].X * DrawLength, DirUnits[DrawDir].Y * DrawLength);
                    cmds.Add(new VMArchitectureCommand { Type = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ?
                            VMArchitectureCommandType.WALL_DELETE : VMArchitectureCommandType.WALL_LINE,
                        level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = StartPosition.X, y = StartPosition.Y, x2 = DrawLength, y2 = DrawDir });
                }
            }

            if (cmds.Count > 0)
            {
                if (!WasDown || !cmds[0].Equals(LastCmd))
                {
                    vm.Context.Architecture.SignalRedraw();
                    WasDown = true;
                }

                var cost = vm.Context.Architecture.LastTestCost;
                if (cost != 0)
                {
                    var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value;
                    state.UIState.TooltipProperties.Show = true;
                    state.UIState.TooltipProperties.Color = disallowed?Color.DarkRed:Color.Black;
                    state.UIState.TooltipProperties.Opacity = 1;
                    state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y);
                    state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost);
                    state.UIState.TooltipProperties.UpdateDead = false;

                    if (!cmds[0].Equals(LastCmd) && disallowed)
                    {
                        HITVM.Get().PlaySoundEvent(UISounds.Error);
                    }
                }
                else
                {
                    state.UIState.TooltipProperties.Show = false;
                    state.UIState.TooltipProperties.Opacity = 0;
                }
                LastCmd = cmds[0];
            }
            else
            {
                if (WasDown)
                {
                    vm.Context.Architecture.SignalRedraw();
                    WasDown = false;
                }
            }

            WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level-1)*2.95f), Direction.NORTH, vm.Context);

            if (state.KeyboardState.IsKeyDown(Keys.LeftShift)) SetCursorGraphic(3);
            else if (state.KeyboardState.IsKeyDown(Keys.LeftControl)) SetCursorGraphic(1);
            else SetCursorGraphic(0);
        }
Exemple #15
0
        public void MouseUp(UpdateState state)
        {
            if (Drawing)
            {
                var cmds = new List<VMArchitectureCommand>();

                if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
                {
                    if (StartPosition != EndPosition)
                    {
                        int smallX = Math.Min(StartPosition.X, EndPosition.X);
                        int smallY = Math.Min(StartPosition.Y, EndPosition.Y);
                        int bigX = Math.Max(StartPosition.X, EndPosition.X);
                        int bigY = Math.Max(StartPosition.Y, EndPosition.Y);

                        cmds.Add(new VMArchitectureCommand
                        {
                            Type = VMArchitectureCommandType.WALL_RECT,
                            level = World.State.Level,
                            pattern = Pattern,
                            style = Style,
                            x = smallX,
                            y = smallY,
                            x2 = bigX - smallX,
                            y2 = bigY - smallY
                        });
                    }
                }
                else
                {
                    if (DrawLength > 0) cmds.Add(new VMArchitectureCommand {
                        Type = (state.KeyboardState.IsKeyDown(Keys.LeftControl))?
                            VMArchitectureCommandType.WALL_DELETE:VMArchitectureCommandType.WALL_LINE,
                        level = World.State.Level, pattern = Pattern, style = Style, x = StartPosition.X, y = StartPosition.Y, x2 = DrawLength, y2 = DrawDir });
                }
                if (cmds.Count > 0 && (Parent.ActiveEntity == null || vm.Context.Architecture.LastTestCost <= Parent.ActiveEntity.TSOState.Budget.Value))
                {
                    vm.SendCommand(new VMNetArchitectureCmd
                    {
                        Commands = new List<VMArchitectureCommand>(cmds)
                    });

                    //vm.Context.Architecture.RunCommands(cmds);
                    HITVM.Get().PlaySoundEvent(UISounds.BuildDragToolPlace);
                } else HITVM.Get().PlaySoundEvent(UISounds.BuildDragToolUp);
            }
            Drawing = false;
        }
Exemple #16
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     if (AutoRotate)
     {
         var startAngle = RotationStartAngle;
         var time = state.Time.TotalGameTime.Ticks;
         var phase = (time % RotationSpeed) / RotationSpeed;
         var multiplier = Math.Sin((Math.PI * 2) * phase);
         var newAngle = startAngle + (RotationRange * multiplier);
         Avatar.RotationY = (float)MathUtils.DegreeToRadian(newAngle);
     }
 }
Exemple #17
0
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

            base.Update(state);

            if (CityRenderer != null)
            {
                if (ZoomLevel > 3 && (CityRenderer.m_Zoomed == TerrainZoomMode.Near) != (ZoomLevel == 4))
                {
                    ZoomLevel = (CityRenderer.m_Zoomed == TerrainZoomMode.Near) ? 4 : 5;
                }

                if (World != null)
                {
                    if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                    {
                        if (World.FrameCounter < 3)
                        {
                            //wait until the draw stage has stabalized a bit. tends to be like this
                            // 1. heavy singular draw
                            // 2. update * 30
                            // 3. normal draws
                            CityRenderer.m_LotZoomProgress = 0;
                            World.Visible = true;
                            World.Opacity = 0;
                        }
                        else if (World.FrameCounter == 5 && GlobalSettings.Default.CompatState < GlobalSettings.TARGET_COMPAT_STATE)
                        {
                            GlobalSettings.Default.CompatState = GlobalSettings.TARGET_COMPAT_STATE;
                            GlobalSettings.Default.Save();
                        }
                        else
                        {
                            CityRenderer.InheritPosition(World, FindController <CoreGameScreenController>());
                        }
                    }
                    if (CityRenderer.m_LotZoomProgress > 0f && CityRenderer.m_LotZoomProgress < 1f)
                    {
                        if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                        {
                            if (CityRenderer.m_LotZoomProgress > 0.9995f)
                            {
                                CityRenderer.m_LotZoomProgress = 1f;
                                CityRenderer.Visible           = false;
                            }
                        }
                        else
                        {
                            if (CityRenderer.m_LotZoomProgress < 0.001f)
                            {
                                CityRenderer.m_LotZoomProgress = 0f;
                                World.Visible = false;
                            }
                        }
                        World.Opacity = Math.Max(0, (CityRenderer.m_LotZoomProgress - 0.5f) * 2);

                        var scale =
                            1 / ((CityRenderer.m_LotZoomProgress * (1 / CityRenderer.m_LotZoomSize) + (1 - CityRenderer.m_LotZoomProgress) * (1 / (Terrain.NEAR_ZOOM_SIZE * CityRenderer.m_WheelZoom))))
                            / CityRenderer.m_LotZoomSize;

                        World.State.PreciseZoom = scale;
                    }
                }

                if (InLot) //if we're in a lot, use the VM's more accurate time!
                {
                    CityRenderer.SetTimeOfDay((vm.Context.Clock.Hours / 24.0) + (vm.Context.Clock.Minutes / 1440.0) + (vm.Context.Clock.Seconds / 86400.0));
                }
                else
                {
                    var time    = DateTime.UtcNow;
                    var tsoTime = TSOTime.FromUTC(time);
                    CityRenderer.SetTimeOfDay((tsoTime.Item1 / 24.0) + (tsoTime.Item2 / 1440.0) + (tsoTime.Item3 / 86400.0));
                }
            }

            lock (StateChanges)
            {
                while (StateChanges.Count > 0)
                {
                    var e = StateChanges.Dequeue();
                    ClientStateChangeProcess(e.State, e.Progress);
                }
            }

            if (vm != null)
            {
                vm.Update();
            }
        }
Exemple #18
0
        public override void Update(UpdateState state)
        {
            base.Update(state);

            UpdateDesiredPosition();

            DisplayRect.Location = DesiredRectPos;

            DeterminePointSide();
        }
Exemple #19
0
 private void MouseEvt(UIMouseEventType type, UpdateState state)
 {
     if (type == UIMouseEventType.MouseDown && OnMouseEvent != null) OnMouseEvent(this); //pass to parents to handle
     if (type == UIMouseEventType.MouseOver) SetHover(true);
     if (type == UIMouseEventType.MouseOut) SetHover(false);
 }
Exemple #20
0
        /**
         * Interaction Functionality
         */
        public void OnMouseEvent(UIMouseEventType evt, UpdateState state)
        {
            switch (evt)
            {
                case UIMouseEventType.MouseUp:
                    state.InputManager.SetFocus(this);
                    break;

                case UIMouseEventType.MouseOver:
                    break;

                case UIMouseEventType.MouseOut:
                    break;
            }
        }
        public override void Update(UpdateState state)
        {
            base.Update(state);
            if (TempVM == null && GUID != 0)
            {
                var world = new ExternalWorld(GameFacade.GraphicsDevice);
                world.Initialize(GameFacade.Scenes);
                var context = new VMContext(world);

                TempVM = new VM(context, new VMServerDriver(37565, null), new VMNullHeadlineProvider());
                TempVM.Init();

                var blueprint = new Blueprint(32, 32);
                blueprint.Light = new RoomLighting[]
                {
                    new RoomLighting() { OutsideLight = 100 },
                    new RoomLighting() { OutsideLight = 100 },
                    new RoomLighting() { OutsideLight = 100 },
                };
                blueprint.OutsideColor = Color.White;
                blueprint.GenerateRoomLights();
                blueprint.RoomColors[2].A /= 2;
                world.State._2D.AmbientLight.SetData(blueprint.RoomColors);

                world.InitBlueprint(blueprint);
                context.Blueprint = blueprint;
                context.Architecture = new VMArchitecture(1, 1, blueprint, TempVM.Context);
            }

            if (GUID != oldGUID)
            {
                SetGUIDLocal(GUID, TempVM);
                state.SharedData["ExternalDraw"] = true;
            }

            if (ForceRedraw)
            {
                state.SharedData["ExternalDraw"] = true;
                ForceRedraw = false;
            }

            if (TempVM != null) TempVM.Update();
        }
Exemple #22
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     if (UpdateCooldown-- < 0)
     {
         populateWithXMLHouses();
         UpdateCooldown = 100;
     }
 }
Exemple #23
0
 private void OnMouse(UIMouseEventType type, UpdateState state)
 {
     if (OnMouseEvt != null) OnMouseEvt(type, state);
 }
Exemple #24
0
        public override void Update(UpdateState state)
        {
            lock (Commands)
            {
                if (Commands.Count > 0) RedoStack.Clear();
                foreach(var cmd in Commands)
                {
                    state.SharedData["ExternalDraw"] = true;
                    cmd.Execute(BHAVView.EditTarget, this);
                    UndoStack.Push(cmd);
                }
                Commands.Clear();
            }

            lock (ValueChangeCmds)
            {
                foreach (var cmd in ValueChangeCmds)
                {
                    cmd.Execute();
                }
                Commands.Clear();
            }

            while (UndoRedoDir > 0)
            {
                if (UndoStack.Count > 0)
                {
                    var cmd = UndoStack.Pop();
                    state.SharedData["ExternalDraw"] = true;
                    cmd.Undo(BHAVView.EditTarget, this);
                    RedoStack.Push(cmd);
                }
                UndoRedoDir--;
            }

            while (UndoRedoDir < 0)
            {
                if (RedoStack.Count > 0)
                {
                    var cmd = RedoStack.Pop();
                    state.SharedData["ExternalDraw"] = true;
                    cmd.Execute(BHAVView.EditTarget, this);
                    UndoStack.Push(cmd);
                }
                UndoRedoDir++;
            }

            if (RedrawNext)
            {
                state.SharedData["ExternalDraw"] = true;
                RedrawNext = false;
            }

            if (Placement != null)
            {
                Placement.Position = GlobalPoint(new Vector2(state.MouseState.X, state.MouseState.Y)) - (new Vector2(Placement.Width, Placement.Height) / 2);
                Placement.Style = PGroupStyles.ByType[PrimitiveGroup.Placement];
                state.SharedData["ExternalDraw"] = true;
                Placement.Update(state);

                PlacingName.Position = new Vector2(LastWidth / 2, LastHeight - 66);
                PlacingDesc.Position = new Vector2(LastWidth / 2, LastHeight - 48);

                var mx = state.MouseState.Position.X;
                var my = state.MouseState.Position.Y;

                if (MouseWasDown && (state.MouseState.LeftButton == ButtonState.Released)
                    && mx > 0 && mx < LastWidth && my > 0 && my < LastHeight)
                {
                    QueueCommand(new AddPrimCommand(Placement));
                    Placement.Position -= BHAVView.Position;
                    ClearPlacement();
                }
            }
            CutoutPhase++;
            MouseWasDown = state.MouseState.LeftButton == ButtonState.Pressed;
            base.Update(state);

            if (BHAVView.HoverPrim != null && (!RightMouseWasDown) &&
                state.MouseState.RightButton == ButtonState.Pressed
                && BHAVView.HoverPrim.Type == PrimBoxType.Primitive)
            {
                QueueCommand(new ToggleBreakpointCommand(BHAVView.HoverPrim));
            }

            RightMouseWasDown = state.MouseState.RightButton == ButtonState.Pressed;
        }
Exemple #25
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     UpdatePeople();
 }
Exemple #26
0
        public void ButtonAnim(UpdateState state)
        {
            icon.button.Selected = false;
            if (Alert && Ticks < 30) icon.button.Selected = true;

            if (++Ticks > 59)
            {
                Ticks = 0;
            }
        }
Exemple #27
0
        public void MouseUp(UpdateState state)
        {
            MouseIsDown = false;
            if (Holding != null && Holding.Clicked)
            {
                if (Holding.CanPlace == VMPlacementError.Success)
                {
                    HITVM.Get().PlaySoundEvent((Holding.IsBought) ? UISounds.ObjectMovePlace : UISounds.ObjectPlace);
                    //ExecuteEntryPoint(11); //User Placement
                    var putDown = Holding;
                    if (Holding.IsBought)
                    {
                        var pos = Holding.Group.BaseObject.Position;
                        vm.SendCommand(new VMNetMoveObjectCmd
                        {
                            ObjectID = Holding.MoveTarget,
                            dir = Holding.Dir,
                            level = pos.Level,
                            x = pos.x,
                            y = pos.y
                        });
                    } else
                    {
                        var pos = Holding.Group.BaseObject.Position;
                        var GUID = (Holding.Group.MultiTile)? Holding.Group.BaseObject.MasterDefinition.GUID : Holding.Group.BaseObject.Object.OBJ.GUID;
                        vm.SendCommand(new VMNetBuyObjectCmd
                        {
                            GUID = GUID,
                            dir = Holding.Dir,
                            level = pos.Level,
                            x = pos.x,
                            y = pos.y
                        });
                    }
                    ClearSelected();
                    if (OnPutDown != null) OnPutDown(putDown, state); //call this after so that buy mode etc can produce more.
                }
                else
                {

                }
            }

            state.UIState.TooltipProperties.Show = false;
            state.UIState.TooltipProperties.Opacity = 0;
            ShowTooltip = false;
        }
Exemple #28
0
        public override void Update(UpdateState state)
        {
            CoreGameScreen CurrentUIScr = (CoreGameScreen)GameFacade.Screens.CurrentUIScreen;

            if (Visible)
            { //if we're not visible, do not update CityRenderer state...
                m_LastMouseState = m_MouseState;
                m_MouseState = Mouse.GetState();

                m_MouseMove = (m_MouseState.RightButton == ButtonState.Pressed);

                if (m_HandleMouse)
                {
                    if (m_Zoomed)
                    {
                        m_SelTile = GetHoverSquare();

                        if (m_CanSend)
                        {
                            Network.UIPacketSenders.SendLotCostRequest(Network.NetworkFacade.Client, (short)m_SelTile[0], (short)m_SelTile[1]);
                            m_CanSend = false;
                        }
                    }

                    if (m_MouseState.RightButton == ButtonState.Pressed && m_LastMouseState.RightButton == ButtonState.Released)
                    {
                        m_MouseStart = new Vector2(m_MouseState.X, m_MouseState.Y); //if middle mouse button activated, record where we started pressing it (to use for panning)
                    }

                    else if (m_MouseState.LeftButton == ButtonState.Released && m_LastMouseState.LeftButton == ButtonState.Pressed) //if clicked...
                    {
                        if (!m_Zoomed)
                        {
                            m_Zoomed = true;
                            double ResScale = 768.0 / m_ScrHeight;
                            double isoScale = (Math.Sqrt(0.5 * 0.5 * 2) / 5.10) * ResScale;
                            double hb = m_ScrWidth * isoScale;
                            double vb = m_ScrHeight * isoScale;

                            m_TargVOffX = (float)(-hb + m_MouseState.X * isoScale * 2);
                            m_TargVOffY = (float)(vb - m_MouseState.Y * isoScale * 2); //zoom into approximate location of mouse cursor if not zoomed already
                        }
                        else
                        {
                            /*
                            if (m_SelTile[0] != -1 && m_SelTile[1] != -1)
                            {
                                m_SelTileTmp[0] = m_SelTile[0];
                                m_SelTileTmp[1] = m_SelTile[1];

                                UIAlertOptions AlertOptions = new UIAlertOptions();
                                AlertOptions.Title = GameFacade.Strings.GetString("246", "1");
                                AlertOptions.Message = GameFacade.Strings.GetString("215", "23", new string[]
                                { m_LotCost.ToString(), CurrentUIScr.ucp.MoneyText.Caption });
                                AlertOptions.Buttons = new UIAlertButton[] {
                                    new UIAlertButton(UIAlertButtonType.Yes, new ButtonClickDelegate(BuyPropertyAlert_OnButtonClick)),
                                    new UIAlertButton(UIAlertButtonType.No) };

                                m_BuyPropertyAlert = UIScreen.ShowAlert(AlertOptions, true);
                            }
                            */
                        }

                        CurrentUIScr.ucp.UpdateZoomButton();
                    }
                }
                else
                {
                    m_SelTile = new int[] { -1, -1 };
                }

                //m_SecondsBehind += time.ElapsedGameTime.TotalSeconds;
                //m_SecondsBehind -= 1 / 60;
                FixedTimeUpdate();
                //SetTimeOfDay(m_DayNightCycle % 1); //calculates sun/moon light colour and position
                //m_DayNightCycle += 0.001; //adjust the cycle speed here. When ingame, set m_DayNightCycle to to the percentage of time passed through the day. (0 to 1)

                m_ViewOffX = (m_TargVOffX) * m_ZoomProgress;
                m_ViewOffY = (m_TargVOffY) * m_ZoomProgress;
            }
        }
Exemple #29
0
        public override void Update(UpdateState state)
        {
            if (!VM.UseWorld) return;
            if (state.NewKeys.Contains(Keys.Enter))
            {
                if (!TextBox.Visible) TextBox.Clear();
                TextBox.Visible = !TextBox.Visible;
            }

            var avatars = vm.Entities.Where(x => (x is VMAvatar)).ToList();
            while (avatars.Count < Labels.Count)
            {
                Remove(Labels[Labels.Count - 1]);
                Labels.RemoveAt(Labels.Count - 1);
            }
            while (avatars.Count > Labels.Count)
            {
                var label = new UILabel();
                label.CaptionStyle = Style.Clone();
                label.CaptionStyle.Color = Colours[Labels.Count % Colours.Length];
                label.Alignment = TextAlignment.Center | TextAlignment.Middle;
                Add(label);
                Labels.Add(label);
            }

            for (int i=0; i<Labels.Count; i++)
            {
                var label = Labels[i];
                var avatar = avatars[i];
                label.Caption = ((VMAvatar)avatar).Message;
                label.Position = ((AvatarComponent)avatar.WorldUI).LastScreenPos + new Vector2(0, -175) / (1<<(3-(int)vm.Context.World.State.Zoom));

                TextAlignment alignment = 0;

                if (label.Position.X < Margin)
                {
                    alignment |= TextAlignment.Left;
                    label.Position = new Vector2(Margin, label.Position.Y);
                }
                else if (label.Position.X > GlobalSettings.Default.GraphicsWidth-Margin)
                {
                    alignment |= TextAlignment.Right;
                    label.Position = new Vector2(GlobalSettings.Default.GraphicsWidth-Margin, label.Position.Y);
                } else
                {
                    alignment |= TextAlignment.Center;
                }

                if (label.Position.Y < Margin)
                {
                    alignment |= TextAlignment.Top;
                    label.Position = new Vector2(label.Position.X, Margin);
                }
                else if (label.Position.Y > GlobalSettings.Default.GraphicsHeight - Margin)
                {
                    alignment |= TextAlignment.Bottom;
                    label.Position = new Vector2(label.Position.X, GlobalSettings.Default.GraphicsHeight - Margin);
                } else
                {
                    alignment |= TextAlignment.Middle;
                }
                label.Alignment = alignment;
                label.Size = new Vector2(1, 1);
            }
            base.Update(state);
        }
Exemple #30
0
 public override void Update(UpdateState state)
 {
     for (int i = 0; i < m_Elements.Count; i++)
     {
         m_Elements[i].Update(state);
     }
 }
Exemple #31
0
        public override void Update(FSO.Common.Rendering.Framework.Model.UpdateState state)
        {
            GameFacade.Game.IsFixedTimeStep = (vm == null || vm.Ready);

            Visible = World?.Visible == false || (World?.State as FSO.LotView.RC.WorldStateRC)?.CameraMode != true;
            GameFacade.Game.IsMouseVisible = Visible;

            base.Update(state);

            if (state.NewKeys.Contains(Microsoft.Xna.Framework.Input.Keys.F1) && state.CtrlDown)
            {
                FSOFacade.Controller.ToggleDebugMenu();
            }

            if (CityRenderer != null)
            {
                if (ZoomLevel > 3 && (CityRenderer.m_Zoomed == TerrainZoomMode.Near) != (ZoomLevel == 4))
                {
                    ZoomLevel = (CityRenderer.m_Zoomed == TerrainZoomMode.Near) ? 4 : 5;
                }

                if (World != null)
                {
                    if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                    {
                        if (World.FrameCounter < 3)
                        {
                            //wait until the draw stage has stabalized a bit. tends to be like this
                            // 1. heavy singular draw
                            // 2. update * 30
                            // 3. normal draws
                            CityRenderer.m_LotZoomProgress = 0;
                            World.Visible = true;
                            World.Opacity = 0;
                        }
                        else if (World.FrameCounter == 5 && GlobalSettings.Default.CompatState < GlobalSettings.TARGET_COMPAT_STATE)
                        {
                            GlobalSettings.Default.CompatState = GlobalSettings.TARGET_COMPAT_STATE;
                            GlobalSettings.Default.Save();
                        }
                        else
                        {
                            CityRenderer.InheritPosition(World, FindController <CoreGameScreenController>());
                        }
                    }
                    if (CityRenderer.m_LotZoomProgress > 0f && CityRenderer.m_LotZoomProgress < 1f)
                    {
                        if (CityRenderer.m_Zoomed == TerrainZoomMode.Lot)
                        {
                            if (CityRenderer.m_LotZoomProgress > 0.9999f)
                            {
                                CityRenderer.m_LotZoomProgress = 1f;
                                CityRenderer.Visible           = false;
                            }
                        }
                        else
                        {
                            if (CityRenderer.m_LotZoomProgress < 0.0001f)
                            {
                                CityRenderer.m_LotZoomProgress = 0f;
                                World.Visible = false;
                            }
                        }
                        World.Opacity = Math.Max(0, (CityRenderer.m_LotZoomProgress - 0.5f) * 2);

                        var scale =
                            1 / ((CityRenderer.m_LotZoomProgress * (1 / CityRenderer.m_LotZoomSize) + (1 - CityRenderer.m_LotZoomProgress) * (1 / (Terrain.NEAR_ZOOM_SIZE * CityRenderer.m_WheelZoom))))
                            / CityRenderer.m_LotZoomSize;

                        World.State.PreciseZoom = scale;
                    }
                }

                if (InLot) //if we're in a lot, use the VM's more accurate time!
                {
                    CityRenderer.SetTimeOfDay((vm.Context.Clock.Hours / 24.0) + (vm.Context.Clock.Minutes / 1440.0) + (vm.Context.Clock.Seconds / 86400.0));
                }
                else
                {
                    var time    = DateTime.UtcNow;
                    var tsoTime = TSOTime.FromUTC(time);
                    CityRenderer.SetTimeOfDay((tsoTime.Item1 / 24.0) + (tsoTime.Item2 / 1440.0) + (tsoTime.Item3 / 86400.0));
                }
            }

            lock (StateChanges)
            {
                while (StateChanges.Count > 0)
                {
                    var e = StateChanges.Dequeue();
                    ClientStateChangeProcess(e.State, e.Progress);
                }
            }

            if (vm != null)
            {
                vm.Update();
            }

            var joinAttempt = DiscordRpcEngine.Secret;

            if (joinAttempt != null)
            {
                var  split = joinAttempt.Split('#');
                uint lotID;
                if (uint.TryParse(split[0], out lotID))
                {
                    FindController <CoreGameScreenController>()?.JoinLot(lotID);
                }

                DiscordRpcEngine.Secret = null;
            }
        }
Exemple #32
0
 public void MouseDown(UpdateState state)
 {
     MouseIsDown = true;
     MouseDownX = state.MouseState.X;
     MouseDownY = state.MouseState.Y;
     if (Holding != null)
     {
         Rotation = Holding.Dir;
         DirChanged = false;
     }
 }
Exemple #33
0
        public void Update(UpdateState state, bool scrolled)
        {
            var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y));
            Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y));

            var cmds = vm.Context.Architecture.Commands;
            cmds.Clear();
            if (Drawing)
            {
                var diff = cursor - StartPosition;
                DrawLength = (int)Math.Round(Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y));
                DrawDir = (int)DirectionUtils.PosMod(Math.Round(Math.Atan2(diff.Y, diff.X) / (Math.PI / 4)), 8);

                if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
                {
                    EndPosition = cursor;
                    int smallX = Math.Min(StartPosition.X, EndPosition.X);
                    int smallY = Math.Min(StartPosition.Y, EndPosition.Y);
                    int bigX = Math.Max(StartPosition.X, EndPosition.X);
                    int bigY = Math.Max(StartPosition.Y, EndPosition.Y);
                    cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.WALL_RECT, level = World.State.Level, pattern = DrawPattern, style = DrawStyle,
                        x = smallX, y = smallY,
                        x2 = bigX-smallX, y2 = bigY-smallY
                    });
                }
                else
                {
                    cursor = StartPosition + new Point(DirUnits[DrawDir].X * DrawLength, DirUnits[DrawDir].Y * DrawLength);
                    cmds.Add(new VMArchitectureCommand { Type = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ?
                            VMArchitectureCommandType.WALL_DELETE : VMArchitectureCommandType.WALL_LINE,
                        level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = StartPosition.X, y = StartPosition.Y, x2 = DrawLength, y2 = DrawDir });
                }
            }

            if (cmds.Count > 0)
            {
                if (!WasDown || !cmds[0].Equals(LastCmd))
                {
                    vm.Context.Architecture.SignalRedraw();
                    LastCmd = cmds[0];
                    WasDown = true;
                }
            }
            else
            {
                if (WasDown)
                {
                    vm.Context.Architecture.SignalRedraw();
                    WasDown = false;
                }
            }

            WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level-1)*2.95f), Direction.NORTH, vm.Context);

            if (state.KeyboardState.IsKeyDown(Keys.LeftShift)) SetCursorGraphic(3);
            else if (state.KeyboardState.IsKeyDown(Keys.LeftControl)) SetCursorGraphic(1);
            else SetCursorGraphic(0);
        }
Exemple #34
0
        public void Update(UpdateState state, bool scrolled)
        {
            if (ShowTooltip) state.UIState.TooltipProperties.UpdateDead = false;
            MouseClicked = (MouseIsDown && (!MouseWasDown));

            if (Holding != null)
            {
                if (state.KeyboardState.IsKeyDown(Keys.Delete))
                {
                    SellBack(null);
                } else if (state.KeyboardState.IsKeyDown(Keys.Escape))
                {
                    OnDelete(Holding, null);
                    ClearSelected();
                }
            }
            if (Holding != null)
            {
                if (MouseClicked) Holding.Clicked = true;
                if (MouseIsDown && Holding.Clicked)
                {
                    bool updatePos = MouseClicked;
                    int xDiff = state.MouseState.X - MouseDownX;
                    int yDiff = state.MouseState.Y - MouseDownY;
                    if (Math.Sqrt(xDiff * xDiff + yDiff * yDiff) > 64)
                    {
                        int dir;
                        if (xDiff > 0)
                        {
                            if (yDiff > 0) dir = 1;
                            else dir = 0;
                        }
                        else
                        {
                            if (yDiff > 0) dir = 2;
                            else dir = 3;
                        }
                        var newDir = (Direction)(1 << (((dir + 4 - (int)World.State.Rotation) % 4) * 2));
                        if (newDir != Holding.Dir || MouseClicked)
                        {
                            updatePos = true;
                            HITVM.Get().PlaySoundEvent(UISounds.ObjectRotate);
                            Holding.Dir = newDir;
                            DirChanged = true;
                        }
                    }
                    if (updatePos)
                    {
                        MoveSelected(Holding.TilePos, Holding.Level);
                        if (!Holding.IsBought && Holding.CanPlace == VMPlacementError.Success &&
                            ParentControl.ActiveEntity != null && ParentControl.ActiveEntity.TSOState.Budget.Value < Holding.Price)
                            Holding.CanPlace = VMPlacementError.InsufficientFunds;
                        if (Holding.CanPlace != VMPlacementError.Success)
                        {
                            state.UIState.TooltipProperties.Show = true;
                            state.UIState.TooltipProperties.Color = Color.Black;
                            state.UIState.TooltipProperties.Opacity = 1;
                            state.UIState.TooltipProperties.Position = new Vector2(MouseDownX,
                                MouseDownY);
                            state.UIState.Tooltip = GameFacade.Strings.GetString("137", "kPErr" + Holding.CanPlace.ToString()
                                + ((Holding.CanPlace == VMPlacementError.CannotPlaceComputerOnEndTable) ? "," : ""));
                            // comma added to curcumvent problem with language file. We should probably just index these with numbers?
                            state.UIState.TooltipProperties.UpdateDead = false;
                            ShowTooltip = true;
                            HITVM.Get().PlaySoundEvent(UISounds.Error);
                        }
                        else
                        {
                            state.UIState.TooltipProperties.Show = false;
                            state.UIState.TooltipProperties.Opacity = 0;
                            ShowTooltip = false;
                        }
                    }
                }
                else
                {
                    var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor) + Holding.TilePosOffset;
                    MoveSelected(tilePos, 1);
                }
            }
            else if (MouseClicked)
            {
                //not holding an object, but one can be selected
                var newHover = World.GetObjectIDAtScreenPos(state.MouseState.X / FSOEnvironment.DPIScaleFactor, state.MouseState.Y / FSOEnvironment.DPIScaleFactor, GameFacade.GraphicsDevice);
                if (MouseClicked && (newHover != 0) && (vm.GetObjectById(newHover) is VMGameObject))
                {
                    var objGroup = vm.GetObjectById(newHover).MultitileGroup;
                    var objBasePos = objGroup.BaseObject.Position;
                    if (objBasePos.Level == World.State.Level)
                    {

                        var ghostGroup = vm.Context.GhostCopyGroup(objGroup);
                        SetSelected(ghostGroup);

                        Holding.MoveTarget = newHover;
                        Holding.TilePosOffset = new Vector2(objBasePos.x / 16f, objBasePos.y / 16f) - World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y) / FSOEnvironment.DPIScaleFactor);
                        if (OnPickup != null) OnPickup(Holding, state);
                        //ExecuteEntryPoint(12); //User Pickup
                    }
                    else
                    {
                        state.UIState.TooltipProperties.Show = true;
                        state.UIState.TooltipProperties.Color = Color.Black;
                        state.UIState.TooltipProperties.Opacity = 1;
                        state.UIState.TooltipProperties.Position = new Vector2(MouseDownX,
                            MouseDownY);
                        state.UIState.Tooltip = GameFacade.Strings.GetString("137", "kPErr" + VMPlacementError.CantEffectFirstLevelFromSecondLevel.ToString());
                        state.UIState.TooltipProperties.UpdateDead = false;
                        ShowTooltip = true;
                        HITVM.Get().PlaySoundEvent(UISounds.Error);
                    }
                }
            }

            MouseWasDown = MouseIsDown;
        }
Exemple #35
0
        public override void Update(UpdateState state)
        {
            lock (Commands)
            {
                if (Commands.Count > 0) RedoStack.Clear();
                foreach(var cmd in Commands)
                {
                    state.SharedData["ExternalDraw"] = true;
                    cmd.Execute(BHAVView.EditTarget, this);
                    UndoStack.Push(cmd);
                }
                Commands.Clear();
            }

            while (UndoRedoDir > 0)
            {
                if (UndoStack.Count > 0)
                {
                    var cmd = UndoStack.Pop();
                    state.SharedData["ExternalDraw"] = true;
                    cmd.Undo(BHAVView.EditTarget, this);
                    RedoStack.Push(cmd);
                }
                UndoRedoDir--;
            }

            while (UndoRedoDir < 0)
            {
                if (RedoStack.Count > 0)
                {
                    var cmd = RedoStack.Pop();
                    state.SharedData["ExternalDraw"] = true;
                    cmd.Execute(BHAVView.EditTarget, this);
                    UndoStack.Push(cmd);
                }
                UndoRedoDir++;
            }

            if (RedrawNext) state.SharedData["ExternalDraw"] = true;

            if (Placement != null)
            {
                Placement.Position = GlobalPoint(new Vector2(state.MouseState.X, state.MouseState.Y)) - (new Vector2(Placement.Width, Placement.Height) / 2);
                Placement.Style = PGroupStyles.ByType[PrimitiveGroup.Placement];
                state.SharedData["ExternalDraw"] = true;
                Placement.Update(state);

                PlacingName.Position = new Vector2(LastWidth / 2, LastHeight - 66);
                PlacingDesc.Position = new Vector2(LastWidth / 2, LastHeight - 48);

                var mx = state.MouseState.Position.X;
                var my = state.MouseState.Position.Y;

                if (state.KeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) ClearPlacement();
                else if (MouseWasDown && (state.MouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                    && mx > 0 && mx < LastWidth && my > 0 && my < LastHeight)
                {
                    QueueCommand(new AddPrimCommand(Placement));
                    Placement.Position -= BHAVView.Position;
                    ClearPlacement();
                }
            }
            CutoutPhase++;
            MouseWasDown = state.MouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            base.Update(state);
        }