From 03986c0f463f5994fba26d2ceaf1fd02c2a61533 Mon Sep 17 00:00:00 2001 From: Trihedraf Date: Sun, 10 Jul 2022 10:59:32 -0700 Subject: [PATCH] Make zoom a setting in the menu (#4931) --- Source/controls/game_controls.cpp | 2 +- Source/cursor.cpp | 5 +++-- Source/diablo.cpp | 4 +--- Source/diablo.h | 1 - Source/options.cpp | 2 ++ Source/options.h | 2 ++ Source/player.cpp | 2 +- Source/qol/itemlabels.cpp | 2 +- Source/scrollrt.cpp | 21 +++++++++++---------- test/scrollrt_test.cpp | 27 ++++++++++++++------------- 10 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Source/controls/game_controls.cpp b/Source/controls/game_controls.cpp index 29a3d89f3..e5a1bf4dd 100644 --- a/Source/controls/game_controls.cpp +++ b/Source/controls/game_controls.cpp @@ -302,7 +302,7 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game case ControllerButton_BUTTON_Y: // Top button #ifdef __3DS__ if (!ctrlEvent.up) { - zoomflag = !zoomflag; + sgOptions.Graphics.zoom.SetValue(!*sgOptions.Graphics.zoom); CalcViewportGeometry(); } #else diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 18e45399d..2a14082f5 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -19,6 +19,7 @@ #include "hwcursor.hpp" #include "inv.h" #include "missiles.h" +#include "options.h" #include "qol/itemlabels.h" #include "qol/stash.h" #include "towners.h" @@ -273,7 +274,7 @@ void CheckCursMove() sy = GetMainPanel().position.y - 1; } - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { sx /= 2; sy /= 2; } @@ -320,7 +321,7 @@ void CheckCursMove() my++; } - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { sy -= TILE_HEIGHT / 4; } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 35985b8d5..0157545aa 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -95,7 +95,6 @@ Point MousePosition; bool gbRunGame; bool gbRunGameResult; bool ReturnToMainMenu; -bool zoomflag; /** Enable updating of player character, set to false once Diablo dies */ bool gbProcessPlayers; bool gbLoadGame; @@ -149,7 +148,6 @@ bool was_ui_init = false; void StartGame(interface_mode uMsg) { - zoomflag = true; CalcViewportGeometry(); cineflag = false; InitCursor(); @@ -1638,7 +1636,7 @@ void InitKeymapActions() N_("Zoom Game Screen."), 'Z', [] { - zoomflag = !zoomflag; + sgOptions.Graphics.zoom.SetValue(!*sgOptions.Graphics.zoom); CalcViewportGeometry(); }, nullptr, diff --git a/Source/diablo.h b/Source/diablo.h index 5e975a63a..f4397f637 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -65,7 +65,6 @@ extern Point MousePosition; extern bool gbRunGame; extern bool gbRunGameResult; extern bool ReturnToMainMenu; -extern DVL_API_FOR_TEST bool zoomflag; extern bool gbProcessPlayers; extern bool gbLoadGame; extern bool cineflag; diff --git a/Source/options.cpp b/Source/options.cpp index 2f5272818..b03a337b2 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -752,6 +752,7 @@ GraphicsOptions::GraphicsOptions() , vSync("Vertical Sync", OptionEntryFlags::RecreateUI, N_("Vertical Sync"), N_("Forces waiting for Vertical Sync. Prevents tearing effect when drawing a frame. Disabling it can help with mouse lag on some systems."), true) #endif , gammaCorrection("Gamma Correction", OptionEntryFlags::Invisible, "Gamma Correction", "Gamma correction level.", 100) + , zoom("Zoom", OptionEntryFlags::None, N_("Zoom"), N_("Zoom on when enabled."), false) , colorCycling("Color Cycling", OptionEntryFlags::None, N_("Color Cycling"), N_("Color cycling effect used for water, lava, and acid animation."), true) , alternateNestArt("Alternate nest art", OptionEntryFlags::OnlyHellfire | OptionEntryFlags::CantChangeInGame, N_("Alternate nest art"), N_("The game will use an alternative palette for Hellfire’s nest tileset."), false) #if SDL_VERSION_ATLEAST(2, 0, 0) @@ -795,6 +796,7 @@ std::vector GraphicsOptions::GetEntries() &vSync, #endif &gammaCorrection, + &zoom, &limitFPS, &showFPS, &showHealthValues, diff --git a/Source/options.h b/Source/options.h index 23bb4cda6..2286f950c 100644 --- a/Source/options.h +++ b/Source/options.h @@ -398,6 +398,8 @@ struct GraphicsOptions : OptionCategoryBase { #endif /** @brief Gamma correction level. */ OptionEntryInt gammaCorrection; + /** @brief Zoom on start. */ + OptionEntryBoolean zoom; /** @brief Enable color cycling animations. */ OptionEntryBoolean colorCycling; /** @brief Use alternate nest palette. */ diff --git a/Source/player.cpp b/Source/player.cpp index 52f0894d6..eb80f131b 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -279,7 +279,7 @@ void ScrollViewPort(const Player &player, ScrollDirection dir) { ScrollInfo.tile = Point { 0, 0 } + (player.position.tile - ViewPosition); - if (zoomflag) { + if (!*sgOptions.Graphics.zoom) { if (abs(ScrollInfo.tile.x) >= 3 || abs(ScrollInfo.tile.y) >= 3) { ScrollInfo._sdir = ScrollDirection::None; } else { diff --git a/Source/qol/itemlabels.cpp b/Source/qol/itemlabels.cpp index e4c6c290a..d2e55e6e1 100644 --- a/Source/qol/itemlabels.cpp +++ b/Source/qol/itemlabels.cpp @@ -85,7 +85,7 @@ void AddItemToLabelQueue(int id, int x, int y) x += *labelCenterOffsets[index]; y -= TILE_HEIGHT; - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { x *= 2; y *= 2; } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 9ac5120a1..c393be99f 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -27,6 +27,7 @@ #include "minitext.h" #include "missiles.h" #include "nthread.h" +#include "options.h" #include "panels/charpanel.hpp" #include "plrmsg.h" #include "qol/chatlog.h" @@ -1081,7 +1082,7 @@ int tileRows; void DrawGame(const Surface &fullOut, Point position) { // Limit rendering to the view area - const Surface &out = zoomflag + const Surface &out = !*sgOptions.Graphics.zoom ? fullOut.subregionY(0, gnViewportHeight) : fullOut.subregionY(0, (gnViewportHeight + 1) / 2); @@ -1100,7 +1101,7 @@ void DrawGame(const Surface &fullOut, Point position) // Skip rendering parts covered by the panels if (CanPanelsCoverView()) { - if (zoomflag) { + if (!*sgOptions.Graphics.zoom) { if (IsLeftPanelOpen()) { position += Displacement(Direction::East) * 2; columns -= 4; @@ -1175,7 +1176,7 @@ void DrawGame(const Surface &fullOut, Point position) DrawFloor(out, position, { sx, sy }, rows, columns); DrawTileContent(out, position, { sx, sy }, rows, columns); - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { Zoom(fullOut.subregionY(0, gnViewportHeight)); } } @@ -1209,11 +1210,11 @@ void DrawView(const Surface &out, Point startPosition) Point pixelCoords = m.second; if (megaTiles) pixelCoords += Displacement { 0, TILE_HEIGHT / 2 }; - if (!zoomflag) + if (*sgOptions.Graphics.zoom) pixelCoords *= 2; if (debugGridTextNeeded && GetDebugGridText(dunCoords, debugGridTextBuffer)) { Size tileSize = { TILE_WIDTH, TILE_HEIGHT }; - if (!zoomflag) + if (*sgOptions.Graphics.zoom) tileSize *= 2; DrawString(out, debugGridTextBuffer, { pixelCoords - Displacement { 0, tileSize.height }, tileSize }, UiFlags::ColorRed | UiFlags::AlignCenter | UiFlags::VerticalCenter); } @@ -1239,7 +1240,7 @@ void DrawView(const Surface &out, Point startPosition) Displacement hor = { TILE_WIDTH / 2, 0 }; Displacement ver = { 0, TILE_HEIGHT / 2 }; - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { hor *= 2; ver *= 2; } @@ -1453,7 +1454,7 @@ int RowsCoveredByPanel() } int rows = PANEL_HEIGHT / TILE_HEIGHT; - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { rows /= 2; } @@ -1468,7 +1469,7 @@ void CalcTileOffset(int *offsetX, int *offsetY) int x; int y; - if (zoomflag) { + if (!*sgOptions.Graphics.zoom) { x = screenWidth % TILE_WIDTH; y = viewportHeight % TILE_HEIGHT; } else { @@ -1499,7 +1500,7 @@ void TilesInView(int *rcolumns, int *rrows) rows++; } - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { // Half the number of tiles, rounded up if ((columns & 1) != 0) { columns++; @@ -1550,7 +1551,7 @@ void CalcViewportGeometry() } // Slightly lower the zoomed view - if (!zoomflag) { + if (*sgOptions.Graphics.zoom) { tileOffset.deltaY += TILE_HEIGHT / 4; if (yo < TILE_HEIGHT / 4) tileRows++; diff --git a/test/scrollrt_test.cpp b/test/scrollrt_test.cpp index ffd6d5f0b..f765256e4 100644 --- a/test/scrollrt_test.cpp +++ b/test/scrollrt_test.cpp @@ -1,6 +1,7 @@ #include #include "diablo.h" +#include "options.h" #include "scrollrt.h" #include "utils/ui_fwd.h" @@ -13,7 +14,7 @@ TEST(Scroll_rt, calc_tiles_in_view_original) gnScreenWidth = 640; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight - 128; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); int columns = 0; int rows = 0; TilesInView(&columns, &rows); @@ -26,7 +27,7 @@ TEST(Scroll_rt, calc_tiles_in_view_original_zoom) gnScreenWidth = 640; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight - 128; - zoomflag = false; + sgOptions.Graphics.zoom.SetValue(true); int columns = 0; int rows = 0; TilesInView(&columns, &rows); @@ -39,7 +40,7 @@ TEST(Scroll_rt, calc_tiles_in_view_960_540) gnScreenWidth = 960; gnScreenHeight = 540; gnViewportHeight = gnScreenHeight; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); int columns = 0; int rows = 0; TilesInView(&columns, &rows); @@ -52,7 +53,7 @@ TEST(Scroll_rt, calc_tiles_in_view_640_512) gnScreenWidth = 640; gnScreenHeight = 512; gnViewportHeight = gnScreenHeight - 128; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); int columns = 0; int rows = 0; TilesInView(&columns, &rows); @@ -65,7 +66,7 @@ TEST(Scroll_rt, calc_tiles_in_view_768_480_zoom) gnScreenWidth = 768; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight; - zoomflag = false; + sgOptions.Graphics.zoom.SetValue(true); int columns = 0; int rows = 0; TilesInView(&columns, &rows); @@ -80,7 +81,7 @@ TEST(Scroll_rt, calc_tile_offset_original) gnScreenWidth = 640; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight - 128; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); int x = 0; int y = 0; CalcTileOffset(&x, &y); @@ -93,7 +94,7 @@ TEST(Scroll_rt, calc_tile_offset_original_zoom) gnScreenWidth = 640; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight - 128; - zoomflag = false; + sgOptions.Graphics.zoom.SetValue(true); int x = 0; int y = 0; CalcTileOffset(&x, &y); @@ -106,7 +107,7 @@ TEST(Scroll_rt, calc_tile_offset_960_540) gnScreenWidth = 960; gnScreenHeight = 540; gnViewportHeight = gnScreenHeight; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); int x = 0; int y = 0; CalcTileOffset(&x, &y); @@ -119,7 +120,7 @@ TEST(Scroll_rt, calc_tile_offset_853_480) gnScreenWidth = 853; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); int x = 0; int y = 0; CalcTileOffset(&x, &y); @@ -132,7 +133,7 @@ TEST(Scroll_rt, calc_tile_offset_768_480_zoom) gnScreenWidth = 768; gnScreenHeight = 480; gnViewportHeight = gnScreenHeight; - zoomflag = false; + sgOptions.Graphics.zoom.SetValue(true); int x = 0; int y = 0; CalcTileOffset(&x, &y); @@ -145,20 +146,20 @@ TEST(Scroll_rt, calc_tile_offset_768_480_zoom) TEST(Scroll_rt, calc_tiles_covered_by_panel_original) { gnScreenWidth = 640; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); EXPECT_EQ(RowsCoveredByPanel(), 0); } TEST(Scroll_rt, calc_tiles_covered_by_panel_960) { gnScreenWidth = 960; - zoomflag = true; + sgOptions.Graphics.zoom.SetValue(false); EXPECT_EQ(RowsCoveredByPanel(), 4); } TEST(Scroll_rt, calc_tiles_covered_by_panel_960_zoom) { gnScreenWidth = 960; - zoomflag = false; + sgOptions.Graphics.zoom.SetValue(true); EXPECT_EQ(RowsCoveredByPanel(), 2); }