Browse Source

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

Eduardo Bart 9 years ago
parent
commit
a55e138002

+ 5
- 3
.gitignore View File

@@ -3,7 +3,9 @@ CMakeCache.txt
3 3
 CMakeFiles
4 4
 cmake_install.cmake
5 5
 Makefile
6
-./otclient
6
+/otclient
7
+/*.h
8
+/*.cxx
7 9
 *.o
8 10
 *.gch
9 11
 *.a
@@ -13,6 +15,6 @@ Makefile
13 15
 *.kdev*
14 16
 *.cbp
15 17
 CMakeLists.txt.user
16
-./modules/myconfig.otml
17
-./modules/myotclientrc.lua
18
+/modules/myconfig.otml
19
+/modules/myotclientrc.lua
18 20
 !.gitignore

+ 0
- 1
modules/addon_playground/playground.lua View File

@@ -1,2 +0,0 @@
1
---scheduleEvent(function() dumpWidgets() end, 100)

+ 0
- 7
modules/addon_playground/playground.otmod View File

@@ -1,7 +0,0 @@
1
-Module
2
-  name: playground
3
-  autoLoad: true
4
-  autoLoadAntecedence: 1000
5
-  onLoad: |
6
-    require 'playground'
7
-

+ 3
- 3
modules/client/client.lua View File

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

+ 1
- 1
modules/client_about/about.lua View File

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

+ 1
- 1
modules/client_about/about.otmod View File

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

+ 1
- 0
modules/client_background/background.lua View File

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

+ 1
- 1
modules/client_background/background.otmod View File

@@ -8,6 +8,6 @@ Module
8 8
     require 'background'
9 9
     Background.init()
10 10
 
11
-  onUnload:
11
+  onUnload: |
12 12
     Background.terminate()
13 13
 

+ 13
- 1
modules/client_entergame/characterlist.lua View File

@@ -54,6 +54,18 @@ local function tryLogin(charInfo, tries)
54 54
 end
55 55
 
56 56
 -- public functions
57
+function CharacterList.terminate()
58
+  characterList = nil
59
+  if charactersWindow then
60
+    charactersWindow:destroy()
61
+    charactersWindow = nil
62
+  end
63
+  if loadBox then
64
+    loadBox:destroy()
65
+    loadBox = nil
66
+  end
67
+end
68
+
57 69
 function CharacterList.create(characters, premDays)
58 70
   if charactersWindow then
59 71
     charactersWindow:destroy()
@@ -77,7 +89,7 @@ function CharacterList.create(characters, premDays)
77 89
     label.characterName = characterName
78 90
     label.worldHost = worldHost
79 91
     label.worldPort = worldIp
80
-    
92
+
81 93
     connect(label, { onDoubleClick = function () CharacterList.doLogin() return true end } )
82 94
 
83 95
     if i == 1 or Settings.get('lastUsedCharacter') == characterName then

+ 2
- 1
modules/client_entergame/entergame.otmod View File

@@ -9,7 +9,8 @@ Module
9 9
     require 'characterlist'
10 10
     EnterGame.init()
11 11
 
12
-  onUnload:
12
+  onUnload: |
13 13
     EnterGame.terminate()
14
+    CharacterList.terminate()
14 15
 
15 16
 

+ 1
- 1
modules/client_entergame/entergame.otui View File

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

+ 1
- 0
modules/client_topmenu/topmenu.lua View File

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

+ 3
- 0
modules/core_lib/core_lib.otmod View File

@@ -20,3 +20,6 @@ Module
20 20
     require 'settings'
21 21
     require 'hotkeys'
22 22
     require 'cursor'
23
+
24
+  onUnload: |
25
+    rootWidget = nil

+ 24
- 20
modules/core_widgets/tooltip/tooltip.lua View File

@@ -1,11 +1,12 @@
1 1
 ToolTip = {}
2 2
 
3 3
 -- private variables
4
-local currentToolTip
4
+local toolTipLabel
5
+local currentHoveredWidget
5 6
 
6 7
 -- private functions
7 8
 local function moveToolTip(tooltip)
8
-  local pos = g_window.getMousePos()
9
+  local pos = g_window.getMousePosition()
9 10
   pos.y = pos.y + 1
10 11
   local xdif = g_window.getSize().width - (pos.x + tooltip:getWidth())
11 12
   if xdif < 2 then
@@ -18,34 +19,37 @@ end
18 19
 
19 20
 -- public functions
20 21
 function ToolTip.display(text)
21
-  if text then
22
-    ToolTip.hide()
23
-    currentToolTip = displayUI('tooltip.otui')
24
-    currentToolTip.onMouseMove = moveToolTip
25
-    local label = currentToolTip:getChildById('toolTipText')
26
-    label:setText(text)
27
-    label:resizeToText()
28
-    local size = label:getSize()
29
-    size.width = size.width + 4
30
-    size.height = size.height + 4
31
-    currentToolTip:setSize(size)
32
-    moveToolTip(currentToolTip)
33
-  end
22
+  if text == nil then return end
23
+  ToolTip.hide()
24
+  toolTipLabel = createWidget('Label', rootWidget)
25
+  toolTipLabel:setId('toolTip')
26
+  toolTipLabel:setBackgroundColor('#111111bb')
27
+  toolTipLabel:setText(text)
28
+  toolTipLabel:resizeToText()
29
+  toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4)
30
+  toolTipLabel.onMouseMove = moveToolTip
31
+  moveToolTip(toolTipLabel)
34 32
 end
35 33
 
36 34
 function ToolTip.hide()
37
-  if currentToolTip then
38
-    currentToolTip:destroy()
39
-    currentToolTip = nil
35
+  if toolTipLabel then
36
+    toolTipLabel:destroy()
37
+    toolTipLabel = nil
40 38
   end
41 39
 end
42 40
 
43 41
 -- UIWidget hooks
44 42
 local function onWidgetHoverChange(widget, hovered)
45 43
   if hovered then
46
-    ToolTip.display(widget.tooltip)
44
+    if widget.tooltip then
45
+      ToolTip.display(widget.tooltip)
46
+      currentHoveredWidget = widget
47
+    end
47 48
   else
48
-    ToolTip:hide()
49
+    if widget == currentHoveredWidget then
50
+      ToolTip:hide()
51
+      currentHoveredWidget = nil
52
+    end
49 53
   end
50 54
 end
51 55
 

+ 3
- 5
modules/core_widgets/tooltip/tooltip.otui View File

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

+ 9
- 18
src/framework/CMakeLists.txt View File

@@ -8,9 +8,8 @@ SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_MODULE_PATH}")
8 8
 
9 9
 # framework options
10 10
 OPTION(NO_CONSOLE "Disables console window on Windows platform" OFF)
11
-OPTION(HANDLE_EXCEPTIONS "Generate crash reports" OFF)
11
+OPTION(CRASH_HANDLER "Generate crash reports" OFF)
12 12
 OPTION(USE_OPENGL_ES2 "Use OpenGL ES 2.0 (for mobiles devices)" OFF)
13
-OPTION(USE_GCC47 "Use experimental gcc 4.7" OFF)
14 13
 
15 14
 # set debug as default build type
16 15
 IF(NOT CMAKE_BUILD_TYPE)
@@ -46,27 +45,22 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
46 45
 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
47 46
 
48 47
 IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
49
-    ADD_DEFINITIONS(-D_DEBUG)
48
+    ADD_DEFINITIONS(-DDEBUG)
50 49
 ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
51 50
 
52 51
 MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
53 52
 IF(USE_OPENGL_ES2)
54
-    MESSAGE(STATUS "Renderer: OpenGL ES 2")
53
+    MESSAGE(STATUS "Renderer: OpenGL ES 2.0")
55 54
 ELSE(USE_OPENGL_ES2)
56 55
     MESSAGE(STATUS "Renderer: OpenGL")
57 56
 ENDIF(USE_OPENGL_ES2)
58 57
 
59
-IF(HANDLE_EXCEPTIONS)
60
-    ADD_DEFINITIONS(-DHANDLE_EXCEPTIONS)
61
-    MESSAGE(STATUS "Generate crash reports: ON")
62
-ELSE(HANDLE_EXCEPTIONS)
63
-    MESSAGE(STATUS "Generate crash reports: OFF")
64
-ENDIF(HANDLE_EXCEPTIONS)
65
-
66
-IF(USE_GCC47)
67
-    SET(CMAKE_C_COMPILER gcc-4.7)
68
-    SET(CMAKE_CXX_COMPILER g++-4.7)
69
-ENDIF(USE_GCC47)
58
+IF(CRASH_HANDLER)
59
+    ADD_DEFINITIONS(-DCRASH_HANDLER)
60
+    MESSAGE(STATUS "Crash handler: ON")
61
+ELSE(CRASH_HANDLER)
62
+    MESSAGE(STATUS "Crash handler: OFF")
63
+ENDIF(CRASH_HANDLER)
70 64
 
71 65
 IF(WIN32)
72 66
     SET(framework_SOURCES ${framework_SOURCES}
@@ -88,9 +82,6 @@ IF(WIN32)
88 82
 ELSE(WIN32)
89 83
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
90 84
     SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -rdynamic")
91
-    IF(USE_GCC47)
92
-        ADD_DEFINITIONS(-D_GLIBCXX__PTHREADS)
93
-    ENDIF(USE_GCC47)
94 85
     SET(ADDITIONAL_LIBRARIES X11 dl)
95 86
     SET(framework_SOURCES ${framework_SOURCES}
96 87
         ${CMAKE_CURRENT_LIST_DIR}/platform/x11window.cpp

+ 5
- 1
src/framework/application.cpp View File

@@ -73,7 +73,7 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
73 73
     signal(SIGTERM, exitSignalHandler);
74 74
     signal(SIGINT, exitSignalHandler);
75 75
 
76
-#ifdef HANDLE_EXCEPTIONS
76
+#ifdef CRASH_HANDLER
77 77
     installCrashHandler();
78 78
 #endif
79 79
 
@@ -119,6 +119,8 @@ void Application::init(const std::vector<std::string>& args, int appFlags)
119 119
 
120 120
 void Application::terminate()
121 121
 {
122
+    g_lua.callGlobalField("g_app", "onTerminate");
123
+
122 124
     // hide the window because there is no render anymore
123 125
     if(m_appFlags & Fw::AppEnableGraphics)
124 126
         g_window.hide();
@@ -160,6 +162,8 @@ void Application::terminate()
160 162
 
161 163
 void Application::run()
162 164
 {
165
+    g_lua.callGlobalField("g_app", "onRun");
166
+
163 167
     ticks_t lastPollTicks = g_clock.updateTicks();
164 168
     m_stopping = false;
165 169
     m_running = true;

+ 5
- 4
src/framework/core/eventdispatcher.cpp View File

@@ -45,8 +45,8 @@ void EventDispatcher::poll()
45 45
         scheduledEvent->execute();
46 46
     }
47 47
 
48
-    int maxEvents = m_eventList.size();
49
-    for(int i=0;i<maxEvents;++i) {
48
+    m_pollEventsSize = m_eventList.size();
49
+    for(int i=0;i<m_pollEventsSize;++i) {
50 50
         EventPtr event = m_eventList.front();
51 51
         m_eventList.pop_front();
52 52
         event->execute();
@@ -64,9 +64,10 @@ ScheduledEventPtr EventDispatcher::scheduleEvent(const SimpleCallback& callback,
64 64
 EventPtr EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront)
65 65
 {
66 66
     EventPtr event(new Event(callback));
67
-    if(pushFront)
67
+    if(pushFront) {
68 68
         m_eventList.push_front(event);
69
-    else
69
+        m_pollEventsSize++;
70
+    } else
70 71
         m_eventList.push_back(event);
71 72
     return event;
72 73
 }

+ 1
- 0
src/framework/core/eventdispatcher.h View File

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

+ 11
- 4
src/framework/luafunctions.cpp View File

@@ -60,7 +60,8 @@ void Application::registerLuaFunctions()
60 60
     g_lua.bindClassMemberFunction<UIWidget>("focusChild", &UIWidget::focusChild);
61 61
     g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild);
62 62
     g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild);
63
-    g_lua.bindClassMemberFunction<UIWidget>("moveChildToTop", &UIWidget::moveChildToTop);
63
+    g_lua.bindClassMemberFunction<UIWidget>("lowerChild", &UIWidget::lowerChild);
64
+    g_lua.bindClassMemberFunction<UIWidget>("raiseChild", &UIWidget::raiseChild);
64 65
     g_lua.bindClassMemberFunction<UIWidget>("moveChildToIndex", &UIWidget::moveChildToIndex);
65 66
     g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
66 67
     g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild);
@@ -74,6 +75,8 @@ void Application::registerLuaFunctions()
74 75
     g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
75 76
     g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
76 77
     g_lua.bindClassMemberFunction<UIWidget>("focus", &UIWidget::focus);
78
+    g_lua.bindClassMemberFunction<UIWidget>("lower", &UIWidget::lower);
79
+    g_lua.bindClassMemberFunction<UIWidget>("raise", &UIWidget::raise);
77 80
     g_lua.bindClassMemberFunction<UIWidget>("grabMouse", &UIWidget::grabMouse);
78 81
     g_lua.bindClassMemberFunction<UIWidget>("ungrabMouse", &UIWidget::ungrabMouse);
79 82
     g_lua.bindClassMemberFunction<UIWidget>("grabKeyboard", &UIWidget::grabKeyboard);
@@ -355,6 +358,11 @@ void Application::registerLuaFunctions()
355 358
     g_lua.bindClassStaticFunction<UIFrameCounter>("create", []{ return UIFrameCounterPtr(new UIFrameCounter); } );
356 359
     g_lua.bindClassMemberFunction<UIFrameCounter>("getFrameCount", &UIFrameCounter::getFrameCount);
357 360
 
361
+    // Protocol
362
+    g_lua.registerClass<Protocol>();
363
+
364
+    // network manipulation via lua is disabled for a while
365
+    /*
358 366
     // OutputMessage
359 367
     g_lua.registerClass<OutputMessage>();
360 368
     g_lua.bindClassStaticFunction<OutputMessage>("new", []{ return OutputMessagePtr(new OutputMessage); });
@@ -365,9 +373,8 @@ void Application::registerLuaFunctions()
365 373
     g_lua.bindClassMemberFunction<OutputMessage>("addU64", &OutputMessage::addU64);
366 374
     g_lua.bindClassMemberFunction<OutputMessage>("addString", (void(OutputMessage::*)(const std::string&))&OutputMessage::addString);
367 375
 
368
-    // Protocol
369
-    g_lua.registerClass<Protocol>();
370 376
     g_lua.bindClassStaticFunction<Protocol>("send", [](const ProtocolPtr proto, OutputMessagePtr msg) { proto->send(*msg.get()); });
377
+    */
371 378
 
372 379
     // Application
373 380
     g_lua.registerStaticClass("g_app");
@@ -415,7 +422,7 @@ void Application::registerLuaFunctions()
415 422
     g_lua.bindClassStaticFunction("g_window", "getPosition", std::bind(&PlatformWindow::getPosition, &g_window));
416 423
     g_lua.bindClassStaticFunction("g_window", "getX", std::bind(&PlatformWindow::getX, &g_window));
417 424
     g_lua.bindClassStaticFunction("g_window", "getY", std::bind(&PlatformWindow::getY, &g_window));
418
-    g_lua.bindClassStaticFunction("g_window", "getMousePos", std::bind(&PlatformWindow::getMousePos, &g_window));
425
+    g_lua.bindClassStaticFunction("g_window", "getMousePosition", std::bind(&PlatformWindow::getMousePosition, &g_window));
419 426
     g_lua.bindClassStaticFunction("g_window", "getKeyboardModifiers", std::bind(&PlatformWindow::getKeyboardModifiers, &g_window));
420 427
     g_lua.bindClassStaticFunction("g_window", "isKeyPressed", std::bind(&PlatformWindow::isKeyPressed, &g_window, _1));
421 428
     g_lua.bindClassStaticFunction("g_window", "isVisible", std::bind(&PlatformWindow::isVisible, &g_window));

+ 1
- 1
src/framework/platform/platformwindow.h View File

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

+ 5
- 2
src/framework/ui/uimanager.cpp View File

@@ -40,9 +40,12 @@ void UIManager::init()
40 40
 
41 41
 void UIManager::terminate()
42 42
 {
43
-    // destroy root widget and its children'
43
+    // destroy root widget and its children
44 44
     m_rootWidget->destroy();
45
-    m_rootWidget.reset();
45
+    m_mouseReceiver = nullptr;
46
+    m_keyboardReceiver = nullptr;
47
+    m_rootWidget = nullptr;
48
+    m_draggingWidget = nullptr;
46 49
 }
47 50
 
48 51
 void UIManager::render()

+ 69
- 26
src/framework/ui/uiwidget.cpp View File

@@ -44,7 +44,10 @@ UIWidget::UIWidget()
44 44
 
45 45
 UIWidget::~UIWidget()
46 46
 {
47
-    // nothing to do
47
+#ifdef DEBUG
48
+    if(!m_destroyed)
49
+        logWarning("widget '", m_id, "' was not explicitly destroyed");
50
+#endif
48 51
 }
49 52
 
50 53
 void UIWidget::draw()
@@ -158,7 +161,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
158 161
     updateChildrenIndexStates();
159 162
 }
160 163
 
161
-void UIWidget::removeChild(const UIWidgetPtr& child)
164
+void UIWidget::removeChild(UIWidgetPtr child)
162 165
 {
163 166
     // remove from children list
164 167
     if(hasChild(child)) {
@@ -269,7 +272,20 @@ void UIWidget::focusPreviousChild(Fw::FocusReason reason)
269 272
         focusChild(toFocus, reason);
270 273
 }
271 274
 
272
-void UIWidget::moveChildToTop(const UIWidgetPtr& child)
275
+void UIWidget::lowerChild(UIWidgetPtr child)
276
+{
277
+    if(!child)
278
+        return;
279
+
280
+    // remove and push child again
281
+    auto it = std::find(m_children.begin(), m_children.end(), child);
282
+    assert(it != m_children.end());
283
+    m_children.erase(it);
284
+    m_children.push_front(child);
285
+    updateChildrenIndexStates();
286
+}
287
+
288
+void UIWidget::raiseChild(UIWidgetPtr child)
273 289
 {
274 290
     if(!child)
275 291
         return;
@@ -320,7 +336,7 @@ void UIWidget::lockChild(const UIWidgetPtr& child)
320 336
     if(child->isFocusable())
321 337
         focusChild(child, Fw::ActiveFocusReason);
322 338
 
323
-    moveChildToTop(child);
339
+    raiseChild(child);
324 340
 }
325 341
 
326 342
 void UIWidget::unlockChild(const UIWidgetPtr& child)
@@ -360,7 +376,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
360 376
         if(lockedChild->isFocusable())
361 377
             focusChild(lockedChild, Fw::ActiveFocusReason);
362 378
 
363
-        moveChildToTop(lockedChild);
379
+        raiseChild(lockedChild);
364 380
     }
365 381
 }
366 382
 
@@ -460,6 +476,21 @@ void UIWidget::focus()
460 476
         parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
461 477
 }
462 478
 
479
+void UIWidget::lower()
480
+{
481
+    UIWidgetPtr parent = getParent();
482
+    if(parent)
483
+        parent->lowerChild(asUIWidget());
484
+}
485
+
486
+void UIWidget::raise()
487
+{
488
+    focus();
489
+    UIWidgetPtr parent = getParent();
490
+    if(parent)
491
+        parent->raiseChild(asUIWidget());
492
+}
493
+
463 494
 void UIWidget::grabMouse()
464 495
 {
465 496
     g_ui.setMouseReceiver(asUIWidget());
@@ -515,8 +546,25 @@ void UIWidget::destroy()
515 546
             parent->removeChild(asUIWidget());
516 547
     }
517 548
 
549
+    // destroy children
550
+    while(!m_children.empty())
551
+        getFirstChild()->destroy();
552
+
518 553
     callLuaField("onDestroy");
519 554
 
555
+#ifdef DEBUG
556
+    auto self = asUIWidget();
557
+    g_lua.collectGarbage();
558
+    g_dispatcher.addEvent([self] {
559
+        g_lua.collectGarbage();
560
+        g_dispatcher.addEvent([self] {
561
+            g_lua.collectGarbage();
562
+            if(self->getUseCount() != 1)
563
+                logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left");
564
+        });
565
+    });
566
+#endif
567
+
520 568
     m_destroyed = true;
521 569
 }
522 570
 
@@ -905,17 +953,11 @@ void UIWidget::updateState(Fw::WidgetState state)
905 953
         }
906 954
         case Fw::HoverState: {
907 955
             updateChildren = true;
908
-            Point mousePos = g_window.getMousePos();
909
-            UIWidgetPtr widget = asUIWidget();
910
-            UIWidgetPtr parent;
911
-            do {
912
-                parent = widget->getParent();
913
-                if(!widget->isExplicitlyEnabled() || !widget->isExplicitlyVisible() || !widget->containsPoint(mousePos) ||
914
-                   (parent && widget != parent->getChildByPos(mousePos))) {
915
-                    newStatus = false;
916
-                    break;
917
-                }
918
-            } while(widget = parent);
956
+            Point mousePos = g_window.getMousePosition();
957
+            UIWidgetPtr self = asUIWidget();
958
+            UIWidgetPtr rootParent = self->getRootParent();
959
+            if(!rootParent || rootParent->recursiveGetChildByPos(mousePos) != self)
960
+                newStatus = false;
919 961
             break;
920 962
         }
921 963
         case Fw::PressedState: {
@@ -1273,7 +1315,7 @@ bool UIWidget::propagateOnMousePress(const Point& mousePos, Fw::MouseButton butt
1273 1315
             return true;
1274 1316
     }
1275 1317
 
1276
-    // only non phatom widgets receives mouse press events
1318
+    // only non phatom widgets receives mouse events
1277 1319
     if(!isPhantom()) {
1278 1320
         bool ret = onMousePress(mousePos, button);
1279 1321
         if(button == Fw::MouseLeftButton && !isPressed())
@@ -1302,12 +1344,15 @@ bool UIWidget::propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton bu
1302 1344
             return true;
1303 1345
     }
1304 1346
 
1305
-    bool ret = onMouseRelease(mousePos, button);
1306
-
1307
-    if(isPressed() && button == Fw::MouseLeftButton)
1308
-        setPressed(false);
1347
+    // only non phatom widgets receives mouse events
1348
+    if(!isPhantom()) {
1349
+        bool ret = onMouseRelease(mousePos, button);
1350
+        if(isPressed() && button == Fw::MouseLeftButton)
1351
+            setPressed(false);
1352
+        return ret;
1353
+    }
1309 1354
 
1310
-    return ret;
1355
+    return false;
1311 1356
 }
1312 1357
 
1313 1358
 bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved)
@@ -1328,10 +1373,7 @@ bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMov
1328 1373
             return true;
1329 1374
     }
1330 1375
 
1331
-    if(!isPhantom())
1332
-        return onMouseMove(mousePos, mouseMoved);
1333
-    else
1334
-        return false;
1376
+    return onMouseMove(mousePos, mouseMoved);
1335 1377
 }
1336 1378
 
1337 1379
 bool UIWidget::propagateOnMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction)
@@ -1353,6 +1395,7 @@ bool UIWidget::propagateOnMouseWheel(const Point& mousePos, Fw::MouseWheelDirect
1353 1395
             return true;
1354 1396
     }
1355 1397
 
1398
+    // only non phatom widgets receives mouse events
1356 1399
     if(!isPhantom())
1357 1400
         return onMouseWheel(mousePos, direction);
1358 1401
     else

+ 5
- 2
src/framework/ui/uiwidget.h View File

@@ -78,11 +78,12 @@ protected:
78 78
 public:
79 79
     void addChild(const UIWidgetPtr& child);
80 80
     void insertChild(int index, const UIWidgetPtr& child);
81
-    void removeChild(const UIWidgetPtr& child);
81
+    void removeChild(UIWidgetPtr child);
82 82
     void focusChild(const UIWidgetPtr& child, Fw::FocusReason reason);
83 83
     void focusNextChild(Fw::FocusReason reason);
84 84
     void focusPreviousChild(Fw::FocusReason reason);
85
-    void moveChildToTop(const UIWidgetPtr& child);
85
+    void lowerChild(UIWidgetPtr child);
86
+    void raiseChild(UIWidgetPtr child);
86 87
     void moveChildToIndex(const UIWidgetPtr& child, int index);
87 88
     void lockChild(const UIWidgetPtr& child);
88 89
     void unlockChild(const UIWidgetPtr& child);
@@ -96,6 +97,8 @@ public:
96 97
     void lock();
97 98
     void unlock();
98 99
     void focus();
100
+    void lower();
101
+    void raise();
99 102
     void grabMouse();
100 103
     void ungrabMouse();
101 104
     void grabKeyboard();

+ 7
- 7
src/otclient/CMakeLists.txt View File

@@ -4,17 +4,17 @@ IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
4 4
 ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
5 5
 
6 6
 # otclient options
7
-OPTION(NO_BOT_PROTECTION "Disables bot protection" OFF)
8
-SET(PROTOCOL 862 CACHE "Protocol version" STRING)
7
+OPTION(BOT_PROTECTION "Enable bot protection" ON)
8
+SET(PROTOCOL 861 CACHE "Protocol version" STRING)
9 9
 ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL})
10 10
 MESSAGE(STATUS "Protocol: " ${PROTOCOL})
11 11
 
12
-IF(NO_BOT_PROTECTION)
13
-    ADD_DEFINITIONS(-DNO_BOT_PROTECTION)
14
-    MESSAGE(STATUS "Bot protection: OFF")
15
-ELSE(NO_BOT_PROTECTION)
12
+IF(BOT_PROTECTION)
13
+    ADD_DEFINITIONS(-DBOT_PROTECTION)
16 14
     MESSAGE(STATUS "Bot protection: ON")
17
-ENDIF(NO_BOT_PROTECTION)
15
+ELSE(BOT_PROTECTION)
16
+    MESSAGE(STATUS "Bot protection: OFF")
17
+ENDIF(BOT_PROTECTION)
18 18
 
19 19
 SET(otclient_SOURCES ${otclient_SOURCES}
20 20
     # otclient

+ 2
- 2
src/otclient/core/game.cpp View File

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

+ 1
- 1
src/otclient/otclient.cpp View File

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

Loading…
Cancel
Save