示例#1
0
        private void HandleLevelUpKeys(ResultSet resultSet)
        {
            var game = (RetroDungeoneerGame)RB.Game;

            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                resultSet.AddExit();
                return;
            }

            int index = -1;

            for (char i = 'a'; i <= 'c'; i++)
            {
                if (RB.KeyPressed((KeyCode)i))
                {
                    index = (int)(i - 'a');
                    break;
                }
            }

            // Check if pointer clicked on any of the items
            if (RB.ButtonReleased(RB.BTN_POINTER_A))
            {
                if (mMenuInventory.pointerIndex >= 0 && mMenuInventory.pointerIndex <= 2)
                {
                    index = mMenuInventory.pointerIndex;
                }
            }

            LevelUp levelUp = LevelUp.None;

            if (index >= 0 && index <= 2)
            {
                switch (index)
                {
                case 0:
                    levelUp = LevelUp.Hp;
                    break;

                case 1:
                    levelUp = LevelUp.Str;
                    break;

                case 2:
                    levelUp = LevelUp.Def;
                    break;
                }

                resultSet.AddLevelUp(levelUp);

                RB.SoundPlay(game.assets.soundSelectOption, 1, RandomUtils.RandomPitch(0.1f));
            }
        }
示例#2
0
        private void HandlePlayerDeadKeys(ResultSet resultSet)
        {
            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                resultSet.AddExit();
                return;
            }

            if (RB.KeyPressed(KeyCode.P))
            {
                resultSet.AddShowCharacterScreen();
            }
        }
示例#3
0
        /// <summary>
        /// Update
        /// </summary>
        public void Update()
        {
            if (RB.KeyPressed(mKeyCode))
            {
                if (!mPressed && mButtonPressedCB != null)
                {
                    mButtonPressedCB(this, mUserData);
                }

                mPressed = true;
            }
            else if (RB.KeyReleased(mKeyCode))
            {
                if (mPressed && mButtonReleasedCB != null)
                {
                    mButtonReleasedCB(this, mUserData);
                }

                mPressed = false;
            }

            if (mTouchArmed)
            {
                if (RB.ButtonDown(RB.BTN_POINTER_A) && mHitRect.Contains(RB.PointerPos()))
                {
                    if (!mPressed && mButtonPressedCB != null)
                    {
                        mButtonPressedCB(this, mUserData);
                    }

                    mPressed = true;
                    mTouched = true;
                }
                else if ((!RB.ButtonDown(RB.BTN_POINTER_A) || !mHitRect.Contains(RB.PointerPos())) && mTouched)
                {
                    if (mPressed && mButtonReleasedCB != null)
                    {
                        mButtonReleasedCB(this, mUserData);
                    }

                    mTouched = false;
                    mPressed = false;
                }
            }
            else if (!RB.ButtonDown(RB.BTN_POINTER_A))
            {
                mTouchArmed = true;
            }
        }
示例#4
0
        private void HandleTargetingKeys(ResultSet resultSet)
        {
            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                resultSet.AddExit();
                return;
            }

            if (RB.KeyPressed(KeyCode.F))
            {
                var ranged = mPlayer.e.equipment.equipment[(int)EquipmentSlot.Ranged];

                if (mGameState == GameState.TARGETING && mTargetingItem == ranged)
                {
                    // Already targeting, do a quick shot by injecting an invalid position which will make
                    // ShootBow() look for nearest enemy
                    resultSet.AddLeftClick(new Vector2i(-1, -1));
                }
            }
        }
        private void HandleMenuKeys(ResultSet resultSet)
        {
            if (!mShowingMessageBox)
            {
                return;
            }

            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                resultSet.AddExit();
                return;
            }

            // Check keyboard input
            for (char i = 'a'; i < 'a' + mMenuMessageBox.optionCount; i++)
            {
                if (RB.KeyPressed((KeyCode)i))
                {
                    int index = (int)(i - 'a');
                    if (mHandlers[index] != null)
                    {
                        mHandlers[index]();
                    }
                }
            }

            // Check mouse input
            if (RB.ButtonReleased(RB.BTN_POINTER_A))
            {
                int index = mMenuMessageBox.pointerIndex;
                if (index >= 0)
                {
                    if (mHandlers[index] != null)
                    {
                        mHandlers[index]();
                    }
                }
            }
        }
示例#6
0
        private void HandleInventoryKeys(ResultSet resultSet)
        {
            var game = (RetroDungeoneerGame)RB.Game;

            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                resultSet.AddExit();
                return;
            }

            for (char i = 'a'; i <= 'z'; i++)
            {
                if (RB.KeyPressed((KeyCode)i))
                {
                    int index = (int)(i - 'a');
                    if (!mPlayer.isEmpty && mPlayer.e.inventory.items.Length > index && !mPlayer.e.inventory.items[index].isEmpty)
                    {
                        resultSet.AddInventoryIndex(mPlayer, index);
                        RB.SoundPlay(game.assets.soundSelectOption, 1, RandomUtils.RandomPitch(0.1f));
                        return;
                    }
                }
            }

            // Check if pointer clicked on any of the items
            if (RB.ButtonReleased(RB.BTN_POINTER_A))
            {
                int index = mMenuInventory.pointerIndex;
                if (index >= 0 && !mPlayer.isEmpty && mPlayer.e.inventory.items.Length > index && !mPlayer.e.inventory.items[index].isEmpty)
                {
                    resultSet.AddInventoryIndex(mPlayer, index);
                    RB.SoundPlay(game.assets.soundSelectOption, 1, RandomUtils.RandomPitch(0.1f));
                    return;
                }
            }
        }
示例#7
0
        private void HandlePlayerTurnKeys(ResultSet resultSet)
        {
            // Check if we should block all player input until all keys are up
            // This is useful to block player input when exiting menus
            if (mBlockMoveUntilKeyUp)
            {
                if (!AnyPlayerKeyDown())
                {
                    mBlockMoveUntilKeyUp = false;
                }
                else
                {
                    return;
                }
            }

            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                resultSet.AddExit();
                return;
            }

            if (RB.KeyPressed(KeyCode.I))
            {
                resultSet.AddShowInventory();
            }

            if (RB.KeyPressed(KeyCode.O))
            {
                resultSet.AddDropInventory();
            }

            if (RB.KeyPressed(KeyCode.P))
            {
                resultSet.AddShowCharacterScreen();
            }

            if (RB.KeyPressed(KeyCode.Return) || RB.KeyPressed(KeyCode.KeypadEnter))
            {
                resultSet.AddTakeStairs();
            }

            if (RB.KeyPressed(KeyCode.H))
            {
                resultSet.AddShowHelp();
            }

            Vector2i delta = Vector2i.zero;

            if (RB.KeyDown(KeyCode.W) || RB.KeyDown(KeyCode.Keypad8))
            {
                delta.y--;
            }
            else if (RB.KeyDown(KeyCode.S) || RB.KeyDown(KeyCode.Keypad2))
            {
                delta.y++;
            }
            else if (RB.KeyDown(KeyCode.A) || RB.KeyDown(KeyCode.Keypad4))
            {
                delta.x--;
            }
            else if (RB.KeyDown(KeyCode.D) || RB.KeyDown(KeyCode.Keypad6))
            {
                delta.x++;
            }
            else if (RB.KeyDown(KeyCode.Q) || RB.KeyDown(KeyCode.Keypad7))
            {
                delta.x--;
                delta.y--;
            }
            else if (RB.KeyDown(KeyCode.E) || RB.KeyDown(KeyCode.Keypad9))
            {
                delta.x++;
                delta.y--;
            }
            else if (RB.KeyDown(KeyCode.Z) || RB.KeyDown(KeyCode.Keypad1))
            {
                delta.x--;
                delta.y++;
            }
            else if (RB.KeyDown(KeyCode.C) || RB.KeyDown(KeyCode.Keypad3))
            {
                delta.x++;
                delta.y++;
            }

            if (delta.x > 1)
            {
                delta.x = 1;
            }
            else if (delta.x < -1)
            {
                delta.x = -1;
            }

            if (delta.y > 1)
            {
                delta.y = 1;
            }
            else if (delta.y < -1)
            {
                delta.y = -1;
            }

            if (delta.x == 0 && delta.y == 0)
            {
                mKeyRepeatStage = 0;
            }
            else
            {
                var ticksDelta = RB.Ticks - mLastMoveTimestamp;

                if (mKeyRepeatStage == 0 || (mKeyRepeatStage == 1 && ticksDelta > C.KEY_REPEAT_SPEED_STAGE1) || (mKeyRepeatStage > 1 && ticksDelta > C.KEY_REPEAT_SPEED_STAGE2))
                {
                    if (delta.x != 0 || delta.y != 0)
                    {
                        mKeyRepeatStage++;
                        mLastMoveTimestamp = RB.Ticks;
                        resultSet.AddMove(delta);
                    }
                }
            }

            // Wait
            if (RB.KeyPressed(KeyCode.X) || RB.KeyPressed(KeyCode.Keypad5))
            {
                resultSet.AddMove(Vector2i.zero);
            }

            if (RB.KeyPressed(KeyCode.G) || RB.KeyPressed(KeyCode.Keypad0))
            {
                resultSet.AddPickup(mPlayer);
            }

            if (RB.KeyPressed(KeyCode.F))
            {
                var ranged = mPlayer.e.equipment.equipment[(int)EquipmentSlot.Ranged];
                var arrow  = mPlayer.e.inventory.GetArrow();
                if (!ranged.isEmpty && !arrow.isEmpty)
                {
                    resultSet.AddTargeting(ranged);
                }
                else
                {
                    if (ranged.isEmpty)
                    {
                        resultSet.AddMessage(C.FSTR.Set("You do not have a ranged weapon equipped."));
                    }
                    else if (arrow.isEmpty)
                    {
                        resultSet.AddMessage(C.FSTR.Set("You do not have an arrow to shoot."));
                    }
                }
            }
        }
示例#8
0
        /// <summary>
        /// Update, handles switching to next scene, and quitting the demo
        /// </summary>
        public virtual void Update()
        {
            var demo = (StressTest)RB.Game;

            if (RB.KeyPressed(KeyCode.Return) || (UnityEngine.Input.mousePresent && RB.ButtonPressed(RB.BTN_POINTER_A)) || RB.ButtonPressed(RB.BTN_A))
            {
                demo.NextScene();
            }

            if ((UnityEngine.Input.mousePresent && RB.ButtonPressed(RB.BTN_POINTER_B)) || RB.ButtonPressed(RB.BTN_X))
            {
                demo.PreviousScene();
            }

            if (RB.ButtonPressed(RB.BTN_SYSTEM))
            {
                Application.Quit();
            }

            if (!UnityEngine.Input.mousePresent)
            {
                if (RB.ButtonReleased(RB.BTN_POINTER_A, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[0] = (long)RB.Ticks;
                }

                if (RB.ButtonReleased(RB.BTN_POINTER_B, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[1] = (long)RB.Ticks;
                }

                if (RB.ButtonReleased(RB.BTN_POINTER_C, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[2] = (long)RB.Ticks;
                }

                if (RB.ButtonReleased(RB.BTN_POINTER_D, RB.PLAYER_ANY))
                {
                    mTouchTimestamp[3] = (long)RB.Ticks;
                }

                // If all fingers are up then check how many fingers have close timestamps
                if (!RB.ButtonDown(RB.BTN_POINTER_A, RB.PLAYER_ANY) &&
                    !RB.ButtonDown(RB.BTN_POINTER_B, RB.PLAYER_ANY) &&
                    !RB.ButtonDown(RB.BTN_POINTER_C, RB.PLAYER_ANY) &&
                    !RB.ButtonDown(RB.BTN_POINTER_D, RB.PLAYER_ANY))
                {
                    int fingerCount = 0;
                    for (int i = 0; i < 4; i++)
                    {
                        long delta = (long)RB.Ticks - (long)mTouchTimestamp[i];
                        if (delta >= 0 && delta < 5)
                        {
                            fingerCount++;
                        }
                    }

                    if (fingerCount == 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            mTouchTimestamp[i] = long.MaxValue;
                        }

                        demo.NextScene();
                    }
                    else if (fingerCount > 1)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            mTouchTimestamp[i] = long.MaxValue;
                        }

                        demo.PreviousScene();
                    }
                }
            }
        }
示例#9
0
    public virtual void Update(bool hasFocus = true)
    {
        Vector2i     mousePos = RB.PointerPos() + new Vector2i(0, 1);     // + 0, 1 is workaround for weird hovering behaviour?!
        UIObj        on       = null;
        List <UIObj> objsNoLongerUnderMouse = new List <UIObj>();

        foreach (UIObj obj in objUnderMouse)
        {
            if (!obj.IsInBounds(mousePos) || !obj.isVisible)
            {
                if (objUnderMouse.Contains(obj))
                {
                    objsNoLongerUnderMouse.Add(obj);
                    obj.OnMouseExit();
                    EventBus.UIMouseExit.Invoke(obj);
                }
            }
        }
        objUnderMouse.RemoveWhere((obj) => objsNoLongerUnderMouse.Contains(obj));
        List <UIObj> uiObjsToUpdate = uiObjs;

        if (currentMsgBox != null)
        {
            uiObjsToUpdate = currentMsgBox.GetUIObjs();
        }
        foreach (UIObj obj in uiObjsToUpdate)
        {
            if (obj.HasKeybind() && RB.KeyPressed(obj.GetKeybind()))
            {
                if (obj.IsInteractable)
                {
                    EventBus.UIClick.Invoke(obj);
                    obj.OnClick();
                }
            }
            if (obj.IsInBounds(mousePos) && obj.isVisible)
            {
                if (!objUnderMouse.Contains(obj))
                {
                    objUnderMouse.Add(obj);
                    obj.OnMouseEnter();
                    EventBus.UIMouseEnter.Invoke(obj);
                }
            }
            if (obj.IsInBounds(mousePos) && obj.IsInteractable)             // && hasFocus) {
            {
                if (obj.currentState != UIObj.State.Hovered)
                {
                    EventBus.UIHoverStart.Invoke(obj);
                }
                obj.currentState = UIObj.State.Hovered;
                on = obj;
            }
            else
            if (obj.currentState != UIObj.State.Disabled)
            {
                if (obj.currentState == UIObj.State.Hovered)
                {
                    EventBus.UIHoverEnd.Invoke(obj);
                }
                obj.currentState = UIObj.State.Enabled;
            }

            obj.Update();
        }
        if (RB.ButtonPressed(RB.BTN_POINTER_A) && hasFocus)
        {
            if (on != null)
            {
                on.currentState = UIObj.State.Pressed;
                mousePressedOn  = on;
                SetFocus(on);
            }
            else
            {
                SetFocus(null);
            }
        }
        else
        if (RB.ButtonReleased(RB.BTN_POINTER_A))
        {
            if (on == mousePressedOn && on != null)
            {
                if (on.currentState == UIObj.State.Hovered)
                {
                    EventBus.UIClick.Invoke(on);
                }
                mousePressedOn.OnClick();
            }
            mousePressedOn = null;
        }
        else
        if (RB.ButtonDown(RB.BTN_POINTER_A) && hasFocus)
        {
            if (mousePressedOn != null && on == mousePressedOn)
            {
                mousePressedOn.currentState = UIObj.State.Pressed;
            }
            else
            if (on != null)
            {
                on.currentState = UIObj.State.Enabled;
            }
        }
    }
示例#10
0
 public override void Update(bool hasFocus = true)
 {
     if (renderTargeting)
     {
         Rect2i   onRect     = new Rect2i(0, 0, 0, 0);
         UIObj    on         = null;
         Pawn     pawnTarget = null;
         Vector2i mouse      = RB.PointerPos();
         if ((mouse - lastMousePos).SqrMagnitude() > 2)
         {
             pawnSelectedByKey = -1;
         }
         for (int i = 0; i <= battle.allies.Length; i++)
         {
             if (RB.KeyPressed(KeyCode.Alpha1 + i))
             {
                 lastMousePos      = mouse;
                 pawnSelectedByKey = i;
             }
         }
         if (RB.KeyPressed(KeyCode.Escape) || RB.KeyPressed(KeyCode.Backspace))
         {
             pawnSelectedByKey = -1;
         }
         if (pawnSelectedByKey >= 0)
         {
             Pawn  p    = battle.GetPawn(pawnSelectedByKey);
             UIObj card = pawnCards[p];
             mouse      = card.pos + card.size / 2;
             on         = card;
             pawnTarget = p;
             onRect     = new Rect2i(on.pos, on.size);
         }
         foreach (KeyValuePair <Pawn, UIObj> cardPair in pawnCards)
         {
             onRect = new Rect2i(cardPair.Value.pos, cardPair.Value.size);
             if (onRect.Contains(mouse))
             {
                 on         = cardPair.Value;
                 pawnTarget = cardPair.Key;
                 break;
             }
         }
         if (on != null && pawnTarget != null)
         {
             if (pawnTarget != targetPawn)
             {
                 SetTooltip(targetSpell.GetShortDescription(battle.BuildContext(pawnTarget.GetId())));
             }
             targetPawn  = pawnTarget;
             targetPoint = new Vector2i(onRect.x + onRect.width, onRect.y + onRect.height / 2);
             targetRect  = new Rect2i(onRect.x - 1, onRect.y - 1, onRect.width + 1, onRect.height + 1);
             if (RB.ButtonPressed(RB.BTN_POINTER_A) || RB.KeyPressed(KeyCode.Return))
             {
                 Game.client.Send(GameMsg.CastSpell, new GameMsg.MsgCastSpell()
                 {
                     spellId = targetSpell.GetId(), targetId = targetPawn.GetId()
                 });
                 renderTargeting = false;
                 targetSpell     = null;
                 targetPawn      = null;
                 SetTooltip("");
             }
         }
         else
         {
             targetPawn = null;
             SetTooltip(targetSpell.GetShortDescription(battle.BuildContext(-1)));
             targetPoint = mouse;
             if (RB.ButtonPressed(RB.BTN_POINTER_ANY))
             {
                 renderTargeting = false;
                 targetSpell     = null;
             }
         }
     }
     else
     {
         base.Update(hasFocus);
     }
 }