Skip to content

Commit ae59785

Browse files
committed
issue #4174 add richText
1 parent 92e7b92 commit ae59785

File tree

8 files changed

+448
-1
lines changed

8 files changed

+448
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/****************************************************************************
2+
Copyright (c) 2013 cocos2d-x.org
3+
4+
http://www.cocos2d-x.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
****************************************************************************/
24+
25+
var UIRichTextTest = UIScene.extend({
26+
_richText:null,
27+
init: function () {
28+
if (this._super()) {
29+
//init text
30+
this._topDisplayLabel.setText("");
31+
this._bottomDisplayLabel.setText("RichText");
32+
33+
var widgetSize = this._widget.getSize();
34+
var button = ccs.Button.create();
35+
button.setTouchEnabled(true);
36+
button.loadTextures("res/cocosgui/animationbuttonnormal.png", "res/cocosgui/animationbuttonpressed.png", "");
37+
button.setTitleText("switch");
38+
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getSize().height * 2.5));
39+
button.addTouchEventListener(this.touchEvent,this);
40+
this._uiLayer.addWidget(button);
41+
42+
43+
// RichText
44+
var richText = ccs.RichText.create();
45+
richText.ignoreContentAdaptWithSize(false);
46+
richText.setSize(cc.size(120, 100));
47+
48+
var re1 = ccs.RichElementText.create(1, cc.white(), 255, "This color is white. ", "Helvetica", 10);
49+
var re2 = ccs.RichElementText.create(2, cc.yellow(), 255, "And this is yellow. ", "Helvetica", 10);
50+
var re3 = ccs.RichElementText.create(3, cc.blue(), 255, "This one is blue. ", "Helvetica", 10);
51+
var re4 = ccs.RichElementText.create(4, cc.green(), 255, "And green. ", "Helvetica", 10);
52+
var re5 = ccs.RichElementText.create(5, cc.red(), 255, "Last one is red ", "Helvetica", 10);
53+
54+
var reimg = ccs.RichElementImage.create(6,cc.white(), 255, "res/cocosgui/sliderballnormal.png");
55+
56+
ccs.ArmatureDataManager.getInstance().addArmatureFileInfo("res/cocosgui/100/100.ExportJson");
57+
var pAr = ccs.Armature.create("100");
58+
pAr.getAnimation().play("Animation1");
59+
60+
var recustom = ccs.RichElementCustomNode.create(1, cc.white(), 255, pAr);
61+
var re6 = ccs.RichElementText.create(7, cc.orange(), 255, "Have fun!! ", "Helvetica", 10);
62+
richText.pushBackElement(re1);
63+
richText.insertElement(re2, 1);
64+
richText.pushBackElement(re3);
65+
richText.pushBackElement(re4);
66+
richText.pushBackElement(re5);
67+
richText.insertElement(reimg, 2);
68+
richText.pushBackElement(recustom);
69+
richText.pushBackElement(re6);
70+
71+
richText.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2));
72+
73+
this._uiLayer.addWidget(richText);
74+
this._richText = richText;
75+
return true;
76+
}
77+
return false;
78+
},
79+
touchEvent: function (sender, type) {
80+
if (type == ccs.TouchEventType.ended) {
81+
if (this._richText.isIgnoreContentAdaptWithSize()) {
82+
this._richText.ignoreContentAdaptWithSize(false);
83+
this._richText.setSize(cc.size(120, 100));
84+
}
85+
else {
86+
this._richText.ignoreContentAdaptWithSize(true);
87+
}
88+
}
89+
}
90+
});

tests/CocoStudioTest/GUITest/UIScene.js

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ UIScene = cc.Layer.extend({
7979
uiLabel.setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0 - uiLabel.getSize().height * 1.75));
8080
this._uiLayer.addWidget(uiLabel);
8181
this._bottomDisplayLabel = uiLabel;
82-
8382
return true;
8483
}
8584
return false;

tests/CocoStudioTest/GUITest/UISceneManager.js

+6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ var s_testArray = [
237237
func: function () {
238238
return new UIWidgetAddNodeTest();
239239
}
240+
},
241+
{
242+
title: "UIRichTextTest",
243+
func: function () {
244+
return new UIRichTextTest();
245+
}
240246
}
241247
];
242248
UISceneManager = cc.Class.extend({

tests/res/cocosgui/100/100.ExportJson

+283
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
{
2+
"content_scale": 1.0,
3+
"armature_data": [
4+
{
5+
"strVersion": "1.3.0.0",
6+
"version": 1.3,
7+
"name": "100",
8+
"bone_data": [
9+
{
10+
"name": "Layer7",
11+
"parent": "",
12+
"x": 0.0,
13+
"y": 0.0,
14+
"z": 1,
15+
"cX": 1.0,
16+
"cY": 1.0,
17+
"kX": 0.0,
18+
"kY": 0.0,
19+
"arrow_x": 0.0,
20+
"arrow_y": 0.0,
21+
"effectbyskeleton": false,
22+
"display_data": [
23+
{
24+
"name": "aaa.png",
25+
"displayType": 0,
26+
"skin_data": [
27+
{
28+
"x": 0.0,
29+
"y": 0.0,
30+
"cX": 1.0,
31+
"cY": 1.0,
32+
"kX": 0.0,
33+
"kY": 0.0
34+
}
35+
]
36+
},
37+
{
38+
"name": "bbb.png",
39+
"displayType": 0,
40+
"skin_data": [
41+
{
42+
"x": 0.0,
43+
"y": 0.0,
44+
"cX": 1.0,
45+
"cY": 1.0,
46+
"kX": 0.0,
47+
"kY": 0.0
48+
}
49+
]
50+
}
51+
]
52+
}
53+
]
54+
}
55+
],
56+
"animation_data": [
57+
{
58+
"name": "100",
59+
"mov_data": [
60+
{
61+
"name": "Animation1",
62+
"dr": 66,
63+
"lp": true,
64+
"to": 0,
65+
"drTW": 0,
66+
"twE": 0,
67+
"sc": 1.0,
68+
"mov_bone_data": [
69+
{
70+
"name": "Layer7",
71+
"dl": 0.0,
72+
"frame_data": [
73+
{
74+
"dI": 0,
75+
"x": 0.0,
76+
"y": 0.0,
77+
"z": 0,
78+
"cX": 1.0,
79+
"cY": 1.0,
80+
"kX": 0.0,
81+
"kY": 0.0,
82+
"fi": 0,
83+
"twE": 0,
84+
"tweenFrame": true
85+
},
86+
{
87+
"dI": 1,
88+
"x": 0.0,
89+
"y": 0.0,
90+
"z": 0,
91+
"cX": 1.0,
92+
"cY": 1.0,
93+
"kX": 0.0,
94+
"kY": 0.0,
95+
"fi": 5,
96+
"twE": 0,
97+
"tweenFrame": true
98+
},
99+
{
100+
"dI": 0,
101+
"x": 0.0,
102+
"y": 0.0,
103+
"z": 0,
104+
"cX": 1.0,
105+
"cY": 1.0,
106+
"kX": 0.0,
107+
"kY": 0.0,
108+
"fi": 10,
109+
"twE": 0,
110+
"tweenFrame": true
111+
},
112+
{
113+
"dI": 1,
114+
"x": 0.0,
115+
"y": 0.0,
116+
"z": 0,
117+
"cX": 1.0,
118+
"cY": 1.0,
119+
"kX": 0.0,
120+
"kY": 0.0,
121+
"fi": 15,
122+
"twE": 0,
123+
"tweenFrame": true
124+
},
125+
{
126+
"dI": 0,
127+
"x": 0.0,
128+
"y": 0.0,
129+
"z": 0,
130+
"cX": 1.0,
131+
"cY": 1.0,
132+
"kX": 0.0,
133+
"kY": 0.0,
134+
"fi": 20,
135+
"twE": 0,
136+
"tweenFrame": true
137+
},
138+
{
139+
"dI": 1,
140+
"x": 0.0,
141+
"y": 0.0,
142+
"z": 0,
143+
"cX": 1.0,
144+
"cY": 1.0,
145+
"kX": 0.0,
146+
"kY": 0.0,
147+
"fi": 25,
148+
"twE": 0,
149+
"tweenFrame": true
150+
},
151+
{
152+
"dI": 0,
153+
"x": 0.0,
154+
"y": 0.0,
155+
"z": 0,
156+
"cX": 1.0,
157+
"cY": 1.0,
158+
"kX": 0.0,
159+
"kY": 0.0,
160+
"fi": 30,
161+
"twE": 0,
162+
"tweenFrame": true
163+
},
164+
{
165+
"dI": 1,
166+
"x": 0.0,
167+
"y": 0.0,
168+
"z": 0,
169+
"cX": 1.0,
170+
"cY": 1.0,
171+
"kX": 0.0,
172+
"kY": 0.0,
173+
"fi": 35,
174+
"twE": 0,
175+
"tweenFrame": true
176+
},
177+
{
178+
"dI": 0,
179+
"x": 0.0,
180+
"y": 0.0,
181+
"z": 0,
182+
"cX": 1.0,
183+
"cY": 1.0,
184+
"kX": 0.0,
185+
"kY": 0.0,
186+
"fi": 40,
187+
"twE": 0,
188+
"tweenFrame": true
189+
},
190+
{
191+
"dI": 1,
192+
"x": 0.0,
193+
"y": 0.0,
194+
"z": 0,
195+
"cX": 1.0,
196+
"cY": 1.0,
197+
"kX": 0.0,
198+
"kY": 0.0,
199+
"fi": 45,
200+
"twE": 0,
201+
"tweenFrame": true
202+
},
203+
{
204+
"dI": 0,
205+
"x": 0.0,
206+
"y": 0.0,
207+
"z": 0,
208+
"cX": 1.0,
209+
"cY": 1.0,
210+
"kX": 0.0,
211+
"kY": 0.0,
212+
"fi": 50,
213+
"twE": 0,
214+
"tweenFrame": true
215+
},
216+
{
217+
"dI": 1,
218+
"x": 0.0,
219+
"y": 0.0,
220+
"z": 0,
221+
"cX": 1.0,
222+
"cY": 1.0,
223+
"kX": 0.0,
224+
"kY": 0.0,
225+
"fi": 55,
226+
"twE": 0,
227+
"tweenFrame": true
228+
},
229+
{
230+
"dI": 0,
231+
"x": 0.0,
232+
"y": 0.0,
233+
"z": 0,
234+
"cX": 1.0,
235+
"cY": 1.0,
236+
"kX": 0.0,
237+
"kY": 0.0,
238+
"fi": 60,
239+
"twE": 0,
240+
"tweenFrame": true
241+
},
242+
{
243+
"dI": 1,
244+
"x": 0.0,
245+
"y": 0.0,
246+
"z": 0,
247+
"cX": 1.0,
248+
"cY": 1.0,
249+
"kX": 0.0,
250+
"kY": 0.0,
251+
"fi": 65,
252+
"twE": 0,
253+
"tweenFrame": true
254+
}
255+
]
256+
}
257+
]
258+
}
259+
]
260+
}
261+
],
262+
"texture_data": [
263+
{
264+
"name": "aaa",
265+
"width": 32.0,
266+
"height": 32.0,
267+
"pX": 0.5,
268+
"pY": 0.5,
269+
"plistFile": ""
270+
},
271+
{
272+
"name": "bbb",
273+
"width": 0.0,
274+
"height": 0.0,
275+
"pX": 0.5,
276+
"pY": 0.5,
277+
"plistFile": ""
278+
}
279+
],
280+
"config_file_path": [
281+
"1000.plist"
282+
]
283+
}

0 commit comments

Comments
 (0)