Browse Source

Introduce GetSpellListSelection and remove selection game logic from DrawSpellList

pull/2560/head^2
obligaron 5 years ago committed by Anders Jenbo
parent
commit
95daecc1bb
  1. 74
      Source/control.cpp
  2. 2
      Source/control.h
  3. 14
      test/control_test.cpp

74
Source/control.cpp

@ -47,11 +47,9 @@ int dropGoldValue;
bool drawmanaflag;
bool chrbtnactive;
int pnumlines;
spell_id pSpell;
UiFlags InfoColor;
char tempstr[256];
int sbooktab;
spell_type pSplType;
int8_t initialDropGoldIndex;
bool talkflag;
bool sbookflag;
@ -581,6 +579,64 @@ void RemoveGold(int pnum, int goldIndex)
dropGoldValue = 0;
}
bool GetSpellListSelection(spell_id &pSpell, spell_type &pSplType)
{
pSpell = spell_id::SPL_INVALID;
pSplType = spell_type::RSPLTYPE_INVALID;
uint64_t mask;
int x = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
int y = PANEL_Y - 17;
for (int i = RSPLTYPE_SKILL; i < RSPLTYPE_INVALID; i++) {
auto &myPlayer = Players[MyPlayerId];
switch ((spell_type)i) {
case RSPLTYPE_SKILL:
mask = myPlayer._pAblSpells;
break;
case RSPLTYPE_SPELL:
mask = myPlayer._pMemSpells;
break;
case RSPLTYPE_SCROLL:
mask = myPlayer._pScrlSpells;
break;
case RSPLTYPE_CHARGES:
mask = myPlayer._pISpells;
break;
case RSPLTYPE_INVALID:
break;
}
int8_t j = SPL_FIREBOLT;
for (uint64_t spl = 1; j < MAX_SPELLS; spl <<= 1, j++) {
if ((mask & spl) == 0)
continue;
int lx = x;
int ly = y - SPLICONLENGTH;
if (MousePosition.x >= lx && MousePosition.x < lx + SPLICONLENGTH && MousePosition.y >= ly && MousePosition.y < ly + SPLICONLENGTH) {
pSpell = (spell_id) j;
pSplType = (spell_type)i;
if (myPlayer._pClass == HeroClass::Monk && j == SPL_SEARCH)
pSplType = RSPLTYPE_SKILL;
return true;
}
x -= SPLICONLENGTH;
if (x == PANEL_X + 12 - SPLICONLENGTH) {
x = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
y -= SPLICONLENGTH;
}
}
if (mask != 0 && x != PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS)
x -= SPLICONLENGTH;
if (x == PANEL_X + 12 - SPLICONLENGTH) {
x = PANEL_X + 12 + SPLICONLENGTH * SPLROWICONLS;
y -= SPLICONLENGTH;
}
}
return false;
}
} // namespace
void DrawSpell(const Surface &out)
@ -611,7 +667,7 @@ void DrawSpellList(const Surface &out)
int s;
uint64_t mask;
pSpell = SPL_INVALID;
spell_id pSpell = SPL_INVALID;
infostr[0] = '\0';
Point location;
int &x = location.x;
@ -663,7 +719,7 @@ void DrawSpellList(const Surface &out)
int ly = y - SPLICONLENGTH;
if (MousePosition.x >= lx && MousePosition.x < lx + SPLICONLENGTH && MousePosition.y >= ly && MousePosition.y < ly + SPLICONLENGTH) {
pSpell = (spell_id)j;
pSplType = (spell_type)i;
spell_type pSplType = (spell_type)i;
if (myPlayer._pClass == HeroClass::Monk && j == SPL_SEARCH)
pSplType = RSPLTYPE_SKILL;
DrawSpellCel(out, location, *pSpellCels, c);
@ -738,8 +794,11 @@ void DrawSpellList(const Surface &out)
void SetSpell()
{
spell_id pSpell;
spell_type pSplType;
spselflag = false;
if (pSpell == SPL_INVALID) {
if (!GetSpellListSelection(pSpell, pSplType)) {
return;
}
@ -754,7 +813,10 @@ void SetSpell()
void SetSpeedSpell(int slot)
{
if (pSpell == SPL_INVALID) {
spell_id pSpell;
spell_type pSplType;
if (!GetSpellListSelection(pSpell, pSplType)) {
return;
}
auto &myPlayer = Players[MyPlayerId];

2
Source/control.h

@ -36,11 +36,9 @@ extern int dropGoldValue;
extern bool drawmanaflag;
extern bool chrbtnactive;
extern int pnumlines;
extern spell_id pSpell;
extern UiFlags InfoColor;
extern char tempstr[256];
extern int sbooktab;
extern spell_type pSplType;
extern int8_t initialDropGoldIndex;
extern bool talkflag;
extern bool sbookflag;

14
test/control_test.cpp

@ -4,20 +4,6 @@
using namespace devilution;
TEST(Control, SetSpell)
{
pnumlines = 1;
pSpell = SPL_FIREBOLT;
pSplType = RSPLTYPE_CHARGES;
auto &myPlayer = Players[MyPlayerId];
SetSpell();
EXPECT_EQ(spselflag, false);
EXPECT_EQ(myPlayer._pRSpell, SPL_FIREBOLT);
EXPECT_EQ(myPlayer._pRSplType, RSPLTYPE_CHARGES);
EXPECT_EQ(pnumlines, 0);
EXPECT_EQ(force_redraw, 255);
}
TEST(Control, ClearPanel)
{
pnumlines = 1;

Loading…
Cancel
Save