Browse Source

add style for colorbox in outfit window

Eduardo Bart 9 years ago
parent
commit
ba62863ff7

+ 1
- 1
README.rdoc View File

@@ -17,7 +17,7 @@ Checkout our website at {http://otclient.info}[http://otclient.info/] for tutori
17 17
 == Need help?
18 18
 
19 19
 If you have any questions or are looking for more information, please feel free to ask on our official
20
-forum at http://otclient.info/
20
+forum at http://otclient.info
21 21
 
22 22
 == Bugs
23 23
 

BIN
modules/core_styles/images/colorbox.png View File


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

@@ -30,4 +30,19 @@ CheckBox < UICheckBox
30 30
 
31 31
   $disabled:
32 32
     background-color: #ffffff88
33
-    color: #aaaaaa88
33
+    color: #aaaaaa88
34
+
35
+ColorBox < UICheckBox
36
+  size: 16 16
37
+  box-size: 16 16
38
+  background-color: #ffffffff
39
+
40
+  $checked:
41
+    image:
42
+      source: /core_styles/images/colorbox.png
43
+      coords: 16 0 16 16
44
+
45
+  $!checked:
46
+    image:
47
+      source: /core_styles/images/colorbox.png
48
+      coords: 0 0 16 16

+ 17
- 17
modules/outfit/outfit.lua View File

@@ -9,10 +9,10 @@ local currentOutfit = 1
9 9
 local function update()
10 10
   local creatureWidget = window:getChildById('creature')
11 11
   creatureWidget:setOutfitType(outfits[currentOutfit][1])
12
-  
12
+
13 13
   local nameWidget = window:getChildById('name')
14 14
   nameWidget:setText(outfits[currentOutfit][2])
15
-  
15
+
16 16
   local availableAddons = outfits[currentOutfit][3]
17 17
   local addon1 = window:getChildById('addon1')
18 18
   local addon2 = window:getChildById('addon2')
@@ -20,7 +20,7 @@ local function update()
20 20
   addon1:setChecked(false)
21 21
   addon2:setChecked(false)
22 22
   addon3:setChecked(false)
23
-  
23
+
24 24
   -- Maybe rework this someday
25 25
   if availableAddons == 1 then
26 26
     addon1:setChecked(true)
@@ -42,7 +42,7 @@ local function update()
42 42
     addon2:setChecked(true)
43 43
     addon3:setChecked(true)
44 44
   end
45
-  
45
+
46 46
 end
47 47
 
48 48
 -- public functions
@@ -61,28 +61,28 @@ function Outfit.create(creature, outfitList)
61 61
   Outfit.destroy()
62 62
   window = loadUI("/outfit/outfit.otui", UI.root)
63 63
   window:lock()
64
-  
64
+
65 65
   local creatureWidget = window:getChildById('creature')
66 66
   creatureWidget:setCreature(creature)
67
-  
67
+
68 68
   local firstColor = UIWidget.create()
69 69
   window:addChild(firstColor)
70 70
   firstColor:setStyle('ColorFirst')
71
-  
71
+
72 72
   for i=0,18 do
73 73
     for j=0,6 do
74 74
       local color = UICheckBox.create()
75 75
       window:addChild(color)
76
-      
76
+
77 77
       local outfitColor = getOufitColor(j*19 + i)
78
-      
78
+
79 79
       color:setStyle('Color')
80 80
       color:setBackgroundColor(outfitColor)
81
-      color:setMarginTop(j * 3 + j * 12)
82
-      color:setMarginLeft(i * 3 + i * 12)
81
+      color:setMarginTop(j * 3 + j * 14)
82
+      color:setMarginLeft(i * 3 + i * 14)
83 83
     end
84 84
   end
85
-  
85
+
86 86
   outfits = outfitList
87 87
   currentOutfit = 1
88 88
   update()
@@ -96,14 +96,14 @@ function Outfit.destroy()
96 96
 end
97 97
 
98 98
 function Outfit.nextType()
99
-  
99
+
100 100
   currentOutfit = currentOutfit + 1
101 101
   if currentOutfit > #outfits then
102 102
     currentOutfit = 1
103 103
   end
104
-  
104
+
105 105
   update()
106
-  
106
+
107 107
 end
108 108
 
109 109
 function Outfit.previousType()
@@ -111,9 +111,9 @@ function Outfit.previousType()
111 111
   if currentOutfit <= 0 then
112 112
     currentOutfit = #outfits
113 113
   end
114
-  
114
+
115 115
   update()
116
-  
116
+
117 117
 end
118 118
 
119 119
 -- hooked events

+ 13
- 21
modules/outfit/outfit.otui View File

@@ -1,31 +1,23 @@
1
-ColorCheckBox < UICheckBox
2
-  size: 12 12
3
-  box-size: 12 12
4
-  background-color: #ffffffff
5
-  
6
-  image:
7
-    source: /core_styles/images/empty_rect.png
8
-
9 1
 ColorFirst < UIWidget
10 2
   id: color
11 3
   margin.left: 20
12 4
   anchors.top: creature.top
13 5
   anchors.left: creature.right
14
-  
15
-Color < ColorCheckBox
6
+
7
+Color < ColorBox
16 8
   anchors.top: color.top
17 9
   anchors.left: color.right
18
-  
10
+
19 11
 Window
20 12
   title: Select Outfit
21
-  size: 420 280
22
-  
13
+  size: 450 280
14
+
23 15
   anchors.horizontalCenter: parent.horizontalCenter
24 16
   anchors.verticalCenter: parent.verticalCenter
25
-  
17
+
26 18
   onEnter: Outfit.accept()
27 19
   onEscape: Outfit.destroy()
28
-  
20
+
29 21
   Label
30 22
     id: name
31 23
     text: Outfit Name
@@ -34,7 +26,7 @@ Window
34 26
     anchors.left: parent.left
35 27
     margin.top: 34
36 28
     margin.left: 20
37
-  
29
+
38 30
   Creature
39 31
     id: creature
40 32
     anchors.top: name.bottom
@@ -48,7 +40,7 @@ Window
48 40
     margin.top: 3
49 41
     anchors.top: creature.bottom
50 42
     anchors.right: creature.right
51
-    
43
+
52 44
   Button
53 45
     @onClick: Outfit.previousType()
54 46
     text: <<
@@ -56,7 +48,7 @@ Window
56 48
     margin.top: 3
57 49
     anchors.top: creature.bottom
58 50
     anchors.left: creature.left
59
-    
51
+
60 52
   CheckBox
61 53
     id: addon1
62 54
     text: Addon 1
@@ -65,7 +57,7 @@ Window
65 57
     width: 100
66 58
     anchors.top: prev.bottom
67 59
     anchors.left: prev.left
68
-    
60
+
69 61
   CheckBox
70 62
     id: addon2
71 63
     text: Addon 2
@@ -74,7 +66,7 @@ Window
74 66
     width: 100
75 67
     anchors.top: prev.bottom
76 68
     anchors.left: prev.left
77
-    
69
+
78 70
   CheckBox
79 71
     id: addon3
80 72
     text: Addon 3
@@ -83,7 +75,7 @@ Window
83 75
     width: 100
84 76
     anchors.top: prev.bottom
85 77
     anchors.left: prev.left
86
-  
78
+
87 79
   HorizontalSeparator
88 80
     anchors.left: parent.left
89 81
     anchors.right: parent.right

+ 7
- 6
src/framework/luascript/luavaluecasts.cpp View File

@@ -163,13 +163,14 @@ bool luavalue_cast(int index, Rect& rect)
163 163
         rect.setWidth(g_lua.popInteger());
164 164
         g_lua.getField("height", index);
165 165
         rect.setHeight(g_lua.popInteger());
166
+        return true;
166 167
     } else if(g_lua.isString()) {
167 168
         return Fw::cast(g_lua.toString(index), rect);
168 169
     } else if(g_lua.isNil()) {
169 170
         rect = Rect();
170 171
         return true;
171 172
     }
172
-    return true;
173
+    return false;
173 174
 }
174 175
 
175 176
 // point
@@ -196,7 +197,7 @@ bool luavalue_cast(int index, Point& point)
196 197
         point = Point();
197 198
         return true;
198 199
     }
199
-    return true;
200
+    return false;
200 201
 }
201 202
 
202 203
 // size
@@ -223,7 +224,7 @@ bool luavalue_cast(int index, Size& size)
223 224
         size = Size();
224 225
         return true;
225 226
     }
226
-    return true;
227
+    return false;
227 228
 }
228 229
 
229 230
 // otml nodes
@@ -270,9 +271,9 @@ bool luavalue_cast(int index, OTMLNodePtr& node)
270 271
                 node->writeAt(cnodeName, g_lua.toString());
271 272
             g_lua.pop();
272 273
         }
273
-    } else
274
-        return false;
275
-    return true;
274
+        return true;
275
+    }
276
+    return false;
276 277
 }
277 278
 
278 279
 // object ptr

+ 12
- 1
src/framework/ui/uicheckbox.cpp View File

@@ -48,7 +48,7 @@ void UICheckBox::render()
48 48
 void UICheckBox::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
49 49
 {
50 50
     if(isPressed() && getRect().contains(mousePos))
51
-        setState(Fw::CheckedState, !isChecked());
51
+        setChecked(!isChecked());
52 52
 }
53 53
 
54 54
 void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode)
@@ -68,3 +68,14 @@ void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode)
68 68
         }
69 69
     }
70 70
 }
71
+
72
+bool UICheckBox::isChecked()
73
+{
74
+    return hasState(Fw::CheckedState);
75
+}
76
+
77
+void UICheckBox::setChecked(bool checked)
78
+{
79
+    if(setState(Fw::CheckedState, checked))
80
+        callLuaField("onCheckChange", checked);
81
+}

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

@@ -30,8 +30,8 @@ class UICheckBox : public UIWidget
30 30
 public:
31 31
     void render();
32 32
 
33
-    bool isChecked() { return hasState(Fw::CheckedState); }
34
-    void setChecked(bool checked) { setState(Fw::CheckedState, checked); }
33
+    bool isChecked();
34
+    void setChecked(bool checked);
35 35
 
36 36
     void setText(const std::string& text) { m_text = text; }
37 37
     std::string getText() { return m_text; }

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

@@ -615,10 +615,10 @@ void UIWidget::updateLayout()
615 615
         m_layout->update();
616 616
 }
617 617
 
618
-void UIWidget::setState(Fw::WidgetState state, bool on)
618
+bool UIWidget::setState(Fw::WidgetState state, bool on)
619 619
 {
620 620
     if(state == Fw::InvalidState)
621
-        return;
621
+        return false;
622 622
 
623 623
     int oldStates = m_states;
624 624
     if(on)
@@ -626,8 +626,11 @@ void UIWidget::setState(Fw::WidgetState state, bool on)
626 626
     else
627 627
         m_states &= ~state;
628 628
 
629
-    if(oldStates != m_states)
629
+    if(oldStates != m_states) {
630 630
         updateStyle();
631
+        return true;
632
+    }
633
+    return false;
631 634
 }
632 635
 
633 636
 bool UIWidget::hasState(Fw::WidgetState state)
@@ -700,9 +703,7 @@ void UIWidget::updateState(Fw::WidgetState state)
700 703
             child->updateState(state);
701 704
     }
702 705
 
703
-    if(newStatus != oldStatus) {
704
-        setState(state, newStatus);
705
-
706
+    if(setState(state, newStatus)) {
706 707
         if(state == Fw::FocusState) {
707 708
             g_dispatcher.addEvent(std::bind(&UIWidget::onFocusChange, asUIWidget(), newStatus, m_lastFocusReason));
708 709
         } else if(state == Fw::HoverState)

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

@@ -149,7 +149,7 @@ public:
149 149
 
150 150
     void updateStates();
151 151
     virtual void updateState(Fw::WidgetState state);
152
-    void setState(Fw::WidgetState state, bool on);
152
+    bool setState(Fw::WidgetState state, bool on);
153 153
     bool hasState(Fw::WidgetState state);
154 154
 
155 155
     void updateStyle();

+ 40
- 0
src/otclient/otclientluafunctions.cpp View File

@@ -39,6 +39,9 @@
39 39
 #include <otclient/ui/uimap.h>
40 40
 #include <otclient/core/outfit.h>
41 41
 
42
+void push_luavalue(const Outfit& outfit);
43
+bool luavalue_cast(int index, Outfit& outfit);
44
+
42 45
 void OTClient::registerLuaFunctions()
43 46
 {
44 47
     g_lua.bindGlobalFunction("exit", std::bind(&OTClient::exit, &g_client));
@@ -90,3 +93,40 @@ void OTClient::registerLuaFunctions()
90 93
     g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
91 94
 #endif
92 95
 }
96
+
97
+void push_luavalue(const Outfit& outfit)
98
+{
99
+    g_lua.newTable();
100
+    g_lua.pushInteger(outfit.getType());
101
+    g_lua.setField("type");
102
+    g_lua.pushInteger(outfit.getAddons());
103
+    g_lua.setField("addons");
104
+    g_lua.pushInteger(outfit.getHead());
105
+    g_lua.setField("head");
106
+    g_lua.pushInteger(outfit.getBody());
107
+    g_lua.setField("body");
108
+    g_lua.pushInteger(outfit.getLegs());
109
+    g_lua.setField("legs");
110
+    g_lua.pushInteger(outfit.getFeet());
111
+    g_lua.setField("feet");
112
+}
113
+
114
+bool luavalue_cast(int index, Outfit& outfit)
115
+{
116
+    if(g_lua.isTable(index)) {
117
+        g_lua.getField("type", index);
118
+        outfit.setType(g_lua.popInteger());
119
+        g_lua.getField("addons", index);
120
+        outfit.setAddons(g_lua.popInteger());
121
+        g_lua.getField("head", index);
122
+        outfit.setHead(g_lua.popInteger());
123
+        g_lua.getField("body", index);
124
+        outfit.setBody(g_lua.popInteger());
125
+        g_lua.getField("legs", index);
126
+        outfit.setLegs(g_lua.popInteger());
127
+        g_lua.getField("feet", index);
128
+        outfit.setFeet(g_lua.popInteger());
129
+        return true;
130
+    }
131
+    return false;
132
+}

Loading…
Cancel
Save