mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
restore some game functionallity
* i'm gradually restoring game functionality with the new modules design, though still a lot to do * you can reload all scripts and modules using Ctrl+R shortcut while playing (finally! this is the reason of all this rework) * a bunch of fixes, but new regression too :P * fix performance issue that could lead freezes in the client in older machines * completely new game module with new design * fix crashs in map render * remove uigame.cpp (now every game input is via lua) * enable DEBUG macro by default, with it you are able to view any possible lua leak while running
This commit is contained in:
@@ -50,15 +50,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++ -Wl,--as-needed")
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
ADD_DEFINITIONS(-DDEBUG)
|
||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
||||
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
# NDEBUG disable asserts
|
||||
ADD_DEFINITIONS(-DNDEBUG)
|
||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
|
||||
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
IF(USE_OPENGL_ES2)
|
||||
MESSAGE(STATUS "Renderer: OpenGL ES 2.0")
|
||||
@@ -66,6 +57,18 @@ ELSE(USE_OPENGL_ES2)
|
||||
MESSAGE(STATUS "Renderer: OpenGL")
|
||||
ENDIF(USE_OPENGL_ES2)
|
||||
|
||||
IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
ADD_DEFINITIONS(-DDEBUG)
|
||||
MESSAGE(STATUS "Debug information: ON")
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Debug information: OFF")
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
# NDEBUG disable asserts
|
||||
ADD_DEFINITIONS(-DNDEBUG)
|
||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
|
||||
IF(CRASH_HANDLER)
|
||||
ADD_DEFINITIONS(-DCRASH_HANDLER)
|
||||
MESSAGE(STATUS "Crash handler: ON")
|
||||
|
@@ -219,10 +219,7 @@ void Application::poll()
|
||||
|
||||
void Application::close()
|
||||
{
|
||||
g_lua.getGlobalField("g_app", "onClose");
|
||||
if(!g_lua.isNil())
|
||||
g_lua.protectedCall();
|
||||
else
|
||||
if(!g_lua.callGlobalField<bool>("g_app", "onClose"))
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@@ -362,6 +362,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("setTextHidden", &UILineEdit::setTextHidden);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("setAlwaysActive", &UILineEdit::setAlwaysActive);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("setValidCharacters", &UILineEdit::setValidCharacters);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("setShiftNavigation", &UILineEdit::setShiftNavigation);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("moveCursor", &UILineEdit::moveCursor);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("appendText", &UILineEdit::appendText);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("removeCharacter", &UILineEdit::removeCharacter);
|
||||
@@ -372,6 +373,7 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("isCursorEnabled", &UILineEdit::isCursorEnabled);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("isAlwaysActive", &UILineEdit::isAlwaysActive);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("isTextHidden", &UILineEdit::isTextHidden);
|
||||
g_lua.bindClassMemberFunction<UILineEdit>("isShiftNavigation", &UILineEdit::isShiftNavigation);
|
||||
|
||||
// UIFrameCounter
|
||||
g_lua.registerClass<UIFrameCounter, UIWidget>();
|
||||
|
@@ -35,6 +35,7 @@ UILineEdit::UILineEdit()
|
||||
m_textHorizontalMargin = 0;
|
||||
m_textHidden = false;
|
||||
m_alwaysActive = false;
|
||||
m_shiftNavigation = false;
|
||||
blinkCursor();
|
||||
}
|
||||
|
||||
@@ -407,8 +408,8 @@ void UILineEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
|
||||
setTextHorizontalMargin(node->value<int>());
|
||||
else if(node->tag() == "always-active")
|
||||
setAlwaysActive(node->value<bool>());
|
||||
//else if(node->tag() == "disable-arrow-navitation")
|
||||
// setArrowNavigation(node->value<bool>());
|
||||
else if(node->tag() == "shift-navigation")
|
||||
setShiftNavigation(node->value<bool>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,28 +435,46 @@ bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
|
||||
if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
|
||||
return true;
|
||||
|
||||
if(keyCode == Fw::KeyDelete) // erase right character
|
||||
removeCharacter(true);
|
||||
else if(keyCode == Fw::KeyBackspace) // erase left character {
|
||||
removeCharacter(false);
|
||||
else if(keyCode == Fw::KeyRight) // move cursor right
|
||||
moveCursor(true);
|
||||
else if(keyCode == Fw::KeyLeft) // move cursor left
|
||||
moveCursor(false);
|
||||
else if(keyCode == Fw::KeyHome) // move cursor to first character
|
||||
setCursorPos(0);
|
||||
else if(keyCode == Fw::KeyEnd) // move cursor to last character
|
||||
setCursorPos(m_text.length());
|
||||
else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
|
||||
appendText(g_window.getClipboardText());
|
||||
else if(keyCode == Fw::KeyTab) {
|
||||
if(!m_alwaysActive) {
|
||||
if(keyboardModifiers == Fw::KeyboardNoModifier) {
|
||||
if(keyCode == Fw::KeyDelete) { // erase right character
|
||||
removeCharacter(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyBackspace) { // erase left character {
|
||||
removeCharacter(false);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
|
||||
moveCursor(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left
|
||||
moveCursor(false);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyHome) { // move cursor to first character
|
||||
setCursorPos(0);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyEnd) { // move cursor to last character
|
||||
setCursorPos(m_text.length());
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->focusNextChild(Fw::KeyboardFocusReason);
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
return true;
|
||||
} else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
|
||||
if(keyCode == Fw::KeyV) {
|
||||
appendText(g_window.getClipboardText());
|
||||
return true;
|
||||
}
|
||||
} else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
|
||||
if(keyCode == Fw::KeyRight && m_shiftNavigation) { // move cursor right
|
||||
moveCursor(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft && m_shiftNavigation) { // move cursor left
|
||||
moveCursor(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UILineEdit::onKeyText(const std::string& keyText)
|
||||
|
@@ -42,6 +42,7 @@ public:
|
||||
void setTextHidden(bool hidden);
|
||||
void setAlwaysActive(bool enable);
|
||||
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
|
||||
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
|
||||
|
||||
void moveCursor(bool right);
|
||||
void appendText(std::string text);
|
||||
@@ -55,6 +56,7 @@ public:
|
||||
bool isCursorEnabled() { return m_cursorPos != -1; }
|
||||
bool isAlwaysActive() { return m_alwaysActive; }
|
||||
bool isTextHidden() { return m_textHidden; }
|
||||
bool isShiftNavigation() { return m_shiftNavigation; }
|
||||
|
||||
protected:
|
||||
virtual void onTextChange(const std::string& text, const std::string& oldText);
|
||||
@@ -77,6 +79,7 @@ private:
|
||||
int m_textHorizontalMargin;
|
||||
bool m_textHidden;
|
||||
bool m_alwaysActive;
|
||||
bool m_shiftNavigation;
|
||||
std::string m_validCharacters;
|
||||
|
||||
std::vector<Rect> m_glyphsCoords;
|
||||
|
@@ -319,7 +319,12 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
/*
|
||||
UIWidgetPtr UIManager::loadWidgetFromStyle()
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent)
|
||||
{
|
||||
OTMLNodePtr originalStyleNode = getStyle(widgetNode->tag());
|
||||
|
@@ -206,7 +206,7 @@ void UIWidget::removeChild(UIWidgetPtr child)
|
||||
|
||||
g_ui.onWidgetDisappear(child);
|
||||
} else
|
||||
logError("Attempt to remove an unknown child from a UIWidget");
|
||||
logError("attempt to remove an unknown child from a UIWidget");
|
||||
}
|
||||
|
||||
|
||||
@@ -637,11 +637,12 @@ void UIWidget::destroy()
|
||||
|
||||
// remove itself from parent
|
||||
if(UIWidgetPtr parent = getParent()) {
|
||||
if(parent->hasChild(asUIWidget()))
|
||||
parent->removeChild(asUIWidget());
|
||||
assert(parent->hasChild(asUIWidget()));
|
||||
parent->removeChild(asUIWidget());
|
||||
}
|
||||
|
||||
destroyChildren();
|
||||
m_focusedChild = nullptr;
|
||||
|
||||
callLuaField("onDestroy");
|
||||
|
||||
@@ -649,12 +650,13 @@ void UIWidget::destroy()
|
||||
|
||||
#ifdef DEBUG
|
||||
auto self = asUIWidget();
|
||||
g_lua.collectGarbage();
|
||||
if(self != g_ui.getRootWidget()) {
|
||||
g_eventDispatcher.scheduleEvent([self] {
|
||||
g_lua.collectGarbage();
|
||||
if(self->getUseCount() != 1)
|
||||
logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left");
|
||||
}, 100);
|
||||
}, 500);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -51,6 +51,9 @@ void UIWidget::drawText(const Rect& screenCoords)
|
||||
if(m_text.length() == 0 || m_color.a() == 0)
|
||||
return;
|
||||
|
||||
#if 0
|
||||
//TODO: creating framebuffers on the fly was slowing down the render
|
||||
// we should use vertex arrys instead of this method
|
||||
Size boxSize = screenCoords.size();
|
||||
if(boxSize != m_textCachedBoxSize || m_textMustRecache) {
|
||||
if(!m_textFramebuffer)
|
||||
@@ -73,6 +76,11 @@ void UIWidget::drawText(const Rect& screenCoords)
|
||||
|
||||
g_painter.setColor(m_color);
|
||||
m_textFramebuffer->draw(screenCoords);
|
||||
#else
|
||||
Rect textRect = screenCoords;
|
||||
textRect.translate(m_textOffset);
|
||||
m_font->renderText(m_text, textRect, m_textAlign, m_color);
|
||||
#endif
|
||||
}
|
||||
|
||||
void UIWidget::onTextChange(const std::string& text, const std::string& oldText)
|
||||
|
@@ -31,6 +31,7 @@ SET(otclient_SOURCES ${otclient_SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/thingstype.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/spritemanager.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/item.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/container.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/tile.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/thing.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/core/creature.cpp
|
||||
|
23
src/otclient/core/container.cpp
Normal file
23
src/otclient/core/container.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 "container.h"
|
@@ -20,17 +20,16 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef UIGAME_H
|
||||
#define UIGAME_H
|
||||
#ifndef CONTAINER_H
|
||||
#define CONTAINER_H
|
||||
|
||||
#include "declarations.h"
|
||||
#include <framework/ui/uiwidget.h>
|
||||
|
||||
class UIGame : public UIWidget
|
||||
class Container
|
||||
{
|
||||
protected:
|
||||
bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
||||
bool onKeyText(const std::string& keyText);
|
||||
public:
|
||||
Container();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@@ -31,6 +31,7 @@ class MapView;
|
||||
class Tile;
|
||||
class Thing;
|
||||
class Item;
|
||||
class Container;
|
||||
class Creature;
|
||||
class Monster;
|
||||
class Npc;
|
||||
@@ -45,6 +46,7 @@ typedef std::shared_ptr<MapView> MapViewPtr;
|
||||
typedef std::shared_ptr<Tile> TilePtr;
|
||||
typedef std::shared_ptr<Thing> ThingPtr;
|
||||
typedef std::shared_ptr<Item> ItemPtr;
|
||||
typedef std::shared_ptr<Container> ContainerPtr;
|
||||
typedef std::shared_ptr<Creature> CreaturePtr;
|
||||
typedef std::shared_ptr<Monster> MonsterPtr;
|
||||
typedef std::shared_ptr<Npc> NpcPtr;
|
||||
|
@@ -764,7 +764,6 @@ void Game::setSafeFight(bool on)
|
||||
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
|
||||
}
|
||||
|
||||
|
||||
void Game::inspectNpcTrade(const ItemPtr& item)
|
||||
{
|
||||
if(!canPerformGameAction() || !item)
|
||||
|
@@ -216,6 +216,7 @@ public:
|
||||
bool isAttacking() { return !!m_attackingCreature; }
|
||||
bool isFollowing() { return !!m_followingCreature; }
|
||||
|
||||
ContainerPtr getContainer(int index) { return m_containers[index]; }
|
||||
CreaturePtr getAttackingCreature() { return m_attackingCreature; }
|
||||
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
||||
int getServerBeat() { return m_serverBeat; }
|
||||
@@ -231,6 +232,7 @@ private:
|
||||
CreaturePtr m_attackingCreature;
|
||||
CreaturePtr m_followingCreature;
|
||||
ProtocolGamePtr m_protocolGame;
|
||||
std::map<int, ContainerPtr> m_containers;
|
||||
bool m_dead;
|
||||
int m_serverBeat;
|
||||
Otc::FightModes m_fightMode;
|
||||
|
@@ -36,12 +36,17 @@
|
||||
|
||||
MapView::MapView()
|
||||
{
|
||||
m_viewRange = NEAR_VIEW;
|
||||
m_lockedFirstVisibleFloor = -1;
|
||||
m_cachedFirstVisibleFloor = 0;
|
||||
m_cachedLastVisibleFloor = 7;
|
||||
m_customCameraPosition.z = 7;
|
||||
|
||||
Size frameBufferSize(std::min(g_graphics.getMaxTextureSize(), (int)DEFAULT_FRAMBUFFER_WIDTH),
|
||||
std::min(g_graphics.getMaxTextureSize(), (int)DEFAULT_FRAMBUFFER_HEIGHT));
|
||||
|
||||
m_framebuffer = FrameBufferPtr(new FrameBuffer(frameBufferSize));
|
||||
m_framebuffer->setClearColor(Fw::black);
|
||||
m_lockedFirstVisibleFloor = -1;
|
||||
setVisibleDimension(Size(15, 11));
|
||||
|
||||
m_shaderProgram = PainterShaderProgramPtr(new PainterShaderProgram);
|
||||
@@ -374,7 +379,6 @@ void MapView::unlockFirstVisibleFloor()
|
||||
void MapView::followCreature(const CreaturePtr& creature)
|
||||
{
|
||||
m_followingCreature = creature;
|
||||
m_customCameraPosition = Position();
|
||||
requestVisibleTilesCacheUpdate();
|
||||
}
|
||||
|
||||
|
@@ -93,7 +93,6 @@ public:
|
||||
MapViewPtr asMapView() { return std::static_pointer_cast<MapView>(shared_from_this()); }
|
||||
|
||||
private:
|
||||
int m_drawFlags;
|
||||
int m_lockedFirstVisibleFloor;
|
||||
int m_cachedFirstVisibleFloor;
|
||||
int m_cachedLastVisibleFloor;
|
||||
@@ -102,7 +101,6 @@ private:
|
||||
Size m_visibleDimension;
|
||||
Point m_virtualCenterOffset;
|
||||
Position m_customCameraPosition;
|
||||
Position m_framebufferCenterPosition;
|
||||
Boolean<true> m_mustUpdateVisibleTilesCache;
|
||||
Boolean<true> m_mustDrawVisibleTilesCache;
|
||||
Boolean<true> m_mustCleanFramebuffer;
|
||||
|
23
src/otclient/core/player.cpp
Normal file
23
src/otclient/core/player.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 "player.h"
|
@@ -31,6 +31,10 @@ public:
|
||||
Player() { }
|
||||
virtual ~Player() { }
|
||||
|
||||
bool isPartyMember() { return (m_shield != 0); }
|
||||
bool isPartyLeader() { return (m_shield & Otc::ShieldYellow); }
|
||||
bool isPartySharedExperienceActive() { return false; }
|
||||
|
||||
PlayerPtr asPlayer() { return std::static_pointer_cast<Player>(shared_from_this()); }
|
||||
};
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include "map.h"
|
||||
#include "tile.h"
|
||||
#include "game.h"
|
||||
|
||||
Thing::Thing()
|
||||
{
|
||||
@@ -53,6 +54,13 @@ const TilePtr& Thing::getTile()
|
||||
return g_map.getTile(m_position);
|
||||
}
|
||||
|
||||
ContainerPtr Thing::getParentContainer()
|
||||
{
|
||||
if(m_position.x == 0xFFFF && m_position.y & 0x40)
|
||||
return g_game.getContainer(m_position.z);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int Thing::getStackpos()
|
||||
{
|
||||
if(m_position.x == 65535 && asItem()) // is inside a container
|
||||
|
@@ -49,6 +49,7 @@ public:
|
||||
Position getPosition() { return m_position; }
|
||||
int getStackPriority();
|
||||
const TilePtr& getTile();
|
||||
ContainerPtr getParentContainer();
|
||||
int getStackpos();
|
||||
|
||||
ThingPtr asThing() { return std::static_pointer_cast<Thing>(shared_from_this()); }
|
||||
|
@@ -305,6 +305,7 @@ void OTClient::registerLuaFunctions()
|
||||
|
||||
g_lua.registerClass<UIMap, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
|
||||
g_lua.bindClassMemberFunction<UIMap>("followCreature", &UIMap::followCreature);
|
||||
g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
|
||||
g_lua.bindClassMemberFunction<UIMap>("zoomIn", &UIMap::zoomIn);
|
||||
g_lua.bindClassMemberFunction<UIMap>("zoomOut", &UIMap::zoomOut);
|
||||
|
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 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 "uigame.h"
|
||||
#include <otclient/core/game.h>
|
||||
#include <framework/ui/uilineedit.h>
|
||||
#include <framework/platform/platformwindow.h>
|
||||
|
||||
bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
|
||||
{
|
||||
if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
|
||||
return true;
|
||||
|
||||
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
|
||||
|
||||
//TODO: move this whole shit to lua
|
||||
if(keyboardModifiers == Fw::KeyboardNoModifier) {
|
||||
if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {
|
||||
g_game.walk(Otc::North);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
|
||||
g_game.walk(Otc::East);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyDown || keyCode == Fw::KeyNumpad2) {
|
||||
g_game.walk(Otc::South);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
|
||||
g_game.walk(Otc::West);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyNumpad9) {
|
||||
g_game.walk(Otc::NorthEast);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyNumpad3) {
|
||||
g_game.walk(Otc::SouthEast);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyNumpad1) {
|
||||
g_game.walk(Otc::SouthWest);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyNumpad7) {
|
||||
g_game.walk(Otc::NorthWest);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyDelete) {
|
||||
chatLineEdit->removeCharacter(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyBackspace) {
|
||||
chatLineEdit->removeCharacter(false);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyRight) {
|
||||
chatLineEdit->moveCursor(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft) {
|
||||
chatLineEdit->moveCursor(false);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyHome) {
|
||||
chatLineEdit->setCursorPos(0);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyEnd) {
|
||||
chatLineEdit->setCursorPos(chatLineEdit->getText().length());
|
||||
return true;
|
||||
}
|
||||
} else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
|
||||
if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {
|
||||
g_game.turn(Otc::North);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
|
||||
g_game.turn(Otc::East);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyDown || keyCode == Fw::KeyNumpad2) {
|
||||
g_game.turn(Otc::South);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
|
||||
g_game.turn(Otc::West);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyV) {
|
||||
chatLineEdit->appendText(g_window.getClipboardText());
|
||||
}
|
||||
} else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
|
||||
if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
|
||||
chatLineEdit->moveCursor(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
|
||||
chatLineEdit->moveCursor(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UIGame::onKeyText(const std::string& keyText)
|
||||
{
|
||||
if(UIWidget::onKeyText(keyText))
|
||||
return true;
|
||||
|
||||
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
|
||||
chatLineEdit->appendText(keyText);
|
||||
return true;
|
||||
}
|
@@ -33,7 +33,6 @@ UIMap::UIMap()
|
||||
m_dragable = true;
|
||||
m_mapView = MapViewPtr(new MapView);
|
||||
g_map.addMapView(m_mapView);
|
||||
m_mapView->followCreature(g_game.getLocalPlayer());
|
||||
}
|
||||
|
||||
UIMap::~UIMap()
|
||||
@@ -96,6 +95,11 @@ void UIMap::zoomOut()
|
||||
m_mapRect.moveCenter(m_rect.center());
|
||||
}
|
||||
|
||||
void UIMap::followCreature(const CreaturePtr& creature)
|
||||
{
|
||||
m_mapView->followCreature(creature);
|
||||
}
|
||||
|
||||
void UIMap::setCameraPosition(const Position& pos)
|
||||
{
|
||||
m_mapView->setCameraPosition(pos);
|
||||
|
@@ -37,6 +37,7 @@ public:
|
||||
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void followCreature(const CreaturePtr& creature);
|
||||
void setCameraPosition(const Position& pos);
|
||||
|
||||
TilePtr getTile(const Point& mousePos);
|
||||
|
Reference in New Issue
Block a user