CCSprite* DamageValueEffect::CreateMissLabel(CCPoint parentPos) { //CCPoint visibleSize = CCDirector::sharedDirector()->getLevelRenderCameraOffset(); //float pos_x = parentPos.x - visibleSize.x; //float pos_y = parentPos.y - visibleSize.y; //CCPoint uiPos = ccp(pos_x, pos_y); CCPoint uiPos = parentPos; ASprite *as = AspriteManager::getInstance()->getAsprite("UI/ui_inbattle.bin"); CCPoint pt; int iFrameID = TXGUI::getResourceIDByName("map_ui_inbattle_FRAME_MISS"); CCSprite* missSprite = as->getSpriteFromFrame_Middle(iFrameID,0,pt); if(missSprite) { missSprite->setPosition(ccp(uiPos.x,uiPos.y+70)); missSprite->setAnchorPoint(ccp(0.5,0.5)); missSprite->setScale(0); missSprite->runAction(getBattleUIAction()); if(m_pDamageLabels->find(missSprite) == m_pDamageLabels->end()) { m_pDamageLabels->insert(make_pair(missSprite,1.3f)); //this->addChild(missSprite); if(GameManager::Get()->GetSceneLayer() != NULL && GameManager::Get()->GetSceneLayer()->getLevelLayer() != NULL && GameManager::Get()->GetSceneLayer()->getLevelLayer()->getObjectLayer()) { GameManager::Get()->GetSceneLayer()->getLevelLayer()->getObjectLayer()->addChild(missSprite,MAP_Z_OBJ_TOP); } } } return missSprite; }
CCSprite* DamageValueEffect::CreateBlockLabel(CCPoint parentPos) { CCPoint uiPos = parentPos; ASprite *as = AspriteManager::getInstance()->getAsprite("UI/ui_inbattle.bin"); CCPoint pt; int iFrameID = TXGUI::getResourceIDByName("map_ui_inbattle_FRAME_BLOCK"); CCSprite* missSprite = as->getSpriteFromFrame_Middle(iFrameID,0,pt); if(missSprite) { missSprite->setPosition(ccp(uiPos.x,uiPos.y+70)); missSprite->setAnchorPoint(ccp(0.5,0.5)); missSprite->setScale(0); missSprite->runAction(getBattleUIAction()); if(m_pDamageLabels->find(missSprite) == m_pDamageLabels->end()) { m_pDamageLabels->insert(make_pair(missSprite,1.3f)); //this->addChild(missSprite); if(GameManager::Get()->GetSceneLayer() != NULL && GameManager::Get()->GetSceneLayer()->getLevelLayer() != NULL && GameManager::Get()->GetSceneLayer()->getLevelLayer()->getObjectLayer()) { GameManager::Get()->GetSceneLayer()->getLevelLayer()->getObjectLayer()->addChild(missSprite,MAP_Z_OBJ_TOP); } } } return missSprite; }
CCSprite* EquipmentUpgradeUILayer::getIconFrame(unsigned int level) { string picName = ""; switch(level) { case 1: picName = "map_ui_system_icon_FRAME_FRAME_GREEN"; break; case 2: picName = "map_ui_system_icon_FRAME_FRAME_BLUE"; break; case 3: picName = "map_ui_system_icon_FRAME_FRAME_PURPLE"; break; case 4: picName = "map_ui_system_icon_FRAME_FRAME_ORANGE"; break; } if(picName != "") { ASprite *as = AspriteManager::getInstance()->getAsprite(KICON_BIN); int idx = getResourceIDByName(picName.c_str()); CCPoint pt; CCSprite * pic = as->getSpriteFromFrame_Middle( idx, 0, pt); if(pic != NULL) { return pic; } } return NULL; }
void FrontCoverLayer::addNewSever() { UILayout* m_layout = UIManager::sharedManager()->getUILayout("SplashLayout"); if(m_severScrollPage) { CCLayer* layer = CCLayer::create(); m_severScrollPage->addPage(layer); int count = m_severList.size(); int currentPage = 0; int column = 3; int row = 2; ASprite *as = AspriteManager::getInstance()->getAsprite(KUI_BIN); int idx = map_ui_FRAME_SELECTSERVE_BUTTON; int selectedId = map_ui_FRAME_SELECTSERVE_BUTTON_CLICKED; float scale = UIManager::sharedManager()->getScaleFactor(); float width = m_severScrollPage->getContentSize().width / scale; float height = m_severScrollPage->getContentSize().height / scale; CCRect rect = as->getframeRect(idx); float deltaWidth = (width - column * rect.size.width )/(column + 1); float deltaHeigth = (height - row * rect.size.height )/(row + 1); for(int i =0; i< count; i++) { int index = i; int page = index / (column * row); int rowIndex = (index - page * column * row) / column; int columnIndex = (index - page * column * row) % column; if(page != currentPage) { currentPage = page; CCLayer* newlayer = CCLayer::create(); m_severScrollPage->addPage(newlayer); } CCPoint pt; CCSprite *pEmptyItem = as->getSpriteFromFrame_Middle( idx, 0, pt); CCSprite *pSelectedItem = as->getSpriteFromFrame_Middle(selectedId ,0,pt); IconButton * pIcon = new IconButton(pEmptyItem, NULL, pSelectedItem, this, menu_selector(FrontCoverLayer::onClickedOneSever)); pIcon->autorelease(); pIcon->SetButtonIndex(index); pIcon->setContentSize(pEmptyItem->getContentSize()); float x = -width * 0.5f + deltaWidth * (columnIndex + 1) + (columnIndex + 0.5f) * rect.size.width ; float y = height * 0.5f - (rowIndex + 0.5f) * (deltaHeigth + rect.size.height ); pIcon->setPosition(ccp(x, y)); UILabelTTF* label = UILabelTTF::create(m_severList[i]->name,KJLinXin,40,pEmptyItem->getContentSize(),kCCTextAlignmentCenter,kCCVerticalTextAlignmentCenter); pIcon->addChild(label); m_lstButton.push_back(pIcon); CCLayer* currentLayer = m_severScrollPage->getPageLayer(currentPage); currentLayer->addChild(pIcon,index); } } }
CCSprite* EquipmentUpgradeUILayer::getIconSpriteById(unsigned int ItemId) { ASprite *as = AspriteManager::getInstance()->getAsprite(KICON_BIN); int idx = GameConfigFromLuaManager::Get()->getItemResourceId(ItemId); CCPoint pt; CCSprite * pic = as->getSpriteFromFrame_Middle( idx, 0, pt); return pic; }
void ASpriteGroup::initPos(int x, int y) { for(ASGGROUPLIST it = this->begin(); it != this->end(); ++it) { ASprite * sprite = *it; sprite->setAnchorPos(this->pos()); } }
void ASpriteGroup::hide() { for(ASGGROUPLIST it = this->begin(); it != this->end(); ++it) { ASprite * sprite = *it; sprite->hide(); } m_isHide = true; }
void ASpriteGroup::show() { for(ASGGROUPLIST it = this->begin(); it != this->end(); ++it) { ASprite * sprite = *it; sprite->show(); } m_isHide = false; }
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 StoryInstanceDirector::LoadAllRoles() { std::vector<unsigned int> vecOut; if (StoryDataCenter::Get()->GetOneItemAllRoleIds(vecOut)) { size_t count = vecOut.size(); for (size_t index = 0;index<count;index++) { unsigned int roleId = vecOut[index]; SpriteSeer* pSeer = 0; if (roleId != 0) { pSeer = InsertOneRole(index+1,roleId); unsigned int seerTypeId = pSeer->GetTypeId(); if (false == SpriteElfConfigFromLuaManager::getInstance()->TellIsElfId(seerTypeId)) { ASprite* pAsprite = AspriteManager::getInstance()->getAsprite("spriteBin/shadow.bin"); if(pAsprite != NULL) { CCPoint cp; CCSpriteBatchNode* pBatchNode = pAsprite->getSpriteBatchNodeFromFrame_Middle(0, 0, cp); if(pBatchNode != NULL) { pSeer->addChildToRoot(pBatchNode); } } } } else { pSeer = GameManager::Get()->getHero(); pSeer = InsertOneRole(index+1,roleId,pSeer); if (pSeer) { m_heroIndex = index+1; } } if (pSeer) { pSeer->getRoot()->setVisible(false); } } } }
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; }
void UIScrollPage::LoadBinary(NiStream &kStream) { UIControlBase::LoadBinary(kStream); uint32_t contentWidth = 0; uint32_t contentHeight = 0; uint32_t direction = 0; int priority = kCCScrollTouchPriority; mutableDic *dic = kStream.GetStreamData(); // get button click callback function kStream.getStringattributeValue(dic, "itemClickedCallback", m_strItemClickedFun); kStream.getStringattributeValue(dic, "itemDoubleClickedCallback", m_strItemDoubleClickedFun); kStream.getStringattributeValue(dic, "itemDragReleaseCallback", m_strItemDragReleaseFun); kStream.getStringattributeValue(dic, "tappedCallback", m_strTappedFun); kStream.getStringattributeValue(dic, "tapCancelCallback", m_strTapCancelFun); kStream.getIntAttributeValue(dic, "itemType", m_itemType); kStream.getIntAttributeValue(dic, "contentWidth", contentWidth); kStream.getIntAttributeValue(dic, "contentHeight", contentHeight); kStream.getIntAttributeValue(dic, "direction", direction); kStream.getSignedIntAttributeValue(dic, "indicatorOffsetX", m_indicatorOffsetX); kStream.getSignedIntAttributeValue(dic, "indicatorOffsetY", m_indicatorOffsetY); kStream.getSignedIntAttributeValue(dic,"priority",priority); contentWidth /= CC_CONTENT_SCALE_FACTOR(); contentHeight /= CC_CONTENT_SCALE_FACTOR(); m_indicatorOffsetX /= CC_CONTENT_SCALE_FACTOR(); m_indicatorOffsetY /= CC_CONTENT_SCALE_FACTOR(); setDirection((EScrollDirection)direction); // query frameRect property mutableDic* framedic = static_cast<mutableDic*>(dic->objectForKey("frameRect")); if( framedic ) { string rectAsIndex = ""; kStream.getStringattributeValue(framedic, "rectAsIndex", rectAsIndex); uint32_t useAscontentRect = 0; kStream.getIntAttributeValue(framedic, "useAscontentRect", useAscontentRect); if (useAscontentRect) { CCPoint pt; string ASfile = KUI_BIN; kStream.getStringattributeValue(framedic, "binFile", ASfile); ASprite *as = AspriteManager::getInstance()->getAsprite(ASfile); int idx = getResourceIDByName(rectAsIndex.c_str()); CCRect scrollRect = as->getframeRect(idx); CCPoint scrollCenter = as->GetFramePointMiddle(idx); // re-calculate the local position CCPoint parentWorldPosition = CCPointZero; if(m_pParent != NULL) { parentWorldPosition = m_pParent->getWorldPosition(); } m_ptLocalPosition.x = scrollCenter.x - parentWorldPosition.x; m_ptLocalPosition.y = scrollCenter.y - parentWorldPosition.y; setContentSize(scrollRect.size); } } else { setContentSize(CCSize(contentWidth, contentHeight)); } m_pScrollLayer = UIScrollLayer::nodeWithNoLayer(m_contentSize, m_direction); m_pScrollLayer->setPosition(m_ptLocalPosition); m_pScrollLayer->setPagesIndicatorPosition(ccp(m_indicatorOffsetX, m_indicatorOffsetY)); m_pScrollLayer->setPriority(priority); m_pScrollLayer->setVisible(m_bIsVisible); m_pControlNode = m_pScrollLayer->getBaseLayer(); // add pages mutableDic* pageDic = static_cast<mutableDic*>(dic->objectForKey("page")); if( pageDic ) { kStream.getIntAttributeValue(pageDic, "count", m_ipageCount); kStream.getIntAttributeValue(pageDic, "column", m_icolumn); kStream.getIntAttributeValue(pageDic, "row", m_irow); kStream.getIntAttributeValue(pageDic, "cellOffsetX", m_celloffsetX); kStream.getIntAttributeValue(pageDic, "cellOffsetY", m_celloffsetY); m_celloffsetX /= CC_CONTENT_SCALE_FACTOR(); m_celloffsetY /= CC_CONTENT_SCALE_FACTOR(); m_bIsConfiged = true; } m_cellAsfile = ""; kStream.getStringattributeValue(dic, "cellAsIndex", m_cellAsfile); m_cellSelectedAsfile = ""; kStream.getStringattributeValue(dic, "cellSelectedAsIndex", m_cellSelectedAsfile); if (m_cellAsfile.empty() == false) { CCPoint pt; m_cellBinFile = KUI_BIN; kStream.getStringattributeValue(dic, "binFile", m_cellBinFile); ASprite *as = AspriteManager::getInstance()->getAsprite(m_cellBinFile); int idx = getResourceIDByName(m_cellAsfile.c_str()); m_cellRect = as->getframeRect(idx); } for(int i = 0 ; i < (int) m_ipageCount ; i ++) { addOneEmptyPage(i); } }
void PvAIManager::refreshPvAILayer() { UIManager *manager = UIManager::sharedManager(); pvaiLayout = manager->getUILayout("PvAILayout"); if (pvaiLayout) { //玩家昵称 UILabel *heroNameLabel = pvaiLayout->FindChildObjectByName<UILabel>("pvaiMcName"); if (heroNameLabel) { string heroName = UserData::getUserName(); heroNameLabel->setString(heroName.c_str()); } //玩家排名 UILabel *heroRankLabel = pvaiLayout->FindChildObjectByName<UILabel>("pvaiMcRank"); if (heroRankLabel) { stringstream heroRankStream; heroRankStream << heroRank; string heroRankStr = heroRankStream.str(); string heroRankText = Localizatioin::getLocalization("M_PVAI_RANK"); heroRankText += heroRankStr; heroRankLabel->setString(heroRankText.c_str()); } //玩家声望 UILabel *heroReputationLabel = pvaiLayout->FindChildObjectByName<UILabel>("pvaiMcReputation"); if (heroReputationLabel) { int heroReputation = UserData::GetUserInfo().m_reputation; stringstream heroReputationStream; heroReputationStream << heroReputation; string heroReputationStr = heroReputationStream.str(); string heroReputationText = Localizatioin::getLocalization("M_PVAI_REPUTATION"); heroReputationText += heroReputationStr; heroReputationLabel->setString(heroReputationText.c_str()); } ////剩余挑战次数 //UILabel *lastTimeLabel = pvaiLayout->FindChildObjectByName<UILabel>("pvaiTodayLastTime"); //if (lastTimeLabel) //{ // stringstream herolastTimeStream; // herolastTimeStream << basicInfo.remainCount; // string herolastTimeStr = herolastTimeStream.str(); // lastTimeLabel->setString(herolastTimeStr.c_str()); //} ////奖励金币数 //UILabel *rewardCoinLabel = pvaiLayout->FindChildObjectByName<UILabel>("pvaiRewardCoin"); //if (rewardCoinLabel) //{ // stringstream herolastTimeStream; // herolastTimeStream << basicInfo.rewardCoin; // string herolastTimeStr = herolastTimeStream.str(); // rewardCoinLabel->setString(herolastTimeStr.c_str()); //} ////奖励声望 //UILabel *rewardReputationLabel = pvaiLayout->FindChildObjectByName<UILabel>("pvaiRewardReputation"); //if (rewardReputationLabel) //{ // stringstream herolastTimeStream; // herolastTimeStream << basicInfo.rewardReputation; // string herolastTimeStr = herolastTimeStream.str(); // rewardReputationLabel->setString(herolastTimeStr.c_str()); //} ////奖励领取时间 //TimeManager::Get()->renewTimer(TIMER_PVAI_REWARD, TimeManager::Get()->getCurServerTime() + basicInfo.rewardGetTime); ////冷却时间 //TimeManager::Get()->renewTimer(TIMER_PVAI_COOLDOWN, TimeManager::Get()->getCurServerTime() + basicInfo.coolDownTime); //挑战玩家列表 int playerCount = aiPlayerVec.size(); int minPlayerCount = min(playerCount, 5); for (int i = minPlayerCount; i < 5; i++) { stringstream iconOtherStream; iconOtherStream << "iconOther" << i+1; string iconOtherStr = iconOtherStream.str(); UIPicture *iconOtherPic= pvaiLayout->FindChildObjectByName<UIPicture>(iconOtherStr); iconOtherPic->setVisible(false); iconOtherStream.str(""); iconOtherStream << "gridOther" << i+1; iconOtherStr = iconOtherStream.str(); iconOtherPic= pvaiLayout->FindChildObjectByName<UIPicture>(iconOtherStr); iconOtherPic->setVisible(false); iconOtherStream.str(""); iconOtherStream << "pvaiOtherPlayerName" << i+1; iconOtherStr = iconOtherStream.str(); UILabel * iconOtherLabel= pvaiLayout->FindChildObjectByName<UILabel>(iconOtherStr); iconOtherLabel->setVisible(false); iconOtherStream.str(""); iconOtherStream << "pvaiOtherPlayerLevel" << i+1; iconOtherStr = iconOtherStream.str(); iconOtherLabel= pvaiLayout->FindChildObjectByName<UILabel>(iconOtherStr); iconOtherLabel->setVisible(false); iconOtherStream.str(""); iconOtherStream << "pvaiOtherPlayerRank" << i+1; iconOtherStr = iconOtherStream.str(); iconOtherLabel= pvaiLayout->FindChildObjectByName<UILabel>(iconOtherStr); iconOtherLabel->setVisible(false); iconOtherStream.str(""); iconOtherStream << "pvaiFightBtn" << i+1; iconOtherStr = iconOtherStream.str(); UIButton * iconOtherBtn= pvaiLayout->FindChildObjectByName<UIButton>(iconOtherStr); iconOtherBtn->setVisible(false); iconOtherStream.str(""); iconOtherStream << "pvaiFightText" << i+1; iconOtherStr = iconOtherStream.str(); iconOtherLabel= pvaiLayout->FindChildObjectByName<UILabel>(iconOtherStr); iconOtherLabel->setVisible(false); } for (int i = 0; i < minPlayerCount; i++) { //头像 stringstream iconOtherStream; iconOtherStream << "iconOther" << i+1; string iconOtherStr = iconOtherStream.str(); UIPicture *iconOtherPic= pvaiLayout->FindChildObjectByName<UIPicture>(iconOtherStr); int playerType = aiPlayerVec[i].type; const char * playerIconName = LuaTinkerManager::Get()->getLuaConfig<const char *>("characterString", "Characters", playerType, "HeadPicture"); int idx = getResourceIDByName(playerIconName); CCPoint pt; ASprite *as = AspriteManager::getInstance()->getAsprite(KICON_BIN); CCSprite * headPic = as->getSpriteFromFrame_Middle( idx, 0, pt); if(headPic) { iconOtherPic->addExtraPic(headPic); } //昵称 stringstream otherPlayerNameStream; otherPlayerNameStream << "pvaiOtherPlayerName" << i+1; string otherPlayerNameStr = otherPlayerNameStream.str(); UILabel *otherPlayerNameLabel = pvaiLayout->FindChildObjectByName<UILabel>(otherPlayerNameStr); otherPlayerNameLabel->setString(aiPlayerVec[i].name.c_str()); //等级 stringstream otherPlayerLevelStream; otherPlayerLevelStream << "pvaiOtherPlayerLevel" << i+1; string otherPlayerLevelStr = otherPlayerLevelStream.str(); UILabel *otherPlayerLevelLabel = pvaiLayout->FindChildObjectByName<UILabel>(otherPlayerLevelStr); int playerLevel = aiPlayerVec[i].level; stringstream levelStream; levelStream << "Lv" << playerLevel; string levelStr = levelStream.str(); otherPlayerLevelLabel->setString(levelStr.c_str()); //排名 stringstream otherPlayerRankStream; otherPlayerRankStream << "pvaiOtherPlayerRank" << i+1; string otherPlayerRankStr = otherPlayerRankStream.str(); UILabel *otherPlayerRankLabel = pvaiLayout->FindChildObjectByName<UILabel>(otherPlayerRankStr); int playerRank = aiPlayerVec[i].rank; string rankText = Localizatioin::getLocalization("M_PVAI_RANK2"); stringstream rankStream; rankStream << rankText << playerRank; string rankStr = rankStream.str(); otherPlayerRankLabel->setString(rankStr.c_str()); } //最近日志列表 float fontSize = GameFontManager::smallFontSize(); int logCount = aiLogInfoVec.size(); int minLogCount = min(logCount, 4); //隐藏多余项目 for (int i = minLogCount; i < 4; i++) { stringstream attackTextStream; attackTextStream << "pvaiChallenge" << i+1; string attackTextStr = attackTextStream.str(); UILabel *attackOrgLabel = pvaiLayout->FindChildObjectByName<UILabel>(attackTextStr); attackOrgLabel->setVisible(false); stringstream resultStream; resultStream << "pvaiChallengeResult" << i+1; string resultStr = resultStream.str(); UILabel *resultLabel = pvaiLayout->FindChildObjectByName<UILabel>(resultStr); resultLabel->setVisible(false); } for (int i = 0; i < minLogCount; i++) { float factor = UIManager::sharedManager()->getScaleFactor(); stringstream attackTextStream; attackTextStream << "pvaiChallenge" << i+1; string attackTextStr = attackTextStream.str(); UILabel *attackOrgLabel = pvaiLayout->FindChildObjectByName<UILabel>(attackTextStr); UIContainer * container = pvaiLayout->FindChildObjectByName<UIContainer>("pvaiLayerContainer"); attackOrgLabel->setVisible(false); CCPoint orgPos = attackOrgLabel->getPosition(); CCPoint orgLeftPos = ccp(orgPos.x - attackOrgLabel->getLabelTTF()->getContentSize().width * factor / 2, orgPos.y); //挑战方向 if (aiLogInfoVec[i].direct) { //主动攻击 string attackText = Localizatioin::getLocalization("M_PVAI_FIGHT1"); string attackName = aiLogInfoVec[i].name; UILabelTTF * attackTextLabel = UILabelTTF::create(attackText.c_str(), KJLinXin, fontSize * factor, CCSizeZero,kCCTextAlignmentLeft,kCCVerticalTextAlignmentBottom); UILabelTTF * attackNameLabel = UILabelTTF::create(attackName.c_str(), KJLinXin, fontSize * factor, CCSizeZero,kCCTextAlignmentLeft,kCCVerticalTextAlignmentBottom); attackTextLabel->setPosition(ccp(orgLeftPos.x + attackTextLabel->getContentSize().width / 2, orgLeftPos.y)); attackNameLabel->setPosition(ccp(orgLeftPos.x + attackTextLabel->getContentSize().width + attackNameLabel->getContentSize().width/ 2, orgLeftPos.y)); UILabel * aTextLabel = new UILabel(attackTextLabel, container->getCurrentNode()); UILabel * aNameLabel = new UILabel(attackNameLabel, container->getCurrentNode()); aNameLabel->setColor(KAILogNameColor); } else { //被攻击 string defenceName = aiLogInfoVec[i].name; string defenceText = Localizatioin::getLocalization("M_PVAI_FIGHT2"); UILabelTTF * defenceTextLabel = UILabelTTF::create(defenceText.c_str(), KJLinXin, fontSize, CCSizeZero,kCCTextAlignmentLeft,kCCVerticalTextAlignmentBottom); UILabelTTF * defenceNameLabel = UILabelTTF::create(defenceName.c_str(), KJLinXin, fontSize, CCSizeZero,kCCTextAlignmentLeft,kCCVerticalTextAlignmentBottom); defenceNameLabel->setPosition(ccp(orgLeftPos.x + defenceNameLabel->getContentSize().width / 2, orgLeftPos.y)); defenceTextLabel->setPosition(ccp(orgLeftPos.x + defenceNameLabel->getContentSize().width + defenceTextLabel->getContentSize().width / 2, orgLeftPos.y)); UILabel * aTextLabel = new UILabel(defenceTextLabel, container->getCurrentNode()); UILabel * aNameLabel = new UILabel(defenceNameLabel, container->getCurrentNode()); aNameLabel->setColor(KAILogNameColor); } //挑战结果 stringstream resultStream; resultStream << "pvaiChallengeResult" << i+1; string resultStr = resultStream.str(); UILabel *resultLabel = pvaiLayout->FindChildObjectByName<UILabel>(resultStr); if (aiLogInfoVec[i].win == aiLogInfoVec[i].direct) { string resultText = Localizatioin::getLocalization("M_PVAI_WIN"); resultLabel->setString(resultText.c_str()); resultLabel->setColor(ccYELLOW); } else { string resultText = Localizatioin::getLocalization("M_PVAI_LOST"); resultLabel->setString(resultText.c_str()); resultLabel->setColor(ccRED); } } } }
CCNode* DamageValueEffect::CreateCritDamageLable(unsigned int damage,CCPoint parentPos,bool isHarmFul) { CCPoint uiPos = parentPos; CCSprite* critNode = CCSprite::create(); critNode->setPosition(ccp(uiPos.x,uiPos.y)); critNode->setAnchorPoint(ccp(0.5,0.5)); ASprite *as = AspriteManager::getInstance()->getAsprite("UI/ui_inbattle.bin"); CCPoint pt; int iFrameID = TXGUI::getResourceIDByName("map_ui_inbattle_FRAME_CRITICALBACK"); CCSprite* critSprite = as->getSpriteFromFrame_Middle(iFrameID,0,pt); if(critSprite) { critSprite->setPosition(CCPointZero); critNode->addChild(critSprite,0); } char damageString[10]; sprintf(damageString,"%d",damage); CCLabelAtlas* label; if(isHarmFul) { label = CCLabelAtlas::create(damageString,"UI/ui_numble_2.png",43,54,48); } else { label = CCLabelAtlas::create(damageString,"UI/ui_numble_3.png",41,43,48); } if(label) { label->setAnchorPoint(ccp(0.5f,0.5f)); label->setPosition(CCPointZero); critNode->addChild(label,1); if(critSprite) { float scale_x = label->getContentSize().width / (0.8f * critSprite->getContentSize().width); float scale_y = label->getContentSize().height / (0.8f * critSprite->getContentSize().height); float scale = (scale_x > scale_y) ? scale_x : scale_y; critSprite->setScale(scale); critSprite->setPosition(CCPointZero); critSprite->setAnchorPoint(ccp(0.5f,0.5f)); } } critNode->setScale(0); critNode->runAction(getBattleUIAction()); if(m_pDamageLabels->find(critNode) == m_pDamageLabels->end()) { m_pDamageLabels->insert(make_pair(critNode,1.3f)); //this->addChild(critNode); if(GameManager::Get()->GetSceneLayer() != NULL && GameManager::Get()->GetSceneLayer()->getLevelLayer() != NULL && GameManager::Get()->GetSceneLayer()->getLevelLayer()->getObjectLayer()) { GameManager::Get()->GetSceneLayer()->getLevelLayer()->getObjectLayer()->addChild(critNode,MAP_Z_OBJ_TOP); } } /*if(isHarmFul) { HandleCritBurst(uiPos,0); }*/ return critNode; }
//-------------------------------------------------------------------------- void BackLayer::LoadMapLayer(ASprite** pASprite, char* packName, int packIndex) //-------------------------------------------------------------------------- { BackLayerObject* pBackObject = NULL; int tmpsprid = 0; SUTIL_Data_init(packName); SUTIL_Data_open(packIndex); int AsframeNum = 0; int tmpId = 0; ASprite* tmpASprite; while(1) { SUTIL_Data_readU8(); // 0x08 읽고 버린다. tmpId = (short)SUTIL_Data_readU16(); if(1 == tmpId) // 마지막 데이타 { m_nLayerSizeX += (short)SUTIL_Data_readU16(); break; } else if(2 == tmpId || 3 == tmpId) // 임시값 그냥 흘러간다. { } else if(11 == tmpId) // 랙트를 그려야 한다. { (short)SUTIL_Data_readU16(); // x (short)SUTIL_Data_readU16(); // y (short)SUTIL_Data_readU16(); // 고유 타입 (short)SUTIL_Data_readU16(); // draw type // 0이면 frame, 1이면 animation (short)SUTIL_Data_readU16(); // draw num (short)SUTIL_Data_readU16(); // 임시3 읽고 버린다. (short)SUTIL_Data_readU16(); // 임시3 읽고 버린다. continue; } else { if(100 <= tmpId) //현재 오브젝트의 스프라이트 넘버값을 알려준다. { tmpsprid = (tmpId-100)/100; tmpASprite = pASprite[tmpsprid]; } } pBackObject = GL_NEW BackLayerObject(); pBackObject->x = (short)SUTIL_Data_readU16(); // x pBackObject->y = (short)SUTIL_Data_readU16(); // y (short)SUTIL_Data_readU16(); // 읽고 버린다. pBackObject->type = (short)SUTIL_Data_readU16(); // 고유 타입 pBackObject->drawtype = (short)SUTIL_Data_readU16(); // draw type // 0이면 frame, 1이면 animation AsframeNum = (short)SUTIL_Data_readU16(); // draw num (short)SUTIL_Data_readU16(); // 임시3 읽고 버린다. pBackObject->spridx = tmpsprid; pBackObject->pAsIns = GL_NEW ASpriteInstance(tmpASprite, 0, 0, NULL); pBackObject->pAsIns->SetAniMoveLock(true); if(0 == pBackObject->drawtype) {SUTIL_SetTypeFrameAsprite(pBackObject->pAsIns, AsframeNum);} else if(1 == pBackObject->drawtype) { SUTIL_SetTypeAniAsprite(pBackObject->pAsIns, AsframeNum); SUTIL_SetLoopAsprite(pBackObject->pAsIns, true); } // pBackObject->adjustx = tmpASprite->GetFrameX(AsframeNum); // pBackObject->width = tmpASprite->GetFrameWidth(AsframeNum); pBackObject->x += m_nLayerSizeX; pBackObject->y += m_nBaseYLine; // pBackObject->x += pBackObject->adjustx; pBackObject->z = 0; pBackObject->startx = pBackObject->x + tmpASprite->GetFrameX(AsframeNum); pBackObject->endx = pBackObject->startx + tmpASprite->GetFrameWidth(AsframeNum); InsertObject(pBackObject); } SUTIL_Data_free(); }
void UITextInputField::LoadBinary(NiStream &kStream) { UIControlBase::LoadBinary(kStream); mutableDic* dic = kStream.GetStreamData(); float contentScale = CCDirector::sharedDirector()->getContentScaleFactor(); uint32_t bLocalizeString = 0; kStream.getIntAttributeValue(dic, "bLocalizeString", bLocalizeString); std::string strTemp = ""; kStream.getStringattributeValue(dic, "placeholder", strTemp); const char* placeholder = strTemp.c_str(); if (bLocalizeString > 0) { placeholder = CCLocalizedString(strTemp.c_str(), strTemp.c_str()); } uint32_t lengthLimit = 0; kStream.getIntAttributeValue(dic, "lengthLimit", lengthLimit); uint32_t isPassword = 0; kStream.getIntAttributeValue(dic, "isPassword", isPassword); int priority = kCCMenuHandlerPriority; kStream.getSignedIntAttributeValue(dic,"priority",priority); uint32_t dimensionWidth = 0; uint32_t dimensionHeight = 0; kStream.getIntAttributeValue(dic, "dimensionWidth", dimensionWidth); kStream.getIntAttributeValue(dic, "dimensionHeight", dimensionHeight); dimensionWidth /= contentScale; dimensionHeight /= contentScale; uint32_t alignment = 1; kStream.getIntAttributeValue(dic, "alignment", alignment); mutableDic *colorDic = static_cast<mutableDic*>(dic->objectForKey("color")); uint32_t color[3] = {255, 255, 255}; if(colorDic) { kStream.getIntAttributeValue(colorDic, "red", color[0]); kStream.getIntAttributeValue(colorDic, "green", color[1]); kStream.getIntAttributeValue(colorDic, "blue", color[2]); } string font = KJLinXin; kStream.getStringattributeValue(dic, "font", font); float largeFontSize = GameFontManager::largeFontSize(); uint32_t fontSize = largeFontSize * contentScale; kStream.getIntAttributeValue(dic, "fontSize", fontSize); fontSize /= contentScale; CCSize dimension = CCSizeMake(dimensionWidth, dimensionHeight); if(dimensionWidth > 0 && dimensionHeight < fontSize) { dimension = CCSizeMake(dimensionWidth, fontSize); } CCSize touchSize = CCSizeZero; mutableDic *rectDic = static_cast<mutableDic*>(dic->objectForKey("rect")); if(rectDic) { uint32_t useASRect = 0; std::string ASRectName = ""; std::string ASfile = KUI_BIN; uint32_t anchorPoint = 0; // if use Asprite Rect kStream.getIntAttributeValue(rectDic, "useASRect", useASRect); kStream.getIntAttributeValue(rectDic, "anchorPoint", anchorPoint); if(useASRect == 1) { kStream.getStringattributeValue(rectDic, "ASRectName", ASRectName); if(ASRectName != "") { mutableDic* dicAsMgr = static_cast<mutableDic*>(rectDic->objectForKey("AspriteManager")); // content attributes if (dicAsMgr) { if (IsIpad()) { kStream.getStringattributeValue(dicAsMgr, "ipad", ASfile); }else { kStream.getStringattributeValue(dicAsMgr, "iphone", ASfile); } } int ID = getResourceIDByName(ASRectName.c_str()); // name not exists, use normal method if(ID != -1) { ASprite *as = AspriteManager::getInstance()->getAsprite(ASfile); CCRect asRect = as->getframeRect(ID); touchSize = asRect.size; switch(anchorPoint) { case 0: { CCRect rect = as->getframeRect(ID); m_ptWorldPosition = rect.origin; } break; case 1: m_ptWorldPosition = as->GetFramePointMiddle(ID); break; default: break; } CCPoint parentWorldPosition = CCPointZero; if(m_pParent != NULL) { parentWorldPosition = m_pParent->getWorldPosition(); } m_ptLocalPosition.x = m_ptWorldPosition.x - parentWorldPosition.x; m_ptLocalPosition.y = m_ptWorldPosition.y - parentWorldPosition.y; } } } } m_pTextInputField = TextInputField::textFieldWithPlaceHolder(placeholder, dimension, (CCTextAlignment)alignment, font.c_str(), (float)fontSize ); m_pTextInputField->setAnchorPoint(ccp(0.5, 0.5)); m_pTextInputField->setPosition(m_ptLocalPosition); m_pTextInputField->setLengthLimit(lengthLimit); m_pTextInputField->setIsPassword(isPassword != 0); m_pTextInputField->setColor(ccc3(color[0], color[1], color[2])); m_pTextInputField->setInitPriority(priority); m_pTextInputField->setTouchInputSize(touchSize); // make background CreateWhiteBack(); if(m_pWhiteBack != NULL) { m_pWhiteBack->setPosition(m_ptLocalPosition); m_pWhiteBack->setVisible(m_bIsVisible); } m_pControlNode = m_pTextInputField; m_pControlNode->setVisible(m_bIsVisible); }
void UIScrollPage::addOneEmptyPage(int pageIndex) { CCLayer* layer = CCLayer::create(); layer->setAnchorPoint(ccp(0, 0)); { int deltaX, deltaY; if(m_cellBinFile == "") { m_cellBinFile = KUI_BIN; } ASprite *as = AspriteManager::getInstance()->getAsprite(m_cellBinFile); int idx = getResourceIDByName(m_cellAsfile.c_str()); int selectedId = getResourceIDByName(m_cellSelectedAsfile.c_str()); CCSize buttonSize = as->getframeRect(idx).size; // float contentScale = CCDirector::sharedDirector()->getContentScaleFactor(); // buttonSize = CCSizeMake(buttonSize.width * contentScale, buttonSize.height * contentScale); if (m_icolumn <= 1) deltaX = 0; else deltaX = (getContentSize().width - 2 * m_celloffsetX - buttonSize.width) / (m_icolumn - 1); if (m_irow <= 1) deltaY = 0; else deltaY = (getContentSize().height - 2 * m_celloffsetY - buttonSize.height) / (m_irow - 1); ///////////////////////////////////////////////////////////////////////////// // row // row for(int r = 0; r < (int)m_irow; r++) { for(int l = 0; l < (int) m_icolumn; l++) { // clone one ccsprite CCPoint pt; CCSprite *pEmptyItem = as->getSpriteFromFrame_Middle( idx, 0, pt); CCSprite *pSelectedItem = as->getSpriteFromFrame_Middle(selectedId ,0,pt); IconButton * pIcon = new IconButton(pEmptyItem, NULL, pSelectedItem, this, menu_selector(UIScrollPage::OnItemClicked)); pIcon->autorelease(); int index = pageIndex * m_icolumn * m_irow; index += r * m_icolumn + l; pIcon->SetButtonIndex(index+1); pIcon->setContentSize(pEmptyItem->getContentSize()); if(m_itemType != 0) { pIcon->creatDragReceiver((DragHandlerType)m_itemType); } pIcon->SetDoubleClickHandler(this,menu_selector(UIScrollPage::OnItemDoubleClicked)); pIcon->SetTappedHandler(this,menu_selector(UIScrollPage::OnTapped),menu_selector(UIScrollPage::OnTapCancel)); pIcon->SetDragFlagTime(150); m_lstButton.push_back(pIcon); int x = l * deltaX + m_celloffsetX + buttonSize.width / 2 - getContentSize().width / 2 ; int y = getContentSize().height / 2 - (r * deltaY + m_celloffsetY + buttonSize.height / 2); // x /= contentScale; // y /= contentScale; pIcon->setPosition(ccp(x, y)); char name[50]; sprintf(name,"%s_%d",this->m_strName.c_str(),index+1); pIcon->SetButtonName(name); layer->addChild(pIcon); } } } addPage(layer); }