Browse Source

Use SDL_StartTextInput for gold drop dialog

pull/3298/head
obligaron 4 years ago committed by Anders Jenbo
parent
commit
2158faadab
  1. 32
      Source/control.cpp
  2. 1
      Source/control.h
  3. 11
      Source/inv.cpp
  4. 11
      Source/miniwin/misc_msg.cpp

32
Source/control.cpp

@ -1684,9 +1684,6 @@ void control_drop_gold(char vkey)
return;
}
char input[6];
memset(input, 0, sizeof(input));
snprintf(input, sizeof(input), "%i", dropGoldValue);
if (vkey == DVL_VK_RETURN) {
if (dropGoldValue > 0)
RemoveGold(myPlayer, initialDropGoldIndex);
@ -1695,17 +1692,7 @@ void control_drop_gold(char vkey)
CloseGoldDrop();
dropGoldValue = 0;
} else if (vkey == DVL_VK_BACK) {
input[strlen(input) - 1] = '\0';
dropGoldValue = atoi(input);
} else if (vkey - '0' >= 0 && vkey - '0' <= 9) {
if (dropGoldValue != 0 || atoi(input) <= initialDropGoldValue) {
input[strlen(input)] = vkey;
if (atoi(input) > initialDropGoldValue)
return;
} else {
input[0] = vkey;
}
dropGoldValue = atoi(input);
dropGoldValue = dropGoldValue / 10;
}
}
@ -1895,7 +1882,24 @@ void DiabloHotkeyMsg(uint32_t dwMsg)
void CloseGoldDrop()
{
if (!dropGoldFlag)
return;
dropGoldFlag = false;
SDL_StopTextInput();
}
void GoldDropNewText(string_view text)
{
for (char vkey : text) {
int digit = vkey - '0';
if (digit >= 0 && digit <= 9) {
int newGoldValue = dropGoldValue * 10;
newGoldValue += digit;
if (newGoldValue <= initialDropGoldValue) {
dropGoldValue = newGoldValue;
}
}
}
}
} // namespace devilution

1
Source/control.h

@ -181,6 +181,7 @@ void control_new_text(string_view text);
bool control_presskeys(int vkey);
void DiabloHotkeyMsg(uint32_t dwMsg);
void CloseGoldDrop();
void GoldDropNewText(string_view text);
extern Rectangle ChrBtnsRect[4];
} // namespace devilution

11
Source/inv.cpp

@ -1166,11 +1166,16 @@ void StartGoldDrop()
else
initialDropGoldValue = myPlayer.SpdList[pcursinvitem - INVITEM_BELT_FIRST]._ivalue;
dropGoldFlag = true;
dropGoldValue = 0;
if (talkflag)
control_reset_talk();
Point start = GetPanelPosition(UiPanels::Inventory, { 67, 128 });
SDL_Rect rect = { start.x, start.y, 180, 20 };
SDL_SetTextInputRect(&rect);
dropGoldFlag = true;
dropGoldValue = 0;
SDL_StartTextInput();
}
} // namespace

11
Source/miniwin/misc_msg.cpp

@ -481,12 +481,15 @@ bool FetchMessage_Real(tagMSG *lpMsg)
case SDL_KEYDOWN:
case SDL_KEYUP: {
#ifdef USE_SDL1
if (gbRunGame && IsTalkActive()) {
if (gbRunGame && (IsTalkActive() || dropGoldFlag)) {
Uint16 unicode = e.key.keysym.unicode;
if (unicode >= ' ') {
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert;
std::string utf8 = convert.to_bytes(unicode);
control_new_text(utf8);
if (IsTalkActive())
control_new_text(utf8);
if (dropGoldFlag)
GoldDropNewText(utf8);
}
}
#endif
@ -559,6 +562,10 @@ bool FetchMessage_Real(tagMSG *lpMsg)
control_new_text(e.text.text);
break;
}
if (gbRunGame && dropGoldFlag) {
GoldDropNewText(e.text.text);
break;
}
return FalseAvail("SDL_TEXTINPUT", e.text.windowID);
case SDL_WINDOWEVENT:
switch (e.window.event) {

Loading…
Cancel
Save