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

@ -74,6 +74,7 @@ SET(SOURCES src/framework/ui/uiframecounter.cpp
# otclient ui # otclient ui
src/otclient/ui/uiitem.cpp src/otclient/ui/uiitem.cpp
src/otclient/ui/uicreature.cpp
src/otclient/ui/uimap.cpp src/otclient/ui/uimap.cpp
# otclient net # otclient net

View File

@ -14,5 +14,6 @@ Module
importStyles 'styles/windows.otui' importStyles 'styles/windows.otui'
importStyles 'styles/listboxes.otui' importStyles 'styles/listboxes.otui'
importStyles 'styles/items.otui' importStyles 'styles/items.otui'
importStyles 'styles/creatures.otui'
return true return true

View File

@ -0,0 +1,6 @@
Creature < UICreature
size: 66 66
creature-margin: 1
border-image:
source: /core_styles/images/panel_flat.png
border: 1

View File

@ -14,4 +14,5 @@ Module
- viplist - viplist
- textmessage - textmessage
- chat - chat
- outfit

41
modules/outfit/outfit.lua Normal file
View File

@ -0,0 +1,41 @@
Outfit = {}
-- private variables
local window = nil
-- public functions
function Outfit.test()
local button = UIButton.create()
UI.root:addChild(button)
button:setText('Set Outfit')
button:setStyle('Button')
button:moveTo({x = 0, y = 100})
button:setWidth('100')
button:setHeight('30')
button.onClick = function() Game.openOutfitWindow() end
end
function Outfit.create(creature, outfitList)
if window ~= nil then
Outfit.destroy()
end
window = loadUI("/outfit/outfit.otui", UI.root)
local creatureWidget = window:getChildById('creature')
creatureWidget:setCreature(creature)
end
function Outfit.destroy()
window:destroy()
window = nil
end
-- private functions
-- hooked events
connect(Game, { onOpenOutfitWindow = Outfit.create,
onLogout = Outfit.destroy })
connect(Game, { onLogin = Outfit.test })

View File

@ -0,0 +1,10 @@
Module
name: outfit
description: Change local player outfit
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
require 'outfit'
return true

View File

@ -0,0 +1,40 @@
Window
title: Select Outfit
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Creature
id: creature
anchors.top: parent.top
anchors.left: parent.left
margin.top: 30
margin.left: 20
HorizontalSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
margin.left: 16
margin.right: 16
margin.bottom: 10
Button
id: buttonOk
text: Ok
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
onClick: Outfit.accept()
Button
id: buttonCancel
text: Cancel
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
onClick: Outfit.destroy()

View File

@ -179,3 +179,8 @@ void Game::talkPrivate(int channelType, const std::string& receiver, const std::
m_protocolGame->sendTalk(channelType, 0, receiver, message); 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 turn(Otc::Direction direction);
void talkChannel(int channelType, int channelId, const std::string& message); void talkChannel(int channelType, int channelId, const std::string& message);
void talkPrivate(int channelType, const std::string& receiver, const std::string& message); void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
void openOutfitWindow();
bool isOnline() { return m_online; } bool isOnline() { return m_online; }

View File

@ -50,6 +50,10 @@ public:
virtual const ThingType& getType() = 0; virtual const ThingType& getType() = 0;
int getAnimationPhases() { return getType().dimensions[ThingType::AnimationPhases]; } 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()); } ThingPtr asThing() { return std::static_pointer_cast<Thing>(shared_from_this()); }
virtual ItemPtr asItem() { return nullptr; } virtual ItemPtr asItem() { return nullptr; }
virtual CreaturePtr asCreature() { return nullptr; } virtual CreaturePtr asCreature() { return nullptr; }

View File

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

View File

@ -838,14 +838,27 @@ void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
void ProtocolGame::parseOutfitWindow(InputMessage& msg) void ProtocolGame::parseOutfitWindow(InputMessage& msg)
{ {
internalGetOutfit(msg); Outfit outfit = internalGetOutfit(msg);
uint8 outfitCount = msg.getU8();
typedef std::tuple<int, std::string, int> OutfitInfo;
std::vector<OutfitInfo> outfitList;
uint8 outfitCount = msg.getU8();
for(int i = 0; i < outfitCount; i++) { for(int i = 0; i < outfitCount; i++) {
msg.getU16(); // outfit id uint16 outfitId = msg.getU16();
msg.getString(); // outfit name std::string outfitName = msg.getString();
msg.getU8(); // addons 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) void ProtocolGame::parseVipState(InputMessage& msg)

View File

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

View File

@ -35,6 +35,7 @@
#include <otclient/net/protocollogin.h> #include <otclient/net/protocollogin.h>
#include <otclient/net/protocolgame.h> #include <otclient/net/protocolgame.h>
#include <otclient/ui/uiitem.h> #include <otclient/ui/uiitem.h>
#include <otclient/ui/uicreature.h>
#include <otclient/ui/uimap.h> #include <otclient/ui/uimap.h>
void OTClient::registerLuaFunctions() 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>("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>("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.registerClass<UIItem, UIWidget>();
g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>); g_lua.bindClassStaticFunction<UIItem>("create", &UIItem::create<UIItem>);
g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem); g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem);
g_lua.bindClassMemberFunction<UIItem>("setItem", &UIItem::setItem); 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.registerClass<UIMap, UIWidget>();
g_lua.bindClassStaticFunction<UIMap>("create", &UIWidget::create<UIMap>); 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