Browse Source

Startup game (diablo or hellfire) can be selected.

pull/3191/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
95b7380ae9
  1. 1
      CMakeLists.txt
  2. 5
      Source/DiabloUI/diabloui.cpp
  3. 2
      Source/DiabloUI/diabloui.h
  4. 80
      Source/DiabloUI/selstart.cpp
  5. 7
      Source/DiabloUI/selstart.h
  6. 13
      Source/diablo.cpp
  7. 2
      Source/options.cpp
  8. 8
      Source/options.h

1
CMakeLists.txt

@ -465,6 +465,7 @@ set(libdevilutionx_SRCS
Source/DiabloUI/selgame.cpp
Source/DiabloUI/selhero.cpp
Source/DiabloUI/selok.cpp
Source/DiabloUI/selstart.cpp
Source/DiabloUI/selyesno.cpp
Source/DiabloUI/support_lines.cpp
Source/DiabloUI/title.cpp

5
Source/DiabloUI/diabloui.cpp

@ -537,6 +537,7 @@ void UnloadUiGFX()
void UiInitialize()
{
UnloadUiGFX();
LoadUiGFX();
if (ArtCursor.surface != nullptr) {
@ -597,7 +598,7 @@ Sint16 GetCenterOffset(Sint16 w, Sint16 bw)
return (bw - w) / 2;
}
void LoadBackgroundArt(const char *pszFile, int frames)
void LoadBackgroundArt(const char *pszFile, int frames, bool withFading)
{
SDL_Color pPal[256];
LoadArt(pszFile, &ArtBackground, frames, pPal);
@ -608,7 +609,7 @@ void LoadBackgroundArt(const char *pszFile, int frames)
ApplyGamma(logical_palette, orig_palette, 256);
fadeTc = 0;
fadeValue = 0;
fadeValue = withFading ? 0 : 256;
if (IsHardwareCursorEnabled() && ArtCursor.surface != nullptr && GetCurrentCursorInfo().type() != CursorType::UserInterface) {
#if SDL_VERSION_ATLEAST(2, 0, 0)

2
Source/DiabloUI/diabloui.h

@ -113,7 +113,7 @@ bool UiItemMouseEvents(SDL_Event *event, const std::vector<std::unique_ptr<UiIte
Sint16 GetCenterOffset(Sint16 w, Sint16 bw = 0);
void LoadPalInMem(const SDL_Color *pPal);
void DrawMouse();
void LoadBackgroundArt(const char *pszFile, int frames = 1);
void LoadBackgroundArt(const char *pszFile, int frames = 1, bool withFading = true);
void UiAddBackground(std::vector<std::unique_ptr<UiItemBase>> *vecDialog);
void UiAddLogo(std::vector<std::unique_ptr<UiItemBase>> *vecDialog, int size = LOGO_MED, int y = 0);
void UiFocusNavigationSelect();

80
Source/DiabloUI/selstart.cpp

@ -0,0 +1,80 @@
#include "selstart.h"
#include "control.h"
#include "DiabloUI/diabloui.h"
#include "options.h"
#include "utils/language.h"
namespace devilution {
namespace {
bool endMenu;
std::vector<std::unique_ptr<UiListItem>> vecDialogItems;
std::vector<std::unique_ptr<UiItemBase>> vecDialog;
Art artLogo;
void ItemSelected(int value)
{
auto option = static_cast<StartUpGameOption>(vecDialogItems[value]->m_value);
sgOptions.Hellfire.startUpGameOption = option;
gbIsHellfire = option == StartUpGameOption::Hellfire;
endMenu = true;
}
void EscPressed()
{
endMenu = true;
}
void FocusChanged(int value)
{
auto option = static_cast<StartUpGameOption>(vecDialogItems[value]->m_value);
gbIsHellfire = option == StartUpGameOption::Hellfire;
ArtBackground.Unload();
ArtBackgroundWidescreen.Unload();
LoadBackgroundArt("ui_art\\mainmenu.pcx", 1, false);
SetFadeLevel(256);
artLogo.Unload();
if (gbIsHellfire) {
LoadArt("ui_art\\mainmenuw.pcx", &ArtBackgroundWidescreen);
LoadMaskedArt("ui_art\\hf_logo2.pcx", &artLogo, 16);
} else {
LoadMaskedArt("ui_art\\smlogo.pcx", &artLogo, 15);
}
gbIsHellfire = true;
}
} // namespace
void UiSelStartUpGameOption()
{
LoadArt("ui_art\\mainmenuw.pcx", &ArtBackgroundWidescreen);
LoadBackgroundArt("ui_art\\mainmenu.pcx");
UiAddBackground(&vecDialog);
SDL_Rect rect = { 0, (Sint16)(UI_OFFSET_Y), 0, 0 };
vecDialog.push_back(std::make_unique<UiImage>(&artLogo, rect, UiFlags::AlignCenter, /*bAnimated=*/true));
vecDialogItems.push_back(std::make_unique<UiListItem>(_("Enter Hellfire"), static_cast<int>(StartUpGameOption::Hellfire)));
vecDialogItems.push_back(std::make_unique<UiListItem>(_("Switch to Diablo"), static_cast<int>(StartUpGameOption::Diablo)));
vecDialog.push_back(std::make_unique<UiList>(vecDialogItems, PANEL_LEFT + 64, (UI_OFFSET_Y + 240), 510, 43, UiFlags::AlignCenter | UiFlags::FontSize42 | UiFlags::ColorUiGold, 5));
UiInitList(vecDialogItems.size(), FocusChanged, ItemSelected, EscPressed, vecDialog, true);
endMenu = false;
while (!endMenu) {
UiClearScreen();
UiRenderItems(vecDialog);
UiPollAndRender();
}
artLogo.Unload();
ArtBackground.Unload();
ArtBackgroundWidescreen.Unload();
vecDialogItems.clear();
vecDialog.clear();
}
} // namespace devilution

7
Source/DiabloUI/selstart.h

@ -0,0 +1,7 @@
#pragma once
namespace devilution {
void UiSelStartUpGameOption();
} // namespace devilution

13
Source/diablo.cpp

@ -74,6 +74,7 @@
#ifdef GPERF_HEAP_FIRST_GAME_ITERATION
#include <gperftools/heap-profiler.h>
#endif
#include <DiabloUI/selstart.h>
namespace devilution {
@ -910,7 +911,7 @@ void DiabloInit()
if (forceSpawn)
gbIsSpawn = true;
if (forceDiablo)
if (forceDiablo || sgOptions.Hellfire.startUpGameOption == StartUpGameOption::Diablo)
gbIsHellfire = false;
gbIsHellfireSaveGame = gbIsHellfire;
@ -936,6 +937,14 @@ void DiabloInit()
ReadOnlyTest();
if (gbIsHellfire && sgOptions.Hellfire.startUpGameOption == StartUpGameOption::None) {
UiSelStartUpGameOption();
if (!gbIsHellfire) {
// Reinitalize the UI Elements cause we changed the game
UiInitialize();
}
}
DiabloInitScreen();
snd_init();
@ -1568,7 +1577,9 @@ int DiabloMain(int argc, char **argv)
DiabloParseFlags(argc, argv);
InitKeymapActions();
LoadOptions();
DiabloInit();
DiabloSplash();
mainmenu_loop();
DiabloDeinit();

2
Source/options.cpp

@ -220,6 +220,7 @@ void LoadOptions()
sgOptions.Hellfire.bIntro = GetIniBool("Hellfire", "Intro", true);
sgOptions.Hellfire.lastSinglePlayerHero = GetIniInt("Hellfire", "LastSinglePlayerHero", 0);
sgOptions.Hellfire.lastMultiplayerHero = GetIniInt("Hellfire", "LastMultiplayerHero", 0);
sgOptions.Hellfire.startUpGameOption = static_cast<StartUpGameOption>(GetIniInt("Hellfire", "StartUpGameOption", static_cast<int>(StartUpGameOption::None)));
GetIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem, sizeof(sgOptions.Hellfire.szItem), "");
sgOptions.Audio.nSoundVolume = GetIniInt("Audio", "Sound Volume", VOLUME_MAX);
@ -375,6 +376,7 @@ void SaveOptions()
SetIniValue("Hellfire", "SItem", sgOptions.Hellfire.szItem);
SetIniValue("Hellfire", "LastSinglePlayerHero", sgOptions.Hellfire.lastSinglePlayerHero);
SetIniValue("Hellfire", "LastMultiplayerHero", sgOptions.Hellfire.lastMultiplayerHero);
SetIniValue("Hellfire", "StartUpGameOption", static_cast<int>(sgOptions.Hellfire.startUpGameOption));
SetIniValue("Audio", "Sound Volume", sgOptions.Audio.nSoundVolume);
SetIniValue("Audio", "Music Volume", sgOptions.Audio.nMusicVolume);

8
Source/options.h

@ -8,6 +8,12 @@
namespace devilution {
enum class StartUpGameOption {
None,
Hellfire,
Diablo,
};
struct DiabloOptions {
/** @brief Play game intro video on startup. */
bool bIntro;
@ -26,6 +32,8 @@ struct HellfireOptions {
std::uint32_t lastSinglePlayerHero;
/** @brief Remembers what multiplayer hero/save was last used. */
std::uint32_t lastMultiplayerHero;
StartUpGameOption startUpGameOption;
};
struct AudioOptions {

Loading…
Cancel
Save