Exemplo n.º 1
0
    public bool ProcessEvent(Event e)
    {
        if (e.type == EventType.KeyDown)
        {
            switch (e.keyCode)
            {
            case KeyCode.Escape:
                Destroy(gameObject);
                break;

            case KeyCode.Tab:
                // advance child focus
                AdvanceWidgetFocus(WorkingArea.transform, !e.shift);
                break;

            case KeyCode.Return:
            case KeyCode.KeypadEnter:
                if (OnReturn != null)
                {
                    OnReturn();
                }
                break;
            }
        }
        else if (e.rawType == EventType.MouseMove)
        {
            MouseCursor.SetCursor(MouseCursor.CurDefault);
        }

        return(true);
    }
Exemplo n.º 2
0
    void Update()
    {
        // initiate resource load.
        if (!ClassLoadThreadDone)
        {
            GameConsole.ConsoleEnabled = false;
            MapView.gameObject.SetActive(false);
            MouseCursor.SetCursor(MouseCursor.CurWait);

            if (ClassLoadThread == null)
            {
                ClassLoadThread = new Thread(new ThreadStart(ClassLoadThreadProc));
                ClassLoadThread.Start();
            }
        }
        else if (ClassLoadThreadDone && ClassLoadThread != null)
        {
            GameConsole.ConsoleEnabled = true;
            MapView.gameObject.SetActive(true);
            ClassLoadThread = null;

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            Config.Load();
            CheckServerConfig();
        }

        lock (pDelegates)
        {
            for (int i = 0; i < pDelegates.Count; i++)
            {
                StartCoroutine(DelegateCoroutine(pDelegates[i]));
            }
            pDelegates.Clear();
        }
    }
Exemplo n.º 3
0
    public bool ProcessEvent(Event ev)
    {
        if (Pack == null)
        {
            return(false);
        }

        if (ev.rawType == EventType.MouseDown ||
            ev.rawType == EventType.MouseUp ||
            ev.rawType == EventType.MouseMove)
        {
            // check if its inside this widget
            Vector2 mPos = Utils.GetMousePosition();
            if (!new Rect(transform.position.x, transform.position.y, Width, Height).Contains(mPos))
            {
                return(false);
            }

            Vector2 mPosLocal = new Vector2(mPos.x - transform.position.x,
                                            mPos.y - transform.position.y);

            int itemHoveredX = (int)(mPosLocal.x / 80 / InvScale);
            int itemHoveredY = (int)(mPosLocal.y / 80 / InvScale);

            int start = Math.Max(Math.Min(Scroll, Pack.Count - InvWidth * InvHeight), 0);
            int end   = Math.Min(start + InvWidth * InvHeight, Pack.Count);

            int itemHovered = itemHoveredY * InvWidth + itemHoveredX + start;
            if (itemHovered < 0 || itemHovered >= Pack.Count)
            {
                return(true);
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            Item item = Pack[itemHovered];

            if (ev.rawType == EventType.MouseMove &&
                ev.commandName == "tooltip")
            {
                UiManager.Instance.SetTooltip(item.ToVisualString());
            }
            else if (ev.rawType == EventType.MouseDown &&
                     ev.commandName == "double")
            {
                if (AutoDropTarget != null)
                {
                    Item newItem = Pack.TakeItem(itemHovered, 1);
                    if (!AutoDropTarget.ProcessAutoDrop(newItem))
                    {
                        Pack.PutItem(itemHovered, newItem);
                    }
                }
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 4
0
 public virtual bool ProcessEvent(Event e)
 {
     if (e.rawType == EventType.MouseMove)
     {
         MouseCursor.SetCursor(MouseCursor.CurDefault);
     }
     return(true);
 }
Exemplo n.º 5
0
    public bool ProcessEvent(Event e)
    {
        if ((e.type == EventType.KeyDown &&
             e.keyCode == KeyCode.BackQuote && e.shift) ||
            (e.type == EventType.KeyDown &&
             (e.keyCode == KeyCode.BackQuote || e.keyCode == KeyCode.Escape) && ConsoleActive))
        {
            ConsoleActive = !ConsoleActive;
            if (ConsoleActive)
            {
                EditField.Value = "";
            }
            return(true);
        }

        if (!ConsoleActive)
        {
            return(false);
        }

        // handle input events here
        if (e.type == EventType.KeyDown)
        {
            switch (e.keyCode)
            {
            case KeyCode.UpArrow:
                if (CommandHistoryPosition > 0)
                {
                    if (CommandHistoryPosition == CommandHistory.Count - 1)
                    {
                        CommandHistory[CommandHistory.Count - 1] = EditField.Value;
                    }
                    CommandHistoryPosition--;
                    EditField.Value          = CommandHistory[CommandHistoryPosition];
                    EditField.CursorPosition = EditField.Value.Length;
                }
                break;

            case KeyCode.DownArrow:
                if (CommandHistoryPosition < CommandHistory.Count - 1)
                {
                    CommandHistoryPosition++;
                    EditField.Value          = CommandHistory[CommandHistoryPosition];
                    EditField.CursorPosition = EditField.Value.Length;
                }
                break;
            }
        }
        else if (e.rawType == EventType.MouseMove)
        {
            if (ConsoleActive)
            {
                MouseCursor.SetCursor(MouseCursor.CurDefault);
            }
        }

        return(true);
    }
Exemplo n.º 6
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            Vector2 mPos = Utils.GetMousePosition();
            if (!new Rect(transform.position.x, transform.position.y, CommandBarL.width + CommandBarR.width, CommandBarR.height).Contains(mPos))
            {
                return(false);
            }

            mPos.x -= transform.position.x + 8 + CommandBarL.width;
            mPos.y -= transform.position.y + 7;

            if (e.rawType == EventType.MouseDown &&
                e.button == 0)
            {
                int bX = (int)mPos.x / 34;
                int bY = (int)mPos.y / 34;
                if (bX >= 0 && bX < 4 &&
                    bY >= 0 && bY < 2)
                {
                    Commands icmd = (Commands)(1 << (bY * 4 + bX));
                    if ((EnabledCommands & icmd) != 0)
                    {
                        CurrentCommandActual = icmd;
                    }
                }
            }

            if (e.rawType == EventType.MouseMove &&
                e.commandName == "tooltip")
            {
                int bX = (int)mPos.x / 34;
                int bY = (int)mPos.y / 34;
                if (bX >= 0 && bX < 4 &&
                    bY >= 0 && bY < 2)
                {
                    Commands icmd = (Commands)(1 << (bY * 4 + bX));
                    if ((EnabledCommands & icmd) != 0)
                    {
                        UiManager.Instance.SetTooltip(Locale.Main[bY * 4 + bX]);
                    }
                }
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);

            return(true);
        }

        return(false);
    }
Exemplo n.º 7
0
 public bool ProcessEvent(Event e)
 {
     if (e.rawType == EventType.MouseDown ||
         e.rawType == EventType.MouseUp ||
         e.rawType == EventType.MouseMove)
     {
         Vector2 mPos = Utils.GetMousePosition();
         if (mPos.x > transform.position.x &&
             mPos.y > transform.position.y &&
             mPos.x < transform.position.x + 176 &&
             mPos.y < transform.position.y + 158)
         {
             MouseCursor.SetCursor(MouseCursor.CurDefault);
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 8
0
    public override bool ProcessEvent(Event e)
    {
        if (e.type == EventType.KeyDown)
        {
            switch (e.keyCode)
            {
            case KeyCode.Escape:
                Client.SendLeaveStructure();
                break;
            }
        }
        else if (e.rawType == EventType.MouseMove)
        {
            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(base.ProcessEvent(e));
    }
        protected override void OnMouseUp(MouseEventArgs arg)
        {
            if (m_bAction == false)
            {
                return;
            }
            ITool pTool;

            pTool = (ITool)m_gSelectTool;
            pTool.OnMouseUp(GetButtonCode(arg), Convert.ToInt32(arg.Shift), arg.X, arg.Y);


            SelectFromGraphics();

            // release object
            m_gSelectTool = null;
            m_bAction     = false;

            MouseCursor cursor;

            cursor = new MouseCursor();
            cursor.SetCursor(esriSystemMouseCursor.esriSystemMouseCursorDefault);
        }
Exemplo n.º 10
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            int lw = 480;
            int lh = 85;

            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y);
            if (mPosLocal.x < 0 || mPosLocal.y < 0 ||
                mPosLocal.x > lw || mPosLocal.y > lh)
            {
                return(false);
            }

            Vector2 spLocal = new Vector2((mPosLocal.x - 5) / 38, (mPosLocal.y - 5) / 38);
            int     spd     = (int)spLocal.y * 12 + (int)spLocal.x;
            if (spd > 24 || spd < 0)
            {
                spd = -1;
            }
            Spell.Spells sp = RemapToSpell(spd);

            if (e.rawType == EventType.MouseDown)
            {
                ActiveSpell = sp;
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(false);
    }
Exemplo n.º 11
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = new Vector2(mPos.x - transform.position.x, mPos.y - transform.position.y);
            // global check if mouse is inside any of child components
            if (!new Rect(0, 0, HBackR.width + HBackL.width, HBackR.height).Contains(mPosLocal) &&
                !new Rect(0, TBackRObject.transform.localPosition.y, TBackR.width + TBackL.width, TBackR.height).Contains(mPosLocal) &&
                (ExtraRObject == null ||
                 !new Rect(0, ExtraRObject.transform.localPosition.y, ExtraR.width + ExtraL.width, ExtraR.height).Contains(mPosLocal)) &&
                (BlackQuad == null ||
                 !new Rect(BlackQuad.transform.localPosition.x,
                           BlackQuad.transform.localPosition.y,
                           TBackR.width, MainCamera.Height - transform.localPosition.y).Contains(mPosLocal)))
            {
                return(false);
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            //
            if (e.rawType == EventType.MouseDown)
            {
                if (BHumanModeObject != null)
                {
                    if (new Rect(BHumanModeObject.transform.localPosition.x,
                                 BHumanModeObject.transform.localPosition.y,
                                 BHumanMode.width, BHumanMode.height).Contains(mPosLocal))
                    {
                        // switch to textmode
                        IsHumanMode = !IsHumanMode;
                    }
                }

                if (BPackOpenObject != null)
                {
                    if (new Rect(BPackOpenObject.transform.localPosition.x,
                                 BPackOpenObject.transform.localPosition.y,
                                 BPackOpen.width, BPackOpen.height).Contains(mPosLocal))
                    {
                        // switch to open inventory.
                        MapView.Instance.InventoryVisible = !MapView.Instance.InventoryVisible;
                    }
                }

                if (BBookOpenObject != null)
                {
                    if (new Rect(BBookOpenObject.transform.localPosition.x,
                                 BBookOpenObject.transform.localPosition.y,
                                 BBookOpen.width, BBookOpen.height).Contains(mPosLocal))
                    {
                        // switch to open spellbook
                        MapView.Instance.SpellbookVisible = !MapView.Instance.SpellbookVisible;
                    }
                }
            }

            // check if event was inside view pic
            if (new Rect(HBackL.width, 0, HBackR.width, HBackR.height).Contains(mPosLocal)) // right side of humanback
            {
                if (_Viewer != null)
                {
                    _Viewer.ProcessEventPic(e, mPosLocal.x - HBackL.width, mPosLocal.y);
                }
            }
            else if (new Rect(TBackL.width, TBackRObject.transform.localPosition.y, TBackR.width, TBackR.height).Contains(mPosLocal))
            {
                if (_Viewer != null)
                {
                    _Viewer.ProcessEventInfo(e, mPosLocal.x - TBackL.width, mPosLocal.y - TBackRObject.transform.localPosition.y);
                }
            }

            return(true);
        }
        else if (e.type == EventType.KeyDown)
        {
            if (e.keyCode == KeyCode.Tab && BHumanModeObject != null)
            {
                IsHumanMode = !IsHumanMode;
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 12
0
    void Update()
    {
        lastMouseDown += Time.unscaledDeltaTime;
        if (lastMouseChange >= 0)
        {
            lastMouseChange += Time.unscaledDeltaTime;
        }

        bool mouse1Clicked = Input.GetMouseButton(0);

        GotProcessors = false;
        EnumerateObjects();
        // get all custom events.
        lock (CustomEvents)
        {
            while (CustomEvents.Count > 0)
            {
                CustomEvent ce = CustomEvents.Dequeue();
                for (int i = Processors.Count - 1; i >= 0; i--)
                {
                    // check if processor's renderer is enabled. implicitly don't give any events to invisible objects.
                    if (!ce.IsForced && !ProcessorsEnabled[i])
                    {
                        continue;
                    }
                    if (((IUiEventProcessor)Processors[i]).ProcessCustomEvent(ce) && !ce.IsGlobal)
                    {
                        break;
                    }
                }
            }
        }
        // get all events.
        Event e = new Event();

        while (Event.PopEvent(e))
        {
            // pressing PrintScreen or Alt+S results in screenshot unconditionally.
            if (e.type == EventType.KeyDown &&
                (e.keyCode == KeyCode.Print ||
                 e.keyCode == KeyCode.SysReq ||
                 (e.keyCode == KeyCode.S && e.alt)))
            {
                MainCamera.Instance.TakeScreenshot();
                return;
            }

            if (e.rawType == EventType.MouseDown)
            {
                if (lastMouseDown > 0.25f)
                {
                    lastMouseDown = 0;
                }
                else
                {
                    e.commandName = "double";
                    lastMouseDown = 1;
                }
            }

            // reverse iteration
            bool EventIsGlobal = (e.type == EventType.KeyUp ||
                                  e.rawType == EventType.MouseUp);
            for (int i = Processors.Count - 1; i >= 0; i--)
            {
                // check if processor's renderer is enabled. implicitly don't give any events to invisible objects.
                if (!ProcessorsEnabled[i])
                {
                    continue;
                }
                if (((IUiEventProcessor)Processors[i]).ProcessEvent(e) && !EventIsGlobal)
                {
                    break;
                }
            }
        }

        // also fake mouse event for each processor
        bool    doStartDrag  = false;
        float   doStartDragX = lastMouseX;
        float   doStartDragY = lastMouseY;
        Vector2 mPos         = Utils.GetMousePosition();
        Object  mProcessor   = null;

        /*if (mPos.x != lastMouseX ||
         *  mPos.y != lastMouseY)*/
        {
            Event ef = new Event();
            ef.type = EventType.MouseMove;

            if (lastMouseChange > 0.5f && !Input.GetMouseButton(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2))
            {
                ef.commandName  = "tooltip";
                lastMouseChange = -1;
            }

            for (int i = Processors.Count - 1; i >= 0; i--)
            {
                // check if processor's renderer is enabled. implicitly don't give any events to invisible objects.
                if (!ProcessorsEnabled[i])
                {
                    continue;
                }
                if (((IUiEventProcessor)Processors[i]).ProcessEvent(ef))
                {
                    mProcessor = Processors[i];
                    break;
                }
            }

            if (lastMouseX != mPos.x ||
                lastMouseY != mPos.y)
            {
                lastMouseX      = mPos.x;
                lastMouseY      = mPos.y;
                doStartDrag     = (DragItem == null) ? mouse1Clicked : false;
                lastMouseChange = 0;
                lastMouseDown   = 1; // disable doubleclick if drag started
                UnsetTooltip();
            }
        }

        CheckMouseOver((IUiEventProcessor)mProcessor);

        // process drag-drop for items.
        // first ask every element if they can process the drop.
        bool dragProcessed = false;

        //for (int i = Processors.Count - 1; i >= 0; i--)
        if (mProcessor != null && mProcessor is IUiItemDragger)
        {
            _CurrentDragDragger = (IUiItemDragger)mProcessor;

            // start dragging if coordinates changed with mouse button pressed.
            // don't call doStartDrag further if one of the widgets has processed it.
            if (doStartDrag && _CurrentDragDragger.ProcessStartDrag(doStartDragX, doStartDragY))
            {
                doStartDrag         = false;
                dragProcessed       = true;
                _CurrentDragDragger = null;
                goto NoDrag;
            }

            // process already done dragging (if any)
            if (DragItem != null && _CurrentDragDragger.ProcessDrag(DragItem, mPos.x, mPos.y))
            {
                dragProcessed = true;
                // check drop. if drop is done and processed, we should complete dragging.
                // make new item.
                // it's the duty of _DragDragger to delete the old item based on drag count.
                if (!mouse1Clicked)
                {
                    // if parent has changed, then it probably doesn't belong to the original pack anymore and thus can't be moved.
                    Item newItem = _DragDragger.ProcessVerifyEndDrag();

                    if (newItem == null)
                    {
                        CancelDrag();
                        _CurrentDragDragger = null;
                        goto NoDrag;
                    }

                    if (_CurrentDragDragger.ProcessDrop(newItem, mPos.x, mPos.y))
                    {
                        _DragDragger.ProcessEndDrag();
                        DragItem      = null;
                        DragItemCount = 0;
                        _DragCallback = null;
                        _DragDragger  = null;
                    }
                }
            }

            _CurrentDragDragger = null;
        }

NoDrag:

        if (DragItem != null)
        {
            // cancel drop if we tried to drop on a bad place.
            // DropItem != null && !mouse1Clicked means that it didnt process drop.
            if (!mouse1Clicked)
            {
                CancelDrag();
            }
            else
            {
                DragItem.Class.File_Pack.UpdateSprite();

                if (!dragProcessed) // set mouse cursor
                {
                    MouseCursor.SetCursor(MouseCursor.CurCantPut);
                }
                else
                {
                    MouseCursor.SetCursor(DragItem.Class.File_Pack.File);
                }
            }
        }
    }
Exemplo n.º 13
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            int lw = 64 + View.InvWidth * 80;
            int lh = 90;

            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y);
            if (mPosLocal.x < 0 || mPosLocal.y < 0 ||
                mPosLocal.x > lw || mPosLocal.y > lh)
            {
                if (ArrowHovered != 0)
                {
                    ArrowHovered = 0;
                    UpdateMaterials();
                }

                return(false);
            }

            // process hover
            if (e.rawType == EventType.MouseMove)
            {
                if (mPosLocal.x < 32)
                {
                    ArrowHovered = 1;
                }
                else if (mPosLocal.x >= lw - 32)
                {
                    ArrowHovered = 2;
                }
                else
                {
                    ArrowHovered = 0;
                }
                UpdateMaterials();
            }
            else if (e.rawType == EventType.MouseDown)
            {
                if (ArrowClicked != ArrowHovered)
                {
                    ArrowClicked = ArrowHovered;
                    UpdateMaterials();
                }
            }
            else if (e.rawType == EventType.MouseUp)
            {
                if (ArrowClicked != 0)
                {
                    ArrowClicked = 0;
                    UpdateMaterials();
                }
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(false);
    }
Exemplo n.º 14
0
    void UpdateInput()
    {
        if (!MapLogic.Instance.IsLoaded)
        {
            return;
        }

        // update mouse x/y
        int     oldMouseCellX = MouseCellX;
        int     oldMouseCellY = MouseCellY;
        Vector3 mPos          = Utils.GetMousePosition();

        mPos.x += ScrollX * 32;
        mPos.y += ScrollY * 32;
        float cXFrac = (mPos.x / 32) - Mathf.Floor(mPos.x / 32);

        _MouseCellX = (int)(mPos.x / 32);
        _MouseCellY = 0;
        for (int y = (int)_VisibleRect.yMin; y <= _VisibleRect.yMax; y++)
        {
            float h1 = y * 32 - GetHeightAt(_MouseCellX, y);
            float h2 = y * 32 - GetHeightAt(_MouseCellX + 1, y);
            float h  = h1 * (1f - cXFrac) + h2 * cXFrac;
            if (mPos.y < h)
            {
                _MouseCellY = y - 1;
                break;
            }
        }
        _MouseCellX = Mathf.Clamp(_MouseCellX, 0, MapLogic.Instance.Width - 1);
        _MouseCellY = Mathf.Clamp(_MouseCellY, 0, MapLogic.Instance.Height - 1);
        //Debug.Log(string.Format("mouse = {0} {1} (from {2} {3})", _MouseCellX, _MouseCellY, mPos.x, mPos.y));

        // temporary!
        if (MapLogic.Instance.ConsolePlayer == null) // mostly if we're server
        {
            if (oldMouseCellX != MouseCellX ||
                oldMouseCellY != MouseCellY)
            {
                MapLogic.Instance.SetTestingVisibility(MouseCellX, MouseCellY, 5);
            }
        }

        // PERMANENT (x2)
        // check currently hovered object
        MapNode[,] nodes = MapLogic.Instance.Nodes;
        MapObject o  = null;
        float     oZ = 0;

        for (int y = (int)_VisibleRect.yMin; y <= _VisibleRect.yMax; y++)
        {
            for (int x = (int)_VisibleRect.xMin; x <= _VisibleRect.xMax; x++)
            {
                foreach (MapObject mobj in nodes[x, y].Objects)
                {
                    if (mobj.GameObject == null || mobj.GameScript == null)
                    {
                        continue;
                    }

                    //
                    if (!(mobj.GameScript is IMapViewSelectable) || !((IMapViewSelectable)mobj.GameScript).IsSelected((int)mPos.x, (int)mPos.y))
                    {
                        continue;
                    }

                    if (mobj.GameObject.transform.position.z < oZ)
                    {
                        o  = mobj;
                        oZ = mobj.GameObject.transform.position.z;
                    }
                }
            }
        }

        MouseCursor.SetCursor(MouseCursor.CurDefault);
        bool hoveringDarkness = (nodes[MouseCellX, MouseCellY].Flags & MapNodeFlags.Visible) == 0;

        if (o != null && (o.GameScript is IMapViewSelfie))
        {
            Infowindow.Viewer = (IMapViewSelfie)o.GameScript;
        }
        else if (SelectedObject != null && (SelectedObject.GameScript is IMapViewSelfie))
        {
            Infowindow.Viewer = (IMapViewSelfie)SelectedObject.GameScript;
        }
        else
        {
            Infowindow.Viewer = null;
        }
        HoveredObject = o;

        if (GetCastSpell() != Spell.Spells.NoneSpell)
        {
            MouseCursor.SetCursor(MouseCursor.CurCast);
            return;
        }

        if (!hoveringDarkness && HoveredObject != null && (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move || Commandbar.CurrentCommand == 0))
        {
            // hovered usable buildings have different cursor picture.
            if (HoveredObject.GetObjectType() == MapObjectType.Structure &&
                ((MapStructure)HoveredObject).Class.Usable)
            {
                MouseCursor.SetCursor(MouseCursor.CurSelectStructure);
            }
            else
            {
                MouseCursor.SetCursor(MouseCursor.CurSelect);
            }
        }
        else if (SelectedObject != null && SelectedObject is IPlayerPawn)
        {
            Player sp = ((IPlayerPawn)SelectedObject).GetPlayer();
            if (sp == MapLogic.Instance.ConsolePlayer)
            {
                if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move)
                {
                    MouseCursor.SetCursor(MouseCursor.CurMove);
                }
                else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack)
                {
                    MouseCursor.SetCursor(MouseCursor.CurAttack);
                }
                else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.MoveAttack)
                {
                    MouseCursor.SetCursor(MouseCursor.CurMoveAttack);
                }
                else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup)
                {
                    MouseCursor.SetCursor(MouseCursor.CurPickup);
                }
            }
        }
    }
Exemplo n.º 15
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseUp)
        {
            IsDragging = false;
        }

        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            Vector2 mPos = Utils.GetMousePosition();
            if (mPos.x > transform.position.x &&
                mPos.y > transform.position.y &&
                mPos.x < transform.position.x + 176 &&
                mPos.y < transform.position.y + 158)
            {
                mPos -= new Vector2(transform.position.x, transform.position.y);
                // check cursor specifically
                int   mapLeft = 8;
                int   mapTop  = 8;
                float sW      = MapLogic.Instance.Width - 16;
                float sH      = MapLogic.Instance.Height - 16;
                float aspect  = sW / sH;
                float w       = 128;
                float h       = 128;
                // handle uneven map sizes
                if (sW > sH)
                {
                    h /= aspect;
                }
                else if (sH > sW)
                {
                    w *= aspect;
                }
                float   cX    = 90 - w / 2;
                float   cY    = 83 - h / 2;
                float   cXCur = 90 - 64;
                float   cYCur = 83 - 64;
                RectInt vrec  = MapView.Instance.UnpaddedVisibleRect;
                vrec.x -= mapLeft;
                vrec.y -= mapTop;

                MouseCursor.SetCursor(MouseCursor.CurDefault);
                if (mPos.x >= cXCur && mPos.x < cXCur + 128 &&
                    mPos.y >= cYCur && mPos.y < cYCur + 128)
                {
                    MouseCursor.SetCursor(MouseCursor.CurSmallDefault);
                    if (e.rawType == EventType.MouseDown)
                    {
                        IsDragging = true;
                    }

                    if (IsDragging)
                    {
                        // find map coordinates from cursor
                        float offsX = Mathf.Round((mPos.x - cX) / w * sW + 8 - vrec.width / 2);
                        float offsY = Mathf.Round((mPos.y - cY) / h * sH + 8 - vrec.height / 2);
                        MapView.Instance.SetScroll((int)offsX, (int)offsY);
                    }
                }

                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 16
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            int lw = 480;
            int lh = 85;

            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y);
            if (mPosLocal.x < 0 || mPosLocal.y < 0 ||
                mPosLocal.x > lw || mPosLocal.y > lh)
            {
                return(false);
            }

            Vector2 spLocal = new Vector2((mPosLocal.x - 5) / 38, (mPosLocal.y - 5) / 38);
            int     spd     = (int)spLocal.y * 12 + (int)spLocal.x;
            if (spd > 24 || spd < 0)
            {
                spd = -1;
            }
            Spell.Spells sp = RemapToSpell(spd);

            if (e.rawType == EventType.MouseDown)
            {
                ActiveSpell = sp;
                MapView.Instance.OneTimeCast = null;

                if (e.commandName == "double" && !Spell.IsAttackSpell(ActiveSpell))
                {
                    MapObject curObject = SelectedObject;
                    if (curObject is MapUnit)
                    {
                        Client.SendCastToUnit((MapUnit)curObject, new global::Spell((int)sp, (MapUnit)curObject), (MapUnit)curObject, curObject.X, curObject.Y);
                    }
                }
            }

            if (e.rawType == EventType.MouseMove &&
                e.commandName == "tooltip" &&
                (SpellsMask & (int)sp) != 0)
            {
                if (spd >= 0 && spd < Locale.Spells.Count)
                {
                    string    tt        = Locale.Spells[spd];
                    MapObject curObject = SelectedObject;
                    if (curObject is MapUnit)
                    {
                        tt += "\n" + new Spell((int)sp, (MapUnit)curObject).ToVisualString();
                    }
                    UiManager.Instance.SetTooltip(tt);
                }
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(false);
    }
Exemplo n.º 17
0
    public bool ProcessEvent(Event e)
    {
        if (!MapLogic.Instance.IsLoaded)
        {
            if (MapLogic.Instance.IsLoading)
            {
                MouseCursor.SetCursor(MouseCursor.CurWait);
            }
            return(false);
        }

        if (e.type == EventType.KeyDown)
        {
            switch (e.keyCode)
            {
            case KeyCode.LeftArrow:
                if (ScrollDeltaX == 0)
                {
                    ScrollDeltaX = -1;
                }
                return(true);

            case KeyCode.RightArrow:
                if (ScrollDeltaX == 0)
                {
                    ScrollDeltaX = 1;
                }
                return(true);

            case KeyCode.UpArrow:
                if (ScrollDeltaY == 0)
                {
                    ScrollDeltaY = -1;
                }
                return(true);

            case KeyCode.DownArrow:
                if (ScrollDeltaY == 0)
                {
                    ScrollDeltaY = 1;
                }
                return(true);

            case KeyCode.Plus:
            case KeyCode.Equals:     // + = =
            case KeyCode.KeypadPlus:
            {
                int oldSpeed = MapLogic.Instance.Speed;
                if (!NetworkManager.IsClient)
                {
                    MapLogic.Instance.Speed++;
                }
                if (oldSpeed != MapLogic.Instance.Speed)
                {
                    MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]);
                }
            }
                return(true);

            case KeyCode.Minus:
            case KeyCode.KeypadMinus:
            {
                int oldSpeed = MapLogic.Instance.Speed;
                if (!NetworkManager.IsClient)
                {
                    MapLogic.Instance.Speed--;
                }
                if (oldSpeed != MapLogic.Instance.Speed)
                {
                    MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]);
                }
            }
                return(true);

            case KeyCode.F3:
                //if (NetworkManager.IsClient)
            {
                DiplomacyWindow wnd = Utils.CreateObjectWithScript <DiplomacyWindow>();
                //Debug.LogFormat("created a window!");
            }
                return(true);

            case KeyCode.Escape:
            {
                // todo: create main menu
                ExampleWindow wnd = Utils.CreateObjectWithScript <ExampleWindow>();
            }
                return(true);

            case KeyCode.Space:
                // check if local unit is dead.
                // for dead local unit, space sends respawn.
                // for alive local unit, space toggles both spellbook and inventory.
                if (MapLogic.Instance.ConsolePlayer != null &&
                    !MapLogic.Instance.ConsolePlayer.Avatar.IsAlive)
                {
                    Client.SendRespawn();
                }
                else
                {
                    bool cstate = InventoryVisible && SpellbookVisible;
                    InventoryVisible = !cstate;
                    SpellbookVisible = !cstate;
                    Spellbook.Update();
                }
                return(true);

            case KeyCode.BackQuote:
                InventoryVisible = !InventoryVisible;
                Spellbook.Update();
                return(true);

            case KeyCode.Q:
                SpellbookVisible = !SpellbookVisible;
                Spellbook.Update();
                return(true);
            }
        }
        else if (e.type == EventType.KeyUp)
        {
            switch (e.keyCode)
            {
            case KeyCode.LeftArrow:
                if (ScrollDeltaX == -1)
                {
                    ScrollDeltaX = 0;
                }
                return(true);

            case KeyCode.RightArrow:
                if (ScrollDeltaX == 1)
                {
                    ScrollDeltaX = 0;
                }
                return(true);

            case KeyCode.UpArrow:
                if (ScrollDeltaY == -1)
                {
                    ScrollDeltaY = 0;
                }
                return(true);

            case KeyCode.DownArrow:
                if (ScrollDeltaY == 1)
                {
                    ScrollDeltaY = 0;
                }
                return(true);
            }
        }
        else if (e.rawType == EventType.MouseMove)
        {
            UpdateInput();
            return(true);
        }
        else if (e.rawType == EventType.MouseDown && e.button == 0)
        {
            // select unit if not selected yet
            // to-do: unfuck this expression later...
            if (HoveredObject != null &&
                (SelectedObject == null || (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move && GetCastSpell() == Spell.Spells.NoneSpell &&
                                            !Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt)) || (Commandbar.CurrentCommand == 0)) &&
                (SelectedObject == null || !(HoveredObject is MapStructure s && s.Class.Usable)))
            {
                SelectedObject = HoveredObject;
            }
            else if (SelectedObject != null && SelectedObject is IPlayerPawn && ((IPlayerPawn)SelectedObject).GetPlayer() == MapLogic.Instance.ConsolePlayer)
            {
                // todo: handle commands here
                // try to walk.
                if (SelectedObject is MapUnit unit)
                {
                    Spell.Spells castSpId = GetCastSpell();
                    if (HoveredObject is MapStructure struc && struc.Class.Usable)
                    {
                        Client.SendUseStructure(unit, struc);
                    }
                    else if (castSpId != Spell.Spells.NoneSpell && (MapLogic.Instance.Nodes[MouseCellX, MouseCellY].Flags & MapNodeFlags.Visible) != 0)
                    {
                        Spell castSp = GetOneTimeCast();
                        if (castSp == null)
                        {
                            castSp = unit.GetSpell(castSpId);
                        }
                        if (HoveredObject != null && HoveredObject is MapUnit)
                        {
                            Client.SendCastToUnit(unit, castSp, (MapUnit)HoveredObject, MouseCellX, MouseCellY);
                        }
                        else
                        {
                            Client.SendCastToArea(unit, castSp, MouseCellX, MouseCellY);
                        }
                        if (castSp == OneTimeCast || Commandbar.CurrentCommandActual == MapViewCommandbar.Commands.Cast)
                        {
                            SpellbookVisible = false;
                            if (Commandbar.CurrentCommandActual == MapViewCommandbar.Commands.Cast)
                            {
                                Commandbar.InitDefault(SelectedObject);
                            }
                        }
                        OneTimeCast = null;
                    }
                    else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move)
                    {
                        Client.SendMoveUnit(unit, MouseCellX, MouseCellY);
                    }
                    else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack &&
                             HoveredObject != null &&
                             HoveredObject is MapUnit)
                    {
                        Client.SendAttackUnit(unit, (MapUnit)HoveredObject);
                    }
                    else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup &&
                             MapLogic.Instance.GetSackAt(MouseCellX, MouseCellY) != null)
                    {
                        Client.SendPickupUnit(unit, MouseCellX, MouseCellY); // issue sack pickup command by current unit at target coordinates
                    }
                }
            }
Exemplo n.º 18
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            int lw = (int)(64 + View.InvWidth * 80 * View.InvScale);
            int lh = 90;

            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y);
            if (mPosLocal.x < 0 || mPosLocal.y < 0 ||
                mPosLocal.x > lw || mPosLocal.y > lh)
            {
                if (ArrowHovered != 0)
                {
                    ArrowHovered = 0;
                    UpdateMaterials();
                }

                return(false);
            }

            // process hover
            if (e.rawType == EventType.MouseMove)
            {
                if (mPosLocal.x < 32)
                {
                    ArrowHovered = 1;
                }
                else if (mPosLocal.x >= lw - 32)
                {
                    ArrowHovered = 2;
                }
                else
                {
                    ArrowHovered = 0;
                }
                UpdateMaterials();
            }
            else if (e.rawType == EventType.MouseDown)
            {
                if (ArrowClicked != ArrowHovered)
                {
                    ArrowClicked = ArrowHovered;
                    UpdateMaterials();
                }
            }
            else if (e.rawType == EventType.MouseUp)
            {
                if (ArrowClicked != 0)
                {
                    if (ArrowClicked == 1) // left arrow
                    {
                        if (View.Scroll > 0)
                        {
                            View.Scroll--;
                        }
                    }
                    else if (ArrowClicked == 2) // right arrow
                    {
                        if (View.Scroll < View.GetVisualPackCount() - View.InvWidth)
                        {
                            View.Scroll++;
                        }
                    }
                    ArrowClicked = 0;
                    UpdateMaterials();
                }
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(false);
    }
    protected override void OnMouseUp(MouseEventArgs arg)
    {
      if (m_bAction == false)
      {
        return;
      }
      ITool pTool;
      pTool = (ITool)m_gSelectTool;
      pTool.OnMouseUp(GetButtonCode(arg), Convert.ToInt32(arg.Shift), arg.X, arg.Y);
      

      SelectFromGraphics();

      // release object
      m_gSelectTool = null;
      m_bAction = false;

      MouseCursor cursor;
      cursor = new MouseCursor();
      cursor.SetCursor(esriSystemMouseCursor.esriSystemMouseCursorDefault); 
    }