void PlayScene::onBtnClothes(CCObject *target, TouchEventType e) { UIButton* btn = (UIButton *)ui_layer_->getWidgetByName(btn_name[sub_stage_id_]); if (btn) { if(e == TOUCH_EVENT_BEGAN) { btn_start_pos_ = btn->getPosition(); } else if(e == TOUCH_EVENT_ENDED) { CCPoint pos = btn->getPosition(); if(btn_start_pos_.fuzzyEquals(pos, 100.0f)) { btn->setPosition(btn_start_pos_); } else { if(!all_finish_) { btn->setEnabled(false); btn = (UIButton *)ui_layer_->getWidgetByName("BtnStartPlay"); btn->setEnabled(true); } else { btn->setEnabled(false); User::CurrentUser()->set_stageid(stageid_ + 1); User::CurrentUser()->Flush(); PopWin::Instance().ShowPopScene(this, true, toucheventselector(PlayScene::onPopBack)); } } } } CCLOG("%s\n", __FUNCTION__); }
void CityListLayer::addCityBtn(int index) { //获得城市按钮位置 stringstream nameStream; nameStream << "cityBtn" << index; string cityBtnName = nameStream.str(); UIButton *btn = cityListLayout->FindChildObjectByName<UIButton>(cityBtnName); CCPoint cityPoint = btn->getPosition(); //初始化各种位置信息 CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); cityInfoList[index - 1].cityPos = ccpAdd(ccp(visibleSize.width / 2, visibleSize.height / 2), cityPoint); cityInfoList[index - 1].playerPos = ccpAdd(cityInfoList[index - 1].cityPos, ccp(0, -25)); cityInfoList[index - 1].namePos = ccpAdd(cityInfoList[index - 1].cityPos, ccp(0, -30)); //获得城市图标资源 CCPoint pt; ASprite * as = AspriteManager::getInstance()->getAsprite(KICON_BIN); stringstream resourceNameStream; resourceNameStream << "map_ui_system_icon_FRAME_ICON_CITY" << index; string cityResourceName = resourceNameStream.str(); int cityResourceId = getResourceIDByName(cityResourceName.c_str()); CCSprite* cityIcon = as->getSpriteFromFrame_Middle(cityResourceId, 0, pt); CCSprite* citySelectIcon = as->getSpriteFromFrame_Middle(cityResourceId, 0, pt); citySelectIcon->setScale(1.2f); //创建城市图标 IconButton * cityBtn = new IconButton(cityIcon, NULL, citySelectIcon, this, menu_selector(CityListLayer::onPressCityBtn)); cityBtn->setPosition(cityInfoList[index - 1].cityPos); cityBtn->SetButtonIndex(index); cityBtn->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(cityBtn); //创建城市名称label float fontSize = GameFontManager::smallFontSize(); CCSize nameLabelSize = CCSizeMake(200 / CC_CONTENT_SCALE_FACTOR(), fontSize); string cityName = MainLandManager::Get()->getCityName(cityInfoList[index - 1].cityId); UILabelTTF * cityNameLabel = UILabelTTF::create(cityName.c_str(), KJLinXin, fontSize, nameLabelSize, kCCTextAlignmentCenter,kCCVerticalTextAlignmentBottom); cityNameLabel->setPosition(cityInfoList[index - 1].namePos); this->addChild(cityNameLabel); }
void UIStrengthen::tableCellTouched( CCTableView* table, CCTableViewCell* cell ) { CCLOG("cell touched at index: %i", cell->getIdx()); strengthenManager->selectGeneralId = cell->getIdx(); strengthenManager->pageNum = 0; strengthenManager->selectEquipmentId = 0; UIButton* button = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("EquipmentButton_1"));; selectFrameImageView->setPosition(button->getPosition()); strengthenManager->init(); refresh(); }
void UIStrengthen::equipmentButtonClicked( CCObject* sender, TouchEventType type ) { UIButton* button = (UIButton*)sender; for (int i = 0; i < 4; i++) { const char* s = CCString::createWithFormat("EquipmentButton_%d", i+1)->getCString(); if (strcmp(button->getName(), s) == 0) { selectFrameImageView->setPosition(button->getPosition()); strengthenManager->selectEquipmentId = strengthenManager->pageNum * 4 + i; refresh(); break; } } }
void UIStrengthen::pageRightButtonClicked( CCObject* sender, TouchEventType type ) { if (type == CCTOUCHBEGAN) { strengthenManager->pageNum++; if (strengthenManager->pageNum > strengthenManager->maxPageNum - 1) { strengthenManager->pageNum = strengthenManager->maxPageNum - 1; return; } CCLOG("formationManager->pageNum: %d", strengthenManager->pageNum); strengthenManager->selectEquipmentId = strengthenManager->pageNum * 4; UIButton* button = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("EquipmentButton_1"));; selectFrameImageView->setPosition(button->getPosition()); refresh(); } }
bool CityListLayer::init() { if(!CCLayer::init()) { return false; } //读取城市列表 initCityList(); UIManager *manager = UIManager::sharedManager(); cityListLayout = manager->CreateUILayoutFromFile("UIplist/cityListUI.plist", this, "CityList"); //添加背景图片 CCSprite * bgImg = CCSprite::create("game.png"); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCSize bgSize = bgImg->getContentSize(); float scaleX = visibleSize.width / bgSize.width; float scaleY = visibleSize.height / bgSize.height; bgImg->setScaleX(scaleX); bgImg->setScaleY(scaleY); bgImg->setPosition(ccp(visibleSize.width/2, visibleSize.height/2)); this->addChild(bgImg, -1); //添加主城 for (size_t i = 0; i < cityInfoList.size(); i++) { addCityBtn(i+1); } //添加关闭按钮 UIButton *btn = cityListLayout->FindChildObjectByName<UIButton>("cityListCloseBtn"); CCPoint closePoint = btn->getPosition(); closePoint = ccpAdd(ccp(visibleSize.width / 2, visibleSize.height / 2), closePoint); CCPoint pt1; ASprite * as1 = AspriteManager::getInstance()->getAsprite(KUI_BIN); int normalCloseId = getResourceIDByName("map_ui_FRAME_INSTANCE_CLOSE"); int selectCloseId = getResourceIDByName("map_ui_FRAME_INSTANCE_CLOSE_CLICKED"); CCSprite * normalCloseBtn = as1->getSpriteFromFrame_Middle(normalCloseId, 0, pt1); CCSprite * selectCloseBtn = as1->getSpriteFromFrame_Middle(selectCloseId, 0, pt1); IconButton * closeBtn = new IconButton(normalCloseBtn, NULL, selectCloseBtn, this, menu_selector(CityListLayer::closeCityList)); closeBtn->setPosition(closePoint); this->addChild(closeBtn); //初始化玩家头像资源 CCPoint pt; ASprite * as = AspriteManager::getInstance()->getAsprite(KICON_BIN); int playerType = UserData::Get()->GetUserType(); stringstream playerResStream; playerResStream << "map_ui_system_icon_FRAME_ICON_ROLEONMAP_" << playerType; string playerResName = playerResStream.str(); int playerResourceId = getResourceIDByName(playerResName.c_str()); playerImg = as->getSpriteFromFrame_Middle(playerResourceId, 0, pt); playerImg->setVisible(false); this->addChild(playerImg); playerMoving = false; return true; }