@ -38,16 +38,15 @@ spell_id SpellPages[6][7] = {
{ SPL_INVALID , SPL_INVALID , SPL_INVALID , SPL_INVALID , SPL_INVALID , SPL_INVALID , SPL_INVALID }
} ;
constexpr int SpellBookDescriptionWidth = 250 ;
constexpr int SpellBookDescriptionHeight = 43 ;
constexpr int SpellBookDescriptionPaddingLeft = 2 ;
constexpr int SpellBookDescriptionPaddingRight = 2 ;
constexpr Size SpellBookDescription { 250 , 43 } ;
constexpr int SpellBookDescriptionPaddingHorizontal = 2 ;
void PrintSBookStr ( const Surface & out , Point position , string_view text , UiFlags flags = UiFlags : : None )
{
DrawString ( out , text ,
{ GetPanelPosition ( UiPanels : : Spell , { SPLICONLENGTH + SpellBookDescriptionPaddingLeft + position . x , position . y } ) ,
{ SpellBookDescriptionWidth - SpellBookDescriptionPaddingLeft - SpellBookDescriptionPaddingRight , 0 } } ,
Rectangle ( GetPanelPosition ( UiPanels : : Spell , position + Displacement { SPLICONLENGTH , 0 } ) ,
SpellBookDescription )
. inset ( { SpellBookDescriptionPaddingHorizontal , 0 } ) ,
UiFlags : : ColorWhite | flags ) ;
}
@ -140,7 +139,7 @@ void DrawSpellBook(const Surface &out)
if ( sn ! = SPL_INVALID & & ( spl & GetSpellBitmask ( sn ) ) ! = 0 ) {
spell_type st = GetSBookTrans ( sn , true ) ;
SetSpellTrans ( st ) ;
const Point spellCellPosition = GetPanelPosition ( UiPanels : : Spell , { 11 , yp + SpellBookDescriptionH eight } ) ;
const Point spellCellPosition = GetPanelPosition ( UiPanels : : Spell , { 11 , yp + SpellBookDescription . h eight } ) ;
DrawSpellCel ( out , spellCellPosition , * pSBkIconCels , SpellITbl [ sn ] ) ;
if ( sn = = player . _pRSpell & & st = = player . _pRSplType ) {
SetSpellTrans ( RSPLTYPE_SKILL ) ;
@ -184,16 +183,19 @@ void DrawSpellBook(const Surface &out)
} break ;
}
}
yp + = SpellBookDescriptionH eight ;
yp + = SpellBookDescription . h eight;
}
}
void CheckSBook ( )
{
Rectangle iconArea = { GetPanelPosition ( UiPanels : : Spell , { 11 , 18 } ) , { 48 - 11 , 314 - 18 } } ;
Rectangle tabArea = { GetPanelPosition ( UiPanels : : Spell , { 7 , 320 } ) , { 311 - 7 , 349 - 320 } } ;
// Icons are drawn in a column near the left side of the panel and aligned with the spell book description entries
// Spell icons/buttons are 37x38 pixels, laid out from 11,18 with a 5 pixel margin between each icon. This is close
// enough to the height of the space given to spell descriptions that we can reuse that value and subtract the
// padding from the end of the area.
Rectangle iconArea = { GetPanelPosition ( UiPanels : : Spell , { 11 , 18 } ) , Size { 37 , SpellBookDescription . height * 7 - 5 } } ;
if ( iconArea . Contains ( MousePosition ) ) {
spell_id sn = SpellPages [ sbooktab ] [ ( MousePosition . y - GetRightPanel ( ) . position . y - 18 ) / 43 ] ;
spell_id sn = SpellPages [ sbooktab ] [ ( MousePosition . y - iconArea . position . y ) / SpellBookDescription . height ] ;
Player & player = * MyPlayer ;
uint64_t spl = player . _pMemSpells | player . _pISpells | player . _pAblSpells ;
if ( sn ! = SPL_INVALID & & ( spl & GetSpellBitmask ( sn ) ) ! = 0 ) {
@ -208,9 +210,23 @@ void CheckSBook()
player . _pRSplType = st ;
force_redraw = 255 ;
}
return ;
}
// The width of the panel excluding the border is 305 pixels. This does not cleanly divide by 4 meaning Diablo tabs
// end up with an extra pixel somewhere around the buttons. Vanilla Diablo had the buttons left-aligned, devilutionX
// instead justifies the buttons and puts the gap between buttons 2/3. See DrawSpellBook
const int TabWidth = gbIsHellfire ? 61 : 76 ;
// Tabs are drawn in a row near the bottom of the panel
Rectangle tabArea = { GetPanelPosition ( UiPanels : : Spell , { 7 , 320 } ) , Size { 305 , 29 } } ;
if ( tabArea . Contains ( MousePosition ) ) {
sbooktab = ( MousePosition . x - ( GetRightPanel ( ) . position . x + 7 ) ) / ( gbIsHellfire ? 61 : 76 ) ;
int hitColumn = MousePosition . x - tabArea . position . x ;
// Clicking on the gutter currently activates tab 3. Could make it do nothing by checking for == here and return early.
if ( ! gbIsHellfire & & hitColumn > TabWidth * 2 ) {
// Subtract 1 pixel to account for the gutter between buttons 2/3
hitColumn - - ;
}
sbooktab = hitColumn / TabWidth ;
}
}