private void puzzlePressed() { game.editing = uiManager.lastButton == editorButton; if (game.editing) { Library.setLevels(false); if (loadFromDesktopButton != null) { loadFromDesktopButton.visible = true; } if (saveToDesktopButton != null) { saveToDesktopButton.visible = true; } } else { Library.setLevels(true); if (loadFromDesktopButton != null) { loadFromDesktopButton.visible = false; } if (saveToDesktopButton != null) { saveToDesktopButton.visible = false; } } // restore puzzle progress from app exit if available if (!game.editing && UserData.settings.puzzleData != null) { int n = UserData.settings.puzzleLevel; 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 { if (firstLevel > Library.maxLevel) { firstLevel = 0; } if (firstLevel == 0) { leftButton.visible = false; } else { leftButton.visible = true; } if (firstLevel < Library.maxLevel - PAGE_LEVELS) { rightButton.visible = true; } else { rightButton.visible = false; } uiManager.changeGroup(PUZZLE_LEVELS); } }
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); }