some cleanup in modules, fixes in tooltip, uiwidget warnings, disable map saving for a while

This commit is contained in:
Eduardo Bart 2012-02-05 20:42:35 -02:00
parent 0471785d30
commit a55e138002
27 changed files with 180 additions and 114 deletions

8
.gitignore vendored
View File

@ -3,7 +3,9 @@ CMakeCache.txt
CMakeFiles CMakeFiles
cmake_install.cmake cmake_install.cmake
Makefile Makefile
./otclient /otclient
/*.h
/*.cxx
*.o *.o
*.gch *.gch
*.a *.a
@ -13,6 +15,6 @@ Makefile
*.kdev* *.kdev*
*.cbp *.cbp
CMakeLists.txt.user CMakeLists.txt.user
./modules/myconfig.otml /modules/myconfig.otml
./modules/myotclientrc.lua /modules/myotclientrc.lua
!.gitignore !.gitignore

View File

@ -1,2 +0,0 @@
-- place any code for testing purposes here
--scheduleEvent(function() dumpWidgets() end, 100)

View File

@ -1,7 +0,0 @@
Module
name: playground
autoLoad: true
autoLoadAntecedence: 1000
onLoad: |
require 'playground'

View File

@ -15,9 +15,9 @@ function Client.init()
-- window position, default is the screen center -- window position, default is the screen center
local displaySize = g_window.getDisplaySize() local displaySize = g_window.getDisplaySize()
local pos = { x = (displaySize.width - size.width)/2, local defaultPos = { x = (displaySize.width - size.width)/2,
y = (displaySize.height - size.height)/2 } y = (displaySize.height - size.height)/2 }
pos = Settings.getPoint('window-pos', pos) local pos = Settings.getPoint('window-pos', defaultPos)
g_window.move(pos) g_window.move(pos)
-- window maximized? -- window maximized?

View File

@ -9,7 +9,7 @@ function About.init()
end end
function About.display() function About.display()
aboutWindow = displayUI('about.otui', { locked = true }) displayUI('about.otui', { locked = true })
end end
function About.terminate() function About.terminate()

View File

@ -8,5 +8,5 @@ Module
require 'about' require 'about'
About.init() About.init()
onUnload: onUnload: |
About.terminate() About.terminate()

View File

@ -6,6 +6,7 @@ local background
-- public functions -- public functions
function Background.init() function Background.init()
background = displayUI('background.otui') background = displayUI('background.otui')
background:lower()
end end
function Background.terminate() function Background.terminate()

View File

@ -8,6 +8,6 @@ Module
require 'background' require 'background'
Background.init() Background.init()
onUnload: onUnload: |
Background.terminate() Background.terminate()

View File

@ -54,6 +54,18 @@ local function tryLogin(charInfo, tries)
end end
-- public functions -- public functions
function CharacterList.terminate()
characterList = nil
if charactersWindow then
charactersWindow:destroy()
charactersWindow = nil
end
if loadBox then
loadBox:destroy()
loadBox = nil
end
end
function CharacterList.create(characters, premDays) function CharacterList.create(characters, premDays)
if charactersWindow then if charactersWindow then
charactersWindow:destroy() charactersWindow:destroy()

View File

@ -9,7 +9,8 @@ Module
require 'characterlist' require 'characterlist'
EnterGame.init() EnterGame.init()
onUnload: onUnload: |
EnterGame.terminate() EnterGame.terminate()
CharacterList.terminate()

View File

@ -40,7 +40,7 @@ MainWindow
LineEdit LineEdit
id: serverHostLineEdit id: serverHostLineEdit
tooltip: Only protocol 8.62 is supported tooltip: Only protocol 8.6 is supported
anchors.left: serverLabel.left anchors.left: serverLabel.left
anchors.right: serverLabel.right anchors.right: serverLabel.right
anchors.top: serverLabel.bottom anchors.top: serverLabel.bottom

View File

@ -30,6 +30,7 @@ function TopMenu.terminate()
Hotkeys.unbindKeyDown('Ctrl+Q') Hotkeys.unbindKeyDown('Ctrl+Q')
leftButtonsPanel = nil leftButtonsPanel = nil
rightButtonsPanel = nil rightButtonsPanel = nil
gameButtonsPanel = nil
topMenu:destroy() topMenu:destroy()
topMenu = nil topMenu = nil
end end

View File

@ -20,3 +20,6 @@ Module
require 'settings' require 'settings'
require 'hotkeys' require 'hotkeys'
require 'cursor' require 'cursor'
onUnload: |
rootWidget = nil

View File

@ -1,11 +1,12 @@
ToolTip = {} ToolTip = {}
-- private variables -- private variables
local currentToolTip local toolTipLabel
local currentHoveredWidget
-- private functions -- private functions
local function moveToolTip(tooltip) local function moveToolTip(tooltip)
local pos = g_window.getMousePos() local pos = g_window.getMousePosition()
pos.y = pos.y + 1 pos.y = pos.y + 1
local xdif = g_window.getSize().width - (pos.x + tooltip:getWidth()) local xdif = g_window.getSize().width - (pos.x + tooltip:getWidth())
if xdif < 2 then if xdif < 2 then
@ -18,34 +19,37 @@ end
-- public functions -- public functions
function ToolTip.display(text) function ToolTip.display(text)
if text then if text == nil then return end
ToolTip.hide() ToolTip.hide()
currentToolTip = displayUI('tooltip.otui') toolTipLabel = createWidget('Label', rootWidget)
currentToolTip.onMouseMove = moveToolTip toolTipLabel:setId('toolTip')
local label = currentToolTip:getChildById('toolTipText') toolTipLabel:setBackgroundColor('#111111bb')
label:setText(text) toolTipLabel:setText(text)
label:resizeToText() toolTipLabel:resizeToText()
local size = label:getSize() toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4)
size.width = size.width + 4 toolTipLabel.onMouseMove = moveToolTip
size.height = size.height + 4 moveToolTip(toolTipLabel)
currentToolTip:setSize(size)
moveToolTip(currentToolTip)
end
end end
function ToolTip.hide() function ToolTip.hide()
if currentToolTip then if toolTipLabel then
currentToolTip:destroy() toolTipLabel:destroy()
currentToolTip = nil toolTipLabel = nil
end end
end end
-- UIWidget hooks -- UIWidget hooks
local function onWidgetHoverChange(widget, hovered) local function onWidgetHoverChange(widget, hovered)
if hovered then if hovered then
if widget.tooltip then
ToolTip.display(widget.tooltip) ToolTip.display(widget.tooltip)
currentHoveredWidget = widget
end
else else
if widget == currentHoveredWidget then
ToolTip:hide() ToolTip:hide()
currentHoveredWidget = nil
end
end end
end end

View File

@ -1,9 +1,7 @@
Panel Label
id: toolTipText
background-color: #111111bb background-color: #111111bb
size: 200 200 size: 200 200
id: toolTip id: toolTip
focusable: false focusable: false
Label
id: toolTipText
anchors.centerIn: parent anchors.centerIn: parent

View File

@ -8,9 +8,8 @@ SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_MODULE_PATH}")
# framework options # framework options
OPTION(NO_CONSOLE "Disables console window on Windows platform" OFF) OPTION(NO_CONSOLE "Disables console window on Windows platform" OFF)
OPTION(HANDLE_EXCEPTIONS "Generate crash reports" OFF) OPTION(CRASH_HANDLER "Generate crash reports" OFF)
OPTION(USE_OPENGL_ES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF) OPTION(USE_OPENGL_ES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF)
OPTION(USE_GCC47 "Use experimental gcc 4.7" OFF)
# set debug as default build type # set debug as default build type
IF(NOT CMAKE_BUILD_TYPE) IF(NOT CMAKE_BUILD_TYPE)
@ -46,27 +45,22 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF(CMAKE_COMPILER_IS_GNUCXX) ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug") IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-D_DEBUG) ADD_DEFINITIONS(-DDEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
IF(USE_OPENGL_ES2) IF(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL ES 2") MESSAGE(STATUS "Renderer: OpenGL ES 2.0")
ELSE(USE_OPENGL_ES2) ELSE(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL") MESSAGE(STATUS "Renderer: OpenGL")
ENDIF(USE_OPENGL_ES2) ENDIF(USE_OPENGL_ES2)
IF(HANDLE_EXCEPTIONS) IF(CRASH_HANDLER)
ADD_DEFINITIONS(-DHANDLE_EXCEPTIONS) ADD_DEFINITIONS(-DCRASH_HANDLER)
MESSAGE(STATUS "Generate crash reports: ON") MESSAGE(STATUS "Crash handler: ON")
ELSE(HANDLE_EXCEPTIONS) ELSE(CRASH_HANDLER)
MESSAGE(STATUS "Generate crash reports: OFF") MESSAGE(STATUS "Crash handler: OFF")
ENDIF(HANDLE_EXCEPTIONS) ENDIF(CRASH_HANDLER)
IF(USE_GCC47)
SET(CMAKE_C_COMPILER gcc-4.7)
SET(CMAKE_CXX_COMPILER g++-4.7)
ENDIF(USE_GCC47)
IF(WIN32) IF(WIN32)
SET(framework_SOURCES ${framework_SOURCES} SET(framework_SOURCES ${framework_SOURCES}
@ -88,9 +82,6 @@ IF(WIN32)
ELSE(WIN32) ELSE(WIN32)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic") SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic")
IF(USE_GCC47)
ADD_DEFINITIONS(-D_GLIBCXX__PTHREADS)
ENDIF(USE_GCC47)
SET(ADDITIONAL_LIBRARIES X11 dl) SET(ADDITIONAL_LIBRARIES X11 dl)
SET(framework_SOURCES ${framework_SOURCES} SET(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp

View File

@ -73,7 +73,7 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
signal(SIGTERM, exitSignalHandler); signal(SIGTERM, exitSignalHandler);
signal(SIGINT, exitSignalHandler); signal(SIGINT, exitSignalHandler);
#ifdef HANDLE_EXCEPTIONS #ifdef CRASH_HANDLER
installCrashHandler(); installCrashHandler();
#endif #endif
@ -119,6 +119,8 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
void Application::terminate() void Application::terminate()
{ {
g_lua.callGlobalField("g_app", "onTerminate");
// hide the window because there is no render anymore // hide the window because there is no render anymore
if(m_appFlags & Fw::AppEnableGraphics) if(m_appFlags & Fw::AppEnableGraphics)
g_window.hide(); g_window.hide();
@ -160,6 +162,8 @@ void Application::terminate()
void Application::run() void Application::run()
{ {
g_lua.callGlobalField("g_app", "onRun");
ticks_t lastPollTicks = g_clock.updateTicks(); ticks_t lastPollTicks = g_clock.updateTicks();
m_stopping = false; m_stopping = false;
m_running = true; m_running = true;

View File

@ -45,8 +45,8 @@ void EventDispatcher::poll()
scheduledEvent->execute(); scheduledEvent->execute();
} }
int maxEvents = m_eventList.size(); m_pollEventsSize = m_eventList.size();
for(int i=0;i<maxEvents;++i) { for(int i=0;i<m_pollEventsSize;++i) {
EventPtr event = m_eventList.front(); EventPtr event = m_eventList.front();
m_eventList.pop_front(); m_eventList.pop_front();
event->execute(); event->execute();
@ -64,9 +64,10 @@ ScheduledEventPtr EventDispatcher::scheduleEvent(const SimpleCallback& callback,
EventPtr EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront) EventPtr EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront)
{ {
EventPtr event(new Event(callback)); EventPtr event(new Event(callback));
if(pushFront) if(pushFront) {
m_eventList.push_front(event); m_eventList.push_front(event);
else m_pollEventsSize++;
} else
m_eventList.push_back(event); m_eventList.push_back(event);
return event; return event;
} }

View File

@ -80,6 +80,7 @@ public:
private: private:
std::list<EventPtr> m_eventList; std::list<EventPtr> m_eventList;
int m_pollEventsSize;
std::priority_queue<ScheduledEventPtr, std::vector<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList; std::priority_queue<ScheduledEventPtr, std::vector<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList;
}; };

View File

@ -60,7 +60,8 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("focusChild", &UIWidget::focusChild); g_lua.bindClassMemberFunction<UIWidget>("focusChild", &UIWidget::focusChild);
g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild); g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild);
g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild); g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild);
g_lua.bindClassMemberFunction<UIWidget>("moveChildToTop", &UIWidget::moveChildToTop); g_lua.bindClassMemberFunction<UIWidget>("lowerChild", &UIWidget::lowerChild);
g_lua.bindClassMemberFunction<UIWidget>("raiseChild", &UIWidget::raiseChild);
g_lua.bindClassMemberFunction<UIWidget>("moveChildToIndex", &UIWidget::moveChildToIndex); g_lua.bindClassMemberFunction<UIWidget>("moveChildToIndex", &UIWidget::moveChildToIndex);
g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild); g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild); g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild);
@ -74,6 +75,8 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock); g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock); g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
g_lua.bindClassMemberFunction<UIWidget>("focus", &UIWidget::focus); g_lua.bindClassMemberFunction<UIWidget>("focus", &UIWidget::focus);
g_lua.bindClassMemberFunction<UIWidget>("lower", &UIWidget::lower);
g_lua.bindClassMemberFunction<UIWidget>("raise", &UIWidget::raise);
g_lua.bindClassMemberFunction<UIWidget>("grabMouse", &UIWidget::grabMouse); g_lua.bindClassMemberFunction<UIWidget>("grabMouse", &UIWidget::grabMouse);
g_lua.bindClassMemberFunction<UIWidget>("ungrabMouse", &UIWidget::ungrabMouse); g_lua.bindClassMemberFunction<UIWidget>("ungrabMouse", &UIWidget::ungrabMouse);
g_lua.bindClassMemberFunction<UIWidget>("grabKeyboard", &UIWidget::grabKeyboard); g_lua.bindClassMemberFunction<UIWidget>("grabKeyboard", &UIWidget::grabKeyboard);
@ -355,6 +358,11 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction<UIFrameCounter>("create", []{ return UIFrameCounterPtr(new UIFrameCounter); } ); g_lua.bindClassStaticFunction<UIFrameCounter>("create", []{ return UIFrameCounterPtr(new UIFrameCounter); } );
g_lua.bindClassMemberFunction<UIFrameCounter>("getFrameCount", &UIFrameCounter::getFrameCount); g_lua.bindClassMemberFunction<UIFrameCounter>("getFrameCount", &UIFrameCounter::getFrameCount);
// Protocol
g_lua.registerClass<Protocol>();
// network manipulation via lua is disabled for a while
/*
// OutputMessage // OutputMessage
g_lua.registerClass<OutputMessage>(); g_lua.registerClass<OutputMessage>();
g_lua.bindClassStaticFunction<OutputMessage>("new", []{ return OutputMessagePtr(new OutputMessage); }); g_lua.bindClassStaticFunction<OutputMessage>("new", []{ return OutputMessagePtr(new OutputMessage); });
@ -365,9 +373,8 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<OutputMessage>("addU64", &OutputMessage::addU64); g_lua.bindClassMemberFunction<OutputMessage>("addU64", &OutputMessage::addU64);
g_lua.bindClassMemberFunction<OutputMessage>("addString", (void(OutputMessage::*)(const std::string&))&OutputMessage::addString); g_lua.bindClassMemberFunction<OutputMessage>("addString", (void(OutputMessage::*)(const std::string&))&OutputMessage::addString);
// Protocol
g_lua.registerClass<Protocol>();
g_lua.bindClassStaticFunction<Protocol>("send", [](const ProtocolPtr proto, OutputMessagePtr msg) { proto->send(*msg.get()); }); g_lua.bindClassStaticFunction<Protocol>("send", [](const ProtocolPtr proto, OutputMessagePtr msg) { proto->send(*msg.get()); });
*/
// Application // Application
g_lua.registerStaticClass("g_app"); g_lua.registerStaticClass("g_app");
@ -415,7 +422,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_window", "getPosition", std::bind(&PlatformWindow::getPosition, &g_window)); g_lua.bindClassStaticFunction("g_window", "getPosition", std::bind(&PlatformWindow::getPosition, &g_window));
g_lua.bindClassStaticFunction("g_window", "getX", std::bind(&PlatformWindow::getX, &g_window)); g_lua.bindClassStaticFunction("g_window", "getX", std::bind(&PlatformWindow::getX, &g_window));
g_lua.bindClassStaticFunction("g_window", "getY", std::bind(&PlatformWindow::getY, &g_window)); g_lua.bindClassStaticFunction("g_window", "getY", std::bind(&PlatformWindow::getY, &g_window));
g_lua.bindClassStaticFunction("g_window", "getMousePos", std::bind(&PlatformWindow::getMousePos, &g_window)); g_lua.bindClassStaticFunction("g_window", "getMousePosition", std::bind(&PlatformWindow::getMousePosition, &g_window));
g_lua.bindClassStaticFunction("g_window", "getKeyboardModifiers", std::bind(&PlatformWindow::getKeyboardModifiers, &g_window)); g_lua.bindClassStaticFunction("g_window", "getKeyboardModifiers", std::bind(&PlatformWindow::getKeyboardModifiers, &g_window));
g_lua.bindClassStaticFunction("g_window", "isKeyPressed", std::bind(&PlatformWindow::isKeyPressed, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "isKeyPressed", std::bind(&PlatformWindow::isKeyPressed, &g_window, _1));
g_lua.bindClassStaticFunction("g_window", "isVisible", std::bind(&PlatformWindow::isVisible, &g_window)); g_lua.bindClassStaticFunction("g_window", "isVisible", std::bind(&PlatformWindow::isVisible, &g_window));

View File

@ -76,7 +76,7 @@ public:
Point getPosition() { return m_position; } Point getPosition() { return m_position; }
int getX() { return m_position.x; } int getX() { return m_position.x; }
int getY() { return m_position.y; } int getY() { return m_position.y; }
Point getMousePos() { return m_inputEvent.mousePos; } Point getMousePosition() { return m_inputEvent.mousePos; }
int getKeyboardModifiers() { return m_inputEvent.keyboardModifiers; } int getKeyboardModifiers() { return m_inputEvent.keyboardModifiers; }
bool isKeyPressed(Fw::Key keyCode) { return m_keysState[keyCode]; } bool isKeyPressed(Fw::Key keyCode) { return m_keysState[keyCode]; }

View File

@ -40,9 +40,12 @@ void UIManager::init()
void UIManager::terminate() void UIManager::terminate()
{ {
// destroy root widget and its children' // destroy root widget and its children
m_rootWidget->destroy(); m_rootWidget->destroy();
m_rootWidget.reset(); m_mouseReceiver = nullptr;
m_keyboardReceiver = nullptr;
m_rootWidget = nullptr;
m_draggingWidget = nullptr;
} }
void UIManager::render() void UIManager::render()

View File

@ -44,7 +44,10 @@ UIWidget::UIWidget()
UIWidget::~UIWidget() UIWidget::~UIWidget()
{ {
// nothing to do #ifdef DEBUG
if(!m_destroyed)
logWarning("widget '", m_id, "' was not explicitly destroyed");
#endif
} }
void UIWidget::draw() void UIWidget::draw()
@ -158,7 +161,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
updateChildrenIndexStates(); updateChildrenIndexStates();
} }
void UIWidget::removeChild(const UIWidgetPtr& child) void UIWidget::removeChild(UIWidgetPtr child)
{ {
// remove from children list // remove from children list
if(hasChild(child)) { if(hasChild(child)) {
@ -269,7 +272,20 @@ void UIWidget::focusPreviousChild(Fw::FocusReason reason)
focusChild(toFocus, reason); focusChild(toFocus, reason);
} }
void UIWidget::moveChildToTop(const UIWidgetPtr& child) void UIWidget::lowerChild(UIWidgetPtr child)
{
if(!child)
return;
// remove and push child again
auto it = std::find(m_children.begin(), m_children.end(), child);
assert(it != m_children.end());
m_children.erase(it);
m_children.push_front(child);
updateChildrenIndexStates();
}
void UIWidget::raiseChild(UIWidgetPtr child)
{ {
if(!child) if(!child)
return; return;
@ -320,7 +336,7 @@ void UIWidget::lockChild(const UIWidgetPtr& child)
if(child->isFocusable()) if(child->isFocusable())
focusChild(child, Fw::ActiveFocusReason); focusChild(child, Fw::ActiveFocusReason);
moveChildToTop(child); raiseChild(child);
} }
void UIWidget::unlockChild(const UIWidgetPtr& child) void UIWidget::unlockChild(const UIWidgetPtr& child)
@ -360,7 +376,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
if(lockedChild->isFocusable()) if(lockedChild->isFocusable())
focusChild(lockedChild, Fw::ActiveFocusReason); focusChild(lockedChild, Fw::ActiveFocusReason);
moveChildToTop(lockedChild); raiseChild(lockedChild);
} }
} }
@ -460,6 +476,21 @@ void UIWidget::focus()
parent->focusChild(asUIWidget(), Fw::ActiveFocusReason); parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
} }
void UIWidget::lower()
{
UIWidgetPtr parent = getParent();
if(parent)
parent->lowerChild(asUIWidget());
}
void UIWidget::raise()
{
focus();
UIWidgetPtr parent = getParent();
if(parent)
parent->raiseChild(asUIWidget());
}
void UIWidget::grabMouse() void UIWidget::grabMouse()
{ {
g_ui.setMouseReceiver(asUIWidget()); g_ui.setMouseReceiver(asUIWidget());
@ -515,8 +546,25 @@ void UIWidget::destroy()
parent->removeChild(asUIWidget()); parent->removeChild(asUIWidget());
} }
// destroy children
while(!m_children.empty())
getFirstChild()->destroy();
callLuaField("onDestroy"); callLuaField("onDestroy");
#ifdef DEBUG
auto self = asUIWidget();
g_lua.collectGarbage();
g_dispatcher.addEvent([self] {
g_lua.collectGarbage();
g_dispatcher.addEvent([self] {
g_lua.collectGarbage();
if(self->getUseCount() != 1)
logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left");
});
});
#endif
m_destroyed = true; m_destroyed = true;
} }
@ -905,19 +953,13 @@ void UIWidget::updateState(Fw::WidgetState state)
} }
case Fw::HoverState: { case Fw::HoverState: {
updateChildren = true; updateChildren = true;
Point mousePos = g_window.getMousePos(); Point mousePos = g_window.getMousePosition();
UIWidgetPtr widget = asUIWidget(); UIWidgetPtr self = asUIWidget();
UIWidgetPtr parent; UIWidgetPtr rootParent = self->getRootParent();
do { if(!rootParent || rootParent->recursiveGetChildByPos(mousePos) != self)
parent = widget->getParent();
if(!widget->isExplicitlyEnabled() || !widget->isExplicitlyVisible() || !widget->containsPoint(mousePos) ||
(parent && widget != parent->getChildByPos(mousePos))) {
newStatus = false; newStatus = false;
break; break;
} }
} while(widget = parent);
break;
}
case Fw::PressedState: { case Fw::PressedState: {
newStatus = m_pressed; newStatus = m_pressed;
break; break;
@ -1273,7 +1315,7 @@ bool UIWidget::propagateOnMousePress(const Point& mousePos, Fw::MouseButton butt
return true; return true;
} }
// only non phatom widgets receives mouse press events // only non phatom widgets receives mouse events
if(!isPhantom()) { if(!isPhantom()) {
bool ret = onMousePress(mousePos, button); bool ret = onMousePress(mousePos, button);
if(button == Fw::MouseLeftButton && !isPressed()) if(button == Fw::MouseLeftButton && !isPressed())
@ -1302,12 +1344,15 @@ bool UIWidget::propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton bu
return true; return true;
} }
// only non phatom widgets receives mouse events
if(!isPhantom()) {
bool ret = onMouseRelease(mousePos, button); bool ret = onMouseRelease(mousePos, button);
if(isPressed() && button == Fw::MouseLeftButton) if(isPressed() && button == Fw::MouseLeftButton)
setPressed(false); setPressed(false);
return ret; return ret;
}
return false;
} }
bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved) bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved)
@ -1328,10 +1373,7 @@ bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMov
return true; return true;
} }
if(!isPhantom())
return onMouseMove(mousePos, mouseMoved); return onMouseMove(mousePos, mouseMoved);
else
return false;
} }
bool UIWidget::propagateOnMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction) bool UIWidget::propagateOnMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction)
@ -1353,6 +1395,7 @@ bool UIWidget::propagateOnMouseWheel(const Point& mousePos, Fw::MouseWheelDirect
return true; return true;
} }
// only non phatom widgets receives mouse events
if(!isPhantom()) if(!isPhantom())
return onMouseWheel(mousePos, direction); return onMouseWheel(mousePos, direction);
else else

View File

@ -78,11 +78,12 @@ protected:
public: public:
void addChild(const UIWidgetPtr& child); void addChild(const UIWidgetPtr& child);
void insertChild(int index, const UIWidgetPtr& child); void insertChild(int index, const UIWidgetPtr& child);
void removeChild(const UIWidgetPtr& child); void removeChild(UIWidgetPtr child);
void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason); void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason);
void focusNextChild(Fw::FocusReason reason); void focusNextChild(Fw::FocusReason reason);
void focusPreviousChild(Fw::FocusReason reason); void focusPreviousChild(Fw::FocusReason reason);
void moveChildToTop(const UIWidgetPtr& child); void lowerChild(UIWidgetPtr child);
void raiseChild(UIWidgetPtr child);
void moveChildToIndex(const UIWidgetPtr& child, int index); void moveChildToIndex(const UIWidgetPtr& child, int index);
void lockChild(const UIWidgetPtr& child); void lockChild(const UIWidgetPtr& child);
void unlockChild(const UIWidgetPtr& child); void unlockChild(const UIWidgetPtr& child);
@ -96,6 +97,8 @@ public:
void lock(); void lock();
void unlock(); void unlock();
void focus(); void focus();
void lower();
void raise();
void grabMouse(); void grabMouse();
void ungrabMouse(); void ungrabMouse();
void grabKeyboard(); void grabKeyboard();

View File

@ -4,17 +4,17 @@ IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6) ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
# otclient options # otclient options
OPTION(NO_BOT_PROTECTION "Disables bot protection" OFF) OPTION(BOT_PROTECTION "Enable bot protection" ON)
SET(PROTOCOL 862 CACHE "Protocol version" STRING) SET(PROTOCOL 861 CACHE "Protocol version" STRING)
ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL}) ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL})
MESSAGE(STATUS "Protocol: " ${PROTOCOL}) MESSAGE(STATUS "Protocol: " ${PROTOCOL})
IF(NO_BOT_PROTECTION) IF(BOT_PROTECTION)
ADD_DEFINITIONS(-DNO_BOT_PROTECTION) ADD_DEFINITIONS(-DBOT_PROTECTION)
MESSAGE(STATUS "Bot protection: OFF")
ELSE(NO_BOT_PROTECTION)
MESSAGE(STATUS "Bot protection: ON") MESSAGE(STATUS "Bot protection: ON")
ENDIF(NO_BOT_PROTECTION) ELSE(BOT_PROTECTION)
MESSAGE(STATUS "Bot protection: OFF")
ENDIF(BOT_PROTECTION)
SET(otclient_SOURCES ${otclient_SOURCES} SET(otclient_SOURCES ${otclient_SOURCES}
# otclient # otclient

View File

@ -94,7 +94,7 @@ void Game::processLogout()
m_protocolGame = nullptr; m_protocolGame = nullptr;
} }
g_map.save(); //g_map.save();
} }
void Game::processDeath() void Game::processDeath()
@ -587,7 +587,7 @@ void Game::removeVip(int playerId)
bool Game::checkBotProtection() bool Game::checkBotProtection()
{ {
#ifndef NO_BOT_PROTECTION #ifdef BOT_PROTECTION
if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) { if(g_lua.isInCppCallback() && !g_ui.isOnInputEvent()) {
logError("caught a lua call to a bot protected game function, the call was canceled"); logError("caught a lua call to a bot protected game function, the call was canceled");
return false; return false;

View File

@ -41,7 +41,7 @@ void OTClient::init(const std::vector<std::string>& args)
g_modules.ensureModuleLoaded("client"); g_modules.ensureModuleLoaded("client");
g_modules.autoLoadModules(1000); g_modules.autoLoadModules(1000);
g_map.load(); //g_map.load();
// load otclientrc.lua // load otclientrc.lua
if(g_resources.fileExists("/otclientrc.lua")) { if(g_resources.fileExists("/otclientrc.lua")) {