From c3a5692e846705faeda7549dbfb327a3e9b52e7b Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 14:21:27 +0800 Subject: [PATCH 01/20] add test frame to UIScene_Editor --- .../CocoStudioGUITest/UIScene_Editor.cpp | 25 +++++++++++++++++++ .../UITest/CocoStudioGUITest/UIScene_Editor.h | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp index 92976538e8..b7e12095d0 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp @@ -26,12 +26,37 @@ bool UIScene_Editor::init() _touchGroup = Layer::create(); addChild(_touchGroup); + //add switch + MenuItem* pLoadJsonItem = MenuItemFont::create("Switch to Binary Load"); + MenuItem* pLoadBinaryItem = MenuItemFont::create("Switch to Json Load"); + + pLoadJsonItem->setTag(1); + pLoadBinaryItem->setTag(2); + + Vector array;; + array.pushBack(pLoadJsonItem); + array.pushBack(pLoadBinaryItem); + + MenuItemToggle *pToggleItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(UIScene_Editor::switchLoadMethod,this), array); + + pToggleItem->setPosition(Vec2(VisibleRect::right().x - 150, VisibleRect::top().y - 50));; + + Menu* pMenu =Menu::create(pToggleItem, NULL); + pMenu->setPosition( Vec2::ZERO ); + + addChild(pMenu, 1); + return true; } return false; } +void UIScene_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + //subclass should override this method +} + void UIScene_Editor::previousCallback(Ref* sender, Widget::TouchEventType event) { switch (event) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h index d681787126..d4507fc753 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.h @@ -69,7 +69,8 @@ public: CC_SYNTHESIZE_READONLY(Text*, _sceneTitle, SceneTitle) UI_SCENE_EDITOR_CREATE_FUNC(UIScene_Editor); - + virtual void switchLoadMethod(Ref* pSender); + protected: Layer* _touchGroup; Layout* _layout; From 3326941939be1e1230945e202d7cd86a5103ee8d Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 14:35:43 +0800 Subject: [PATCH 02/20] add switch loading method to buttonTest --- .../UIButtonTest/UIButtonTest_Editor.cpp | 82 ++++++++++++------- .../UIButtonTest/UIButtonTest_Editor.h | 4 +- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp index 468b8a1d61..53a668ecec 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp @@ -16,46 +16,70 @@ UIButtonTest_Editor::~UIButtonTest_Editor() } +void UIButtonTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIButtonTest_Editor::configureGUIScene() +{ + Size screenSize = Director::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + ui::Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* button = static_cast(Helper::seekWidgetByName(root, "Button_123")); + button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); + + Button* title_button = static_cast(Helper::seekWidgetByName(root, "Button_126")); + title_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); + + Button* scale9_button = static_cast(Helper::seekWidgetByName(root, "Button_129")); + scale9_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent,this)); + +} + bool UIButtonTest_Editor::init() { if (UIScene_Editor::init()) { -// auto _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); - - - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.csb")); - - - + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + this->configureGUIScene(); - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - Button* button = static_cast(Helper::seekWidgetByName(root, "Button_123")); - button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); - - Button* title_button = static_cast(Helper::seekWidgetByName(root, "Button_126")); - title_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); - - Button* scale9_button = static_cast(Helper::seekWidgetByName(root, "Button_129")); - scale9_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); - - _displayValueLabel = Text::create(); - _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); + _displayValueLabel = ui::Text::create(); + _displayValueLabel->setFontName("Marker Felt"); _displayValueLabel->setFontSize(30); _displayValueLabel->setString("No event"); _displayValueLabel->setPosition(Vec2(_layout->getContentSize().width / 2, - _layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f)); - _touchGroup->addChild(_displayValueLabel); + _layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f)); + + _touchGroup->addChild(_displayValueLabel,20); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h index 1985dcb907..33f8e5c72e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.h @@ -35,7 +35,9 @@ public: bool init(); void touchEvent(Ref* pSender, Widget::TouchEventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); + protected: UI_SCENE_EDITOR_CREATE_FUNC(UIButtonTest_Editor); Text* _displayValueLabel; From 7fdc37a70e46cf402a4b7bc20a963023d99ab759 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 14:43:20 +0800 Subject: [PATCH 03/20] add switch method to checkBoxTest --- .../UICheckBoxTest/UICheckBoxTest_Editor.cpp | 61 +++++++++++++------ .../UICheckBoxTest/UICheckBoxTest_Editor.h | 3 +- 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp index 097cae5079..07594f4ad1 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp @@ -16,27 +16,54 @@ UICheckBoxTest_Editor::~UICheckBoxTest_Editor() } +void UICheckBoxTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UICheckBoxTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + CheckBox* checkbox = static_cast(Helper::seekWidgetByName(root, "CheckBox_540")); + checkbox->addEventListener(CC_CALLBACK_2(UICheckBoxTest_Editor::selectedStateEvent, this)); + +} + bool UICheckBoxTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.csb")); -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_2.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - CheckBox* checkbox = static_cast(Helper::seekWidgetByName(root, "CheckBox_540")); - checkbox->addEventListener(CC_CALLBACK_2(UICheckBoxTest_Editor::selectedStateEvent, this)); + + this->configureGUIScene(); _displayValueLabel = Text::create(); _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); @@ -44,7 +71,7 @@ bool UICheckBoxTest_Editor::init() _displayValueLabel->setString("No event"); _displayValueLabel->setPosition(Vec2(_layout->getContentSize().width / 2, _layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f)); - _touchGroup->addChild(_displayValueLabel); + _touchGroup->addChild(_displayValueLabel,20); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h index c9ed1cb988..d2d03b7ce6 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.h @@ -34,7 +34,8 @@ public: ~UICheckBoxTest_Editor(); bool init(); void selectedStateEvent(Ref* pSender, CheckBox::EventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UICheckBoxTest_Editor) Text* _displayValueLabel; From f49264375534b74afa3e1595bc65ddb9ca4726d6 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 15:01:38 +0800 Subject: [PATCH 04/20] add switch method to UILayout and UIIamgeView --- .../UIImageViewTest_Editor.cpp | 53 +- .../UIImageViewTest/UIImageViewTest_Editor.h | 4 +- .../UILayoutTest/UILayoutTest_Editor.cpp | 807 +++++++++++------- .../UILayoutTest/UILayoutTest_Editor.h | 26 +- 4 files changed, 583 insertions(+), 307 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp index 06a136ccf7..a0a6f7fa98 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp @@ -4,26 +4,53 @@ // UIImageViewTest_Editor +void UIImageViewTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIImageViewTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + +} bool UIImageViewTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h index 195f239fae..37a1604d73 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.h @@ -31,7 +31,9 @@ class UIImageViewTest_Editor : public UIScene_Editor { public: bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); + protected: UI_SCENE_EDITOR_CREATE_FUNC(UIImageViewTest_Editor) }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp index 5632895887..a1e24b12c7 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp @@ -13,44 +13,72 @@ UILayoutTest_Editor::UILayoutTest_Editor() UILayoutTest_Editor::~UILayoutTest_Editor() { +} + +void UILayoutTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + + } bool UILayoutTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); + this->configureGUIScene(); return true; } @@ -71,43 +99,68 @@ UILayoutTest_Color_Editor::~UILayoutTest_Color_Editor() } +void UILayoutTest_Color_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Color_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); +} + bool UILayoutTest_Color_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + this->configureGUIScene(); return true; } @@ -127,43 +180,69 @@ UILayoutTest_Gradient_Editor::~UILayoutTest_Gradient_Editor() } +void UILayoutTest_Gradient_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Gradient_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_Gradient_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + this->configureGUIScene(); return true; } @@ -183,43 +262,70 @@ UILayoutTest_BackGroundImage_Editor::~UILayoutTest_BackGroundImage_Editor() } +void UILayoutTest_BackGroundImage_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_BackGroundImage_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_BackGroundImage_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + + this->configureGUIScene(); return true; } @@ -239,43 +345,70 @@ UILayoutTest_BackGroundImage_Scale9_Editor::~UILayoutTest_BackGroundImage_Scale9 } +void UILayoutTest_BackGroundImage_Scale9_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_BackGroundImage_Scale9_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_BackGroundImage_Scale9_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + + this->configureGUIScene(); return true; } @@ -295,43 +428,70 @@ UILayoutTest_Layout_Linear_Vertical_Editor::~UILayoutTest_Layout_Linear_Vertical } +void UILayoutTest_Layout_Linear_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Layout_Linear_Vertical_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_Layout_Linear_Vertical_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); + _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); + this->configureGUIScene(); return true; } @@ -351,43 +511,69 @@ UILayoutTest_Layout_Linear_Horizontal_Editor::~UILayoutTest_Layout_Linear_Horizo } +void UILayoutTest_Layout_Linear_Horizontal_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Layout_Linear_Horizontal_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + + this->configureGUIScene(); return true; } @@ -408,42 +594,68 @@ UILayoutTest_Layout_Relative_Align_Parent_Editor::~UILayoutTest_Layout_Relative_ } +void UILayoutTest_Layout_Relative_Align_Parent_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Layout_Relative_Align_Parent_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); + this->configureGUIScene(); return true; } @@ -464,43 +676,68 @@ UILayoutTest_Layout_Relative_Location_Editor::~UILayoutTest_Layout_Relative_Loca } +void UILayoutTest_Layout_Relative_Location_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILayoutTest_Layout_Relative_Location_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UILayoutTest_Layout_Relative_Location_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h index 15025f5f99..5b0fb91c4f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.h @@ -33,7 +33,8 @@ public: UILayoutTest_Editor(); ~UILayoutTest_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Editor) }; @@ -45,7 +46,8 @@ public: UILayoutTest_Color_Editor(); ~UILayoutTest_Color_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Color_Editor) }; @@ -57,7 +59,8 @@ public: UILayoutTest_Gradient_Editor(); ~UILayoutTest_Gradient_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Gradient_Editor) }; @@ -69,7 +72,8 @@ public: UILayoutTest_BackGroundImage_Editor(); ~UILayoutTest_BackGroundImage_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_BackGroundImage_Editor) }; @@ -81,7 +85,8 @@ public: UILayoutTest_BackGroundImage_Scale9_Editor(); ~UILayoutTest_BackGroundImage_Scale9_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_BackGroundImage_Scale9_Editor) }; @@ -92,6 +97,8 @@ class UILayoutTest_Layout_Linear_Vertical_Editor : public UIScene_Editor public: UILayoutTest_Layout_Linear_Vertical_Editor(); ~UILayoutTest_Layout_Linear_Vertical_Editor(); + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); bool init(); protected: @@ -105,7 +112,8 @@ public: UILayoutTest_Layout_Linear_Horizontal_Editor(); ~UILayoutTest_Layout_Linear_Horizontal_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Linear_Horizontal_Editor) }; @@ -117,7 +125,8 @@ public: UILayoutTest_Layout_Relative_Align_Parent_Editor(); ~UILayoutTest_Layout_Relative_Align_Parent_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Relative_Align_Parent_Editor) }; @@ -129,7 +138,8 @@ public: UILayoutTest_Layout_Relative_Location_Editor(); ~UILayoutTest_Layout_Relative_Location_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILayoutTest_Layout_Relative_Location_Editor) }; From 21b11cc3c6358d4a8190b725acb4a1f2763220ec Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 15:19:40 +0800 Subject: [PATCH 05/20] add switch method to LoadingBar, ListView , pageView and scrollView --- .../UIListViewTest/UIListViewTest_Editor.cpp | 187 +++++++----- .../UIListViewTest/UIListViewTest_Editor.h | 6 +- .../UILoadingBarTest_Editor.cpp | 68 +++-- .../UILoadingBarTest_Editor.h | 3 +- .../UIPageViewTest/UIPageViewTest_Editor.cpp | 91 +++--- .../UIPageViewTest/UIPageViewTest_Editor.h | 3 +- .../UIScrollViewTest_Editor.cpp | 272 +++++++++++------- .../UIScrollViewTest_Editor.h | 11 +- 8 files changed, 417 insertions(+), 224 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp index 81ae580b79..af770b4903 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp @@ -15,47 +15,73 @@ UIListViewTest_Vertical_Editor::~UIListViewTest_Vertical_Editor() } +void UIListViewTest_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIListViewTest_Vertical_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene,this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + // ListView* listView = static_cast(UIHelper::seekWidgetByName(root, "ListView_1214")); + // CCLOG("listView isBounceEnabled = %d", listView->isBounceEnabled()); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback,this)); + + + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback,this)); + _layout->addChild(right_button); + +} + bool UIListViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene,this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - -// ListView* listView = static_cast(UIHelper::seekWidgetByName(root, "ListView_1214")); -// CCLOG("listView isBounceEnabled = %d", listView->isBounceEnabled()); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback,this)); - - - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback,this)); - _layout->addChild(right_button); + this->configureGUIScene(); return true; } @@ -72,6 +98,61 @@ UIListViewTest_Horizontal_Editor::UIListViewTest_Horizontal_Editor() } +void UIListViewTest_Horizontal_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIListViewTest_Horizontal_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene,this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback,this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + UIListViewTest_Horizontal_Editor::~UIListViewTest_Horizontal_Editor() { @@ -81,38 +162,10 @@ bool UIListViewTest_Horizontal_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene,this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback,this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); + + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h index 0f5d0e07ef..f8d1efe3e8 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.h @@ -34,7 +34,8 @@ public: ~UIListViewTest_Vertical_Editor(); bool init(); void selectedItemEvent(Ref* pSender, ListView::EventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIListViewTest_Vertical_Editor) Text* _displayValueLabel; @@ -50,7 +51,8 @@ public: ~UIListViewTest_Horizontal_Editor(); bool init(); void selectedItemEvent(Ref* pSender, ListView::EventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIListViewTest_Horizontal_Editor) Text* _displayValueLabel; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp index f882651fdf..bd7a25c62c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp @@ -15,34 +15,60 @@ UILoadingBarTest_Editor::~UILoadingBarTest_Editor() } +void UILoadingBarTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UILoadingBarTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + // back_label->addTouchEventListener(this, toucheventselector(UIScene_Editor::toGUIEditorTestScene)); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + LoadingBar* loadingBar_left_to_right = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_856")); + loadingBar_left_to_right->setPercent(0); + + LoadingBar* loadingBar_right_to_left = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_857")); + loadingBar_right_to_left->setPercent(0); + +} + bool UILoadingBarTest_Editor::init() { if (UIScene_Editor::init()) { scheduleUpdate(); -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); -// back_label->addTouchEventListener(this, toucheventselector(UIScene_Editor::toGUIEditorTestScene)); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - LoadingBar* loadingBar_left_to_right = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_856")); - loadingBar_left_to_right->setPercent(0); - - LoadingBar* loadingBar_right_to_left = dynamic_cast(Helper::seekWidgetByName(root, "LoadingBar_857")); - loadingBar_right_to_left->setPercent(0); - + + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h index 1cb987c22d..ed7c26d39e 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.h @@ -13,7 +13,8 @@ public: bool init(); void update(float delta); void toCocosGUITestScene(Ref* sender, Widget::TouchEventType event); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UILoadingBarTest_Editor) int _count; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp index 96f6f9e93b..f509bff3f4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp @@ -16,43 +16,70 @@ UIPageViewTest_Editor::~UIPageViewTest_Editor() } +void UIPageViewTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIPageViewTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UIPageViewTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h index ae3beb4eb6..82248d2fdc 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.h @@ -35,7 +35,8 @@ public: bool init(); void pageViewEvent(Ref* pSender, PageView::EventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIPageViewTest_Editor) Text* _displayValueLabel; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp index f782dfe945..f2d4eefdb6 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp @@ -15,43 +15,70 @@ UIScrollViewTest_Vertical_Editor::~UIScrollViewTest_Vertical_Editor() } +void UIScrollViewTest_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIScrollViewTest_Vertical_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + +} + bool UIScrollViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + + this->configureGUIScene(); return true; } @@ -69,45 +96,72 @@ UIScrollViewTest_Horizontal_Editor::UIScrollViewTest_Horizontal_Editor() UIScrollViewTest_Horizontal_Editor::~UIScrollViewTest_Horizontal_Editor() { +} + +void UIScrollViewTest_Horizontal_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIScrollViewTest_Horizontal_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); + + } bool UIScrollViewTest_Horizontal_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + this->configureGUIScene(); return true; } @@ -127,43 +181,68 @@ UIScrollViewTest_Both_Editor::~UIScrollViewTest_Both_Editor() } +void UIScrollViewTest_Both_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIScrollViewTest_Both_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + Button* left_button = Button::create(); + left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); + left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, + left_button->getContentSize().height * 0.625)); + left_button->setTouchEnabled(true); + left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); + left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(left_button); + + Button* right_button = Button::create(); + right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); + right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, + right_button->getContentSize().height * 0.625)); + right_button->setTouchEnabled(true); + right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); + right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); + _layout->addChild(right_button); +} + bool UIScrollViewTest_Both_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - Button* left_button = Button::create(); - left_button->loadTextures("Images/b1.png", "Images/b2.png", ""); - left_button->setPosition(Vec2(_layout->getContentSize().width / 2 - left_button->getContentSize().width, - left_button->getContentSize().height * 0.625)); - left_button->setTouchEnabled(true); - left_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::previousCallback, this)); - left_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(left_button); - - Button* right_button = Button::create(); - right_button->loadTextures("Images/f1.png", "Images/f2.png", ""); - right_button->setPosition(Vec2(_layout->getContentSize().width / 2 + right_button->getContentSize().width, - right_button->getContentSize().height * 0.625)); - right_button->setTouchEnabled(true); - right_button->setLocalZOrder(_layout->getLocalZOrder() + 1); - right_button->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::nextCallback, this)); - _layout->addChild(right_button); - + this->configureGUIScene(); return true; } @@ -183,6 +262,7 @@ UIScrollViewTest_ScrollToPercentBothDirection_Editor::~UIScrollViewTest_ScrollTo } + bool UIScrollViewTest_ScrollToPercentBothDirection_Editor::init() { if (UIScene_Editor::init()) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h index 648f97ec5e..627d5df685 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.h @@ -33,7 +33,8 @@ public: UIScrollViewTest_Vertical_Editor(); ~UIScrollViewTest_Vertical_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_Vertical_Editor) Text* _displayValueLabel; @@ -46,7 +47,8 @@ public: UIScrollViewTest_Horizontal_Editor(); ~UIScrollViewTest_Horizontal_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_Horizontal_Editor) Text* _displayValueLabel; @@ -59,7 +61,8 @@ public: UIScrollViewTest_Both_Editor(); ~UIScrollViewTest_Both_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_Both_Editor) Text* _displayValueLabel; @@ -72,7 +75,7 @@ public: UIScrollViewTest_ScrollToPercentBothDirection_Editor(); ~UIScrollViewTest_ScrollToPercentBothDirection_Editor(); bool init(); - + protected: UI_SCENE_EDITOR_CREATE_FUNC(UIScrollViewTest_ScrollToPercentBothDirection_Editor) Text* _displayValueLabel; From 3304bba017aecad24e6c1ff6ea9f9de811cc34dd Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 15:47:40 +0800 Subject: [PATCH 06/20] add switch method to all the GUI tests --- .../UISliderTest/UISliderTest_Editor.cpp | 70 +++++++++++------ .../UISliderTest/UISliderTest_Editor.h | 4 +- .../UITextAtlasTest_Editor.cpp | 53 +++++++++---- .../UITextAtlasTest/UITextAtlasTest_Editor.h | 3 +- .../UITextBMFontTest_Editor.cpp | 51 +++++++++---- .../UITextBMFontTest_Editor.h | 3 +- .../UITextFieldTest_Editor.cpp | 73 ++++++++++++------ .../UITextFieldTest/UITextFieldTest_Editor.h | 3 +- .../UITextTest/UITextTest_Editor.cpp | 54 +++++++++---- .../UITextTest/UITextTest_Editor.h | 3 +- .../UIWidgetAddNodeTest_Editor.cpp | 76 +++++++++++++------ .../UIWidgetAddNodeTest_Editor.h | 3 +- 12 files changed, 280 insertions(+), 116 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp index 54d2252ecb..b27625bb9b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp @@ -16,32 +16,58 @@ UISliderTest_Editor::~UISliderTest_Editor() } +void UISliderTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UISliderTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + + Slider* slider = static_cast(Helper::seekWidgetByName(root, "Slider_738")); + slider->addEventListener(CC_CALLBACK_2(UISliderTest_Editor::sliderEvent, this)); + + Slider* scale9_slider = static_cast(Helper::seekWidgetByName(root, "Slider_740")); + scale9_slider->addEventListener(CC_CALLBACK_2(UISliderTest_Editor::sliderEvent, this)); +} + bool UISliderTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - - Slider* slider = static_cast(Helper::seekWidgetByName(root, "Slider_738")); - slider->addEventListener(CC_CALLBACK_2(UISliderTest_Editor::sliderEvent, this)); - - Slider* scale9_slider = static_cast(Helper::seekWidgetByName(root, "Slider_740")); - scale9_slider->addEventListener(CC_CALLBACK_2(UISliderTest_Editor::sliderEvent, this)); - + + this->configureGUIScene(); _displayValueLabel = Text::create(); _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); @@ -49,7 +75,7 @@ bool UISliderTest_Editor::init() _displayValueLabel->setString("No event"); _displayValueLabel->setPosition(Vec2(_layout->getContentSize().width / 2, _layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f)); - _touchGroup->addChild(_displayValueLabel); + _touchGroup->addChild(_displayValueLabel, 20); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h index 3637d2212e..ff7dc3ec40 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.h @@ -12,7 +12,9 @@ public: ~UISliderTest_Editor(); bool init(); void sliderEvent(Ref* pSender, Slider::EventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); + protected: UI_SCENE_EDITOR_CREATE_FUNC(UISliderTest_Editor) Text* _displayValueLabel; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp index ed418ac7d7..bade2452e9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp @@ -3,26 +3,51 @@ #include "UITextAtlasTest_Editor.h" // UITextAtlasTest_Editor +void UITextAtlasTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UITextAtlasTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); +} bool UITextAtlasTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - + + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h index a061b28d1c..e0a170acec 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.h @@ -31,7 +31,8 @@ class UITextAtlasTest_Editor : public UIScene_Editor { public: bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UITextAtlasTest_Editor) }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp index dc7eff0ed9..788f994a02 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp @@ -4,26 +4,51 @@ // UITextBMFontTest_Editor +void UITextBMFontTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UITextBMFontTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); +} bool UITextBMFontTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h index 765d0966a3..8ff7eccdab 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.h @@ -31,7 +31,8 @@ class UITextBMFontTest_Editor : public UIScene_Editor { public: bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UITextBMFontTest_Editor) }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp index b340b57a9a..8fb8f98623 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp @@ -16,33 +16,60 @@ UITextFieldTest_Editor::~UITextFieldTest_Editor() } +void UITextFieldTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UITextFieldTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + TextField* textField_normal = static_cast(Helper::seekWidgetByName(root, "TextField_1109")); + textField_normal->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); + + TextField* textField_max_character = static_cast(Helper::seekWidgetByName(root, "TextField_1110")); + textField_max_character->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); + + TextField* textField_password = static_cast(Helper::seekWidgetByName(root, "TextField_1107")); + textField_password->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); +} + bool UITextFieldTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - TextField* textField_normal = static_cast(Helper::seekWidgetByName(root, "TextField_1109")); - textField_normal->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); - - TextField* textField_max_character = static_cast(Helper::seekWidgetByName(root, "TextField_1110")); - textField_max_character->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); - - TextField* textField_password = static_cast(Helper::seekWidgetByName(root, "TextField_1107")); - textField_password->addEventListener(CC_CALLBACK_2(UITextFieldTest_Editor::textFieldEvent, this)); + + this->configureGUIScene(); _displayValueLabel = Text::create(); _displayValueLabel->setFontName("fonts/Marker Felt.ttf"); @@ -50,7 +77,7 @@ bool UITextFieldTest_Editor::init() _displayValueLabel->setString("No event"); _displayValueLabel->setPosition(Vec2(_layout->getContentSize().width / 2, _layout->getContentSize().height - _displayValueLabel->getContentSize().height * 1.75f)); - _touchGroup->addChild(_displayValueLabel); + _touchGroup->addChild(_displayValueLabel, 20); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h index 38b1f8306f..1621d68d10 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.h @@ -34,7 +34,8 @@ public: ~UITextFieldTest_Editor(); bool init(); void textFieldEvent(Ref* pSender, TextField::EventType type); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UITextFieldTest_Editor) Text* _displayValueLabel; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp index 97b45c4936..f80c4c6f8b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp @@ -7,25 +7,51 @@ // UITextTest_Editor using namespace ui; +void UITextTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UITextTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + +} + bool UITextTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h index 69bf1bdcbb..54c83d2315 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.h @@ -31,7 +31,8 @@ class UITextTest_Editor : public UIScene_Editor { public: bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UITextTest_Editor) }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp index 6f5276a3a1..313cedbc84 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp @@ -15,35 +15,63 @@ UIWidgetAddNodeTest_Editor::~UIWidgetAddNodeTest_Editor() } +void UIWidgetAddNodeTest_Editor::switchLoadMethod(cocos2d::Ref *pSender) +{ + MenuItemToggle *item = (MenuItemToggle*)pSender; + + if (item->getSelectedIndex() == 0){ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); + + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + }else{ + _layout->removeFromParentAndCleanup(true); + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.csb")); + _touchGroup->addChild(_layout); + + this->configureGUIScene(); + } +} + +void UIWidgetAddNodeTest_Editor::configureGUIScene() +{ + Size screenSize = CCDirector::getInstance()->getWinSize(); + Size rootSize = _layout->getContentSize(); + _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, + (screenSize.height - rootSize.height) / 2)); + + Layout* root = static_cast(_layout->getChildByName("root_Panel")); + + Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); + back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); + + _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); + + + // Create the ui widget + Widget* widget = Widget::create(); + widget->setPosition(Vec2(rootSize.width / 2.0f, rootSize.height / 2.0f)); + widget->setLocalZOrder(_layout->getLocalZOrder() + 1); + _layout->addChild(widget); + + Sprite* sprite = Sprite::create("cocosui/ccicon.png"); + widget->addChild(sprite); + + +} + + bool UIWidgetAddNodeTest_Editor::init() { if (UIScene_Editor::init()) { -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.csb")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); _touchGroup->addChild(_layout); - Size screenSize = CCDirector::getInstance()->getWinSize(); - Size rootSize = _layout->getContentSize(); - _touchGroup->setPosition(Vec2((screenSize.width - rootSize.width) / 2, - (screenSize.height - rootSize.height) / 2)); - - Layout* root = static_cast(_layout->getChildByName("root_Panel")); - - Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); - back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); - - _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); - - - // Create the ui widget - Widget* widget = Widget::create(); - widget->setPosition(Vec2(rootSize.width / 2.0f, rootSize.height / 2.0f)); - widget->setLocalZOrder(_layout->getLocalZOrder() + 1); - _layout->addChild(widget); - - Sprite* sprite = Sprite::create("cocosui/ccicon.png"); - widget->addChild(sprite); - + this->configureGUIScene(); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h index d50be1d6d8..11d4c36097 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.h @@ -33,7 +33,8 @@ public: UIWidgetAddNodeTest_Editor(); ~UIWidgetAddNodeTest_Editor(); bool init(); - + virtual void switchLoadMethod(Ref* pSender); + void configureGUIScene(); protected: UI_SCENE_EDITOR_CREATE_FUNC(UIWidgetAddNodeTest_Editor) }; From 68bd717ea7481aac9ac9e54b92cb85c464353e0e Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 7 Jul 2014 12:06:24 +0800 Subject: [PATCH 07/20] issue #4689: support external key. --- cocos/base/CCController-android.cpp | 16 ++++++- cocos/base/CCController-iOS.mm | 4 ++ cocos/base/CCController.h | 3 ++ .../cocos2dx/lib/GameControllerHelper.java | 32 +++++++++++-- .../Classes/GameControllerTest.cpp | 47 ++++++++++++++----- .../Classes/GameControllerTest.h | 3 +- 6 files changed, 87 insertions(+), 18 deletions(-) diff --git a/cocos/base/CCController-android.cpp b/cocos/base/CCController-android.cpp index f4b9c1fa82..6d370d86d9 100644 --- a/cocos/base/CCController-android.cpp +++ b/cocos/base/CCController-android.cpp @@ -47,6 +47,7 @@ public: auto iter = std::find_if(Controller::s_allController.begin(), Controller::s_allController.end(), [&](Controller* controller){ return (deviceName == controller->_deviceName) && (deviceId == controller->_deviceId); }); + return iter; } static void onConnected(const std::string& deviceName, int deviceId) @@ -99,13 +100,16 @@ public: static void onAxisEvent(const std::string& deviceName, int deviceId, int axisCode, float value, bool isAnalog) { + log("onAxisEvent:%s,%d,%d,%f",deviceName.c_str(),deviceId,axisCode,value); + auto iter = findController(deviceName, deviceId); if (iter == Controller::s_allController.end()) { + log("onAxisEvent: not find,connect new"); onConnected(deviceName, deviceId); iter = findController(deviceName, deviceId); } - + (*iter)->onAxisEvent(axisCode, value, isAnalog); } @@ -154,6 +158,16 @@ Controller::Controller() init(); } +void Controller::receiveExternalKeyEvent(int externalKeyCode,bool receive) +{ + JniMethodInfo t; + if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/GameControllerHelper", "receiveExternalKeyEvent", "(IIZ)V")) { + + t.env->CallStaticVoidMethod(t.classID, t.methodID, _deviceId, externalKeyCode, receive); + t.env->DeleteLocalRef(t.classID); + } +} + NS_CC_END extern "C" { diff --git a/cocos/base/CCController-iOS.mm b/cocos/base/CCController-iOS.mm index 0aba02f228..26f83d4d64 100644 --- a/cocos/base/CCController-iOS.mm +++ b/cocos/base/CCController-iOS.mm @@ -311,6 +311,10 @@ bool Controller::isConnected() const return _impl->_gcController.isAttachedToDevice == YES; } +void Controller::receiveExternalKeyEvent(int externalKeyCode,bool receive) +{ +} + NS_CC_END #endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) diff --git a/cocos/base/CCController.h b/cocos/base/CCController.h index bd54e5517d..63997a270f 100644 --- a/cocos/base/CCController.h +++ b/cocos/base/CCController.h @@ -99,6 +99,9 @@ public: const KeyStatus& getKeyStatus(int keyCode); + //Setting up receives external key which not contained within enum Key. + void receiveExternalKeyEvent(int externalKeyCode,bool receive); + void setTag(int tag) { _controllerTag = tag;} int getTag() const { return _controllerTag;} diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java index 9d182a0482..0ccf1dd714 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java @@ -1,6 +1,8 @@ package org.cocos2dx.lib; -import android.util.Log; +import java.util.ArrayList; + +import android.util.SparseArray; import android.util.SparseIntArray; import android.view.InputDevice; import android.view.KeyEvent; @@ -147,6 +149,8 @@ public class GameControllerHelper { return handled; } + private static SparseArray> mControllerExtendKey = new SparseArray>(); + public boolean dispatchKeyEvent(KeyEvent event) { boolean handled = false; @@ -154,9 +158,18 @@ public class GameControllerHelper { int keyCode = event.getKeyCode(); int controllerKey = ControllerKeyMap.get(keyCode); - if (controllerKey != 0 && (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )) + if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) + || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) { + int deviceId = event.getDeviceId(); + if (controllerKey == 0) { + if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) { + controllerKey = keyCode; + }else { + return false; + } + } + int action = event.getAction(); if (action == KeyEvent.ACTION_DOWN) { handled = true; @@ -169,4 +182,17 @@ public class GameControllerHelper { return handled; } + + public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) { + if (receive) { + if (mControllerExtendKey.get(deviceId) == null) { + mControllerExtendKey.put(deviceId, new ArrayList()); + } + mControllerExtendKey.get(deviceId).add(externalKeyCode); + } else { + if (mControllerExtendKey.get(deviceId) != null) { + mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode)); + } + } + } } diff --git a/tests/game-controller-test/Classes/GameControllerTest.cpp b/tests/game-controller-test/Classes/GameControllerTest.cpp index 9e535b6d64..c340b2772c 100644 --- a/tests/game-controller-test/Classes/GameControllerTest.cpp +++ b/tests/game-controller-test/Classes/GameControllerTest.cpp @@ -32,6 +32,13 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even { return; } + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + //receive back key + controller->receiveExternalKeyEvent(4,true); + //receive menu key + controller->receiveExternalKeyEvent(82,true); +#endif if (_firstHolder.controller == nullptr && _secondHolder.controller == nullptr) { @@ -41,12 +48,12 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even if (_firstHolder._holderNode) { _firstHolder.controller = controller; - _firstHolder._deviceIdLabel->setString(deviceId); + _firstHolder._deviceLabel->setString(deviceId); } else { _secondHolder.controller = controller; - _secondHolder._deviceIdLabel->setString(deviceId); + _secondHolder._deviceLabel->setString(deviceId); } } else if(_secondHolder.controller == nullptr) @@ -68,7 +75,7 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even char deviceId[20]; sprintf(deviceId,"device id:%d",controller->getDeviceId()); - _secondHolder._deviceIdLabel->setString(deviceId); + _secondHolder._deviceLabel->setString(deviceId); } else { @@ -88,7 +95,7 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even } char deviceId[20]; sprintf(deviceId,"device id:%d",controller->getDeviceId()); - _firstHolder._deviceIdLabel->setString(deviceId); + _firstHolder._deviceLabel->setString(deviceId); } } @@ -144,7 +151,7 @@ void GameControllerTest::resetControllerHolderState(ControllerHolder& holder) holder._leftJoystick->setPosition(Vec2(238,460)); holder._rightJoystick->setPosition(Vec2(606,293)); - holder._deviceIdLabel->setString("Disconnected"); + holder._deviceLabel->setString("Disconnected"); } void GameControllerTest::showButtonState(cocos2d::Controller *controller, int keyCode, bool isPressed) @@ -193,7 +200,12 @@ void GameControllerTest::showButtonState(cocos2d::Controller *controller, int ke holder->_buttonR1->setColor(Color3B(19,231,238)); break; default: - break; + { + char ketStatus[30]; + sprintf(ketStatus,"External Key Down:%d",keyCode); + holder->_externalKeyLabel->setString(ketStatus); + break; + } } } else @@ -231,7 +243,12 @@ void GameControllerTest::showButtonState(cocos2d::Controller *controller, int ke holder->_buttonR1->setColor(Color3B::WHITE); break; default: - break; + { + char ketStatus[30]; + sprintf(ketStatus,"External Key Up:%d",keyCode); + holder->_externalKeyLabel->setString(ketStatus); + break; + } } } } @@ -249,6 +266,7 @@ void GameControllerTest::onKeyUp(cocos2d::Controller *controller, int keyCode, c void GameControllerTest::onAxisEvent(cocos2d::Controller* controller, int keyCode, cocos2d::Event* event) { //onConnectController(controller,nullptr); + log("controller:%d,keyCode:%d",controller,keyCode); ControllerHolder* holder = nullptr; if (controller == _firstHolder.controller) holder = &_firstHolder; @@ -344,12 +362,16 @@ void GameControllerTest::createControllerSprite(ControllerHolder& holder) holder._rightJoystick->setPosition(Vec2(606,293)); holder._holderNode->addChild(holder._rightJoystick); - holder._deviceIdLabel = Label::createWithTTF("Disconnected","fonts/Marker Felt.ttf",36); - holder._deviceIdLabel->setPosition(Vec2(499,460)); - holder._deviceIdLabel->setTextColor(Color4B::RED); - holder._holderNode->addChild(holder._deviceIdLabel); + holder._deviceLabel = Label::createWithTTF("Disconnected","fonts/Marker Felt.ttf",36); + holder._deviceLabel->setPosition(Vec2(499,460)); + holder._deviceLabel->setTextColor(Color4B::RED); + holder._holderNode->addChild(holder._deviceLabel); + + holder._externalKeyLabel = Label::createWithTTF("External Key event","fonts/Marker Felt.ttf",36); + holder._externalKeyLabel->setPosition(Vec2(499,500)); + holder._externalKeyLabel->setTextColor(Color4B::RED); + holder._holderNode->addChild(holder._externalKeyLabel); //----------------------------------------------------------------- - //371,294 64 auto dPadTexture = Director::getInstance()->getTextureCache()->addImage("dPad.png"); auto dPadCenter = Sprite::createWithTexture(dPadTexture,Rect(60,60,68,68)); @@ -400,7 +422,6 @@ void GameControllerTest::createControllerSprite(ControllerHolder& holder) holder._buttonR2->setPosition(Vec2(998-220,910)); holder._holderNode->addChild(holder._buttonR2); //----------------------------------------------------------------- - //750 460,70 holder._buttonX = Sprite::create("X.png"); holder._buttonX->setPosition(Vec2(750 - 70,460)); holder._holderNode->addChild(holder._buttonX); diff --git a/tests/game-controller-test/Classes/GameControllerTest.h b/tests/game-controller-test/Classes/GameControllerTest.h index 26b843e534..ff94d71f28 100644 --- a/tests/game-controller-test/Classes/GameControllerTest.h +++ b/tests/game-controller-test/Classes/GameControllerTest.h @@ -53,7 +53,8 @@ private: cocos2d::Sprite* _buttonL2; cocos2d::Sprite* _buttonR2; - cocos2d::Label* _deviceIdLabel; + cocos2d::Label* _deviceLabel; + cocos2d::Label* _externalKeyLabel; }ControllerHolder; ControllerHolder _firstHolder; From ddfe82ae08826991de8595fe5587700b6b67170b Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 7 Jul 2014 15:04:29 +0800 Subject: [PATCH 08/20] Replace log with CCLOG --- cocos/base/CCController-android.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cocos/base/CCController-android.cpp b/cocos/base/CCController-android.cpp index 6d370d86d9..d333105533 100644 --- a/cocos/base/CCController-android.cpp +++ b/cocos/base/CCController-android.cpp @@ -47,19 +47,19 @@ public: auto iter = std::find_if(Controller::s_allController.begin(), Controller::s_allController.end(), [&](Controller* controller){ return (deviceName == controller->_deviceName) && (deviceId == controller->_deviceId); }); + return iter; } static void onConnected(const std::string& deviceName, int deviceId) { // Check whether the controller is already connected. - log("onConnected %s,%d", deviceName.c_str(),deviceId); + CCLOG("onConnected %s,%d", deviceName.c_str(),deviceId); auto iter = findController(deviceName, deviceId); if (iter != Controller::s_allController.end()) return; - log("onConnected new device"); // It's a new controller being connected. auto controller = new cocos2d::Controller(); controller->_deviceId = deviceId; @@ -71,11 +71,11 @@ public: static void onDisconnected(const std::string& deviceName, int deviceId) { - log("onDisconnected %s,%d", deviceName.c_str(),deviceId); + CCLOG("onDisconnected %s,%d", deviceName.c_str(),deviceId); + auto iter = findController(deviceName, deviceId); if (iter == Controller::s_allController.end()) { - log("Could not find the controller!"); CCLOGERROR("Could not find the controller!"); return; } @@ -86,11 +86,10 @@ public: static void onButtonEvent(const std::string& deviceName, int deviceId, int keyCode, bool isPressed, float value, bool isAnalog) { - log("onButtonEvent %s,%d", deviceName.c_str(),deviceId); auto iter = findController(deviceName, deviceId); if (iter == Controller::s_allController.end()) { - log("onButtonEvent new connect"); + CCLOG("onButtonEvent:connect new controller."); onConnected(deviceName, deviceId); iter = findController(deviceName, deviceId); } @@ -100,12 +99,10 @@ public: static void onAxisEvent(const std::string& deviceName, int deviceId, int axisCode, float value, bool isAnalog) { - log("onAxisEvent:%s,%d,%d,%f",deviceName.c_str(),deviceId,axisCode,value); - auto iter = findController(deviceName, deviceId); if (iter == Controller::s_allController.end()) { - log("onAxisEvent: not find,connect new"); + CCLOG("onAxisEvent:connect new controller."); onConnected(deviceName, deviceId); iter = findController(deviceName, deviceId); } From 0483c6428696955340584be386af6916a27093b7 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 7 Jul 2014 15:21:14 +0800 Subject: [PATCH 09/20] fix widget ignoreContentSize issue --- .../editor-support/cocostudio/WidgetReader/WidgetReader.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 06478699ae..01652acff0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -114,8 +114,10 @@ namespace cocostudio void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize,false)); - + bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); + if (ignoreSizeExsit) { + widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); + } widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType)); From 037a7dc8824f6ae0b3a4d5b14756a56ebf61cfe4 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 7 Jul 2014 15:22:14 +0800 Subject: [PATCH 10/20] fix TextReader TTF font Reader issue --- .../cocostudio/WidgetReader/TextReader/TextReader.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 48c3d7dbfb..9f8ff87c42 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -49,7 +49,7 @@ namespace cocostudio Text* label = static_cast(widget); - std::string jsonPath = GUIReader::getInstance()->getFilePath(); + std::string binaryFilePath = GUIReader::getInstance()->getFilePath(); for (int i = 0; i < cocoNode->GetChildNum(); ++i) { @@ -70,11 +70,7 @@ namespace cocostudio label->setFontSize(valueToInt(value)); }else if(key == P_FontName){ std::string fontFilePath; - if(FileUtils::getInstance()->isFileExist(value)){ - fontFilePath = jsonPath.append(value); - }else{ - fontFilePath = value; - } + fontFilePath = binaryFilePath.append(value); label->setFontName(fontFilePath); }else if(key == P_AreaWidth){ label->setTextAreaSize(Size(valueToFloat(value), label->getTextAreaSize().height)); From 6f33e4b84f5b5782367a0eaad6322875d22901ba Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 7 Jul 2014 15:31:06 +0800 Subject: [PATCH 11/20] add UIPageView button tests --- .../CocoStudioGUITest/CocosGUIScene.cpp | 2 +- .../UIPageViewTest/UIPageViewTest.cpp | 100 ++++++++++++++++++ .../UIPageViewTest/UIPageViewTest.h | 14 +++ .../CocoStudioGUITest/UISceneManager.cpp | 6 +- .../UITest/CocoStudioGUITest/UISceneManager.h | 1 + 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index c626b4359b..6dfc88a1b9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -183,7 +183,7 @@ g_guisTests[] = UISceneManager* sceneManager = UISceneManager::sharedUISceneManager(); sceneManager->setCurrentUISceneId(kUIPageViewTest); sceneManager->setMinUISceneId(kUIPageViewTest); - sceneManager->setMaxUISceneId(kUIPageViewTest); + sceneManager->setMaxUISceneId(kUIPageViewButtonTest); Scene* scene = sceneManager->currentUIScene(); Director::getInstance()->replaceScene(scene); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index e8ab78b8ce..ea955ea155 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -97,3 +97,103 @@ void UIPageViewTest::pageViewEvent(Ref *pSender, PageView::EventType type) break; } } + + +// UIPageViewButtonTest +UIPageViewButtonTest::UIPageViewButtonTest() +: _displayValueLabel(nullptr) +{ + +} + +UIPageViewButtonTest::~UIPageViewButtonTest() +{ +} + +bool UIPageViewButtonTest::init() +{ + if (UIScene::init()) + { + Size widgetSize = _widget->getContentSize(); + + // Add a label in which the dragpanel events will be displayed + _displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32); + _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f)); + _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, + widgetSize.height / 2.0f + + _displayValueLabel->getContentSize().height * 1.5)); + _uiLayer->addChild(_displayValueLabel); + + // Add the black background + Text* alert = Text::create("PageView with Buttons", "fonts/Marker Felt.ttf", 30); + alert->setColor(Color3B(159, 168, 176)); + alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f)); + _uiLayer->addChild(alert); + + Layout* root = static_cast(_uiLayer->getChildByTag(81)); + + Layout* background = dynamic_cast(root->getChildByName("background_Panel")); + + // Create the page view + PageView* pageView = PageView::create(); + pageView->setContentSize(Size(240.0f, 130.0f)); + Size backgroundSize = background->getContentSize(); + pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f + + (backgroundSize.width - pageView->getContentSize().width) / 2.0f, + (widgetSize.height - backgroundSize.height) / 2.0f + + (backgroundSize.height - pageView->getContentSize().height) / 2.0f)); + + pageView->removeAllPages(); + + int pageCount = 4; + for (int i = 0; i < pageCount; ++i) + { + VBox* layout = VBox::create(); + layout->setContentSize(Size(240.0f, 130.0f)); + + for (int j = 0; j < 3; j++) { + Button *btn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + btn->setName(StringUtils::format("button %d", j)); + btn->addTouchEventListener( CC_CALLBACK_2(UIPageViewButtonTest::onButtonClicked, this)); + + layout->addChild(btn); + } + + pageView->insertPage(layout,i); + } + + pageView->removePageAtIndex(0); + + pageView->addEventListener(CC_CALLBACK_2(UIPageViewButtonTest::pageViewEvent, this)); + + _uiLayer->addChild(pageView); + + return true; + } + return false; +} + +void UIPageViewButtonTest::onButtonClicked(Ref* pSender, Widget::TouchEventType type) +{ + Button *btn = (Button*)pSender; + CCLOG("button %s clicked", btn->getName().c_str()); +} + + +void UIPageViewButtonTest::pageViewEvent(Ref *pSender, PageView::EventType type) +{ + switch (type) + { + case PageView::EventType::TURNING: + { + PageView* pageView = dynamic_cast(pSender); + + _displayValueLabel->setString(CCString::createWithFormat("page = %ld", pageView->getCurPageIndex() + 1)->getCString()); + } + break; + + default: + break; + } +} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h index 7bbb1cd59b..114737a291 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.h @@ -41,4 +41,18 @@ protected: Text* _displayValueLabel; }; +class UIPageViewButtonTest : public UIScene +{ +public: + UIPageViewButtonTest(); + ~UIPageViewButtonTest(); + bool init(); + + void pageViewEvent(Ref* pSender, PageView::EventType type); + void onButtonClicked(Ref* pSender, Widget::TouchEventType type); +protected: + UI_SCENE_CREATE_FUNC(UIPageViewButtonTest) + Text* _displayValueLabel; +}; + #endif /* defined(__TestCpp__UIPageViewTest__) */ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 507c0d483b..7c590f4810 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -100,7 +100,8 @@ static const char* s_testArray[] = "UIScrollViewTest_Both", "UIScrollViewTest_ScrollToPercentBothDirection", "UIScrollViewTest_ScrollToPercentBothDirection_Bounce", - "UIPageViewTest,", + "UIPageViewTest", + "UIPageViewButtonTest", "UIListViewTest_Vertical", "UIListViewTest_Horizontal", /* @@ -344,7 +345,8 @@ Scene *UISceneManager::currentUIScene() case kUIPageViewTest: return UIPageViewTest::sceneWithTitle(s_testArray[_currentUISceneId]); - + case kUIPageViewButtonTest: + return UIPageViewButtonTest::sceneWithTitle(s_testArray[_currentUISceneId]); case kUIListViewTest_Vertical: return UIListViewTest_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 8afdc9a83c..7201d4422d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -90,6 +90,7 @@ enum kUIScrollViewTest_ScrollToPercentBothDirection, kUIScrollViewTest_ScrollToPercentBothDirection_Bounce, kUIPageViewTest, + kUIPageViewButtonTest, kUIListViewTest_Vertical, kUIListViewTest_Horizontal, /* From 9a77ea9d57bacd9f509dcea51e9db181387000b8 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 7 Jul 2014 15:48:50 +0800 Subject: [PATCH 12/20] add nested layout --- .../UIPageViewTest/UIPageViewTest.cpp | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index ea955ea155..973d6ba1ef 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -148,19 +148,30 @@ bool UIPageViewButtonTest::init() int pageCount = 4; for (int i = 0; i < pageCount; ++i) { - VBox* layout = VBox::create(); - layout->setContentSize(Size(240.0f, 130.0f)); - - for (int j = 0; j < 3; j++) { - Button *btn = Button::create("cocosui/animationbuttonnormal.png", - "cocosui/animationbuttonpressed.png"); - btn->setName(StringUtils::format("button %d", j)); - btn->addTouchEventListener( CC_CALLBACK_2(UIPageViewButtonTest::onButtonClicked, this)); + HBox* outerBox = HBox::create(); + outerBox->setContentSize(Size(240.0f, 130.0f)); + + for (int k = 0; k < 2; ++k) { + VBox* innerBox = VBox::create(); - layout->addChild(btn); + for (int j = 0; j < 3; j++) { + Button *btn = Button::create("cocosui/animationbuttonnormal.png", + "cocosui/animationbuttonpressed.png"); + btn->setName(StringUtils::format("button %d", j)); + btn->addTouchEventListener( CC_CALLBACK_2(UIPageViewButtonTest::onButtonClicked, this)); + + innerBox->addChild(btn); + } + + LinearLayoutParameter *parameter = LinearLayoutParameter::create(); + parameter->setMargin(Margin(0,0,100,0)); + innerBox->setLayoutParameter(parameter); + + outerBox->addChild(innerBox); + } - pageView->insertPage(layout,i); + pageView->insertPage(outerBox,i); } pageView->removePageAtIndex(0); From 3f262568a22c5175fcf7142d0c74fe26ed40b6e0 Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 7 Jul 2014 17:24:14 +0800 Subject: [PATCH 13/20] [ci skip: update version] --- cocos/cocos2d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/cocos2d.cpp b/cocos/cocos2d.cpp index 86a9e47df5..34b671cd8e 100644 --- a/cocos/cocos2d.cpp +++ b/cocos/cocos2d.cpp @@ -31,7 +31,7 @@ NS_CC_BEGIN const char* cocos2dVersion() { - return "cocos2d-x 3.2alpha0"; + return "cocos2d-x 3.2beta0"; } NS_CC_END From d935b5db3841aa6ec0311331002631089ddc4b1b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 7 Jul 2014 17:35:05 +0800 Subject: [PATCH 14/20] roll back initWithImage logic --- cocos/renderer/CCTexture2D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index 3449f5a7a6..571edffa06 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -711,7 +711,7 @@ std::string Texture2D::getDescription() const // implementation Texture2D (Image) bool Texture2D::initWithImage(Image *image) { - return initWithImage(image, image->getRenderFormat()); + return initWithImage(image, PixelFormat::NONE); } bool Texture2D::initWithImage(Image *image, PixelFormat format) From d1034fdaae0c24bc18e67554d38e173b8406d6c0 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 7 Jul 2014 17:47:07 +0800 Subject: [PATCH 15/20] 1.fixed lose disconnected event. 2.fixed incorrect device name and device id; --- cocos/base/CCController.h | 4 +- .../cocos2dx/lib/GameControllerActivity.java | 32 ++----- .../cocos2dx/lib/GameControllerHelper.java | 83 ++++++++++++++++--- .../cocos2dx/lib/GameControllerNibiru.java | 58 +++++++++---- .../org/cocos2dx/lib/GameControllerOuya.java | 37 +++++---- .../Classes/GameControllerTest.cpp | 20 ++--- 6 files changed, 151 insertions(+), 83 deletions(-) diff --git a/cocos/base/CCController.h b/cocos/base/CCController.h index 63997a270f..7f8d89dabc 100644 --- a/cocos/base/CCController.h +++ b/cocos/base/CCController.h @@ -99,7 +99,9 @@ public: const KeyStatus& getKeyStatus(int keyCode); - //Setting up receives external key which not contained within enum Key. + //Activate receives key event from external key. e.g. back,menu. + //Controller receives only standard key which contained within enum Key by default. + //The API only work on the android platform for support diversified game controller. void receiveExternalKeyEvent(int externalKeyCode,bool receive); void setTag(int tag) { _controllerTag = tag;} diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java index 1bad95bfa7..f5bc665c2b 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java @@ -31,11 +31,9 @@ import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListene import org.cocos2dx.lib.Cocos2dxActivity; import android.os.Bundle; -import android.view.InputDevice; import android.view.KeyEvent; import android.view.MotionEvent; import android.util.Log; -import android.util.SparseArray; public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener { // =========================================================== @@ -224,30 +222,11 @@ public abstract class GameControllerActivity extends Cocos2dxActivity implements return handled || super.dispatchGenericMotionEvent(event); } - protected SparseArray mGameController = null; - @Override public void onInputDeviceAdded(int deviceId) { Log.d(TAG,"onInputDeviceAdded:" + deviceId); - try { - InputDevice device = InputDevice.getDevice(deviceId); - int deviceSource = device.getSources(); - - if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - if (mGameController == null) { - mGameController = new SparseArray(); - } - String deviceName = device.getName(); - mGameController.append(deviceId, deviceName); - GameControllerAdapter.onConnected(deviceName, deviceId); - } - } catch (Exception e) { - e.printStackTrace(); - } - + mControllerHelper.onInputDeviceAdded(deviceId); } /* * This is an unusual case. Input devices don't typically change, but they @@ -274,10 +253,7 @@ public abstract class GameControllerActivity extends Cocos2dxActivity implements public void onInputDeviceRemoved(int deviceId) { Log.d(TAG,"onInputDeviceRemoved:" + deviceId); - if (mGameController != null && mGameController.get(deviceId) != null) { - GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId); - mGameController.delete(deviceId); - } + mControllerHelper.onInputDeviceRemoved(deviceId); } @Override @@ -293,8 +269,10 @@ public abstract class GameControllerActivity extends Cocos2dxActivity implements if (mControllerOuya != null) { mControllerOuya.onResume(); } + + mControllerHelper.gatherControllers(); } - + @Override protected void onPause() { if (mControllerNibiru != null) { diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java index 0ccf1dd714..e4c756e074 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java @@ -55,7 +55,6 @@ public class GameControllerHelper { ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START); ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT); - //KEYCODE_BUTTON_MODE } private float mOldLeftThumbstickX = 0.0f; @@ -78,68 +77,71 @@ public class GameControllerHelper { || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) { if (event.getAction() == MotionEvent.ACTION_MOVE) { - int devicedId = event.getDeviceId(); + int deviceId = event.getDeviceId(); String deviceName = event.getDevice().getName(); + if(mGameController.get(deviceId) == null){ + mGameController.append(deviceId, deviceName); + } float newAXIS_LX = event.getAxisValue(AXIS_X); if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true); mOldLeftThumbstickX = newAXIS_LX; handled = true; } float newAXIS_LY = event.getAxisValue(AXIS_Y); if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true); mOldLeftThumbstickY = newAXIS_LY; handled = true; } float newAXIS_RX = event.getAxisValue(AXIS_Z); if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true); mOldRightThumbstickX = newAXIS_RX; handled = true; } float newAXIS_RY = event.getAxisValue(AXIS_RZ); if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true); mOldRightThumbstickY = newAXIS_RY; handled = true; } float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER); if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true); mOldLeftTrigger = newAXIS_LTRIGGER; handled = true; } float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER); if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true); mOldRightTrigger = newAXIS_RTRIGGER; handled = true; } float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE); if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true); mOldBrake = newAXIS_BRAKE; handled = true; } float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE); if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true); mOldThrottle = newAXIS_THROTTLE; handled = true; } float newAXIS_GAS = event.getAxisValue(AXIS_GAS); if (Float.compare(newAXIS_GAS , mOldGas) != 0) { - GameControllerAdapter.onAxisEvent(deviceName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true); + GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true); mOldGas = newAXIS_GAS; handled = true; } @@ -162,6 +164,12 @@ public class GameControllerHelper { || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) { int deviceId = event.getDeviceId(); + String deviceName = event.getDevice().getName(); + + if(mGameController.get(deviceId) == null){ + mGameController.append(deviceId, deviceName); + } + if (controllerKey == 0) { if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) { controllerKey = keyCode; @@ -173,10 +181,10 @@ public class GameControllerHelper { int action = event.getAction(); if (action == KeyEvent.ACTION_DOWN) { handled = true; - GameControllerAdapter.onButtonEvent(event.getDevice().getName(),event.getDeviceId(), controllerKey,true, 1.0f, false); + GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false); }else if (action == KeyEvent.ACTION_UP) { handled = true; - GameControllerAdapter.onButtonEvent(event.getDevice().getName(),event.getDeviceId(), controllerKey,false, 0.0f, false); + GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false); } } @@ -195,4 +203,53 @@ public class GameControllerHelper { } } } + + SparseArray mGameController = new SparseArray(); + + void onInputDeviceAdded(int deviceId){ + try { + InputDevice device = InputDevice.getDevice(deviceId); + int deviceSource = device.getSources(); + + if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) + || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) + { + String deviceName = device.getName(); + mGameController.append(deviceId, deviceName); + GameControllerAdapter.onConnected(deviceName, deviceId); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + void onInputDeviceChanged(int deviceId){ + gatherControllers(); + } + + void onInputDeviceRemoved(int deviceId) { + if (mGameController.get(deviceId) != null) { + GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId); + mGameController.delete(deviceId); + } + } + + void gatherControllers(){ + int controllerCount = mGameController.size(); + for (int i = 0; i < controllerCount; i++) { + try { + int controllerDeveceId = mGameController.keyAt(i); + InputDevice device = InputDevice.getDevice(controllerDeveceId); + if (device == null) { + GameControllerAdapter.onDisconnected(mGameController.get(controllerDeveceId), controllerDeveceId); + mGameController.delete(controllerDeveceId); + } + } catch (Exception e) { + int controllerDeveceId = mGameController.keyAt(i); + GameControllerAdapter.onDisconnected(mGameController.get(controllerDeveceId), controllerDeveceId); + mGameController.delete(controllerDeveceId); + e.printStackTrace(); + } + } + } } diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java index c53a661500..34983ab812 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java @@ -27,7 +27,6 @@ public class GameControllerNibiru implements OnControllerSeviceListener, OnKeyLi OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameControllerDelegate { private static final String TAG = "NibiruTag"; - private static final String mVendorName = "Nibiru"; private Context mContext; private SparseIntArray mKeyMap; @@ -132,7 +131,14 @@ OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameContr } if (mControllerEventListener != null) { - mControllerEventListener.onButtonEvent(mVendorName, playerOrder, mKeyMap.get(keyCode), true, 1.0f, false); + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(), + mKeyMap.get(keyCode), true, 1.0f, false); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } } } @@ -144,28 +150,52 @@ OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameContr } if (mControllerEventListener != null) { - mControllerEventListener.onButtonEvent(mVendorName, playerOrder, - mKeyMap.get(keyCode), false, 0.0f, false); + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(), + mKeyMap.get(keyCode), false, 0.0f, false); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } } } @Override public void onLeftStickChanged(int playerOrder, float x, float y) { if (mControllerEventListener != null) { - mControllerEventListener.onAxisEvent(mVendorName, playerOrder, - GameControllerDelegate.THUMBSTICK_LEFT_X, x, true); - mControllerEventListener.onAxisEvent(mVendorName, playerOrder, - GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true); + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + String deviceName = controllerDevice.getDeviceName(); + int deviceId = controllerDevice.getDeviceId(); + + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_LEFT_X, x, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } } } @Override public void onRightStickChanged(int playerOrder, float x, float y) { if (mControllerEventListener != null) { - mControllerEventListener.onAxisEvent(mVendorName, playerOrder, - GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true); - mControllerEventListener.onAxisEvent(mVendorName, playerOrder, - GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true); + try { + ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder); + + String deviceName = controllerDevice.getDeviceName(); + int deviceId = controllerDevice.getDeviceId(); + + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, + GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true); + } catch (ControllerServiceException e) { + e.printStackTrace(); + } } } @@ -174,11 +204,11 @@ OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameContr if (mControllerEventListener != null) { if (state == ControllerDevice.STATE_CONN) { - mControllerEventListener.onConnected(mVendorName, playerOrder); + mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId()); } else if (state == ControllerDevice.STATE_DISCONN) { - mControllerEventListener.onDisconnected(mVendorName, playerOrder); + mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId()); } } } diff --git a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java index 903449cdd3..ca6ccede4f 100644 --- a/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java +++ b/cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java @@ -10,8 +10,6 @@ import android.view.KeyEvent; import android.view.MotionEvent; public class GameControllerOuya implements GameControllerDelegate{ - - public static final String sVendorName = "Ouya"; private SparseIntArray mKeyMap; @@ -61,27 +59,28 @@ public class GameControllerOuya implements GameControllerDelegate{ if (handled && mControllerEventListener != null) { - OuyaController c = OuyaController.getControllerByDeviceId(event.getDeviceId()); - int controllerID = OuyaController.getPlayerNumByDeviceId(event.getDeviceId()); + int deviceId = event.getDeviceId(); + String deviceName = event.getDevice().getName(); + OuyaController c = OuyaController.getControllerByDeviceId(deviceId); float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2); if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true); mOldLeftTrigger = newLeftTrigger; } float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2); if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true); mOldRightTrigger = newRightTrigger; } float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X); if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) { if (Float.compare(newLeftThumbstickX, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true); }else { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true); } mOldLeftThumbstickX = newLeftThumbstickX; } @@ -89,9 +88,9 @@ public class GameControllerOuya implements GameControllerDelegate{ float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y); if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) { if (Float.compare(newLeftThumbstickY, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true); }else { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true); } mOldLeftThumbstickY = newLeftThumbstickY; } @@ -99,9 +98,9 @@ public class GameControllerOuya implements GameControllerDelegate{ float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X); if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) { if (Float.compare(newRightThumbstickX, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true); }else { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true); } mOldRightThumbstickX = newRightThumbstickX; } @@ -109,9 +108,9 @@ public class GameControllerOuya implements GameControllerDelegate{ float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y); if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) { if (Float.compare(newRightThumbstickY, 0.0f) == 0) { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true); }else { - mControllerEventListener.onAxisEvent(sVendorName, controllerID, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true); + mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true); } mOldRightThumbstickY = newRightThumbstickY; } @@ -122,9 +121,14 @@ public class GameControllerOuya implements GameControllerDelegate{ public boolean dispatchKeyEvent(KeyEvent event) { boolean handled = false; + int action = event.getAction(); int keyCode = event.getKeyCode(); + if (keyCode == KeyEvent.KEYCODE_BUTTON_L2 || keyCode == KeyEvent.KEYCODE_BUTTON_R2) { + return true; + } + if (action == KeyEvent.ACTION_DOWN) { handled = OuyaController.onKeyDown(keyCode, event); } @@ -139,11 +143,10 @@ public class GameControllerOuya implements GameControllerDelegate{ isAnalog = true; } - int controllerID = OuyaController.getPlayerNumByDeviceId(event.getDeviceId()); if (action == KeyEvent.ACTION_DOWN) { - mControllerEventListener.onButtonEvent(sVendorName, controllerID, mKeyMap.get(keyCode), true, 1.0f, isAnalog); + mControllerEventListener.onButtonEvent(event.getDevice().getName(), event.getDeviceId(), mKeyMap.get(keyCode), true, 1.0f, isAnalog); }else { - mControllerEventListener.onButtonEvent(sVendorName, controllerID, mKeyMap.get(keyCode), false, 0.0f, isAnalog); + mControllerEventListener.onButtonEvent(event.getDevice().getName(), event.getDeviceId(), mKeyMap.get(keyCode), false, 0.0f, isAnalog); } } diff --git a/tests/game-controller-test/Classes/GameControllerTest.cpp b/tests/game-controller-test/Classes/GameControllerTest.cpp index c340b2772c..9c1dcbbe5f 100644 --- a/tests/game-controller-test/Classes/GameControllerTest.cpp +++ b/tests/game-controller-test/Classes/GameControllerTest.cpp @@ -73,9 +73,9 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even this->addChild(_secondHolder._holderNode); } - char deviceId[20]; - sprintf(deviceId,"device id:%d",controller->getDeviceId()); - _secondHolder._deviceLabel->setString(deviceId); + char deviceInfo[50]; + sprintf(deviceInfo,"%s id:%d",controller->getDeviceName().c_str(), controller->getDeviceId()); + _secondHolder._deviceLabel->setString(deviceInfo); } else { @@ -93,9 +93,9 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even _firstHolder._holderNode->setPosition(Vec2(_visibleThreeQuarterX, _visibleCentreY)); this->addChild(_firstHolder._holderNode); } - char deviceId[20]; - sprintf(deviceId,"device id:%d",controller->getDeviceId()); - _firstHolder._deviceLabel->setString(deviceId); + char deviceInfo[50]; + sprintf(deviceInfo,"%s id:%d",controller->getDeviceName().c_str(), controller->getDeviceId()); + _firstHolder._deviceLabel->setString(deviceInfo); } } @@ -202,7 +202,7 @@ void GameControllerTest::showButtonState(cocos2d::Controller *controller, int ke default: { char ketStatus[30]; - sprintf(ketStatus,"External Key Down:%d",keyCode); + sprintf(ketStatus,"Key Down:%d",keyCode); holder->_externalKeyLabel->setString(ketStatus); break; } @@ -245,7 +245,7 @@ void GameControllerTest::showButtonState(cocos2d::Controller *controller, int ke default: { char ketStatus[30]; - sprintf(ketStatus,"External Key Up:%d",keyCode); + sprintf(ketStatus,"Key Up:%d",keyCode); holder->_externalKeyLabel->setString(ketStatus); break; } @@ -265,8 +265,6 @@ void GameControllerTest::onKeyUp(cocos2d::Controller *controller, int keyCode, c void GameControllerTest::onAxisEvent(cocos2d::Controller* controller, int keyCode, cocos2d::Event* event) { - //onConnectController(controller,nullptr); - log("controller:%d,keyCode:%d",controller,keyCode); ControllerHolder* holder = nullptr; if (controller == _firstHolder.controller) holder = &_firstHolder; @@ -367,7 +365,7 @@ void GameControllerTest::createControllerSprite(ControllerHolder& holder) holder._deviceLabel->setTextColor(Color4B::RED); holder._holderNode->addChild(holder._deviceLabel); - holder._externalKeyLabel = Label::createWithTTF("External Key event","fonts/Marker Felt.ttf",36); + holder._externalKeyLabel = Label::createWithTTF("Key event","fonts/Marker Felt.ttf",36); holder._externalKeyLabel->setPosition(Vec2(499,500)); holder._externalKeyLabel->setTextColor(Color4B::RED); holder._holderNode->addChild(holder._externalKeyLabel); From 9cf01c0e4756d4522952178d21380deeaceb1ef9 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 7 Jul 2014 17:57:08 +0800 Subject: [PATCH 16/20] update test case --- .../Classes/GameControllerTest.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/game-controller-test/Classes/GameControllerTest.cpp b/tests/game-controller-test/Classes/GameControllerTest.cpp index 9c1dcbbe5f..ef27469315 100644 --- a/tests/game-controller-test/Classes/GameControllerTest.cpp +++ b/tests/game-controller-test/Classes/GameControllerTest.cpp @@ -40,20 +40,20 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even controller->receiveExternalKeyEvent(82,true); #endif - if (_firstHolder.controller == nullptr && _secondHolder.controller == nullptr) - { - char deviceId[20]; - sprintf(deviceId,"device id:%d",controller->getDeviceId()); + char deviceInfo[50]; + sprintf(deviceInfo,"%s id:%d",controller->getDeviceName().c_str(), controller->getDeviceId()); + if (_firstHolder.controller == nullptr && _secondHolder.controller == nullptr) + { if (_firstHolder._holderNode) { _firstHolder.controller = controller; - _firstHolder._deviceLabel->setString(deviceId); + _firstHolder._deviceLabel->setString(deviceInfo); } else { _secondHolder.controller = controller; - _secondHolder._deviceLabel->setString(deviceId); + _secondHolder._deviceLabel->setString(deviceInfo); } } else if(_secondHolder.controller == nullptr) @@ -73,8 +73,6 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even this->addChild(_secondHolder._holderNode); } - char deviceInfo[50]; - sprintf(deviceInfo,"%s id:%d",controller->getDeviceName().c_str(), controller->getDeviceId()); _secondHolder._deviceLabel->setString(deviceInfo); } else @@ -93,8 +91,7 @@ void GameControllerTest::onConnectController(Controller* controller, Event* even _firstHolder._holderNode->setPosition(Vec2(_visibleThreeQuarterX, _visibleCentreY)); this->addChild(_firstHolder._holderNode); } - char deviceInfo[50]; - sprintf(deviceInfo,"%s id:%d",controller->getDeviceName().c_str(), controller->getDeviceId()); + _firstHolder._deviceLabel->setString(deviceInfo); } } @@ -361,7 +358,7 @@ void GameControllerTest::createControllerSprite(ControllerHolder& holder) holder._holderNode->addChild(holder._rightJoystick); holder._deviceLabel = Label::createWithTTF("Disconnected","fonts/Marker Felt.ttf",36); - holder._deviceLabel->setPosition(Vec2(499,460)); + holder._deviceLabel->setPosition(Vec2(499,650)); holder._deviceLabel->setTextColor(Color4B::RED); holder._holderNode->addChild(holder._deviceLabel); From bbf0fead9110c5770eca5fe7afaadd148415cf49 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 7 Jul 2014 18:25:53 +0800 Subject: [PATCH 17/20] update API annotation. --- cocos/base/CCController.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cocos/base/CCController.h b/cocos/base/CCController.h index 7f8d89dabc..46aabbc283 100644 --- a/cocos/base/CCController.h +++ b/cocos/base/CCController.h @@ -99,9 +99,13 @@ public: const KeyStatus& getKeyStatus(int keyCode); - //Activate receives key event from external key. e.g. back,menu. - //Controller receives only standard key which contained within enum Key by default. - //The API only work on the android platform for support diversified game controller. + /** Activate receives key event from external key. e.g. back,menu. + * Controller receives only standard key which contained within enum Key by default. + * @warning The API only work on the android platform for support diversified game controller. + * + * @param externalKeyCode external key code + * @param receive true if external key event on this controller should be receive, false otherwise. + */ void receiveExternalKeyEvent(int externalKeyCode,bool receive); void setTag(int tag) { _controllerTag = tag;} From fd7f3dba4b3ef084bc94f60db81bcef599901559 Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 7 Jul 2014 19:59:41 +0800 Subject: [PATCH 18/20] [ci skip] --- docs/RELEASE_NOTES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.md index c93588166a..0ebf4815cd 100644 --- a/docs/RELEASE_NOTES.md +++ b/docs/RELEASE_NOTES.md @@ -27,7 +27,7 @@ * Download: http://cdn.cocos2d-x.org/cocos2d-x-3.2rc0.zip * Full Changelog: https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.2rc0/CHANGELOG -* API Reference: http://www.cocos2d-x.org/reference/native-cpp/V3.2beta0/index.html +* API Reference: http://www.cocos2d-x.org/reference/native-cpp/V3.2rc0/index.html * v3.0 Release Notes can be found here: [v3.0 Release Notes](https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.0/docs/RELEASE_NOTES.md) # Requirements @@ -116,7 +116,7 @@ Please refer to this document: [ReadMe](../README.md) # Highlights of v3.2rc0 -* `fbx-conv` support generating binary format, and `Sprite3D` support it, and about +* `fbx-conv` support generating binary format, and `Sprite3D` support it * about 20% performance improved in `Sprite3D` * game controller support * fast tilemap support, it is faster for static tilemap From fa62f4273f332a4ba60f6c0561b8b9c529fbb5f8 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Mon, 7 Jul 2014 10:14:57 -0700 Subject: [PATCH 19/20] fixed missing zlib.h header path --- cocos/2d/cocos2d_wp8_headers.props | 2 +- cocos/editor-support/cocostudio/proj.wp8/libCocosStudio.vcxproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/cocos2d_wp8_headers.props b/cocos/2d/cocos2d_wp8_headers.props index d9e60d6d8c..ca110ab470 100644 --- a/cocos/2d/cocos2d_wp8_headers.props +++ b/cocos/2d/cocos2d_wp8_headers.props @@ -7,7 +7,7 @@ - $(EngineRoot)cocos\platform\wp8;$(EngineRoot)cocos\platform\winrt;$(EngineRoot)\external\winrt-specific\angle\include;$(EngineRoot)\external\curl\include\wp8;$(EngineRoot)\external\winrt-specific;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external;$(EngineRoot)cocos\editor-support;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(GeneratedFilesDir) + $(EngineRoot)cocos\platform\wp8;$(EngineRoot)cocos\platform\winrt;$(EngineRoot)\external\winrt-specific\angle\include;$(EngineRoot)\external\curl\include\wp8;$(EngineRoot)\external\winrt-specific;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external;$(EngineRoot)cocos\editor-support;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\wp8-specific\zlib\include;$(GeneratedFilesDir) _VARIADIC_MAX=10;NOMINMAX;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true true diff --git a/cocos/editor-support/cocostudio/proj.wp8/libCocosStudio.vcxproj b/cocos/editor-support/cocostudio/proj.wp8/libCocosStudio.vcxproj index f235f18d40..8002859cb3 100644 --- a/cocos/editor-support/cocostudio/proj.wp8/libCocosStudio.vcxproj +++ b/cocos/editor-support/cocostudio/proj.wp8/libCocosStudio.vcxproj @@ -77,7 +77,7 @@ Use pch.h $(WindowsSDK_MetadataPath);$(AdditionalUsingDirectories) - $(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support;$(EngineRoot)external;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\wp8-specific\zlib\include;$(EngineRoot)extensions;%(AdditionalIncludeDirectories) + $(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos\editor-support;$(EngineRoot)external;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;%(AdditionalIncludeDirectories) WP8;_DEBUG;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 4267;4251;4244;%(DisableSpecificWarnings) /Zm200 %(AdditionalOptions) From 021ee7d1e7c8b43ce5e16f400b1db7851bb87920 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Mon, 7 Jul 2014 11:17:05 -0700 Subject: [PATCH 20/20] check if _itemsPerRow == 0 to avoid divide by zero --- cocos/2d/CCLabelAtlas.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos/2d/CCLabelAtlas.cpp b/cocos/2d/CCLabelAtlas.cpp index be8c324ed2..886091396d 100644 --- a/cocos/2d/CCLabelAtlas.cpp +++ b/cocos/2d/CCLabelAtlas.cpp @@ -133,6 +133,11 @@ bool LabelAtlas::initWithString(const std::string& theString, const std::string& //CCLabelAtlas - Atlas generation void LabelAtlas::updateAtlasValues() { + if(_itemsPerRow == 0) + { + return; + } + ssize_t n = _string.length(); const unsigned char *s = (unsigned char*)_string.c_str();