Skip to content

Commit 2881ce7

Browse files
committed
Merge pull request cocos2d#14632 from liamcindy/UITest
update for ui resource test
2 parents a8a9c8e + 136b2bd commit 2881ce7

File tree

16 files changed

+164
-6
lines changed

16 files changed

+164
-6
lines changed

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ bool UIButtonTest::init()
7575

7676
_uiLayer->addChild(imageView);
7777

78+
_button = button;
7879

80+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
81+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
82+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UIButtonTest::printWidgetResources, this));
83+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
84+
auto pMenu1 = Menu::create(item1, nullptr);
85+
pMenu1->setPosition(Vec2(0, 0));
86+
this->addChild(pMenu1, 10);
7987

8088
return true;
8189
}
@@ -117,6 +125,16 @@ void UIButtonTest::touchEvent(Ref *pSender, Widget::TouchEventType type)
117125
}
118126
}
119127

128+
void UIButtonTest::printWidgetResources(cocos2d::Ref* sender)
129+
{
130+
cocos2d::ResourceData normalFileName = _button->getNormalFile();
131+
CCLOG("normalFileName Name : %s, Type: %d", normalFileName.file.c_str(), normalFileName.type);
132+
cocos2d::ResourceData clickedFileName = _button->getPressedFile();
133+
CCLOG("clickedFileName Name : %s, Type: %d", clickedFileName.file.c_str(), clickedFileName.type);
134+
cocos2d::ResourceData disabledFileName = _button->getDisabledFile();
135+
CCLOG("disabledFileName Name : %s, Type: %d", disabledFileName.file.c_str(), disabledFileName.type);
136+
}
137+
120138

121139
// UIButtonTest_Scale9
122140
UIButtonTest_Scale9::UIButtonTest_Scale9()

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ class UIButtonTest : public UIScene
4040
virtual bool init() override;
4141
void touchEvent(cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type);
4242

43+
void printWidgetResources(cocos2d::Ref* sender);
4344
protected:
4445
cocos2d::ui::Text* _displayValueLabel;
46+
cocos2d::ui::Button* _button;
4547
};
4648

4749
class UIButtonTest_Scale9 : public UIScene

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,23 @@ bool UICheckBoxTest::init()
4040
_uiLayer->addChild(alert);
4141

4242
// Create the checkbox
43-
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png",
43+
_checkBox = CheckBox::create("cocosui/check_box_normal.png",
4444
"cocosui/check_box_normal_press.png",
4545
"cocosui/check_box_active.png",
4646
"cocosui/check_box_normal_disable.png",
4747
"cocosui/check_box_active_disable.png");
48-
checkBox->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
48+
_checkBox->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
4949

50-
checkBox->addEventListener(CC_CALLBACK_2(UICheckBoxTest::selectedEvent, this));
51-
_uiLayer->addChild(checkBox);
50+
_checkBox->addEventListener(CC_CALLBACK_2(UICheckBoxTest::selectedEvent, this));
51+
_uiLayer->addChild(_checkBox);
52+
53+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
54+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
55+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UICheckBoxTest::printWidgetResources, this));
56+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
57+
auto pMenu1 = Menu::create(item1, nullptr);
58+
pMenu1->setPosition(Vec2(0, 0));
59+
this->addChild(pMenu1, 10);
5260

5361
return true;
5462
}
@@ -73,6 +81,20 @@ void UICheckBoxTest::selectedEvent(Ref* pSender,CheckBox::EventType type)
7381

7482
}
7583

84+
void UICheckBoxTest::printWidgetResources(cocos2d::Ref* sender)
85+
{
86+
cocos2d::ResourceData backGroundFileName = _checkBox->getBackNormalFile();
87+
CCLOG("backGroundFile Name : %s, Type: %d", backGroundFileName.file.c_str(),backGroundFileName.type);
88+
cocos2d::ResourceData backGroundSelectedFileName = _checkBox->getBackPressedFile();
89+
CCLOG("backGroundSelectedFile Name : %s, Type: %d", backGroundSelectedFileName.file.c_str(), backGroundSelectedFileName.type);
90+
cocos2d::ResourceData backGroundDisabledFileName = _checkBox->getBackDisabledFile();
91+
CCLOG("backGroundDisabledFile Name : %s, Type: %d", backGroundDisabledFileName.file.c_str(), backGroundDisabledFileName.type);
92+
cocos2d::ResourceData frontCrossFileName = _checkBox->getCrossNormalFile();
93+
CCLOG("frontCrossFile Name : %s, Type: %d", frontCrossFileName.file.c_str(), frontCrossFileName.type);
94+
cocos2d::ResourceData frontCrossDisabledFileName = _checkBox->getCrossDisabledFile();
95+
CCLOG("frontCrossDisabledFile Name : %s, Type: %d", frontCrossDisabledFileName.file.c_str(), frontCrossDisabledFileName.type);
96+
}
97+
7698

7799
// UICheckBoxDefaultBehaviorTest
78100
UICheckBoxDefaultBehaviorTest::UICheckBoxDefaultBehaviorTest()

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ class UICheckBoxTest : public UIScene
4040
virtual bool init() override;
4141
void selectedEvent(cocos2d::Ref* sender,cocos2d::ui::CheckBox::EventType type);
4242

43+
void printWidgetResources(cocos2d::Ref* sender);
4344
protected:
4445
cocos2d::ui::Text* _displayValueLabel;
46+
cocos2d::ui::CheckBox* _checkBox;
4547
};
4648

4749
class UICheckBoxDefaultBehaviorTest : public UIScene

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,26 @@ bool UIImageViewTest::init()
3535

3636
_uiLayer->addChild(imageView);
3737

38-
38+
_image = imageView;
39+
40+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
41+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
42+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UIImageViewTest::printWidgetResources, this));
43+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
44+
auto pMenu1 = Menu::create(item1, nullptr);
45+
pMenu1->setPosition(Vec2(0, 0));
46+
this->addChild(pMenu1, 10);
3947

4048
return true;
4149
}
4250
return false;
4351
}
4452

53+
void UIImageViewTest::printWidgetResources(cocos2d::Ref* sender)
54+
{
55+
cocos2d::ResourceData textureFile = _image->getRenderFile();
56+
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
57+
}
4558

4659
// UIImageViewTest_Scale9
4760

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class UIImageViewTest : public UIScene
3535
CREATE_FUNC(UIImageViewTest);
3636

3737
virtual bool init() override;
38+
39+
void printWidgetResources(cocos2d::Ref* sender);
40+
protected:
41+
cocos2d::ui::ImageView* _image;
3842
};
3943

4044
class UIImageViewTest_Scale9 : public UIScene

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,28 @@ bool UILayoutTest_BackGroundImage::init()
264264
button_scale9->getContentSize().height / 2.0f));
265265

266266
layout->addChild(button_scale9);
267+
268+
_layout = layout;
269+
270+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
271+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
272+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UILayoutTest_BackGroundImage::printWidgetResources, this));
273+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
274+
auto pMenu1 = Menu::create(item1, nullptr);
275+
pMenu1->setPosition(Vec2(0, 0));
276+
this->addChild(pMenu1, 10);
267277

268278
return true;
269279
}
270280
return false;
271281
}
272282

283+
void UILayoutTest_BackGroundImage::printWidgetResources(cocos2d::Ref* sender)
284+
{
285+
cocos2d::ResourceData textureFile = _layout->getRenderFile();
286+
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
287+
}
288+
273289
// UILayoutTest_BackGroundImage_Scale9
274290

275291
UILayoutTest_BackGroundImage_Scale9::UILayoutTest_BackGroundImage_Scale9()

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class UILayoutTest_BackGroundImage : public UIScene
6767
virtual bool init() override;
6868

6969
CREATE_FUNC(UILayoutTest_BackGroundImage);
70+
71+
void printWidgetResources(cocos2d::Ref* sender);
72+
protected:
73+
cocos2d::ui::Layout* _layout;
7074
};
7175

7276
class UILayoutTest_BackGroundImage_Scale9 : public UIScene

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ bool UILoadingBarTest_Left::init()
7979
_uiLayer->addChild(loadingBar,1);
8080
_uiLayer->addChild(loadingBarCopy,2);
8181
_uiLayer->addChild(button);
82+
83+
_loadingBar = loadingBar;
84+
85+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
86+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
87+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UILoadingBarTest_Left::printWidgetResources, this));
88+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
89+
auto pMenu1 = Menu::create(item1, nullptr);
90+
pMenu1->setPosition(Vec2(0, 0));
91+
this->addChild(pMenu1, 10);
8292

8393
return true;
8494
}
@@ -98,6 +108,12 @@ void UILoadingBarTest_Left::update(float delta)
98108
loadingBarCopy->setPercent(_count);
99109
}
100110

111+
void UILoadingBarTest_Left::printWidgetResources(cocos2d::Ref* sender)
112+
{
113+
cocos2d::ResourceData textureFile = _loadingBar->getRenderFile();
114+
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
115+
}
116+
101117
// UILoadingBarTest_Right
102118

103119
UILoadingBarTest_Right::UILoadingBarTest_Right()
@@ -493,4 +509,4 @@ void UILoadingBarIssue12249::update(float delta)
493509
LoadingBar* loadingBarCopy = static_cast<LoadingBar*>(_uiLayer->getChildByTag(1));
494510
loadingBar->setPercent(_count);
495511
loadingBarCopy->setPercent(_count);
496-
}
512+
}

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ class UILoadingBarTest_Left : public UIScene
3838
~UILoadingBarTest_Left();
3939
virtual bool init() override;
4040
void update(float delta)override;
41+
void printWidgetResources(cocos2d::Ref* sender);
4142

4243
protected:
4344
int _count;
45+
cocos2d::ui::LoadingBar* _loadingBar;
4446
};
4547

4648
class UILoadingBarTest_Right : public UIScene

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ bool UISliderTest::init()
5454
slider->addEventListener(CC_CALLBACK_2(UISliderTest::sliderEvent, this));
5555
_uiLayer->addChild(slider);
5656

57+
_slider = slider;
58+
59+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
60+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
61+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UISliderTest::printWidgetResources, this));
62+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
63+
auto pMenu1 = Menu::create(item1, nullptr);
64+
pMenu1->setPosition(Vec2(0, 0));
65+
this->addChild(pMenu1, 10);
5766

5867
return true;
5968
}
@@ -70,6 +79,19 @@ void UISliderTest::sliderEvent(Ref *pSender, Slider::EventType type)
7079
_displayValueLabel->setString(StringUtils::format("Percent %f", 10000.0 * percent / maxPercent));
7180
}
7281
}
82+
void UISliderTest::printWidgetResources(cocos2d::Ref* sender)
83+
{
84+
cocos2d::ResourceData textureFile = _slider->getBackFile();
85+
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
86+
cocos2d::ResourceData progressBarTextureFile = _slider->getProgressBarFile();
87+
CCLOG("progressBarTextureFile Name : %s, Type: %d", progressBarTextureFile.file.c_str(), progressBarTextureFile.type);
88+
cocos2d::ResourceData slidBallNormalTextureFile = _slider->getBallNormalFile();
89+
CCLOG("slidBallNormalTextureFile Name : %s, Type: %d", slidBallNormalTextureFile.file.c_str(), slidBallNormalTextureFile.type);
90+
cocos2d::ResourceData slidBallPressedTextureFile = _slider->getBallPressedFile();
91+
CCLOG("slidBallPressedTextureFile Name : %s, Type: %d", slidBallPressedTextureFile.file.c_str(), slidBallPressedTextureFile.type);
92+
cocos2d::ResourceData slidBallDisabledTextureFile = _slider->getBallDisabledFile();
93+
CCLOG("slidBallDisabledTextureFile Name : %s, Type: %d", slidBallDisabledTextureFile.file.c_str(), slidBallDisabledTextureFile.type);
94+
}
7395

7496
// UISliderTest_Scale9
7597

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ class UISliderTest : public UIScene
3838
~UISliderTest();
3939
virtual bool init() override;
4040
void sliderEvent(cocos2d::Ref* sender, cocos2d::ui::Slider::EventType type);
41+
void printWidgetResources(cocos2d::Ref* sender);
4142

4243
protected:
4344
cocos2d::ui::TextBMFont* _displayValueLabel;
45+
cocos2d::ui::Slider* _slider;
4446
};
4547

4648
class UISliderTest_Scale9 : public UIScene

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@ bool UITextAtlasTest::init()
3434
textAtlas->setPosition(Vec2((widgetSize.width) / 2, widgetSize.height / 2.0f));
3535
_uiLayer->addChild(textAtlas);
3636

37+
_textAtlas = textAtlas;
38+
39+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
40+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
41+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UITextAtlasTest::printWidgetResources, this));
42+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
43+
auto pMenu1 = Menu::create(item1, nullptr);
44+
pMenu1->setPosition(Vec2(0, 0));
45+
this->addChild(pMenu1, 10);
3746
return true;
3847
}
3948
return false;
4049
}
50+
void UITextAtlasTest::printWidgetResources(cocos2d::Ref* sender)
51+
{
52+
cocos2d::ResourceData textureFile = _textAtlas->getRenderFile();
53+
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
54+
}

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class UITextAtlasTest : public UIScene
1313
CREATE_FUNC(UITextAtlasTest);
1414

1515
virtual bool init() override;
16+
void printWidgetResources(cocos2d::Ref* sender);
17+
protected:
18+
cocos2d::ui::TextAtlas* _textAtlas;
1619
};
1720

1821
#endif /* defined(__TestCpp__UITextAtlasTest__) */

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ bool UITextBMFontTest::init()
2525
textBMFont->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + textBMFont->getContentSize().height / 8.0f));
2626
_uiLayer->addChild(textBMFont);
2727

28+
_textBMFont = textBMFont;
29+
30+
TTFConfig ttfConfig("fonts/arial.ttf", 15);
31+
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
32+
auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UITextBMFontTest::printWidgetResources, this));
33+
item1->setPosition(Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
34+
auto pMenu1 = Menu::create(item1, nullptr);
35+
pMenu1->setPosition(Vec2(0, 0));
36+
this->addChild(pMenu1, 10);
37+
2838
return true;
2939
}
3040
return false;
3141
}
42+
void UITextBMFontTest::printWidgetResources(cocos2d::Ref* sender)
43+
{
44+
cocos2d::ResourceData textureFile = _textBMFont->getRenderFile();
45+
CCLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
46+
}

tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class UITextBMFontTest : public UIScene
3535
CREATE_FUNC(UITextBMFontTest)
3636

3737
virtual bool init() override;
38+
void printWidgetResources(cocos2d::Ref* sender);
39+
protected:
40+
cocos2d::ui::TextBMFont* _textBMFont;
3841
};
3942

4043
#endif /* defined(__TestCpp__UITextBMFontTest__) */

0 commit comments

Comments
 (0)