1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-25 10:20:17 +01:00

Added Unicode support in high score dialog.

Cherry picked form ecea9c812a.
This commit is contained in:
Muzychenko Andrey 2021-11-03 12:53:04 +03:00
parent 2abcaac437
commit da4b99e983
5 changed files with 88 additions and 48 deletions

View file

@ -10,7 +10,7 @@
int high_score::dlg_enter_name; int high_score::dlg_enter_name;
int high_score::dlg_score; int high_score::dlg_score;
int high_score::dlg_position; int high_score::dlg_position;
LPCSTR high_score::default_name; LPCWSTR high_score::default_name;
high_score_struct* high_score::dlg_hst; high_score_struct* high_score::dlg_hst;
winhelp_entry high_score::help[21] winhelp_entry high_score::help[21]
@ -40,7 +40,8 @@ winhelp_entry high_score::help[21]
int high_score::read(high_score_struct* table, int* ptrToSmth) int high_score::read(high_score_struct* table, int* ptrToSmth)
{ {
char Buffer[20]; char scoreBuffer[20];
wchar_t nameBuffer[20];
int scoreSum = 0; int scoreSum = 0;
clear_table(table); clear_table(table);
@ -52,18 +53,17 @@ int high_score::read(high_score_struct* table, int* ptrToSmth)
for (auto position = 0; position < 5; ++position) for (auto position = 0; position < 5; ++position)
{ {
auto tablePtr = &table[position]; auto tablePtr = &table[position];
_itoa_s(position, Buffer, 10);
lstrcatA(Buffer, ".Name"); wsprintfW(nameBuffer, L"%d.Name", position);
options::get_string(optPath, Buffer, buf1, "", 32); options::get_string(optPath, nameBuffer, tablePtr->Name, L"", 32);
buf1[32] = 0; tablePtr->Name[31] = 0;
lstrcpyA(tablePtr->Name, buf1);
_itoa_s(position, Buffer, 10); sprintf_s(scoreBuffer, "%d.Score", position);
lstrcatA(Buffer, ".Score"); options::get_string(optPath, scoreBuffer, buf1, "", 300);
options::get_string(optPath, Buffer, buf1, "", 300);
tablePtr->Score = atol(buf1); tablePtr->Score = atol(buf1);
for (int i = lstrlenA(tablePtr->Name); --i >= 0; scoreSum += tablePtr->Name[i])
{ for (auto i = lstrlenW(tablePtr->Name) - 1; i >= 0; i--)
} scoreSum += tablePtr->Name[i];
scoreSum += tablePtr->Score; scoreSum += tablePtr->Score;
} }
@ -78,29 +78,30 @@ int high_score::read(high_score_struct* table, int* ptrToSmth)
int high_score::write(high_score_struct* table, int* ptrToSmth) int high_score::write(high_score_struct* table, int* ptrToSmth)
{ {
char Buffer[20]; char scoreBuffer[20];
wchar_t nameBuffer[20];
high_score_struct* tablePtr = table;
int scoreSum = 0; int scoreSum = 0;
CHAR* buf = memory::allocate(300u); CHAR* buf = memory::allocate(300u);
if (!buf) if (!buf)
return 1; return 1;
const CHAR* optPath = pinball::get_rc_string(166, 0); auto optPath = pinball::get_rc_string(166, 0);
for (auto position = 0; position < 5; ++position) for (auto position = 0; position < 5; ++position)
{ {
_itoa_s(position, Buffer, 10); auto tablePtr = &table[position];
lstrcatA(Buffer, ".Name");
options::set_string(optPath, Buffer, tablePtr->Name); wsprintfW(nameBuffer, L"%d.Name", position);
_itoa_s(position, Buffer, 10); options::set_string(optPath, nameBuffer, tablePtr->Name);
lstrcatA(Buffer, ".Score");
sprintf_s(scoreBuffer, "%d.Score", position);
_ltoa_s(tablePtr->Score, buf, 300, 10); _ltoa_s(tablePtr->Score, buf, 300, 10);
options::set_string(optPath, Buffer, buf); options::set_string(optPath, scoreBuffer, buf);
for (int i = lstrlenA(tablePtr->Name); --i >= 0; scoreSum += tablePtr->Name[i])
{ for (auto i = lstrlenW(tablePtr->Name) - 1; i >= 0; i--)
} scoreSum += tablePtr->Name[i];
scoreSum += tablePtr->Score; scoreSum += tablePtr->Score;
++tablePtr;
} }
scramble_number_string(scoreSum, buf); scramble_number_string(scoreSum, buf);
options::set_string(optPath, "Verification", buf); options::set_string(optPath, "Verification", buf);
memory::free(buf); memory::free(buf);
@ -130,7 +131,7 @@ int high_score::get_score_position(high_score_struct* table, int score)
return -1; return -1;
} }
int high_score::place_new_score_into(high_score_struct* table, int score, LPSTR scoreStr, int position) int high_score::place_new_score_into(high_score_struct* table, int score, LPWSTR name, int position)
{ {
if (position >= 0) if (position >= 0)
{ {
@ -148,9 +149,9 @@ int high_score::place_new_score_into(high_score_struct* table, int score, LPSTR
} }
high_score_struct* posTable = &table[position]; high_score_struct* posTable = &table[position];
posTable->Score = score; posTable->Score = score;
if (lstrlenA(scoreStr) >= 31) if (lstrlenW(name) >= 31)
scoreStr[31] = 0; name[31] = 0;
lstrcpyA(posTable->Name, scoreStr); lstrcpyW(posTable->Name, name);
posTable->Name[31] = 0; posTable->Name[31] = 0;
} }
return position; return position;
@ -169,7 +170,7 @@ void high_score::show_high_score_dialog(high_score_struct* table)
DialogBoxParamW(winmain::hinst, L"dlg_highscores", winmain::hwnd_frame, HighScore, 0); DialogBoxParamW(winmain::hinst, L"dlg_highscores", winmain::hwnd_frame, HighScore, 0);
} }
void high_score::show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCSTR defaultName) void high_score::show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCWSTR defaultName)
{ {
dlg_position = pos; dlg_position = pos;
dlg_score = score; dlg_score = score;
@ -185,7 +186,7 @@ INT_PTR high_score::HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
HWND parent; HWND parent;
int nIDDlgItem; int nIDDlgItem;
CHAR name[32]; wchar_t name[32];
switch (msg) switch (msg)
{ {
@ -203,7 +204,7 @@ INT_PTR high_score::HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
show_high_scores(hWnd, dlg_hst); show_high_scores(hWnd, dlg_hst);
for (nIDDlgItem = DLG_HIGHSCORES_EditName1; nIDDlgItem < 611; ++nIDDlgItem) for (nIDDlgItem = DLG_HIGHSCORES_EditName1; nIDDlgItem < 611; ++nIDDlgItem)
{ {
ShowWindow(GetDlgItem(hWnd, nIDDlgItem), 0); ShowWindow(GetDlgItem(hWnd, nIDDlgItem), SW_HIDE);
} }
if (dlg_enter_name == 1) if (dlg_enter_name == 1)
{ {
@ -213,12 +214,12 @@ INT_PTR high_score::HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 1; return 1;
} }
HWND nameTextBox = GetDlgItem(hWnd, dlg_position + DLG_HIGHSCORES_EditName1); HWND nameTextBox = GetDlgItem(hWnd, dlg_position + DLG_HIGHSCORES_EditName1);
ShowWindow(nameTextBox, 5); ShowWindow(nameTextBox, SW_SHOW);
EnableWindow(nameTextBox, 1); EnableWindow(nameTextBox, 1);
SetFocus(nameTextBox); SetFocus(nameTextBox);
if (default_name) if (default_name)
{ {
SetWindowTextA(nameTextBox, default_name); SetWindowTextW(nameTextBox, default_name);
SendMessageA(nameTextBox, EM_SETSEL, 0, -1); SendMessageA(nameTextBox, EM_SETSEL, 0, -1);
} }
SendMessageA(nameTextBox, EM_SETLIMITTEXT, 31u, 0); SendMessageA(nameTextBox, EM_SETLIMITTEXT, 31u, 0);
@ -239,7 +240,7 @@ INT_PTR high_score::HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
break; break;
} }
GetDlgItemTextA(hWnd, dlg_position + DLG_HIGHSCORES_EditName1, name, 32); GetDlgItemTextW(hWnd, dlg_position + DLG_HIGHSCORES_EditName1, name, 32);
name[31] = 0; name[31] = 0;
place_new_score_into(dlg_hst, dlg_score, name, dlg_position); place_new_score_into(dlg_hst, dlg_score, name, dlg_position);
break; break;
@ -276,7 +277,7 @@ void high_score::show_high_scores(HWND hDlg, high_score_struct* table)
{ {
if (dlg_enter_name == 1 && dlg_position == i) if (dlg_enter_name == 1 && dlg_position == i)
{ {
hsdlg_show_score(hDlg, " ", dlg_score, i); hsdlg_show_score(hDlg, L" ", dlg_score, i);
nextPosition = 1; nextPosition = 1;
} }
hsdlg_show_score(hDlg, tablePtr->Name, tablePtr->Score, i + nextPosition); hsdlg_show_score(hDlg, tablePtr->Name, tablePtr->Score, i + nextPosition);
@ -284,7 +285,7 @@ void high_score::show_high_scores(HWND hDlg, high_score_struct* table)
} }
} }
void high_score::hsdlg_show_score(HWND hDlg, LPCSTR name, int score, int position) void high_score::hsdlg_show_score(HWND hDlg, LPCWSTR name, int score, int position)
{ {
CHAR scoreStr[36]; CHAR scoreStr[36];
if (position < 5) if (position < 5)
@ -292,7 +293,7 @@ void high_score::hsdlg_show_score(HWND hDlg, LPCSTR name, int score, int positio
score::string_format(score, scoreStr); score::string_format(score, scoreStr);
if (scoreStr[0]) if (scoreStr[0])
{ {
SetWindowTextA(GetDlgItem(hDlg, position + DLG_HIGHSCORES_StaticName1), name); SetWindowTextW(GetDlgItem(hDlg, position + DLG_HIGHSCORES_StaticName1), name);
SetWindowTextA(GetDlgItem(hDlg, position + DLG_HIGHSCORES_Score1), scoreStr); SetWindowTextA(GetDlgItem(hDlg, position + DLG_HIGHSCORES_Score1), scoreStr);
} }
} }

View file

@ -3,7 +3,7 @@
struct high_score_struct struct high_score_struct
{ {
char Name[32]; wchar_t Name[32];
int Score; int Score;
}; };
@ -15,19 +15,19 @@ public:
static int write(high_score_struct* table, int* ptrToSmth); static int write(high_score_struct* table, int* ptrToSmth);
static void clear_table(high_score_struct* table); static void clear_table(high_score_struct* table);
static int get_score_position(high_score_struct* table, int score); static int get_score_position(high_score_struct* table, int score);
static int place_new_score_into(high_score_struct* table, int score, LPSTR scoreStr, int position); static int place_new_score_into(high_score_struct* table, int score, LPWSTR name, int position);
static void scramble_number_string(int Value, char* Buffer); static void scramble_number_string(int Value, char* Buffer);
static void show_high_score_dialog(high_score_struct* table); static void show_high_score_dialog(high_score_struct* table);
static void show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCSTR defaultName); static void show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCWSTR defaultName);
static INT_PTR __stdcall HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); static INT_PTR __stdcall HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void show_high_scores(HWND hDlg, high_score_struct* table); static void show_high_scores(HWND hDlg, high_score_struct* table);
static void hsdlg_show_score(HWND hDlg, LPCSTR name, int score, int position); static void hsdlg_show_score(HWND hDlg, LPCWSTR name, int score, int position);
private : private :
static int dlg_enter_name; static int dlg_enter_name;
static int dlg_score; static int dlg_score;
static int dlg_position; static int dlg_position;
static LPCSTR default_name; static LPCWSTR default_name;
static high_score_struct* dlg_hst; static high_score_struct* dlg_hst;
static winhelp_entry help[21]; static winhelp_entry help[21];
}; };

View file

@ -351,6 +351,43 @@ void options::set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value)
path_free(); path_free();
} }
void options::get_string(LPCSTR optPath, LPCWSTR lpValueName, LPWSTR dst, LPCWSTR defaultValue, int iMaxLength)
{
DWORD dwDisposition;
HKEY hKey;
lstrcpynW(dst, defaultValue, iMaxLength);
if (!OptionsRegPath)
return;
auto regPath = path(optPath);
if (!RegCreateKeyExA(HKEY_CURRENT_USER, regPath, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisposition))
{
DWORD bufferSize = iMaxLength * sizeof(wchar_t);
RegQueryValueExW(hKey, lpValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(dst), &bufferSize);
RegCloseKey(hKey);
}
path_free();
}
void options::set_string(LPCSTR optPath, LPCWSTR lpValueName, LPCWSTR value)
{
DWORD dwDisposition;
HKEY hKey;
if (!OptionsRegPath)
return;
auto regPath = path(optPath);
if (!RegCreateKeyExA(HKEY_CURRENT_USER, regPath, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisposition))
{
DWORD bufferSize = (lstrlenW(value) + 1) * sizeof(wchar_t);
RegSetValueExW(hKey, lpValueName, 0, 1u, LPBYTE(value), bufferSize);
RegCloseKey(hKey);
}
path_free();
}
void options::menu_check(UINT uIDCheckItem, int check) void options::menu_check(UINT uIDCheckItem, int check)
{ {

View file

@ -75,6 +75,8 @@ public:
static void set_int(LPCSTR optPath, LPCSTR lpValueName, int data); static void set_int(LPCSTR optPath, LPCSTR lpValueName, int data);
static void get_string(LPCSTR optPath, LPCSTR lpValueName, LPSTR dst, LPCSTR defaultValue, int iMaxLength); static void get_string(LPCSTR optPath, LPCSTR lpValueName, LPSTR dst, LPCSTR defaultValue, int iMaxLength);
static void set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value); static void set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value);
static void get_string(LPCSTR optPath, LPCWSTR lpValueName, LPWSTR dst, LPCWSTR defaultValue, int iMaxLength);
static void set_string(LPCSTR optPath, LPCWSTR lpValueName, LPCWSTR value);
static void menu_check(UINT uIDCheckItem, int check); static void menu_check(UINT uIDCheckItem, int check);
static void menu_set(UINT uIDEnableItem, int enable); static void menu_set(UINT uIDEnableItem, int enable);
static void toggle(UINT uIDCheckItem); static void toggle(UINT uIDCheckItem);

View file

@ -502,8 +502,8 @@ void pb::keydown(int key)
ball->Acceleration.X = 0.0; ball->Acceleration.X = 0.0;
break; break;
case 'H': case 'H':
char String1[200]; wchar_t String1[200];
lstrcpyA(String1, pinball::get_rc_string(26, 0)); lstrcpyW(String1, pinball::get_rc_Wstring(26, 0));
high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1); high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1);
break; break;
case 'M': case 'M':
@ -556,7 +556,7 @@ void pb::end_game()
{ {
int scores[4]{}; int scores[4]{};
int scoreIndex[4]{}; int scoreIndex[4]{};
char String1[200]; wchar_t String1[200];
mode_change(2); mode_change(2);
int playerCount = MainTable->PlayerCount; int playerCount = MainTable->PlayerCount;
@ -593,7 +593,7 @@ void pb::end_game()
int position = high_score::get_score_position(highscore_table, scores[i]); int position = high_score::get_score_position(highscore_table, scores[i]);
if (position >= 0) if (position >= 0)
{ {
lstrcpyA(String1, pinball::get_rc_string(scoreIndex[i] + 26, 0)); lstrcpyW(String1, pinball::get_rc_Wstring(scoreIndex[i] + 26, 0));
high_score::show_and_set_high_score_dialog(highscore_table, scores[i], position, String1); high_score::show_and_set_high_score_dialog(highscore_table, scores[i], position, String1);
} }
} }