From ce681480eaf1d57accc606a41cd3e26b0ded28c0 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 18 Nov 2011 22:12:17 -0200 Subject: [PATCH] fix compile error on mingw32, add lua events for channels --- CMakeLists.txt | 5 +- src/framework/ui/uiimage.cpp | 41 +++++++++ src/framework/ui/uiimage.h | 69 +++++++++++++++ src/framework/ui/uiwidget.h | 16 ++-- src/framework/util/types.h | 4 +- .../luafunctions.cpp} | 43 +--------- src/otclient/luascript/luavaluecasts.cpp | 85 +++++++++++++++++++ src/otclient/luascript/luavaluecasts.h | 39 +++++++++ src/otclient/net/protocolgameparse.cpp | 35 +++++--- 9 files changed, 274 insertions(+), 63 deletions(-) create mode 100644 src/framework/ui/uiimage.cpp create mode 100644 src/framework/ui/uiimage.h rename src/otclient/{otclientluafunctions.cpp => luascript/luafunctions.cpp} (78%) create mode 100644 src/otclient/luascript/luavaluecasts.cpp create mode 100644 src/otclient/luascript/luavaluecasts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 534bc881..b691b235 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,10 @@ SET(SOURCES # otclient src/otclient/otclient.cpp - src/otclient/otclientluafunctions.cpp + + # otclient luascript + src/otclient/luascript/luafunctions.cpp + src/otclient/luascript/luavaluecasts.cpp # otclient core src/otclient/core/game.cpp diff --git a/src/framework/ui/uiimage.cpp b/src/framework/ui/uiimage.cpp new file mode 100644 index 00000000..cffb7004 --- /dev/null +++ b/src/framework/ui/uiimage.cpp @@ -0,0 +1,41 @@ +#include "uiimage.h" +#include + +void UIImage::draw(const Rect& screenCoords) +{ + +} + +void UIImage::applyStyle(const OTMLNodePtr& styleNode) +{ + /* + for(const OTMLNodePtr& node : styleNode->children()) { + if(node->tag() == "image-source") + setImageSource(node->value()); + else if(node->tag() == "image-clip") + setImageClip(node->value()); + else if(node->tag() == "image-rect") + setImageRect(node->value()); + else if(node->tag() == "image-fixed-ratio") + setImageFixedRatio(node->value()); + else if(node->tag() == "image-repeated") + setImageRepeated(node->value()); + else if(node->tag() == "image-smooth") + setImageSmooth(node->value()); + else if(node->tag() == "image-color") + setImageColor(node->value()); + else if(node->tag() == "image-border-top") + setImageBorderTop(node->value()); + else if(node->tag() == "image-border-right") + setImageBorderRight(node->value()); + else if(node->tag() == "image-border-bottom") + setImageBorderBottom(node->value()); + else if(node->tag() == "image-border-left") + setImageBorderLeft(node->value()); + else if(node->tag() == "image-border") { + + } + } + */ +} + diff --git a/src/framework/ui/uiimage.h b/src/framework/ui/uiimage.h new file mode 100644 index 00000000..c688d4d9 --- /dev/null +++ b/src/framework/ui/uiimage.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2010-2011 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 UIIMAGE_H +#define UIIMAGE_H + +#include +#include +#include "declarations.h" + +class UIImage +{ +public: + void draw(const Rect& screenCoords); + void applyStyle(const OTMLNodePtr& styleNode); + + void setImageSource(const std::string& source); + void setImageClip(const Rect& clipRect); + void setImageRect(const Rect& rect); + void setImageFixedRatio(bool fixedRatio); + void setImageRepeated(bool repeated); + void setImageSmooth(bool smooth); + void setImageColor(const Color& color); + void setImageBorderTop(int border); + void setImageBorderRight(int border); + void setImageBorderBottom(int border); + void setImageBorderLeft(int border); + +protected: + TexturePtr m_imageTexture; + Rect m_imageClipRect; + Rect m_imageRect; + Boolean m_imageFixedRatio; + Boolean m_imageRepeated; + Color m_imageColor; + + // border image coords + Rect m_leftBorderTexCoords; + Rect m_rightBorderTexCoords; + Rect m_topBorderTexCoords; + Rect m_bottomBorderTexCoords; + Rect m_topLeftCornerTexCoords; + Rect m_topRightCornerTexCoords; + Rect m_bottomLeftCornerTexCoords; + Rect m_bottomRightCornerTexCoords; + Rect m_centerTexCoords; + Size m_bordersSize; +}; + +#endif diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index d7fa153b..96a6673f 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -183,14 +183,14 @@ protected: protected: std::string m_id; Fw::FocusReason m_lastFocusReason; - boolean m_enabled; - boolean m_visible; - boolean m_focusable; - boolean m_fixedSize; - boolean m_pressed; - boolean m_phantom; - boolean m_updateEventScheduled; - boolean m_firstOnStyle; + Boolean m_enabled; + Boolean m_visible; + Boolean m_focusable; + Boolean m_fixedSize; + Boolean m_pressed; + Boolean m_phantom; + Boolean m_updateEventScheduled; + Boolean m_firstOnStyle; Rect m_rect; UILayoutPtr m_layout; UIWidgetWeakPtr m_parent; diff --git a/src/framework/util/types.h b/src/framework/util/types.h index eeb5999a..b4a91c13 100644 --- a/src/framework/util/types.h +++ b/src/framework/util/types.h @@ -44,8 +44,8 @@ typedef std::function BooleanCallback; // boolean with default value initializer template -struct boolean { - boolean() : v(def) { } +struct Boolean { + Boolean() : v(def) { } operator bool &() { return v; } operator bool const &() const { return v; } bool& operator=(const bool& o) { v = o; return v; } diff --git a/src/otclient/otclientluafunctions.cpp b/src/otclient/luascript/luafunctions.cpp similarity index 78% rename from src/otclient/otclientluafunctions.cpp rename to src/otclient/luascript/luafunctions.cpp index f7311e68..9b0bef12 100644 --- a/src/otclient/otclientluafunctions.cpp +++ b/src/otclient/luascript/luafunctions.cpp @@ -20,8 +20,7 @@ * THE SOFTWARE. */ -#include "otclient.h" - +#include #include #include #include @@ -39,8 +38,7 @@ #include #include -void push_luavalue(const Outfit& outfit); -bool luavalue_cast(int index, Outfit& outfit); +#include "luavaluecasts.h" void OTClient::registerLuaFunctions() { @@ -95,40 +93,3 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); #endif } - -void push_luavalue(const Outfit& outfit) -{ - g_lua.newTable(); - g_lua.pushInteger(outfit.getType()); - g_lua.setField("type"); - g_lua.pushInteger(outfit.getAddons()); - g_lua.setField("addons"); - g_lua.pushInteger(outfit.getHead()); - g_lua.setField("head"); - g_lua.pushInteger(outfit.getBody()); - g_lua.setField("body"); - g_lua.pushInteger(outfit.getLegs()); - g_lua.setField("legs"); - g_lua.pushInteger(outfit.getFeet()); - g_lua.setField("feet"); -} - -bool luavalue_cast(int index, Outfit& outfit) -{ - if(g_lua.isTable(index)) { - g_lua.getField("type", index); - outfit.setType(g_lua.popInteger()); - g_lua.getField("addons", index); - outfit.setAddons(g_lua.popInteger()); - g_lua.getField("head", index); - outfit.setHead(g_lua.popInteger()); - g_lua.getField("body", index); - outfit.setBody(g_lua.popInteger()); - g_lua.getField("legs", index); - outfit.setLegs(g_lua.popInteger()); - g_lua.getField("feet", index); - outfit.setFeet(g_lua.popInteger()); - return true; - } - return false; -} diff --git a/src/otclient/luascript/luavaluecasts.cpp b/src/otclient/luascript/luavaluecasts.cpp new file mode 100644 index 00000000..ff166448 --- /dev/null +++ b/src/otclient/luascript/luavaluecasts.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2010-2011 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 "luavaluecasts.h" +#include + +void push_luavalue(const Outfit& outfit) +{ + g_lua.newTable(); + g_lua.pushInteger(outfit.getType()); + g_lua.setField("type"); + g_lua.pushInteger(outfit.getAddons()); + g_lua.setField("addons"); + g_lua.pushInteger(outfit.getHead()); + g_lua.setField("head"); + g_lua.pushInteger(outfit.getBody()); + g_lua.setField("body"); + g_lua.pushInteger(outfit.getLegs()); + g_lua.setField("legs"); + g_lua.pushInteger(outfit.getFeet()); + g_lua.setField("feet"); +} + +bool luavalue_cast(int index, Outfit& outfit) +{ + if(g_lua.isTable(index)) { + g_lua.getField("type", index); + outfit.setType(g_lua.popInteger()); + g_lua.getField("addons", index); + outfit.setAddons(g_lua.popInteger()); + g_lua.getField("head", index); + outfit.setHead(g_lua.popInteger()); + g_lua.getField("body", index); + outfit.setBody(g_lua.popInteger()); + g_lua.getField("legs", index); + outfit.setLegs(g_lua.popInteger()); + g_lua.getField("feet", index); + outfit.setFeet(g_lua.popInteger()); + return true; + } + return false; +} + +void push_luavalue(const Position& pos) +{ + g_lua.newTable(); + g_lua.pushInteger(pos.x); + g_lua.setField("x"); + g_lua.pushInteger(pos.y); + g_lua.setField("y"); + g_lua.pushInteger(pos.z); + g_lua.setField("z"); +} + +bool luavalue_cast(int index, Position& pos) +{ + if(g_lua.isTable(index)) { + g_lua.getField("x", index); + pos.x = g_lua.popInteger(); + g_lua.getField("y", index); + pos.y = g_lua.popInteger(); + g_lua.getField("z", index); + pos.z = g_lua.popInteger(); + } + return false; +} diff --git a/src/otclient/luascript/luavaluecasts.h b/src/otclient/luascript/luavaluecasts.h new file mode 100644 index 00000000..71eb4064 --- /dev/null +++ b/src/otclient/luascript/luavaluecasts.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2010-2011 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 OTCLIENT_LUAVALUECASTS_H +#define OTCLIENT_LUAVALUECASTS_H + +#include +#include +#include + +// outfit +void push_luavalue(const Outfit& outfit); +bool luavalue_cast(int index, Outfit& outfit); + +// position +void push_luavalue(const Position& pos); +bool luavalue_cast(int index, Position& pos); + + +#endif \ No newline at end of file diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 5eb18b5d..dbef2856 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include void ProtocolGame::parseMessage(InputMessage& msg) @@ -711,8 +712,10 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) { msg.getU32(); // unkSpeak std::string name = msg.getString(); // name - uint16 level = msg.getU16(); // level - uint8 type = msg.getU8(); + int level = msg.getU16(); // level + int type = msg.getU8(); + int channelId; + Position creaturePos; switch(type) { case Otc::SpeakSay: @@ -721,13 +724,13 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) case Otc::SpeakMonsterSay: case Otc::SpeakMonsterYell: case Otc::SpeakPrivateNpcToPlayer: - parsePosition(msg); // creaturePos + creaturePos = parsePosition(msg); // creaturePos break; case Otc::SpeakChannelRed: case Otc::SpeakChannelOrange: case Otc::SpeakChannelYellow: case Otc::SpeakChannelWhite: - msg.getU16(); // channelId + channelId = msg.getU16(); // channelId break; case Otc::SpeakPrivate: case Otc::SpeakPrivatePlayerToNpc: @@ -742,23 +745,33 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg) std::string message = msg.getString(); // message g_dispatcher.addEvent([=] { - g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message); + g_lua.callGlobalField("Game", "onCreatureSpeak", name, level, type, message, channelId, creaturePos); }); } void ProtocolGame::parseChannelList(InputMessage& msg) { - uint8 count = msg.getU8(); - for(uint8 i = 0; i < count; i++) { - msg.getU16(); - msg.getString(); + int count = msg.getU8(); + std::vector > channelList(count); + for(int i = 0; i < count; i++) { + int id = msg.getU16(); + std::string name = msg.getString(); + channelList.push_back(std::make_tuple(id, name)); } + + g_dispatcher.addEvent([=] { + g_lua.callGlobalField("Game", "onChannelList", channelList); + }); } void ProtocolGame::parseOpenChannel(InputMessage& msg) { - msg.getU16(); // channelId - msg.getString(); // name + int channelId = msg.getU16(); + std::string name = msg.getString(); + + g_dispatcher.addEvent([=] { + g_lua.callGlobalField("Game", "onOpenChannel", channelId, name); + }); } void ProtocolGame::parseOpenPrivatePlayerChat(InputMessage& msg)