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); }
public static UIManager confirmDialog(double x, double y, BlitRect panel, Action okayCallback, BlitRect okayBlit, BlitRect cancelBlit, Action cancelCallback = null, Action selectSoundCallback = null) { dialog = new UIManager(); dialog.selectSoundCallback = selectSoundCallback; cancelCallback = cancelCallback ?? closeDialog; int i; Point point; BlitRect blit; Action f; var buttonPoints = new Array <Point> { new Point(x, y), new Point(x + 3, y + 3), new Point(x + okayBlit.width + 4, y + 3) }; var buttonBlits = new Array <BlitRect> { panel, okayBlit, cancelBlit }; var buttonCallbacks = new Array <Action> { null, okayCallback, cancelCallback }; for (i = 0; i < buttonPoints.length; i++) { point = buttonPoints[i]; blit = buttonBlits[i]; f = buttonCallbacks[i]; dialog.addButton(point.x, point.y, blit, f, null, f != null); } return(dialog); }
public static UIManager openDialog(Array <Point> buttonPoints, Array <BlitRect> buttonBlits, Array <Action> buttonCallbacks, Action selectSoundCallback) { dialog = new UIManager(); dialog.selectSoundCallback = selectSoundCallback; int i; Point point; BlitRect blit; Action f; for (i = 0; i < buttonPoints.length; i++) { point = buttonPoints[i]; blit = buttonBlits[i]; f = buttonCallbacks[i]; dialog.addButton(point.x, point.y, blit, f, null, f != null); } return(dialog); }