@ -45,44 +45,41 @@ namespace MWGui
QuickKeysMenu : : QuickKeysMenu ( )
: WindowBase ( " openmw_quickkeys_menu.layout " )
, mKey ( std : : vector < keyData > ( 10 ) )
, mSelected ( nullptr )
, mActivated ( nullptr )
, mAssignDialog ( 0 )
, mItemSelectionDialog ( 0 )
, mMagicSelectionDialog ( 0 )
, mSelectedIndex ( - 1 )
, mActivatedIndex ( - 1 )
{
getWidget ( mOkButton , " OKButton " ) ;
getWidget ( mInstructionLabel , " InstructionLabel " ) ;
mMainWidget - > setSize ( mMainWidget - > getWidth ( ) ,
mMainWidget - > getHeight ( ) + ( mInstructionLabel - > getTextSize ( ) . height - mInstructionLabel - > getHeight ( ) ) ) ;
mMainWidget - > getHeight ( ) +
( mInstructionLabel - > getTextSize ( ) . height - mInstructionLabel - > getHeight ( ) ) ) ;
mOkButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & QuickKeysMenu : : onOkButtonClicked ) ;
center ( ) ;
for ( int i = 0 ; i < 10 ; + + i )
{
ItemWidget * button ;
getWidget ( button , " QuickKey " + MyGUI : : utility : : toString ( i + 1 ) ) ;
button - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & QuickKeysMenu : : onQuickKeyButtonClicked ) ;
mQuickKeyButtons . push_back ( button ) ;
mKey [ i ] . index = i + 1 ;
getWidget ( mKey [ i ] . button , " QuickKey " + MyGUI : : utility : : toString ( i + 1 ) ) ;
mKey [ i ] . button - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & QuickKeysMenu : : onQuickKeyButtonClicked ) ;
mAssigned . push_back ( Type_Unassigned ) ;
unassign ( button , i ) ;
unassign ( & mKey [ i ] ) ;
}
}
void QuickKeysMenu : : clear ( )
{
mActivated Index = - 1 ;
mActivated = nullptr ;
for ( int i = 0 ; i < 10 ; + + i )
{
unassign ( m Quick KeyButtons [ i ] , i ) ;
unassign ( & m Key[ i ] ) ;
}
}
@ -93,30 +90,74 @@ namespace MWGui
delete mMagicSelectionDialog ;
}
void QuickKeysMenu : : unassign( ItemWidget * key , int index )
void QuickKeysMenu : : onOpen( )
{
key- > clearUserStrings ( ) ;
key - > setItem ( MWWorld : : Ptr ( ) ) ;
while ( key - > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( key - > getChildAt ( 0 ) ) ;
WindowBase: : onOpen ( ) ;
MWWorld : : Ptr player = MWMechanics : : getPlayer ( ) ;
MWWorld : : InventoryStore & store = player . getClass ( ) . getInventoryStore ( player ) ;
if ( index = = 9 )
// Check if quick keys are still valid
for ( int i = 0 ; i < 10 ; + + i )
{
mAssigned [ index ] = Type_HandToHand ;
switch ( mKey [ i ] . type )
{
case Type_Unassigned :
case Type_HandToHand :
case Type_Magic :
break ;
case Type_Item :
case Type_MagicItem :
{
MWWorld : : Ptr item = * mKey [ i ] . button - > getUserData < MWWorld : : Ptr > ( ) ;
// Make sure the item is available and is not broken
if ( ! item | | item . getRefData ( ) . getCount ( ) < 1 | |
( item . getClass ( ) . hasItemHealth ( item ) & &
item . getClass ( ) . getItemHealth ( item ) < = 0 ) )
{
// Try searching for a compatible replacement
item = store . findReplacement ( mKey [ i ] . id ) ;
if ( item )
mKey [ i ] . button - > setUserData ( MWWorld : : Ptr ( item ) ) ;
MyGUI : : ImageBox * image = key - > createWidget < MyGUI : : ImageBox > ( " ImageBox " ,
break ;
}
}
}
}
}
void QuickKeysMenu : : unassign ( keyData * key )
{
key - > button - > clearUserStrings ( ) ;
key - > button - > setItem ( MWWorld : : Ptr ( ) ) ;
while ( key - > button - > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( key - > button - > getChildAt ( 0 ) ) ;
if ( key - > index = = 10 )
{
key - > type = Type_HandToHand ;
MyGUI : : ImageBox * image = key - > button - > createWidget < MyGUI : : ImageBox > ( " ImageBox " ,
MyGUI : : IntCoord ( 14 , 13 , 32 , 32 ) , MyGUI : : Align : : Default ) ;
image - > setImageTexture ( " icons \\ k \\ stealth_handtohand.dds " ) ;
image - > setNeedMouseFocus ( false ) ;
}
else
{
mAssigned [ index ] = Type_Unassigned ;
key - > type = Type_Unassigned ;
key - > id = " " ;
key - > name = " " ;
MyGUI : : TextBox * textBox = key - > createWidgetReal < MyGUI : : TextBox > ( " SandText " , MyGUI : : FloatCoord ( 0 , 0 , 1 , 1 ) , MyGUI : : Align : : Default ) ;
textBox - > setTextAlign ( MyGUI : : Align : : Center ) ;
textBox - > setCaption ( MyGUI : : utility : : toString ( index + 1 ) ) ;
textBox - > setNeedMouseFocus ( false ) ;
MyGUI : : TextBox * textBox = key - > button - > createWidgetReal < MyGUI : : TextBox > ( " SandText " ,
MyGUI : : FloatCoord ( 0 , 0 , 1 , 1 ) , MyGUI : : Align : : Default ) ;
textBox - > setTextAlign ( MyGUI : : Align : : Center ) ;
textBox - > setCaption ( MyGUI : : utility : : toString ( key - > index ) ) ;
textBox - > setNeedMouseFocus ( false ) ;
}
/*
@ -153,21 +194,24 @@ namespace MWGui
int index = - 1 ;
for ( int i = 0 ; i < 10 ; + + i )
{
if ( sender = = m Quick KeyButtons [ i ] | | sender - > getParent ( ) = = m Quick KeyButtons [ i ] )
if ( sender = = m Key[ i ] . button | | sender - > getParent ( ) = = m Key[ i ] . button )
{
index = i ;
break ;
}
}
assert ( index ! = - 1 ) ;
mSelected Index = index ;
mSelected = & mKey [ index ] ;
{
// open assign dialog
if ( ! mAssignDialog )
mAssignDialog = new QuickKeysMenuAssign ( this ) ;
mAssignDialog - > setVisible ( true ) ;
}
// prevent reallocation of zero key from Type_HandToHand
if ( mSelected - > index = = 10 )
return ;
// open assign dialog
if ( ! mAssignDialog )
mAssignDialog = new QuickKeysMenuAssign ( this ) ;
mAssignDialog - > setVisible ( true ) ;
}
void QuickKeysMenu : : onOkButtonClicked ( MyGUI : : Widget * sender )
@ -175,10 +219,9 @@ namespace MWGui
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( GM_QuickKeysMenu ) ;
}
void QuickKeysMenu : : onItemButtonClicked ( MyGUI : : Widget * sender )
{
if ( ! mItemSelectionDialog )
if ( ! mItemSelectionDialog )
{
mItemSelectionDialog = new ItemSelectionDialog ( " #{sQuickMenu6} " ) ;
mItemSelectionDialog - > eventItemSelected + = MyGUI : : newDelegate ( this , & QuickKeysMenu : : onAssignItem ) ;
@ -188,43 +231,45 @@ namespace MWGui
mItemSelectionDialog - > openContainer ( MWMechanics : : getPlayer ( ) ) ;
mItemSelectionDialog - > setFilter ( SortFilterItemModel : : Filter_OnlyUsableItems ) ;
mAssignDialog - > setVisible ( false ) ;
mAssignDialog - > setVisible ( false ) ;
}
void QuickKeysMenu : : onMagicButtonClicked ( MyGUI : : Widget * sender )
{
if ( ! mMagicSelectionDialog )
if ( ! mMagicSelectionDialog )
{
mMagicSelectionDialog = new MagicSelectionDialog ( this ) ;
}
mMagicSelectionDialog - > setVisible ( true ) ;
mAssignDialog - > setVisible ( false ) ;
mAssignDialog - > setVisible ( false ) ;
}
void QuickKeysMenu : : onUnassignButtonClicked ( MyGUI : : Widget * sender )
{
unassign ( m QuickKeyButtons[ m SelectedIndex] , mSelectedIndex ) ;
mAssignDialog - > setVisible ( false ) ;
unassign ( m Selected) ;
mAssignDialog - > setVisible ( false ) ;
}
void QuickKeysMenu : : onCancelButtonClicked ( MyGUI : : Widget * sender )
{
mAssignDialog - > setVisible ( false ) ;
mAssignDialog - > setVisible ( false ) ;
}
void QuickKeysMenu : : onAssignItem ( MWWorld : : Ptr item )
{
assert ( mSelectedIndex > = 0 ) ;
ItemWidget * button = mQuickKeyButtons [ mSelectedIndex ] ;
while ( button - > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( button - > getChildAt ( 0 ) ) ;
assert ( mSelected ) ;
mAssigned [ mSelectedIndex ] = Type_Item ;
while ( mSelected - > button - > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( mSelected - > button - > getChildAt ( 0 ) ) ;
button - > setItem ( item , ItemWidget : : Barter ) ;
button - > setUserString ( " ToolTipType " , " ItemPtr " ) ;
button - > setUserData ( MWWorld : : Ptr ( item ) ) ;
mSelected - > type = Type_Item ;
mSelected - > id = item . getCellRef ( ) . getRefId ( ) ;
mSelected - > name = item . getClass ( ) . getName ( item ) ;
mSelected - > button - > setItem ( item , ItemWidget : : Barter ) ;
mSelected - > button - > setUserString ( " ToolTipType " , " ItemPtr " ) ;
mSelected - > button - > setUserData ( item ) ;
if ( mItemSelectionDialog )
mItemSelectionDialog - > setVisible ( false ) ;
@ -247,20 +292,20 @@ namespace MWGui
mItemSelectionDialog - > setVisible ( false ) ;
}
void QuickKeysMenu : : onAssignMagicItem ( MWWorld : : Ptr item )
void QuickKeysMenu : : onAssignMagicItem ( MWWorld : : Ptr item )
{
assert ( mSelected Index > = 0 ) ;
ItemWidget * button = mQuickKeyButtons [ mSelectedIndex ] ;
while ( button- > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( button- > getChildAt ( 0 ) ) ;
assert ( mSelected ) ;
while ( mSelected- > button- > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( mSelected- > button- > getChildAt ( 0 ) ) ;
m Assigned[ mSelectedIndex ] = Type_MagicItem ;
m Selected- > type = Type_MagicItem ;
button- > setFrame ( " textures \\ menu_icon_select_magic_magic.dds " , MyGUI : : IntCoord ( 2 , 2 , 40 , 40 ) ) ;
button- > setIcon ( item ) ;
mSelected- > button- > setFrame ( " textures \\ menu_icon_select_magic_magic.dds " , MyGUI : : IntCoord ( 2 , 2 , 40 , 40 ) ) ;
mSelected- > button- > setIcon ( item ) ;
button- > setUserString ( " ToolTipType " , " ItemPtr " ) ;
button- > setUserData ( MWWorld : : Ptr ( item ) ) ;
mSelected- > button- > setUserString ( " ToolTipType " , " ItemPtr " ) ;
mSelected- > button- > setUserData ( MWWorld : : Ptr ( item ) ) ;
if ( mMagicSelectionDialog )
mMagicSelectionDialog - > setVisible ( false ) ;
@ -277,21 +322,20 @@ namespace MWGui
*/
}
void QuickKeysMenu : : onAssignMagic ( const std : : string & spellId )
void QuickKeysMenu : : onAssignMagic ( const std : : string & spellId )
{
assert ( mSelectedIndex > = 0 ) ;
ItemWidget * button = mQuickKeyButtons [ mSelectedIndex ] ;
while ( button - > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( button - > getChildAt ( 0 ) ) ;
assert ( mSelected ) ;
while ( mSelected - > button - > getChildCount ( ) ) // Destroy number label
MyGUI : : Gui : : getInstance ( ) . destroyWidget ( mSelected - > button - > getChildAt ( 0 ) ) ;
mAssigned [ mSelectedIndex ] = Type_Magic ;
mSelected - > type = Type_Magic ;
mSelected - > id = spellId ;
button- > setItem ( MWWorld : : Ptr ( ) ) ;
button- > setUserString ( " ToolTipType " , " Spell " ) ;
button- > setUserString ( " Spell " , spellId ) ;
mSelected- > button- > setItem ( MWWorld : : Ptr ( ) ) ;
mSelected- > button- > setUserString ( " ToolTipType " , " Spell " ) ;
mSelected- > button- > setUserString ( " Spell " , spellId ) ;
const MWWorld : : ESMStore & esmStore =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) ;
const MWWorld : : ESMStore & esmStore = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) ;
// use the icon of the first effect
const ESM : : Spell * spell = esmStore . get < ESM : : Spell > ( ) . find ( spellId ) ;
@ -304,8 +348,8 @@ namespace MWGui
path . insert ( slashPos + 1 , " b_ " ) ;
path = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > correctIconPath ( path ) ;
button- > setFrame ( " textures \\ menu_icon_select_magic.dds " , MyGUI : : IntCoord ( 2 , 2 , 40 , 40 ) ) ;
button- > setIcon ( path ) ;
mSelected- > button- > setFrame ( " textures \\ menu_icon_select_magic.dds " , MyGUI : : IntCoord ( 2 , 2 , 40 , 40 ) ) ;
mSelected- > button- > setIcon ( path ) ;
if ( mMagicSelectionDialog )
mMagicSelectionDialog - > setVisible ( false ) ;
@ -322,7 +366,7 @@ namespace MWGui
*/
}
void QuickKeysMenu : : onAssignMagicCancel ( )
void QuickKeysMenu : : onAssignMagicCancel ( )
{
mMagicSelectionDialog - > setVisible ( false ) ;
}
@ -330,18 +374,17 @@ namespace MWGui
void QuickKeysMenu : : updateActivatedQuickKey ( )
{
// there is no delayed action, nothing to do.
if ( mActivated Index < 0 )
if ( ! mActivated )
return ;
activateQuickKey ( mActivated I ndex) ;
activateQuickKey ( mActivated - > i ndex) ;
}
void QuickKeysMenu : : activateQuickKey ( int index )
{
assert ( index - 1 > = 0 ) ;
ItemWidget * button = mQuickKeyButtons [ index - 1 ] ;
assert ( index > = 1 & & index < = 10 ) ;
QuickKeyType type = mAssigned [ index - 1 ] ;
keyData * key = & mKey [ index - 1 ] ;
MWWorld : : Ptr player = MWMechanics : : getPlayer ( ) ;
MWWorld : : InventoryStore & store = player . getClass ( ) . getInventoryStore ( player ) ;
@ -354,64 +397,100 @@ namespace MWGui
| | playerStats . getHitRecovery ( ) ;
bool isReturnNeeded = playerStats . isParalyzed ( ) | | playerStats . isDead ( ) ;
if ( isReturnNeeded & & type ! = Type_Item )
{
return ;
}
if ( isDelayNeeded & & type ! = Type_Item )
{
mActivatedIndex = index ;
if ( isReturnNeeded )
return ;
}
else if ( isDelayNeeded )
mActivated = key ;
else
mActivatedIndex = - 1 ;
mActivated = nullptr ;
if ( type = = Type_Item | | type = = Type_MagicItem )
if ( key - > type = = Type_Item | | key - > type = = Type_MagicItem )
{
MWWorld : : Ptr item = * button - > getUserData < MWWorld : : Ptr > ( ) ;
// make sure the item is available
if ( item . getRefData ( ) . getCount ( ) < 1 )
MWWorld : : Ptr item = * key - > button - > getUserData < MWWorld : : Ptr > ( ) ;
MWWorld : : ContainerStoreIterator it = store . begin ( ) ;
for ( ; it ! = store . end ( ) ; + + it )
{
// Try searching for a compatible replacement
std : : string id = item . getCellRef ( ) . getRefId ( ) ;
if ( * it = = item )
break ;
}
if ( it = = store . end ( ) )
item = nullptr ;
for ( MWWorld : : ContainerStoreIterator it = store . begin ( ) ; it ! = store . end ( ) ; + + it )
// check the item is available and not broken
if ( ! item | | item . getRefData ( ) . getCount ( ) < 1 | |
( item . getClass ( ) . hasItemHealth ( item ) & & item . getClass ( ) . getItemHealth ( item ) < = 0 ) )
{
item = store . findReplacement ( key - > id ) ;
if ( ! item | | item . getRefData ( ) . getCount ( ) < 1 )
{
if ( Misc : : StringUtils : : ciEqual ( it - > getCellRef ( ) . getRefId ( ) , id ) )
{
item = * it ;
button - > setUserData ( MWWorld : : Ptr ( item ) ) ;
break ;
}
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox (
" #{sQuickMenu5} " + key - > name ) ;
return ;
}
}
if ( key - > type = = Type_Item )
{
bool isWeapon = item . getTypeName ( ) = = typeid ( ESM : : Weapon ) . name ( ) ;
bool isTool = item . getTypeName ( ) = = typeid ( ESM : : Probe ) . name ( ) | |
item . getTypeName ( ) = = typeid ( ESM : : Lockpick ) . name ( ) ;
if ( item . getRefData ( ) . getCount ( ) < 1 )
// delay weapon switching if player is busy
if ( isDelayNeeded & & ( isWeapon | | isTool ) )
{
// No replacement was found
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox (
" #{sQuickMenu5} " + item . getClass ( ) . getName ( item ) ) ;
return ;
}
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > useItem ( item ) ;
MWWorld : : ConstContainerStoreIterator rightHand = store . getSlot ( MWWorld : : InventoryStore : : Slot_CarriedRight ) ;
// change draw state only if the item is in player's right hand
if ( rightHand ! = store . end ( ) & & item = = * rightHand )
{
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Weapon ) ;
}
}
}
else if ( key - > type = = Type_MagicItem )
{
// equip, if it can be equipped
if ( ! item . getClass ( ) . getEquipmentSlots ( item ) . first . empty ( ) )
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > useItem ( item ) ;
// make sure that item was successfully equipped
if ( ! store . isEquipped ( item ) )
return ;
}
if ( type = = Type_Magic )
store . setSelectedEnchantItem ( it ) ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Spell ) ;
}
}
else if ( key - > type = = Type_Magic )
{
std : : string spellId = button - > getUserString ( " Spell " ) ;
std : : string spellId = key- > id ;
// Make sure the player still has this spell
MWMechanics : : CreatureStats & stats = player . getClass ( ) . getCreatureStats ( player ) ;
MWMechanics : : Spells & spells = stats . getSpells ( ) ;
if ( ! spells . hasSpell ( spellId ) )
{
const ESM : : Spell * spell = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : Spell > ( ) . find ( spellId ) ;
MWBase : : Environment : : get ( ) . getW indowManager( ) - > messageBox (
" #{sQuickMenu5} " + spell - > mName ) ;
const ESM : : Spell * spell =
MWBase : : Environment : : get ( ) . getW orld( ) - > getStore ( ) . get < ESM : : Spell > ( ) . find ( spellId ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sQuickMenu5} " + spell - > mName ) ;
return ;
}
store . setSelectedEnchantItem ( store . end ( ) ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setSelectedSpell ( spellId , int ( MWMechanics : : getSpellSuccessChance ( spellId , player ) ) ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( )
- > setSelectedSpell ( spellId , int ( MWMechanics : : getSpellSuccessChance ( spellId , player ) ) ) ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Spell ) ;
/*
@ -424,62 +503,7 @@ namespace MWGui
End of tes3mp addition
*/
}
else if ( type = = Type_Item )
{
MWWorld : : Ptr item = * button - > getUserData < MWWorld : : Ptr > ( ) ;
bool isWeapon = item . getTypeName ( ) = = typeid ( ESM : : Weapon ) . name ( ) ;
bool isTool = item . getTypeName ( ) = = typeid ( ESM : : Probe ) . name ( ) | | item . getTypeName ( ) = = typeid ( ESM : : Lockpick ) . name ( ) ;
// delay weapon switching if player is busy
if ( isDelayNeeded & & ( isWeapon | | isTool ) )
{
mActivatedIndex = index ;
return ;
}
// disable weapon switching if player is dead or paralyzed
if ( isReturnNeeded & & ( isWeapon | | isTool ) )
{
return ;
}
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > useItem ( item ) ;
MWWorld : : ConstContainerStoreIterator rightHand = store . getSlot ( MWWorld : : InventoryStore : : Slot_CarriedRight ) ;
// change draw state only if the item is in player's right hand
if ( rightHand ! = store . end ( ) & & item = = * rightHand )
{
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Weapon ) ;
}
}
else if ( type = = Type_MagicItem )
{
MWWorld : : Ptr item = * button - > getUserData < MWWorld : : Ptr > ( ) ;
// retrieve ContainerStoreIterator to the item
MWWorld : : ContainerStoreIterator it = store . begin ( ) ;
for ( ; it ! = store . end ( ) ; + + it )
{
if ( * it = = item )
{
break ;
}
}
assert ( it ! = store . end ( ) ) ;
// equip, if it can be equipped
if ( ! item . getClass ( ) . getEquipmentSlots ( item ) . first . empty ( ) )
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > useItem ( item ) ;
// make sure that item was successfully equipped
if ( ! store . isEquipped ( item ) )
return ;
}
store . setSelectedEnchantItem ( it ) ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Spell ) ;
}
else if ( type = = Type_HandToHand )
else if ( key - > type = = Type_HandToHand )
{
store . unequipSlot ( MWWorld : : InventoryStore : : Slot_CarriedRight , player ) ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . setDrawState ( MWMechanics : : DrawState_Weapon ) ;
@ -554,9 +578,9 @@ namespace MWGui
for ( int i = 0 ; i < 10 ; + + i )
{
ItemWidget * button = m Quick KeyButtons [ i ] ;
ItemWidget * button = m Key[ i ] . button ;
int type = m Assigned[ i ] ;
int type = m Key[ i ] . type ;
ESM : : QuickKeys : : QuickKey key ;
key . mType = type ;
@ -595,51 +619,38 @@ namespace MWGui
ESM : : QuickKeys keys ;
keys . load ( reader ) ;
MWWorld : : Ptr player = MWMechanics : : getPlayer ( ) ;
MWWorld : : InventoryStore & store = player . getClass ( ) . getInventoryStore ( player ) ;
int i = 0 ;
for ( std : : vector < ESM : : QuickKeys : : QuickKey > : : const_iterator it = keys . mKeys . begin ( ) ; it ! = keys . mKeys . end ( ) ; + + it )
{
if ( i > = 10 )
return ;
mSelectedIndex = i ;
int keyType = it - > mType ;
std : : string id = it - > mId ;
ItemWidget * button = mQuickKeyButtons [ i ] ;
mSelected = & mKey [ i ] ;
mSelected - > type = ( QuickKeysMenu : : QuickKeyType ) it - > mType ;
mSelected - > id = it - > mId ;
switch ( keyT ype)
switch ( mSelected- > t ype)
{
case Type_Magic :
if ( MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : Spell > ( ) . search ( id) )
onAssignMagic ( id) ;
if ( MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : Spell > ( ) . search ( mSelected- > id) )
onAssignMagic ( mSelected- > id) ;
break ;
case Type_Item :
case Type_MagicItem :
{
// Find the item by id
MWWorld : : Ptr player = MWMechanics : : getPlayer ( ) ;
MWWorld : : InventoryStore & store = player . getClass ( ) . getInventoryStore ( player ) ;
MWWorld : : Ptr item ;
for ( MWWorld : : ContainerStoreIterator iter = store . begin ( ) ; iter ! = store . end ( ) ; + + iter )
{
if ( Misc : : StringUtils : : ciEqual ( iter - > getCellRef ( ) . getRefId ( ) , id ) )
{
if ( item . isEmpty ( ) | |
// Prefer the stack with the lowest remaining uses
! item . getClass ( ) . hasItemHealth ( * iter ) | |
iter - > getClass ( ) . getItemHealth ( * iter ) < item . getClass ( ) . getItemHealth ( item ) )
{
item = * iter ;
}
}
}
MWWorld : : Ptr item = store . findReplacement ( mSelected - > id ) ;
if ( item . isEmpty ( ) )
unassign ( button , i ) ;
unassign ( & mKey [ i ] ) ;
else
{
if ( keyT ype = = Type_Item )
if ( mSelected - > type = = Type_Item )
onAssignItem ( item ) ;
else if ( keyT ype = = Type_MagicItem )
else if ( mSelected - > type = = Type_MagicItem )
onAssignMagicItem ( item ) ;
}
@ -647,7 +658,7 @@ namespace MWGui
}
case Type_Unassigned :
case Type_HandToHand :
unassign ( button , i ) ;
unassign ( & mKey [ i ] ) ;
break ;
}