void initializeButtonState(buttonState *state, brogueButton *buttons, short buttonCount, short winX, short winY, short winWidth, short winHeight) { short i, j; // Initialize variables for the state struct: state->buttonChosen = state->buttonFocused = state->buttonDepressed = -1; state->buttonCount = buttonCount; state->winX = winX; state->winY = winY; state->winWidth = winWidth; state->winHeight = winHeight; for (i=0; i < state->buttonCount; i++) { state->buttons[i] = buttons[i]; } copyDisplayBuffer(state->rbuf, displayBuffer); clearDisplayBuffer(state->dbuf); drawButtonsInState(state); // Clear the rbuf so that it resets only those parts of the screen in which buttons are drawn in the first place: for (i=0; i<COLS; i++) { for (j=0; j<ROWS; j++) { state->rbuf[i][j].opacity = (state->dbuf[i][j].opacity ? 100 : 0); } } }
void titleMenu() { signed short flames[COLS][(ROWS + MENU_FLAME_ROW_PADDING)][3]; // red, green and blue signed short colorSources[MENU_FLAME_COLOR_SOURCE_COUNT][4]; // red, green, blue, and rand, one for each color source (no more than MENU_FLAME_COLOR_SOURCE_COUNT). color *colors[COLS][(ROWS + MENU_FLAME_ROW_PADDING)]; unsigned char mask[COLS][ROWS]; boolean controlKeyWasDown = false; short i, b, x, y, button; buttonState state; brogueButton buttons[6]; char whiteColorEscape[10] = ""; char goldColorEscape[10] = ""; char newGameText[100] = "", customNewGameText[100] = ""; rogueEvent theEvent; enum NGCommands buttonCommands[6] = {NG_NEW_GAME, NG_OPEN_GAME, NG_VIEW_RECORDING, NG_HIGH_SCORES, NG_QUIT}; cellDisplayBuffer shadowBuf[COLS][ROWS]; // Initialize the RNG so the flames aren't always the same. seedRandomGenerator(0); // Empty nextGamePath and nextGameSeed so that the buttons don't try to load an old game path or seed. rogue.nextGamePath[0] = '\0'; rogue.nextGameSeed = 0; // Initialize the title menu buttons. encodeMessageColor(whiteColorEscape, 0, &white); encodeMessageColor(goldColorEscape, 0, KEYBOARD_LABELS ? &itemMessageColor : &white); sprintf(newGameText, " %sN%sew Game ", goldColorEscape, whiteColorEscape); sprintf(customNewGameText, " %sN%sew Game (custom) ", goldColorEscape, whiteColorEscape); b = 0; button = -1; initializeButton(&(buttons[b])); strcpy(buttons[b].text, newGameText); buttons[b].hotkey[0] = 'n'; buttons[b].hotkey[1] = 'N'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %sO%spen Game ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'o'; buttons[b].hotkey[1] = 'O'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %sV%siew Recording ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'v'; buttons[b].hotkey[1] = 'V'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %sH%sigh Scores ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'h'; buttons[b].hotkey[1] = 'H'; b++; // Seth: /* initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %sQ%suit ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'q'; buttons[b].hotkey[1] = 'Q'; b++;*/ x = COLS - 1 - 20 - 2; y = ROWS - 1; for (i = b-1; i >= 0; i--) { y -= 2; buttons[i].x = x; buttons[i].y = y; buttons[i].buttonColor = titleButtonColor; buttons[i].flags |= B_WIDE_CLICK_AREA; } blackOutScreen(); clearDisplayBuffer(shadowBuf); initializeButtonState(&state, buttons, b, x, y, 20, b*2-1); rectangularShading(x, y, 20, b*2-1, &black, INTERFACE_OPACITY, shadowBuf); drawButtonsInState(&state); initializeMenuFlames(true, colors, colorSources, flames, mask); rogue.creaturesWillFlashThisTurn = false; // total unconscionable hack do { if (!controlKeyWasDown && controlKeyIsDown()) { strcpy(state.buttons[0].text, customNewGameText); drawButtonsInState(&state); buttonCommands[0] = NG_NEW_GAME_WITH_SEED; controlKeyWasDown = true; } else if (controlKeyWasDown && !controlKeyIsDown()) { strcpy(state.buttons[0].text, newGameText); drawButtonsInState(&state); buttonCommands[0] = NG_NEW_GAME; controlKeyWasDown = false; } // Update the display. updateMenuFlames(colors, colorSources, flames); drawMenuFlames(flames, mask); overlayDisplayBuffer(shadowBuf, NULL); overlayDisplayBuffer(state.dbuf, NULL); // Pause briefly. if (pauseBrogue(MENU_FLAME_UPDATE_DELAY)) { // There was input during the pause! Get the input. nextBrogueEvent(&theEvent, true, false, true); // Process the input. button = processButtonInput(&state, NULL, &theEvent); } // Revert the display. overlayDisplayBuffer(state.rbuf, NULL); } while (button == -1 && rogue.nextGame == NG_NOTHING); drawMenuFlames(flames, mask); if (button != -1) { rogue.nextGame = buttonCommands[button]; } }
void titleMenu() { signed short flames[COLS][(ROWS + MENU_FLAME_ROW_PADDING)][3]; // red, green and blue signed short colorSources[MENU_FLAME_COLOR_SOURCE_COUNT][4]; // red, green, blue, and rand, one for each color source (no more than MENU_FLAME_COLOR_SOURCE_COUNT). color *colors[COLS][(ROWS + MENU_FLAME_ROW_PADDING)]; unsigned char mask[COLS][ROWS]; boolean controlKeyWasDown = false; short i, b, x, y, button; buttonState state; brogueButton buttons[6]; char whiteColorEscape[10] = ""; char goldColorEscape[10] = ""; char newGameText[100] = "", customNewGameText[100] = ""; rogueEvent theEvent; enum NGCommands buttonCommands[6] = {NG_NEW_GAME, NG_OPEN_GAME, NG_VIEW_RECORDING, NG_HIGH_SCORES, NG_QUIT}; BROGUE_WINDOW *root, *window, *title_window, *button_window; BROGUE_DRAW_CONTEXT *context, *title_context, *button_context; BROGUE_EFFECT *button_effect; BROGUE_GRAPHIC *title_graphic; // Initialize the RNG so the flames aren't always the same. seedRandomGenerator(0); // Empty nextGamePath and nextGameSeed so that the buttons don't try to load an old game path or seed. rogue.nextGamePath[0] = '\0'; rogue.nextGameSeed = 0; // Initialize the title menu buttons. encodeMessageColor(whiteColorEscape, 0, &white); encodeMessageColor(goldColorEscape, 0, &itemMessageColor); sprintf(newGameText, " %s(N)%s 开始新游戏", goldColorEscape, whiteColorEscape); sprintf(customNewGameText, " %s(N)%s 生成新游戏", goldColorEscape, whiteColorEscape); b = 0; button = -1; initializeButton(&(buttons[b])); strcpy(buttons[b].text, newGameText); buttons[b].hotkey[0] = 'n'; buttons[b].hotkey[1] = 'N'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %s(O)%s 读取存档 ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'o'; buttons[b].hotkey[1] = 'O'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %s(V)%s 观看录像 ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'v'; buttons[b].hotkey[1] = 'V'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %s(H)%s 最高分 ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'h'; buttons[b].hotkey[1] = 'H'; b++; initializeButton(&(buttons[b])); sprintf(buttons[b].text, " %s(Q)%s 退出游戏 ", goldColorEscape, whiteColorEscape); buttons[b].hotkey[0] = 'q'; buttons[b].hotkey[1] = 'Q'; b++; x = COLS - 1 - 20 - 2; y = ROWS - 3; for (i = b-1; i >= 0; i--) { y -= 2; buttons[i].x = 1; buttons[i].y = 1 + 2 * i; buttons[i].buttonColor = interfaceButtonColor; buttons[i].flags |= B_WIDE_CLICK_AREA; } title_graphic = BrogueGraphic_open("svg/title.svg"); root = ioGetRoot(); window = BrogueWindow_open(root, 0, 0, COLS, ROWS); context = BrogueDrawContext_open(window); title_window = BrogueWindow_open(window, 0, 0, COLS, ROWS); title_context = BrogueDrawContext_open(title_window); if (title_graphic != NULL) { BrogueDrawContext_drawGraphic(title_context, 0, 0, COLS, ROWS, title_graphic); } button_window = BrogueWindow_open(window, x, y, 22, b * 2 + 1); BrogueWindow_setColor(button_window, windowColor); button_context = BrogueDrawContext_open(button_window); button_effect = BrogueEffect_open(button_context, BUTTON_EFFECT_NAME); blackOutScreen(); initializeButtonState(&state, buttons, b, button_context, button_effect, x, y, 20, b*2-1); drawButtonsInState(button_context, button_effect, &state); initializeMenuFlames(true, colors, colorSources, flames, mask); rogue.creaturesWillFlashThisTurn = false; // total unconscionable hack do { if (!controlKeyWasDown && controlKeyIsDown()) { strcpy(state.buttons[0].text, customNewGameText); drawButtonsInState(button_context, button_effect, &state); buttonCommands[0] = NG_NEW_GAME_WITH_SEED; controlKeyWasDown = true; } else if (controlKeyWasDown && !controlKeyIsDown()) { strcpy(state.buttons[0].text, newGameText); drawButtonsInState(button_context, button_effect, &state); buttonCommands[0] = NG_NEW_GAME; controlKeyWasDown = false; } // Update the display. updateMenuFlames(colors, colorSources, flames); drawMenuFlames(context, flames); // Pause briefly. if (pauseBrogue(MENU_FLAME_UPDATE_DELAY)) { // There was input during the pause! Get the input. nextBrogueEvent(&theEvent, true, false, true); // Process the input. button = processButtonInput(button_context, button_effect, &state, NULL, &theEvent); } } while (button == -1 && rogue.nextGame == NG_NOTHING); drawMenuFlames(context, flames); if (button != -1) { rogue.nextGame = buttonCommands[button]; } BrogueWindow_close(window); BrogueGraphic_close(title_graphic); }