From: Holger Schemel Date: Sat, 9 Apr 2016 00:28:51 +0000 (+0200) Subject: cleanup of setting/resetting game status to control text font usage X-Git-Tag: 4.0.0.0-rc1~10 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=bc6e19a34de8c4c290dc3c6bee70ac805525070b;p=rocksndiamonds.git cleanup of setting/resetting game status to control text font usage --- diff --git a/src/editor.c b/src/editor.c index 6682acf0..862a1866 100644 --- a/src/editor.c +++ b/src/editor.c @@ -6403,10 +6403,8 @@ static void CreateRadiobuttonGadgets() void CreateLevelEditorGadgets() { - int old_game_status = game_status; - - /* setting 'game_status' is needed to get the right fonts for the editor */ - SetGameStatus(GAME_MODE_EDITOR); + /* force EDITOR font inside level editor */ + SetFontStatus(GAME_MODE_EDITOR); /* these values are not constant, but can change at runtime */ ed_fieldx = MAX_ED_FIELDX - 1; @@ -6440,7 +6438,7 @@ void CreateLevelEditorGadgets() CreateTextbuttonGadgets(); CreateDrawingAreas(); - SetGameStatus(old_game_status); + ResetFontStatus(); } void FreeLevelEditorGadgets() diff --git a/src/screens.c b/src/screens.c index 3bcb01c4..b86aa1c9 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1247,11 +1247,7 @@ static void drawCursorXY(int xpos, int ypos, int graphic) static void drawChooseTreeCursor(int ypos, boolean active) { - int last_game_status = game_status; /* save current game status */ - drawCursorExt(0, ypos, active, -1); - - SetGameStatus(last_game_status); /* restore current game status */ } void DrawHeadline() @@ -1309,13 +1305,12 @@ void DrawTitleScreenMessage(int nr, boolean initial) { char *filename = getLevelSetTitleMessageFilename(nr, initial); struct TitleMessageInfo *tmi = getTitleMessageInfo(nr, initial); - int last_game_status = game_status; /* save current game status */ if (filename == NULL) return; /* force TITLE font on title message screen */ - SetGameStatus(getTitleMessageGameMode(initial)); + SetFontStatus(getTitleMessageGameMode(initial)); /* if chars *and* width set to "-1", automatically determine width */ if (tmi->chars == -1 && tmi->width == -1) @@ -1354,7 +1349,7 @@ void DrawTitleScreenMessage(int nr, boolean initial) filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1, tmi->autowrap, tmi->centered, tmi->parse_comments); - SetGameStatus(last_game_status); /* restore current game status */ + ResetFontStatus(); } void DrawTitleScreen() @@ -1590,7 +1585,6 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) DrawInfoScreen_NotAvailable("Title screen information:", "No title screen for this level set."); - return; } @@ -3696,7 +3690,6 @@ static void drawChooseTreeList(int first_entry, int num_page_entries, int yoffset_setup = 16; int yoffset = (ti->type == TREE_TYPE_LEVEL_DIR || ti->type == TREE_TYPE_LEVEL_NR ? yoffset_sets : yoffset_setup); - int last_game_status = game_status; /* save current game status */ title_string = ti->infotext; @@ -3736,8 +3729,6 @@ static void drawChooseTreeList(int first_entry, int num_page_entries, initCursor(i, IMG_MENU_BUTTON); } - SetGameStatus(last_game_status); /* restore current game status */ - redraw_mask |= REDRAW_FIELD; } @@ -3785,7 +3776,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, int step = (button == 1 ? 1 : button == 2 ? 5 : 10); int num_entries = numTreeInfoInGroup(ti); int num_page_entries; - int last_game_status = game_status; /* save current game status */ boolean position_set_by_scrollbar = (dx == 999); if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN) @@ -3793,8 +3783,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, else num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN; - SetGameStatus(last_game_status); /* restore current game status */ - if (button == MB_MENU_INITIALIZE) { int num_entries = numTreeInfoInGroup(ti); @@ -3878,12 +3866,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, if (mx || my) /* mouse input */ { - int last_game_status = game_status; /* save current game status */ - x = (mx - mSX) / 32; y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS; - - SetGameStatus(last_game_status); /* restore current game status */ } else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */ { @@ -6935,14 +6919,10 @@ static void CreateScreenScrollbars() void CreateScreenGadgets() { - int last_game_status = game_status; /* save current game status */ - CreateScreenMenubuttons(); CreateScreenScrollbuttons(); CreateScreenScrollbars(); - - SetGameStatus(last_game_status); /* restore current game status */ } void FreeScreenGadgets() diff --git a/src/tools.c b/src/tools.c index 211e6e01..bd235f94 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2428,7 +2428,6 @@ static void setRequestPosition(int *x, int *y, boolean add_border_size) void DrawEnvelopeRequest(char *text) { - int last_game_status = game_status; /* save current game status */ char *text_final = text; char *text_door_style = NULL; int graphic = IMG_BACKGROUND_REQUEST; @@ -2496,13 +2495,13 @@ void DrawEnvelopeRequest(char *text) tile_size, tile_size); /* force DOOR font inside door area */ - SetGameStatus(GAME_MODE_PSEUDO_DOOR); + SetFontStatus(GAME_MODE_PSEUDO_DOOR); DrawTextBuffer(sx + sx_offset, sy + sy_offset, text_final, font_nr, line_length, -1, max_lines, line_spacing, mask_mode, request.autowrap, request.centered, FALSE); - SetGameStatus(last_game_status); /* restore current game status */ + ResetFontStatus(); for (i = 0; i < NUM_TOOL_BUTTONS; i++) RedrawGadget(tool_gadget[i]); @@ -2861,7 +2860,6 @@ static void DrawPreviewLevelExt(boolean restart) boolean show_level_border = (BorderElement != EL_EMPTY); int level_xsize = lev_fieldx + (show_level_border ? 2 : 0); int level_ysize = lev_fieldy + (show_level_border ? 2 : 0); - int last_game_status = game_status; /* save current game status */ if (restart) { @@ -2907,8 +2905,6 @@ static void DrawPreviewLevelExt(boolean restart) DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align); } - SetGameStatus(last_game_status); /* restore current game status */ - return; } @@ -3008,8 +3004,6 @@ static void DrawPreviewLevelExt(boolean restart) DrawPreviewLevelLabelExt(label_state); } - - SetGameStatus(last_game_status); /* restore current game status */ } void DrawPreviewLevelInitial() @@ -3737,7 +3731,6 @@ static int RequestHandleEvents(unsigned int req_state) static boolean RequestDoor(char *text, unsigned int req_state) { unsigned int old_door_state; - int last_game_status = game_status; /* save current game status */ int max_request_line_len = MAX_REQUEST_LINE_FONT1_LEN; int font_nr = FONT_TEXT_2; char *text_ptr; @@ -3794,7 +3787,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) DrawBackground(DX, DY, DXSIZE, DYSIZE); /* force DOOR font inside door area */ - SetGameStatus(GAME_MODE_PSEUDO_DOOR); + SetFontStatus(GAME_MODE_PSEUDO_DOOR); /* write text for request */ for (text_ptr = text, ty = 0; ty < MAX_REQUEST_LINES; ty++) @@ -3834,7 +3827,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) // text_ptr += tl + (tc == ' ' || tc == '?' || tc == '!' ? 1 : 0); } - SetGameStatus(last_game_status); /* restore current game status */ + ResetFontStatus(); if (req_state & REQ_ASK) { @@ -8282,11 +8275,38 @@ void JoinRectangles(int *x, int *y, int *width, int *height, *height = MAX(*height, height2); } +void SetAnimStatus(int anim_status_new) +{ + global.anim_status_next = anim_status_new; +} + void SetGameStatus(int game_status_new) { game_status = game_status_new; - global.anim_status_next = game_status; + SetAnimStatus(game_status_new); +} + +void SetFontStatus(int game_status_new) +{ + static int last_game_status = -1; + + if (game_status_new != -1) + { + // set game status for font use after storing last game status + last_game_status = game_status; + game_status = game_status_new; + } + else + { + // reset game status after font use from last stored game status + game_status = last_game_status; + } +} + +void ResetFontStatus() +{ + SetFontStatus(-1); } void ChangeViewportPropertiesIfNeeded() diff --git a/src/tools.h b/src/tools.h index 041a2d1d..53a1af65 100644 --- a/src/tools.h +++ b/src/tools.h @@ -249,7 +249,10 @@ void PlayMenuMusic(); void PlaySoundActivating(); void PlaySoundSelecting(); +void SetAnimStatus(int); void SetGameStatus(int); +void SetFontStatus(int); +void ResetFontStatus(); void ToggleFullscreenOrChangeWindowScalingIfNeeded(); void ChangeViewportPropertiesIfNeeded();