Example #1
0
        private void propertyHeldCallback()
        {
            int        dir;
            int        mask   = 0;
            int        amount = 0;
            BlitButton button;

            button = uiManager.lastButton;
            if (button == turnerButton)
            {
                mask   = Room.UP_DOWN_LEFT_RIGHT;
                amount = -1;
            }
            else if (button == generatorButton)
            {
                mask   = Room.TIMER_0 | Room.TIMER_1 | Room.TIMER_2 | Room.TIMER_3;
                amount = 1;
            }
            button.id    = Room.rotateBits(button.id, amount, mask, 4);
            button.blit  = game.level.getPropertyBlit(button.id);
            button.frame = button.blit is BlitClip ? (button.blit as BlitClip).frame : 0;
            if (button.active)
            {
                property &= ~mask;
                property |= button.id;
            }
        }
Example #2
0
        public BlitButton addButton(double x, double y, BlitRect blit, Action callback = null, Rectangle area = null, Boolean states = true)
        {
            var button = new BlitButton(x, y, blit, callback, area, states);

            buttons.push(button);
            return(button);
        }
Example #3
0
        public TitleMenu()
        {
            uiManager = new UIManager();
            uiManager.selectSoundCallback = game.selectSound;
            levelButtonRect = new Rectangle(0, 0, renderer.numberButtonBlit.width - 1, renderer.numberButtonBlit.height - 1);

            mapCopyBuffer = Room.create2DArray(Level.ROOM_WIDTH, Level.ROOM_HEIGHT);

            // puzzle, adventure, editor
            puzzleButton    = uiManager.addButton(Game.WIDTH * 0.5 - renderer.puzzleButtonBlit.width * 2, Game.HEIGHT * 0.5 - renderer.puzzleButtonBlit.height * 0.5, renderer.puzzleButtonBlit, puzzlePressed);
            adventureButton = uiManager.addButton(Game.WIDTH * 0.5 - renderer.adventureButtonBlit.width * 0.5, Game.HEIGHT * 0.5 - renderer.adventureButtonBlit.height * 0.5, renderer.adventureButtonBlit, adventurePressed);
            editorButton    = uiManager.addButton(Game.WIDTH * 0.5 + renderer.editorButtonBlit.width, Game.HEIGHT * 0.5 - renderer.editorButtonBlit.height * 0.5, renderer.editorButtonBlit, puzzlePressed);

            // level button grid
            uiManager.addGroup();
            uiManager.changeGroup(1);
            levelButtons = new Array <BlitButton>();
            double     buttonX = Game.WIDTH * 0.5 - ((LEVEL_BUTTONS_WIDE - 1) * LEVEL_BUTTON_GAP + levelButtonRect.width * LEVEL_BUTTONS_WIDE) * 0.5;
            double     buttonY = Game.HEIGHT * 0.5 - ((LEVEL_BUTTONS_HIGH - 1) * LEVEL_BUTTON_GAP + levelButtonRect.height * LEVEL_BUTTONS_HIGH) * 0.5;
            BlitButton levelButton;

            for (r = 0; r < LEVEL_BUTTONS_HIGH; r++)
            {
                for (c = 0; c < LEVEL_BUTTONS_WIDE; c++)
                {
                    levelButton = uiManager.addButton(
                        buttonX + c * (levelButtonRect.width + LEVEL_BUTTON_GAP),
                        buttonY + r * (levelButtonRect.height + LEVEL_BUTTON_GAP),
                        renderer.numberButtonBlit, levelPressed, levelButtonRect
                        );
                    levelButton.releaseCallback = levelReleased;
                    levelButton.id       = c + r * LEVEL_BUTTONS_WIDE;
                    levelButton.targetId = 1;
                    levelButtons.push(levelButton);
                }
            }
            int border     = 2;
            var buttonRect = new Rectangle(0, 0, renderer.cancelButtonBlit.width, renderer.cancelButtonBlit.height);

            leftButton         = uiManager.addButton(Game.WIDTH * 0.5 - 3 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.leftButtonBlit, directionPressed, buttonRect);
            leftButton.visible = false;
            backButton         = uiManager.addButton(Game.WIDTH * 0.5 - 1 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.cancelButtonBlit, backPressed, buttonRect);
            rightButton        = uiManager.addButton(Game.WIDTH * 0.5 + 1 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.rightButtonBlit, directionPressed, buttonRect);
            if (!Game.MOBILE)
            {
                loadFromDesktopButton = uiManager.addButton(Game.WIDTH * 0.5 - 5 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.loadButtonBlit, loadFromDesktop, buttonRect);
                loadFromDesktopButton.feedCallbackToEvent = true;
                saveToDesktopButton = uiManager.addButton(Game.WIDTH * 0.5 + 3 * Game.SCALE + border, Game.HEIGHT - Game.SCALE * 2 + border, renderer.saveButtonBlit, saveToDesktop, buttonRect);
                saveToDesktopButton.feedCallbackToEvent = true;
            }
            scoreTextBox       = new TextBox(Game.WIDTH, 8, 0x0, 0x0);
            scoreTextBox.align = "center";
            if (UserData.settings.best != null)
            {
                setScore((int)UserData.settings.best);
            }
            uiManager.changeGroup(0);
        }
Example #4
0
 private void clearProperty()
 {
     property = 0;
     for (i = 0; i < properties.length; i++)
     {
         button        = properties[i];
         button.active = false;
     }
 }
Example #5
0
 public void render(BitmapData bitmapData)
 {
     for (i = 0; i < buttons.length; i++)
     {
         button = buttons[i];
         if (button.visible)
         {
             button.render(bitmapData);
         }
     }
 }
Example #6
0
        public void render()
        {
            BlitRect blit;

            if (uiManager.currentGroup == 1)
            {
                //renderer.guiBitmapData.copyPixels(renderer.darkBitmapData, renderer.darkBitmapData.rect, new Point(), null, null, true);
                renderer.guiBitmapData.fillRect(renderer.darkBitmapData.rect, renderer.darkBitmapDataColor);
            }
            uiManager.render(renderer.guiBitmapData);
            if (uiManager.currentGroup == 0)
            {
                for (i = 0; i < properties.length; i++)
                {
                    button = properties[i];
                    if (button.active)
                    {
                        renderer.propertySelectedBlit.x = (int)button.x;
                        renderer.propertySelectedBlit.y = (int)button.y;
                        renderer.propertySelectedBlit.render(renderer.guiBitmapData);
                        button.render(renderer.guiBitmapData);
                    }
                }
                if (property > 0)
                {
                    game.level.renderProperty(propertyButton.x + 2, propertyButton.y + 2, property, renderer.guiBitmapData, false);
                }
                if (renderer.camera.dragScroll)
                {
                    renderer.lockedBlit.x = (int)propertyButton.x + 2;
                    renderer.lockedBlit.y = (int)propertyButton.y + 2;
                    renderer.lockedBlit.render(renderer.guiBitmapData);
                }
                if (generatorButton.over)
                {
                    renderer.timerCountBlit.x = (int)generatorButton.x - 0;
                    renderer.timerCountBlit.y = (int)generatorButton.y - 0;
                    renderer.timerCountBlit.render(renderer.guiBitmapData, getTimerFrame(generatorButton.id));
                    if (generatorButton.held && ((property & Room.GENERATOR) == Room.GENERATOR))
                    {
                        renderer.timerCountBlit.x = (int)propertyButton.x + 2;
                        renderer.timerCountBlit.y = (int)propertyButton.y + 2;
                        renderer.timerCountBlit.render(renderer.guiBitmapData, getTimerFrame(property));
                    }
                }
            }
            if (UIManager.dialog != null)
            {
                UIManager.dialog.render(renderer.guiBitmapData);
            }
        }
Example #7
0
 private void levelPressed()
 {
     if (!game.editing)
     {
         int    n   = uiManager.lastButton.id + firstLevel;
         String str = (n < 10 ? "0" : "") + n;
         game.setNextGame(Room.PUZZLE, n);
         game.transition.begin(game.initLevel, Transition.DEFAULT_TRANSITION_TICKS, Transition.DEFAULT_TRANSITION_TICKS, str, 15);
     }
     else
     {
         buttonInHand = uiManager.lastButton;
         sourceId     = buttonInHand.id + firstLevel;
         sourceLevel  = Library.levels[sourceId];
         targetLevel  = null;
         prevButtonX  = uiManager.lastButton.x;
         prevButtonY  = uiManager.lastButton.y;
     }
 }
Example #8
0
        private void togglePaletteSide(Boolean saveSettings)
        {
            int        i;
            BlitButton button;
            double     step = Game.WIDTH - Game.SCALE * 4;

            paletteRight = !paletteRight;
            if (!paletteRight)
            {
                step = -step;
            }
            for (i = 0; i < paletteButtons.length; i++)
            {
                button    = paletteButtons[i];
                button.x += step;
            }
            UserData.settings.paletteRight = paletteRight;
            if (saveSettings)
            {
                UserData.push(true);
            }
        }
Example #9
0
        private void propertySelect()
        {
            int id;
            int cancels;

            button = uiManager.lastButton;
            if (button == playerButton)
            {
                pressPlayer();
            }
            var active = !button.active;

            cancels = button.targetId;
            //if(!button.active) cancels = button.id | cancels;
            property = 0;

            for (i = 0; i < properties.length; i++)
            {
                button = properties[i];
                if (cancels > 0 & button.id > 0)
                {
                    button.active = false;
                    continue;
                }
                if (button.active)
                {
                    property |= button.id;
                }
            }

            if (active)
            {
                property |= uiManager.lastButton.id;
                uiManager.lastButton.active = true;
            }
            propertyLegal = ((property & (Room.WALL | Room.ENEMY | Room.ALLY)) > 0) || property == 0;
        }
Example #10
0
 private void levelReleased()
 {
     if (buttonInHand != null)
     {
         buttonInHand.x = prevButtonX;
         buttonInHand.y = prevButtonY;
         int        i;
         BlitButton overButton;
         int        x = (int)(Game.WIDTH * 0.5 - renderer.levelMovePanelBlit.width * 0.5);
         int        y = (int)(Game.HEIGHT * 0.5 - renderer.levelMovePanelBlit.height * 0.5);
         for (i = 0; i < uiManager.buttonsOver.length; i++)
         {
             overButton = uiManager.buttonsOver[i];
             if (overButton != buttonInHand)
             {
                 if (overButton.targetId > 0)
                 {
                     int step = renderer.cancelButtonBlit.width + 1;
                     UIManager.openDialog(
                         new Array <Point> {
                         new Point(x, y),
                         new Point(x + 3, y + 3),
                         new Point(x + 3 + (step * 1), y + 3),
                         new Point(x + 3 + (step * 2), y + 3),
                         new Point(x + 3 + (step * 3), y + 3),
                         new Point(x + 3 + (step * 4), y + 3)
                     },
                         new Array <BlitRect> {
                         renderer.levelMovePanelBlit,
                         renderer.cancelButtonBlit,
                         renderer.insertBeforeButtonBlit,
                         renderer.insertAfterButtonBlit,
                         renderer.swapButtonBlit,
                         renderer.saveButtonBlit
                     },
                         new Array <Action> {
                         null,
                         UIManager.closeDialog,
                         insertBefore,
                         insertAfter,
                         swapLevels,
                         writeSourceToTarget
                     },
                         game.selectSound
                         );
                     // swap init
                     targetId                     = firstLevel + overButton.id;
                     targetLevel                  = Library.levels[targetId];
                     overButton.over              = false;
                     buttonInHand.over            = false;
                     buttonInHand                 = null;
                     uiManager.buttonsOver.length = 0;
                     return;
                 }
                 else
                 {
                     if (overButton == backButton)
                     {
                         confirmDialog(deleteLevelDialog);
                     }
                     else if (overButton == rightButton)
                     {
                         targetId = sourceId + PAGE_LEVELS;
                         insertAfter();
                     }
                     else if (overButton == leftButton)
                     {
                         targetId = sourceId - PAGE_LEVELS;
                         insertBefore();
                     }
                 }
             }
         }
         buttonInHand = null;
     }
     if (game.editing && uiManager.lastButton.heldCount > 0)
     {
         int    n   = uiManager.lastButton.id + firstLevel;
         String str = (n < 10 ? "0" : "") + n;
         game.setNextGame(Room.PUZZLE, n);
         game.transition.begin(game.initLevel, Transition.DEFAULT_TRANSITION_TICKS, Transition.DEFAULT_TRANSITION_TICKS, str, 30);
     }
 }
Example #11
0
        public RoomPalette(Level level)
        {
            uiManager = new UIManager();
            uiManager.selectSoundCallback = game.selectSound;

            // PALETTE
            paletteRight = UserData.settings.paletteLeft;
            back         = uiManager.addButton(0, Game.SCALE + ((int)(Game.HEIGHT * 0.5 - renderer.roomPaletteBlit.height * 0.5) >> 0), renderer.roomPaletteBlit, null, new Rectangle(0, 0, Game.SCALE * 4, Game.SCALE * 8));
            // properties
            propertyLegal = true;
            properties    = new Array <BlitButton>();
            int generator     = Room.GENERATOR | Room.TIMER_0;
            int allyCancel    = Room.INDESTRUCTIBLE | Room.ALLY | Room.ENEMY | Room.WALL | generator | Room.UP_DOWN_LEFT_RIGHT | Room.M_UP_DOWN_LEFT_RIGHT;
            int enemyCancel   = Room.INDESTRUCTIBLE | Room.ALLY | Room.SWAP | Room.ENEMY | Room.UP_DOWN_LEFT_RIGHT | Room.M_UP_DOWN_LEFT_RIGHT;
            int nonTrapCancel = Room.INDESTRUCTIBLE | Room.ALLY | Room.TURNER | Room.MOVER | Room.VIRUS;

            addPropertyButton(Game.SCALE * 0, Game.SCALE * 0, Room.INDESTRUCTIBLE | Room.WALL, -1, true);
            playerButton = addPropertyButton(Game.SCALE * 1, Game.SCALE * 0, Room.PLAYER | Room.ALLY, allyCancel | Room.BOMB, true);
            addPropertyButton(Game.SCALE * 2, Game.SCALE * 0, Room.ALLY | Room.SWAP, allyCancel, true);
            addPropertyButton(Game.SCALE * 3, Game.SCALE * 0, Room.WALL | Room.SWAP, allyCancel, true);
            addPropertyButton(Game.SCALE * 0, Game.SCALE * 1, Room.WALL, Room.ALLY | Room.SWAP | Room.WALL, true);
            addPropertyButton(Game.SCALE * 1, Game.SCALE * 1, Room.BOMB, Room.PLAYER | Room.INDESTRUCTIBLE | Room.BOMB, true);
            generatorButton = addPropertyButton(Game.SCALE * 2, Game.SCALE * 1, generator, Room.ALLY | Room.INDESTRUCTIBLE | generator | Room.SWAP, true);
            generatorButton.heldCallback = propertyHeldCallback;
            addPropertyButton(Game.SCALE * 3, Game.SCALE * 1, Room.ENEMY | Room.VIRUS, enemyCancel, true);
            turnerButton = addPropertyButton(Game.SCALE * 0, Game.SCALE * 2, Room.ENEMY | Room.TURNER | Room.UP, enemyCancel, true);
            turnerButton.heldCallback = propertyHeldCallback;
            addPropertyButton(Game.SCALE * 1, Game.SCALE * 2, Room.ENEMY | Room.MOVER | Room.M_LEFT | Room.M_RIGHT, enemyCancel, true);
            addPropertyButton(Game.SCALE * 2, Game.SCALE * 2, Room.ENEMY | Room.MOVER | Room.M_UP | Room.M_DOWN, enemyCancel, true);
            addPropertyButton(Game.SCALE * 3, Game.SCALE * 2, Room.ENEMY | Room.MOVER | Room.M_UP_DOWN_LEFT_RIGHT, enemyCancel, true);
            addPropertyButton(Game.SCALE * 0, Game.SCALE * 3, Room.ENEMY | Room.TRAP | Room.M_UP, nonTrapCancel | Room.M_UP, true);
            addPropertyButton(Game.SCALE * 1, Game.SCALE * 3, Room.ENEMY | Room.TRAP | Room.M_RIGHT, nonTrapCancel | Room.M_RIGHT, true);
            addPropertyButton(Game.SCALE * 2, Game.SCALE * 3, Room.ENEMY | Room.TRAP | Room.M_DOWN, nonTrapCancel | Room.M_DOWN, true);
            addPropertyButton(Game.SCALE * 3, Game.SCALE * 3, Room.ENEMY | Room.TRAP | Room.M_LEFT, nonTrapCancel | Room.M_LEFT, true);

            var buttonRect = new Rectangle(0, 0, renderer.propertyButtonBlit.width, renderer.propertyButtonBlit.height);
            var border     = 2;

            propertyButton = uiManager.addButton(2 * Game.SCALE + border, back.y + 4 * Game.SCALE + border, renderer.propertyButtonBlit, clearProperty, buttonRect);
            playButton     = uiManager.addButton(0 * Game.SCALE + border, back.y + 6 * Game.SCALE + border, renderer.playButtonBlit, playRoom, buttonRect);
            uiManager.addButton(2 * Game.SCALE + border, back.y + 6 * Game.SCALE + border, renderer.swapButtonBlit, togglePaletteSide, buttonRect);
            scrollButton        = uiManager.addButton(0 * Game.SCALE + border, back.y + 4 * Game.SCALE + border, renderer.scrollButtonBlit, toggleScroll, buttonRect);
            scrollButton.active = !renderer.camera.dragScroll;
            paletteButtons      = uiManager.buttons.slice();
            if (paletteRight)
            {
                togglePaletteSide(false);
            }

            optionsButton = uiManager.addButton(Game.WIDTH - renderer.settingsButtonBlit.width, 0, renderer.settingsButtonBlit, options);

            // OPTIONS
            uiManager.addGroup();
            uiManager.changeGroup(1);
            uiManager.addButton(Game.WIDTH - renderer.settingsButtonBlit.width, 0, renderer.settingsButtonBlit, cancel);
            var    buttonXs = UIManager.distributeRects(Game.WIDTH * 0.5, buttonRect.width, 4, 4);
            var    buttonYs = UIManager.distributeRects(Game.HEIGHT * 0.5, buttonRect.height, 4, 2);
            double buttonY;            // = Game.HEIGHT * 0.5 - Game.SCALE + border;

            buttonY = buttonYs[0];
            uiManager.addButton(buttonXs[0], buttonY, renderer.cancelButtonBlit, quit, buttonRect);
            uiManager.addButton(buttonXs[1], buttonY, renderer.loadButtonBlit, load, buttonRect);
            uiManager.addButton(buttonXs[2], buttonY, renderer.saveButtonBlit, save, buttonRect);
            checkButton        = uiManager.addButton(buttonXs[3], buttonY, renderer.checkButtonBlit, level.toggleCheckView, buttonRect);
            checkButton.active = level.checkView;

            // mobile buttons
            buttonY               = buttonYs[1];
            buttonXs              = UIManager.distributeRects(Game.WIDTH * 0.5, buttonRect.width, 4, 2);
            controlsButton        = uiManager.addButton(buttonXs[0], buttonY, renderer.controlsButtonBlit, level.toggleControls, buttonRect);
            controlsButton.active = level.tapControls;
            orientationButton     = uiManager.addButton(buttonXs[1], buttonY, renderer.orientationButtonBlit, game.toggleOrientation, buttonRect);
            // desktop buttons
            soundButton             = uiManager.addButton(buttonXs[0], buttonY, renderer.soundButtonBlit, level.toggleSound, buttonRect);
            soundButton.active      = level.soundButton.active;
            fullscreenButton        = uiManager.addButton(buttonXs[1], buttonY, renderer.fullscreenButtonBlit, level.toggleFullscreen, buttonRect);
            fullscreenButton.active = level.fullscreenButton.active;
            fullscreenButton.feedCallbackToEvent = true;
            if (!Game.MOBILE)
            {
                controlsButton.visible    = false;
                orientationButton.visible = false;
            }
            else
            {
                soundButton.visible      = false;
                fullscreenButton.visible = false;
            }
            uiManager.changeGroup(0);
        }
Example #12
0
 public void update(double mouseX, double mouseY, Boolean mousePressed, Boolean mouseClick, Boolean mouseReleased = false)
 {
     buttonsOver.length = 0;
     if (!mousePressed)
     {
         mouseLock = false;
         ignore    = false;
     }
     else
     {
         if (ignore)
         {
             return;
         }
     }
     mouseOver = false;
     button    = buttons[0];
     for (i = buttons.length - 1; i > -1; i--)
     {
         button = buttons[i];
         if (
             button.visible &&
             mouseX >= button.x + button.area.x &&
             mouseY >= button.y + button.area.y &&
             mouseX < button.x + button.area.x + button.area.width &&
             mouseY < button.y + button.area.y + button.area.height
             )
         {
             button.over = Game.MOBILE ? (mousePressed || mouseReleased) : true;
             if (button.over)
             {
                 mouseOver = true;
                 if (button == lastButton)
                 {
                     buttonsOver.unshift(button);
                 }
                 else
                 {
                     buttonsOver.push(button);
                 }
             }
             if (mouseClick)
             {
                 lastButton = button;
                 if (button.callback != null)
                 {
                     if (button.feedCallbackToEvent)
                     {
                         mousePressedCallback = button.callback;
                     }
                     else
                     {
                         button.callback();
                         if ((selectSoundCallback != null) && !button.silent)
                         {
                             selectSoundCallback();
                         }
                     }
                 }
                 mouseLock        = true;
                 button.heldCount = BlitButton.HELD_DELAY;
                 break;
             }
             else if (mousePressed)
             {
                 if (button == lastButton)
                 {
                     if (button.heldCount > 0)
                     {
                         button.heldCount--;
                     }
                     else
                     {
                         button.held = true;
                         if (button.heldCallback != null)
                         {
                             button.heldCount = BlitButton.HELD_DELAY;
                             button.heldCallback();
                         }
                     }
                 }
                 else
                 {
                     if (!button.focusLock)
                     {
                         lastButton = button;
                         if (button.callback != null)
                         {
                             button.callback();
                             if (selectSoundCallback != null && !button.silent)
                             {
                                 selectSoundCallback();
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             if (button.over)
             {
                 button.over = false;
                 button.held = false;
             }
         }
     }
     if (mouseReleased)
     {
         if (lastButton != null && lastButton.over && lastButton.releaseCallback != null)
         {
             lastButton.releaseCallback();
             lastButton.over = false;
         }
     }
     if (mouseClick && !mouseOver)
     {
         ignore = true;
     }
 }
Example #13
0
 public void addExistingButton(BlitButton button)
 {
     buttons.push(button);
 }