Browse Source

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
Eduardo Bart 9 years ago
parent
commit
c0611bfe2a
99 changed files with 938 additions and 385 deletions
  1. 7
    0
      modules/client/client.lua
  2. 1
    0
      modules/client/client.otmod
  3. 4
    1
      modules/client_background/background.lua
  4. 2
    2
      modules/client_background/background.otui
  5. 12
    12
      modules/client_entergame/characterlist.lua
  6. 2
    6
      modules/client_terminal/terminal.lua
  7. 8
    6
      modules/client_topmenu/topmenu.lua
  8. 2
    4
      modules/core_lib/core_lib.otmod
  9. 0
    2
      modules/core_lib/globals.lua
  10. 1
    1
      modules/core_lib/keyboard.lua
  11. 1
    1
      modules/core_lib/mouse.lua
  12. 2
    1
      modules/core_lib/widgets/uitabbar.lua
  13. 1
    3
      modules/core_styles/core_styles.otmod
  14. BIN
      modules/core_styles/icons/exit.png
  15. 1
    1
      modules/core_styles/styles/buttons.otui
  16. 1
    1
      modules/core_styles/styles/comboboxes.otui
  17. 0
    0
      modules/core_styles/styles/messageboxes.otui
  18. 0
    1
      modules/core_styles/styles/progressbars.otui
  19. 1
    1
      modules/core_styles/styles/separators.otui
  20. 1
    1
      modules/core_styles/styles/tabbars.otui
  21. 0
    21
      modules/core_styles/styles/windows.otui
  22. 24
    0
      modules/game/const.lua
  23. 19
    19
      modules/game/creature.lua
  24. 20
    5
      modules/game/game.otmod
  25. 295
    0
      modules/game/gameinterface.lua
  26. 53
    0
      modules/game/gameinterface.otui
  27. 0
    0
      modules/game/icons/emblem_blue.png
  28. 0
    0
      modules/game/icons/emblem_green.png
  29. 0
    0
      modules/game/icons/emblem_red.png
  30. 0
    0
      modules/game/icons/shield_blue.png
  31. 0
    0
      modules/game/icons/shield_blue_not_shared.png
  32. 0
    0
      modules/game/icons/shield_blue_shared.png
  33. 0
    0
      modules/game/icons/shield_blue_white.png
  34. 0
    0
      modules/game/icons/shield_yellow.png
  35. 0
    0
      modules/game/icons/shield_yellow_not_shared.png
  36. 0
    0
      modules/game/icons/shield_yellow_shared.png
  37. 0
    0
      modules/game/icons/shield_yellow_white.png
  38. 0
    0
      modules/game/icons/skull_black.png
  39. 0
    0
      modules/game/icons/skull_green.png
  40. 0
    0
      modules/game/icons/skull_orange.png
  41. 0
    0
      modules/game/icons/skull_red.png
  42. 0
    0
      modules/game/icons/skull_white.png
  43. 0
    0
      modules/game/icons/skull_yellow.png
  44. 0
    0
      modules/game/images/bottompanel.png
  45. 0
    0
      modules/game/images/logout.png
  46. 0
    0
      modules/game/images/mappanel.png
  47. 0
    0
      modules/game/images/miniwindow.png
  48. 0
    0
      modules/game/images/sidepanel.png
  49. 41
    0
      modules/game/styles/countwindow.otui
  50. 0
    0
      modules/game/styles/creatures.otui
  51. 0
    0
      modules/game/styles/items.otui
  52. 20
    0
      modules/game/styles/miniwindow.otui
  53. 0
    0
      modules/game/uiminiwindow.lua
  54. 2
    0
      modules/game/widgets/uicountwindow.lua
  55. 64
    0
      modules/game/widgets/uigamemap.lua
  56. 5
    2
      modules/game/widgets/uiitem.lua
  57. 0
    0
      modules/game/widgets/uiminiwindowcontainer.lua
  58. 1
    1
      modules/game_console/channelswindow.otui
  59. 102
    82
      modules/game_console/console.lua
  60. 10
    1
      modules/game_console/console.otmod
  61. 6
    7
      modules/game_console/console.otui
  62. 32
    18
      modules/game_textmessage/textmessage.lua
  63. 10
    1
      modules/game_textmessage/textmessage.otmod
  64. 0
    0
      modules/game_textmessage/textmessage.otui
  65. 0
    0
      modules/old/game/game.lua
  66. 17
    0
      modules/old/game/game.otmod
  67. 0
    0
      modules/old/game/game.otui
  68. 0
    0
      modules/old/game/map.lua
  69. 1
    1
      modules/old/game/movewindow.otui
  70. 0
    0
      modules/old/game/player.lua
  71. 0
    0
      modules/old/game/thing.lua
  72. 1
    1
      modules/old/game_hotkeys/hotkeys_manager.lua
  73. 1
    1
      modules/old/game_hotkeys/hotkeys_manager.otui
  74. 4
    4
      modules/old/game_interface/gameinterface.otui
  75. 3
    9
      modules/otclientrc.lua
  76. 12
    9
      src/framework/CMakeLists.txt
  77. 1
    4
      src/framework/application.cpp
  78. 2
    0
      src/framework/luafunctions.cpp
  79. 40
    21
      src/framework/ui/uilineedit.cpp
  80. 3
    0
      src/framework/ui/uilineedit.h
  81. 5
    0
      src/framework/ui/uimanager.cpp
  82. 6
    4
      src/framework/ui/uiwidget.cpp
  83. 8
    0
      src/framework/ui/uiwidgettext.cpp
  84. 1
    0
      src/otclient/CMakeLists.txt
  85. 23
    0
      src/otclient/core/container.cpp
  86. 6
    7
      src/otclient/core/container.h
  87. 2
    0
      src/otclient/core/declarations.h
  88. 0
    1
      src/otclient/core/game.cpp
  89. 2
    0
      src/otclient/core/game.h
  90. 6
    2
      src/otclient/core/mapview.cpp
  91. 0
    2
      src/otclient/core/mapview.h
  92. 23
    0
      src/otclient/core/player.cpp
  93. 4
    0
      src/otclient/core/player.h
  94. 8
    0
      src/otclient/core/thing.cpp
  95. 1
    0
      src/otclient/core/thing.h
  96. 1
    0
      src/otclient/luafunctions.cpp
  97. 0
    117
      src/otclient/ui/uigame.cpp
  98. 5
    1
      src/otclient/ui/uimap.cpp
  99. 1
    0
      src/otclient/ui/uimap.h

+ 7
- 0
modules/client/client.lua View File

@@ -1,5 +1,12 @@
1 1
 Client = {}
2 2
 
3
+function Client.reloadScripts()
4
+  dofile 'otclientrc.lua'
5
+  reloadModules()
6
+  TextMessage.displayEventAdvance('All modules and scripts were reloaded.')
7
+  print('All modules and scripts were reloaded.')
8
+end
9
+
3 10
 function Client.init()
4 11
   g_window.setMinimumSize({ width = 600, height = 480 })
5 12
 

+ 1
- 0
modules/client/client.otmod View File

@@ -14,6 +14,7 @@ Module
14 14
     - client_terminal
15 15
     - client_modulemanager
16 16
     - client_entergame
17
+    - game
17 18
 
18 19
   @onLoad: |
19 20
     dofile 'client'

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

@@ -11,7 +11,10 @@ function Background.init()
11 11
   local clientVersionLabel = background:getChildById('clientVersionLabel')
12 12
   clientVersionLabel:setText('OTClient ' .. g_app.getVersion() .. '\n' ..
13 13
                              'Built on ' .. g_app.getBuildDate())
14
-  Effects.fadeIn(clientVersionLabel, 1500)
14
+
15
+  if not g_game.isOnline() then
16
+    Effects.fadeIn(clientVersionLabel, 1500)
17
+  end
15 18
 
16 19
   connect(g_game, { onGameStart = Background.hide })
17 20
   connect(g_game, { onGameEnd = Background.show })

+ 2
- 2
modules/client_background/background.otui View File

@@ -11,12 +11,12 @@ Panel
11 11
   focusable: false
12 12
 
13 13
   UILabel
14
-    background-color: #00000099
15 14
     id: clientVersionLabel
15
+    background-color: #00000099
16 16
     anchors.right: parent.right
17 17
     anchors.bottom: parent.bottom
18 18
     text-offset: 4 2
19 19
     height: 32
20 20
     width: 120
21 21
     color: #ffffff
22
-    font: verdana-11px-monochrome
22
+    font: verdana-11px-monochrome

+ 12
- 12
modules/client_entergame/characterlist.lua View File

@@ -52,7 +52,6 @@ local function tryLogin(charInfo, tries)
52 52
   Settings.set('lastUsedCharacter', charInfo.characterName)
53 53
 end
54 54
 
55
-
56 55
 function onGameLoginError(message)
57 56
   CharacterList.destroyLoadBox()
58 57
   local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
@@ -67,6 +66,10 @@ end
67 66
 
68 67
 -- public functions
69 68
 function CharacterList.init()
69
+  charactersWindow = displayUI('characterlist.otui')
70
+  charactersWindow:hide()
71
+  characterList = charactersWindow:getChildById('characterList')
72
+  charactersWindow.onKeyPress = onCharactersWindowKeyPress
70 73
   connect(g_game, { onLoginError = onGameLoginError })
71 74
   connect(g_game, { onConnectionError = onGameConnectionError })
72 75
   connect(g_game, { onGameStart = CharacterList.destroyLoadBox })
@@ -74,11 +77,13 @@ function CharacterList.init()
74 77
 end
75 78
 
76 79
 function CharacterList.terminate()
80
+  disconnect(g_game, { onLoginError = onGameLoginError })
81
+  disconnect(g_game, { onConnectionError = onGameConnectionError })
82
+  disconnect(g_game, { onGameStart = CharacterList.destroyLoadBox })
83
+  disconnect(g_game, { onGameEnd = CharacterList.show })
77 84
   characterList = nil
78
-  if charactersWindow then
79
-    charactersWindow:destroy()
80
-    charactersWindow = nil
81
-  end
85
+  charactersWindow:destroy()
86
+  charactersWindow = nil
82 87
   if loadBox then
83 88
     g_game.cancelLogin()
84 89
     loadBox:destroy()
@@ -88,14 +93,9 @@ function CharacterList.terminate()
88 93
 end
89 94
 
90 95
 function CharacterList.create(characters, premDays)
91
-  if charactersWindow then
92
-    charactersWindow:destroy()
93
-  end
94
-
95
-  charactersWindow = displayUI('characterlist.otui')
96
-  characterList = charactersWindow:getChildById('characterList')
96
+  CharacterList.show()
97
+  characterList:destroyChildren()
97 98
   local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
98
-  connect(charactersWindow, {onKeyPress = onCharactersWindowKeyPress })
99 99
 
100 100
   local focusLabel
101 101
   for i,characterInfo in ipairs(characters) do

+ 2
- 6
modules/client_terminal/terminal.lua View File

@@ -184,12 +184,8 @@ function Terminal.executeCommand(command)
184 184
 
185 185
   -- detect and convert commands with simple syntax
186 186
   local realCommand
187
-  if commandEnv[command] then
188
-    if type(commandEnv[command]) == "function" then
189
-      realCommand = command .. '()'
190
-    else
191
-      realCommand = 'print(' .. command .. ')'
192
-    end
187
+  if string.sub(command, 1, 1) == '=' then
188
+    realCommand = 'print(' .. string.sub(command,2) .. ')'
193 189
   else
194 190
     realCommand = command
195 191
   end

+ 8
- 6
modules/client_topmenu/topmenu.lua View File

@@ -30,25 +30,27 @@ end
30 30
 
31 31
 -- public functions
32 32
 function TopMenu.init()
33
+  connect(g_game, { onGameStart = TopMenu.showGameButtons,
34
+                    onGameEnd = TopMenu.hideGameButtons })
35
+
33 36
   topMenu = displayUI('topmenu.otui')
37
+
34 38
   leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
35 39
   rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
36 40
   gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
37
-
38
-  connect(g_game, { onGameStart = TopMenu.showGameButtons,
39
-                    onGameEnd = TopMenu.hideGameButtons })
40 41
 end
41 42
 
42 43
 function TopMenu.terminate()
44
+  disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
45
+                       onGameEnd = TopMenu.hideGameButtons })
46
+
43 47
   leftButtonsPanel = nil
44 48
   rightButtonsPanel = nil
45 49
   gameButtonsPanel = nil
50
+
46 51
   topMenu:destroy()
47 52
   topMenu = nil
48 53
 
49
-  disconnect(g_game, { onGameStart = TopMenu.showGameButtons,
50
-                       onGameEnd = TopMenu.hideGameButtons })
51
-
52 54
   TopMenu = nil
53 55
 end
54 56
 

+ 2
- 4
modules/core_lib/core_lib.otmod View File

@@ -10,10 +10,12 @@ Module
10 10
     dofile 'ext/table'
11 11
     dofile 'ext/string'
12 12
     dofile 'ext/os'
13
+
13 14
     dofile 'math/point'
14 15
     dofile 'math/size'
15 16
     dofile 'math/color'
16 17
     dofile 'math/rect'
18
+
17 19
     dofile 'const'
18 20
     dofile 'util'
19 21
     dofile 'globals'
@@ -35,8 +37,4 @@ Module
35 37
     dofile 'widgets/uitabbar'
36 38
     dofile 'widgets/uipopupmenu'
37 39
     dofile 'widgets/uiwindow'
38
-    --dofile 'widgets/uiminiwindow'
39
-    --dofile 'widgets/uiminiwindowcontainer'
40 40
     dofile 'widgets/uimessagebox'
41
-
42
-

+ 0
- 2
modules/core_lib/globals.lua View File

@@ -68,5 +68,3 @@ end
68 68
 function reloadModules()
69 69
   g_modules.reloadModules()
70 70
 end
71
-
72
-

+ 1
- 1
modules/core_lib/keyboard.lua View File

@@ -70,8 +70,8 @@ local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
70 70
 end
71 71
 
72 72
 local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTicks)
73
-  local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
74 73
   if keyCode == KeyUnknown then return false end
74
+  local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
75 75
   local comboConf = widget.boundKeyPressCombos[keyComboDesc]
76 76
   if comboConf and (autoRepeatTicks >= comboConf.autoRepeatDelay or autoRepeatTicks == 0) and comboConf.callback then
77 77
     comboConf.callback()

+ 1
- 1
modules/core_lib/mouse.lua View File

@@ -1,7 +1,7 @@
1 1
 Mouse = {}
2 2
 
3 3
 function Mouse.setTargetCursor()
4
-  g_window.setMouseCursor('/core_styles/icons/targetcursor.png', {x=9,y=9})
4
+  g_window.setMouseCursor('/core_styles/cursors/targetcursor.png', {x=9,y=9})
5 5
 end
6 6
 
7 7
 function Mouse.restoreCursor()

+ 2
- 1
modules/core_lib/widgets/uitabbar.lua View File

@@ -36,7 +36,8 @@ function UITabBar:addTab(text, panel)
36 36
   tab.tabBar = self
37 37
   tab:setText(text)
38 38
   tab:setWidth(tab:getTextSize().width + tab:getPaddingLeft() + tab:getPaddingRight())
39
-  connect(tab, { onClick = onTabClick })
39
+  tab.onClick = onTabClick
40
+  tab.onDestroy = function() tab.tabPanel:destroy() end
40 41
 
41 42
   table.insert(self.tabs, tab)
42 43
   if #self.tabs == 1 then

+ 1
- 3
modules/core_styles/core_styles.otmod View File

@@ -23,9 +23,7 @@ Module
23 23
     importStyle 'styles/tabbars.otui'
24 24
     importStyle 'styles/windows.otui'
25 25
     importStyle 'styles/listboxes.otui'
26
-    importStyle 'styles/items.otui'
27
-    importStyle 'styles/creatures.otui'
28 26
     importStyle 'styles/popupmenus.otui'
29 27
     importStyle 'styles/comboboxes.otui'
30 28
     importStyle 'styles/spinboxes.otui'
31
-    importStyle 'styles/messagebox.otui'
29
+    importStyle 'styles/messageboxes.otui'

BIN
modules/core_styles/icons/exit.png View File


+ 1
- 1
modules/core_styles/styles/buttons.otui View File

@@ -18,7 +18,7 @@ Button < UIButton
18 18
     color: #f0ad4d88
19 19
     image-color: #ffffff88
20 20
 
21
-ConsoleButton < UIButton
21
+TabButton < UIButton
22 22
   size: 20 20
23 23
   image-source: /core_styles/styles/images/tabbutton.png
24 24
   image-color: white

+ 1
- 1
modules/core_styles/styles/comboboxes.otui View File

@@ -42,4 +42,4 @@ ComboBox < UIComboBox
42 42
     image-clip: 0 20 89 20
43 43
 
44 44
   $on:
45
-    image-clip: 0 40 89 20
45
+    image-clip: 0 40 89 20

modules/core_styles/styles/messagebox.otui → modules/core_styles/styles/messageboxes.otui View File


+ 0
- 1
modules/core_styles/styles/progressbars.otui View File

@@ -4,4 +4,3 @@ ProgressBar < UIProgressBar
4 4
   border: 1 black
5 5
   image: /core_styles/styles/images/progressbar.png
6 6
   image-border: 1
7
-

+ 1
- 1
modules/core_styles/styles/separators.otui View File

@@ -3,4 +3,4 @@ HorizontalSeparator < UIWidget
3 3
   image-border-top: 2
4 4
   height: 2
5 5
   phantom: true
6
-  focusable: false
6
+  focusable: false

+ 1
- 1
modules/core_styles/styles/tabbars.otui View File

@@ -31,4 +31,4 @@ TabBarButton < UIButton
31 31
     color: #80c7f8
32 32
 
33 33
   $on !checked:
34
-    color: #F55E5E
34
+    color: #F55E5E

+ 0
- 21
modules/core_styles/styles/windows.otui View File

@@ -22,24 +22,3 @@ Window < UIWindow
22 22
 
23 23
 MainWindow < Window
24 24
   anchors.centerIn: parent
25
-
26
-MiniWindow < UIMiniWindow
27
-  font: verdana-11px-antialised
28
-  //icon: /core_styles/icons/login.png
29
-  icon-rect: 4 4 16 16
30
-  width: 192
31
-  height: 200
32
-  text-offset: 26 5
33
-  text-align: topLeft
34
-  margin-top: 2
35
-  margin-left: 6
36
-  margin-right: 6
37
-  move-policy: free updated
38
-  image-source: /core_styles/styles/images/mini_window.png
39
-  image-border: 4
40
-  image-border-top: 23
41
-  padding: 25 8 2 8
42
-
43
-  $on:
44
-    height: 24
45
-    image-border-bottom: 1

+ 24
- 0
modules/game/const.lua View File

@@ -0,0 +1,24 @@
1
+SkullNone = 0
2
+SkullYellow = 1
3
+SkullGreen = 2
4
+SkullWhite = 3
5
+SkullRed = 4
6
+SkullBlack = 5
7
+SkullOrange = 6
8
+
9
+ShieldNone = 0
10
+ShieldWhiteYellow = 1
11
+ShieldWhiteBlue = 2
12
+ShieldBlue = 3
13
+ShieldYellow = 4
14
+ShieldBlueSharedExp = 5
15
+ShieldYellowSharedExp = 6
16
+ShieldBlueNoSharedExpBlink = 7
17
+ShieldYellowNoSharedExpBlink = 8
18
+ShieldBlueNoSharedExp = 9
19
+ShieldYellowNoSharedExp = 10
20
+
21
+EmblemNone = 0
22
+EmblemGreen = 1
23
+EmblemRed = 2
24
+EmblemBlue = 3

+ 19
- 19
modules/game/creature.lua View File

@@ -25,51 +25,51 @@ EmblemBlue = 3
25 25
 
26 26
 function getSkullImagePath(skullId)
27 27
   if skullId == SkullYellow then
28
-    return 'images/skull_yellow.png'
28
+    return 'icons/skull_yellow.png'
29 29
   elseif skullId == SkullGreen then
30
-    return 'images/skull_green.png'
30
+    return 'icons/skull_green.png'
31 31
   elseif skullId == SkullWhite then
32
-    return 'images/skull_white.png'
32
+    return 'icons/skull_white.png'
33 33
   elseif skullId == SkullRed then
34
-    return 'images/skull_red.png'
34
+    return 'icons/skull_red.png'
35 35
   elseif skullId == SkullBlack then
36
-    return 'images/skull_black.png'
36
+    return 'icons/skull_black.png'
37 37
   elseif skullId == SkullOrange then
38
-    return 'images/skull_orange.png'
38
+    return 'icons/skull_orange.png'
39 39
   end
40 40
 end
41 41
 
42 42
 function getShieldImagePathAndBlink(shieldId)
43 43
   if shieldId == ShieldWhiteYellow then
44
-    return 'images/shield_yellow_white.png', false
44
+    return 'icons/shield_yellow_white.png', false
45 45
   elseif shieldId == ShieldWhiteBlue then
46
-    return 'images/shield_blue_white.png', false
46
+    return 'icons/shield_blue_white.png', false
47 47
   elseif shieldId == ShieldBlue then
48
-    return 'images/shield_blue.png', false
48
+    return 'icons/shield_blue.png', false
49 49
   elseif shieldId == ShieldYellow then
50
-    return 'images/shield_yellow.png', false
50
+    return 'icons/shield_yellow.png', false
51 51
   elseif shieldId == ShieldBlueSharedExp then
52
-    return 'images/shield_blue_shared.png', false
52
+    return 'icons/shield_blue_shared.png', false
53 53
   elseif shieldId == ShieldYellowSharedExp then
54
-    return 'images/shield_yellow_shared.png', false
54
+    return 'icons/shield_yellow_shared.png', false
55 55
   elseif shieldId == ShieldBlueNoSharedExpBlink then
56
-    return 'images/shield_blue_not_shared.png', true
56
+    return 'icons/shield_blue_not_shared.png', true
57 57
   elseif shieldId == ShieldYellowNoSharedExpBlink then
58
-    return 'images/shield_yellow_not_shared.png', true
58
+    return 'icons/shield_yellow_not_shared.png', true
59 59
   elseif shieldId == ShieldBlueNoSharedExp then
60
-    return 'images/shield_blue_not_shared.png', false
60
+    return 'icons/shield_blue_not_shared.png', false
61 61
   elseif shieldId == ShieldYellowNoSharedExp then
62
-    return 'images/shield_yellow_not_shared.png', false
62
+    return 'icons/shield_yellow_not_shared.png', false
63 63
   end
64 64
 end
65 65
 
66 66
 function getEmblemImagePath(emblemId)
67 67
   if emblemId == EmblemGreen then
68
-    return 'images/emblem_green.png'
68
+    return 'icons/emblem_green.png'
69 69
   elseif emblemId == EmblemRed then
70
-    return 'images/emblem_red.png'
70
+    return 'icons/emblem_red.png'
71 71
   elseif emblemId == EmblemBlue then
72
-    return 'images/emblem_blue.png'
72
+    return 'icons/emblem_blue.png'
73 73
   end
74 74
 end
75 75
 

+ 20
- 5
modules/game/game.otmod View File

@@ -7,11 +7,26 @@ Module
7 7
 
8 8
   dependencies:
9 9
     - game_tibiafiles
10
+    - client_background
10 11
     //- game_shaders
11 12
 
12
-  onLoad: |
13
-    dofile 'game'
14
-    dofile 'thing'
13
+  load-later:
14
+    - game_textmessage
15
+    - game_console
16
+
17
+  @onLoad: |
18
+    importStyle 'styles/items.otui'
19
+    importStyle 'styles/creatures.otui'
20
+    importStyle 'styles/miniwindow.otui'
21
+    importStyle 'styles/countwindow.otui'
22
+
23
+    dofile 'const'
24
+
25
+    dofile 'widgets/uigamemap'
26
+
27
+    dofile 'gameinterface'
15 28
     dofile 'creature'
16
-    dofile 'player'
17
-    dofile 'map'
29
+    GameInterface.init()
30
+
31
+  @onUnload: |
32
+    GameInterface.terminate()

+ 295
- 0
modules/game/gameinterface.lua View File

@@ -0,0 +1,295 @@
1
+GameInterface = {}
2
+
3
+local WALK_AUTO_REPEAT_DELAY = 90
4
+local gameRootPanel
5
+local gameMapPanel
6
+local gameRightPanel
7
+local gameLeftPanel
8
+local gameBottomPanel
9
+local logoutButton
10
+
11
+function GameInterface.init()
12
+  connect(g_game, { onGameStart = GameInterface.show }, true)
13
+  connect(g_game, { onGameEnd = GameInterface.hide }, true)
14
+
15
+  gameRootPanel = displayUI('gameinterface.otui')
16
+  gameRootPanel:hide()
17
+  gameRootPanel:lower()
18
+
19
+  gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
20
+  gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
21
+  gameLeftPanel = gameRootPanel:getChildById('gameLeftPanel')
22
+  gameBottomPanel = gameRootPanel:getChildById('gameBottomPanel')
23
+
24
+  logoutButton = TopMenu.addRightButton('logoutButton', 'Logout', 'images/logout.png', GameInterface.tryLogout)
25
+  logoutButton:hide()
26
+
27
+  Keyboard.bindKeyPress('Up', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
28
+  Keyboard.bindKeyPress('Right', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
29
+  Keyboard.bindKeyPress('Down', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
30
+  Keyboard.bindKeyPress('Left', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
31
+  Keyboard.bindKeyPress('Numpad8', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
32
+  Keyboard.bindKeyPress('Numpad9', function() g_game.walk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
33
+  Keyboard.bindKeyPress('Numpad6', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
34
+  Keyboard.bindKeyPress('Numpad3', function() g_game.walk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
35
+  Keyboard.bindKeyPress('Numpad2', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
36
+  Keyboard.bindKeyPress('Numpad1', function() g_game.walk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
37
+  Keyboard.bindKeyPress('Numpad4', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
38
+  Keyboard.bindKeyPress('Numpad7', function() g_game.walk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
39
+  Keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
40
+  Keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
41
+  Keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
42
+  Keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
43
+  Keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
44
+  Keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
45
+  Keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
46
+  Keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
47
+  Keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
48
+
49
+  if g_game.isOnline() then
50
+    GameInterface.show()
51
+  end
52
+end
53
+
54
+function GameInterface.terminate()
55
+  disconnect(g_game, { onGameStart = GameInterface.show })
56
+  disconnect(g_game, { onGameEnd = GameInterface.hide })
57
+
58
+  logoutButton:destroy()
59
+  logoutButton = nil
60
+  gameRootPanel:destroy()
61
+  gameRootPanel = nil
62
+  gameMapPanel = nil
63
+  gameRightPanel = nil
64
+  gameLeftPanel = nil
65
+  gameBottomPanel = nil
66
+  GameInterface = nil
67
+end
68
+
69
+function GameInterface.show()
70
+  g_app.onClose = GameInterface.tryExit
71
+  logoutButton:show()
72
+  Background.hide()
73
+  gameRootPanel:show()
74
+  gameRootPanel:focus()
75
+  gameMapPanel:followCreature(g_game.getLocalPlayer())
76
+end
77
+
78
+function GameInterface.hide()
79
+  gameRootPanel:hide()
80
+  logoutButton:hide()
81
+  Background.show()
82
+  g_app.onClose = nil
83
+end
84
+
85
+function GameInterface.tryExit()
86
+  if g_game.isOnline() then
87
+    g_game.forceLogout()
88
+    scheduleEvent(exit, 10)
89
+  end
90
+end
91
+
92
+function GameInterface.tryLogout()
93
+  if g_game.isOnline() then
94
+    g_game.safeLogout()
95
+    return true
96
+  end
97
+end
98
+
99
+function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
100
+  local menu = createWidget('PopupMenu')
101
+
102
+  if lookThing then
103
+    menu:addOption('Look', function() g_game.look(lookThing) end)
104
+  end
105
+
106
+  if useThing then
107
+    if useThing:isContainer() then
108
+      if useThing:isInsideContainer() then
109
+        menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end)
110
+        menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
111
+      else
112
+        menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
113
+      end
114
+    else
115
+      if useThing:isMultiUse() then
116
+        menu:addOption('Use with ...', function() g_game.startUseWith(useThing) end)
117
+      else
118
+        menu:addOption('Use', function() g_game.use(useThing) end)
119
+      end
120
+    end
121
+
122
+    if useThing:isRotateable() then
123
+      menu:addOption('Rotate', function() g_game.rotate(useThing) end)
124
+    end
125
+
126
+  end
127
+
128
+  if lookThing and not lookThing:asCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
129
+    menu:addSeparator()
130
+    menu:addOption('Trade with ...', function() print('trade with') end)
131
+  end
132
+
133
+  -- check for move up
134
+
135
+  if creatureThing then
136
+    menu:addSeparator()
137
+
138
+    if creatureThing:asLocalPlayer() then
139
+      menu:addOption('Set Outfit', function() g_game.requestOutfit() end)
140
+
141
+      if creatureThing:isPartyMember() --[[and not fighting]] then
142
+        if creatureThing:isPartyLeader() then
143
+          if creatureThing:isPartySharedExperienceActive() then
144
+            menu:addOption('Disable Shared Experience', function() g_game.partyShareExperience(false) end)
145
+          else
146
+            menu:addOption('Enable Shared Experience', function() g_game.partyShareExperience(true) end)
147
+          end
148
+        end
149
+        menu:addOption('Leave Party', function() g_game.partyLeave() end)
150
+      end
151
+
152
+    else
153
+      local localPlayer = g_game.getLocalPlayer()
154
+      if localPlayer then
155
+        if g_game.getAttackingCreature() ~= creatureThing then
156
+          menu:addOption('Attack', function() g_game.attack(creatureThing) end)
157
+        else
158
+          menu:addOption('Stop Attack', function() g_game.cancelAttack() end)
159
+        end
160
+
161
+        if g_game.getFollowingCreature() ~= creatureThing then
162
+          menu:addOption('Follow', function() g_game.follow(creatureThing) end)
163
+        else
164
+          menu:addOption('Stop Follow', function() g_game.cancelFollow() end)
165
+        end
166
+
167
+        if creatureThing:asPlayer() then
168
+          menu:addSeparator()
169
+          menu:addOption('Message to ' .. creatureThing:getName(), function() print('message') end)
170
+          menu:addOption('Add to VIP list', function() g_game.addVip(creatureThing:getName()) end)
171
+
172
+          local localPlayerShield = localPlayer:asCreature():getShield()
173
+          local creatureShield = creatureThing:getShield()
174
+
175
+          if localPlayerShield == ShieldNone or localPlayerShield == ShieldWhiteBlue then
176
+            if creatureShield == ShieldWhiteYellow then
177
+              menu:addOption('Join ' .. creatureThing:getName() .. '\'s Party', function() g_game.partyJoin(creatureThing:getId()) end)
178
+            else
179
+              menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
180
+            end
181
+          elseif localPlayerShield == ShieldWhiteYellow then
182
+            if creatureShield == ShieldWhiteBlue then
183
+              menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
184
+            end
185
+          elseif localPlayerShield == ShieldYellow or localPlayerShield == ShieldYellowSharedExp or localPlayerShield == ShieldYellowNoSharedExpBlink or localPlayerShield == ShieldYellowNoSharedExp then
186
+            if creatureShield == ShieldWhiteBlue then
187
+              menu:addOption('Revoke ' .. creatureThing:getName() .. '\'s Invitation', function() g_game.partyRevokeInvitation(creatureThing:getId()) end)
188
+            elseif creatureShield == ShieldBlue or creatureShield == ShieldBlueSharedExp or creatureShield == ShieldBlueNoSharedExpBlink or creatureShield == ShieldBlueNoSharedExp then
189
+              menu:addOption('Pass Leadership to ' .. creatureThing:getName(), function() g_game.partyPassLeadership(creatureThing:getId()) end)
190
+            else
191
+              menu:addOption('Invite to Party', function() g_game.partyInvite(creatureThing:getId()) end)
192
+            end
193
+          end
194
+        end
195
+      end
196
+    end
197
+
198
+    menu:addSeparator()
199
+    menu:addOption('Copy Name', function() g_window.setClipboardText(creatureThing:getName()) end)
200
+
201
+  end
202
+
203
+  menu:display(menuPosition)
204
+end
205
+
206
+function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
207
+  local keyboardModifiers = g_window.getKeyboardModifiers()
208
+
209
+  if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
210
+    -- todo auto walk
211
+    return true
212
+  end
213
+
214
+  if not Options.classicControl then
215
+    if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
216
+      GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
217
+      return true
218
+    elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
219
+      g_game.look(lookThing)
220
+      return true
221
+    elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
222
+      if useThing:isContainer() then
223
+        if useThing:isInsideContainer() then
224
+          g_game.open(useThing, useThing:getContainerId())
225
+          return true
226
+        else
227
+          g_game.open(useThing, Containers.getFreeContainerId())
228
+        return true
229
+        end
230
+      elseif useThing:isMultiUse() then
231
+        g_game.startUseWith(useThing)
232
+        return true
233
+      else
234
+        g_game.use(useThing)
235
+        return true
236
+      end
237
+      return true
238
+    elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
239
+      g_game.attack(creatureThing)
240
+      return true
241
+    end
242
+  else
243
+    if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
244
+      if multiUseThing:asCreature() then
245
+        g_game.attack(multiUseThing:asCreature())
246
+        return true
247
+      elseif multiUseThing:isContainer() then
248
+        if multiUseThing:isInsideContainer() then
249
+          g_game.open(multiUseThing, multiUseThing:getContainerId())
250
+          return true
251
+        else
252
+          g_game.open(multiUseThing, Containers.getFreeContainerId())
253
+          return true
254
+        end
255
+      elseif multiUseThing:isMultiUse() then
256
+        g_game.startUseWith(multiUseThing)
257
+        return true
258
+      else
259
+        g_game.use(multiUseThing)
260
+      end
261
+      return true
262
+    elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
263
+      g_game.look(lookThing)
264
+      return true
265
+    elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
266
+      GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
267
+      return true
268
+    elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
269
+      g_game.attack(creatureThing)
270
+      return true
271
+    end
272
+  end
273
+
274
+  return false
275
+end
276
+
277
+function GameInterface.getRootPanel()
278
+  return gameRootPanel
279
+end
280
+
281
+function GameInterface.getMapPanel()
282
+  return gameMapPanel
283
+end
284
+
285
+function GameInterface.getRightPanel()
286
+  return gameRightPanel
287
+end
288
+
289
+function GameInterface.getLeftPanel()
290
+  return gameLeftPanel
291
+end
292
+
293
+function GameInterface.getBottomPanel()
294
+  return gameBottomPanel
295
+end

+ 53
- 0
modules/game/gameinterface.otui View File

@@ -0,0 +1,53 @@
1
+GameSidePanel < Panel
2
+  image-source: images/sidepanel.png
3
+  image-border: 4
4
+
5
+GameBottomPanel < Panel
6
+  image-source: images/bottompanel.png
7
+  image-border: 4
8
+
9
+GameMapPanel < UIGameMap
10
+  padding: 4
11
+  image-source: images/mappanel.png
12
+  image-border: 4
13
+
14
+UIWidget
15
+  id: gameRootPanel
16
+  anchors.fill: parent
17
+  anchors.top: topMenu.bottom
18
+
19
+  GameSidePanel
20
+    id: gameRightPanel
21
+    width: 190
22
+    layout: verticalBox
23
+    anchors.right: parent.right
24
+    anchors.top: parent.top
25
+    anchors.bottom: parent.bottom
26
+
27
+  GameSidePanel
28
+    id: gameLeftPanel
29
+    width: 190
30
+    layout: verticalBox
31
+    anchors.left: parent.left
32
+    anchors.top: parent.top
33
+    anchors.bottom: parent.bottom
34
+
35
+  GameBottomPanel
36
+    id: gameBottomPanel
37
+    height: 170
38
+    anchors.left: gameLeftPanel.right
39
+    anchors.right: gameRightPanel.left
40
+    anchors.bottom: parent.bottom
41
+
42
+  GameMapPanel
43
+    id: gameMapPanel
44
+    anchors.left: gameLeftPanel.right
45
+    anchors.right: gameRightPanel.left
46
+    anchors.top: parent.top
47
+    anchors.bottom: gameBottomPanel.top
48
+    focusable: false
49
+
50
+  UIWidget
51
+    id: mouseGrabber
52
+    focusable: false
53
+    visible: false

modules/game/images/emblem_blue.png → modules/game/icons/emblem_blue.png View File


modules/game/images/emblem_green.png → modules/game/icons/emblem_green.png View File


modules/game/images/emblem_red.png → modules/game/icons/emblem_red.png View File


modules/game/images/shield_blue.png → modules/game/icons/shield_blue.png View File


modules/game/images/shield_blue_not_shared.png → modules/game/icons/shield_blue_not_shared.png View File


modules/game/images/shield_blue_shared.png → modules/game/icons/shield_blue_shared.png View File


modules/game/images/shield_blue_white.png → modules/game/icons/shield_blue_white.png View File


modules/game/images/shield_yellow.png → modules/game/icons/shield_yellow.png View File


modules/game/images/shield_yellow_not_shared.png → modules/game/icons/shield_yellow_not_shared.png View File


modules/game/images/shield_yellow_shared.png → modules/game/icons/shield_yellow_shared.png View File


modules/game/images/shield_yellow_white.png → modules/game/icons/shield_yellow_white.png View File


modules/game/images/skull_black.png → modules/game/icons/skull_black.png View File


modules/game/images/skull_green.png → modules/game/icons/skull_green.png View File


modules/game/images/skull_orange.png → modules/game/icons/skull_orange.png View File


modules/game/images/skull_red.png → modules/game/icons/skull_red.png View File


modules/game/images/skull_white.png → modules/game/icons/skull_white.png View File


modules/game/images/skull_yellow.png → modules/game/icons/skull_yellow.png View File


modules/old/game_interface/images/bottompanel.png → modules/game/images/bottompanel.png View File


modules/core_styles/icons/logout.png → modules/game/images/logout.png View File


modules/old/game_interface/images/mappanel.png → modules/game/images/mappanel.png View File


modules/old/game_interface/images/miniwindow.png → modules/game/images/miniwindow.png View File


modules/old/game_interface/images/sidepanel.png → modules/game/images/sidepanel.png View File


+ 41
- 0
modules/game/styles/countwindow.otui View File

@@ -0,0 +1,41 @@
1
+CountWindow < MainWindow
2
+  id: countWindow
3
+  text: Move Staackable Item
4
+  size: 196 112
5
+  @onEscape: self:destroy()
6
+
7
+  Label
8
+    text: Amount:
9
+    width: 64
10
+    anchors.left: parent.left
11
+    anchors.top: parent.top
12
+    margin-top: 2
13
+
14
+  SpinBox
15
+    id: spinbox
16
+    anchors.left: prev.right
17
+    anchors.right: parent.right
18
+    anchors.top: parent.top
19
+
20
+  HorizontalSeparator
21
+    id: separator
22
+    anchors.left: parent.left
23
+    anchors.right: parent.right
24
+    anchors.bottom: next.top
25
+    margin-bottom: 10
26
+
27
+  Button
28
+    id: buttonOk
29
+    text: Ok
30
+    width: 64
31
+    anchors.right: next.left
32
+    anchors.bottom: parent.bottom
33
+    margin-right: 10
34
+
35
+  Button
36
+    id: buttonCancel
37
+    text: Cancel
38
+    width: 64
39
+    anchors.right: parent.right
40
+    anchors.bottom: parent.bottom
41
+    @onClick: self:getParent():destroy()

modules/core_styles/styles/creatures.otui → modules/game/styles/creatures.otui View File


modules/core_styles/styles/items.otui → modules/game/styles/items.otui View File


+ 20
- 0
modules/game/styles/miniwindow.otui View File

@@ -0,0 +1,20 @@
1
+MiniWindow < UIMiniWindow
2
+  font: verdana-11px-antialised
3
+  //icon: /core_styles/icons/login.png
4
+  icon-rect: 4 4 16 16
5
+  width: 192
6
+  height: 200
7
+  text-offset: 26 5
8
+  text-align: topLeft
9
+  margin-top: 2
10
+  margin-left: 6
11
+  margin-right: 6
12
+  move-policy: free updated
13
+  image-source: /core_styles/styles/images/mini_window.png
14
+  image-border: 4
15
+  image-border-top: 23
16
+  padding: 25 8 2 8
17
+
18
+  $on:
19
+    height: 24
20
+    image-border-bottom: 1

modules/old/game_interface/uiminiwindow.lua → modules/game/uiminiwindow.lua View File


+ 2
- 0
modules/game/widgets/uicountwindow.lua View File

@@ -0,0 +1,2 @@
1
+UICountWindow = {}
2
+

+ 64
- 0
modules/game/widgets/uigamemap.lua View File

@@ -0,0 +1,64 @@
1
+UIGameMap = extends(UIMap)
2
+
3
+function UIGameMap.create()
4
+  local gameMap = UIGameMap.internalCreate()
5
+  return gameMap
6
+end
7
+
8
+
9
+function UIGameMap:onDragEnter(mousePos)
10
+  local tile = self:getTile(mousePos)
11
+  if not tile then return false end
12
+
13
+  local thing = tile:getTopMoveThing()
14
+  if not thing then return false end
15
+
16
+  self.parsed = false
17
+  self.currentDragThing = thing
18
+  Mouse.setTargetCursor()
19
+  return true
20
+end
21
+
22
+function UIGameMap:onDragLeave(droppedWidget, mousePos)
23
+  if not self.parsed then
24
+    self.currentDragThing = nil
25
+  end
26
+
27
+  Mouse.restoreCursor()
28
+  return true
29
+end
30
+
31
+function UIGameMap:onDrop(widget, mousePos)
32
+  if not widget or not widget.currentDragThing then return false end
33
+
34
+  local tile = self:getTile(mousePos)
35
+  if not tile then return false end
36
+
37
+  local count = widget.currentDragThing:getCount()
38
+  if widget.currentDragThing:isStackable() and count > 1 then
39
+    widget.parsed = true
40
+    local moveWindow = createWidget('CountWindow', rootWidget)
41
+    local spinbox = moveWindow:getChildById('spinbox')
42
+    spinbox:setMaximum(count)
43
+    spinbox:setMinimum(1)
44
+    spinbox:setCurrentIndex(count)
45
+
46
+    local okButton = moveWindow:getChildById('buttonOk')
47
+    okButton.onClick = function()
48
+      g_game.move(widget.currentDragThing, tile:getPosition(), spinbox:getCurrentIndex())
49
+      okButton:getParent():destroy()
50
+      widget.currentDragThing = nil
51
+    end
52
+    moveWindow.onEnter = okButton.onClick
53
+  else
54
+    g_game.move(widget.currentDragThing, tile:getPosition(), 1)
55
+  end
56
+
57
+  return true
58
+end
59
+
60
+function UIGameMap:onMouseRelease(mousePosition, mouseButton)
61
+  local tile = self:getTile(mousePosition)
62
+  if tile and GameInterface.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
63
+  return false
64
+end

modules/old/game_interface/uiitem.lua → modules/game/widgets/uiitem.lua View File

@@ -33,14 +33,17 @@ function UIItem:onDrop(widget, mousePos)
33 33
   local count = widget.currentDragThing:getCount()
34 34
   if widget.currentDragThing:isStackable() and count > 1 then
35 35
     widget.parsed = true
36
-    local moveWindow = displayUI('/game/movewindow.otui')
36
+    local countWindow = createWidget('CountWindow', rootWidget)
37 37
     local spinbox = moveWindow:getChildById('spinbox')
38 38
     spinbox:setMaximum(count)
39 39
     spinbox:setMinimum(1)
40 40
     spinbox:setCurrentIndex(count)
41 41
 
42 42
     local okButton = moveWindow:getChildById('buttonOk')
43
-    okButton.onClick = function() g_game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
43
+    okButton.onClick = function()
44
+      g_game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy()
45
+      widget.currentDragThing = nil
46
+    end
44 47
     moveWindow.onEnter = okButton.onClick
45 48
   else
46 49
     g_game.move(widget.currentDragThing, pos, 1)

modules/old/game_interface/uiminiwindowcontainer.lua → modules/game/widgets/uiminiwindowcontainer.lua View File


modules/old/game_console/channelswindow.otui → modules/game_console/channelswindow.otui View File

@@ -53,4 +53,4 @@ MainWindow
53 53
     width: 64
54 54
     anchors.right: parent.right
55 55
     anchors.bottom: parent.bottom
56
-    @onClick: self:getParent():destroy()
56
+    @onClick: self:getParent():destroy()

modules/old/game_console/console.lua → modules/game_console/console.lua View File

@@ -76,9 +76,83 @@ function applyMessagePrefixies(name, level, message)
76 76
   return message
77 77
 end
78 78
 
79
+
80
+-- hooked events
81
+local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
82
+  speaktype = SpeakTypes[speaktype]
83
+  if speaktype.hideInConsole then return end
84
+
85
+  message = applyMessagePrefixies(name, level, message)
86
+
87
+  if speaktype.private then
88
+    Console.addPrivateText(message, speaktype, name, false)
89
+  else
90
+    local channel = channels[channelId]
91
+
92
+    if channel then
93
+      Console.addText(message, speaktype, channel)
94
+    else
95
+      -- server sent a message on a channel that we are not aware of, must leave it
96
+      g_game.leaveChannel(channelId)
97
+    end
98
+  end
99
+end
100
+
101
+local function onOpenChannel(channelId, channelName)
102
+  Console.addChannel(channelName, channelId)
103
+end
104
+
105
+local function onOpenPrivateChannel(receiver)
106
+  local privateTab = Console.getTab(receiver)
107
+  if privateTab == nil then
108
+    Console.addTab(receiver, true)
109
+  end
110
+end
111
+
112
+local function doChannelListSubmit(channelsWindow)
113
+  local channelListPanel = channelsWindow:getChildById('channelList')
114
+  local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
115
+  if openPrivateChannelWith ~= '' then
116
+    g_game.openPrivateChannel(openPrivateChannelWith)
117
+  else
118
+    local selectedChannelLabel = channelListPanel:getFocusedChild()
119
+    if not selectedChannelLabel then return end
120
+    g_game.joinChannel(selectedChannelLabel.channelId)
121
+  end
122
+  channelsWindow:destroy()
123
+end
124
+
125
+local function onChannelList(channelList)
126
+  local channelsWindow = displayUI('channelswindow.otui')
127
+  local channelListPanel = channelsWindow:getChildById('channelList')
128
+  channelsWindow.onEnter = function() doChannelListSubmit(channelsWindow) end
129
+  Keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
130
+  Keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
131
+
132
+  for k,v in pairs(channelList) do
133
+    local channelId = v[1]
134
+    local channelName = v[2]
135
+
136
+    if channelId ~= 0 and #channelName > 0 then
137
+      local label = createWidget('ChannelListLabel', channelListPanel)
138
+      label.channelId = channelId
139
+      label:setText(channelName)
140
+
141
+      label:setPhantom(false)
142
+      label.onDoubleClick = function() doChannelListSubmit(channelsWindow) end
143
+    end
144
+  end
145
+end
146
+
147
+
79 148
 -- public functions
80
-function Console.create()
81
-  consolePanel = displayUI('console.otui', g_game.gameBottomPanel)
149
+function Console.init()
150
+  connect(g_game, { onCreatureSpeak = onCreatureSpeak,
151
+                    onChannelList = onChannelList,
152
+                    onOpenChannel = onOpenChannel,
153
+                    onOpenPrivateChannel = onOpenPrivateChannel})
154
+
155
+  consolePanel = displayUI('console.otui', GameInterface.getBottomPanel())
82 156
   consoleLineEdit = consolePanel:getChildById('consoleLineEdit')
83 157
   consoleBuffer = consolePanel:getChildById('consoleBuffer')
84 158
   consoleTabBar = consolePanel:getChildById('consoleTabBar')
@@ -88,25 +162,42 @@ function Console.create()
88 162
   Console.addChannel('Default', 0)
89 163
   Console.addTab('Server Log', false)
90 164
 
91
-  Keyboard.bindKeyDown('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
92
-  Keyboard.bindKeyDown('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
93
-  Keyboard.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
94
-  Keyboard.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
165
+  Keyboard.bindKeyPress('Shift+Up', function() navigateMessageHistory(1) end, consolePanel)
166
+  Keyboard.bindKeyPress('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel)
167
+  Keyboard.bindKeyPress('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
168
+  Keyboard.bindKeyPress('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
95 169
   Keyboard.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
96 170
 
97 171
   -- apply buttom functions after loaded
98
-  connect(consolePanel:getChildById('nextChannelButton'), { onClick = function() consoleTabBar:selectNextTab() end } )
99
-  connect(consolePanel:getChildById('prevChannelButton'), { onClick = function() consoleTabBar:selectPrevTab() end } )
100
-  connect(consoleTabBar, { onTabChange = Console.onTabChange })
172
+  consolePanel:getChildById('nextChannelButton').onClick = function() consoleTabBar:selectNextTab() end
173
+  consolePanel:getChildById('prevChannelButton').onClick = function() consoleTabBar:selectPrevTab() end
174
+  consoleTabBar.onTabChange = Console.onTabChange
101 175
 
102 176
   -- tibia like hotkeys
103 177
   Keyboard.bindKeyDown('Ctrl+O', g_game.requestChannels)
104 178
   Keyboard.bindKeyDown('Ctrl+E', Console.removeCurrentTab)
105 179
 end
106 180
 
107
-function Console.destroy()
181
+function Console.terminate()
182
+  disconnect(g_game, { onCreatureSpeak = onCreatureSpeak,
183
+                       onChannelList = onChannelList,
184
+                       onOpenChannel = onOpenChannel,
185
+                       onOpenPrivateChannel = onOpenPrivateChannel })
186
+
187
+  for channelid, channelname in ipairs(channels) do
188
+    g_game.leaveChannel(channelid)
189
+  end
190
+
191
+  Keyboard.unbindKeyDown('Ctrl+O')
192
+  Keyboard.unbindKeyDown('Ctrl+E')
193
+
108 194
   consolePanel:destroy()
109 195
   consolePanel = nil
196
+  consoleLineEdit = nil
197
+  consoleBuffer = nil
198
+  consoleTabBar = nil
199
+
200
+  Console = nil
110 201
 end
111 202
 
112 203
 function Console.setLineEditText(text)
@@ -117,7 +208,7 @@ function Console.addTab(name, focus)
117 208
   local tab = consoleTabBar:addTab(name)
118 209
   if focus then
119 210
     consoleTabBar:selectTab(tab)
120
-  else
211
+  elseif name ~= 'Server Log' then
121 212
     consoleTabBar:blinkTab(tab)
122 213
   end
123 214
   return tab
@@ -299,75 +390,3 @@ function Console.sayModeChange(sayMode)
299 390
   buttom:setIcon(SayModes[sayMode].icon)
300 391
   buttom.sayMode = sayMode
301 392
 end
302
-
303
-local function onCreatureSpeak(name, level, speaktype, message, channelId, creaturePos)
304
-  speaktype = SpeakTypes[speaktype]
305
-  if speaktype.hideInConsole then return end
306
-
307
-  message = applyMessagePrefixies(name, level, message)
308
-
309
-  if speaktype.private then
310
-    Console.addPrivateText(message, speaktype, name, false)
311
-  else
312
-    local channel = channels[channelId]
313
-
314
-    if channel then
315
-      Console.addText(message, speaktype, channel)
316
-    else
317
-      -- server sent a message on a channel that we are not aware of, must leave it
318
-      g_game.leaveChannel(channelId)
319
-    end
320
-  end
321
-end
322
-
323
-local function onOpenChannel(channelId, channelName)
324
-  Console.addChannel(channelName, channelId)
325
-end
326
-
327
-local function onOpenPrivateChannel(receiver)
328
-  local privateTab = Console.getTab(receiver)
329
-  if privateTab == nil then
330
-    Console.addTab(receiver, true)
331
-  end
332
-end
333
-
334
-local function doChannelListSubmit(channelsWindow)
335
-  local channelListPanel = channelsWindow:getChildById('channelList')
336
-  local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
337
-  if openPrivateChannelWith ~= '' then
338
-    g_game.openPrivateChannel(openPrivateChannelWith)
339
-  else
340
-    local selectedChannelLabel = channelListPanel:getFocusedChild()
341
-    if not selectedChannelLabel then return end
342
-    g_game.joinChannel(selectedChannelLabel.channelId)
343
-  end
344
-  channelsWindow:destroy()
345
-end
346
-
347
-local function onChannelList(channelList)
348
-  local channelsWindow = displayUI('channelswindow.otui')
349
-  local channelListPanel = channelsWindow:getChildById('channelList')
350
-  connect(channelsWindow, { onEnter = function () doChannelListSubmit(channelsWindow) end } )
351
-
352
-  for k,v in pairs(channelList) do
353
-    local channelId = v[1]
354
-    local channelName = v[2]
355
-
356
-    if channelId ~= 0 and #channelName > 0 then
357
-      local label = createWidget('ChannelListLabel', channelListPanel)
358
-      label.channelId = channelId
359
-      label:setText(channelName)
360
-
361
-      label:setPhantom(false)
362
-      connect(label, { onDoubleClick = function () doChannelListSubmit(channelsWindow) end } )
363
-    end
364
-  end
365
-end
366
-
367
-connect(g_game, { onGameStart = Console.create,
368
-                onGameEnd = Console.destroy,
369
-                onCreatureSpeak = onCreatureSpeak,
370
-                onChannelList = onChannelList,
371
-                onOpenChannel = onOpenChannel,
372
-                onOpenPrivateChannel = onOpenPrivateChannel})

modules/old/game_console/console.otmod → modules/game_console/console.otmod View File

@@ -3,5 +3,14 @@ Module
3 3
   description: Manage chat window
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  onLoad: |
6
+  reloadable: true
7
+
8
+  dependecies:
9
+    - game
10
+
11
+  @onLoad: |
7 12
     dofile 'console'
13
+    Console.init()
14
+
15
+  @onUnload: |
16
+    Console.terminate()

modules/old/game_console/console.otui → modules/game_console/console.otui View File

@@ -14,7 +14,7 @@ Panel
14 14
   id: consolePanel
15 15
   anchors.fill: parent
16 16
 
17
-  ConsoleButton
17
+  TabButton
18 18
     id: prevChannelButton
19 19
     icon: /core_styles/icons/leftarrow.png
20 20
     anchors.left: parent.left
@@ -30,7 +30,7 @@ Panel
30 30
     anchors.right: next.left
31 31
     margin-left: 5
32 32
 
33
-  ConsoleButton
33
+  TabButton
34 34
     id: nextChannelButton
35 35
     icon: /core_styles/icons/rightarrow.png
36 36
     anchors.right: next.left
@@ -38,7 +38,7 @@ Panel
38 38
     margin-right: 5
39 39
     margin-top: 6
40 40
 
41
-  ConsoleButton
41
+  TabButton
42 42
     id: closeChannelButton
43 43
     tooltip: Close this channel (Ctrl+E)
44 44
     icon: /core_styles/icons/closechannel.png
@@ -49,7 +49,7 @@ Panel
49 49
     margin-top: 6
50 50
     @onClick: Console.removeCurrentTab()
51 51
 
52
-  ConsoleButton
52
+  TabButton
53 53
     id: channelsButton
54 54
     tooltip: Open new channel (Ctrl+O)
55 55
     icon: /core_styles/icons/channels.png
@@ -71,7 +71,7 @@ Panel
71 71
     margin-top: 4
72 72
     focusable: false
73 73
 
74
-  ConsoleButton
74
+  TabButton
75 75
     id: sayModeButton
76 76
     icon: /core_styles/icons/say.png
77 77
     tooltip: Adjust volume
@@ -91,5 +91,4 @@ Panel
91 91
     margin-right: 6
92 92
     margin-left: 6
93 93
     margin-bottom: 6
94
-    always-active: true
95
-    focusable: false
94
+    shift-navigation: true

modules/old/game_textmessage/textmessage.lua → modules/game_textmessage/textmessage.lua View File

@@ -17,7 +17,7 @@ local MessageTypes = {
17 17
 }
18 18
 
19 19
 local centerTextMessagePanel
20
-local centerLabel
20
+local bottomStatusLabel
21 21
 
22 22
 -- private functions
23 23
 local function displayMessage(msgtype, msg, time)
@@ -30,17 +30,17 @@ local function displayMessage(msgtype, msg, time)
30 30
   end
31 31
 
32 32
   if msgtype.labelId  then
33
-    local label = g_game.gameMapPanel:recursiveGetChildById(msgtype.labelId)
33
+    local label = GameInterface.getMapPanel():recursiveGetChildById(msgtype.labelId)
34 34
 
35
-    label:setVisible(true)
36 35
     label:setText(msg)
37 36
     label:setColor(msgtype.color)
38
-    label:resizeToText()
39 37
 
40 38
     if msgtype.wrap then
41 39
       label:setWidth(label:getParent():getWidth())
42 40
       label:wrapText()
43 41
       label:setHeight(label:getTextSize().height)
42
+    else
43
+      label:resizeToText()
44 44
     end
45 45
 
46 46
     if not time then
@@ -49,6 +49,7 @@ local function displayMessage(msgtype, msg, time)
49 49
       time = time * 1000
50 50
     end
51 51
     removeEvent(label.hideEvent)
52
+    addEvent(function() label:setVisible(true) end)
52 53
     label.hideEvent = scheduleEvent(function() label:setVisible(false) end, time)
53 54
   end
54 55
 end
@@ -64,10 +65,14 @@ local function createTextMessageLabel(id, parent)
64 65
 end
65 66
 
66 67
 -- public functions
68
+function TextMessage.init()
69
+  connect(g_game, { onDeath = TextMessage.displayDeadMessage,
70
+                    onTextMessage = TextMessage.display,
71
+                    onGameStart = TextMessage.clearMessages })
67 72
 
68
-function TextMessage.create()
69
-  centerTextMessagePanel = createWidget('Panel', g_game.gameMapPanel)
73
+  centerTextMessagePanel = createWidget('Panel', GameInterface.getMapPanel())
70 74
   centerTextMessagePanel:setId('centerTextMessagePanel')
75
+
71 76
   local layout = UIVerticalLayout.create(centerTextMessagePanel)
72 77
   layout:setFitChildren(true)
73 78
   centerTextMessagePanel:setLayout(layout)
@@ -78,13 +83,31 @@ function TextMessage.create()
78 83
   createTextMessageLabel('centerAdvance', centerTextMessagePanel)
79 84
   createTextMessageLabel('centerInfo', centerTextMessagePanel)
80 85
 
81
-  bottomStatusLabel = createTextMessageLabel('bottomStatus', g_game.gameMapPanel)
86
+  bottomStatusLabel = createTextMessageLabel('bottomStatus', GameInterface.getMapPanel())
82 87
   bottomStatusLabel:setHeight(16)
83 88
   bottomStatusLabel:addAnchor(AnchorBottom, 'parent', AnchorBottom)
84 89
   bottomStatusLabel:addAnchor(AnchorLeft, 'parent', AnchorLeft)
85 90
   bottomStatusLabel:addAnchor(AnchorRight, 'parent', AnchorRight)
86 91
 end
87 92
 
93
+function TextMessage.terminate()
94
+  disconnect(g_game, { onDeath = TextMessage.displayDeadMessage,
95
+                       onTextMessage = TextMessage.display,
96
+                       onGameStart = TextMessage.clearMessages })
97
+  centerTextMessagePanel:destroy()
98
+  centerTextMessagePanel = nil
99
+  bottomStatusLabel:destroy()
100
+  bottomStatusLabel = nil
101
+  TextMessage = nil
102
+end
103
+
104
+function TextMessage.clearMessages()
105
+  GameInterface.getMapPanel():recursiveGetChildById('centerWarning'):hide()
106
+  GameInterface.getMapPanel():recursiveGetChildById('centerAdvance'):hide()
107
+  GameInterface.getMapPanel():recursiveGetChildById('centerInfo'):hide()
108
+  GameInterface.getMapPanel():recursiveGetChildById('bottomStatus'):hide()
109
+end
110
+
88 111
 function TextMessage.displayStatus(msg, time)
89 112
   displayMessage(MessageTypes.warning, msg)
90 113
 end
@@ -100,18 +123,8 @@ function TextMessage.display(msgtypedesc, msg)
100 123
   end
101 124
 end
102 125
 
103
-local function onGameDeath()
104
-  local advanceLabel = g_game.gameMapPanel:recursiveGetChildById('centerAdvance')
126
+function TextMessage.displayDeadMessage()
127
+  local advanceLabel = GameInterface.getMapPanel():recursiveGetChildById('centerAdvance')
105 128
   if advanceLabel:isVisible() then return end
106 129
   TextMessage.displayEventAdvance('You are dead.')
107 130
 end
108
-
109
-local function onGameTextMessage(msgtypedesc, msg)
110
-  TextMessage.display(msgtypedesc, msg)
111
-end
112
-
113
-connect(g_game, { onGameStart = TextMessage.create,
114
-                onGameEnd = TextMessage.destroy,
115
-                onDeath = onGameDeath,
116
-                onTextMessage = onGameTextMessage })

modules/old/game_textmessage/textmessage.otmod → modules/game_textmessage/textmessage.otmod View File

@@ -3,5 +3,14 @@ Module
3 3
   description: Manage game text messages
4 4
   author: OTClient team
5 5
   website: https://github.com/edubart/otclient
6
-  onLoad: |
6
+  reloadable: true
7
+
8
+  dependecies:
9
+    - game
10
+
11
+  @onLoad: |
7 12
     dofile 'textmessage'
13
+    TextMessage.init()
14
+
15
+  @onUnload: |
16
+    TextMessage.terminate()

modules/old/game_textmessage/textmessage.otui → modules/game_textmessage/textmessage.otui View File


modules/game/game.lua → modules/old/game/game.lua View File


+ 17
- 0
modules/old/game/game.otmod View File

@@ -0,0 +1,17 @@
1
+Module
2
+  name: game
3
+  description: Create the game interface, where the ingame stuff starts
4
+  author: OTClient team
5
+  website: https://github.com/edubart/otclient
6
+  reloadable: true
7
+
8
+  dependencies:
9
+    - game_tibiafiles
10
+    //- game_shaders
11
+
12
+  onLoad: |
13
+    dofile 'game'
14
+    dofile 'thing'
15
+    dofile 'creature'
16
+    dofile 'player'
17
+    dofile 'map'

modules/game/game.otui → modules/old/game/game.otui View File


modules/game/map.lua → modules/old/game/map.lua View File


modules/game/movewindow.otui → modules/old/game/movewindow.otui View File

@@ -1,4 +1,4 @@
1
-MainWindow
1
+CountWindow < MainWindow
2 2
   text: Move Item
3 3
   size: 196 112
4 4
   @onEscape: self:destroy()

modules/game/player.lua → modules/old/game/player.lua View File


modules/game/thing.lua → modules/old/game/thing.lua View File


+ 1
- 1
modules/old/game_hotkeys/hotkeys_manager.lua View File

@@ -455,4 +455,4 @@ function HotkeysManager.hotkeyCapture(widget, keyCode, keyboardModifiers)
455 455
   hotkeysWindow:getChildById('assignWindow'):getChildById('addButton'):enable()
456 456
 
457 457
   return true
458
-end
458
+end

+ 1
- 1
modules/old/game_hotkeys/hotkeys_manager.otui View File

@@ -156,4 +156,4 @@ MainWindow
156 156
     width: 64
157 157
     anchors.right: parent.right
158 158
     anchors.bottom: parent.bottom
159
-    @onClick: HotkeysManager.hide()
159
+    @onClick: HotkeysManager.hide()

+ 4
- 4
modules/old/game_interface/gameinterface.otui View File

@@ -1,14 +1,14 @@
1 1
 GameSidePanel < UIMiniWindowContainer
2
-  image-source: /core_styles/styles/images/sidepanel.png
2
+  image-source: images/sidepanel.png
3 3
   image-border: 4
4 4
 
5 5
 GameBottomPanel < Panel
6
-  image-source: /core_styles/styles/images/bottompanel.png
6
+  image-source: images/bottompanel.png
7 7
   image-border: 4
8 8
 
9 9
 GameMapPanel < UIMap
10 10
   padding: 4
11
-  image-source: /core_styles/styles/images/mappanel.png
11
+  image-source: images/mappanel.png
12 12
   image-border: 4
13 13
 
14 14
 UIGame
@@ -16,7 +16,7 @@ UIGame
16 16
   anchors.fill: parent
17 17
   anchors.top: topMenu.bottom
18 18
 
19
-  InterfacePanel
19
+  GameSidePanel
20 20
     id: gameRightPanel
21 21
     width: 190
22 22
     layout: verticalBox

+ 3
- 9
modules/otclientrc.lua View File

@@ -1,5 +1,6 @@
1
+-- this file is loaded after all modules are loaded and initialized
1 2
 -- you can place any custom user code here
3
+-- you
2 4
 
3 5
 Keyboard.bindKeyDown('F1', function() g_game.talk('exura gran') end)
4 6
 Keyboard.bindKeyDown('F2', function() g_game.talk('exori mort') end)
@@ -7,12 +8,4 @@ Keyboard.bindKeyDown('F3', function() g_game.talk('exori frigo') end)
7 8
 Keyboard.bindKeyDown('F4', function() g_game.talk('exevo vis hur') end)
8 9
 Keyboard.bindKeyDown('F5', function() g_game.talk('utani gran hur') end)
9 10
 Keyboard.bindKeyDown('F6', function() g_game.talk('exani tera') end)
10
-
11
-local function reload()
12
-  dofile('otclientrc.lua')
13
-  TextMessage.displayEventAdvance('Script otclientrc.lua reloaded.')
14
-  print('Script otclient.rc lua reloaded')
15
-end
16
-Keyboard.bindKeyDown('Ctrl+R', reload)
17
-
18
-rcloaded = true
11
+Keyboard.bindKeyDown('Ctrl+R', Client.reloadScripts)

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

@@ -50,15 +50,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
50 50
     SET(CMAKE_CXX_LINK_FLAGS           "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++ -Wl,--as-needed")
51 51
 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
52 52
 
53
-IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
54
-    ADD_DEFINITIONS(-DDEBUG)
55
-ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
56
-
57
-IF(CMAKE_BUILD_TYPE STREQUAL "Release")
58
-    # NDEBUG disable asserts
59
-    ADD_DEFINITIONS(-DNDEBUG)
60
-ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
61
-
62 53
 MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
63 54
 IF(USE_OPENGL_ES2)
64 55
     MESSAGE(STATUS "Renderer: OpenGL ES 2.0")
@@ -66,6 +57,18 @@ ELSE(USE_OPENGL_ES2)
66 57
     MESSAGE(STATUS "Renderer: OpenGL")
67 58
 ENDIF(USE_OPENGL_ES2)
68 59
 
60
+IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
61
+    ADD_DEFINITIONS(-DDEBUG)
62
+    MESSAGE(STATUS "Debug information: ON")
63
+ELSE()
64
+    MESSAGE(STATUS "Debug information: OFF")
65
+ENDIF()
66
+
67
+IF(CMAKE_BUILD_TYPE STREQUAL "Release")
68
+    # NDEBUG disable asserts
69
+    ADD_DEFINITIONS(-DNDEBUG)
70
+ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
71
+
69 72
 IF(CRASH_HANDLER)
70 73
     ADD_DEFINITIONS(-DCRASH_HANDLER)
71 74
     MESSAGE(STATUS "Crash handler: ON")

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

@@ -219,10 +219,7 @@ void Application::poll()
219 219
 
220 220
 void Application::close()
221 221
 {
222
-    g_lua.getGlobalField("g_app", "onClose");
223
-    if(!g_lua.isNil())
224
-        g_lua.protectedCall();
225
-    else
222
+    if(!g_lua.callGlobalField<bool>("g_app", "onClose"))
226 223
         exit();
227 224
 }
228 225
 

+ 2
- 0
src/framework/luafunctions.cpp View File

@@ -362,6 +362,7 @@ void Application::registerLuaFunctions()
362 362
     g_lua.bindClassMemberFunction<UILineEdit>("setTextHidden", &UILineEdit::setTextHidden);
363 363
     g_lua.bindClassMemberFunction<UILineEdit>("setAlwaysActive", &UILineEdit::setAlwaysActive);
364 364
     g_lua.bindClassMemberFunction<UILineEdit>("setValidCharacters", &UILineEdit::setValidCharacters);
365
+    g_lua.bindClassMemberFunction<UILineEdit>("setShiftNavigation", &UILineEdit::setShiftNavigation);
365 366
     g_lua.bindClassMemberFunction<UILineEdit>("moveCursor", &UILineEdit::moveCursor);
366 367
     g_lua.bindClassMemberFunction<UILineEdit>("appendText", &UILineEdit::appendText);
367 368
     g_lua.bindClassMemberFunction<UILineEdit>("removeCharacter", &UILineEdit::removeCharacter);
@@ -372,6 +373,7 @@ void Application::registerLuaFunctions()
372 373
     g_lua.bindClassMemberFunction<UILineEdit>("isCursorEnabled", &UILineEdit::isCursorEnabled);
373 374
     g_lua.bindClassMemberFunction<UILineEdit>("isAlwaysActive", &UILineEdit::isAlwaysActive);
374 375
     g_lua.bindClassMemberFunction<UILineEdit>("isTextHidden", &UILineEdit::isTextHidden);
376
+    g_lua.bindClassMemberFunction<UILineEdit>("isShiftNavigation", &UILineEdit::isShiftNavigation);
375 377
 
376 378
     // UIFrameCounter
377 379
     g_lua.registerClass<UIFrameCounter, UIWidget>();

+ 40
- 21
src/framework/ui/uilineedit.cpp View File

@@ -35,6 +35,7 @@ UILineEdit::UILineEdit()
35 35
     m_textHorizontalMargin = 0;
36 36
     m_textHidden = false;
37 37
     m_alwaysActive = false;
38
+    m_shiftNavigation = false;
38 39
     blinkCursor();
39 40
 }
40 41
 
@@ -407,8 +408,8 @@ void UILineEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
407 408
             setTextHorizontalMargin(node->value<int>());
408 409
         else if(node->tag() == "always-active")
409 410
             setAlwaysActive(node->value<bool>());
410
-        //else if(node->tag() == "disable-arrow-navitation")
411
-        //    setArrowNavigation(node->value<bool>());
411
+        else if(node->tag() == "shift-navigation")
412
+            setShiftNavigation(node->value<bool>());
412 413
     }
413 414
 }
414 415
 
@@ -434,28 +435,46 @@ bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
434 435
     if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
435 436
         return true;
436 437
 
437
-    if(keyCode == Fw::KeyDelete) // erase right character
438
-        removeCharacter(true);
439
-    else if(keyCode == Fw::KeyBackspace) // erase left character {
440
-        removeCharacter(false);
441
-    else if(keyCode == Fw::KeyRight) // move cursor right
442
-        moveCursor(true);
443
-    else if(keyCode == Fw::KeyLeft) // move cursor left
444
-        moveCursor(false);
445
-    else if(keyCode == Fw::KeyHome) // move cursor to first character
446
-        setCursorPos(0);
447
-    else if(keyCode == Fw::KeyEnd) // move cursor to last character
448
-        setCursorPos(m_text.length());
449
-    else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
450
-        appendText(g_window.getClipboardText());
451
-    else if(keyCode == Fw::KeyTab) {
452
-        if(!m_alwaysActive) {
438
+    if(keyboardModifiers == Fw::KeyboardNoModifier) {
439
+        if(keyCode == Fw::KeyDelete) { // erase right character
440
+            removeCharacter(true);
441
+            return true;
442
+        } else if(keyCode == Fw::KeyBackspace) { // erase left character {
443
+            removeCharacter(false);
444
+            return true;
445
+        } else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
446
+            moveCursor(true);
447
+            return true;
448
+        } else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left
449
+            moveCursor(false);
450
+            return true;
451
+        } else if(keyCode == Fw::KeyHome) { // move cursor to first character
452
+            setCursorPos(0);
453
+            return true;
454
+        } else if(keyCode == Fw::KeyEnd) { // move cursor to last character
455
+            setCursorPos(m_text.length());
456
+            return true;
457
+        } else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
453 458
             if(UIWidgetPtr parent = getParent())
454 459
                 parent->focusNextChild(Fw::KeyboardFocusReason);
460
+            return true;
455 461
         }
456
-    } else
457
-        return false;
458
-    return true;
462
+    } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
463
+        if(keyCode == Fw::KeyV) {
464
+            appendText(g_window.getClipboardText());
465
+            return true;
466
+        }
467
+    } else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
468
+        if(keyCode == Fw::KeyRight && m_shiftNavigation) { // move cursor right
469
+            moveCursor(true);
470
+            return true;
471
+        } else if(keyCode == Fw::KeyLeft && m_shiftNavigation) { // move cursor left
472
+            moveCursor(false);
473
+            return true;
474
+        }
475
+    }
476
+
477
+    return false;
459 478
 }
460 479
 
461 480
 bool UILineEdit::onKeyText(const std::string& keyText)

+ 3
- 0
src/framework/ui/uilineedit.h View File

@@ -42,6 +42,7 @@ public:
42 42
     void setTextHidden(bool hidden);
43 43
     void setAlwaysActive(bool enable);
44 44
     void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
45
+    void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
45 46
 
46 47
     void moveCursor(bool right);
47 48
     void appendText(std::string text);
@@ -55,6 +56,7 @@ public:
55 56
     bool isCursorEnabled() { return m_cursorPos != -1; }
56 57
     bool isAlwaysActive() { return m_alwaysActive; }
57 58
     bool isTextHidden() { return m_textHidden; }
59
+    bool isShiftNavigation() { return m_shiftNavigation; }
58 60
 
59 61
 protected:
60 62
     virtual void onTextChange(const std::string& text, const std::string& oldText);
@@ -77,6 +79,7 @@ private:
77 79
     int m_textHorizontalMargin;
78 80
     bool m_textHidden;
79 81
     bool m_alwaysActive;
82
+    bool m_shiftNavigation;
80 83
     std::string m_validCharacters;
81 84
 
82 85
     std::vector<Rect> m_glyphsCoords;

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

@@ -319,7 +319,12 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
319 319
         return nullptr;
320 320
     }
321 321
 }
322
+/*
323
+UIWidgetPtr UIManager::loadWidgetFromStyle()
324
+{
322 325
 
326
+}
327
+*/
323 328
 UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent)
324 329
 {
325 330
     OTMLNodePtr originalStyleNode = getStyle(widgetNode->tag());

+ 6
- 4
src/framework/ui/uiwidget.cpp View File

@@ -206,7 +206,7 @@ void UIWidget::removeChild(UIWidgetPtr child)
206 206
 
207 207
         g_ui.onWidgetDisappear(child);
208 208
     } else
209
-        logError("Attempt to remove an unknown child from a UIWidget");
209
+        logError("attempt to remove an unknown child from a UIWidget");
210 210
 }
211 211
 
212 212
 
@@ -637,11 +637,12 @@ void UIWidget::destroy()
637 637
 
638 638
     // remove itself from parent
639 639
     if(UIWidgetPtr parent = getParent()) {
640
-        if(parent->hasChild(asUIWidget()))
641
-            parent->removeChild(asUIWidget());
640
+        assert(parent->hasChild(asUIWidget()));
641
+        parent->removeChild(asUIWidget());
642 642
     }
643 643
 
644 644
     destroyChildren();
645
+    m_focusedChild = nullptr;
645 646
 
646 647
     callLuaField("onDestroy");
647 648
 
@@ -649,12 +650,13 @@ void UIWidget::destroy()
649 650
 
650 651
 #ifdef DEBUG
651 652
     auto self = asUIWidget();
653
+    g_lua.collectGarbage();
652 654
     if(self != g_ui.getRootWidget()) {
653 655
         g_eventDispatcher.scheduleEvent([self] {
654 656
             g_lua.collectGarbage();
655 657
             if(self->getUseCount() != 1)
656 658
                 logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left");
657
-        }, 100);
659
+        }, 500);
658 660
     }
659 661
 #endif
660 662
 }

+ 8
- 0
src/framework/ui/uiwidgettext.cpp View File

@@ -51,6 +51,9 @@ void UIWidget::drawText(const Rect& screenCoords)
51 51
     if(m_text.length() == 0 || m_color.a() == 0)
52 52
         return;
53 53
 
54
+#if 0
55
+    //TODO: creating framebuffers on the fly was slowing down the render
56
+    // we should use vertex arrys instead of this method
54 57
     Size boxSize = screenCoords.size();
55 58
     if(boxSize != m_textCachedBoxSize || m_textMustRecache) {
56 59
         if(!m_textFramebuffer)
@@ -73,6 +76,11 @@ void UIWidget::drawText(const Rect& screenCoords)
73 76
 
74 77
     g_painter.setColor(m_color);
75 78
     m_textFramebuffer->draw(screenCoords);
79
+#else
80
+    Rect textRect = screenCoords;
81
+    textRect.translate(m_textOffset);
82
+    m_font->renderText(m_text, textRect, m_textAlign, m_color);
83
+#endif
76 84
 }
77 85
 
78 86
 void UIWidget::onTextChange(const std::string& text, const std::string& oldText)

+ 1
- 0
src/otclient/CMakeLists.txt View File

@@ -31,6 +31,7 @@ SET(otclient_SOURCES ${otclient_SOURCES}
31 31
     ${CMAKE_CURRENT_LIST_DIR}/core/thingstype.cpp
32 32
     ${CMAKE_CURRENT_LIST_DIR}/core/spritemanager.cpp
33 33
     ${CMAKE_CURRENT_LIST_DIR}/core/item.cpp
34
+    ${CMAKE_CURRENT_LIST_DIR}/core/container.cpp
34 35
     ${CMAKE_CURRENT_LIST_DIR}/core/tile.cpp
35 36
     ${CMAKE_CURRENT_LIST_DIR}/core/thing.cpp
36 37
     ${CMAKE_CURRENT_LIST_DIR}/core/creature.cpp

+ 23
- 0
src/otclient/core/container.cpp View File

@@ -0,0 +1,23 @@
1
+/*
2
+ * Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+#include "container.h"

src/otclient/ui/uigame.h → src/otclient/core/container.h View File

@@ -20,17 +20,16 @@
20 20
  * THE SOFTWARE.
21 21
  */
22 22
 
23
-#ifndef UIGAME_H
24
-#define UIGAME_H
23
+#ifndef CONTAINER_H
24
+#define CONTAINER_H
25 25
 
26 26
 #include "declarations.h"
27
-#include <framework/ui/uiwidget.h>
28 27
 
29
-class UIGame : public UIWidget
28
+class Container
30 29
 {
31
-protected:
32
-    bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
33
-    bool onKeyText(const std::string& keyText);
30
+public:
31
+    Container();
32
+
34 33
 };
35 34
 
36 35
 #endif

+ 2
- 0
src/otclient/core/declarations.h View File

@@ -31,6 +31,7 @@ class MapView;
31 31
 class Tile;
32 32
 class Thing;
33 33
 class Item;
34
+class Container;
34 35
 class Creature;
35 36
 class Monster;
36 37
 class Npc;
@@ -45,6 +46,7 @@ typedef std::shared_ptr<MapView> MapViewPtr;
45 46
 typedef std::shared_ptr<Tile> TilePtr;
46 47
 typedef std::shared_ptr<Thing> ThingPtr;
47 48
 typedef std::shared_ptr<Item> ItemPtr;
49
+typedef std::shared_ptr<Container> ContainerPtr;
48 50
 typedef std::shared_ptr<Creature> CreaturePtr;
49 51
 typedef std::shared_ptr<Monster> MonsterPtr;
50 52
 typedef std::shared_ptr<Npc> NpcPtr;

+ 0
- 1
src/otclient/core/game.cpp View File

@@ -764,7 +764,6 @@ void Game::setSafeFight(bool on)
764 764
     m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
765 765
 }
766 766
 
767
-
768 767
 void Game::inspectNpcTrade(const ItemPtr& item)
769 768
 {
770 769
     if(!canPerformGameAction() || !item)

+ 2
- 0
src/otclient/core/game.h View File

@@ -216,6 +216,7 @@ public:
216 216
     bool isAttacking() { return !!m_attackingCreature; }
217 217
     bool isFollowing() { return !!m_followingCreature; }
218 218
 
219
+    ContainerPtr getContainer(int index) { return m_containers[index]; }
219 220
     CreaturePtr getAttackingCreature() { return m_attackingCreature; }
220 221
     CreaturePtr getFollowingCreature() { return m_followingCreature; }
221 222
     int getServerBeat() { return m_serverBeat; }
@@ -231,6 +232,7 @@ private:
231 232
     CreaturePtr m_attackingCreature;
232 233
     CreaturePtr m_followingCreature;
233 234
     ProtocolGamePtr m_protocolGame;
235
+    std::map<int, ContainerPtr> m_containers;
234 236
     bool m_dead;
235 237
     int m_serverBeat;
236 238
     Otc::FightModes m_fightMode;

+ 6
- 2
src/otclient/core/mapview.cpp View File

@@ -36,12 +36,17 @@
36 36
 
37 37
 MapView::MapView()
38 38
 {
39
+    m_viewRange = NEAR_VIEW;
40
+    m_lockedFirstVisibleFloor = -1;
41
+    m_cachedFirstVisibleFloor = 0;
42
+    m_cachedLastVisibleFloor = 7;
43
+    m_customCameraPosition.z = 7;
44
+
39 45
     Size frameBufferSize(std::min(g_graphics.getMaxTextureSize(), (int)DEFAULT_FRAMBUFFER_WIDTH),
40 46
                          std::min(g_graphics.getMaxTextureSize(), (int)DEFAULT_FRAMBUFFER_HEIGHT));
41 47
 
42 48
     m_framebuffer = FrameBufferPtr(new FrameBuffer(frameBufferSize));
43 49
     m_framebuffer->setClearColor(Fw::black);
44
-    m_lockedFirstVisibleFloor = -1;
45 50
     setVisibleDimension(Size(15, 11));
46 51
 
47 52
     m_shaderProgram = PainterShaderProgramPtr(new PainterShaderProgram);
@@ -374,7 +379,6 @@ void MapView::unlockFirstVisibleFloor()
374 379
 void MapView::followCreature(const CreaturePtr& creature)
375 380
 {
376 381
     m_followingCreature = creature;
377
-    m_customCameraPosition = Position();
378 382
     requestVisibleTilesCacheUpdate();
379 383
 }
380 384
 

+ 0
- 2
src/otclient/core/mapview.h View File

@@ -93,7 +93,6 @@ public:
93 93
     MapViewPtr asMapView() { return std::static_pointer_cast<MapView>(shared_from_this()); }
94 94
 
95 95
 private:
96
-    int m_drawFlags;
97 96
     int m_lockedFirstVisibleFloor;
98 97
     int m_cachedFirstVisibleFloor;
99 98
     int m_cachedLastVisibleFloor;
@@ -102,7 +101,6 @@ private:
102 101
     Size m_visibleDimension;
103 102
     Point m_virtualCenterOffset;
104 103
     Position m_customCameraPosition;
105
-    Position m_framebufferCenterPosition;
106 104
     Boolean<true> m_mustUpdateVisibleTilesCache;
107 105
     Boolean<true> m_mustDrawVisibleTilesCache;
108 106
     Boolean<true> m_mustCleanFramebuffer;

+ 23
- 0
src/otclient/core/player.cpp View File

@@ -0,0 +1,23 @@
1
+/*
2
+ * Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+#include "player.h"

+ 4
- 0
src/otclient/core/player.h View File

@@ -31,6 +31,10 @@ public:
31 31
     Player() { }
32 32
     virtual ~Player() { }
33 33
 
34
+    bool isPartyMember() { return (m_shield != 0); }
35
+    bool isPartyLeader() { return (m_shield & Otc::ShieldYellow); } 
36
+    bool isPartySharedExperienceActive() { return false; }
37
+
34 38
     PlayerPtr asPlayer() { return std::static_pointer_cast<Player>(shared_from_this()); }
35 39
 };
36 40
 

+ 8
- 0
src/otclient/core/thing.cpp View File

@@ -26,6 +26,7 @@
26 26
 #include <framework/graphics/graphics.h>
27 27
 #include "map.h"
28 28
 #include "tile.h"
29
+#include "game.h"
29 30
 
30 31
 Thing::Thing()
31 32
 {
@@ -53,6 +54,13 @@ const TilePtr& Thing::getTile()
53 54
     return g_map.getTile(m_position);
54 55
 }
55 56
 
57
+ContainerPtr Thing::getParentContainer()
58
+{
59
+    if(m_position.x == 0xFFFF && m_position.y & 0x40)
60
+        return g_game.getContainer(m_position.z);
61
+    return nullptr;
62
+}
63
+
56 64
 int Thing::getStackpos()
57 65
 {
58 66
     if(m_position.x == 65535 && asItem()) // is inside a container

+ 1
- 0
src/otclient/core/thing.h View File

@@ -49,6 +49,7 @@ public:
49 49
     Position getPosition() { return m_position; }
50 50
     int getStackPriority();
51 51
     const TilePtr& getTile();
52
+    ContainerPtr getParentContainer();
52 53
     int getStackpos();
53 54
 
54 55
     ThingPtr asThing() { return std::static_pointer_cast<Thing>(shared_from_this()); }

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

@@ -305,6 +305,7 @@ void OTClient::registerLuaFunctions()
305 305
 
306 306
     g_lua.registerClass<UIMap, UIWidget>();
307 307
     g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );
308
+    g_lua.bindClassMemberFunction<UIMap>("followCreature", &UIMap::followCreature);
308 309
     g_lua.bindClassMemberFunction<UIMap>("getTile", &UIMap::getTile);
309 310
     g_lua.bindClassMemberFunction<UIMap>("zoomIn", &UIMap::zoomIn);
310 311
     g_lua.bindClassMemberFunction<UIMap>("zoomOut", &UIMap::zoomOut);

+ 0
- 117
src/otclient/ui/uigame.cpp View File

@@ -1,117 +0,0 @@
1
-/*
2
- * Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- * THE SOFTWARE.
21
- */
22
-
23
-#include "uigame.h"
24
-#include <otclient/core/game.h>
25
-#include <framework/ui/uilineedit.h>
26
-#include <framework/platform/platformwindow.h>
27
-
28
-bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks)
29
-{
30
-    if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
31
-        return true;
32
-
33
-    UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
34
-
35
-    //TODO: move this whole shit to lua
36
-    if(keyboardModifiers == Fw::KeyboardNoModifier) {
37
-        if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {
38
-            g_game.walk(Otc::North);
39
-            return true;
40
-        } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
41
-            g_game.walk(Otc::East);
42
-            return true;
43
-        } else if(keyCode == Fw::KeyDown || keyCode == Fw::KeyNumpad2) {
44
-            g_game.walk(Otc::South);
45
-            return true;
46
-        } else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
47
-            g_game.walk(Otc::West);
48
-            return true;
49
-        } else if(keyCode == Fw::KeyNumpad9) {
50
-            g_game.walk(Otc::NorthEast);
51
-            return true;
52
-        } else if(keyCode == Fw::KeyNumpad3) {
53
-            g_game.walk(Otc::SouthEast);
54
-            return true;
55
-        } else if(keyCode == Fw::KeyNumpad1) {
56
-            g_game.walk(Otc::SouthWest);
57
-            return true;
58
-        } else if(keyCode == Fw::KeyNumpad7) {
59
-            g_game.walk(Otc::NorthWest);
60
-            return true;
61
-        } else if(keyCode == Fw::KeyDelete) {
62
-            chatLineEdit->removeCharacter(true);
63
-            return true;
64
-        } else if(keyCode == Fw::KeyBackspace) {
65
-            chatLineEdit->removeCharacter(false);
66
-            return true;
67
-        } else if(keyCode == Fw::KeyRight) {
68
-            chatLineEdit->moveCursor(true);
69
-            return true;
70
-        } else if(keyCode == Fw::KeyLeft) {
71
-            chatLineEdit->moveCursor(false);
72
-            return true;
73
-        } else if(keyCode == Fw::KeyHome) {
74
-            chatLineEdit->setCursorPos(0);
75
-            return true;
76
-        } else if(keyCode == Fw::KeyEnd) {
77
-            chatLineEdit->setCursorPos(chatLineEdit->getText().length());
78
-            return true;
79
-        }
80
-    } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
81
-        if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {
82
-            g_game.turn(Otc::North);
83
-            return true;
84
-        } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
85
-            g_game.turn(Otc::East);
86
-            return true;
87
-        } else if(keyCode == Fw::KeyDown || keyCode == Fw::KeyNumpad2) {
88
-            g_game.turn(Otc::South);
89
-            return true;
90
-        } else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
91
-            g_game.turn(Otc::West);
92
-            return true;
93
-        } else if(keyCode == Fw::KeyV) {
94
-            chatLineEdit->appendText(g_window.getClipboardText());
95
-        }
96
-    } else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
97
-        if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
98
-            chatLineEdit->moveCursor(true);
99
-            return true;
100
-        } else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
101
-            chatLineEdit->moveCursor(false);
102
-            return true;
103
-        }
104
-    }
105
-
106
-    return false;
107
-}
108
-
109
-bool UIGame::onKeyText(const std::string& keyText)
110
-{
111
-    if(UIWidget::onKeyText(keyText))
112
-        return true;
113
-
114
-    UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
115
-    chatLineEdit->appendText(keyText);
116
-    return true;
117
-}

+ 5
- 1
src/otclient/ui/uimap.cpp View File

@@ -33,7 +33,6 @@ UIMap::UIMap()
33 33
     m_dragable = true;
34 34
     m_mapView = MapViewPtr(new MapView);
35 35
     g_map.addMapView(m_mapView);
36
-    m_mapView->followCreature(g_game.getLocalPlayer());
37 36
 }
38 37
 
39 38
 UIMap::~UIMap()
@@ -96,6 +95,11 @@ void UIMap::zoomOut()
96 95
     m_mapRect.moveCenter(m_rect.center());
97 96
 }
98 97
 
98
+void UIMap::followCreature(const CreaturePtr& creature)
99
+{
100
+    m_mapView->followCreature(creature);
101
+}
102
+
99 103
 void UIMap::setCameraPosition(const Position& pos)
100 104
 {
101 105
     m_mapView->setCameraPosition(pos);

+ 1
- 0
src/otclient/ui/uimap.h View File

@@ -37,6 +37,7 @@ public:
37 37
 
38 38
     void zoomIn();
39 39
     void zoomOut();
40
+    void followCreature(const CreaturePtr& creature);
40 41
     void setCameraPosition(const Position& pos);
41 42
 
42 43
     TilePtr getTile(const Point& mousePos);

Loading…
Cancel
Save