Browse Source

implement combobox and do some ui rework

Eduardo Bart 9 years ago
parent
commit
b8150d160e
48 changed files with 413 additions and 589 deletions
  1. 1
    1
      LICENSE
  2. 2
    0
      modules/addon_playground/playground.lua
  3. 17
    0
      modules/core_scripts/const.lua
  4. 1
    0
      modules/core_styles/styles/checkboxes.otui
  5. 2
    1
      modules/core_styles/styles/comboboxes.otui
  6. 2
    0
      modules/core_widgets/core_widgets.otmod
  7. 3
    3
      modules/core_widgets/tooltip/tooltip.lua
  8. 7
    0
      modules/core_widgets/uibutton.lua
  9. 40
    0
      modules/core_widgets/uicombobox.lua
  10. 9
    0
      modules/core_widgets/uilabel.lua
  11. 17
    18
      modules/core_widgets/uipopupmenu.lua
  12. 0
    2
      src/framework/CMakeLists.txt
  13. 9
    9
      src/framework/const.h
  14. 1
    1
      src/framework/graphics/particle.h
  15. 1
    1
      src/framework/graphics/particleaffector.cpp
  16. 30
    22
      src/framework/luafunctions.cpp
  17. 0
    2
      src/framework/ui/ui.h
  18. 0
    72
      src/framework/ui/uibutton.cpp
  19. 0
    49
      src/framework/ui/uibutton.h
  20. 2
    2
      src/framework/ui/uicheckbox.cpp
  21. 1
    1
      src/framework/ui/uicheckbox.h
  22. 2
    2
      src/framework/ui/uiframecounter.cpp
  23. 1
    1
      src/framework/ui/uiframecounter.h
  24. 0
    75
      src/framework/ui/uilabel.cpp
  25. 0
    53
      src/framework/ui/uilabel.h
  26. 49
    48
      src/framework/ui/uilineedit.cpp
  27. 15
    12
      src/framework/ui/uilineedit.h
  28. 1
    1
      src/framework/ui/uiverticallayout.cpp
  29. 124
    13
      src/framework/ui/uiwidget.cpp
  30. 33
    19
      src/framework/ui/uiwidget.h
  31. 3
    3
      src/framework/ui/uiwindow.cpp
  32. 1
    1
      src/framework/ui/uiwindow.h
  33. 8
    8
      src/otclient/core/game.cpp
  34. 2
    2
      src/otclient/core/item.cpp
  35. 1
    1
      src/otclient/core/item.h
  36. 3
    3
      src/otclient/core/localplayer.cpp
  37. 10
    10
      src/otclient/core/map.cpp
  38. 2
    2
      src/otclient/core/thing.h
  39. 1
    1
      src/otclient/core/tile.h
  40. 2
    2
      src/otclient/net/protocolgameparse.cpp
  41. 2
    2
      src/otclient/ui/uicreature.cpp
  42. 1
    1
      src/otclient/ui/uicreature.h
  43. 2
    2
      src/otclient/ui/uiitem.cpp
  44. 1
    1
      src/otclient/ui/uiitem.h
  45. 2
    2
      src/otclient/ui/uimap.cpp
  46. 1
    1
      src/otclient/ui/uimap.h
  47. 1
    1
      src/otclient/util/position.h
  48. 0
    138
      tools/katepart-syntax/lua.xml

+ 1
- 1
LICENSE View File

@@ -1,6 +1,6 @@
1 1
 OTClient is made available under the MIT License
2 2
 
3
-Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
3
+Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
4 4
 
5 5
 Permission is hereby granted, free of charge, to any person obtaining a copy
6 6
 of this software and associated documentation files (the "Software"), to deal

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

@@ -3,6 +3,8 @@
3 3
 function init()
4 4
   local box = createWidget('ComboBox')
5 5
   box:moveTo({x=100, y=8})
6
+  box:addOption('Option 1')
7
+  box:addOption('Option 2')
6 8
   displayUI(box)
7 9
 end
8 10
 

+ 17
- 0
modules/core_scripts/const.lua View File

@@ -132,3 +132,20 @@ MouseNoButton = 0
132 132
 MouseLeftButton = 1
133 133
 MouseRightButton = 2
134 134
 MouseMidButton = 3
135
+
136
+AlignNone = 0
137
+AlignLeft = 1
138
+AlignRight = 2
139
+AlignTop = 4
140
+AlignBottom = 8
141
+AlignHorizontalCenter = 16
142
+AlignVerticalCenter = 32
143
+AlignTopLeft = 5
144
+AlignTopRight = 6
145
+AlignBottomLeft = 9
146
+AlignBottomRight = 10
147
+AlignLeftCenter = 33
148
+AlignRightCenter = 34
149
+AlignTopCenter = 20
150
+AlignBottomCenter = 24
151
+AlignCenter = 48

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

@@ -1,6 +1,7 @@
1 1
 CheckBox < UICheckBox
2 2
   size: 12 12
3 3
   box-size: 12 12
4
+  text-align: left
4 5
   text-offset: 16 -1
5 6
   color: #aaaaaa
6 7
   background-color: #ffffffff

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

@@ -2,7 +2,8 @@ ComboBox < UIComboBox
2 2
   font: verdana-11px-antialised
3 3
   color: #aaaaaa
4 4
   size: 86 20
5
-  text-margin: 3
5
+  text-offset: 3 0
6
+  text-align: left
6 7
   border-image:
7 8
     source: /core_styles/images/combobox.png
8 9
     border: 1

+ 2
- 0
modules/core_widgets/core_widgets.otmod View File

@@ -7,6 +7,8 @@ Module
7 7
   onLoad: |
8 8
     require 'tooltip/tooltip'
9 9
     require 'messagebox/messagebox'
10
+    require 'uibutton'
11
+    require 'uilabel'
10 12
     require 'uicombobox'
11 13
     require 'uipopupmenu'
12 14
     return true

+ 3
- 3
modules/core_widgets/tooltip/tooltip.lua View File

@@ -49,9 +49,9 @@ local function onWidgetHoverChange(widget, hovered)
49 49
   end
50 50
 end
51 51
 
52
-local function onWidgetStyleApply(widget, style)
53
-  if style and style.tooltip then
54
-    widget.tooltip = style.tooltip
52
+local function onWidgetStyleApply(widget, styleName, styleNode)
53
+  if styleNode.tooltip then
54
+    widget.tooltip = styleNode.tooltip
55 55
   end
56 56
 end
57 57
 

+ 7
- 0
modules/core_widgets/uibutton.lua View File

@@ -0,0 +1,7 @@
1
+UIButton = extends(UIWidget)
2
+
3
+function UIButton.create()
4
+  local button = UIButton.internalCreate()
5
+  button:setFocusable(false)
6
+  return button
7
+end

+ 40
- 0
modules/core_widgets/uicombobox.lua View File

@@ -1 +1,41 @@
1 1
 UIComboBox = extends(UIWidget)
2
+
3
+function UIComboBox.create()
4
+  local combobox = UIComboBox.internalCreate()
5
+  combobox.options = {}
6
+  combobox.currentIndex = -1
7
+  return combobox
8
+end
9
+
10
+function UIComboBox:setCurrentOption(text)
11
+  if not self.options then return end
12
+  for i,v in ipairs(self.options) do
13
+    if v.text == text and self.currentIndex ~= i then
14
+      self.currentIndex = i
15
+      self:setText(text)
16
+      self:onOptionChange(text, data)
17
+      return
18
+    end
19
+  end
20
+end
21
+
22
+function UIComboBox:addOption(text, data)
23
+  table.insert(self.options, { text = text, data = data })
24
+  local index = #self.options
25
+  if index == 1 then self:setCurrentOption(text) end
26
+  return index
27
+end
28
+
29
+function UIComboBox:onMousePress(mousePos, mouseButton)
30
+  local menu = createWidget('PopupMenu', self)
31
+  for i,v in ipairs(self.options) do
32
+    menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
33
+  end
34
+  menu:setWidth(self:getWidth())
35
+  menu:display({ x = self:getX(), y = self:getY() + self:getHeight() })
36
+  return true
37
+end
38
+
39
+function UIComboBox:onOptionChange(optionText, optionData)
40
+  -- nothing todo
41
+end

+ 9
- 0
modules/core_widgets/uilabel.lua View File

@@ -0,0 +1,9 @@
1
+UILabel = extends(UIWidget)
2
+
3
+function UILabel.create()
4
+  local label = UILabel.internalCreate()
5
+  label:setPhantom(true)
6
+  label:setFocusable(false)
7
+  label:setTextAlign(AlignLeft)
8
+  return label
9
+end

+ 17
- 18
modules/core_widgets/uipopupmenu.lua View File

@@ -1,7 +1,5 @@
1 1
 UIPopupMenu = extends(UIWidget)
2 2
 
3 3
 function UIPopupMenu.create()
4 4
   local menu = UIPopupMenu.internalCreate()
5 5
   local layout = UIVerticalLayout.create(menu)
@@ -10,41 +8,39 @@ function UIPopupMenu.create()
10 8
   return menu
11 9
 end
12 10
 
13
-function UIPopupMenu.display(menu, pos)
14
-  displayUI(menu, {x = pos.x, y = pos.y})
15
-  menu:bindRectToParent()
16
-  menu:grabMouse()
17
-  menu:grabKeyboard()
18
-  return menu
11
+function UIPopupMenu:display(pos)
12
+  displayUI(self, {x = pos.x, y = pos.y})
13
+  self:bindRectToParent()
14
+  self:grabMouse()
15
+  self:grabKeyboard()
19 16
 end
20 17
 
21
-function UIPopupMenu.addOption(menu, optionName, optionCallback)
22
-  local optionWidget = createWidget(menu:getStyleName() .. 'Button', menu)
23
-  local lastOptionWidget = menu:getLastChild()
18
+function UIPopupMenu:addOption(optionName, optionCallback)
19
+  local optionWidget = createWidget(self:getStyleName() .. 'Button', self)
20
+  local lastOptionWidget = self:getLastChild()
24 21
   optionWidget.onClick = function()
25 22
     optionCallback()
26
-    menu:destroy()
23
+    self:destroy()
27 24
   end
28 25
   optionWidget:setText(optionName)
29 26
 end
30 27
 
31
-function UIPopupMenu.addSeparator(menu)
32
-  local separatorWidget = createWidget(menu:getStyleName() .. 'Separator', menu)
28
+function UIPopupMenu:addSeparator()
29
+  createWidget(self:getStyleName() .. 'Separator', self)
33 30
 end
34 31
 
35
-function UIPopupMenu.onMousePress(menu, mousePos, mouseButton)
36
-  -- clicks outside menu area destroys the menu
37
-  if not menu:containsPoint(mousePos) then
38
-    menu:destroy()
32
+function UIPopupMenu:onMousePress(mousePos, mouseButton)
33
+  -- clicks outside self area destroys the self
34
+  if not self:containsPoint(mousePos) then
35
+    self:destroy()
39 36
     return true
40 37
   end
41 38
   return false
42 39
 end
43 40
 
44
-function UIPopupMenu.onKeyPress(menu, keyCode, keyText, keyboardModifiers)
41
+function UIPopupMenu:onKeyPress(keyCode, keyText, keyboardModifiers)
45 42
   if keyCode == KeyEscape then
46
-    menu:destroy()
43
+    self:destroy()
47 44
     return true
48 45
   end
49 46
   return false

+ 0
- 2
src/framework/CMakeLists.txt View File

@@ -187,8 +187,6 @@ SET(framework_SOURCES ${framework_SOURCES}
187 187
     # framework ui
188 188
     ${CMAKE_CURRENT_LIST_DIR}/ui/uimanager.cpp
189 189
     ${CMAKE_CURRENT_LIST_DIR}/ui/uiwidget.cpp
190
-    ${CMAKE_CURRENT_LIST_DIR}/ui/uilabel.cpp
191
-    ${CMAKE_CURRENT_LIST_DIR}/ui/uibutton.cpp
192 190
     ${CMAKE_CURRENT_LIST_DIR}/ui/uilineedit.cpp
193 191
     ${CMAKE_CURRENT_LIST_DIR}/ui/uiwindow.cpp
194 192
     ${CMAKE_CURRENT_LIST_DIR}/ui/uianchorlayout.cpp

+ 9
- 9
src/framework/const.h View File

@@ -198,15 +198,15 @@ namespace Fw
198 198
         AlignBottom = 8,
199 199
         AlignHorizontalCenter = 16,
200 200
         AlignVerticalCenter = 32,
201
-        AlignTopLeft = AlignTop | AlignLeft,
202
-        AlignTopRight = AlignTop | AlignRight,
203
-        AlignBottomLeft = AlignBottom | AlignLeft,
204
-        AlignBottomRight = AlignBottom | AlignRight,
205
-        AlignLeftCenter = AlignLeft | AlignVerticalCenter,
206
-        AlignRightCenter = AlignRight | AlignVerticalCenter,
207
-        AlignTopCenter = AlignTop | AlignHorizontalCenter,
208
-        AlignBottomCenter = AlignBottom | AlignHorizontalCenter,
209
-        AlignCenter = AlignVerticalCenter | AlignHorizontalCenter
201
+        AlignTopLeft = AlignTop | AlignLeft, // 5
202
+        AlignTopRight = AlignTop | AlignRight, // 6
203
+        AlignBottomLeft = AlignBottom | AlignLeft, // 9
204
+        AlignBottomRight = AlignBottom | AlignRight, // 10
205
+        AlignLeftCenter = AlignLeft | AlignVerticalCenter, // 33
206
+        AlignRightCenter = AlignRight | AlignVerticalCenter, // 34
207
+        AlignTopCenter = AlignTop | AlignHorizontalCenter, // 20
208
+        AlignBottomCenter = AlignBottom | AlignHorizontalCenter, // 24
209
+        AlignCenter = AlignVerticalCenter | AlignHorizontalCenter // 48
210 210
     };
211 211
 
212 212
     enum AnchorEdge {

+ 1
- 1
src/framework/graphics/particle.h View File

@@ -36,7 +36,7 @@ public:
36 36
 
37 37
     bool hasFinished() { return m_finished; }
38 38
 
39
-    PointF getPosition() { return m_position; }
39
+    PointF getPos() { return m_position; }
40 40
     PointF getVelocity() { return m_velocity; }
41 41
 
42 42
     void setPos(const PointF& position) { m_position = position; }

+ 1
- 1
src/framework/graphics/particleaffector.cpp View File

@@ -131,7 +131,7 @@ void AttractionAffector::updateParticle(const ParticlePtr& particle, double elap
131 131
     if(!m_active)
132 132
         return;
133 133
 
134
-    PointF pPosition = particle->getPosition();
134
+    PointF pPosition = particle->getPos();
135 135
     PointF d = PointF(m_position.x - pPosition.x, pPosition.y - m_position.y);
136 136
     if(d.length() == 0)
137 137
         return;

+ 30
- 22
src/framework/luafunctions.cpp View File

@@ -37,6 +37,9 @@ void Application::registerLuaFunctions()
37 37
     g_lua.registerClass<UIWidget>();
38 38
     g_lua.bindClassStaticFunction<UIWidget>("create", &UIWidget::create<UIWidget>);
39 39
     g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
40
+    g_lua.bindClassMemberFunction<UIWidget>("render", &UIWidget::render);
41
+    g_lua.bindClassMemberFunction<UIWidget>("renderSelf", &UIWidget::renderSelf);
42
+    g_lua.bindClassMemberFunction<UIWidget>("renderChildren", &UIWidget::renderChildren);
40 43
     g_lua.bindClassMemberFunction<UIWidget>("setVisible", &UIWidget::setVisible);
41 44
     g_lua.bindClassMemberFunction<UIWidget>("setEnabled", &UIWidget::setEnabled);
42 45
     g_lua.bindClassMemberFunction<UIWidget>("setPressed", &UIWidget::setPressed);
@@ -53,7 +56,7 @@ void Application::registerLuaFunctions()
53 56
     g_lua.bindClassMemberFunction<UIWidget>("setWidth", &UIWidget::setWidth);
54 57
     g_lua.bindClassMemberFunction<UIWidget>("setHeight", &UIWidget::setHeight);
55 58
     //g_lua.bindClassMemberFunction<UIWidget>("setImage", &UIWidget::setImage);
56
-    //g_lua.bindClassMemberFunction<UIWidget>("setFont", &UIWidget::setFont);
59
+    g_lua.bindClassMemberFunction<UIWidget>("setIcon", &UIWidget::setIcon);
57 60
     g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity);
58 61
     g_lua.bindClassMemberFunction<UIWidget>("setBackgroundColor", &UIWidget::setBackgroundColor);
59 62
     g_lua.bindClassMemberFunction<UIWidget>("setForegroundColor", &UIWidget::setForegroundColor);
@@ -61,10 +64,15 @@ void Application::registerLuaFunctions()
61 64
     g_lua.bindClassMemberFunction<UIWidget>("setMarginRight", &UIWidget::setMarginRight);
62 65
     g_lua.bindClassMemberFunction<UIWidget>("setMarginBottom", &UIWidget::setMarginBottom);
63 66
     g_lua.bindClassMemberFunction<UIWidget>("setMarginLeft", &UIWidget::setMarginLeft);
67
+    g_lua.bindClassMemberFunction<UIWidget>("setText", &UIWidget::setText);
68
+    g_lua.bindClassMemberFunction<UIWidget>("setTextAlign", &UIWidget::setTextAlign);
69
+    g_lua.bindClassMemberFunction<UIWidget>("setTextOffset", &UIWidget::setTextOffset);
70
+    g_lua.bindClassMemberFunction<UIWidget>("setFont", &UIWidget::setFont);
64 71
     g_lua.bindClassMemberFunction<UIWidget>("setSizeFixed", &UIWidget::setSizeFixed);
65 72
     g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason);
66 73
     g_lua.bindClassMemberFunction<UIWidget>("bindRectToParent", &UIWidget::bindRectToParent);
67 74
     g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize);
75
+    g_lua.bindClassMemberFunction<UIWidget>("resizeToText", &UIWidget::resizeToText);
68 76
     g_lua.bindClassMemberFunction<UIWidget>("moveTo", &UIWidget::moveTo);
69 77
     g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
70 78
     g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
@@ -102,15 +110,13 @@ void Application::registerLuaFunctions()
102 110
     g_lua.bindClassMemberFunction<UIWidget>("getLayout", &UIWidget::getLayout);
103 111
     g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
104 112
     g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
105
-    g_lua.bindClassMemberFunction<UIWidget>("getPosition", &UIWidget::getPosition);
113
+    g_lua.bindClassMemberFunction<UIWidget>("getPos", &UIWidget::getPos);
106 114
     g_lua.bindClassMemberFunction<UIWidget>("getSize", &UIWidget::getSize);
107 115
     g_lua.bindClassMemberFunction<UIWidget>("getRect", &UIWidget::getRect);
108 116
     g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX);
109 117
     g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY);
110 118
     g_lua.bindClassMemberFunction<UIWidget>("getWidth", &UIWidget::getWidth);
111 119
     g_lua.bindClassMemberFunction<UIWidget>("getHeight", &UIWidget::getHeight);
112
-    //g_lua.bindClassMemberFunction<UIWidget>("getImage", &UIWidget::getImage);
113
-    //g_lua.bindClassMemberFunction<UIWidget>("getFont", &UIWidget::getFont);
114 120
     g_lua.bindClassMemberFunction<UIWidget>("getForegroundColor", &UIWidget::getForegroundColor);
115 121
     g_lua.bindClassMemberFunction<UIWidget>("getBackgroundColor", &UIWidget::getBackgroundColor);
116 122
     g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity);
@@ -118,6 +124,11 @@ void Application::registerLuaFunctions()
118 124
     g_lua.bindClassMemberFunction<UIWidget>("getMarginRight", &UIWidget::getMarginRight);
119 125
     g_lua.bindClassMemberFunction<UIWidget>("getMarginBottom", &UIWidget::getMarginBottom);
120 126
     g_lua.bindClassMemberFunction<UIWidget>("getMarginLeft", &UIWidget::getMarginLeft);
127
+    g_lua.bindClassMemberFunction<UIWidget>("getText", &UIWidget::getText);
128
+    g_lua.bindClassMemberFunction<UIWidget>("getTextAlign", &UIWidget::getTextAlign);
129
+    g_lua.bindClassMemberFunction<UIWidget>("getTextOffset", &UIWidget::getTextOffset);
130
+    g_lua.bindClassMemberFunction<UIWidget>("getFont", &UIWidget::getFont);
131
+    g_lua.bindClassMemberFunction<UIWidget>("getTextSize", &UIWidget::getTextSize);
121 132
     g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason);
122 133
     g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
123 134
     g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
@@ -169,32 +180,30 @@ void Application::registerLuaFunctions()
169 180
     g_lua.bindClassMemberFunction<UIAnchorLayout>("centerIn", &UIAnchorLayout::centerIn);
170 181
     g_lua.bindClassMemberFunction<UIAnchorLayout>("fill", &UIAnchorLayout::fill);
171 182
 
172
-    // UILabel
173
-    g_lua.registerClass<UILabel, UIWidget>();
174
-    g_lua.bindClassStaticFunction<UILabel>("create", &UIWidget::create<UILabel>);
175
-    g_lua.bindClassMemberFunction<UILabel>("getText", &UILabel::getText);
176
-    g_lua.bindClassMemberFunction<UILabel>("setText", &UILabel::setText);
177
-    g_lua.bindClassMemberFunction("resizeToText", &UILabel::resizeToText);
178
-
179
-    // UILabel
183
+    // UIProgressBar
180 184
     g_lua.registerClass<UIProgressBar, UIWidget>();
181 185
     g_lua.bindClassStaticFunction<UIProgressBar>("create", &UIWidget::create<UIProgressBar>);
182 186
     g_lua.bindClassMemberFunction<UIProgressBar>("getPercent", &UIProgressBar::getPercent);
183 187
     g_lua.bindClassMemberFunction<UIProgressBar>("setPercent", &UIProgressBar::setPercent);
184 188
 
185
-    // UIButton
186
-    g_lua.registerClass<UIButton, UIWidget>();
187
-    g_lua.bindClassStaticFunction<UIButton>("create", &UIWidget::create<UIButton>);
188
-    g_lua.bindClassMemberFunction<UIButton>("getText", &UIButton::getText);
189
-    g_lua.bindClassMemberFunction<UIButton>("setText", &UIButton::setText);
190
-
191 189
     // UILineEdit
192 190
     g_lua.registerClass<UILineEdit, UIWidget>();
193 191
     g_lua.bindClassStaticFunction<UILineEdit>("create", &UIWidget::create<UILineEdit>);
194
-    g_lua.bindClassMemberFunction<UILineEdit>("getText", &UILineEdit::getText);
195
-    g_lua.bindClassMemberFunction<UILineEdit>("setText", &UILineEdit::setText);
196
-    g_lua.bindClassMemberFunction<UILineEdit>("clearText", &UILineEdit::clearText);
192
+    g_lua.bindClassMemberFunction<UILineEdit>("setTextHorizontalMargin", &UILineEdit::setTextHorizontalMargin);
193
+    g_lua.bindClassMemberFunction<UILineEdit>("setCursorPos", &UILineEdit::setCursorPos);
194
+    g_lua.bindClassMemberFunction<UILineEdit>("setCursorEnabled", &UILineEdit::setCursorEnabled);
195
+    g_lua.bindClassMemberFunction<UILineEdit>("setTextHidden", &UILineEdit::setTextHidden);
196
+    g_lua.bindClassMemberFunction<UILineEdit>("setAlwaysActive", &UILineEdit::setAlwaysActive);
197
+    g_lua.bindClassMemberFunction<UILineEdit>("moveCursor", &UILineEdit::moveCursor);
198
+    g_lua.bindClassMemberFunction<UILineEdit>("appendText", &UILineEdit::appendText);
199
+    g_lua.bindClassMemberFunction<UILineEdit>("removeCharacter", &UILineEdit::removeCharacter);
200
+    g_lua.bindClassMemberFunction<UILineEdit>("getDisplayedText", &UILineEdit::getDisplayedText);
201
+    g_lua.bindClassMemberFunction<UILineEdit>("getTextPos", &UILineEdit::getTextPos);
202
+    g_lua.bindClassMemberFunction<UILineEdit>("getTextHorizontalMargin", &UILineEdit::getTextHorizontalMargin);
197 203
     g_lua.bindClassMemberFunction<UILineEdit>("getCursorPos", &UILineEdit::getCursorPos);
204
+    g_lua.bindClassMemberFunction<UILineEdit>("isCursorEnabled", &UILineEdit::isCursorEnabled);
205
+    g_lua.bindClassMemberFunction<UILineEdit>("isAlwaysActive", &UILineEdit::isAlwaysActive);
206
+    g_lua.bindClassMemberFunction<UILineEdit>("isTextHidden", &UILineEdit::isTextHidden);
198 207
 
199 208
     // UICheckBox
200 209
     g_lua.registerClass<UICheckBox, UIWidget>();
@@ -202,7 +211,6 @@ void Application::registerLuaFunctions()
202 211
     g_lua.bindClassMemberFunction<UICheckBox>("isChecked", &UICheckBox::isChecked);
203 212
     g_lua.bindClassMemberFunction<UICheckBox>("setChecked", &UICheckBox::setChecked);
204 213
 
205
-
206 214
     // UIWindow
207 215
     g_lua.registerClass<UIWindow, UIWidget>();
208 216
     g_lua.bindClassStaticFunction<UIWindow>("create", &UIWidget::create<UIWindow>);

+ 0
- 2
src/framework/ui/ui.h View File

@@ -25,8 +25,6 @@
25 25
 
26 26
 #include "uimanager.h"
27 27
 #include "uiwidget.h"
28
-#include "uibutton.h"
29
-#include "uilabel.h"
30 28
 #include "uilineedit.h"
31 29
 #include "uiwindow.h"
32 30
 #include "uiframecounter.h"

+ 0
- 72
src/framework/ui/uibutton.cpp View File

@@ -1,72 +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 "uibutton.h"
24
-#include <framework/graphics/borderimage.h>
25
-#include <framework/graphics/font.h>
26
-#include <framework/otml/otmlnode.h>
27
-#include <framework/luascript/luainterface.h>
28
-#include <framework/graphics/graphics.h>
29
-#include <framework/graphics/texture.h>
30
-#include <framework/graphics/texturemanager.h>
31
-
32
-UIButton::UIButton()
33
-{
34
-    m_focusable = false;
35
-}
36
-
37
-void UIButton::render()
38
-{
39
-    UIWidget::render();
40
-
41
-    if(m_icon) {
42
-        Rect iconRect;
43
-        iconRect.resize(m_icon->getSize());
44
-        iconRect.moveCenter(m_rect.center());
45
-        g_painter.drawTexturedRect(iconRect, m_icon);
46
-    }
47
-
48
-    Rect textRect = m_rect;
49
-    textRect.translate(m_textOffset);
50
-    m_font->renderText(m_text, textRect, Fw::AlignCenter, m_foregroundColor);
51
-}
52
-
53
-void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
54
-{
55
-    UIWidget::onStyleApply(styleNode);
56
-
57
-    for(OTMLNodePtr node : styleNode->children()) {
58
-        if(node->tag() == "text-offset")
59
-            m_textOffset = node->value<Point>();
60
-        else if(node->tag() == "text")
61
-            m_text = node->value();
62
-        else if(node->tag() == "icon")
63
-            m_icon = g_textures.getTexture(node->value());
64
-    }
65
-}
66
-
67
-void UIButton::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
68
-{
69
-    if(isPressed() && getRect().contains(mousePos)) {
70
-        callLuaField("onClick");
71
-    }
72
-}

+ 0
- 49
src/framework/ui/uibutton.h View File

@@ -1,49 +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
-#ifndef UIBUTTON_H
24
-#define UIBUTTON_H
25
-
26
-#include "uiwidget.h"
27
-
28
-class UIButton : public UIWidget
29
-{
30
-public:
31
-    UIButton();
32
-
33
-    virtual void render();
34
-
35
-    void setText(const std::string& text) { m_text = text; }
36
-    std::string getText() const { return m_text; }
37
-
38
-    UIButtonPtr asUIButton() { return std::static_pointer_cast<UIButton>(shared_from_this()); }
39
-
40
-protected:
41
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
42
-    virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
43
-
44
-    Point m_textOffset;
45
-    TexturePtr m_icon;
46
-    std::string m_text;
47
-};
48
-
49
-#endif

+ 2
- 2
src/framework/ui/uicheckbox.cpp View File

@@ -58,9 +58,9 @@ void UICheckBox::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
58 58
         setChecked(!isChecked());
59 59
 }
60 60
 
61
-void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode)
61
+void UICheckBox::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
62 62
 {
63
-    UIWidget::onStyleApply(styleNode);
63
+    UIWidget::onStyleApply(styleName, styleNode);
64 64
 
65 65
     for(OTMLNodePtr node : styleNode->children()) {
66 66
         if(node->tag() == "text-offset")

+ 1
- 1
src/framework/ui/uicheckbox.h View File

@@ -40,7 +40,7 @@ public:
40 40
     UICheckBoxPtr asUICheckBox() { return std::static_pointer_cast<UICheckBox>(shared_from_this()); }
41 41
 
42 42
 protected:
43
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
43
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
44 44
     virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
45 45
 
46 46
     std::string m_text;

+ 2
- 2
src/framework/ui/uiframecounter.cpp View File

@@ -50,9 +50,9 @@ void UIFrameCounter::render()
50 50
     m_font->renderText(m_fpsText, m_rect, m_align, Fw::white);
51 51
 }
52 52
 
53
-void UIFrameCounter::onStyleApply(const OTMLNodePtr& styleNode)
53
+void UIFrameCounter::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
54 54
 {
55
-    UIWidget::onStyleApply(styleNode);
55
+    UIWidget::onStyleApply(styleName, styleNode);
56 56
 
57 57
     for(const OTMLNodePtr& node : styleNode->children()) {
58 58
         if(node->tag() == "align")

+ 1
- 1
src/framework/ui/uiframecounter.h View File

@@ -36,7 +36,7 @@ public:
36 36
     int getFrameCount() { return m_frameCount; }
37 37
 
38 38
 protected:
39
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
39
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
40 40
 
41 41
 private:
42 42
     Fw::AlignmentFlag m_align;

+ 0
- 75
src/framework/ui/uilabel.cpp View File

@@ -1,75 +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 "uilabel.h"
24
-#include "uitranslator.h"
25
-#include <framework/graphics/font.h>
26
-#include <framework/otml/otmlnode.h>
27
-
28
-UILabel::UILabel()
29
-{
30
-    m_focusable = false;
31
-    m_phantom = true;
32
-    m_textAlign = Fw::AlignLeft;
33
-}
34
-
35
-void UILabel::render()
36
-{
37
-    UIWidget::render();
38
-    Rect textRect = m_rect;
39
-    textRect.setTopLeft(textRect.topLeft() + m_textOffset);
40
-    m_font->renderText(m_text, textRect, m_textAlign, m_foregroundColor);
41
-}
42
-
43
-void UILabel::setText(const std::string& text)
44
-{
45
-    m_text = text;
46
-
47
-    // auto resize
48
-    if(!m_fixedSize && !m_rect.isValid()) {
49
-        Size textSize = m_font->calculateTextRectSize(m_text);
50
-        if(m_rect.width() <= 0)
51
-            m_rect.setWidth(textSize.width());
52
-        if(m_rect.height() <= 0)
53
-            m_rect.setHeight(textSize.height());
54
-    }
55
-}
56
-
57
-void UILabel::resizeToText()
58
-{
59
-    resize(m_font->calculateTextRectSize(m_text));
60
-}
61
-
62
-void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
63
-{
64
-    UIWidget::onStyleApply(styleNode);
65
-
66
-    for(const OTMLNodePtr& node : styleNode->children()) {
67
-        if(node->tag() == "text")
68
-            setText(node->value());
69
-        else if(node->tag() == "text-align")
70
-            setTextAlign(Fw::translateAlignment(node->value()));
71
-        else if(node->tag() == "text-offset") {
72
-            setTextOffset(node->value<Point>());
73
-        }
74
-    }
75
-}

+ 0
- 53
src/framework/ui/uilabel.h View File

@@ -1,53 +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
-#ifndef UILABEL_H
24
-#define UILABEL_H
25
-
26
-#include "uiwidget.h"
27
-
28
-class UILabel : public UIWidget
29
-{
30
-public:
31
-    UILabel();
32
-    virtual void render();
33
-
34
-    void resizeToText();
35
-
36
-    void setText(const std::string& text);
37
-    void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; }
38
-    void setTextOffset(const Point& offset) { m_textOffset = offset; }
39
-
40
-    std::string getText() const { return m_text; }
41
-    Fw::AlignmentFlag getTextAlign() const { return m_textAlign; }
42
-    Point getTextOffset() const { return m_textOffset; }
43
-
44
-protected:
45
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
46
-
47
-private:
48
-    std::string m_text;
49
-    Point m_textOffset;
50
-    Fw::AlignmentFlag m_textAlign;
51
-};
52
-
53
-#endif

+ 49
- 48
src/framework/ui/uilineedit.cpp View File

@@ -29,8 +29,8 @@
29 29
 
30 30
 UILineEdit::UILineEdit()
31 31
 {
32
-    m_align = Fw::AlignLeftCenter;
33 32
     m_cursorPos = 0;
33
+    m_textAlign = Fw::AlignLeftCenter;
34 34
     m_startRenderPos = 0;
35 35
     m_textHorizontalMargin = 0;
36 36
     m_textHidden = false;
@@ -38,9 +38,12 @@ UILineEdit::UILineEdit()
38 38
     blinkCursor();
39 39
 }
40 40
 
41
-void UILineEdit::render()
41
+void UILineEdit::renderSelf()
42 42
 {
43
-    UIWidget::render();
43
+    drawBackground(m_rect);
44
+    drawBorder(m_rect);
45
+    drawImage(m_rect);
46
+    drawIcon(m_rect);
44 47
 
45 48
     //TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture
46 49
 
@@ -81,7 +84,7 @@ void UILineEdit::update()
81 84
 
82 85
     // map glyphs positions
83 86
     Size textBoxSize;
84
-    const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_align, &textBoxSize);
87
+    const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize);
85 88
     const Rect *glyphsTextureCoords = m_font->getGlyphsTextureCoords();
86 89
     const Size *glyphsSize = m_font->getGlyphsSize();
87 90
     int glyph;
@@ -141,16 +144,16 @@ void UILineEdit::update()
141 144
     textScreenCoords.addRight(-m_textHorizontalMargin);
142 145
     m_drawArea = textScreenCoords;
143 146
 
144
-    if(m_align & Fw::AlignBottom) {
147
+    if(m_textAlign & Fw::AlignBottom) {
145 148
         m_drawArea.translate(0, textScreenCoords.height() - textBoxSize.height());
146
-    } else if(m_align & Fw::AlignVerticalCenter) {
149
+    } else if(m_textAlign & Fw::AlignVerticalCenter) {
147 150
         m_drawArea.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2);
148 151
     } else { // AlignTop
149 152
     }
150 153
 
151
-    if(m_align & Fw::AlignRight) {
154
+    if(m_textAlign & Fw::AlignRight) {
152 155
         m_drawArea.translate(textScreenCoords.width() - textBoxSize.width(), 0);
153
-    } else if(m_align & Fw::AlignHorizontalCenter) {
156
+    } else if(m_textAlign & Fw::AlignHorizontalCenter) {
154 157
         m_drawArea.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0);
155 158
     } else { // AlignLeft
156 159
 
@@ -169,17 +172,17 @@ void UILineEdit::update()
169 172
         Rect glyphTextureCoords = glyphsTextureCoords[glyph];
170 173
 
171 174
         // first translate to align position
172
-        if(m_align & Fw::AlignBottom) {
175
+        if(m_textAlign & Fw::AlignBottom) {
173 176
             glyphScreenCoords.translate(0, textScreenCoords.height() - textBoxSize.height());
174
-        } else if(m_align & Fw::AlignVerticalCenter) {
177
+        } else if(m_textAlign & Fw::AlignVerticalCenter) {
175 178
             glyphScreenCoords.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2);
176 179
         } else { // AlignTop
177 180
             // nothing to do
178 181
         }
179 182
 
180
-        if(m_align & Fw::AlignRight) {
183
+        if(m_textAlign & Fw::AlignRight) {
181 184
             glyphScreenCoords.translate(textScreenCoords.width() - textBoxSize.width(), 0);
182
-        } else if(m_align & Fw::AlignHorizontalCenter) {
185
+        } else if(m_textAlign & Fw::AlignHorizontalCenter) {
183 186
             glyphScreenCoords.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0);
184 187
         } else { // AlignLeft
185 188
             // nothing to do
@@ -225,38 +228,12 @@ void UILineEdit::update()
225 228
     }
226 229
 }
227 230
 
228
-void UILineEdit::setFont(const FontPtr& font)
231
+void UILineEdit::setTextHorizontalMargin(int margin)
229 232
 {
230
-    if(m_font != font) {
231
-        m_font = font;
232
-        update();
233
-    }
234
-}
235
-
236
-void UILineEdit::setText(const std::string& text)
237
-{
238
-    if(m_text != text) {
239
-        m_text = text;
240
-        m_cursorPos = text.length();
241
-        blinkCursor();
242
-        update();
243
-    }
244
-}
245
-
246
-void UILineEdit::setTextHidden(bool hidden)
247
-{
248
-    m_textHidden = true;
233
+    m_textHorizontalMargin = margin;
249 234
     update();
250 235
 }
251 236
 
252
-void UILineEdit::setAlign(Fw::AlignmentFlag align)
253
-{
254
-    if(m_align != align) {
255
-        m_align = align;
256
-        update();
257
-    }
258
-}
259
-
260 237
 void UILineEdit::setCursorPos(int pos)
261 238
 {
262 239
     if(pos != m_cursorPos) {
@@ -280,6 +257,17 @@ void UILineEdit::setCursorEnabled(bool enable)
280 257
     update();
281 258
 }
282 259
 
260
+void UILineEdit::setTextHidden(bool hidden)
261
+{
262
+    m_textHidden = true;
263
+    update();
264
+}
265
+
266
+void UILineEdit::setAlwaysActive(bool enable)
267
+{
268
+    m_alwaysActive = enable;
269
+}
270
+
283 271
 void UILineEdit::appendText(std::string text)
284 272
 {
285 273
     if(m_cursorPos >= 0) {
@@ -373,21 +361,34 @@ std::string UILineEdit::getDisplayedText()
373 361
         return m_text;
374 362
 }
375 363
 
376
-void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode)
364
+void UILineEdit::onTextChange(const std::string& text)
365
+{
366
+    m_cursorPos = text.length();
367
+    blinkCursor();
368
+    update();
369
+    UIWidget::onTextChange(text);
370
+}
371
+
372
+void UILineEdit::onFontChange(const std::string& font)
377 373
 {
378
-    UIWidget::onStyleApply(styleNode);
374
+    update();
375
+    UIWidget::onFontChange(font);
376
+}
377
+
378
+void UILineEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
379
+{
380
+    UIWidget::onStyleApply(styleName, styleNode);
379 381
 
380 382
     for(const OTMLNodePtr& node : styleNode->children()) {
381 383
         if(node->tag() == "text") {
382 384
             setText(node->value());
383 385
             setCursorPos(m_text.length());
384
-        } else if(node->tag() == "text-hidden") {
386
+        } else if(node->tag() == "text-hidden")
385 387
             setTextHidden(node->value<bool>());
386
-        } else if(node->tag() == "text-margin") {
387
-            m_textHorizontalMargin = node->value<int>();
388
-        } else if(node->tag() == "always-active") {
389
-            m_alwaysActive = true;
390
-        }
388
+        else if(node->tag() == "text-margin")
389
+            setTextHorizontalMargin(node->value<int>());
390
+        else if(node->tag() == "always-active")
391
+            setAlwaysActive(node->value<bool>());
391 392
     }
392 393
 }
393 394
 

+ 15
- 12
src/framework/ui/uilineedit.h View File

@@ -30,30 +30,35 @@ class UILineEdit : public UIWidget
30 30
 public:
31 31
     UILineEdit();
32 32
 
33
-    virtual void render();
33
+    virtual void renderSelf();
34 34
 
35
+private:
35 36
     void update();
36 37
 
37
-    void setText(const std::string& text);
38
-    void setTextHidden(bool hidden);
39
-    void setAlign(Fw::AlignmentFlag align);
38
+public:
39
+    void setTextHorizontalMargin(int margin);
40 40
     void setCursorPos(int pos);
41
-    void setCursorEnabled(bool enable = true);
41
+    void setCursorEnabled(bool enable);
42
+    void setTextHidden(bool hidden);
43
+    void setAlwaysActive(bool enable);
42 44
 
43
-    void clearText() { setText(""); }
44 45
     void moveCursor(bool right);
45 46
     void appendText(std::string text);
46 47
     void appendCharacter(char c);
47 48
     void removeCharacter(bool right);
48 49
 
49
-    void setFont(const FontPtr& font);
50
-    std::string getText() const { return m_text; }
51 50
     std::string getDisplayedText();
52 51
     int getTextPos(Point pos);
53
-    int getCursorPos() const { return m_cursorPos; }
52
+    int getTextHorizontalMargin() { return m_textHorizontalMargin; }
53
+    int getCursorPos() { return m_cursorPos; }
54
+    bool isCursorEnabled() { return m_cursorPos != -1; }
55
+    bool isAlwaysActive() { return m_alwaysActive; }
56
+    bool isTextHidden() { return m_textHidden; }
54 57
 
55 58
 protected:
56
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
59
+    virtual void onTextChange(const std::string& text);
60
+    virtual void onFontChange(const std::string& font);
61
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
57 62
     virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
58 63
     virtual void onFocusChange(bool focused, Fw::FocusReason reason);
59 64
     virtual bool onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers);
@@ -62,9 +67,7 @@ protected:
62 67
 private:
63 68
     void blinkCursor();
64 69
 
65
-    std::string m_text;
66 70
     Rect m_drawArea;
67
-    Fw::AlignmentFlag m_align;
68 71
     int m_cursorPos;
69 72
     Point m_startInternalPos;
70 73
     int m_startRenderPos;

+ 1
- 1
src/framework/ui/uiverticallayout.cpp View File

@@ -54,7 +54,7 @@ void UIVerticalLayout::update()
54 54
     if(m_alignBottom)
55 55
         std::reverse(widgets.begin(), widgets.end());
56 56
 
57
-    Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPosition();
57
+    Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPos();
58 58
     int prefferedHeight = 0;
59 59
     int gap;
60 60
 

+ 124
- 13
src/framework/ui/uiwidget.cpp View File

@@ -33,6 +33,7 @@
33 33
 #include <framework/otml/otmlnode.h>
34 34
 #include <framework/graphics/graphics.h>
35 35
 #include <framework/platform/platformwindow.h>
36
+#include <framework/graphics/texturemanager.h>
36 37
 
37 38
 UIWidget::UIWidget()
38 39
 {
@@ -41,6 +42,10 @@ UIWidget::UIWidget()
41 42
     m_font = g_fonts.getDefaultFont();
42 43
     m_opacity = 255;
43 44
     m_marginTop = m_marginRight = m_marginBottom = m_marginLeft = 0;
45
+    //m_backgroundColor = Fw::alpha;
46
+    m_backgroundColor = Fw::white;
47
+    m_foregroundColor = Fw::white;
48
+    m_textAlign = Fw::AlignCenter;
44 49
 
45 50
     // generate an unique id, this is need because anchored layouts find widgets by id
46 51
     static unsigned long id = 1;
@@ -74,11 +79,12 @@ void UIWidget::render()
74 79
 
75 80
 void UIWidget::renderSelf()
76 81
 {
77
-    // draw background
78
-    if(m_image) {
79
-        g_painter.setColor(m_backgroundColor);
80
-        m_image->draw(m_rect);
81
-    }
82
+    // draw style components in order
83
+    drawBackground(m_rect);
84
+    drawBorder(m_rect);
85
+    drawImage(m_rect);
86
+    drawIcon(m_rect);
87
+    drawText(m_rect);
82 88
 }
83 89
 
84 90
 void UIWidget::renderChildren()
@@ -86,7 +92,10 @@ void UIWidget::renderChildren()
86 92
     // draw children
87 93
     for(const UIWidgetPtr& child : m_children) {
88 94
         // render only visible children with a valid rect inside our rect
89
-        if(child->isExplicitlyVisible() && child->getRect().isValid() && child->getRect().intersects(m_rect)) {
95
+        if(child->isExplicitlyVisible() &&
96
+           child->getRect().isValid() &&
97
+           child->getRect().intersects(m_rect) &&
98
+           child->getOpacity() > 0) {
90 99
             // store current graphics opacity
91 100
             int oldOpacity = g_painter.getOpacity();
92 101
 
@@ -99,13 +108,63 @@ void UIWidget::renderChildren()
99 108
             // debug draw box
100 109
             //g_painter.setColor(Fw::green);
101 110
             //g_painter.drawBoundingRect(child->getRect());
102
-            //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPosition() + Point(2, 0), Fw::red);
111
+            //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPos() + Point(2, 0), Fw::red);
103 112
 
104 113
             g_painter.setOpacity(oldOpacity);
105 114
         }
106 115
     }
107 116
 }
108 117
 
118
+void UIWidget::drawBackground(const Rect& screenCoords)
119
+{
120
+    /*
121
+    if(m_backgroundColor.a() > 0) {
122
+        g_painter.setColor(m_backgroundColor);
123
+        g_painter.drawFilledRect(screenCoords);
124
+        //g_painter.drawFilledRect(screenCoords.expanded(-m_borderWidth));
125
+    }
126
+    */
127
+}
128
+
129
+void UIWidget::drawBorder(const Rect& screenCoords)
130
+{
131
+    /*
132
+    if(m_borderWidth > 0 && m_borderColor.a() > 0) {
133
+        g_painter.bindColor(m_borderColor);
134
+        g_painter.drawBoundingRect(screenCoords, m_borderWidth);
135
+    }
136
+    */
137
+}
138
+
139
+void UIWidget::drawImage(const Rect& screenCoords)
140
+{
141
+    if(m_image) {
142
+        g_painter.setColor(m_backgroundColor);
143
+        m_image->draw(screenCoords);
144
+    }
145
+}
146
+
147
+void UIWidget::drawIcon(const Rect& screenCoords)
148
+{
149
+    if(m_icon) {
150
+        Rect iconRect;
151
+        iconRect.resize(m_icon->getSize());
152
+        iconRect.moveCenter(screenCoords.center());
153
+        g_painter.setColor(Fw::white);
154
+        g_painter.drawTexturedRect(iconRect, m_icon);
155
+    }
156
+}
157
+
158
+void UIWidget::drawText(const Rect& screenCoords)
159
+{
160
+    g_painter.setColor(m_foregroundColor);
161
+    if(m_text.length() > 0 && m_foregroundColor.a() > 0) {
162
+        Rect textRect = screenCoords;
163
+        textRect.translate(m_textOffset);
164
+        m_font->renderText(m_text, textRect, m_textAlign, m_foregroundColor);
165
+    }
166
+}
167
+
109 168
 void UIWidget::setEnabled(bool enabled)
110 169
 {
111 170
     if(enabled != m_enabled) {
@@ -215,6 +274,36 @@ void UIWidget::setRect(const Rect& rect)
215 274
     m_updateEventScheduled = true;
216 275
 }
217 276
 
277
+void UIWidget::setIcon(const std::string& iconFile)
278
+{
279
+    m_icon = g_textures.getTexture(iconFile);
280
+}
281
+
282
+void UIWidget::setText(const std::string& text)
283
+{
284
+    if(m_text != text) {
285
+        m_text = text;
286
+
287
+        // update rect size
288
+        if(!m_rect.isValid()) {
289
+            Size textSize = m_font->calculateTextRectSize(m_text);
290
+            Size newSize = getSize();
291
+            if(newSize.width() <= 0)
292
+                newSize.setWidth(textSize.width());
293
+            if(newSize.height() <= 0)
294
+                newSize.setHeight(textSize.height());
295
+            resize(newSize);
296
+        }
297
+
298
+        onTextChange(text);
299
+    }
300
+}
301
+
302
+void UIWidget::setFont(const std::string& fontName)
303
+{
304
+    m_font = g_fonts.getFont(fontName);
305
+}
306
+
218 307
 void UIWidget::bindRectToParent()
219 308
 {
220 309
     Rect boundRect = m_rect;
@@ -672,8 +761,8 @@ void UIWidget::updateLayout()
672 761
 void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
673 762
 {
674 763
     try {
675
-        onStyleApply(styleNode);
676
-        callLuaField("onStyleApply", styleNode);
764
+        onStyleApply(styleNode->tag(), styleNode);
765
+        callLuaField("onStyleApply", styleNode->tag(), styleNode);
677 766
     } catch(Exception& e) {
678 767
         logError("Failed to apply style to widget '", m_id, "' style: ", e.what());
679 768
     }
@@ -862,7 +951,7 @@ void UIWidget::updateStyle()
862 951
     m_stateStyle = newStateStyle;
863 952
 }
864 953
 
865
-void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
954
+void UIWidget::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
866 955
 {
867 956
     // first set id
868 957
     if(const OTMLNodePtr& node = styleNode->get("id"))
@@ -878,8 +967,16 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
878 967
         }
879 968
         else if(node->tag() == "border-image")
880 969
             setImage(BorderImage::loadFromOTML(node));
970
+        if(node->tag() == "icon")
971
+            setIcon(node->value());
972
+        else if(node->tag() == "text")
973
+            setText(node->value());
974
+        else if(node->tag() == "text-align")
975
+            setTextAlign(Fw::translateAlignment(node->value()));
976
+        else if(node->tag() == "text-offset")
977
+            setTextOffset(node->value<Point>());
881 978
         else if(node->tag() == "font")
882
-            setFont(g_fonts.getFont(node->value()));
979
+            setFont(node->value());
883 980
         else if(node->tag() == "color")
884 981
             setForegroundColor(node->value<Color>());
885 982
         else if(node->tag() == "background-color")
@@ -902,7 +999,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
902 999
             setHeight(node->value<int>());
903 1000
         else if(node->tag() == "fixed-size")
904 1001
             setSizeFixed(node->value<bool>());
905
-        else if(node->tag() == "position")
1002
+        else if(node->tag() == "pos")
906 1003
             moveTo(node->value<Point>());
907 1004
         else if(node->tag() == "x")
908 1005
             setX(node->value<int>());
@@ -1007,7 +1104,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
1007 1104
             }
1008 1105
         // lua functions
1009 1106
         } else if(boost::starts_with(node->tag(), "@")) {
1010
-            // on load once
1107
+            // load once
1011 1108
             if(m_firstOnStyle) {
1012 1109
                 std::string funcName = node->tag().substr(1);
1013 1110
                 std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]";
@@ -1051,6 +1148,17 @@ void UIWidget::onHoverChange(bool hovered)
1051 1148
         g_ui.getRootWidget()->updateState(Fw::HoverState);
1052 1149
 }
1053 1150
 
1151
+
1152
+void UIWidget::onTextChange(const std::string& text)
1153
+{
1154
+    callLuaField("onTextChange", text);
1155
+}
1156
+
1157
+void UIWidget::onFontChange(const std::string& font)
1158
+{
1159
+    callLuaField("onFontChange", font);
1160
+}
1161
+
1054 1162
 bool UIWidget::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers)
1055 1163
 {
1056 1164
     if(callLuaField<bool>("onKeyPress", keyCode, keyText, keyboardModifiers))
@@ -1140,6 +1248,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
1140 1248
 
1141 1249
 void UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
1142 1250
 {
1251
+    if(isPressed() && getRect().contains(mousePos))
1252
+        callLuaField("onClick");
1253
+
1143 1254
     callLuaField("onMouseRelease", mousePos, button);
1144 1255
 
1145 1256
     // do a backup of children list, because it may change while looping it

+ 33
- 19
src/framework/ui/uiwidget.h View File

@@ -27,6 +27,7 @@
27 27
 #include <framework/luascript/luaobject.h>
28 28
 #include <framework/graphics/declarations.h>
29 29
 #include <framework/otml/otmlnode.h>
30
+#include <framework/graphics/font.h>
30 31
 
31 32
 class UIWidget : public LuaObject
32 33
 {
@@ -40,9 +41,17 @@ public:
40 41
     void destroy();
41 42
 
42 43
     virtual void render();
43
-    void renderSelf();
44
-    void renderChildren();
44
+    virtual void renderSelf();
45
+    virtual void renderChildren();
45 46
 
47
+protected:
48
+    void drawBackground(const Rect& screenCoords);
49
+    void drawBorder(const Rect& screenCoords);
50
+    void drawImage(const Rect& screenCoords);
51
+    void drawIcon(const Rect& screenCoords);
52
+    void drawText(const Rect& screenCoords);
53
+
54
+public:
46 55
     void setVisible(bool visible);
47 56
     void setEnabled(bool enabled);
48 57
     void setPressed(bool pressed) { m_pressed = pressed; updateState(Fw::PressedState); }
@@ -59,7 +68,7 @@ public:
59 68
     void setWidth(int width) { resize(Size(width, getHeight())); }
60 69
     void setHeight(int height) { resize(Size(getWidth(), height)); }
61 70
     void setImage(const ImagePtr& image) { m_image = image; }
62
-    virtual void setFont(const FontPtr& font) { m_font = font; }
71
+    void setIcon(const std::string& iconFile);
63 72
     void setOpacity(int opacity) { m_opacity = opacity; }
64 73
     void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
65 74
     void setForegroundColor(const Color& color) { m_foregroundColor = color; }
@@ -67,11 +76,16 @@ public:
67 76
     void setMarginRight(int margin) { m_marginRight = margin; updateParentLayout(); }
68 77
     void setMarginBottom(int margin) { m_marginBottom = margin; updateParentLayout(); }
69 78
     void setMarginLeft(int margin) { m_marginLeft = margin; updateParentLayout(); }
79
+    void setText(const std::string& text);
80
+    void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; }
81
+    void setTextOffset(const Point& offset) { m_textOffset = offset; }
82
+    void setFont(const std::string& fontName);
70 83
     void setSizeFixed(bool fixed) { m_fixedSize = fixed; updateParentLayout(); }
71 84
     void setLastFocusReason(Fw::FocusReason reason) { m_lastFocusReason = reason; }
72 85
 
73 86
     void bindRectToParent();
74
-    void resize(const Size& size) { setRect(Rect(getPosition(), size)); }
87
+    void resize(const Size& size) { setRect(Rect(getPos(), size)); }
88
+    void resizeToText() { resize(getTextSize()); }
75 89
     void moveTo(const Point& pos) { setRect(Rect(pos, getSize())); }
76 90
     void hide() { setVisible(false); }
77 91
     void show() { setVisible(true); }
@@ -84,6 +98,7 @@ public:
84 98
     void ungrabMouse();
85 99
     void grabKeyboard();
86 100
     void ungrabKeyboard();
101
+    void clearText() { setText(""); }
87 102
 
88 103
     bool isActive() { return hasState(Fw::ActiveState); }
89 104
     bool isEnabled() { return !hasState(Fw::DisabledState); }
@@ -111,15 +126,13 @@ public:
111 126
     UILayoutPtr getLayout() { return m_layout; }
112 127
     UIWidgetPtr getParent() { return m_parent.lock(); }
113 128
     UIWidgetPtr getRootParent();
114
-    Point getPosition() { return m_rect.topLeft(); }
129
+    Point getPos() { return m_rect.topLeft(); }
115 130
     Size getSize() { return m_rect.size(); }
116 131
     Rect getRect() { return m_rect; }
117 132
     int getX() { return m_rect.x(); }
118 133
     int getY() { return m_rect.y(); }
119 134
     int getWidth() { return m_rect.width(); }
120 135
     int getHeight() { return m_rect.height(); }
121
-    ImagePtr getImage() { return m_image; }
122
-    FontPtr getFont() { return m_font; }
123 136
     Color getForegroundColor() { return m_foregroundColor; }
124 137
     Color getBackgroundColor() { return m_backgroundColor; }
125 138
     int getOpacity() { return m_opacity; }
@@ -127,6 +140,12 @@ public:
127 140
     int getMarginRight() { return m_marginRight; }
128 141
     int getMarginBottom() { return m_marginBottom; }
129 142
     int getMarginLeft() { return m_marginLeft; }
143
+    std::string getText() { return m_text; }
144
+    Fw::AlignmentFlag getTextAlign() { return m_textAlign; }
145
+    Point getTextOffset() { return m_textOffset; }
146
+    std::string getFont() { return m_font->getName(); }
147
+    Size getTextSize() { return m_font->calculateTextRectSize(m_text); }
148
+
130 149
     Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
131 150
     OTMLNodePtr getStyle() { return m_style; }
132 151
     std::string getStyleName() { return m_style->tag(); }
@@ -175,27 +194,18 @@ private:
175 194
     void updateStyle();
176 195
 
177 196
 protected:
178
-    /// Triggered when widget style is changed
179
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
180
-    /// Triggered when widget is moved or resized
197
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
181 198
     virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
182
-    /// Triggered when widget gets or loses focus
183 199
     virtual void onFocusChange(bool focused, Fw::FocusReason reason);
184
-    /// Triggered when the mouse enters or leaves widget area
185 200
     virtual void onHoverChange(bool hovered);
186
-    /// Triggered when user presses key while widget has focus
201
+    virtual void onTextChange(const std::string& text);
202
+    virtual void onFontChange(const std::string& font);
187 203
     virtual bool onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers);
188
-    /// Triggered when user releases key while widget has focus
189 204
     virtual bool onKeyRelease(uchar keyCode, std::string keyText, int keyboardModifiers);
190
-    /// Triggered when a mouse button is pressed down while mouse pointer is inside widget area
191 205
     virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
192
-    /// Triggered when a mouse button is released
193 206
     virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
194
-    /// Triggered when mouse moves (even when the mouse is outside widget area)
195 207
     virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
196
-    /// Triggered when mouse middle button wheels inside widget area
197 208
     virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
198
-
199 209
     friend class UIManager;
200 210
 
201 211
 protected:
@@ -218,6 +228,7 @@ protected:
218 228
     OTMLNodePtr m_style;
219 229
     OTMLNodePtr m_stateStyle;
220 230
     ImagePtr m_image;
231
+    TexturePtr m_icon;
221 232
     FontPtr m_font;
222 233
     Color m_backgroundColor;
223 234
     Color m_foregroundColor;
@@ -227,6 +238,9 @@ protected:
227 238
     int m_marginRight;
228 239
     int m_marginBottom;
229 240
     int m_marginLeft;
241
+    std::string m_text;
242
+    Point m_textOffset;
243
+    Fw::AlignmentFlag m_textAlign;
230 244
 };
231 245
 
232 246
 #endif

+ 3
- 3
src/framework/ui/uiwindow.cpp View File

@@ -56,9 +56,9 @@ void UIWindow::render()
56 56
     m_font->renderText(m_title, headTextRect, m_titleAlign, m_foregroundColor);
57 57
 }
58 58
 
59
-void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
59
+void UIWindow::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
60 60
 {
61
-    UIWidget::onStyleApply(styleNode);
61
+    UIWidget::onStyleApply(styleName, styleNode);
62 62
 
63 63
     for(OTMLNodePtr node : styleNode->children()) {
64 64
         if(node->tag() == "head-height")
@@ -94,7 +94,7 @@ bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button)
94 94
             m_moving = true;
95 95
             m_movingReference = mousePos - getRect().topLeft();
96 96
             m_oldIndex = getParent()->getChildIndex(asUIWidget());
97
-            m_oldPos = getPosition();
97
+            m_oldPos = getPos();
98 98
             getParent()->moveChildToTop(asUIWidget());
99 99
         }
100 100
     }

+ 1
- 1
src/framework/ui/uiwindow.h View File

@@ -41,7 +41,7 @@ public:
41 41
     std::string getTitle() const { return m_title; }
42 42
 
43 43
 protected:
44
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
44
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
45 45
     virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
46 46
     virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
47 47
     virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);

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

@@ -98,7 +98,7 @@ void Game::processTextMessage(int type, const std::string& message)
98 98
 void Game::processInventoryChange(int slot, const ItemPtr& item)
99 99
 {
100 100
     if(item)
101
-        item->setPosition(Position(65535, slot, 0));
101
+        item->setPos(Position(65535, slot, 0));
102 102
 
103 103
     g_lua.callGlobalField("Game","onInventoryChange", slot, item);
104 104
 }
@@ -162,8 +162,8 @@ void Game::turn(Otc::Direction direction)
162 162
 void Game::look(const ThingPtr& thing)
163 163
 {
164 164
     // thing is at map
165
-    if(thing->getPosition().x != 65535) {
166
-        Position tilePos = thing->getPosition();
165
+    if(thing->getPos().x != 65535) {
166
+        Position tilePos = thing->getPos();
167 167
         TilePtr tile = nullptr;
168 168
         int stackpos = -1;
169 169
 
@@ -182,21 +182,21 @@ void Game::look(const ThingPtr& thing)
182 182
     }
183 183
     // thing is at inventory
184 184
     else
185
-        m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), 0);
185
+        m_protocolGame->sendLookAt(thing->getPos(), thing->getId(), 0);
186 186
 }
187 187
 
188 188
 void Game::use(const ThingPtr& thing)
189 189
 {
190 190
     // thing is at map
191
-    if(thing->getPosition().x != 65535) {
192
-        TilePtr tile = g_map.getTile(thing->getPosition());
191
+    if(thing->getPos().x != 65535) {
192
+        TilePtr tile = g_map.getTile(thing->getPos());
193 193
         int stackpos = tile->getThingStackpos(thing);
194 194
         if(stackpos != -1)
195
-            m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), stackpos, 0);
195
+            m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);
196 196
     }
197 197
     // thing is at inventory
198 198
     else
199
-        m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), 0, 0); // last 0 has something to do with container
199
+        m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), 0, 0); // last 0 has something to do with container
200 200
 }
201 201
 
202 202
 void Game::talkChannel(int channelType, int channelId, const std::string& message)

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

@@ -41,7 +41,7 @@ void Item::draw(const Point& p)
41 41
         internalDraw(p, b);
42 42
 }
43 43
 
44
-void Item::setPosition(const Position& position)
44
+void Item::setPos(const Position& position)
45 45
 {
46 46
     if(m_type->properties[ThingType::IsGround]) {
47 47
         m_xPattern = position.x % m_type->dimensions[ThingType::PatternX];
@@ -49,7 +49,7 @@ void Item::setPosition(const Position& position)
49 49
         m_zPattern = position.z % m_type->dimensions[ThingType::PatternZ];
50 50
     }
51 51
 
52
-    Thing::setPosition(position);
52
+    Thing::setPos(position);
53 53
 }
54 54
 
55 55
 void Item::setData(int data)

+ 1
- 1
src/otclient/core/item.h View File

@@ -37,7 +37,7 @@ public:
37 37
 
38 38
     void draw(const Point& p);
39 39
 
40
-    void setPosition(const Position &position);
40
+    void setPos(const Position &position);
41 41
     void setData(int data);
42 42
 
43 43
     int getData() { return m_data; }

+ 3
- 3
src/otclient/core/localplayer.cpp View File

@@ -35,7 +35,7 @@ void LocalPlayer::clientWalk(Otc::Direction direction)
35 35
 {
36 36
     // We're not walking, so start a client walk.
37 37
     if(!m_walking) {
38
-        Position newPos = m_position + Position::getPositionFromDirection(direction);
38
+        Position newPos = m_position + Position::getPosFromDirection(direction);
39 39
         Creature::walk(newPos, false);
40 40
         m_clientWalking = true;
41 41
     }
@@ -49,7 +49,7 @@ void LocalPlayer::walk(const Position& position, bool inverse)
49 49
     if(m_clientWalking) {
50 50
         m_clientWalking = false;
51 51
 
52
-        Position pos = Position::getPositionFromDirection(m_direction);
52
+        Position pos = Position::getPosFromDirection(m_direction);
53 53
         Point walkOffset = Point(m_walkOffset.x - pos.x * 32,
54 54
                                  m_walkOffset.y - pos.y * 32);
55 55
 
@@ -97,7 +97,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
97 97
         return false;
98 98
     }
99 99
 
100
-    Position newPos = m_position + Position::getPositionFromDirection(direction);
100
+    Position newPos = m_position + Position::getPosFromDirection(direction);
101 101
     TilePtr tile = g_map.getTile(newPos);
102 102
     if(!tile->isWalkable()) {
103 103
         // TODO: create enum for 17, white message on screen bottom and console.

+ 10
- 10
src/otclient/core/map.cpp View File

@@ -88,7 +88,7 @@ void Map::draw(const Rect& rect)
88 88
 
89 89
         // after drawing all tiles, draw shots
90 90
         for(const MissilePtr& shot : m_missilesAtFloor[iz]) {
91
-            Position missilePos = shot->getPosition();
91
+            Position missilePos = shot->getPos();
92 92
             shot->draw(positionTo2D(missilePos) - m_drawOffset);
93 93
         }
94 94
     }
@@ -132,7 +132,7 @@ void Map::draw(const Rect& rect)
132 132
 
133 133
     // draw animated text
134 134
     for(auto it = m_animatedTexts.begin(), end = m_animatedTexts.end(); it != end; ++it) {
135
-        Point pos = positionTo2D((*it)->getPosition()) - m_drawOffset;
135
+        Point pos = positionTo2D((*it)->getPos()) - m_drawOffset;
136 136
         pos.x *= horizontalStretchFactor;
137 137
         pos.y *= verticalStretchFactor;
138 138
         (*it)->draw(rect.topLeft() + pos);
@@ -140,7 +140,7 @@ void Map::draw(const Rect& rect)
140 140
 
141 141
     // draw static text
142 142
     for(auto it = m_staticTexts.begin(), end = m_staticTexts.end(); it != end; ++it) {
143
-        Point pos = positionTo2D((*it)->getPosition()) - m_drawOffset;
143
+        Point pos = positionTo2D((*it)->getPos()) - m_drawOffset;
144 144
         pos.x *= horizontalStretchFactor;
145 145
         pos.y *= verticalStretchFactor;
146 146
         (*it)->draw(rect.topLeft() + pos);
@@ -246,7 +246,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
246 246
         m_creatures[creature->getId()] = creature;
247 247
     }
248 248
     else if(MissilePtr shot = thing->asMissile()) {
249
-        m_missilesAtFloor[shot->getPosition().z].push_back(shot);
249
+        m_missilesAtFloor[shot->getPos().z].push_back(shot);
250 250
     }
251 251
     else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) {
252 252
         m_animatedTexts.push_back(animatedText);
@@ -255,7 +255,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
255 255
         bool mustAdd = true;
256 256
         for(auto it = m_staticTexts.begin(), end = m_staticTexts.end(); it != end; ++it) {
257 257
             StaticTextPtr cStaticText = *it;
258
-            if(cStaticText->getPosition() == pos) {
258
+            if(cStaticText->getPos() == pos) {
259 259
                 // try to combine messages
260 260
                 if(cStaticText->addMessage(staticText->getName(), staticText->getMessageType(), staticText->getFirstMessage())) {
261 261
                     mustAdd = false;
@@ -276,7 +276,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
276 276
     }
277 277
 
278 278
     thing->start();
279
-    thing->setPosition(pos);
279
+    thing->setPos(pos);
280 280
 }
281 281
 
282 282
 ThingPtr Map::getThing(const Position& pos, int stackPos)
@@ -298,9 +298,9 @@ void Map::removeThing(const ThingPtr& thing)
298 298
         return;
299 299
 
300 300
     if(MissilePtr shot = thing->asMissile()) {
301
-        auto it = std::find(m_missilesAtFloor[shot->getPosition().z].begin(), m_missilesAtFloor[shot->getPosition().z].end(), shot);
302
-        if(it != m_missilesAtFloor[shot->getPosition().z].end()) {
303
-            m_missilesAtFloor[shot->getPosition().z].erase(it);
301
+        auto it = std::find(m_missilesAtFloor[shot->getPos().z].begin(), m_missilesAtFloor[shot->getPos().z].end(), shot);
302
+        if(it != m_missilesAtFloor[shot->getPos().z].end()) {
303
+            m_missilesAtFloor[shot->getPos().z].erase(it);
304 304
         }
305 305
         return;
306 306
     }
@@ -317,7 +317,7 @@ void Map::removeThing(const ThingPtr& thing)
317 317
         return;
318 318
     }
319 319
 
320
-    if(TilePtr& tile = m_tiles[thing->getPosition()])
320
+    if(TilePtr& tile = m_tiles[thing->getPos()])
321 321
         tile->removeThing(thing);
322 322
 }
323 323
 

+ 2
- 2
src/otclient/core/thing.h View File

@@ -44,10 +44,10 @@ public:
44 44
     virtual void draw(const Point& p) = 0;
45 45
 
46 46
     void setId(int id);
47
-    virtual void setPosition(const Position& position) { m_position = position; }
47
+    virtual void setPos(const Position& position) { m_position = position; }
48 48
 
49 49
     int getId() const { return m_id; }
50
-    Position getPosition() const { return m_position; }
50
+    Position getPos() const { return m_position; }
51 51
     int getStackPriority();
52 52
     virtual ThingType *getType();
53 53
     int getAnimationPhases() { return m_type->dimensions[ThingType::AnimationPhases]; }

+ 1
- 1
src/otclient/core/tile.h View File

@@ -44,7 +44,7 @@ public:
44 44
     ThingPtr removeThing(int stackPos);
45 45
     ThingPtr removeThing(const ThingPtr& thing);
46 46
 
47
-    const Position& getPosition() { return m_position; }
47
+    const Position& getPos() { return m_position; }
48 48
     int getDrawElevation() { return m_drawElevation; }
49 49
     std::vector<CreaturePtr> getCreatures();
50 50
     ItemPtr getGround();

+ 2
- 2
src/otclient/net/protocolgameparse.cpp View File

@@ -535,7 +535,7 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg)
535 535
 
536 536
     EffectPtr effect = EffectPtr(new Effect());
537 537
     effect->setId(effectId);
538
-    effect->setPosition(pos);
538
+    effect->setPos(pos);
539 539
 
540 540
     g_map.addThing(effect, pos);
541 541
 }
@@ -547,7 +547,7 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg)
547 547
     std::string text = msg.getString();
548 548
 
549 549
     AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
550
-    animatedText->setPosition(position);
550
+    animatedText->setPos(position);
551 551
     animatedText->setColor(color);
552 552
     animatedText->setText(text);
553 553
 

+ 2
- 2
src/otclient/ui/uicreature.cpp View File

@@ -41,12 +41,12 @@ void UICreature::render()
41 41
     renderChildren();
42 42
 }
43 43
 
44
-void UICreature::onStyleApply(const OTMLNodePtr& styleNode)
44
+void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
45 45
 {
46 46
     for(OTMLNodePtr node : styleNode->children()) {
47 47
         if(node->tag() == "creature-margin")
48 48
             m_creatureMargin = node->value<int>();
49 49
     }
50 50
 
51
-    UIWidget::onStyleApply(styleNode);
51
+    UIWidget::onStyleApply(styleName, styleNode);
52 52
 }

+ 1
- 1
src/otclient/ui/uicreature.h View File

@@ -38,7 +38,7 @@ public:
38 38
     CreaturePtr getCreature() { return m_creature; }
39 39
 
40 40
 protected:
41
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
41
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
42 42
 
43 43
 private:
44 44
     CreaturePtr m_creature;

+ 2
- 2
src/otclient/ui/uiitem.cpp View File

@@ -41,12 +41,12 @@ void UIItem::render()
41 41
     renderChildren();
42 42
 }
43 43
 
44
-void UIItem::onStyleApply(const OTMLNodePtr& styleNode)
44
+void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
45 45
 {
46 46
     for(OTMLNodePtr node : styleNode->children()) {
47 47
         if(node->tag() == "item margin")
48 48
             m_itemMargin = node->value<int>();
49 49
     }
50 50
 
51
-    UIWidget::onStyleApply(styleNode);
51
+    UIWidget::onStyleApply(styleName, styleNode);
52 52
 }

+ 1
- 1
src/otclient/ui/uiitem.h View File

@@ -37,7 +37,7 @@ public:
37 37
     ItemPtr getItem() { return m_item; }
38 38
 
39 39
 protected:
40
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
40
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
41 41
 
42 42
 private:
43 43
     ItemPtr m_item;

+ 2
- 2
src/otclient/ui/uimap.cpp View File

@@ -46,14 +46,14 @@ void UIMap::render()
46 46
     renderChildren();
47 47
 }
48 48
 
49
-void UIMap::onStyleApply(const OTMLNodePtr& styleNode)
49
+void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
50 50
 {
51 51
     for(OTMLNodePtr node : styleNode->children()) {
52 52
         if(node->tag() == "map margin")
53 53
             m_mapMargin = node->value<int>();
54 54
     }
55 55
 
56
-    UIWidget::onStyleApply(styleNode);
56
+    UIWidget::onStyleApply(styleName, styleNode);
57 57
 }
58 58
 
59 59
 bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)

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

@@ -33,7 +33,7 @@ public:
33 33
     void render();
34 34
 
35 35
 protected:
36
-    virtual void onStyleApply(const OTMLNodePtr& styleNode);
36
+    virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
37 37
     virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
38 38
     virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
39 39
 

+ 1
- 1
src/otclient/util/position.h View File

@@ -33,7 +33,7 @@ public:
33 33
     Position() : x(-1), y(-1), z(-1) { }
34 34
     Position(int x, int y, int z) : x(x), y(y), z(z) { }
35 35
 
36
-    static Position getPositionFromDirection(Otc::Direction direction) {
36
+    static Position getPosFromDirection(Otc::Direction direction) {
37 37
         switch(direction) {
38 38
         case Otc::North:
39 39
             return Position( 0, -1, 0);

+ 0
- 138
tools/katepart-syntax/lua.xml View File

@@ -136,142 +136,6 @@
136 136
       <item> displayUI </item>
137 137
       <item> createWidget </item>
138 138
     </list>
139
-    <list name="otclient-core-constants">
140
-      <item> AnchorNone </item>
141
-      <item> AnchorTop </item>
142
-      <item> AnchorBottom </item>
143
-      <item> AnchorLeft </item>
144
-      <item> AnchorRight </item>
145
-      <item> AnchorVerticalCenter </item>
146
-      <item> AnchorHorizontalCenter </item>
147
-
148
-      <item> LogDebug </item>
149
-      <item> LogInfo </item>
150
-      <item> LogWarning </item>
151
-      <item> LogError </item>
152
-      <item> LogFatal </item>
153
-
154
-      <item> ActiveFocusReason </item>
155
-
156
-      <item> KeyUnknown </item>
157
-      <item> KeyEscape </item>
158
-      <item> KeyTab </item>
159
-      <item> KeyBackspace </item>
160
-      <item> KeyReturn </item>
161
-      <item> KeyEnter </item>
162
-      <item> KeyInsert </item>
163
-      <item> KeyDelete </item>
164
-      <item> KeyPause </item>
165
-      <item> KeyPrintScreen </item>
166
-      <item> KeyHome </item>
167
-      <item> KeyEnd </item>
168
-      <item> KeyPageUp </item>
169
-      <item> KeyPageDown </item>
170
-      <item> KeyUp </item>
171
-      <item> KeyDown </item>
172
-      <item> KeyLeft </item>
173
-      <item> KeyRight </item>
174
-      <item> KeyNumLock </item>
175
-      <item> KeyScrollLock </item>
176
-      <item> KeyCapsLock </item>
177
-      <item> KeyCtrl </item>
178
-      <item> KeyShift </item>
179
-      <item> KeyAlt </item>
180
-      <item> KeyAltGr </item>
181
-      <item> KeyMeta </item>
182
-      <item> KeyMenu </item>
183
-      <item> KeySpace </item>
184
-      <item> KeyExclamation </item>
185
-      <item> KeyQuote </item>
186
-      <item> KeyNumberSign </item>
187
-      <item> KeyDollar </item>
188
-      <item> KeyPercent </item>
189
-      <item> KeyAmpersand </item>
190
-      <item> KeyApostrophe </item>
191
-      <item> KeyLeftParen </item>
192
-      <item> KeyRightParen </item>
193
-      <item> KeyAsterisk </item>
194
-      <item> KeyPlus </item>
195
-      <item> KeyComma </item>
196
-      <item> KeyMinus </item>
197
-      <item> KeyPeriod </item>
198
-      <item> KeySlash </item>
199
-      <item> Key0 </item>
200
-      <item> Key1 </item>
201
-      <item> Key2 </item>
202
-      <item> Key3 </item>
203
-      <item> Key4 </item>
204
-      <item> Key5 </item>
205
-      <item> Key6 </item>
206
-      <item> Key7 </item>
207
-      <item> Key8 </item>
208
-      <item> Key9 </item>
209
-      <item> KeyColon </item>
210
-      <item> KeySemicolon </item>
211
-      <item> KeyLess </item>
212
-      <item> KeyEqual </item>
213
-      <item> KeyGreater </item>
214
-      <item> KeyQuestion </item>
215
-      <item> KeyAtSign </item>
216
-      <item> KeyA </item>
217
-      <item> KeyB </item>
218
-      <item> KeyC </item>
219
-      <item> KeyD </item>
220
-      <item> KeyE </item>
221
-      <item> KeyF </item>
222
-      <item> KeyG </item>
223
-      <item> KeyH </item>
224
-      <item> KeyI </item>
225
-      <item> KeyJ </item>
226
-      <item> KeyK </item>
227
-      <item> KeyL </item>
228
-      <item> KeyM </item>
229
-      <item> KeyN </item>
230
-      <item> KeyO </item>
231
-      <item> KeyP </item>
232
-      <item> KeyQ </item>
233
-      <item> KeyR </item>
234
-      <item> KeyS </item>
235
-      <item> KeyT </item>
236
-      <item> KeyU </item>
237
-      <item> KeyV </item>
238
-      <item> KeyW </item>
239
-      <item> KeyX </item>
240
-      <item> KeyY </item>
241
-      <item> KeyZ </item>
242
-      <item> KeyLeftBracket </item>
243
-      <item> KeyBackslash </item>
244
-      <item> KeyRightBracket </item>
245
-      <item> KeyCaret </item>
246
-      <item> KeyUnderscore </item>
247
-      <item> KeyGrave </item>
248
-      <item> KeyLeftCurly </item>
249
-      <item> KeyBar </item>
250
-      <item> KeyRightCurly </item>
251
-      <item> KeyTilde </item>
252
-      <item> KeyF1 </item>
253
-      <item> KeyF2 </item>
254
-      <item> KeyF3 </item>
255
-      <item> KeyF4 </item>
256
-      <item> KeyF5 </item>
257
-      <item> KeyF6 </item>
258
-      <item> KeyF7 </item>
259
-      <item> KeyF8 </item>
260
-      <item> KeyF9 </item>
261
-      <item> KeyF10 </item>
262
-      <item> KeyF11 </item>
263
-      <item> KeyF12 </item>
264
-
265
-      <item> KeyboardNoModifier </item>
266
-      <item> KeyboardCtrlModifier </item>
267
-      <item> KeyboardAltModifier </item>
268
-      <item> KeyboardShiftModifier </item>
269
-
270
-      <item> MouseNoButton </item>
271
-      <item> MouseLeftButton </item>
272
-      <item> MouseRightButton </item>
273
-      <item> MouseMidButton </item>
274
-    </list>
275 139
     <list name="attention">
276 140
       <item> TODO </item>
277 141
       <item> FIXME </item>
@@ -302,7 +166,6 @@
302 166
         <RegExpr      attribute="Keyword"  context="#stay" beginRegion="chunk" String="\bfunction\b" />
303 167
         <keyword      attribute="Keyword"  context="#stay" String="keywords" />
304 168
         <keyword      attribute="Keyword"  context="#stay"  String="pseudo-variables" />
305
-        <keyword      attribute="Otclient Core Const"  context="#stay"  String="otclient-core-constants" />
306 169
         <RegExpr      attribute="Keyword"  context="#stay" endRegion="chunk"   beginRegion="chunk" String="\belse\b" />
307 170
         <RegExpr      attribute="Keyword"  context="#stay" endRegion="chunk"   beginRegion="chunk" String="\belseif\b" />
308 171
         <RegExpr      attribute="Keyword"  context="#stay" beginRegion="chunk" String="\bdo\b" />
@@ -358,7 +221,6 @@
358 221
       <itemData name="Lua Base Func"          defStyleNum="dsNormal"  color="#0057AE"/>
359 222
       <itemData name="Otclient Core Func"     defStyleNum="dsKeyword" color="#0057AE"/>
360 223
       <itemData name="Const"                  defStyleNum="dsNormal" color="#a800ff"/>
361
-      <itemData name="Otclient Core Const"    defStyleNum="dsNormal" color="#a42a38"/>
362 224
       <itemData name="Global Class"           defStyleNum="dsKeyword" color="#006E28"/>
363 225
       <itemData name="Keyword"                defStyleNum="dsKeyword"/>
364 226
       <itemData name="Error"                  defStyleNum="dsError"/>

Loading…
Cancel
Save