Example #1
0
        public override void Update(TSO.Common.rendering.framework.model.UpdateState state)
        {
            base.Update(state);
            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));
            }
            else
            {
                CityRenderer.SetTimeOfDay(0.5); //Afr0, please implement time of day sync with server! Right now speed is one minute per second, but final will be per 3 seconds.
            }
            if (vm != null)
            {
                vm.Update(state.Time);
            }
        }
Example #2
0
 public override void Update(UpdateState state)
 {
     for (int i = 0; i < m_Elements.Count; i++)
     {
         m_Elements[i].Update(state);
     }
 }
Example #3
0
        public void HandleMouseEvents(UpdateState state)
        {
            var mouseBtnDown = state.MouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            var mouseDif = mouseBtnDown != LastMouseDownState;
            LastMouseDownState = mouseBtnDown;

            if (mouseDif)
            {
                if (mouseBtnDown)
                {
                    if (LastMouseDown != null)
                    {
                        /** We already have mouse down on an object **/
                        return;
                    }
                    if (LastMouseOver != null)
                    {
                        LastMouseDown = LastMouseOver;
                        LastMouseDown.Callback(UIMouseEventType.MouseDown, state);
                    }
                }
                else
                {
                    if (LastMouseDown != null)
                    {
                        LastMouseDown.Callback(UIMouseEventType.MouseUp, state);
                        LastMouseDown = null;
                    }
                }
            }

            if (state.MouseEvents.Count > 0)
            {
                var topMost =
                    state.MouseEvents.OrderByDescending(x => x.Element.Depth).First();

                /** Same element **/
                if (LastMouseOver == topMost)
                {
                    return;
                }

                if (LastMouseOver != null)
                {
                    LastMouseOver.Callback(UIMouseEventType.MouseOut, state);
                }

                topMost.Callback(UIMouseEventType.MouseOver, state);
                LastMouseOver = topMost;
            }
            else
            {
                if (LastMouseOver != null)
                {
                    LastMouseOver.Callback(UIMouseEventType.MouseOut, state);
                    LastMouseOver = null;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Utility to apply the result of pressing keys against a buffer
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="keys"></param>
        public KeyboardInputResult ApplyKeyboardInput(StringBuilder m_SBuilder, UpdateState state, int cursorIndex, int cursorEndIndex, bool allowInput)
        {
            var PressedKeys = state.KeyboardState.GetPressedKeys();
            if (PressedKeys.Length == 0) { return null; }

            var didChange = false;
            var result = new KeyboardInputResult();

            var m_CurrentKeyState = state.KeyboardState;
            var m_OldKeyState = state.PreviousKeyboardState;

            result.ShiftDown = PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift);
            result.CapsDown = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock);
            result.NumLockDown = System.Windows.Forms.Control.IsKeyLocked(System.Windows.Forms.Keys.NumLock);
            result.CtrlDown = PressedKeys.Contains(Keys.LeftControl) || PressedKeys.Contains(Keys.RightControl);

            for (int j = 0; j < state.NewKeys.Count; j++)
            {
                var key = state.NewKeys[j];

                if (key == Keys.Back || key == Keys.Delete)
                {
                    if (m_SBuilder.Length > 0)
                    {
                        /**
                         * Delete previous character or delete selection
                         */
                        if (cursorEndIndex == -1 && result.CtrlDown)
                        {
                            /** Delete up until the previous whitespace char **/
                            int newEndIndex = cursorIndex;
                            if (newEndIndex == -1)
                            {
                                newEndIndex = m_SBuilder.Length - 1;
                            }
                            while (newEndIndex >= 0)
                            {
                                if (Char.IsWhiteSpace(m_SBuilder[newEndIndex]))
                                {
                                    /** Keep the whitespace char **/
                                    newEndIndex++;
                                    break;
                                }
                                newEndIndex--;
                            }
                            cursorEndIndex = newEndIndex;
                        }

                        if (cursorEndIndex == -1)
                        {
                            /** Previous character **/
                            var index = cursorIndex == -1 ? m_SBuilder.Length : cursorIndex;
                            if ((key == Keys.Back) && (index > 0))
                            {
                                var numToDelete = 1;
                                if (index > 1 && m_SBuilder[index-1] == '\n' && m_SBuilder[index - 2] == '\r')
                                {
                                    numToDelete = 2;
                                }

                                m_SBuilder.Remove(index - numToDelete, numToDelete);
                                result.NumDeletes += numToDelete;

                                if (cursorIndex != -1)
                                {
                                    cursorIndex -= numToDelete;
                                }
                            }
                            else if ((key == Keys.Delete) && (index < m_SBuilder.Length))
                            {
                                /** Guys, delete removes the next character, not the last!! **/
                                var numToDelete = 1;
                                if ((index < m_SBuilder.Length - 1) && m_SBuilder[index] == '\r' && m_SBuilder[index + 1] == '\n')
                                {
                                    numToDelete = 2;
                                }

                                m_SBuilder.Remove(index, numToDelete);
                                result.NumDeletes += numToDelete;
                            }
                        }
                        else
                        {
                            DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                        }
                        result.SelectionChanged = true;
                        didChange = true;
                    }
                }
                else if (key == Keys.Enter)
                {
                    if (allowInput)
                    {
                        /** Line break **/
                        if (cursorEndIndex != -1)
                        {
                            /** Delete selected text **/
                            DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                        }

                        if (cursorIndex == -1)
                        {
                            m_SBuilder.Append("\r\n");
                        }
                        else
                        {
                            m_SBuilder.Insert(cursorIndex, "\r\n");
                            cursorIndex += 2;
                        }
                        result.NumInsertions += 2;
                        didChange = true;
                        result.EnterPressed = true;
                    }
                }
                else if (key == Keys.Tab)
                {
                    result.TabPressed = true;
                }
                else
                {
                    if (result.CtrlDown)
                    {
                        switch (key)
                        {
                            case Keys.A:
                                /** Select all **/
                                cursorIndex = 0;
                                cursorEndIndex = m_SBuilder.Length;
                                result.SelectionChanged = true;
                                break;

                            case Keys.C:
                            case Keys.X:
                                /** Copy text to clipboard **/
                                if (cursorEndIndex != -1)
                                {
                                    var selectionStart = Math.Max(0, cursorIndex);
                                    var selectionEnd = cursorEndIndex;
                                    GetSelectionRange(ref selectionStart, ref selectionEnd);

                                    var str = m_SBuilder.ToString().Substring(selectionStart, selectionEnd - selectionStart);
                                    System.Windows.Forms.Clipboard.SetText((str == null) ? " " : str);

                                    if (key == Keys.X)
                                    {
                                        DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                                    }
                                }
                                break;

                            case Keys.V:
                                /** Paste text in **/
                                var clipboardText = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text);
                                if (clipboardText != null)
                                {
                                    /** TODO: Cleanup the clipboard text to make sure its valid **/

                                    /** If i have selection, delete it **/
                                    if (cursorEndIndex != -1)
                                    {
                                        DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                                    }

                                    /** Paste **/
                                    if (cursorIndex == -1)
                                    {
                                        m_SBuilder.Append(clipboardText);
                                    }
                                    else
                                    {
                                        m_SBuilder.Insert(Math.Min(cursorIndex, m_SBuilder.Length), clipboardText);
                                        cursorIndex += clipboardText.Length;
                                    }
                                    result.NumInsertions += clipboardText.Length;
                                    didChange = true;
                                }
                                break;
                        }
                        continue;
                    }

                    char value = TranslateChar(key, result.ShiftDown, result.CapsDown, result.NumLockDown);
                    /** For now we dont support tabs in text **/
                    if (value != '\0' && value != '\t')
                    {
                        if (allowInput)
                        {
                            if (cursorEndIndex != -1)
                            {
                                /** Delete selected text **/
                                DeleteSelectedText(m_SBuilder, ref cursorIndex, ref cursorEndIndex, ref didChange, result);
                            }

                            if (cursorIndex == -1)
                            {
                                m_SBuilder.Append(value);
                            }
                            else
                            {
                                m_SBuilder.Insert(cursorIndex, value);
                                cursorIndex++;
                            }
                            result.NumInsertions++;
                            didChange = true;
                        }
                    }
                    else
                    {
                        result.UnhandledKeys.Add(key);
                    }
                }

            }

            result.SelectionStart = cursorIndex;
            result.SelectionEnd = cursorEndIndex;

            result.ContentChanged = didChange;
            return result;
        }
 private void HolderPutDown(UIObjectSelection holding, UpdateState state)
 {
     if (OldSelection != -1)
     {
         if (!holding.IsBought && (state.KeyboardState.IsKeyDown(Keys.LeftShift) || state.KeyboardState.IsKeyDown(Keys.RightShift)))
         {
             //place another
             var prevDir = holding.Dir;
             Catalog_OnSelectionChange(OldSelection);
             Holder.Holding.Dir = prevDir;
         }
         else
         {
             Catalog.SetActive(OldSelection, false);
             OldSelection = -1;
         }
     }
     QueryPanel.Active = false;
 }
 private void HolderPickup(UIObjectSelection holding, UpdateState state)
 {
     QueryPanel.Mode = 0;
     QueryPanel.Active = true;
     QueryPanel.Tab = 1;
     QueryPanel.SetInfo(holding.Group.BaseObject, holding.IsBought);
 }
Example #7
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     if (UpdateCooldown-- < 0)
     {
         populateWithXMLHouses();
         UpdateCooldown = 100;
     }
 }
Example #8
0
 public abstract void Update(UpdateState state);
Example #9
0
        public bool TestScroll(UpdateState state)
        {
            var mouse = state.MouseState;

            if (State == null) { return false; }

            var screenWidth = State.WorldSpace.WorldPxWidth;
            var screenHeight = State.WorldSpace.WorldPxHeight;

            /** Corners **/
            var xBound = screenWidth - ScrollBounds;
            var yBound = screenHeight - ScrollBounds;

            var cursor = CursorType.Normal;
            var scrollVector = new Vector2(0, 0);
            if (mouse.X > 0 && mouse.Y > 0 && mouse.X < screenWidth && mouse.Y < screenHeight)
            {
                if (mouse.Y <= ScrollBounds)
                {
                    if (mouse.X <= ScrollBounds)
                    {
                        /** Scroll top left **/
                        cursor = CursorType.ArrowUpLeft;
                        scrollVector = new Vector2(-1, -1);
                    }
                    else if (mouse.X >= xBound)
                    {
                        /** Scroll top right **/
                        cursor = CursorType.ArrowUpRight;
                        scrollVector = new Vector2(1, -1);
                    }
                    else
                    {
                        /** Scroll up **/
                        cursor = CursorType.ArrowUp;
                        scrollVector = new Vector2(0, -1);
                    }
                }
                else if (mouse.Y <= yBound)
                {
                    if (mouse.X <= ScrollBounds)
                    {
                        /** Left **/
                        cursor = CursorType.ArrowLeft;
                        scrollVector = new Vector2(-1, 0);
                    }
                    else if (mouse.X >= xBound)
                    {
                        /** Right **/
                        cursor = CursorType.ArrowRight;
                        scrollVector = new Vector2(1, -1);
                    }
                }
                else
                {
                    if (mouse.X <= ScrollBounds)
                    {
                        /** Scroll bottom left **/
                        cursor = CursorType.ArrowDownLeft;
                        scrollVector = new Vector2(-1, 1);
                    }
                    else if (mouse.X >= xBound)
                    {
                        /** Scroll bottom right **/
                        cursor = CursorType.ArrowDownRight;
                        scrollVector = new Vector2(1, 1);
                    }
                    else
                    {
                        /** Scroll down **/
                        cursor = CursorType.ArrowDown;
                        scrollVector = new Vector2(0, 1);
                    }
                }
            }

            if (cursor != CursorType.Normal)
            {
                /**
                 * Calculate scroll vector based on rotation & scroll type
                 */
                scrollVector = new Vector2();

                var basis = GetScrollBasis();

                switch (cursor)
                {
                    case CursorType.ArrowDown:
                        scrollVector = basis[1];
                        break;

                    case CursorType.ArrowUp:
                        scrollVector = -basis[1];
                        break;

                    case CursorType.ArrowLeft:
                        scrollVector = -basis[0];
                        break;

                    case CursorType.ArrowRight:
                        scrollVector = basis[0];
                        break;
                }

                /** We need to scroll **/
                if (scrollVector != Vector2.Zero)
                {
                    State.CenterTile += scrollVector * new Vector2(0.0625f, 0.0625f);
                }
            }

            if (cursor != CursorType.Normal)
            {
                CursorManager.INSTANCE.SetCursor(cursor);
                return true; //we scrolled, return true and set cursor
            }
            return false;
        }
Example #10
0
 public override void Update(UpdateState state)
 {
     base.Update(state);
     /** Check for mouse scrolling **/
 }
Example #11
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);
     }
 }
 private void MouseEvt(UIMouseEventType type, UpdateState state)
 {
     if (type == UIMouseEventType.MouseDown && OnMouseEvent != null) OnMouseEvent(this); //pass to parents to handle
 }
        public override void Update(TSO.Common.rendering.framework.model.UpdateState state)
        {
            base.Update(state);
            if (ActiveEntity == null || ActiveEntity.Dead)
            {
                ActiveEntity     = vm.Entities.FirstOrDefault(x => x is VMAvatar); //try and hook onto a sim if we have none selected.
                Queue.QueueOwner = ActiveEntity;
            }

            if (Visible)
            {
                if (ShowTooltip)
                {
                    GameFacade.Screens.TooltipProperties.UpdateDead = false;
                }

                var scrolled = World.TestScroll(state);
                if (MouseIsOn && ActiveEntity != null)
                {
                    if (state.MouseState.X != OldMX || state.MouseState.Y != OldMY)
                    {
                        OldMX = state.MouseState.X;
                        OldMY = state.MouseState.Y;
                        var newHover = World.GetObjectIDAtScreenPos(state.MouseState.X, state.MouseState.Y, GameFacade.GraphicsDevice);
                        if (newHover == 0)
                        {
                            newHover = ActiveEntity.ObjectID;
                        }
                        if (ObjectHover != newHover)
                        {
                            ObjectHover = newHover;
                            if (ObjectHover != 0)
                            {
                                var menu = vm.GetObjectById(ObjectHover).GetPieMenu(vm, ActiveEntity);
                                InteractionsAvailable = (menu.Count > 0);
                            }
                        }
                    }
                }
                else
                {
                    ObjectHover = 0;
                }

                if (!scrolled)
                { //set cursor depending on interaction availability
                    CursorType cursor;
                    if (ObjectHover == 0)
                    {
                        cursor = CursorType.LiveNothing;
                    }
                    else
                    {
                        if (InteractionsAvailable)
                        {
                            if (vm.GetObjectById(ObjectHover) is VMAvatar)
                            {
                                cursor = CursorType.LivePerson;
                            }
                            else
                            {
                                cursor = CursorType.LiveObjectAvail;
                            }
                        }
                        else
                        {
                            cursor = CursorType.LiveObjectUnavail;
                        }
                    }

                    CursorManager.INSTANCE.SetCursor(cursor);
                }

                //set cutaway around mouse

                var       cuts = vm.Context.Blueprint.Cutaway;
                Rectangle newCut;
                if (WallsMode == 0)
                {
                    newCut = new Rectangle(-1, -1, 1024, 1024); //cut all; walls down.
                }
                else if (WallsMode == 1)
                {
                    var mouseTilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y + 128));
                    newCut = new Rectangle((int)(mouseTilePos.X - 1.5), (int)(mouseTilePos.Y - 1.5), 4, 4);
                }
                else
                {
                    newCut = new Rectangle(0, 0, 0, 0); //walls up or roof
                }


                if (!newCut.Equals(MouseCutRect))
                {
                    if (cuts.Contains(MouseCutRect))
                    {
                        cuts.Remove(MouseCutRect);
                    }
                    MouseCutRect = newCut;
                    cuts.Add(MouseCutRect);
                    vm.Context.Blueprint.Damage.Add(new tso.world.model.BlueprintDamage(tso.world.model.BlueprintDamageType.WALL_CUT_CHANGED));
                }
            }
        }
        public GameScreen(GraphicsDevice device)
        {
            this.Device = device;

            State = new UpdateState();
        }
 public override void Update(UpdateState state)
 {
     if (QueryPanel.Mode == 0 && QueryPanel.Active)
     {
         if (Opacity > 0) Opacity -= 1f / 20f;
         else
         {
             Opacity = 0;
             Visible = false;
         }
     }
     else
     {
         Visible = true;
         if (Opacity < 1) Opacity += 1f / 20f;
         else Opacity = 1;
     }
     base.Update(state);
 }
        private void TouchStub(UpdateState state)
        {
            var test = TouchPanel.EnableMouseTouchPoint;
            TouchCollection touches = TouchPanel.GetState();
            if (touches.Count > 0)
            {
                if (touchedFrames < TOUCH_ACCEPT_TIME)
                {
                    touchedFrames++;
                }
                else
                {
                    //right click, take center
                    Vector2 avg = new Vector2();
                    for (int i = 0; i < touches.Count; i++)
                    {
                        avg += touches[i].Position;
                    }
                    avg /= touches.Count;

                    state.MouseState = new MouseState(
                        (int)avg.X, (int)avg.Y, state.MouseState.ScrollWheelValue,
                        (touches.Count > 1) ? ButtonState.Released : ButtonState.Pressed,
                        (touches.Count > 1) ? ButtonState.Pressed : ButtonState.Released,
                        ButtonState.Released,
                        ButtonState.Released,
                        ButtonState.Released
                        );

                    state.TouchMode = true;
                }
            }
            else
            {
                touchedFrames = 0;
                state.TouchMode = false;
            }
        }
 private void HolderDelete(UIObjectSelection holding, UpdateState state)
 {
     if (OldSelection != -1)
     {
         Catalog.SetActive(OldSelection, false);
         OldSelection = -1;
     }
     QueryPanel.Active = false;
 }
Example #18
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.MiddleButton == 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.MiddleButton == ButtonState.Pressed && m_LastMouseState.MiddleButton == 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)
                            {
                                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 = UIAlertButtons.YesNo;

                                m_BuyPropertyAlert = UIScreen.ShowAlert(AlertOptions, true);
                                m_BuyPropertyAlert.ButtonMap[UIAlertButtons.Yes].OnButtonClick +=
                                    new ButtonClickDelegate(BuyPropertyAlert_OnButtonClick);
                            }
                        }

                        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;
            }
        }
Example #19
0
 public abstract void Update(UpdateState Time);