什么破博客,,,崩溃了就要重写也不带自动保存
参考http://blog.csdn.net/butwang/archive/2011/02/15/6185631.aspx
function
Packet_OnUpdateShow()
szPacketName = " base " ;
while i < j do
local theAction,bLocked = PlayerPackage:EnumItem(szPacketName, i - 1 );
PACKAGE_BUTTONS[k]:SetProperty( " DragAcceptName " , " P " .. tostring (i));
-- PushDebugMessage("packet index= " .. k.. " pos="..i);
if theAction:GetID() ~= 0 then
PACKAGE_BUTTONS[k]:SetActionItem(theAction:GetID());
itemnum = itemnum + 1 ;
else
PACKAGE_BUTTONS[k]:SetActionItem( - 1 );
end
szPacketName = " base " ;
while i < j do
local theAction,bLocked = PlayerPackage:EnumItem(szPacketName, i - 1 );
PACKAGE_BUTTONS[k]:SetProperty( " DragAcceptName " , " P " .. tostring (i));
-- PushDebugMessage("packet index= " .. k.. " pos="..i);
if theAction:GetID() ~= 0 then
PACKAGE_BUTTONS[k]:SetActionItem(theAction:GetID());
itemnum = itemnum + 1 ;
else
PACKAGE_BUTTONS[k]:SetActionItem( - 1 );
end
通过PlayerPackage:EnumItem的第二个参数 i-1获得index 在map里查表 得到second为
这部分的理解见之前luaplus的帖子
INT PlayerPackage::EnumItem(LuaPlus::LuaState
*
state)
{
const static STRING s_strBaseName = " base " ; // 基本物品 0-19
const static STRING s_strMaterialName = " material " ; // 材料物品 20-39
const static STRING s_strQuestName = " quest " ; // 任务物品 40-59
LuaStack args(state);
// 检查参数
if ( ! (args[ 2 ].IsString()))
{
KLThrow( " LUA: PlayerPackage::EnumItem Wrong Param1 " );
}
if ( ! (args[ 3 ].IsInteger()))
{
KLThrow( " LUA: PlayerPackage::EnumItem Wrong Param2 " );
}
STRING strPakageType = args[ 2 ].GetString();
INT nIndex = args[ 3 ].GetInteger();
// 查询物品
INT nOffIndex = - 1 ;
if (strPakageType == s_strBaseName)
{
nOffIndex = BASE_CONTAINER_OFFSET;
}
else if (strPakageType == s_strMaterialName)
{
nOffIndex = MAT_CONTAINER_OFFSET;
}
else if (strPakageType == s_strQuestName)
{
nOffIndex = TASK_CONTAINER_OFFSET;
}
if (nOffIndex >= 0 )
{
tActionItem * pActionItem = CActionSystem::GetMe() -> EnumAction(nIndex + nOffIndex,
{
const static STRING s_strBaseName = " base " ; // 基本物品 0-19
const static STRING s_strMaterialName = " material " ; // 材料物品 20-39
const static STRING s_strQuestName = " quest " ; // 任务物品 40-59
LuaStack args(state);
// 检查参数
if ( ! (args[ 2 ].IsString()))
{
KLThrow( " LUA: PlayerPackage::EnumItem Wrong Param1 " );
}
if ( ! (args[ 3 ].IsInteger()))
{
KLThrow( " LUA: PlayerPackage::EnumItem Wrong Param2 " );
}
STRING strPakageType = args[ 2 ].GetString();
INT nIndex = args[ 3 ].GetInteger();
// 查询物品
INT nOffIndex = - 1 ;
if (strPakageType == s_strBaseName)
{
nOffIndex = BASE_CONTAINER_OFFSET;
}
else if (strPakageType == s_strMaterialName)
{
nOffIndex = MAT_CONTAINER_OFFSET;
}
else if (strPakageType == s_strQuestName)
{
nOffIndex = TASK_CONTAINER_OFFSET;
}
if (nOffIndex >= 0 )
{
tActionItem * pActionItem = CActionSystem::GetMe() -> EnumAction(nIndex + nOffIndex,
NAMETYPE_PACKAGEITEM);
if (pActionItem)
{
LuaObject objReturn = state->BoxPointer(pActionItem);
objReturn.SetMetaTable(*CActionItem::s_pMetaTable);
objReturn.PushStack();
if(((tObject_Item*)pActionItem->GetImpl())->IsLocked())
state->PushInteger(1);
else
state->PushInteger(0);
return 2 ;
}
}
// 非法ActionItem
LuaObject objReturn = state -> BoxPointer( & (CActionItem::s_InvalidAction));
objReturn.SetMetaTable( * CActionItem::s_pMetaTable);
objReturn.PushStack();
state -> PushInteger( 0 );
return 2 ;
}
if (pActionItem)
{
LuaObject objReturn = state->BoxPointer(pActionItem);
objReturn.SetMetaTable(*CActionItem::s_pMetaTable);
objReturn.PushStack();
if(((tObject_Item*)pActionItem->GetImpl())->IsLocked())
state->PushInteger(1);
else
state->PushInteger(0);
return 2 ;
}
}
// 非法ActionItem
LuaObject objReturn = state -> BoxPointer( & (CActionItem::s_InvalidAction));
objReturn.SetMetaTable( * CActionItem::s_pMetaTable);
objReturn.PushStack();
state -> PushInteger( 0 );
return 2 ;
}
tActionItem
*
CActionSystem::EnumAction(INT nPosIndex, LPCTSTR szFilter)
{
std::map < INT, CActionItem * > ::iterator it;
for (it = m_mapAllAction.begin(); it != m_mapAllAction.end(); it ++ )
{
if (_stricmp(it -> second -> GetType_String(), szFilter) == 0 )
{
if (it ->second->GetPosIndex() == nPosIndex)
{
return it -> second;
}
}
}
return NULL;
}
{
std::map < INT, CActionItem * > ::iterator it;
for (it = m_mapAllAction.begin(); it != m_mapAllAction.end(); it ++ )
{
if (_stricmp(it -> second -> GetType_String(), szFilter) == 0 )
{
if (it ->second->GetPosIndex() == nPosIndex)
{
return it -> second;
}
}
}
return NULL;
}
void
LuaObject::SetMetaTable(
const
LuaObject
&
valueObj)
{
luaplus_assert(m_state);
lua_State * L = GetCState(); ( void )L;
lua_lock(L);
luaT_setmetatable(m_state -> m_state, & m_object, hvalue( & valueObj.m_object));
lua_unlock(L);
}
{
luaplus_assert(m_state);
lua_State * L = GetCState(); ( void )L;
lua_lock(L);
luaT_setmetatable(m_state -> m_state, & m_object, hvalue( & valueObj.m_object));
lua_unlock(L);
}
ActionButton::s_pMetaTable
->
RegisterObjectFunctor(
"
SetActionItem
"
,
&
ActionButton::Lua_SetActionItem);
===================================
INT ActionButton::Lua_SetActionItem(LuaPlus::LuaState * pState)
{
LuaStack args(pState);
if ( ! (args[ 2 ].IsInteger())) return 0 ;
INT idItem = (INT)args[ 2 ].GetInteger();
Update(idItem);
return 0 ;
}
===================================
INT ActionButton::Lua_SetActionItem(LuaPlus::LuaState * pState)
{
LuaStack args(pState);
if ( ! (args[ 2 ].IsInteger())) return 0 ;
INT idItem = (INT)args[ 2 ].GetInteger();
Update(idItem);
return 0 ;
}
VOID ActionButton::Update(INT idItem)
{
// 取得ActionItem
tActionItem * pActionItem = g_pActionSys -> GetAction(idItem);
// 断开和原来的Action的联系
if (m_pActionItem && pActionItem != m_pActionItem)
{
m_pActionItem -> RemoveRefrence( this );
}
if (NULL == pActionItem)
{
// 如果逻辑项为空, 清空显示
BeDestroyed();
m_pWindow -> setProperty( " ShowTooltip " , " True " );
return ;
}
// 不显示默认tooltip
m_pWindow -> setProperty( " ShowTooltip " , " False " );
// 设置有效无效标记
if (pActionItem -> IsEnabled())
{
Bright();
}
else
{
Gloom();
}
// 设置新的Action
((CEGUI::IFalagardActionButton*)(CEGUI::FalagardActionButton*)m_pWindow)->
{
// 取得ActionItem
tActionItem * pActionItem = g_pActionSys -> GetAction(idItem);
// 断开和原来的Action的联系
if (m_pActionItem && pActionItem != m_pActionItem)
{
m_pActionItem -> RemoveRefrence( this );
}
if (NULL == pActionItem)
{
// 如果逻辑项为空, 清空显示
BeDestroyed();
m_pWindow -> setProperty( " ShowTooltip " , " True " );
return ;
}
// 不显示默认tooltip
m_pWindow -> setProperty( " ShowTooltip " , " False " );
// 设置有效无效标记
if (pActionItem -> IsEnabled())
{
Bright();
}
else
{
Gloom();
}
// 设置新的Action
((CEGUI::IFalagardActionButton*)(CEGUI::FalagardActionButton*)m_pWindow)->
setLogicItemData((void*)(INT_PTR)pActionItem->
GetID());
m_pActionItem = pActionItem;
LPCTSTR DragName = ((CEGUI::FalagardActionButton * )m_pWindow) -> getDragAcceptName();
if (DragName[ 0 ] == ' M ' || DragName[ 0 ] == ' F ' )
{
pActionItem -> AddReference( this ,TRUE);
}
else
{
pActionItem -> AddReference( this ,FALSE);
}
const STRING strIconName =
CUISystem::GetMe() -> GetIconManager() -> GetIconFullName(m_pActionItem -> GetIconName());
m_pWindow -> show();
m_pWindow -> setProperty( " Empty " , " False " );
if ( ! strIconName.empty())
{
m_pWindow -> setProperty( " NormalImage " , strIconName);
}
}
m_pActionItem = pActionItem;
LPCTSTR DragName = ((CEGUI::FalagardActionButton * )m_pWindow) -> getDragAcceptName();
if (DragName[ 0 ] == ' M ' || DragName[ 0 ] == ' F ' )
{
pActionItem -> AddReference( this ,TRUE);
}
else
{
pActionItem -> AddReference( this ,FALSE);
}
const STRING strIconName =
CUISystem::GetMe() -> GetIconManager() -> GetIconFullName(m_pActionItem -> GetIconName());
m_pWindow -> show();
m_pWindow -> setProperty( " Empty " , " False " );
if ( ! strIconName.empty())
{
m_pWindow -> setProperty( " NormalImage " , strIconName);
}
}
tActionItem
*
CActionSystem::GetAction(INT id)
{
std::map < INT, CActionItem* > ::iterator it;
it = m_mapAllAction.find(id);
if ( it != m_mapAllAction.end() )
return it -> second;
return NULL;
}
{
std::map < INT, CActionItem* > ::iterator it;
it = m_mapAllAction.find(id);
if ( it != m_mapAllAction.end() )
return it -> second;
return NULL;
}
总体流程应该是这样的:
一开始初始化的时候,当前背包的物品 遍历一遍 每个执行 local theAction,bLocked = PlayerPackage:EnumItem(szPacketName, i-1)
m_mapAllAction这里面装了所有的action当前人物的包里的action 的位置posindex也被存在里面了
it->second->GetPosIndex() == nPosIndex
获得到cActionItem=theAction 的到id绑到button上
rbclick的时候 调用 相应item的 doaction向服务器端发包
什么破博客,,,崩溃了就要重写也不带自动保存