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;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...
    CCNode* gameScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("DemoCowboy.json");
    addChild(gameScene);
    
    //Create player
    CCNode* playerNode = gameScene->getChildByTag(10004);
    player = new Player(playerNode);
    
    //Assign callbacks to the buttons
    CCNode* uiNode = gameScene->getChildByTag(10005);
    UILayer* ui = (UILayer*)uiNode->getComponent("GUIComponent")->getNode();
    
    UIButton* btnLeft = (UIButton*)ui->getWidgetByName("LeftButton");
    btnLeft->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveLeft));
    
    UIButton* btnRight = (UIButton*)ui->getWidgetByName("RightButton");
    btnRight->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveRight));
    
    UIButton* btnFire = (UIButton*)ui->getWidgetByName("FireButton");
//    btnFire->addReleaseEvent(this, coco_releaseselector(HelloWorld::onFire));
    btnFire->addTouchEventListener(this, toucheventselector(HelloWorld::onFire));
    
    //Enable update loop
    this->scheduleUpdate();
    
    return true;
}
Beispiel #3
0
void PlayScene::onEnter() {
  CCScene::onEnter();

  CCLOG("%s", __FUNCTION__);
  // load ui
  ui_layer_ = UILayer::create();
  ui_layer_text_ = UILayer::create();
  char path[1024];
  snprintf(path, 1024, "MainScene/GirlScene%d.json",
           stageid_);

  Layout *layout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile(path));
  ui_layer_->addWidget(layout);

  card_mgr_.CreateLayer(this);
  this->addChild(ui_layer_, 0, 100);
  this->addChild(card_mgr_.card_layer(), 1, 101);
  this->addChild(ui_layer_text_, 2, 100);

  card_mgr_.Init(stageid_);

  UIButton *btn = (UIButton *)ui_layer_->getWidgetByName("BtnBack");
  if (btn) {
    btn->addTouchEventListener(this, toucheventselector(PlayScene::onBtnBack));
    btn->setPressedActionEnabled(true);
  }

  UIPanel *panel = (UIPanel *)ui_layer_->getWidgetByName("PanelSecond");
  if(panel == NULL) {
    return;
  }
  panel->setVisible(false);
  panel->setTouchEnable(false);

  btn = (UIButton *)ui_layer_->getWidgetByName("BtnStartPlay");
  if (btn) {
    btn->addTouchEventListener(this, toucheventselector(PlayScene::onBtnStartPlay));
    CCScaleTo* scale1 = CCScaleTo::create( 1.0f, 1.2f);
    CCScaleTo* scale2 = CCScaleTo::create( 1.0f, 0.8f);
    CCSequence* scale = CCSequence::createWithTwoActions(scale1, scale2);
    btn->getVirtualRenderer()->runAction(CCRepeatForever::create(scale));
  }
  btn = (UIButton *)ui_layer_->getWidgetByName("BtnShirt");
  if (btn) {
    btn->setTouchEnable(false);
  }
  card_mgr_.SetEnable(false);

  be_back_ = false;
  property_state_ = -1;
}
Beispiel #4
0
void SelectMenuView::noticeShowLock(int beautyIndex, int needHeart)
{
	_panelUnlock->setVisible(true);
	_panelUnlock->setTouchEnabled(true);

	// setting head 
	UIImageView* head = (UIImageView*)_panelUnlock->getChildByName("panelLock_head");
	char tmp[32];
	sprintf(tmp,"head_%d.png",beautyIndex);
	head->loadTexture(tmp,UI_TEX_TYPE_PLIST);

	// setting heart number
	for(int i=0; i<MAX_HEART; i++)
	{
		sprintf(tmp,"panelLock_heart_%d",i+1);
		if(i<needHeart)
		{
			_panelUnlock->getChildByName(tmp)->setVisible(true);
		}
		else
		{
			_panelUnlock->getChildByName(tmp)->setVisible(false);
		}
	}

	// setting beauty name
	UILabelBMFont* labelName = (UILabelBMFont*) _panelUnlock->getChildByName("panelLock_txt_name");
	labelName->setText(BeautyStaticData::getInstance()->getName(beautyIndex));

	// setting unlock price
	UILabelBMFont* labelPrice = (UILabelBMFont*) _panelUnlock->getChildByName("panelLock_txt_price");
	sprintf(tmp,"$%d",BeautyStaticData::getInstance()->getRequiement(beautyIndex+1));
	labelPrice->setText(tmp);

	// animation
	UIWidget* bg = _panelUnlock->getChildByName("panelLock_bg");
	bg->setScale(0.1f);
	bg->runAction(CCScaleTo::create(0.3f,1));

	UIButton* button = (UIButton*)_panelUnlock->getChildByName("panelLock_btn_back");
	button->setTouchEnabled(true);
	button->setPressedActionEnabled(true);
	button->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchUnlock));
	button = (UIButton*)_panelUnlock->getChildByName("panelLock_btn_unlock");
	button->setTouchEnabled(true);
	button->setPressedActionEnabled(true);
	button->addTouchEventListener(this,toucheventselector(SelectMenuView::onTouchUnlock));

	this->addWidget(_panelUnlock);
}
Beispiel #5
0
void GameLayer::initAnswerLayer(std::vector<std::string> &StrVector)
{
    CCArray *answerChildren = _answerLayer->getChildren();
    
    _canAnsImageSize = static_cast<UIButton *>(answerChildren->objectAtIndex(0))->getContentSize();
    
    CCObject *obj_butt;
    
    int countPerRow = 8;
    int row = 0,col = 0;
    int currCount = 0;
    
    CCARRAY_FOREACH(answerChildren, obj_butt)
    {
        row = currCount / countPerRow;
        col = currCount % countPerRow;
        
        UIButton *anButt = (UIButton *)(obj_butt);
        anButt->setTouchEnable(true);
        anButt->addTouchEventListener(this,toucheventselector(GameLayer::answerButt));
        
        CCPoint buttPoint = CCPointMake(CG_FISTANBUTT_POINT.x + (CG_ANSWER_BUTT_SPACE_SIZE.width)* col, CG_FISTANBUTT_POINT.y + (CG_ANSWER_BUTT_SPACE_SIZE.height) * row);
        
        anButt->setPosition(buttPoint);
        
        std::string butt_titlt_str = StrVector.at(currCount);
        
        if (!CGHelper::isChineseChar(butt_titlt_str.c_str())) {
            anButt->setTitleFontSize(20);
        }
        
        anButt->setText(butt_titlt_str.c_str());
        currCount++;
    }
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 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));
}
Beispiel #9
0
bool UIWepon::init()
{
	if (!CCLayer::init())
	{
		return false;
	}

	uiLayer = UILayer::create();

	UILayout* weponRoot = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UIWepon.ExportJson"));
	uiLayer->addWidget(weponRoot);

	UIButton* closeButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("CloseButton"));
	closeButton->addTouchEventListener(this, toucheventselector(UIWepon::closeButtonClicked));

	UIButton* fillButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("FillButton"));
	fillButton->addTouchEventListener(this, toucheventselector(UIWepon::fillButtonClicked));

	UIButton* pageLeftButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("PageLeftButton"));
	pageLeftButton->addTouchEventListener(this, toucheventselector(UIWepon::pageLeftButtonClicked));

	UIButton* pageRightButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("PageRightButton"));
	pageRightButton->addTouchEventListener(this, toucheventselector(UIWepon::pageRightButtonClicked));

	equipmentFeatureImageView = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName("EquipmentFeatureImageView"));
	roundImageView = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName("RoundImageView"));

	for (int i = 0; i < 4; i++)
	{
		const char* s = CCString::createWithFormat("GemImageView_%d", i+1)->getCString();
		gemImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	for (int i = 0; i < 4; i++)
	{
		const char* s = CCString::createWithFormat("EquipmentAttributeValueLabel_%d", i+1)->getCString();
		equipmentAttributeValueLable[i] = dynamic_cast<UILabel*>(uiLayer->getWidgetByName(s));
	}
	
	addChild(uiLayer);
	refresh();
	return true;
}
Beispiel #10
0
void PlayScene::TakeOff() {
  UIButton* btn = NULL;
  btn = (UIButton *)ui_layer_->getWidgetByName(btn_name[sub_stage_id_]);

  if (btn) {
    btn->setTouchEnable(true);
    btn->addTouchEventListener(this, toucheventselector(PlayScene::onBtnClothes));
    btn->addMoveEvent(this, coco_moveselector(PlayScene::onBtnMoveClothes));
    TakeOffAction(btn);
  }
  CCLOG("%s error sub_stage_id_:%d\n", __FUNCTION__, sub_stage_id_);
  return;
}
bool SettingMenuLayer::init(bool musicVolumeClosed, bool musicEffectClosed,int musicVolume, int musicEffect)
{
	if(UILayer::init())
	{
		this->setTouchEnabled(true);
		this->setTouchMode(kCCTouchesOneByOne);
		SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();

		CCDirector::sharedDirector()->pause();

		Widget * myWidget =  dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("UI/SettingMenu/SettingMenu_1.json"));
		this->addWidget(myWidget);

		musicVolumeSlider = dynamic_cast<UISlider*>(this->getWidgetByName("volume_bar"));
		musicEffectSlider = dynamic_cast<UISlider*>(this->getWidgetByName("effect_bar"));
		musicVolumeCheckBox = dynamic_cast<UICheckBox*>(this->getWidgetByName("volume_CheckBox"));
		musicEffectCheckBox = dynamic_cast<UICheckBox*>(this->getWidgetByName("effect_CheckBox"));
		UIButton* resumeBtn = dynamic_cast<UIButton*>(this->getWidgetByName("resume"));
		UIButton* quitBtn = dynamic_cast<UIButton*>(this->getWidgetByName("quit"));
				
		musicVolumeCheckBox->addEventListenerCheckBox(this,checkboxselectedeventselector(SettingMenuLayer::musicVolumeCheckBoxCallFunc));
		musicEffectCheckBox->addEventListenerCheckBox(this,checkboxselectedeventselector(SettingMenuLayer::musicEffectCheckBoxCallFunc));
		musicVolumeSlider->addEventListenerSlider(this, sliderpercentchangedselector(SettingMenuLayer::musicVolumeSliderCallFunc));
		musicEffectSlider->addEventListenerSlider(this, sliderpercentchangedselector(SettingMenuLayer::musicEffectSliderCallFunc));
		resumeBtn->addTouchEventListener(this, toucheventselector(SettingMenuLayer::resumeGame));
		quitBtn->addTouchEventListener(this, toucheventselector(SettingMenuLayer::quitGame));

		musicVolumeCheckBox->setSelectedState(musicVolumeClosed);
		musicEffectCheckBox->setSelectedState(musicEffectClosed);
		musicVolumeSlider->setPercent(musicVolume);
		musicEffectSlider->setPercent(musicEffect);

		return true;
	}

	return false;
}
Beispiel #12
0
void ShopScene::onEnter() {
  CCScene::onEnter();

  CCLOG("%s", __FUNCTION__);
  // load ui
  ui_layer_ = UILayer::create();
  Layout *layout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("MainScene/ShopScene.json"));
  ui_layer_->addWidget(layout);
  this->addChild(ui_layer_, 0, 100);

  UIButton *btn = (UIButton *)ui_layer_->getWidgetByName("BtnBack");
  if (btn) {
    btn->addTouchEventListener(this, toucheventselector(ShopScene::onBtnBack));
    btn->setPressedActionEnabled(true);
  }

  struct ButtonListener bl[] = {
      {"BtnSale10", toucheventselector(ShopScene::onBtnSale1)},
      {"BtnSale20", toucheventselector(ShopScene::onBtnSale2)},
      {"BtnSale70", toucheventselector(ShopScene::onBtnSale3)},
      {"BtnSale150", toucheventselector(ShopScene::onBtnSale4)},
      {"BtnSaleSpecial", toucheventselector(ShopScene::onBtnSale5)},
  };

  for (size_t i = 0; i < sizeof(bl) / sizeof(bl[0]); i++) {
      btn = (UIButton *)ui_layer_->getWidgetByName(bl[i].name);
      if (btn) {
    btn->addTouchEventListener(this, bl[i].selector);
      }
  }

  if (iap_ == NULL) {
    iap_ = ProductList();
    CCLOG("init iap %p\n", iap_);
  }
}
Beispiel #13
0
bool UIMainCity::init()
{
	if (!CCLayer::init())
	{
		return false;
	}

	uiLayer = UILayer::create();

	UILayout* mainCityRoot = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UIMainCity.ExportJson"));
	uiLayer->addWidget(mainCityRoot);

	UIButton* fightingButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("FightingButton"));
	fightingButton->addTouchEventListener(this, toucheventselector(UIMainCity::fightingButtonClicked));

	UIButton* formationButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("FormationButton"));
	formationButton->addTouchEventListener(this, toucheventselector(UIMainCity::formationButtonClicked));
	
	UIButton* starringButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("StarringButton"));
	starringButton->addTouchEventListener(this, toucheventselector(UIMainCity::starringButtonClicked));

	UIButton* generalButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("GeneralButton"));
	generalButton->addTouchEventListener(this, toucheventselector(UIMainCity::generalButtonClicked));

	UIButton* bagButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("BagButton"));
	bagButton->addTouchEventListener(this, toucheventselector(UIMainCity::bagButtonClicked));

	UIButton* strengthenButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("StrengthenButton"));
	strengthenButton->addTouchEventListener(this, toucheventselector(UIMainCity::strengthenButtonClicked));

	UIButton* rideButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("RideButton"));
	rideButton->addTouchEventListener(this, toucheventselector(UIMainCity::rideButtonClicked));

	UIButton* countryButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("NationButton"));
	countryButton->addTouchEventListener(this, toucheventselector(UIMainCity::countryButtonClicked));

	setVisible(false);
	addChild(uiLayer);

	return true;
}
bool UIButtonTest_Scale9::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the button events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Button scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the button
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        // open scale9 render
        button->setScale9Enabled(true);
        button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        button->setSize(CCSizeMake(150, button->getContentSize().height * 1.5f));
        button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
        m_pUiLayer->addWidget(button);
        
        return true;
    }
    return false;
}
Beispiel #15
0
// on "init" you need to initialize your instance
bool LayerChatWindow::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}
	lstStringMessage.clear();
	lstStringMessage.push_back("Nhanh lên nào (14)!");
	lstStringMessage.push_back("Mạng lag quá (9)!");
	lstStringMessage.push_back("Bài xấu quá (3)!");
	lstStringMessage.push_back("Hehe, lên nóc nhà\nmà bắt con gà (6)");
	lstStringMessage.push_back("Nhất rồi, haha (1)");
	lstStringMessage.push_back("Đánh gà thế (11)!");
	lstStringMessage.push_back("Đỏ vãi lúa (13)!");
	lstStringMessage.push_back("Nhọ như chó mực (5)!");

	//return true;

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	_count = 100;
	layerButton = UILayer::create();
	layerButton->addWidget(GUIReader::shareReader()->widgetFromJsonFile("LayerChatWindow_1.ExportJson"));
	this->addChild(layerButton);
	layerButton->setTouchPriority(-128);
	this->setTouchEnabled(true);

	//Get all chat button
	for( int i = 1; i <= 8; i++ ){
		UIButton* btnChat = dynamic_cast<UIButton*>(layerButton->getWidgetByName( CCString::createWithFormat("btnChat%d", i)->getCString() ));
		btnChat->setTitleText( lstStringMessage.at(i-1).c_str() );
		btnChat->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonChats);
	}
	UIButton* btnClose = dynamic_cast<UIButton*>(layerButton->getWidgetByName("btnClose"));
	btnClose->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonClose);
	//
	UIButton* btnSend = dynamic_cast<UIButton*>(layerButton->getWidgetByName("btnSend"));
	btnSend->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonSend);

	txtChat = dynamic_cast<UITextField*>(layerButton->getWidgetByName("txtChat"));
	txtChat->setText("");
	txtChat->setPlaceHolder("Noi dung");
	txtChat->setTextHorizontalAlignment(kCCTextAlignmentCenter);
	txtChat->setTextVerticalAlignment(kCCVerticalTextAlignmentCenter);
	txtChat->addEventListenerTextField(this, textfieldeventselector(LayerChatWindow::textFieldEvent));

	UIPanel* pEmo = dynamic_cast<UIPanel*>(layerButton->getWidgetByName("pEmo"));
	UIImageView* pImg = dynamic_cast<UIImageView*>(layerButton->getWidgetByName("Image_25_0"));
	//Add all emo to this
	int i = 1;
// 	CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(CCString::createWithFormat("onion%d.ExportJson", 1)->getCString());
// 	CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(CCString::createWithFormat("onion%d.ExportJson", 1)->getCString());
	int row=-1, col = 1;
	int widthOfPage = 580;
	int numOfCols = 9;
	int space = 10;
	int widthOfImage = 50;
	int startPosX = widthOfPage/2 - (widthOfImage+space)*numOfCols/2 - 300;
	int startPosY = space - 100;
	lstEmo.clear();
	for( int i = 1; i<=16; i++ ){
		CCArmature *armature = CCArmature::create(CCString::createWithFormat("onion%d", 1)->getCString());
		armature->getAnimation()->playByIndex(i-1);
		RichElementCustomNode* recustom = RichElementCustomNode::create(1, ccWHITE, 255, armature);
		RichText* _richText = RichText::create();
		_richText->setContentSize( armature->getContentSize() );
		_richText->pushBackElement(recustom); 
		if( col> numOfCols ){
			row++;
			col = 1;
		}
		_richText->setAnchorPoint(ccp(0, 1));
		_richText->setPosition(ccp( startPosX + 60*(col-1)
			, -1*row*50 - startPosY - (row+1)*space ));
		_richText->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::OnEmoClick);

		lstEmo.push_back( armature );

		UIButton* b = UIButton::create();
		b->setPosition(ccp( startPosX + 60*(col-1)
			, -1*row*50 - startPosY - (row+1)*space ));
		b->setAnchorPoint(ccp(0, 1));
		b->setContentSize( armature->getContentSize() );
		b->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::OnEmoClick);
		b->loadTextures("emo_blank.png", "", "");
		b->setTag(i);

		pImg->addChild( _richText );
		pImg->addChild( b );
		//CCLOG("button w: %lf h: %lf", b->getContentSize().width, b->getContentSize().height);
		col++;
	}
	return true;
}
void LoginScene::onEnter(){
    CCLayer::onEnter();
	TouchGroup* ui = TouchGroup::create();
	loginWidget = GUIReader::shareReader()->widgetFromJsonFile("Scene/LoginSence/LoginSence.json");
    loginWidget->setSizeType(SIZE_ABSOLUTE);
    loginWidget->setSize(CCDirector::sharedDirector()->getVisibleSize());
    
    ui->addWidget(loginWidget);
	ui->setAnchorPoint(CCPointZero);
	this->addChild(ui);
    
    
    //登陆区域
    UIPanel* login_panel = (UIPanel*)UIHelper::seekWidgetByName(loginWidget, "bodyPanel");
    login_panel->setCloseIME(true);

    //loginWidget->getChildByTag(4);
    //UIPanel* bg_panel = (UIPanel*)loginWidget->getChildByTag(63);

    UIImageView *upImg = (UIImageView*)UIHelper::seekWidgetByName(loginWidget, "upImg");
    CCSize fs = CCDirector::sharedDirector()->getVisibleSize();
    //float scale = fs.width/upImg->getSize().width;

    float scale = std::max(fs.width/upImg->getSize().width, fs.height/upImg->getSize().height);
    //if(scale > 1){
        upImg->setScale(scale);
    //}

    UIImageView *logo = (UIImageView*)UIHelper::seekWidgetByName(loginWidget, "logoImage");

    float sca = std::min(fs.width/640, fs.height/960);
    logo->setScale(sca);

    ImageView *userIcon = (ImageView *)UIHelper::seekWidgetByName(loginWidget, "userIcon");
    userIcon->setScale(sca);

    ImageView *userIconBg = (ImageView *)UIHelper::seekWidgetByName(loginWidget, "userIconBg");
    userIconBg->setScale(sca);    

    ImageView *userLi = (ImageView*)UIHelper::seekWidgetByName(loginWidget, "usernameLiImage");
    TextField *usernameInput = (TextField*)UIHelper::seekWidgetByName(loginWidget, "username");
    //userLi->setScale(sca);
    usernameInput->setScale(sca);

    ImageView *passwordLi = (ImageView*)UIHelper::seekWidgetByName(loginWidget, "passwordLiImage");
    //passwordLi->setScale(sca);
    
    TextField *passwordInput = (TextField*)UIHelper::seekWidgetByName(loginWidget, "password");
    passwordInput->setScale(sca);


    UIButton* loginBtn = (UIButton*)UIHelper::seekWidgetByName(loginWidget, "loginButton");
    //login_panel->getChildByTag(8);
    loginBtn->addTouchEventListener(this,toucheventselector(LoginScene::loginPress));
    

    //float ms = std::min(fs.width/640, fs.height/960);
    //if (ms < 1)
   // {
        //logo->setScale(ms);
    loginBtn->setScale(sca);
    //}
    Button *regB = (Button*)UIHelper::seekWidgetByName(loginWidget, "regButton");
    regB->setScale(sca);


    UIButton* topBtn = (UIButton*)UIHelper::seekWidgetByName(loginWidget, "tabLoginButton");
    topBtn->setScale(sca);

    CCLog("init UIPanel");


    //用户名
    /*
    m_userName = CCEditBox::create(CCSize(320,50), CCScale9Sprite::createWithSpriteFrameName("button.png"));
	m_userName->setFontSize(23);
	m_userName->setAnchorPoint(CCPointZero);
	m_userName->setPlaceHolder("请输入用户名");
    m_userName->setPlaceholderFontColor(ccc3(248,252,255));
	m_userName->setInputMode(kEditBoxInputModeAny);
	m_userName->setReturnType(kKeyboardReturnTypeDone);
	m_userName->setPosition(ccp(153,378));
	m_userName->setDelegate(this);
	m_userName->setTouchPriority(0);
    */

    username = (UITextField*)UIHelper::seekWidgetByName(loginWidget, "username");

    password = (UITextField*)UIHelper::seekWidgetByName(loginWidget, "password");
    midView = (UIPanel*)UIHelper::seekWidgetByName(loginWidget, "midView");

    CCLog("init midView");


    //密码
  
    
    
    UIButton* registerBtn = (UIButton*)UIHelper::seekWidgetByName(loginWidget, "regButton");
    //login_panel->getChildByTag(44);
    registerBtn->addTouchEventListener(this, toucheventselector(LoginScene::registerPress));
    
    //切换账号
    UIButton* tabLoginBtn = (UIButton*)UIHelper::seekWidgetByName(loginWidget, "tabLoginButton");//login_panel->getChildByTag(87);
    tabLoginBtn->addTouchEventListener(this, toucheventselector(LoginScene::tabloginPress));
    
    //login_panel->addNode(m_userName);
    //login_panel->addNode(m_passWord);
    CCLog("init button");
    //更新显示
    refurbishScene();

    
}
Beispiel #17
0
bool MainScene::init() {
    mNextTickCount = 0;
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object

    /////////////////////////////
    // 3. add your codes below...

    CCSize size = CCDirector::sharedDirector()->getWinSize(); 

    m_pLayer = UILayer::create();
    addChild(m_pLayer);

    UILayout* m_pLayout = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("Welcome/Main.json"));

    m_pLayer->addWidget(m_pLayout);

    m_uinLabel = dynamic_cast<UILabel*>(
      m_pLayer->getWidgetByName("Uin_Label"));

    m_sessionLabel = dynamic_cast<UILabel*>(
      m_pLayer->getWidgetByName("Session_Label"));
    
    m_userInfoLabel = dynamic_cast<UILabel*>(
      m_pLayer->getWidgetByName("UserInfo_Label"));

    m_resultLabel = dynamic_cast<UILabel*>(
      m_pLayer->getWidgetByName("Result_Label"));

    UIButton * btnSwitchAccount = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("SwitchAccount_Btn"));
    btnSwitchAccount->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchSwitchAccount));

    UIButton * btnRegistGuest = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("RegistGuest_Btn"));
    btnRegistGuest->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchRegistGuest));

    UIButton * btnCharge = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("Charge_Btn"));
    btnCharge->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchCharge));

    UIButton * btnBuy = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("Buy_Btn"));
    btnBuy->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchBuy));

    UIButton * btnSwitchBar = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("SwitchToolbar_Btn"));
    btnSwitchBar->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchSwitchBar));

    UIButton * btnAntiAddiction = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("AntiAddictin_Btn"));
    btnAntiAddiction->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchAntiAddiction));

    UIButton * btnLogout = dynamic_cast<UIButton*>(
      m_pLayer->getWidgetByName("Logout_Btn"));
    btnLogout->addTouchEventListener(this,
      toucheventselector(MainScene::OnTouchLogout));

    FillUserInfo();

    EventEmitter::CallbackFunctor_t loginFunc = 
      std::bind( &MainScene::onLogined, this, std::placeholders::_1);
    int handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_LOGINED, loginFunc);
    if (handle < 0) {
        CCLog("Fail to listening to logined event");
    } else {
        AddHandle(UserAccountMgr::EVENT_LOGINED, handle);
    }

    EventEmitter::CallbackFunctor_t charingFunc = 
      std::bind( &MainScene::onCharging, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_CHARGING, charingFunc);
    if (handle < 0) {
        CCLog("Fail to listening to charging event");
    } else {
        AddHandle(UserAccountMgr::EVENT_CHARGING, handle);
    }

    EventEmitter::CallbackFunctor_t chargedFunc = 
      std::bind( &MainScene::onCharged, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_CHARGED, chargedFunc);
    if (handle < 0) {
        CCLog("Fail to listening to charge event");
    } else {
        AddHandle(UserAccountMgr::EVENT_CHARGED, handle);
    }


    EventEmitter::CallbackFunctor_t buyingFunc = 
      std::bind( &MainScene::onBuying, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_BUYING, buyingFunc);
    if (handle < 0) {
        CCLog("Fail to listening to buy event");
    } else {
        AddHandle(UserAccountMgr::EVENT_BUYING, handle);
    }

    EventEmitter::CallbackFunctor_t boughtFunc = 
      std::bind( &MainScene::onBought, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_BOUGHT, boughtFunc);
    if (handle < 0) {
        CCLog("Fail to listening to buy event");
    } else {
        AddHandle(UserAccountMgr::EVENT_BOUGHT, handle);
    }

    EventEmitter::CallbackFunctor_t antiAddiction = 
      std::bind( &MainScene::onAntiAddictionInfo, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_ANTI_ADDICTION_INFO, 
        antiAddiction);
    if (handle < 0) {
        CCLog("Fail to listening to anti addiction event");
    } else {
        AddHandle(UserAccountMgr::EVENT_ANTI_ADDICTION_INFO, handle);
    }

    EventEmitter::CallbackFunctor_t switchAccountFunc = 
      std::bind( &MainScene::onSwitchAccount, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_SWITCH_ACCOUNT, 
        switchAccountFunc);
    if (handle < 0) {
        CCLog("Fail to listening to anti addiction event");
    } else {
        AddHandle(UserAccountMgr::EVENT_SWITCH_ACCOUNT, handle);
    }

    EventEmitter::CallbackFunctor_t logoutFunc = 
      std::bind( &MainScene::onLogout, this, std::placeholders::_1);
    handle = 
      g_userAccountMgr.AddListener(UserAccountMgr::EVENT_LOGOUT, 
        logoutFunc);
    if (handle < 0) {
        CCLog("Fail to listening to anti addiction event");
    } else {
        AddHandle(UserAccountMgr::EVENT_LOGOUT, handle);
    }

    this->schedule(schedule_selector(MainScene::Tick), 1, -1, 1);
    return true;
}
// void HelloWorld::NetReconnect(cocos2d::CCObject *pSender)
// {
// 	NetWorkNode::retry();
//// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
     NetInit();
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);

	
  //创建一个UILayer层 
    ul =UILayer::create(); 
    //将UILayer层加入到当前的场景 
    this->addChild(ul); 
	ul->setTag(10026);
    //使用json文件给Layer层添加CocoStudio生成的控件 
    ul->addWidget(GUIReader::shareReader()->widgetFromJsonFile("\\json\\DemoLogin.json")); 
	UIButton* CloseButton = dynamic_cast<UIButton*>(ul->getWidgetByName("close_Button"));
	CloseButton->addTouchEventListener(this,toucheventselector(HelloWorld::Close));
	UIButton* LoginButton = dynamic_cast<UIButton*>(ul->getWidgetByName("login_Button"));
	LoginButton->addTouchEventListener(this,toucheventselector(HelloWorld::GetLoginText));
	this->addChild(netNode);
    return true;
}
Beispiel #19
0
bool UIStrengthen::init()
{
	if (!CCLayer::init())
	{
		return false;
	}

	uiLayer = UILayer::create();

	UILayout* strengthenRoot = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("ui/UIStrengthen.ExportJson"));
	uiLayer->addWidget(strengthenRoot);

	UIButton* closeButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("CloseButton"));
	closeButton->addTouchEventListener(this, toucheventselector(UIStrengthen::closeButtonClicked));

	UIButton* strengthenButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("StrengthenButton"));
	strengthenButton->addTouchEventListener(this, toucheventselector(UIStrengthen::strengthenButtonClicked));

	UIButton* pageLeftButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("PageLeftButton"));
	pageLeftButton->addTouchEventListener(this, toucheventselector(UIStrengthen::pageLeftButtonClicked));

	UIButton* pageRightButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("PageRightButton"));
	pageRightButton->addTouchEventListener(this, toucheventselector(UIStrengthen::pageRightButtonClicked));

	for (int i = 0; i < 4; i++)
	{
		const char* s = CCString::createWithFormat("EquipmentButton_%d", i+1)->getCString();
		UIButton* equipmentButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName(s));
		equipmentButton->addTouchEventListener(this, toucheventselector(UIStrengthen::equipmentButtonClicked));
	}

	for (int i = 0; i < 2; i++)
	{
		const char* s = CCString::createWithFormat("GemButton_%d", i+1)->getCString();
		UIButton* gemButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName(s));
		gemButton->addTouchEventListener(this, toucheventselector(UIStrengthen::gemButtonClicked));
	}

	for (int i = 0; i < 4; i++)
	{
		const char* s = CCString::createWithFormat("EquipmentImageView_%d", i+1)->getCString();
		equipmentImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	for (int i = 0; i < 3; i++)
	{
		const char* s = CCString::createWithFormat("GemImageView_%d", i+1)->getCString();
		gemImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	for (int i = 0; i < 2; i++)
	{
		const char* s = CCString::createWithFormat("GemFrontImageView_%d", i+1)->getCString();
		gemFrontImageView[i] = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName(s));
	}

	strengthenfeatureImageView = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName("FeatureImageView"));

	strengthenTestButton = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("StrengthenTestButton"));

	selectFrameImageView = dynamic_cast<UIImageView*>(uiLayer->getWidgetByName("SelectFrameImageView"));

	UIPanel* tableViewPanel = dynamic_cast<UIPanel*>(uiLayer->getWidgetByName("TableViewPanel"));

	CCTableView* strengthenTableView = CCTableView::create(this, CCSizeMake(strengthenTestButton->getContentSize().width, tableViewPanel->getContentSize().height));
	strengthenTableView->setDirection(kCCScrollViewDirectionVertical);
	strengthenTableView->setVerticalFillOrder(kCCTableViewFillTopDown);

	CCPoint strengthenTestPosition = strengthenTestButton->getPosition();
	strengthenTableView->setPosition(ccp(strengthenTestPosition.x, strengthenTestPosition.y - tableViewPanel->getContentSize().height));
	strengthenTableView->setDelegate(this);
	strengthenTableView->reloadData();

	addChild(uiLayer);
	addChild(strengthenTableView);

	setVisible(false);
	refresh();
	return true;
}