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

View File

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

View File

@ -171,7 +171,6 @@ void Game::processEnterGame()
g_lua.callGlobalField("g_game", "onEnterGame"); g_lua.callGlobalField("g_game", "onEnterGame");
} }
void Game::processGameStart() void Game::processGameStart()
{ {
m_online = true; 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); 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 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; m_containers[containerId] = container;
container->onAddItems(items); container->onAddItems(items);
@ -302,7 +301,7 @@ void Game::processCloseContainer(int containerId)
container->onClose(); container->onClose();
} }
void Game::processContainerAddItem(int containerId, const ItemPtr& item) void Game::processContainerAddItem(int containerId, const ItemPtr& item, int slot)
{ {
ContainerPtr container = getContainer(containerId); ContainerPtr container = getContainer(containerId);
if(!container) { if(!container) {
@ -310,7 +309,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item)
return; return;
} }
container->onAddItem(item); container->onAddItem(item, slot);
} }
void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& item) 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); void processTalk(const std::string& name, int level, Otc::MessageMode mode, const std::string& text, int channelId, const Position& pos);
// container related // 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 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 processContainerUpdateItem(int containerId, int slot, const ItemPtr& item);
void processContainerRemoveItem(int containerId, int slot); void processContainerRemoveItem(int containerId, int slot);

View File

@ -317,6 +317,10 @@ void Client::registerLuaFunctions()
g_lua.bindClassMemberFunction<Container>("getContainerItem", &Container::getContainerItem); g_lua.bindClassMemberFunction<Container>("getContainerItem", &Container::getContainerItem);
g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent); g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent);
g_lua.bindClassMemberFunction<Container>("isClosed", &Container::isClosed); 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.registerClass<Thing>();
g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId); g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId);

View File

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