From c1cf53829ed37348776a1d719ed0ab1a867613ee Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 12 Jan 2012 17:20:18 -0200 Subject: [PATCH] implement grid layout --- BUGS | 1 + TODO | 1 - src/framework/CMakeLists.txt | 3 +- src/framework/luafunctions.cpp | 11 ++ src/framework/ui/declarations.h | 2 + src/framework/ui/ui.h | 1 + src/framework/ui/uigridlayout.cpp | 91 +++++++++++++++ src/framework/ui/uigridlayout.h | 57 ++++++++++ src/framework/ui/uilayout.h | 4 +- src/framework/ui/uirichtext.cpp | 24 ++++ src/framework/ui/uirichtext.h | 33 ++++++ src/framework/ui/uiverticallayout.cpp | 30 ----- src/framework/ui/uiverticallayout.h | 12 +- src/framework/ui/uiwidget.cpp | 4 +- src/framework/ui/uiwidgetbasestyle.cpp | 5 +- src/otclient/core/item.h | 2 +- src/otclient/net/protocolcodes.h | 2 +- src/otclient/net/protocolgame.h | 30 ++--- src/otclient/net/protocolgameparse.cpp | 148 +++++++++++++------------ src/otclient/net/protocolgamesend.cpp | 24 ++-- src/otclient/net/protocollogin.cpp | 2 +- 21 files changed, 340 insertions(+), 147 deletions(-) create mode 100644 src/framework/ui/uigridlayout.cpp create mode 100644 src/framework/ui/uigridlayout.h create mode 100644 src/framework/ui/uirichtext.cpp create mode 100644 src/framework/ui/uirichtext.h diff --git a/BUGS b/BUGS index bf0b2fc3..8ae84f93 100644 --- a/BUGS +++ b/BUGS @@ -10,3 +10,4 @@ hotkeys works while windows are locked, it shouldnt some animated hits are displayed as 2 hits instead of one numpad on windows doesn't work correctly skulls is rendering outside map bounds +these are some issues when skill progressbar is 0% or 100% diff --git a/TODO b/TODO index 38bbfda4..52c75d7b 100644 --- a/TODO +++ b/TODO @@ -54,7 +54,6 @@ Low priority TODO == UI [bart] fix massive hotkeys when holding down a key -[bart] grid layout [bart] horizontal box layout [bart] move layout proprieties to widget style [bart] multiline text editor widget diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 271524a8..206af41f 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -189,8 +189,9 @@ SET(framework_SOURCES ${framework_SOURCES} ${CMAKE_CURRENT_LIST_DIR}/ui/uiwidgettext.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uiwidgetbasestyle.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uilineedit.cpp - ${CMAKE_CURRENT_LIST_DIR}/ui/uianchorlayout.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uiverticallayout.cpp + ${CMAKE_CURRENT_LIST_DIR}/ui/uigridlayout.cpp + ${CMAKE_CURRENT_LIST_DIR}/ui/uianchorlayout.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uilayout.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uiframecounter.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uitranslator.cpp diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 3d907325..24dd31fe 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -281,6 +281,17 @@ void Application::registerLuaFunctions() g_lua.bindClassStaticFunction("create", [](UIWidgetPtr parent){ return UIVerticalLayoutPtr(new UIVerticalLayout(parent)); } ); g_lua.bindClassMemberFunction("setFitParent", &UIVerticalLayout::setFitParent); + // UIGridLayout + g_lua.registerClass(); + g_lua.bindClassStaticFunction("create", [](UIWidgetPtr parent){ return UIGridLayoutPtr(new UIGridLayout(parent)); }); + g_lua.bindClassMemberFunction("setCellSize", &UIGridLayout::setCellSize); + g_lua.bindClassMemberFunction("setCellWidth", &UIGridLayout::setCellWidth); + g_lua.bindClassMemberFunction("setCellHeight", &UIGridLayout::setCellHeight); + g_lua.bindClassMemberFunction("setCellSpacing", &UIGridLayout::setCellSpacing); + g_lua.bindClassMemberFunction("setNumColumns", &UIGridLayout::setNumColumns); + g_lua.bindClassMemberFunction("setNumLines", &UIGridLayout::setNumLines); + g_lua.bindClassMemberFunction("asUIGridLayout", &UIGridLayout::asUIGridLayout); + // UIAnchorLayout g_lua.registerClass(); g_lua.bindClassStaticFunction("create", [](UIWidgetPtr parent){ return UIAnchorLayoutPtr(new UIAnchorLayout(parent)); } ); diff --git a/src/framework/ui/declarations.h b/src/framework/ui/declarations.h index 9ca8997d..4cde7dd8 100644 --- a/src/framework/ui/declarations.h +++ b/src/framework/ui/declarations.h @@ -31,6 +31,7 @@ class UILineEdit; class UIFrameCounter; class UILayout; class UIVerticalLayout; +class UIGridLayout; class UIAnchorLayout; typedef std::shared_ptr UIWidgetPtr; @@ -40,6 +41,7 @@ typedef std::shared_ptr UILineEditPtr; typedef std::shared_ptr UIFrameCounterPtr; typedef std::shared_ptr UILayoutPtr; typedef std::shared_ptr UIVerticalLayoutPtr; +typedef std::shared_ptr UIGridLayoutPtr; typedef std::shared_ptr UIAnchorLayoutPtr; typedef std::deque UIWidgetList; diff --git a/src/framework/ui/ui.h b/src/framework/ui/ui.h index f59f469e..1e157123 100644 --- a/src/framework/ui/ui.h +++ b/src/framework/ui/ui.h @@ -29,6 +29,7 @@ #include "uiframecounter.h" #include "uilayout.h" #include "uiverticallayout.h" +#include "uigridlayout.h" #include "uianchorlayout.h" #endif diff --git a/src/framework/ui/uigridlayout.cpp b/src/framework/ui/uigridlayout.cpp new file mode 100644 index 00000000..bf984113 --- /dev/null +++ b/src/framework/ui/uigridlayout.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2010-2012 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 "uigridlayout.h" +#include "uiwidget.h" + +UIGridLayout::UIGridLayout(UIWidgetPtr parentWidget): UILayout(parentWidget) +{ + m_cellSize = Size(16,16); + m_cellSpacing = 0; + m_numColumns = 1; + m_numLines = 1; +} + +void UIGridLayout::applyStyle(const OTMLNodePtr& styleNode) +{ + UILayout::applyStyle(styleNode); + + + for(const OTMLNodePtr& node : styleNode->children()) { + if(node->tag() == "cell-size") + setCellSize(node->value()); + else if(node->tag() == "cell-width") + setCellWidth(node->value()); + else if(node->tag() == "cell-height") + setCellHeight(node->value()); + else if(node->tag() == "cell-spacing") + setCellSpacing(node->value()); + else if(node->tag() == "num-columns") + setNumColumns(node->value()); + else if(node->tag() == "num-lines") + setNumLines(node->value()); + } +} + +void UIGridLayout::removeWidget(const UIWidgetPtr& widget) +{ + update(); +} + +void UIGridLayout::addWidget(const UIWidgetPtr& widget) +{ + update(); +} + +void UIGridLayout::internalUpdate() +{ + UIWidgetPtr parentWidget = getParentWidget(); + UIWidgetList widgets = parentWidget->getChildren(); + + Rect childrenRect = parentWidget->getChildrenRect(); + Point topLeft = childrenRect.topLeft(); + + int index = 0; + for(const UIWidgetPtr& widget : widgets) { + if(!widget->isExplicitlyVisible()) + continue; + + int line = index / m_numLines; + int column = index % m_numLines; + Point virtualPos = Point(column * (m_cellSize.width() + m_cellSpacing), line * (m_cellSize.height() + m_cellSpacing)); + Point pos = topLeft + virtualPos; + + widget->setRect(Rect(pos, m_cellSize)); + + index++; + + if(index >= m_numColumns * m_numLines) + break; + } +} + diff --git a/src/framework/ui/uigridlayout.h b/src/framework/ui/uigridlayout.h new file mode 100644 index 00000000..51534399 --- /dev/null +++ b/src/framework/ui/uigridlayout.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010-2012 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 UIGRIDLAYOUT_H +#define UIGRIDLAYOUT_H + +#include + +class UIGridLayout : public UILayout +{ +public: + UIGridLayout(UIWidgetPtr parentWidget); + + void applyStyle(const OTMLNodePtr& styleNode); + void removeWidget(const UIWidgetPtr& widget); + void addWidget(const UIWidgetPtr& widget); + + void setCellSize(const Size& size) { m_cellSize = size; update(); } + void setCellWidth(int width) { m_cellSize.setWidth(width); update(); } + void setCellHeight(int height) { m_cellSize.setHeight(height); update(); } + void setCellSpacing(int spacing) { m_cellSpacing = spacing; update(); } + void setNumColumns(int columns) { m_numColumns = columns; update(); } + void setNumLines(int lines) { m_numLines = lines; update(); } + + virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; } + +protected: + void internalUpdate(); + +private: + Size m_cellSize; + int m_cellSpacing; + int m_numColumns; + int m_numLines; +}; + +#endif + diff --git a/src/framework/ui/uilayout.h b/src/framework/ui/uilayout.h index f834c54e..dd1563e5 100644 --- a/src/framework/ui/uilayout.h +++ b/src/framework/ui/uilayout.h @@ -25,7 +25,7 @@ #include "declarations.h" #include -#include +#include class UILayout : public LuaObject { @@ -46,11 +46,11 @@ public: bool isUpdateDisabled() { return m_updateDisabled; } bool isUpdating() { return m_updating; } - virtual bool needsUpdatesOnChildChange() { return false; } UILayoutPtr asUILayout() { return std::static_pointer_cast(shared_from_this()); } virtual UIAnchorLayoutPtr asUIAnchorLayout() { return nullptr; } virtual UIVerticalLayoutPtr asUIVerticalLayout() { return nullptr; } + virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; } protected: virtual void internalUpdate() = 0; diff --git a/src/framework/ui/uirichtext.cpp b/src/framework/ui/uirichtext.cpp new file mode 100644 index 00000000..6334dc49 --- /dev/null +++ b/src/framework/ui/uirichtext.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2010-2012 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 "uirichtext.h" + diff --git a/src/framework/ui/uirichtext.h b/src/framework/ui/uirichtext.h new file mode 100644 index 00000000..dfad2720 --- /dev/null +++ b/src/framework/ui/uirichtext.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010-2012 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 UIRICHTEXT_H +#define UIRICHTEXT_H + +#include + + +class UIRichText : public UIWidget +{ +}; + +#endif // UIRICHTEXT_H diff --git a/src/framework/ui/uiverticallayout.cpp b/src/framework/ui/uiverticallayout.cpp index 2f81c6e3..2eb72088 100644 --- a/src/framework/ui/uiverticallayout.cpp +++ b/src/framework/ui/uiverticallayout.cpp @@ -22,7 +22,6 @@ #include "uiverticallayout.h" #include "uiwidget.h" -#include #include UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget) @@ -45,35 +44,6 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode) } } -void UIVerticalLayout::addWidget(const UIWidgetPtr& widget) -{ - update(); -} - -void UIVerticalLayout::removeWidget(const UIWidgetPtr& widget) -{ - update(); -} - -void UIVerticalLayout::setAlignBottom(bool aliginBottom) -{ - m_alignBottom = aliginBottom; - update(); -} - -void UIVerticalLayout::setSpacing(int spacing) -{ - m_spacing = spacing; - update(); -} - -void UIVerticalLayout::setFitParent(bool fitParent) -{ - m_fitParent = fitParent; - update(); -} - - void UIVerticalLayout::internalUpdate() { UIWidgetPtr parentWidget = getParentWidget(); diff --git a/src/framework/ui/uiverticallayout.h b/src/framework/ui/uiverticallayout.h index 5552326f..78e63156 100644 --- a/src/framework/ui/uiverticallayout.h +++ b/src/framework/ui/uiverticallayout.h @@ -31,14 +31,12 @@ public: UIVerticalLayout(UIWidgetPtr parentWidget); void applyStyle(const OTMLNodePtr& styleNode); - void addWidget(const UIWidgetPtr& widget); - void removeWidget(const UIWidgetPtr& widget); + void addWidget(const UIWidgetPtr& widget) { update(); } + void removeWidget(const UIWidgetPtr& widget) { update(); } - void setAlignBottom(bool aliginBottom); - void setSpacing(int spacing); - void setFitParent(bool fitParent); - - bool needsUpdatesOnChildChange() { return m_fitParent; } + void setAlignBottom(bool aliginBottom) { m_alignBottom = aliginBottom; update(); } + void setSpacing(int spacing) { m_spacing = spacing; update(); } + void setFitParent(bool fitParent) { m_fitParent = fitParent; update(); } UIVerticalLayoutPtr asUIVerticalLayout() { return std::static_pointer_cast(shared_from_this()); } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 935f3057..b089ec93 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -364,8 +364,8 @@ void UIWidget::unlockChild(const UIWidgetPtr& child) void UIWidget::applyStyle(const OTMLNodePtr& styleNode) { + m_loadingStyle = true; try { - m_loadingStyle = true; onStyleApply(styleNode->tag(), styleNode); callLuaField("onStyleApply", styleNode->tag(), styleNode); @@ -377,10 +377,10 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode) } m_firstOnStyle = false; - m_loadingStyle = false; } catch(Exception& e) { logError("Failed to apply style to widget '", m_id, "' style: ", e.what()); } + m_loadingStyle = false; } void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge) { diff --git a/src/framework/ui/uiwidgetbasestyle.cpp b/src/framework/ui/uiwidgetbasestyle.cpp index 3f4a9810..e28d7e90 100644 --- a/src/framework/ui/uiwidgetbasestyle.cpp +++ b/src/framework/ui/uiwidgetbasestyle.cpp @@ -21,8 +21,9 @@ */ #include "uiwidget.h" -#include "uianchorlayout.h" #include "uiverticallayout.h" +#include "uigridlayout.h" +#include "uianchorlayout.h" #include "uitranslator.h" #include @@ -233,6 +234,8 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode) UILayoutPtr layout; if(layoutType == "verticalBox") layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget())); + else if(layoutType == "grid") + layout = UIGridLayoutPtr(new UIGridLayout(asUIWidget())); else if(layoutType == "anchor") layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget())); else diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index 277a2443..70a2c288 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -31,7 +31,7 @@ class Item : public Thing public: Item(); - static ItemPtr create(int id = 0); + static ItemPtr create(int id); enum { TICKS_PER_FRAME = 500 diff --git a/src/otclient/net/protocolcodes.h b/src/otclient/net/protocolcodes.h index 82188b59..399b1fd0 100644 --- a/src/otclient/net/protocolcodes.h +++ b/src/otclient/net/protocolcodes.h @@ -308,7 +308,7 @@ namespace Proto { case Proto::SpeakYell: return "yell"; case Proto::SpeakMonsterSay: - return "monsterSay"; + return "monsterSay"; case Proto::SpeakMonsterYell: return "monsterYell"; case Proto::SpeakPrivateNpcToPlayer: diff --git a/src/otclient/net/protocolgame.h b/src/otclient/net/protocolgame.h index 5dc1c489..a8e15421 100644 --- a/src/otclient/net/protocolgame.h +++ b/src/otclient/net/protocolgame.h @@ -60,18 +60,18 @@ public: void sendPlayerPurchase(int thingId, int count, int amount, bool ignoreCapacity, bool buyWithBackpack); void sendPlayerSale(int thingId, int count, int amount, bool ignoreEquipped); void sendCloseShop(); - void sendRequestTrade(const Position& pos, int thingId, int stackpos, int playerId); + void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId); void sendLookInTrade(bool counterOffer, int index); void sendAcceptTrade(); void sendRejectTrade(); void sendUseItem(const Position& position, int itemId, int stackpos, int index); void sendUseItemEx(const Position& fromPos, int fromThingId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos); - void sendUseItemCreature(const Position& pos, int thingId, int stackpos, int creatureId); + void sendUseItemCreature(const Position& pos, int thingId, int stackpos, uint creatureId); void sendRotateItem(const Position& pos, int thingId, int stackpos); void sendCloseContainer(int containerId); void sendUpContainer(int containerId); - void sendTextWindow(int windowTextId, const std::string& text); - void sendHouseWindow(int doorId, int id, const std::string& text); + void sendTextWindow(uint windowTextId, const std::string& text); + void sendHouseWindow(int doorId, uint id, const std::string& text); void sendLookAt(const Position& position, int thingId, int stackpos); void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message); void sendGetChannels(); @@ -80,12 +80,12 @@ public: void sendPrivateChannel(const std::string& receiver); void sendCloseNpcChannel(); void sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes chaseMode, bool safeFight); - void sendAttack(int creatureId); - void sendFollow(int creatureId); - void sendInviteToParty(int creatureId); - void sendJoinParty(int creatureId); - void sendRevokeInvitation(int creatureId); - void sendPassLeadership(int creatureId); + void sendAttack(uint creatureId); + void sendFollow(uint creatureId); + void sendInviteToParty(uint creatureId); + void sendJoinParty(uint creatureId); + void sendRevokeInvitation(uint creatureId); + void sendPassLeadership(uint creatureId); void sendLeaveParty(); void sendShareExperience(bool active, int unknown); void sendOpenChannel(); @@ -96,12 +96,12 @@ public: void sendGetOutfit(); void sendSetOutfit(const Outfit& outfit); void sendAddVip(const std::string& name); - void sendRemoveVip(int playerId); + void sendRemoveVip(uint playerId); void sendGetQuestLog(); void sendGetQuestLine(int questId); private: - void sendLoginPacket(uint32 timestamp, uint8 unknown); + void sendLoginPacket(uint timestamp, uint8 unknown); // Parse Messages void parseMessage(InputMessage& msg); @@ -173,13 +173,13 @@ private: void parseQuestList(InputMessage& msg); void parseQuestPartList(InputMessage& msg); - void setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height); - void setFloorDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height, int32 offset, int32* skipTiles); + void setMapDescription(InputMessage& msg, int x, int y, int z, int width, int height); + void setFloorDescription(InputMessage& msg, int x, int y, int z, int width, int height, int offset, int* skipTiles); void setTileDescription(InputMessage& msg, Position position); Outfit internalGetOutfit(InputMessage& msg); ThingPtr internalGetThing(InputMessage& msg); - ItemPtr internalGetItem(InputMessage& msg, uint16 id); + ItemPtr internalGetItem(InputMessage& msg, int id = 0); void addPosition(OutputMessage& msg, const Position& position); Position parsePosition(InputMessage& msg); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index c15097ec..9fcfe145 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -37,7 +37,7 @@ void ProtocolGame::parseMessage(InputMessage& msg) { try { while(!msg.eof()) { - uint8 opt = msg.getU8(); + int opt = msg.getU8(); switch(opt) { case Proto::GameServerInitGame: @@ -267,7 +267,7 @@ void ProtocolGame::parseMessage(InputMessage& msg) void ProtocolGame::parsePlayerLogin(InputMessage& msg) { - int playerId = msg.getU32(); + uint playerId = msg.getU32(); int serverBeat = msg.getU16(); int playerCanReportBugs = msg.getU8(); @@ -279,7 +279,7 @@ void ProtocolGame::parsePlayerLogin(InputMessage& msg) void ProtocolGame::parseGMActions(InputMessage& msg) { - for(uint8 i = 0; i < Proto::NumViolationReasons; ++i) + for(int i = 0; i < Proto::NumViolationReasons; ++i) msg.getU8(); } @@ -359,7 +359,7 @@ void ProtocolGame::parseMoveWest(InputMessage& msg) void ProtocolGame::parseUpdateTile(InputMessage& msg) { Position tilePos = parsePosition(msg); - uint16 thingId = msg.getU16(true); + int thingId = msg.getU16(true); if(thingId == 0xFF01) { msg.getU16(); } else { @@ -371,7 +371,7 @@ void ProtocolGame::parseUpdateTile(InputMessage& msg) void ProtocolGame::parseTileAddThing(InputMessage& msg) { Position pos = parsePosition(msg); - uint8 stackPos = msg.getU8(); + int stackPos = msg.getU8(); ThingPtr thing = internalGetThing(msg); g_map.addThing(thing, pos, stackPos); @@ -380,13 +380,13 @@ void ProtocolGame::parseTileAddThing(InputMessage& msg) void ProtocolGame::parseTileTransformThing(InputMessage& msg) { Position pos = parsePosition(msg); - uint8 stackPos = msg.getU8(); + int stackPos = msg.getU8(); - uint16 thingId = msg.getU16(); + int thingId = msg.getU16(); + assert(thingId != 0); if(thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) { parseCreatureTurn(msg); - } - else { + } else { ThingPtr thing = internalGetItem(msg, thingId); g_map.removeThingByPos(pos, stackPos); g_map.addThing(thing, pos, stackPos); @@ -396,7 +396,7 @@ void ProtocolGame::parseTileTransformThing(InputMessage& msg) void ProtocolGame::parseTileRemoveThing(InputMessage& msg) { Position pos = parsePosition(msg); - uint8 stackPos = msg.getU8(); + int stackPos = msg.getU8(); g_map.removeThingByPos(pos, stackPos); } @@ -404,7 +404,7 @@ void ProtocolGame::parseTileRemoveThing(InputMessage& msg) void ProtocolGame::parseCreatureMove(InputMessage& msg) { Position oldPos = parsePosition(msg); - uint8 oldStackpos = msg.getU8(); + int oldStackpos = msg.getU8(); Position newPos = parsePosition(msg); ThingPtr thing = g_map.getTile(oldPos)->getThing(oldStackpos); @@ -435,10 +435,10 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg) msg.getString(); // name msg.getU8(); // capacity msg.getU8(); // hasParent - uint8 size = msg.getU8(); // size + int size = msg.getU8(); // size - for(uint32 i = 0; i < size; i++) - internalGetItem(msg, 0xFFFF); + for(int i = 0; i < size; i++) + internalGetItem(msg); } void ProtocolGame::parseCloseContainer(InputMessage& msg) @@ -449,14 +449,14 @@ void ProtocolGame::parseCloseContainer(InputMessage& msg) void ProtocolGame::parseContainerAddItem(InputMessage& msg) { msg.getU8(); // cid - internalGetItem(msg, 0xFFFF); + internalGetItem(msg); } void ProtocolGame::parseContainerUpdateItem(InputMessage& msg) { msg.getU8(); // cid msg.getU8(); // slot - internalGetItem(msg, 0xFFFF); + internalGetItem(msg); } void ProtocolGame::parseContainerRemoveItem(InputMessage& msg) @@ -467,21 +467,21 @@ void ProtocolGame::parseContainerRemoveItem(InputMessage& msg) void ProtocolGame::parseAddInventoryItem(InputMessage& msg) { - uint8 slot = msg.getU8(); - ItemPtr item = internalGetItem(msg, 0xFFFF); + int slot = msg.getU8(); + ItemPtr item = internalGetItem(msg); g_game.processInventoryChange(slot, item); } void ProtocolGame::parseRemoveInventoryItem(InputMessage& msg) { - uint8 slot = msg.getU8(); + int slot = msg.getU8(); g_game.processInventoryChange(slot, ItemPtr()); } void ProtocolGame::parseOpenShopWindow(InputMessage& msg) { - uint8 listCount = msg.getU8(); - for(uint8 i = 0; i < listCount; ++i) { + int listCount = msg.getU8(); + for(int i = 0; i < listCount; ++i) { msg.getU16(); // item id msg.getU8(); // runecharges msg.getString(); // item name @@ -494,7 +494,7 @@ void ProtocolGame::parseOpenShopWindow(InputMessage& msg) void ProtocolGame::parsePlayerCash(InputMessage& msg) { msg.getU32(); - uint8 size = msg.getU8(); + int size = msg.getU8(); for(int i = 0; i < size; i++) { msg.getU16(); // itemid @@ -509,10 +509,10 @@ void ProtocolGame::parseCloseShopWindow(InputMessage&) void ProtocolGame::parseSafeTradeRequest(InputMessage& msg) { msg.getString(); // name - uint8 count = msg.getU8(); + int count = msg.getU8(); - for(uint8 i = 0; i < count; i++) - internalGetItem(msg, 0xFFFF); + for(int i = 0; i < count; i++) + internalGetItem(msg); } void ProtocolGame::parseSafeTradeClose(InputMessage&) @@ -542,7 +542,7 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg) void ProtocolGame::parseAnimatedText(InputMessage& msg) { Position position = parsePosition(msg); - uint8 color = msg.getU8(); + int color = msg.getU8(); std::string text = msg.getString(); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); @@ -566,8 +566,8 @@ void ProtocolGame::parseDistanceMissile(InputMessage& msg) void ProtocolGame::parseCreatureSquare(InputMessage& msg) { - uint32 id = msg.getU32(); - uint8 color = msg.getU8(); + uint id = msg.getU32(); + int color = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -576,8 +576,8 @@ void ProtocolGame::parseCreatureSquare(InputMessage& msg) void ProtocolGame::parseCreatureHealth(InputMessage& msg) { - uint32 id = msg.getU32(); - uint8 healthPercent = msg.getU8(); + uint id = msg.getU32(); + int healthPercent = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -586,7 +586,7 @@ void ProtocolGame::parseCreatureHealth(InputMessage& msg) void ProtocolGame::parseCreatureLight(InputMessage& msg) { - uint32 id = msg.getU32(); + uint id = msg.getU32(); Light light; light.intensity = msg.getU8(); @@ -599,7 +599,7 @@ void ProtocolGame::parseCreatureLight(InputMessage& msg) void ProtocolGame::parseCreatureOutfit(InputMessage& msg) { - uint32 id = msg.getU32(); + uint id = msg.getU32(); Outfit outfit = internalGetOutfit(msg); CreaturePtr creature = g_map.getCreatureById(id); @@ -609,8 +609,8 @@ void ProtocolGame::parseCreatureOutfit(InputMessage& msg) void ProtocolGame::parseCreatureSpeed(InputMessage& msg) { - uint32 id = msg.getU32(); - uint16 speed = msg.getU16(); + uint id = msg.getU32(); + int speed = msg.getU16(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -619,8 +619,8 @@ void ProtocolGame::parseCreatureSpeed(InputMessage& msg) void ProtocolGame::parseCreatureSkulls(InputMessage& msg) { - uint32 id = msg.getU32(); - uint8 skull = msg.getU8(); + uint id = msg.getU32(); + int skull = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -629,8 +629,8 @@ void ProtocolGame::parseCreatureSkulls(InputMessage& msg) void ProtocolGame::parseCreatureShields(InputMessage& msg) { - uint32 id = msg.getU32(); - uint8 shield = msg.getU8(); + uint id = msg.getU32(); + int shield = msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); if(creature) @@ -639,7 +639,7 @@ void ProtocolGame::parseCreatureShields(InputMessage& msg) void ProtocolGame::parseCreatureTurn(InputMessage& msg) { - uint32 id = msg.getU32(); + uint id = msg.getU32(); Otc::Direction direction = (Otc::Direction)msg.getU8(); CreaturePtr creature = g_map.getCreatureById(id); @@ -744,7 +744,7 @@ void ProtocolGame::parsePlayerSkills(InputMessage& msg) void ProtocolGame::parsePlayerIcons(InputMessage& msg) { - uint16 icons = msg.getU16(); + int icons = msg.getU16(); m_localPlayer->setIcons((Otc::PlayerIcons)icons); } @@ -837,7 +837,7 @@ void ProtocolGame::parseClosePrivateChannel(InputMessage& msg) void ProtocolGame::parseTextMessage(InputMessage& msg) { - uint8 type = msg.getU8(); + int type = msg.getU8(); std::string typeDesc = Proto::translateTextMessageType(type); std::string message = msg.getString(); @@ -857,9 +857,9 @@ void ProtocolGame::parseFloorChangeUp(InputMessage& msg) Position pos = g_map.getCentralPosition(); pos.z--; - int32 skip = 0; + int skip = 0; if(pos.z == 7) - for(int32 i = 5; i >= 0; i--) + for(int i = 5; i >= 0; i--) setFloorDescription(msg, pos.x - 8, pos.y - 6, i, 18, 14, 8 - i, &skip); else if(pos.z > 7) setFloorDescription(msg, pos.x - 8, pos.y - 6, pos.z - 2, 18, 14, 3, &skip); @@ -913,7 +913,7 @@ void ProtocolGame::parseOutfitWindow(InputMessage& msg) void ProtocolGame::parseVipState(InputMessage& msg) { - int id = msg.getU32(); + uint id = msg.getU32(); std::string name = msg.getString(); bool online = msg.getU8() != 0; @@ -922,14 +922,14 @@ void ProtocolGame::parseVipState(InputMessage& msg) void ProtocolGame::parseVipLogin(InputMessage& msg) { - int id = msg.getU32(); + uint id = msg.getU32(); g_lua.callGlobalField("Game", "onVipStateChange", id, true); } void ProtocolGame::parseVipLogout(InputMessage& msg) { - int id = msg.getU32(); + uint id = msg.getU32(); g_lua.callGlobalField("Game", "onVipStateChange", id, false); } @@ -948,8 +948,8 @@ void ProtocolGame::parseAddMarker(InputMessage& msg) void ProtocolGame::parseQuestList(InputMessage& msg) { - uint16 questsCount = msg.getU16(); - for(uint16 i = 0; i < questsCount; i++) { + int questsCount = msg.getU16(); + for(int i = 0; i < questsCount; i++) { msg.getU16(); // quest id msg.getString(); // quest name msg.getU8(); // quest state @@ -959,8 +959,8 @@ void ProtocolGame::parseQuestList(InputMessage& msg) void ProtocolGame::parseQuestPartList(InputMessage& msg) { msg.getU16(); // quest id - uint8 missionCount = msg.getU8(); - for(uint8 i = 0; i < missionCount; i++) { + int missionCount = msg.getU8(); + for(int i = 0; i < missionCount; i++) { msg.getString(); // quest name msg.getString(); // quest description } @@ -987,12 +987,12 @@ void ProtocolGame::setMapDescription(InputMessage& msg, int32 x, int32 y, int32 void ProtocolGame::setFloorDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height, int32 offset, int32* skipTiles) { - int32 skip = *skipTiles; + int skip = *skipTiles; - for(int32 nx = 0; nx < width; nx++) { - for(int32 ny = 0; ny < height; ny++) { + for(int nx = 0; nx < width; nx++) { + for(int ny = 0; ny < height; ny++) { if(skip == 0) { - uint16 tileOpt = msg.getU16(true); + int tileOpt = msg.getU16(true); if(tileOpt >= 0xFF00) skip = (msg.getU16() & 0xFF); else { @@ -1014,7 +1014,7 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position) int stackPos = 0; while(true) { - uint16 inspectTileId = msg.getU16(true); + int inspectTileId = msg.getU16(true); if(inspectTileId >= 0xFF00) return; else { @@ -1022,7 +1022,8 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position) logTraceError("too many things, stackpos=", stackPos, " pos=", position); ThingPtr thing = internalGetThing(msg); - g_map.addThing(thing, position, 255); + if(thing) + g_map.addThing(thing, position, 255); } stackPos++; } @@ -1032,14 +1033,14 @@ Outfit ProtocolGame::internalGetOutfit(InputMessage& msg) { Outfit outfit; - uint16 id = msg.getU16(); + int id = msg.getU16(); if(id != 0) { outfit.setCategory(ThingsType::Creature); - uint8 head = msg.getU8(); - uint8 body = msg.getU8(); - uint8 legs = msg.getU8(); - uint8 feet = msg.getU8(); - uint8 addons = msg.getU8(); + int head = msg.getU8(); + int body = msg.getU8(); + int legs = msg.getU8(); + int feet = msg.getU8(); + int addons = msg.getU8(); outfit.setId(id); outfit.setHead(head); @@ -1049,7 +1050,7 @@ Outfit ProtocolGame::internalGetOutfit(InputMessage& msg) outfit.setAddons(addons); } else { - uint16 id = msg.getU16(); + int id = msg.getU16(); if(id == 0) { outfit.setCategory(ThingsType::Effect); outfit.setId(13); @@ -1067,12 +1068,13 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) { ThingPtr thing; - uint16 thingId = msg.getU16(); + int thingId = msg.getU16(); + assert(thingId != 0); if(thingId == 0x0061 || thingId == 0x0062) { // add new creature CreaturePtr creature; if(thingId == 0x0062) { //creature is known - uint32 id = msg.getU32(); + uint id = msg.getU32(); CreaturePtr knownCreature = g_map.getCreatureById(id); if(knownCreature) @@ -1080,8 +1082,8 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) else logTraceError("server says creature is known, but its not on creatures list"); } else if(thingId == 0x0061) { //creature is not known - uint32 removeId = msg.getU32(); - uint32 id = msg.getU32(); + uint removeId = msg.getU32(); + uint id = msg.getU32(); std::string name = msg.getString(); if(name.length() > 0) // every creature name must start with a capital letter @@ -1112,11 +1114,11 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) light.intensity = msg.getU8(); light.color = msg.getU8(); - uint16 speed = msg.getU16(); - uint8 skull = msg.getU8(); - uint8 shield = msg.getU8(); + int speed = msg.getU16(); + int skull = msg.getU8(); + int shield = msg.getU8(); - uint8 emblem = 0; + int emblem = 0; if(thingId == 0x0061) // emblem is sent only in packet type 0x61 emblem = msg.getU8(); @@ -1144,9 +1146,9 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg) return thing; } -ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, uint16 id) +ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, int id) { - if(id == 0xFFFF) + if(id == 0) id = msg.getU16(); ItemPtr item = Item::create(id); diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index b5de456e..493c01ef 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -23,7 +23,7 @@ #include "protocolgame.h" #include -void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown) +void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown) { OutputMessage oMsg; @@ -217,7 +217,7 @@ void ProtocolGame::sendCloseShop() send(oMsg); } -void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, int playerId) +void ProtocolGame::sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientTradeObject); @@ -275,7 +275,7 @@ void ProtocolGame::sendUseItemEx(const Position& fromPos, int fromThingId, int f send(oMsg); } -void ProtocolGame::sendUseItemCreature(const Position& pos, int thingId, int stackpos, int creatureId) +void ProtocolGame::sendUseItemCreature(const Position& pos, int thingId, int stackpos, uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientUseOnCreature); @@ -312,7 +312,7 @@ void ProtocolGame::sendUpContainer(int containerId) send(oMsg); } -void ProtocolGame::sendTextWindow(int windowTextId, const std::string& text) +void ProtocolGame::sendTextWindow(uint windowTextId, const std::string& text) { OutputMessage oMsg; oMsg.addU8(Proto::ClientEditText); @@ -321,7 +321,7 @@ void ProtocolGame::sendTextWindow(int windowTextId, const std::string& text) send(oMsg); } -void ProtocolGame::sendHouseWindow(int doorId, int id, const std::string& text) +void ProtocolGame::sendHouseWindow(int doorId, uint id, const std::string& text) { OutputMessage oMsg; oMsg.addU8(Proto::ClientEditList); @@ -420,7 +420,7 @@ void ProtocolGame::sendFightTatics(Otc::FightModes fightMode, Otc::ChaseModes ch send(oMsg); } -void ProtocolGame::sendAttack(int creatureId) +void ProtocolGame::sendAttack(uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientAttack); @@ -430,7 +430,7 @@ void ProtocolGame::sendAttack(int creatureId) send(oMsg); } -void ProtocolGame::sendFollow(int creatureId) +void ProtocolGame::sendFollow(uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientFollow); @@ -438,7 +438,7 @@ void ProtocolGame::sendFollow(int creatureId) send(oMsg); } -void ProtocolGame::sendInviteToParty(int creatureId) +void ProtocolGame::sendInviteToParty(uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientInviteToParty); @@ -446,7 +446,7 @@ void ProtocolGame::sendInviteToParty(int creatureId) send(oMsg); } -void ProtocolGame::sendJoinParty(int creatureId) +void ProtocolGame::sendJoinParty(uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientJoinParty); @@ -454,7 +454,7 @@ void ProtocolGame::sendJoinParty(int creatureId) send(oMsg); } -void ProtocolGame::sendRevokeInvitation(int creatureId) +void ProtocolGame::sendRevokeInvitation(uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientRevokeInvitation); @@ -462,7 +462,7 @@ void ProtocolGame::sendRevokeInvitation(int creatureId) send(oMsg); } -void ProtocolGame::sendPassLeadership(int creatureId) +void ProtocolGame::sendPassLeadership(uint creatureId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientPassLeadership); @@ -555,7 +555,7 @@ void ProtocolGame::sendAddVip(const std::string& name) send(oMsg); } -void ProtocolGame::sendRemoveVip(int playerId) +void ProtocolGame::sendRemoveVip(uint playerId) { OutputMessage oMsg; oMsg.addU8(Proto::ClientRemoveBuddy); diff --git a/src/otclient/net/protocollogin.cpp b/src/otclient/net/protocollogin.cpp index 188ca691..a01e24d9 100644 --- a/src/otclient/net/protocollogin.cpp +++ b/src/otclient/net/protocollogin.cpp @@ -55,7 +55,7 @@ void ProtocolLogin::onRecv(InputMessage& inputMessage) { try { while(!inputMessage.eof()) { - uint8 opt = inputMessage.getU8(); + int opt = inputMessage.getU8(); switch(opt) { case Proto::LoginServerError: parseError(inputMessage);