void SceneEditorScreenMain::OnSelectBody(BaseObject * owner, void * userData, void * callerData) { UIButton *btn = (UIButton *)owner; for(int32 i = 0; i < (int32)bodies.size(); ++i) { if(bodies[i]->bodyControl->GetParent()) { if(btn == bodies[i]->headerButton) { // click on selected body - nothing to do return; } if(libraryControl->GetParent()) { RemoveControl(libraryControl); bodies[i]->bodyControl->UpdateLibraryState(false, libraryControl->GetRect().dx); } RemoveControl(bodies[i]->bodyControl); bodies[i]->headerButton->SetSelected(false, false); } } AddControl(bodies[btn->GetTag()]->bodyControl); bodies[btn->GetTag()]->headerButton->SetSelected(true, false); if(libraryControl->GetParent()) { BringChildFront(libraryControl); } }
void TaskChatLayer::processGuildChat(int type, bool visible) { UIButton* btnLeft = taskChatLayout->FindChildObjectByName<UIButton>("ItemExchangShopBtn"); UILabel* labelLeft = taskChatLayout->FindChildObjectByName<UILabel>("ItemExchangText"); btnLeft->setVisible(visible); labelLeft->setVisible(visible); // type 10 11 12 13 分别代表公会商人、祈福、活动、排行 if(type == 10) { labelLeft->setString(Localizatioin::getLocalization("G_SHOP_TITLE")); } else if(type == 11) { labelLeft->setString(Localizatioin::getLocalization("G_BENEDICTION_TITLE")); } else if(type == 12) { labelLeft->setString(Localizatioin::getLocalization("G_INSTANCE")); } else if(type == 13) { labelLeft->setString(Localizatioin::getLocalization("G_RANK")); } mShopType = type; }
FogControl::FogControl(const Rect & rect, FogControlDelegate *newDelegate) : UIControl(rect) { ControlsFactory::CustomizeDialog(this); delegate = newDelegate; Rect propertyRect(0, 0, rect.dx, rect.dy - ControlsFactory::BUTTON_HEIGHT); fogProperties = new PropertyList(propertyRect, NULL); AddControl(fogProperties); ControlsFactory::AddFogSubsection(fogProperties, true, 0.006f, Color::White()); Rect buttonRect(0, rect.dy - ControlsFactory::BUTTON_HEIGHT, rect.dx / 2, ControlsFactory::BUTTON_HEIGHT); UIButton *btnCancel = ControlsFactory::CreateButton(buttonRect, LocalizedString(L"dialog.cancel")); btnCancel->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &FogControl::OnCancel)); AddControl(btnCancel); SafeRelease(btnCancel); buttonRect.x = rect.dx - buttonRect.dx; UIButton *btnCreate = ControlsFactory::CreateButton(buttonRect, LocalizedString(L"dialog.set")); btnCreate->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &FogControl::OnSet)); AddControl(btnCreate); SafeRelease(btnCreate); }
void PromptBox::buttonClicked(CCObject *pSender, TouchEventType eType) { if (eType != TOUCH_EVENT_ENDED) { return; } ::playSound("music/click.ogg"); UIButton *button = dynamic_cast<UIButton*>(pSender) ; int tag = button->getTag() ; switch (tag) { case ButtonTag_Cancel: { removeFromParent(); } break; case ButtonTag_Confirm: { CCDirector::sharedDirector()->end(); } break; default: break; } }
NS_CC_BEGIN /** * 创建 */ UIButton* UIButton::create(const char *upSprite,const char *downSprite) { UIButton *node = new UIButton(); if (node) { node->_up = CCSprite::create(upSprite); node->_down = CCSprite::create(downSprite); node->upPngName = upSprite; node->downPngName = downSprite; if (node->_up && node->_down) { node->addChild(node->_up); node->addChild(node->_down ); node->_up->setVisible(true); node->_down->setVisible(false); node->autorelease(); return node; } } CC_SAFE_DELETE(node); return NULL; }
void GameWeekRewardLayer::BindingUIItems(CCObject *p) { CCString str; str.initWithFormat("%d%d",eNetMsgTypeMissionSys, eNetMsgMissionSysWeekRewardKind); CSJson::Value root = XQDate::sharedInstance().GetDate(str.getCString()); bool isShowBtn = false; for (int i = 0; i < root.size(); i ++) { CSJson::Value & val = root[i]; if (val["iscomplete"].asInt() == 1) { isShowBtn = true; } } ul = UILayer::create(); addChild(ul, 1); auto myLayout = static_cast<Layout*>(GUIReader::shareReader() -> widgetFromJsonFile("./CocoStudioResources/WeekRewardLayer.json")); ul -> addWidget(myLayout); UIPanel *myPanel = dynamic_cast<UIPanel*>(ul -> getWidgetByName("Panel_2")); myPanel -> addReleaseEvent(this, coco_releaseselector(GameWeekRewardLayer::touchWindow)); // bind ui images UIButton *btn = dynamic_cast<UIButton*>(ul -> getWidgetByName("LotteryBtn")); if (isShowBtn) { btn->disable(); btn->setVisible(false); } else { btn -> addReleaseEvent(this, coco_releaseselector(GameWeekRewardLayer::getWeekRewardBtnClick)); } //设置字体不被选中; }
// Initialize the control(s) attached. void UIButtonMetadata::InitializeControl(const String& controlName, const Vector2& position) { BaseMetadata::InitializeControl(controlName, position); int paramsCount = this->GetParamsCount(); for (BaseMetadataParams::METADATAPARAMID i = 0; i < paramsCount; i ++) { UIButton* button = dynamic_cast<UIButton*>(this->treeNodeParams[i].GetUIControl()); WideString controlText = StringToWString(button->GetName()); HierarchyTreeNode* activeNode = GetTreeNode(i); // Initialize the button for all states. int statesCount = UIControlStateHelper::GetUIControlStatesCount(); for (int stateID = 0; stateID < statesCount; stateID ++) { UIControl::eControlState state = UIControlStateHelper::GetUIControlState(stateID); button->SetStateFont(state, EditorFontManager::Instance()->GetDefaultFont()); button->SetStateText(state, controlText); // Button is state-aware. activeNode->GetExtraData().SetLocalizationKey(controlText, state); } // Define some properties for the reference state. button->SetStateDrawType(GetReferenceState(), UIControlBackground::DRAW_SCALE_TO_RECT); } }
void CocosGUIExamplesRegisterScene::onEnter() { CCScene::onEnter(); m_pUILayer = UILayer::create(); m_pUILayer->scheduleUpdate(); addChild(m_pUILayer); // register root from json m_pLayout = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("cocosgui/gui_examples/register_1/register_1.json")); m_pUILayer->addWidget(m_pLayout); // e-mail layout UILayout* eMail_layout = dynamic_cast<UILayout*>(m_pLayout->getChildByName("e-mail_Panel")); // ui node container add to e-mail layout UINodeContainer* nodeContainer = UINodeContainer::create(); nodeContainer->setPosition(ccp(eMail_layout->getContentSize().width / 2, eMail_layout->getContentSize().height / 2)); #if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) && (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) // CCEditBox add to ui node container CCSize editBoxSize = eMail_layout->getContentSize(); CCEditBox* email_editBox = CCEditBox::create(editBoxSize, CCScale9Sprite::create("cocosgui/gui_examples/register_1/e-mail.png")); email_editBox->setFontName("SongTypeFont"); email_editBox->setFontSize(20); email_editBox->setPlaceholderFontColor(ccc3(127, 127, 127)); email_editBox->setPlaceHolder("Email"); email_editBox->setInputMode(kEditBoxInputModeEmailAddr); nodeContainer->addCCNode(email_editBox); // add ui node container to layout eMail_layout->addChild(nodeContainer); #else #pragma message ("Warning: CCEditBox not implmented for CC_PLATFORM_WINRT and CC_PLATFORM_WP8") #endif // content panel UILayout* content_panel = dynamic_cast<UILayout*>(m_pLayout->getChildByName("content_Panel")); // password textfield add event UITextField* passwordAgin_textfield = dynamic_cast<UITextField*>(content_panel->getChildByName("password agin_TextField")); passwordAgin_textfield->addAttachWithIMEEvent(this, coco_TextField_AttachWithIME_selector(CocosGUIExamplesRegisterScene::attachWithIMEEvent)); passwordAgin_textfield->addDetachWithIMEEvent(this, coco_TextField_DetachWithIME_selector(CocosGUIExamplesRegisterScene::detachWithIMEEvent)); // register button UILayout* register_button_panel = dynamic_cast<UILayout*>(m_pLayout->getChildByName("register button_Panel")); UIButton* button = dynamic_cast<UIButton*>(register_button_panel->getChildByName("register_Button")); button->addReleaseEvent(this, coco_releaseselector(CocosGUIExamplesRegisterScene::toCocosGUIExamplesEquipScene)); // back button UIButton* back_button = UIButton::create(); back_button->setTouchEnable(true); back_button->loadTextures("cocosgui/UITest/b1.png", "cocosgui/UITest/b2.png", ""); back_button->setPosition(ccp(back_button->getContentSize().width, back_button->getContentSize().height)); back_button->addReleaseEvent(this, coco_releaseselector(CocosGUIExamplesRegisterScene::toCocosGUIScene)); // back_button->addReleaseEvent(this, coco_releaseselector(CocosGUIExamplesRegisterScene::toCocosGUIExamplesStartScene)); m_pUILayer->addWidget(back_button); }
//---------------------------------------------------------------------------- void UIAuiManager::SetActiveTableFrame(const std::string &tabName) { std::map<std::string, UIButtonPtr>::iterator it = mAuiTabButs.find(tabName); if (it != mAuiTabButs.end()) { UIButton *tabBut = it->second; UIFrame *uiContentFrame = mAuiContentFrames[tabBut]; UITabFrame *tabFrame = DynamicCast<UITabFrame>( uiContentFrame->GetParent()->GetParent()); tabFrame->_SetActiveTab(tabBut->GetName()); if (mActiveTableBut) { mActiveTableBut->SetActivate(false); mActiveTableBut = 0; } if (mActiveTableContentFrame) { mActiveTableContentFrame->SetActivate(false); mActiveTableContentFrame = 0; } mActiveTableBut = tabBut; mActiveTableContentFrame = uiContentFrame; if (mActiveTableBut) mActiveTableBut->SetActivate(true); if (mActiveTableContentFrame) mActiveTableContentFrame->SetActivate(true); } }
void LayerBaCayAvatar::vaoBanChoi(CCObject *obj,TouchEventType type) { UIButton *abc = (UIButton*)obj; int tag=abc->getTag(); if(type==TOUCH_EVENT_ENDED) if(tag==1) { //yêu cầu làm khách boost::shared_ptr<IRequest> request (new PlayerToSpectatorRequest()); GameServer::getSingleton().getSmartFox()->Send(request); btn_vaochoi->setEnabled(true); btn_dungday->setEnabled(false); //yêu cầu rời game boost::shared_ptr<ISFSObject> params (new SFSObject()); boost::shared_ptr<Room> lastRoom = GameServer::getSingleton().getSmartFox()->LastJoinedRoom(); boost::shared_ptr<IRequest> req (new ExtensionRequest("rqlg", params, lastRoom)); GameServer::getSingleton().getSmartFox()->Send(req); }/// else{ //yêu cầu vào chơi boost::shared_ptr<IRequest> request (new SpectatorToPlayerRequest()); GameServer::getSingleton().getSmartFox()->Send(request); CCLog("da vao"); btn_vaochoi->setEnabled(false); btn_dungday->setEnabled(true); //yêu cầu join game boost::shared_ptr<ISFSObject> params (new SFSObject()); boost::shared_ptr<Room> lastRoom = GameServer::getSingleton().getSmartFox()->LastJoinedRoom(); boost::shared_ptr<IRequest> req2 (new ExtensionRequest("rqjg", params, lastRoom)); GameServer::getSingleton().getSmartFox()->Send(req2); } }
void FrontCoverLayer::setLastLoginSever() { if(m_layout) { UIButton* button = m_layout->FindChildObjectByName<UIButton>("latestSeverBt"); if(button) { const char* ip = UserData::GetLastIP(); unsigned int port = UserData::GetLastPort(); const char* name = UserData::GetLastServerName(); if(*ip == '\0' || port == 0) { button->setEnabled(false); } else { UILabelTTF* label = button->getTextLabel(); if(label) { label->setString(name); } } } } }
CreateNodesDialog::CreateNodesDialog(const Rect & rect) : DraggableDialog(rect) { ControlsFactory::CustomizeDialog(this); sceneNode = NULL; scene = NULL; dialogDelegate = NULL; propertyList = 0; header = new UIStaticText(Rect(0, 0, rect.dx, ControlsFactory::BUTTON_HEIGHT)); header->SetFont(ControlsFactory::GetFont12()); header->SetTextColor(ControlsFactory::GetColorLight()); header->SetAlign(ALIGN_HCENTER | ALIGN_VCENTER); AddControl(header); float32 buttonY = rect.dy - ControlsFactory::BUTTON_HEIGHT; float32 buttonX = (rect.dx - ControlsFactory::BUTTON_WIDTH * 2) / 2; UIButton *btnCancel = ControlsFactory::CreateButton(Vector2(buttonX, buttonY), LocalizedString(L"dialog.cancel")); btnCancel->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &CreateNodesDialog::OnCancel)); AddControl(btnCancel); buttonX += ControlsFactory::BUTTON_WIDTH; UIButton *btnOk = ControlsFactory::CreateButton(Vector2(buttonX, buttonY), LocalizedString(L"dialog.ok")); btnOk->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &CreateNodesDialog::OnOk)); AddControl(btnOk); propertyRect = Rect(0, ControlsFactory::BUTTON_HEIGHT, rect.dx, buttonY - ControlsFactory::BUTTON_HEIGHT); SafeRelease(btnCancel); SafeRelease(btnOk); }
void UIButtonMetadata::UpdateExtraData(HierarchyTreeNodeExtraData& extraData, eExtraDataUpdateStyle updateStyle) { if (!VerifyActiveParamID()) { return; } UIButton* button = GetActiveUIButton(); // Button is state-aware. int statesCount = UIControlStateHelper::GetUIControlStatesCount(); for (int stateID = 0; stateID < statesCount; stateID ++) { UIControl::eControlState state = UIControlStateHelper::GetUIControlState(stateID); UIStaticText* textControl = button->GetStateTextControl(state); if (!textControl) { continue; } UpdateStaticTextExtraData(textControl, state, extraData, updateStyle); } if (updateStyle == UPDATE_EXTRADATA_FROM_CONTROL) { // Also need to recover Dirty Flags in this case. RecoverPropertyDirtyFlags(); } }
void OnButtonClick_1(void *sender, void*args) { UIButton *button = static_cast<UIButton*>(sender); std::cout << "OnButtonClick_1 : " << button->getTag() << std::endl; button->setPosX(button->getPosX() + 10); }
void TestCase::AddReturnButton(UIScreen* pUIScreen) { UIButton* pButton = new UIButton(pUIScreen, IMath::VEC2_ZERO, "RETURN"); Vector2 pos(0.0f, ScreenUtil::GetInstance().GetScreenHeight() - pButton->GetSize().y); pButton->SetPosition(pos); pButton->ConnectEvent(UMI_CLICKED, this, (MSG_CALLBACK)&TestCase::OnBtnReturnClicked); }
void LayerChatWindow::onButtonChats( CCObject* pSender, TouchEventType type ) { UIButton* btnChat = dynamic_cast<UIButton*>(pSender); if(type == TOUCH_EVENT_ENDED){ CCLog("onButtonChats %s", btnChat->getTitleText()); txtChat->setText( btnChat->getTitleText() ); } }
void GameLayer_Menu::addTaskBtnCallback(cocos2d::CCObject *target, SEL_CallFuncO callfun) { UIButton* taskBtn = dynamic_cast<UIButton*>(gameMenu->getWidgetByName("SysInfoBtn")); taskBtn->addReleaseEvent(target, callfun); taskBtn->setPressedActionEnabled(true); }
void PlayScene::onBtnMoveClothes(CCObject *target) { UIButton* btn = (UIButton *)ui_layer_->getWidgetByName(btn_name[sub_stage_id_]); if (btn) { CCPoint move_pos = btn->getTouchMovePos(); btn->setPosition(move_pos); } CCLOG("%s\n", __FUNCTION__); }
void LayerChatWindow::OnEmoClick( CCObject* pSender, TouchEventType type ) { UIButton* btn = dynamic_cast<UIButton*>(pSender); if( type == TOUCH_EVENT_ENDED ){ CCLOG("OnEmoClick button tag: %d", btn->getTag()); txtChat->setText( CCString::createWithFormat("%s(%d)", txtChat->getStringValue(), btn->getTag())->getCString() ); } }
void Scene_GameItem::itemBtnCallBack(cocos2d::CCObject *object) { UIButton* btn = (UIButton*)object; UIImageView* img; //通过游戏的道具信息获取道具价钱. sItemData* itemData = CGameInfoMan::sharedInstance().getItemDate(GameShare_Global::shareGlobal()->gameType, btn->getTag()); UILabel* itemInfo = dynamic_cast<UILabel*>(ul->getWidgetByName("Label_591")); switch (btn->getTag()) { case Btn_1: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_1")); break; case Btn_2: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_2")); break; case Btn_3: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_3")); break; case Btn_4: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_4")); break; default: break; } if (img->isVisible()) { img->setVisible(false); if (itemData) { CCString infoStr; infoStr.initWithFormat("%s:%s",itemData->ItemName.c_str(),itemData->ItemDetail.c_str()); itemInfo->setText(infoStr.getCString()); needGold -= itemData->CurrencyValue; } }else{ img->setVisible(true); if (itemData) { CCString infoStr; infoStr.initWithFormat("%s:%s",itemData->ItemName.c_str(),itemData->ItemDetail.c_str()); itemInfo->setText(infoStr.getCString()); needGold += itemData->CurrencyValue; if (CPlayerInfoMan::sharedInstance().getPlayerInfo().nMoney < needGold) { GameLayer_Alert *alertUl = GameLayer_Alert::creatWithOnlySure(Type_OnlySure); needGold -= itemData->CurrencyValue; alertUl->setText(GET_STRING_CSV(1010000021)); this->addChild(alertUl,1); img->setVisible(false); } } } this->setItemByTag(btn->getTag()); }
void SceneEditorScreenMain::OnCloseBody(BaseObject * owner, void * userData, void * callerData) { UIButton *btn = (UIButton *)owner; int32 tag = btn->GetTag(); bool needToSwitchBody = false; Vector<BodyItem*>::iterator it = bodies.begin(); for(int32 i = 0; i < (int32)bodies.size(); ++i, ++it) { if(btn == bodies[i]->closeButton) { if(bodies[i]->bodyControl->GetParent()) { RemoveControl(libraryControl); RemoveControl(bodies[i]->bodyControl); needToSwitchBody = true; } RemoveControl(bodies[i]->headerButton); SafeRelease(bodies[i]->headerButton); SafeRelease(bodies[i]->closeButton); SafeRelease(bodies[i]->bodyControl); SafeDelete(*it); bodies.erase(it); break; } } for(int32 i = 0; i < (int32)bodies.size(); ++i) { bodies[i]->headerButton->SetRect( Rect(TAB_BUTTONS_OFFSET + i * (ControlsFactory::BUTTON_WIDTH), BODY_Y_OFFSET - ControlsFactory::BUTTON_HEIGHT, ControlsFactory::BUTTON_WIDTH, ControlsFactory::BUTTON_HEIGHT)); bodies[i]->headerButton->SetTag(i); if(bodies[i]->closeButton) { bodies[i]->closeButton->SetTag(i); } bodies[i]->bodyControl->SetTag(i); } if(bodies.size()) { if(tag) { --tag; } //set as current bodies[tag]->headerButton->PerformEvent(UIControl::EVENT_TOUCH_UP_INSIDE); } }
void UIComponentTest::defaultPlay() { CCComRender *render = static_cast<CCComRender*>(m_rootNode->getChildByTag(10025)->getComponent("GUIComponent")); cocos2d::ui::TouchGroup* touchGroup = static_cast<cocos2d::ui::TouchGroup*>(render->getNode()); UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_154")); UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_156")); button->addTouchEventListener(this, toucheventselector(UIComponentTest::touchEvent)); }
void MainMenuScene::UIAnimationInit() { // ui animation root from json Layout* uianimation_root = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("MainMenu.json")); m_pUILayer->addWidget(uianimation_root); // TextButton button UIButton* button = static_cast<UIButton*>(m_pUILayer->getWidgetByName("Button_Play")); button->addTouchEventListener(this, toucheventselector(MainMenuScene::startUIAnimation)); }
void ShopLayer::updateScroV(bool isVis) { UIScrollView* scroV = dynamic_cast<UIScrollView*>(m_layerLayout->getChildByName("ScrollView")); for (int i = 0; i < 8; i++) { UIButton* scroPanel = dynamic_cast<UIButton*>(scroV->getChildByName(CCString::createWithFormat("Panel_%d", i)->getCString())); UIImageView* discountImg = dynamic_cast<UIImageView*>(scroPanel->getChildByName("discountImg")); discountImg->setVisible(isVis); } }
UIButton* UIButton::create() { UIButton* widget = new UIButton(); if (widget && widget->init()) { return widget; } CC_SAFE_DELETE(widget); return NULL; }
void CocosGUIExamplesUIAnimationScene::UIAnimationInit() { // ui animation root from json Layout* uianimation_root = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("cocosgui/gui_examples/SampleUIAnimation/SampleUIAnimation.json")); m_pUILayer->addWidget(uianimation_root); // TextButton button UIButton* button = static_cast<UIButton*>(m_pUILayer->getWidgetByName("TextButton")); button->addTouchEventListener(this, toucheventselector(CocosGUIExamplesUIAnimationScene::startUIAnimation)); }
bool AheadChapter::init() { if (!CCLayerRGBA::init()) return false; _aUILayer = UILayer::create(); this->addChild(_aUILayer); _ahead_root = static_cast<Layout *>(CCUIHELPER->createWidgetFromJsonFile(CG_GamePathes[kAheadChapter].c_str())); _aUILayer->addWidget(_ahead_root); UIButton *startButt = static_cast<UIButton *>(_ahead_root->getChildByName("start_butt")); startButt->setTouchEnable(true); startButt->addTouchEventListener(this, toucheventselector(AheadChapter::startGame)); UIButton *resetButt = static_cast<UIButton *>(_ahead_root->getChildByName("reset_butt")); resetButt->setTouchEnable(true); resetButt->addTouchEventListener(this, toucheventselector(AheadChapter::reSetGame)); UIButton *settingButt = static_cast<UIButton *>(_ahead_root->getChildByName("setting_butt")); settingButt->setTouchEnable(true); settingButt->addTouchEventListener(this, toucheventselector(AheadChapter::settingGame)); UIImageView *map_image = static_cast<UIImageView *>(_ahead_root->getChildByName("gMap_image")); map_image->setTouchEnable(true); map_image->addTouchEventListener(this, toucheventselector(AheadChapter::enterAcountManager)); return true; }
SampleSelector::SampleSelector(Context* context) : Object(context) { UIView* view = FeatureExamples::GetUIView(); UILayout* rootLayout = new UILayout(context_); rootLayout->SetAxis(UI_AXIS_Y); rootLayout->SetRect(view->GetRect()); view->AddChild(rootLayout); const char* examples[] = { "Hello World", "Hello GUI", "Render to Texture", "2D Sprite", "2D Physics", "2D Constraints", "2D Rope", "2D Spriter Animation", "3D Static Scene", "3D Animating Scene", "3D Light Animation", "3D Billboards", "3D Particles", "3D Physics", "3D Skeletal Animation", "3D Decals", "3D Character", "3D Dynamic Geometry", "3D Ragdolls", "3D Vehicle Demo", "3D Crowd Navigation", "3D Water", "3D Multiple Viewports" }; for (size_t i = 0; i < sizeof(examples) / sizeof(examples[0]); i++) { UIButton* button = new UIButton(context_); button->SetLayoutMinWidth(128); button->SetText(examples[i]); button->SetId(examples[i]); button->SubscribeToEvent(button, E_WIDGETEVENT, ATOMIC_HANDLER(SampleSelector, HandleWidgetEvent)); rootLayout->AddChild(button); } Input* input = GetSubsystem<Input>(); input->SetMouseVisible(true); input->SetMouseMode(MM_FREE); // Subscribe key up event SubscribeToEvent(E_KEYUP, ATOMIC_HANDLER(SampleSelector, HandleKeyUp)); context->RegisterSubsystem(this); }
void TartarLayer::onEnter() { CCLayer::onEnter(); UiManager::Singleton().Init(this); UiManager::Singleton().SetupWidget("../UIProject/Json/Tartar.json"); UIWidget* pUIWidget = UiManager::Singleton().GetChildByName("Panel1"); pUIWidget->setVisible(true); pUIWidget = UiManager::Singleton().GetChildByName("Panel2"); pUIWidget->setVisible(false); UILabel* pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_Warning")); pUILabel->setVisible(false); pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_DayDiff")); pUILabel->setVisible(false); pUILabel = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_PastDay")); pUILabel->setVisible(false); UITextField* pUITextField = DynamicCast<UITextField*>(UiManager::Singleton().GetChildByName("TextField_Year")); pUITextField->setMaxLengthEnable(true); pUITextField->setMaxLength(4); pUITextField->addInsertTextEvent(this, coco_TextFieldInsertTextSelector(TartarLayer::TextFieldInserted)); pUITextField = DynamicCast<UITextField*>(UiManager::Singleton().GetChildByName("TextField_Mon")); pUITextField->setMaxLengthEnable(true); pUITextField->setMaxLength(2); pUITextField->addInsertTextEvent(this, coco_TextFieldInsertTextSelector(TartarLayer::TextFieldInserted)); pUITextField = DynamicCast<UITextField*>(UiManager::Singleton().GetChildByName("TextField_Day")); pUITextField->setMaxLengthEnable(true); pUITextField->setMaxLength(2); pUITextField->addInsertTextEvent(this, coco_TextFieldInsertTextSelector(TartarLayer::TextFieldInserted)); UIButton* pButton = DynamicCast<UIButton*>(UiManager::Singleton().GetChildByName("TextButton_Start")); pButton->addReleaseEvent(this, coco_releaseselector(TartarLayer::BottonOKClicked)); pButton = DynamicCast<UIButton*>(UiManager::Singleton().GetChildByName("TextButton_Finish")); pButton->addReleaseEvent(this, coco_releaseselector(TartarLayer::BottonFinishClicked)); pButton = DynamicCast<UIButton*>(UiManager::Singleton().GetChildByName("TextButton_Order")); pButton->addReleaseEvent(this, coco_releaseselector(TartarLayer::BottonOrderClicked)); UILabel* pUILabelWarning = DynamicCast<UILabel*>(UiManager::Singleton().GetChildByName("Label_NeedCheck")); pUILabelWarning->setVisible(false); UIImageView* pImage = DynamicCast<UIImageView*>(UiManager::Singleton().GetChildByName("ImageView")); CCRect rect = pImage->getRect(); float normalWidth = cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width - 10.0f; float normalHeight = normalWidth * 0.6f; pImage->setScaleX(normalWidth / rect.size.width * pImage->getScaleX()); pImage->setScaleY(normalHeight / rect.size.height * pImage->getScaleY()); }
UIButton*UIButton::create() { UIButton *node = new UIButton(); if (node) { node->autorelease(); return node; } CC_SAFE_DELETE(node); return NULL; }