From a13f1580d5ae341f1932571ce85b156dea2953e6 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 7 Nov 2019 08:25:44 +0800 Subject: [PATCH] Prefill player name from list --- CMakeLists.txt | 1 + Packaging/OpenDingux/build.sh | 2 +- SourceX/DiabloUI/selhero.cpp | 56 +++++++++++++++++++++++++++++++++-- SourceX/DiabloUI/selhero.h | 6 +++- SourceX/controls/README.md | 2 +- 5 files changed, 62 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ec0378f3..790dd2000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,7 @@ foreach( NONET DINGUX RETROFW + PREFILL_PLAYER_NAME ) if(${def_name}) list(APPEND def_list ${def_name}) diff --git a/Packaging/OpenDingux/build.sh b/Packaging/OpenDingux/build.sh index 86f3d4c1f..130d2d66d 100755 --- a/Packaging/OpenDingux/build.sh +++ b/Packaging/OpenDingux/build.sh @@ -80,7 +80,7 @@ build() { cd ../../build rm -f CMakeCache.txt - local -a defs=(-DDINGUX=ON -DBINARY_RELEASE=ON) + local -a defs=(-DDINGUX=ON -DBINARY_RELEASE=ON -DPREFILL_PLAYER_NAME=ON) if [[ "$TARGET" == "rg350" ]]; then defs+=( -DNONET=ON diff --git a/SourceX/DiabloUI/selhero.cpp b/SourceX/DiabloUI/selhero.cpp index e8656b77e..eb6142387 100644 --- a/SourceX/DiabloUI/selhero.cpp +++ b/SourceX/DiabloUI/selhero.cpp @@ -1,12 +1,14 @@ #include "selhero.h" #include +#include +#include -#include "scrollbar.h" -#include "selyesno.h" #include "DiabloUI/diabloui.h" #include "DiabloUI/dialogs.h" #include "devilution.h" +#include "scrollbar.h" +#include "selyesno.h" namespace dvl { @@ -241,6 +243,9 @@ void selhero_ClassSelector_Select(int value) strcpy(title, "New Multi Player Hero"); } memset(selhero_heroInfo.name, '\0', sizeof(selhero_heroInfo.name)); +#ifdef PREFILL_PLAYER_NAME + strcpy(selhero_heroInfo.name, selhero_GenerateName(selhero_heroInfo.heroclass)); +#endif UiInitList(0, 0, NULL, selhero_Name_Select, selhero_Name_Esc, ENTERNAME_DIALOG, size(ENTERNAME_DIALOG)); } @@ -370,4 +375,51 @@ BOOL UiSelHeroMultDialog( selhero_isMultiPlayer = true; return UiSelHeroDialog(fninfo, fncreate, fnstats, fnremove, dlgresult, name); } + +const char *selhero_GenerateName(std::uint8_t hero_class) +{ + static const char *const kNames[3][10] = { + { + "Aidan", + "Qarak", + "Born", + "Cathan", + "Halbu", + "Lenalas", + "Maximus", + "Vane", + "Myrdgar", + "Rothat", + }, + { + "Moreina", + "Akara", + "Kashya", + "Flavie", + "Divo", + "Oriana", + "Iantha", + "Shikha", + "Basanti", + "Elexa", + }, + { + "Jazreth", + "Drognan", + "Armin", + "Fauztin", + "Jere", + "Kazzulk", + "Ranslor", + "Sarnakyle", + "Valthek", + "Horazon", + } + }; + const auto seed = std::chrono::system_clock::now().time_since_epoch().count(); + std::default_random_engine generator(seed); + std::uniform_int_distribution dist(0, sizeof(kNames[0]) / sizeof(kNames[0][0]) - 1); + return kNames[hero_class][dist(generator)]; } + +} // namespace dvl diff --git a/SourceX/DiabloUI/selhero.h b/SourceX/DiabloUI/selhero.h index a4d578de9..616fa9a5b 100644 --- a/SourceX/DiabloUI/selhero.h +++ b/SourceX/DiabloUI/selhero.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace dvl { void selhero_List_Init(); @@ -15,4 +17,6 @@ void selhero_Name_Select(int value); void selhero_Name_Esc(); void selhero_Load_Focus(int value); void selhero_Load_Select(int value); -} +const char *selhero_GenerateName(std::uint8_t hero_class); + +} // namespace dvl diff --git a/SourceX/controls/README.md b/SourceX/controls/README.md index 9168aad7a..770854e03 100644 --- a/SourceX/controls/README.md +++ b/SourceX/controls/README.md @@ -22,7 +22,7 @@ Low-level gamepad handling is abstracted and 3 implementations are provided: Example keyboard-as-controller build flags: ```bash -cmake .. -DUSE_SDL1=ON -DHAS_KBCTRL=1 \ +cmake .. -DUSE_SDL1=ON -DHAS_KBCTRL=1 -DPREFILL_PLAYER_NAME=ON \ -DKBCTRL_BUTTON_DPAD_LEFT=SDLK_LEFT \ -DKBCTRL_BUTTON_DPAD_RIGHT=SDLK_RIGHT \ -DKBCTRL_BUTTON_DPAD_UP=SDLK_UP \