예제 #1
0
    public void Update()
    {
        mousePos = RB.PointerPos();
        if (currentScreen != null)
        {
            currentScreen.Update(message.Length == 0);
        }
        if (message.Length > 0)
        {
            if (RB.ButtonPressed(RB.BTN_POINTER_A))
            {
                message = "";
                if (onClickMessage != null)
                {
                    onClickMessage.Invoke();
                    onClickMessage = null;
                }
            }
        }
        HashSet <int> soundSet = new HashSet <int>();

        while (soundQueue.Count > 0)
        {
            soundSet.Add(soundQueue.Dequeue());
        }
        foreach (int sound in soundSet)
        {
            RB.SoundPlay(sound, volume);
        }
    }
예제 #2
0
        private static void RenderMouseHover()
        {
            var tilePos = SceneGame.GetMouseTilePos();

            if (tilePos.x == -1)
            {
                return;
            }

            EntityFunctions.GetEntitiesStringAtTile(tilePos, C.FSTR);

            if (C.FSTR.Length > 0)
            {
                // Preserve camera location
                var cameraPos = RB.CameraGet();
                RB.CameraReset();

                var mousePos = RB.PointerPos();

                var anchorPos = new Vector2i(mousePos.x + 4, mousePos.y + 12);

                var textSize      = RB.PrintMeasure(C.FONT_SMALL, C.FSTR);
                var textRect      = new Rect2i(anchorPos.x, anchorPos.y, textSize.width, textSize.height);
                var textFrameRect = new Rect2i(textRect.x - 4, textRect.y - 4, textRect.width + 8, textRect.height + 8);

                RB.DrawRectFill(textFrameRect, C.COLOR_MENU_BACKGROUND);
                RB.DrawRect(textFrameRect, Color.white);
                RB.Print(C.FONT_SMALL, textRect, Color.white, 0, C.FSTR);

                RB.CameraSet(cameraPos);
            }
        }
예제 #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
 public virtual void Render()
 {
     foreach (UIObj uiObj in uiObjs)
     {
         if (uiObj.isVisible)
         {
             uiObj.Render();
         }
     }
     RenderForeground();
     if (currentMsgBox != null)
     {
         RB.AlphaSet(120);
         RB.DrawRectFill(new Rect2i(0, 0, size.width, size.height), Color.black);
         RB.AlphaSet(255);
         currentMsgBox.Render();
     }
     if (tooltip.Length > 0)
     {
         Vector2i tooltipSize = RB.PrintMeasure(tooltip) + new Vector2i(6, 6);
         Vector2i topRightPos = RB.PointerPos() - new Vector2i(0, tooltipSize.y);
         if (topRightPos.y >= 0)
         {
             if (topRightPos.x + tooltipSize.width < RB.DisplaySize.width)
             {
                 RenderTooltip(new Rect2i(topRightPos, tooltipSize), tooltip);
             }
             else
             {
                 RenderTooltip(new Rect2i(RB.PointerPos() - tooltipSize, tooltipSize), tooltip);
             }
         }
         else
         {
             if (topRightPos.x + tooltipSize.width < RB.DisplaySize.width)
             {
                 RenderTooltip(new Rect2i(RB.PointerPos(), tooltipSize), tooltip);
             }
             else
             {
                 RenderTooltip(new Rect2i(RB.PointerPos() - new Vector2i(tooltipSize.x, 0), tooltipSize), tooltip);
             }
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            var demo = (DemoReel)RB.Game;

            RB.Clear(DemoUtil.IndexToRGB(1));

            DrawNoisePad(4, 4);
            DrawPiano(4, 200);
            DrawMusicPlayer(350, 4);

            mNextButton.Render();
            mPrevButton.Render();

            if (RB.PointerPosValid())
            {
                RB.DrawSprite(4, RB.PointerPos());
            }
        }
예제 #6
0
    public override void OnClick()
    {
        if (hideTabs)
        {
            return;
        }
        Vector2i pos = RB.PointerPos();

        if (pos.y < tabY)
        {
            for (int i = 0; i < tabs.Length; i++)
            {
                if (pos.x >= tabTitleX[i] && pos.x < tabTitleX[i + 1])
                {
                    OpenTab(i);
                    Game.PlaySound(Game.AUDIO_BUTTON);
                    return;
                }
            }
        }
    }
예제 #7
0
        private bool IsVirtualKeyPressed(KeyboardKey key)
        {
            bool pressed = false;

            if (RB.ButtonDown(RB.BTN_POINTER_ANY))
            {
                for (int i = 0; i < 4 && !pressed; i++)
                {
                    if (RB.PointerPosValid(i) && RB.ButtonDown(mPointerButtons[i]))
                    {
                        var pos = RB.PointerPos(i);
                        if (key.Rect.Contains(pos - mKeyboardOffset))
                        {
                            pressed = true;
                        }
                    }
                }
            }

            // If not pressed, but was pressed then "type" it
            if (!pressed && key.WasPointerPressed)
            {
                var c = (char)key.Code1;
                if (mShiftPressed)
                {
                    c = ((char)key.Code2).ToString().ToUpperInvariant()[0];
                }

                c = mLookup[(int)c];

                if (c > '\0' && c <= '~')
                {
                    ProcessStringInput(c.ToString());
                }
            }

            key.WasPointerPressed = pressed;
            return(pressed);
        }
예제 #8
0
        /// <summary>
        /// Get tile position at current pointer position. This takes into account camera position.
        /// </summary>
        /// <returns>Tile position</returns>
        public static Vector2i GetMouseTilePos()
        {
            var game = (RetroDungeoneerGame)RB.Game;

            if (!RB.PointerPosValid())
            {
                return(new Vector2i(-1, -1));
            }

            var mousePos = RB.PointerPos() + mCamera.GetPos();

            mousePos.x -= (RB.DisplaySize.width / 2) - (game.assets.spriteSheet.grid.cellSize.width / 2);
            mousePos.y -= (RB.DisplaySize.height / 2) - (game.assets.spriteSheet.grid.cellSize.height / 2);

            var tilePos = new Vector2i(mousePos.x / game.assets.spriteSheet.grid.cellSize.width, mousePos.y / game.assets.spriteSheet.grid.cellSize.height);

            if (tilePos.x < 0 || tilePos.y < 0 || tilePos.x >= game.map.size.width || tilePos.y >= game.map.size.height)
            {
                return(new Vector2i(-1, -1));
            }

            return(tilePos);
        }
예제 #9
0
        /// <summary>
        /// Update
        /// </summary>
        public override void Update()
        {
            base.Update();

            if (RB.ButtonDown(RB.BTN_POINTER_A))
            {
                if (mDragging)
                {
                    int dragDelta = RB.PointerPos().x - mPrevPointerPos.x;
                    mPos.x += dragDelta;

                    Rect.x = mPos.x - (Rect.width / 2);

                    int minMargin = RB.SpriteSize(0).width / 2;
                    if (Rect.x < minMargin)
                    {
                        Rect.x = minMargin;
                    }
                    else if (Rect.x + Rect.width > RB.DisplaySize.width - minMargin)
                    {
                        Rect.x = RB.DisplaySize.width - minMargin - Rect.width;
                    }
                }

                mPrevPointerPos = RB.PointerPos();
                mDragging       = true;
            }
            else
            {
                mDragging = false;
            }

            if (mExtended)
            {
                if (Rect.width < mExtendedRect.width)
                {
                    Rect.x--;
                    Rect.width += 2;
                }
            }
            else
            {
                if (Rect.width > mBaseRect.width)
                {
                    Rect.x++;
                    Rect.width -= 2;
                }
            }

            if (mLaser)
            {
                mLaserOffset -= 0.1f;
                if (mLaserOffset < 0)
                {
                    mLaserOffset = 0;
                }

                if (RB.ButtonPressed(RB.BTN_POINTER_A))
                {
                    Shoot();
                }
            }
            else
            {
                mLaserOffset += 0.1f;
                if (mLaserOffset > 1)
                {
                    mLaserOffset = 1;
                }
            }

            // Rest mPos after collision rect corrections
            mPos = new Vector2i((int)Rect.center.x, (int)Rect.center.y);
        }
예제 #10
0
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            var demo = (DemoReel)RB.Game;

            RB.Clear(DemoUtil.IndexToRGB(1));

            mFormatStr.Set("@C// Test gamepad input for two players\n");
            mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_A, @[email protected]_ONE) {\n");
            mFormatStr.Append("   @C// Handle button A down for player one\n@N");
            mFormatStr.Append("}\n");
            mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_LEFT, @[email protected]_TWO) {\n");
            mFormatStr.Append("   @C// Handle button LEFT transitioning from \"up\" to \"down\"\n@N");
            mFormatStr.Append("}\n");
            mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_MENU, @[email protected]_ANY) {\n");
            mFormatStr.Append("   @C// Handle button MENU transitioning from \"down\" to \"up\"\n@N");
            mFormatStr.Append("}");

            RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            DrawGamepad(260, 15, RB.PLAYER_ONE);
            DrawGamepad(400, 15, RB.PLAYER_TWO);
            DrawMouse(540, 8);

            RB.DrawLine(new Vector2i(16, 85), new Vector2i(RB.DisplaySize.width - 16, 85), DemoUtil.IndexToRGB(2));

            mFormatStr.Set("@C// Test keyboard input\n");
            mFormatStr.Append("@Kif @N(@[email protected](@[email protected])) {\n");
            mFormatStr.Append("   @C// Handle Left Shift down\n@N");
            mFormatStr.Append("}\n\n");
            mFormatStr.Append("@C// Retrieve the string of characters typed since last update\n");
            mFormatStr.Append("@Kstring@n userInput += @[email protected]();");

            RB.Print(new Vector2i(50, 92), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            mFormatStr.Set("@C// Get pointer position (mouse or touch)\n");
            mFormatStr.Append("@[email protected](@L4@N, @[email protected]());\n\n");
            mFormatStr.Append("@C// Test pointer button input\n");
            mFormatStr.Append("@Kif @N(@[email protected](@[email protected]_POINTER_A)) {\n");
            mFormatStr.Append("   @C// Handle Pointer Button A down\n@N");
            mFormatStr.Append("}\n");

            RB.Print(new Vector2i(350, 92), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            DrawKeyboard(mKeyboardOffset.x, mKeyboardOffset.y);
            DrawInputString(14, 155);

            mNextButton.Render();
            mPrevButton.Render();

            if (RB.PointerPosValid())
            {
                RB.DrawSprite(4, RB.PointerPos());
            }

            if (!UnityEngine.Input.mousePresent)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (RB.PointerPosValid(i))
                    {
                        RB.DrawEllipse(RB.PointerPos(i), new Vector2i(64, 64), mTouchColor[i]);
                    }
                }
            }
        }
예제 #11
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;
            }
        }
    }
예제 #12
0
        /// <summary>
        /// Update
        /// </summary>
        public override void Update()
        {
            var demo = (DemoReel)RB.Game;

            for (int i = mFadeSounds.Count - 1; i >= 0; i--)
            {
                var soundRef = mFadeSounds[i];
                RB.SoundVolumeSet(soundRef, RB.SoundVolumeGet(soundRef) * 0.75f);

                if (RB.SoundVolumeGet(soundRef) < 0.01f)
                {
                    mFadeSounds.RemoveAt(i);
                }
            }

            if (!RB.MusicIsPlaying())
            {
                mMusicTurnSpeed--;
                if (mMusicTurnSpeed < 0)
                {
                    mMusicTurnSpeed = 0;
                }
            }

            mMusicTicks += mMusicTurnSpeed;

            for (int i = 0; i < mPianoButtons.Length; i++)
            {
                mPianoButtons[i].Update();
                if (mPianoButtons[i].Pressed)
                {
                    break;
                }
            }

            for (int i = 0; i < mEffectButtons.Length; i++)
            {
                mEffectButtons[i].Update();
                if (mEffectButtons[i].Pressed)
                {
                    break;
                }
            }

            mMusicPlayButton.Update();
            mPositionalButton.Update();

            mNextButton.Update();
            mPrevButton.Update();

            int color = 1;

            if ((RB.Ticks % 200 > 170 && RB.Ticks % 200 < 180) || (RB.Ticks % 200) > 190)
            {
                color = 5;
            }

            mNextButton.LabelColor = color;
            mPrevButton.LabelColor = color;

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

            mListenerPos = new Vector2i(330 + (Mathf.Sin(mPositionalTicks / 50.0f) * 100), (RB.DisplaySize.height / 2) + 32);

            if (mPositionalPlaying)
            {
                mSoundPos = RB.PointerPos();
                RB.SoundPosSet(mPosSoundRef, mSoundPos);
            }

            RB.SoundListenerPosSet(mListenerPos);

            var positionalVol = RB.SoundVolumeGet(mPosSoundRef);

            // Change music volume to inverse of waterfall volume
            if (demo.IsMusicPlaying())
            {
                RB.MusicVolumeSet((1.0f - positionalVol) * demo.MusicVolume());
            }

            if (mPositionalPlaying)
            {
                mPositionalTicks++;

                positionalVol += 0.05f;
                if (positionalVol > 1)
                {
                    positionalVol = 1;
                }

                RB.SoundVolumeSet(mPosSoundRef, positionalVol);
            }
            else
            {
                positionalVol -= 0.05f;
                if (positionalVol < 0)
                {
                    positionalVol = 0;
                }

                RB.SoundVolumeSet(mPosSoundRef, positionalVol);
            }

            UpdateMusicButtonLabel();
            UpdatePositionalButtonLabel();
        }
예제 #13
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);
     }
 }
예제 #14
0
        /// <summary>
        /// Render the menu
        /// </summary>
        public void Render()
        {
            int      yOffset       = 0;
            int      optionSpacing = 10;
            int      borderSpacing = 8;
            Vector2i summarySize   = Vector2i.zero;

            Rect2i optionsRect = new Rect2i(RB.DisplaySize.width / 2, RB.DisplaySize.height / 2, mWidestOption + 48, mOptionCount * (optionSpacing + 1));

            if (mSummary.Length > 0)
            {
                summarySize         = RB.PrintMeasure(C.FONT_SMALL, new Rect2i(0, 0, optionsRect.width - (borderSpacing * 2), 9999), RB.ALIGN_H_CENTER | RB.TEXT_OVERFLOW_WRAP, mSummary);
                optionsRect.height += summarySize.height;
                optionsRect.height += borderSpacing * 2;
            }

            optionsRect.height += borderSpacing * 2;

            optionsRect.x -= optionsRect.width / 2;
            optionsRect.y -= optionsRect.height / 2;

            RB.DrawRectFill(optionsRect, C.COLOR_MENU_BACKGROUND);
            RB.DrawRect(optionsRect, Color.white);

            // Draw header
            var headerSize = RB.PrintMeasure(C.FONT_SMALL, mHeader);
            var headerRect = new Rect2i(optionsRect.x + (optionsRect.width / 2) - (headerSize.width / 2) - 16, optionsRect.y - 6, headerSize.width + 32, 12);

            RB.DrawRectFill(headerRect, C.COLOR_MENU_HEADER_BACKGROUND);
            RB.DrawRect(headerRect, Color.white);
            headerRect.y++;
            RB.Print(C.FONT_SMALL, headerRect, Color.white, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mHeader);

            yOffset += borderSpacing;

            if (mSummary.Length > 0)
            {
                yOffset += borderSpacing;

                var summaryRect = new Rect2i(optionsRect.x + borderSpacing, optionsRect.y + yOffset, optionsRect.width - (borderSpacing * 2), 9999);

                RB.Print(C.FONT_SMALL, summaryRect, Color.gray, RB.ALIGN_H_CENTER | RB.TEXT_OVERFLOW_WRAP, mSummary);

                yOffset += summarySize.height + borderSpacing;
            }

            char shortCut = 'a';

            int oldPointerIndex = mPointerIndex;

            mPointerIndex = -1;

            for (int i = 0; i < mOptionCount; i++)
            {
                var optionColor = Color.white;
                var optionRect  = new Rect2i(optionsRect.x + borderSpacing, optionsRect.y + yOffset, optionsRect.width - (borderSpacing * 2), optionSpacing);
                if (optionRect.Contains(RB.PointerPos()))
                {
                    optionColor   = Color.yellow;
                    mPointerIndex = i;
                }

                RB.Print(
                    C.FONT_SMALL,
                    optionRect,
                    optionColor,
                    RB.ALIGN_V_CENTER,
                    C.FSTR.Set("@AAAAAA").Append(shortCut).Append(".@- ").Append(mOptions[i].text));

                yOffset += optionSpacing + 1;
                shortCut++;
            }

            if (oldPointerIndex != mPointerIndex && mPointerIndex >= 0)
            {
                RB.SoundPlay(C.SOUND_POINTER_SELECT, 0.35f, RandomUtils.RandomPitch(0.1f));
            }
        }