Some work on container pagination

Bind lua functions for containers
Update onAddItem now it have the pagination slot
Note: getSize as i see is equal to getItemsCount, but not sure thats why
I've added !
This commit is contained in:
Joao Pasqualini Costa 2013-10-20 20:21:20 -02:00
parent 971d90a596
commit 7290ec3334
6 changed files with 42 additions and 21 deletions

View File

@ -23,7 +23,7 @@
#include "container.h"
#include "item.h"
Container::Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent)
Container::Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
{
m_id = id;
m_capacity = capacity;
@ -31,6 +31,10 @@ Container::Container(int id, int capacity, const std::string& name, const ItemPt
m_containerItem = containerItem;
m_hasParent = hasParent;
m_closed = false;
m_unlocked = isUnlocked;
m_hasPages = hasPages;
m_size = containerSize;
m_firstIndex = firstIndex;
}
ItemPtr Container::getItem(int slot)
@ -51,12 +55,12 @@ void Container::onClose()
callLuaField("onClose");
}
void Container::onAddItem(const ItemPtr& item)
void Container::onAddItem(const ItemPtr& item, int slot)
{
m_items.push_front(item);
updateItemsPositions();
callLuaField("onAddItem", 0, item);
callLuaField("onAddItem", slot, item);
}
ItemPtr Container::findItemById(uint itemId, int subType)

View File

@ -32,7 +32,7 @@
class Container : public LuaObject
{
protected:
Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent);
Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent, bool isUnlocked, bool hasPages, int containerSize, int firstIndex);
public:
ItemPtr getItem(int slot);
@ -45,12 +45,16 @@ public:
std::string getName() { return m_name; }
bool hasParent() { return m_hasParent; }
bool isClosed() { return m_closed; }
bool isUnlocked() { return m_unlocked; }
bool hasPages() { return m_hasPages; }
int getSize() { return m_size; }
int getFirstIndex() { return m_firstIndex; }
ItemPtr findItemById(uint itemId, int subType);
protected:
void onOpen(const ContainerPtr& previousContainer);
void onClose();
void onAddItem(const ItemPtr& item);
void onAddItem(const ItemPtr& item, int slot);
void onAddItems(const std::vector<ItemPtr>& items);
void onUpdateItem(int slot, const ItemPtr& item);
void onRemoveItem(int slot);
@ -66,6 +70,10 @@ private:
std::string m_name;
bool m_hasParent;
bool m_closed;
bool m_unlocked;
bool m_hasPages;
int m_size;
int m_firstIndex;
std::deque<ItemPtr> m_items;
};

View File

@ -171,7 +171,6 @@ void Game::processEnterGame()
g_lua.callGlobalField("g_game", "onEnterGame");
}
void Game::processGameStart()
{
m_online = true;
@ -274,10 +273,10 @@ void Game::processTalk(const std::string& name, int level, Otc::MessageMode mode
g_lua.callGlobalField("g_game", "onTalk", name, level, mode, text, channelId, pos);
}
void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items)
void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex)
{
ContainerPtr previousContainer = getContainer(containerId);
ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent));
ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent, isUnlocked, hasPages, containerSize, firstIndex));
m_containers[containerId] = container;
container->onAddItems(items);
@ -302,7 +301,7 @@ void Game::processCloseContainer(int containerId)
container->onClose();
}
void Game::processContainerAddItem(int containerId, const ItemPtr& item)
void Game::processContainerAddItem(int containerId, const ItemPtr& item, int slot)
{
ContainerPtr container = getContainer(containerId);
if(!container) {
@ -310,7 +309,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
return;
}
container->onAddItem(item);
container->onAddItem(item, slot);
}
void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item)

View File

@ -80,9 +80,9 @@ protected:
void processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos);
// container related
void processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items);
void processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector<ItemPtr>& items, bool isUnlocked, bool hasPages, int containerSize, int firstIndex);
void processCloseContainer(int containerId);
void processContainerAddItem(int containerId, const ItemPtr& item);
void processContainerAddItem(int containerId, const ItemPtr& item, int slot);
void processContainerUpdateItem(int containerId, int slot, const ItemPtr& item);
void processContainerRemoveItem(int containerId, int slot);

View File

@ -68,7 +68,7 @@ void Client::registerLuaFunctions()
g_lua.bindSingletonFunction("g_things", "findItemTypeByClientId", &ThingTypeManager::findItemTypeByClientId, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByName", &ThingTypeManager::findItemTypeByName, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypesByName", &ThingTypeManager::findItemTypesByName, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypesByString", &ThingTypeManager::findItemTypesByString, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypesByString", &ThingTypeManager::findItemTypesByString, &g_things);
g_lua.bindSingletonFunction("g_things", "findItemTypeByCategory", &ThingTypeManager::findItemTypeByCategory, &g_things);
g_lua.bindSingletonFunction("g_things", "findThingTypeByAttr", &ThingTypeManager::findThingTypeByAttr, &g_things);
@ -317,6 +317,10 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Container>("getContainerItem", &Container::getContainerItem);
g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent);
g_lua.bindClassMemberFunction<Container>("isClosed", &Container::isClosed);
g_lua.bindClassMemberFunction<Container>("isUnlocked", &Container::isUnlocked);
g_lua.bindClassMemberFunction<Container>("hasPages", &Container::hasPages);
g_lua.bindClassMemberFunction<Container>("getSize", &Container::getSize);
g_lua.bindClassMemberFunction<Container>("getFirstIndex", &Container::getFirstIndex);
g_lua.registerClass<Thing>();
g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId);
@ -646,7 +650,7 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIMinimap>("getMinZoom", &UIMinimap::getMinZoom);
g_lua.bindClassMemberFunction<UIMinimap>("getMaxZoom", &UIMinimap::getMaxZoom);
g_lua.bindClassMemberFunction<UIMinimap>("getZoom", &UIMinimap::getZoom);
g_lua.bindClassMemberFunction<UIMinimap>("getScale", &UIMinimap::getScale);
g_lua.bindClassMemberFunction<UIMinimap>("getScale", &UIMinimap::getScale);
g_lua.bindClassMemberFunction<UIMinimap>("anchorPosition", &UIMinimap::anchorPosition);
g_lua.bindClassMemberFunction<UIMinimap>("fillPosition", &UIMinimap::fillPosition);
g_lua.bindClassMemberFunction<UIMinimap>("centerInPosition", &UIMinimap::centerInPosition);

View File

@ -620,11 +620,16 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg)
int capacity = msg->getU8();
bool hasParent = (msg->getU8() != 0);
bool isUnlocked;
bool hasPages;
int containerSize;
int firstIndex;
if(g_game.getFeature(Otc::GameContainerPagination)) {
msg->getU8(); // drag and drop
msg->getU8(); // pagination
msg->getU16(); // container size
msg->getU16(); // first index
isUnlocked = (msg->getU8() != 0); // drag and drop
hasPages = (msg->getU8() != 0); // pagination
containerSize = msg->getU16(); // container size
firstIndex = msg->getU16(); // first index
}
int itemCount = msg->getU8();
@ -633,7 +638,7 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg)
for(int i = 0; i < itemCount; i++)
items[i] = getItem(msg);
g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items);
g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items, isUnlocked, hasPages, containerSize, firstIndex);
}
void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg)
@ -645,11 +650,12 @@ void ProtocolGame::parseCloseContainer(const InputMessagePtr& msg)
void ProtocolGame::parseContainerAddItem(const InputMessagePtr& msg)
{
int containerId = msg->getU8();
int slot = 0;
if(g_game.getFeature(Otc::GameContainerPagination)) {
msg->getU16(); // slot
slot = msg->getU16(); // slot
}
ItemPtr item = getItem(msg);
g_game.processContainerAddItem(containerId, item);
g_game.processContainerAddItem(containerId, item, slot);
}
void ProtocolGame::parseContainerUpdateItem(const InputMessagePtr& msg)