From 35f9b9d75066d4d190cf9043ad29ca2bddf0b450 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 24 Sep 2020 18:26:33 +0200 Subject: [PATCH] Add game speed to the ingame options menu This removes the option to disable color animations (color cyceling) --- Source/diablo.cpp | 1 + Source/diablo.h | 1 + Source/gamemenu.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++-- Source/gamemenu.h | 3 +++ Source/mainmenu.cpp | 7 +++---- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 209befb8a..e4e0821ef 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -42,6 +42,7 @@ int PauseMode; int sgnTimeoutCurs; char sgbMouseDown; int color_cycle_timer; +int ticks_per_sec = 20; WORD game_speed; /* rdata */ diff --git a/Source/diablo.h b/Source/diablo.h index 43d3fca27..181917290 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -47,6 +47,7 @@ extern int debugmonsttypes; extern int PauseMode; extern char sgbMouseDown; extern int color_cycle_timer; +extern int ticks_per_sec; extern WORD game_speed; void FreeGameMem(); diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index 7459d095b..d55d2ca09 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -4,6 +4,7 @@ * Implementation of the in-game menu functions. */ #include "all.h" +#include "../3rdParty/Storm/Source/storm.h" DEVILUTION_BEGIN_NAMESPACE @@ -36,7 +37,8 @@ TMenuItem sgOptionsMenu[] = { { GMENU_ENABLED | GMENU_SLIDER, NULL, &gamemenu_music_volume }, { GMENU_ENABLED | GMENU_SLIDER, NULL, &gamemenu_sound_volume }, { GMENU_ENABLED | GMENU_SLIDER, "Gamma", &gamemenu_gamma }, - { GMENU_ENABLED , NULL, &gamemenu_color_cycling }, +// { GMENU_ENABLED , NULL, &gamemenu_color_cycling }, + { GMENU_ENABLED | GMENU_SLIDER, "Speed", &gamemenu_speed }, { GMENU_ENABLED , "Previous Menu", &gamemenu_previous }, { GMENU_ENABLED , NULL, NULL }, // clang-format on @@ -177,7 +179,8 @@ void gamemenu_options(BOOL bActivate) gamemenu_get_music(); gamemenu_get_sound(); gamemenu_get_gamma(); - gamemenu_get_color_cycling(); + gamemenu_get_speed(); + //gamemenu_get_color_cycling(); gmenu_set_items(sgOptionsMenu, NULL); } @@ -302,6 +305,44 @@ int gamemenu_slider_gamma() return gmenu_slider_get(&sgOptionsMenu[2], 30, 100); } +void gamemenu_get_speed() +{ + if (gbMaxPlayers != 1) { + sgOptionsMenu[3].dwFlags &= ~(GMENU_ENABLED | GMENU_SLIDER); + if (ticks_per_sec >= 50) + sgOptionsMenu[3].pszStr = "Speed: Fastest"; + if (ticks_per_sec >= 40) + sgOptionsMenu[3].pszStr = "Speed: Faster"; + if (ticks_per_sec >= 30) + sgOptionsMenu[3].pszStr = "Speed: Fast"; + else if (ticks_per_sec == 20) + sgOptionsMenu[3].pszStr = "Speed: Normal"; + return; + } + + sgOptionsMenu[3].dwFlags |= GMENU_ENABLED | GMENU_SLIDER; + + sgOptionsMenu[3].pszStr = "Speed"; + gmenu_slider_steps(&sgOptionsMenu[3], 46); + gmenu_slider_set(&sgOptionsMenu[3], 20, 50, ticks_per_sec); +} + +void gamemenu_speed(BOOL bActivate) +{ + if (bActivate) { + if (ticks_per_sec != 20) + ticks_per_sec = 20; + else + ticks_per_sec = 50; + gmenu_slider_set(&sgOptionsMenu[3], 20, 50, ticks_per_sec); + } else { + ticks_per_sec = gmenu_slider_get(&sgOptionsMenu[3], 20, 50); + } + + SRegSaveValue("devilutionx", "game speed", 0, ticks_per_sec); + game_speed = 1000 / ticks_per_sec; +} + void gamemenu_color_cycling(BOOL bActivate) { BOOL color_cycling; diff --git a/Source/gamemenu.h b/Source/gamemenu.h index d39630a22..dc752d959 100644 --- a/Source/gamemenu.h +++ b/Source/gamemenu.h @@ -36,6 +36,9 @@ void gamemenu_gamma(BOOL bActivate); int gamemenu_slider_gamma(); void gamemenu_color_cycling(BOOL bActivate); +void gamemenu_get_speed(); +void gamemenu_speed(BOOL bActivate); + /* rdata */ extern char *music_toggle_names[]; extern char *sound_toggle_names[]; diff --git a/Source/mainmenu.cpp b/Source/mainmenu.cpp index 5a8e0330c..2023443bc 100644 --- a/Source/mainmenu.cpp +++ b/Source/mainmenu.cpp @@ -138,11 +138,10 @@ BOOL mainmenu_single_player() { gbMaxPlayers = 1; - int tps = 20; - if (!SRegLoadValue("devilutionx", "game speed", 0, &tps)) { - SRegSaveValue("devilutionx", "game speed", 0, tps); + if (!SRegLoadValue("devilutionx", "game speed", 0, &ticks_per_sec)) { + SRegSaveValue("devilutionx", "game speed", 0, ticks_per_sec); } - game_speed = 1000 / tps; + game_speed = 1000 / ticks_per_sec; return mainmenu_init_menu(SELHERO_NEW_DUNGEON); }