Browse Source

Prefill player name from list

pull/481/head
Gleb Mazovetskiy 6 years ago committed by Anders Jenbo
parent
commit
a13f1580d5
  1. 1
      CMakeLists.txt
  2. 2
      Packaging/OpenDingux/build.sh
  3. 56
      SourceX/DiabloUI/selhero.cpp
  4. 6
      SourceX/DiabloUI/selhero.h
  5. 2
      SourceX/controls/README.md

1
CMakeLists.txt

@ -300,6 +300,7 @@ foreach(
NONET
DINGUX
RETROFW
PREFILL_PLAYER_NAME
)
if(${def_name})
list(APPEND def_list ${def_name})

2
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

56
SourceX/DiabloUI/selhero.cpp

@ -1,12 +1,14 @@
#include "selhero.h"
#include <algorithm>
#include <chrono>
#include <random>
#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<std::size_t> dist(0, sizeof(kNames[0]) / sizeof(kNames[0][0]) - 1);
return kNames[hero_class][dist(generator)];
}
} // namespace dvl

6
SourceX/DiabloUI/selhero.h

@ -1,5 +1,7 @@
#pragma once
#include <cstdint>
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

2
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 \

Loading…
Cancel
Save