[9349] Add posssibility for one action button set per talent spec.

This commit is contained in:
hunuza 2010-02-10 17:37:53 +01:00
parent ddeea6017f
commit acf507fd5a
9 changed files with 57 additions and 45 deletions

View file

@ -676,7 +676,7 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8
// original action bar
for (PlayerCreateInfoActions::const_iterator action_itr = info->action.begin(); action_itr != info->action.end(); ++action_itr)
addActionButton(action_itr->button,action_itr->action,action_itr->type);
addActionButton(0, action_itr->button,action_itr->action,action_itr->type);
// original items
CharStartOutfitEntry const* oEntry = NULL;
@ -5635,10 +5635,11 @@ void Player::SendInitialActionButtons() const
WorldPacket data(SMSG_ACTION_BUTTONS, 1+(MAX_ACTION_BUTTONS*4));
data << uint8(0); // can be 0, 1, 2 (talent spec)
ActionButtonList const& currentActionButtonList = m_actionButtons[m_activeSpec];
for(int button = 0; button < MAX_ACTION_BUTTONS; ++button)
{
ActionButtonList::const_iterator itr = m_actionButtons.find(button);
if(itr != m_actionButtons.end() && itr->second.uState != ACTIONBUTTON_DELETED)
ActionButtonList::const_iterator itr = currentActionButtonList.find(button);
if(itr != currentActionButtonList.end() && itr->second.uState != ACTIONBUTTON_DELETED)
data << uint32(itr->second.packedData);
else
data << uint32(0);
@ -5703,14 +5704,14 @@ bool Player::IsActionButtonDataValid(uint8 button, uint32 action, uint8 type, Pl
return true;
}
ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type)
ActionButton* Player::addActionButton(uint8 spec, uint8 button, uint32 action, uint8 type)
{
if (!IsActionButtonDataValid(button,action,type,this))
return NULL;
// it create new button (NEW state) if need or return existed
ActionButton& ab = m_actionButtons[button];
ActionButton& ab = m_actionButtons[spec][button];
// set data and update to CHANGED if not NEW
ab.SetActionAndType(action,ActionButtonType(type));
@ -5721,12 +5722,13 @@ ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type)
void Player::removeActionButton(uint8 button)
{
ActionButtonList::iterator buttonItr = m_actionButtons.find(button);
if (buttonItr==m_actionButtons.end())
ActionButtonList& currentActionButtonList = m_actionButtons[m_activeSpec];
ActionButtonList::iterator buttonItr = currentActionButtonList.find(button);
if (buttonItr==currentActionButtonList.end())
return;
if(buttonItr->second.uState==ACTIONBUTTON_NEW)
m_actionButtons.erase(buttonItr); // new and not saved
currentActionButtonList.erase(buttonItr); // new and not saved
else
buttonItr->second.uState = ACTIONBUTTON_DELETED; // saved, will deleted at next save
@ -5735,8 +5737,9 @@ void Player::removeActionButton(uint8 button)
ActionButton const* Player::GetActionButton(uint8 button)
{
ActionButtonList::iterator buttonItr = m_actionButtons.find(button);
if (buttonItr==m_actionButtons.end() || buttonItr->second.uState == ACTIONBUTTON_DELETED)
ActionButtonList& currentActionButtonList = m_actionButtons[m_activeSpec];
ActionButtonList::iterator buttonItr = currentActionButtonList.find(button);
if (buttonItr==currentActionButtonList.end() || buttonItr->second.uState == ACTIONBUTTON_DELETED)
return NULL;
return &buttonItr->second;
@ -15208,9 +15211,10 @@ bool Player::isAllowedToLoot(Creature* creature)
void Player::_LoadActions(QueryResult *result)
{
m_actionButtons.clear();
for(int i = 0; i < MAX_TALENT_SPEC_COUNT; ++i)
m_actionButtons[i].clear();
//QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
//QueryResult *result = CharacterDatabase.PQuery("SELECT spec, button,action,type FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
if(result)
{
@ -15218,18 +15222,19 @@ void Player::_LoadActions(QueryResult *result)
{
Field *fields = result->Fetch();
uint8 button = fields[0].GetUInt8();
uint32 action = fields[1].GetUInt32();
uint8 type = fields[2].GetUInt8();
uint8 spec = fields[0].GetUInt8();
uint8 button = fields[1].GetUInt8();
uint32 action = fields[2].GetUInt32();
uint8 type = fields[3].GetUInt8();
if(ActionButton* ab = addActionButton(button, action, type))
if(ActionButton* ab = addActionButton(spec, button, action, type))
ab->uState = ACTIONBUTTON_UNCHANGED;
else
{
sLog.outError( " ...at loading, and will deleted in DB also");
// Will deleted in DB at next save (it can create data until save but marked as deleted)
m_actionButtons[button].uState = ACTIONBUTTON_DELETED;
m_actionButtons[spec][button].uState = ACTIONBUTTON_DELETED;
}
}
while( result->NextRow() );
@ -16312,29 +16317,32 @@ void Player::SaveGoldToDB()
void Player::_SaveActions()
{
for(ActionButtonList::iterator itr = m_actionButtons.begin(); itr != m_actionButtons.end(); )
for(int i = 0; i < MAX_TALENT_SPEC_COUNT; ++i)
{
switch (itr->second.uState)
for(ActionButtonList::iterator itr = m_actionButtons[i].begin(); itr != m_actionButtons[i].end(); )
{
case ACTIONBUTTON_NEW:
CharacterDatabase.PExecute("INSERT INTO character_action (guid,button,action,type) VALUES ('%u', '%u', '%u', '%u')",
GetGUIDLow(), (uint32)itr->first, (uint32)itr->second.GetAction(), (uint32)itr->second.GetType() );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
case ACTIONBUTTON_CHANGED:
CharacterDatabase.PExecute("UPDATE character_action SET action = '%u', type = '%u' WHERE guid= '%u' AND button= '%u' ",
(uint32)itr->second.GetAction(), (uint32)itr->second.GetType(), GetGUIDLow(), (uint32)itr->first );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
case ACTIONBUTTON_DELETED:
CharacterDatabase.PExecute("DELETE FROM character_action WHERE guid = '%u' and button = '%u'", GetGUIDLow(), (uint32)itr->first );
m_actionButtons.erase(itr++);
break;
default:
++itr;
break;
switch (itr->second.uState)
{
case ACTIONBUTTON_NEW:
CharacterDatabase.PExecute("INSERT INTO character_action (guid,spec, button,action,type) VALUES ('%u', '%u', '%u', '%u', '%u')",
GetGUIDLow(), i, (uint32)itr->first, (uint32)itr->second.GetAction(), (uint32)itr->second.GetType() );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
case ACTIONBUTTON_CHANGED:
CharacterDatabase.PExecute("UPDATE character_action SET action = '%u', type = '%u' WHERE guid= '%u' AND button= '%u' AND spec = '%u'",
(uint32)itr->second.GetAction(), (uint32)itr->second.GetType(), GetGUIDLow(), (uint32)itr->first, i );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
case ACTIONBUTTON_DELETED:
CharacterDatabase.PExecute("DELETE FROM character_action WHERE guid = '%u' AND button = '%u' AND spec = '%u'", GetGUIDLow(), (uint32)itr->first, i);
m_actionButtons[i].erase(itr++);
break;
default:
++itr;
break;
}
}
}
}