mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
inventory module
This commit is contained in:
@@ -259,6 +259,19 @@ namespace Otc
|
||||
SpriteNoMask = 255
|
||||
};
|
||||
|
||||
enum InventorySlots {
|
||||
InventorySlotHead = 1,
|
||||
InventorySlotNecklace,
|
||||
InventorySlotBackpack,
|
||||
InventorySlotArmor,
|
||||
InventorySlotRight,
|
||||
InventorySlotLeft,
|
||||
InventorySlotLegs,
|
||||
InventorySlotFeet,
|
||||
InventorySlotRing,
|
||||
InventorySlotAmmo
|
||||
};
|
||||
|
||||
enum Statistic {
|
||||
Health,
|
||||
MaxHealth,
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include "game.h"
|
||||
#include "localplayer.h"
|
||||
#include <otclient/net/protocolgame.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
Game g_game;
|
||||
|
||||
@@ -102,6 +103,13 @@ void Game::processTextMessage(int type, const std::string& message)
|
||||
g_lua.callGlobalField("Game","onTextMessage", type, message);
|
||||
}
|
||||
|
||||
void Game::processInventoryChange(int slot, const ItemPtr& item)
|
||||
{
|
||||
g_dispatcher.addEvent([=] {
|
||||
g_lua.callGlobalField("Game","onInventoryChange", slot, item);
|
||||
});
|
||||
}
|
||||
|
||||
void Game::walk(Otc::Direction direction)
|
||||
{
|
||||
if(!m_online || !m_localPlayer->canWalk(direction))
|
||||
@@ -158,9 +166,6 @@ void Game::turn(Otc::Direction direction)
|
||||
}
|
||||
}
|
||||
|
||||
// Game.talkChannel(1, 0, "lalala")
|
||||
// TODO: MAKE SURE IT WAS AN USER EVENT AND NOT DIRECTLY FROM SCRIPT.
|
||||
|
||||
void Game::talkChannel(int channelType, int channelId, const std::string& message)
|
||||
{
|
||||
if(!m_online)
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "declarations.h"
|
||||
#include <otclient/net/declarations.h>
|
||||
#include <otclient/core/item.h>
|
||||
|
||||
class Game
|
||||
{
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
void processLogout();
|
||||
|
||||
void processTextMessage(int type, const std::string& message);
|
||||
void processInventoryChange(int slot, const ItemPtr& item);
|
||||
|
||||
void walk(Otc::Direction direction);
|
||||
void turn(Otc::Direction direction);
|
||||
|
@@ -452,13 +452,15 @@ void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
|
||||
|
||||
void ProtocolGame::parseAddInventoryItem(InputMessage& msg)
|
||||
{
|
||||
msg.getU8(); // slot
|
||||
internalGetItem(msg, 0xFFFF);
|
||||
uint8 slot = msg.getU8();
|
||||
ItemPtr item = internalGetItem(msg, 0xFFFF);
|
||||
g_game.processInventoryChange(slot, item);
|
||||
}
|
||||
|
||||
void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg)
|
||||
{
|
||||
msg.getU8(); // slot
|
||||
uint8 slot = msg.getU8();
|
||||
g_game.processInventoryChange(slot, ItemPtr(nullptr));
|
||||
}
|
||||
|
||||
void ProtocolGame::parseOpenShopWindow(InputMessage& msg)
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#include <otclient/core/spritemanager.h>
|
||||
#include <otclient/net/protocollogin.h>
|
||||
#include <otclient/net/protocolgame.h>
|
||||
#include <otclient/ui/uiitem.h>
|
||||
#include <otclient/ui/uimap.h>
|
||||
|
||||
void OTClient::registerLuaFunctions()
|
||||
@@ -65,6 +66,11 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||
|
||||
g_lua.registerClass<UIItem, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
|
||||
g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem);
|
||||
g_lua.bindClassMemberFunction<UIItem>("setItem", &UIItem::setItem);
|
||||
|
||||
g_lua.registerClass<UIMap, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIMap>("create", &UIWidget::create<UIMap>);
|
||||
|
||||
|
52
src/otclient/ui/uiitem.cpp
Normal file
52
src/otclient/ui/uiitem.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "uiitem.h"
|
||||
#include <framework/otml/otml.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
|
||||
void UIItem::setup()
|
||||
{
|
||||
UIWidget::setup();
|
||||
}
|
||||
|
||||
void UIItem::render()
|
||||
{
|
||||
renderSelf();
|
||||
|
||||
if(m_item) {
|
||||
g_graphics.bindColor(Fw::white);
|
||||
m_item->draw(m_rect.topLeft() + m_itemMargin);
|
||||
}
|
||||
|
||||
renderChildren();
|
||||
}
|
||||
|
||||
void UIItem::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
{
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "item margin")
|
||||
m_itemMargin = node->value<int>();
|
||||
}
|
||||
|
||||
UIWidget::onStyleApply(styleNode);
|
||||
}
|
47
src/otclient/ui/uiitem.h
Normal file
47
src/otclient/ui/uiitem.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef UIITEM_H
|
||||
#define UIITEM_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include <framework/ui/uiwidget.h>
|
||||
#include <otclient/core/item.h>
|
||||
|
||||
class UIItem : public UIWidget
|
||||
{
|
||||
public:
|
||||
void setup();
|
||||
void render();
|
||||
|
||||
void setItem(const ItemPtr& item) { m_item = item; }
|
||||
ItemPtr getItem() { return m_item; }
|
||||
|
||||
protected:
|
||||
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
||||
|
||||
private:
|
||||
ItemPtr m_item;
|
||||
int m_itemMargin;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user