outfit window init

This commit is contained in:
Henrique
2011-11-14 20:32:55 -02:00
parent da3b39017d
commit a95d0bcc1f
16 changed files with 242 additions and 5 deletions

View File

@@ -179,3 +179,8 @@ void Game::talkPrivate(int channelType, const std::string& receiver, const std::
m_protocolGame->sendTalk(channelType, 0, receiver, message);
}
void Game::openOutfitWindow()
{
m_protocolGame->sendGetOutfit();
}

View File

@@ -52,6 +52,7 @@ public:
void turn(Otc::Direction direction);
void talkChannel(int channelType, int channelId, const std::string& message);
void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
void openOutfitWindow();
bool isOnline() { return m_online; }

View File

@@ -50,6 +50,10 @@ public:
virtual const ThingType& getType() = 0;
int getAnimationPhases() { return getType().dimensions[ThingType::AnimationPhases]; }
void setXPattern(int xPattern) { m_xPattern = xPattern; }
void setYPattern(int yPattern) { m_yPattern = yPattern; }
void setZPattern(int zPattern) { m_zPattern = zPattern; }
ThingPtr asThing() { return std::static_pointer_cast<Thing>(shared_from_this()); }
virtual ItemPtr asItem() { return nullptr; }
virtual CreaturePtr asCreature() { return nullptr; }

View File

@@ -56,6 +56,7 @@ public:
void sendTurnWest();
void sendUseItem(const Position& position, int itemId, int stackpos, int index);
void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message);
void sendGetOutfit();
void sendAddVip(const std::string& name);
void sendRemoveVip(int id);

View File

@@ -838,14 +838,27 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
void ProtocolGame::parseOutfitWindow(InputMessage& msg)
{
internalGetOutfit(msg);
uint8 outfitCount = msg.getU8();
Outfit outfit = internalGetOutfit(msg);
typedef std::tuple<int, std::string, int> OutfitInfo;
std::vector<OutfitInfo> outfitList;
uint8 outfitCount = msg.getU8();
for(int i = 0; i < outfitCount; i++) {
msg.getU16(); // outfit id
msg.getString(); // outfit name
msg.getU8(); // addons
uint16 outfitId = msg.getU16();
std::string outfitName = msg.getString();
uint8 outfitAddons = msg.getU8();
outfitList.push_back(OutfitInfo(outfitId, outfitName, outfitAddons));
}
CreaturePtr creature = CreaturePtr(new Creature);
creature->setXPattern(2);
creature->setOutfit(outfit);
g_dispatcher.addEvent([=] {
g_lua.callGlobalField("Game", "onOpenOutfitWindow", creature, outfitList);
});
}
void ProtocolGame::parseVipState(InputMessage& msg)

View File

@@ -195,6 +195,13 @@ void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& r
send(oMsg);
}
void ProtocolGame::sendGetOutfit()
{
OutputMessage oMsg;
oMsg.addU8(Otc::ClientGetOutfit);
send(oMsg);
}
void ProtocolGame::sendAddVip(const std::string& name)
{
OutputMessage oMsg;

View File

@@ -35,6 +35,7 @@
#include <otclient/net/protocollogin.h>
#include <otclient/net/protocolgame.h>
#include <otclient/ui/uiitem.h>
#include <otclient/ui/uicreature.h>
#include <otclient/ui/uimap.h>
void OTClient::registerLuaFunctions()
@@ -65,12 +66,18 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &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<UICreature, UIWidget>();
g_lua.bindClassStaticFunction<UICreature>("create", &UICreature::create<UICreature>);
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
g_lua.bindClassMemberFunction<UICreature>("setCreature", &UICreature::setCreature);
g_lua.registerClass<UIMap, UIWidget>();
g_lua.bindClassStaticFunction<UIMap>("create", &UIWidget::create<UIMap>);

View 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 "uicreature.h"
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
void UICreature::setup()
{
UIWidget::setup();
}
void UICreature::render()
{
renderSelf();
if(m_creature) {
g_graphics.bindColor(Fw::white);
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin);
}
renderChildren();
}
void UICreature::onStyleApply(const OTMLNodePtr& styleNode)
{
for(OTMLNodePtr node : styleNode->children()) {
if(node->tag() == "creature-margin")
m_creatureMargin = node->value<int>();
}
UIWidget::onStyleApply(styleNode);
}

View 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 UICREATURE_H
#define UICREATURE_H
#include "declarations.h"
#include <framework/ui/uiwidget.h>
#include <otclient/core/creature.h>
class UICreature : public UIWidget
{
public:
void setup();
void render();
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
CreaturePtr getCreature() { return m_creature; }
protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode);
private:
CreaturePtr m_creature;
int m_creatureMargin;
};
#endif