コード例 #1
0
ファイル: dagMessageCmd.cpp プロジェクト: BigRoy/Maya-devkit
MStatus dagMessageCmd::doIt( const MArgList& args)
//
// Takes the  nodes that are on the active selection list and adds an
// attriubte changed callback to each one.
//
{
	MStatus 		status;
	MSelectionList 	list;
    MArgDatabase argData(syntax(), args);

	status = argData.getObjects(list);
	if (MS::kSuccess != status) {
		MGlobal::displayError("Error getting objects");
		return status;
	}

	//	Get the flags
	//
	bool allDagUsed = argData.isFlagSet(kAllDagFlag);
	bool parentAddedUsed = argData.isFlagSet(kParentAddedFlag);
	bool parentRemovedUsed = argData.isFlagSet(kParentRemovedFlag);
	bool childAddedUsed = argData.isFlagSet(kChildAddedFlag);
	bool childRemovedUsed = argData.isFlagSet(kChildRemovedFlag);
	bool childReorderedUsed = argData.isFlagSet(kChildReorderedFlag);
	bool helpUsed = argData.isFlagSet(kHelpFlag);

	bool nothingSet = (	!allDagUsed && !parentAddedUsed && 
						!parentRemovedUsed && !childAddedUsed && 
						!childRemovedUsed && !childReorderedUsed && 
						!helpUsed);

	if (nothingSet) {
		MGlobal::displayError("A flag must be used. dagMessage -help for availible flags.");
		return MS::kFailure;
	}

	if (argData.isFlagSet(kHelpFlag)) {
		MGlobal::displayInfo("dagMessage -help");
		MGlobal::displayInfo("\tdagMessage adds a callback to the selected nodes,");
		MGlobal::displayInfo("\tor if no nodes are selected, to all nodes. The callback");
		MGlobal::displayInfo("\tprints a message when called. When the plug-in is unloaded");
		MGlobal::displayInfo("\tthe callbacks are removed.");
		MGlobal::displayInfo("");
		MGlobal::displayInfo("\t-h -help : This message is printed");
		MGlobal::displayInfo("\t-ad -allDag : parent changes and child reorders");
		MGlobal::displayInfo("\t-pa -parentAdded : A parent is added");
		MGlobal::displayInfo("\t-pr -parentRemoved : A parent is removed");
		MGlobal::displayInfo("\t-ca -childAdded : A child is added (only for individual nodes)");
		MGlobal::displayInfo("\t-cr -childRemoved : A child is removed (only for individual nodes)");
		MGlobal::displayInfo("\t-cro -childReordered : A child is reordered");
		MGlobal::displayInfo("");
	}

	unsigned nObjs = list.length();
	if (nObjs == 0) {
		//	Add the callback for all changes of the specified type.
		//
		if (allDagUsed) {
			MCallbackId id = MDagMessage::addAllDagChangesCallback(userDAGGenericCB, NULL, &status);
			if (status) {
				callbackIds.append( id );
				MGlobal::displayInfo("Added a callback for all Dag changes on all nodes.\n");
			} else {
				MGlobal::displayError("Could not add a -allDag callback");
				return status;
			}
		}

		if (parentAddedUsed) {
			status = addGenericCallback(NULL, 
										MDagMessage::kParentAdded,
										MString(" parent added "));
			if (MS::kSuccess != status) {
				return status;
			}
		}

		if (parentRemovedUsed) {
			status = addGenericCallback(NULL, 
										MDagMessage::kParentRemoved,
										MString(" parent removed "));
			if (MS::kSuccess != status) {
				return status;
			}
		}		

		if (childAddedUsed) {
			MGlobal::displayError("-childAdded can only be used when a node is selected");
			status = MS::kFailure;
			return status;
		}

		if (childRemovedUsed) {
			MGlobal::displayError("-childRemoved can only be used when a node is selected");
			status = MS::kFailure;
			return status;
		}	

		if (childReorderedUsed) {
			status = addGenericCallback(NULL, 
										MDagMessage::kChildReordered,
										MString(" child reordered "));
			if (MS::kSuccess != status) {
				return status;
			}
		}	
	} else {
		for (unsigned int i=0; i< nObjs; i++) {
			MDagPath dagPath;
			list.getDagPath(i, dagPath);

			if (!dagPath.isValid()) {
				continue;
			}

			//	Add the callback for all changes of the specified type.
			//
			if (allDagUsed) {
				MCallbackId id = MDagMessage::addAllDagChangesCallback(dagPath, userDAGGenericCB, NULL, &status);
				if (status) {
					callbackIds.append( id );
					MString infoStr("Added a callback for all Dag changes on ");
					infoStr += dagPath.fullPathName();
					MGlobal::displayInfo(infoStr);
				} else {
					MGlobal::displayError("Could not add a -allDag callback");
					return status;
				}
			}

			if (parentAddedUsed) {
				status = addGenericCallback(&dagPath, 
											MDagMessage::kParentAdded,
											MString(" parent added "));
				if (MS::kSuccess != status) {
					return status;
				}
			}

			if (parentRemovedUsed) {
				status = addGenericCallback(&dagPath, 
											MDagMessage::kParentRemoved,
											MString(" parent removed "));
				if (MS::kSuccess != status) {
					return status;
				}
			}		

			if (childAddedUsed) {
				status = addGenericCallback(&dagPath, 
											MDagMessage::kChildAdded,
											MString(" child added "));
				if (MS::kSuccess != status) {
					return status;
				}
			}

			if (childRemovedUsed) {
				status = addGenericCallback(&dagPath, 
											MDagMessage::kChildRemoved,
											MString(" child removed "));
				if (MS::kSuccess != status) {
					return status;
				}
			}	

			if (childReorderedUsed) {
				status = addGenericCallback(&dagPath, 
											MDagMessage::kChildReordered,
											MString(" child reordered "));
				if (MS::kSuccess != status) {
					return status;
				}
			}	
		}
	}
	
	return status;
}
コード例 #2
0
ファイル: IFShakeGuideLayer.cpp プロジェクト: ourgames/dc208
bool IFShakeGuideLayer::initData()
{
    this->setVisible(false);
    m_defaultWidth = 140;
    if (CCCommonUtils::isIosAndroidPad())
    {
        m_defaultWidth = 240;
    }
    CCLoadSprite::doResourceByCommonIndex(500, true);
    setCleanFunction([](){
        CCLoadSprite::doResourceByCommonIndex(500, false);
    });
    
    CCBLoadFile("shakeGuideLayer",this,this);
    string infoStr("");
    int guideTime = CCUserDefault::sharedUserDefault()->getIntegerForKey(MSG_SHAKEGUIDETIME, 0);
    
    string shakePicStr = GlobalData::shared()->shakePicStr;
    vector<string> picVec ;
    CCCommonUtils::splitString(shakePicStr, "|", picVec);
    
    int count = picVec.size();
    int index = -1;
    if(count > 0 ){
        index = rand() % count;
    }
    if (m_forceShake) {
        string picStr = "g007.png";
        auto m_pic= CCLoadSprite::createSprite(picStr.c_str());
        CCCommonUtils::setSpriteMaxSize(m_pic, 100);
        m_head->addChild(m_pic);
    }
    if (index != -1) {
        m_headImgNode = HFHeadImgNode::create();
        m_headImgNode->initHeadImgUrl2(m_head, CCCommonUtils::getShakePicUrl(picVec[index]), 1.0f, 100, true);
        CCLOG("shakelog: picUrl%s",CCCommonUtils::getShakePicUrl(picVec[index]).c_str());
    }
    schedule(schedule_selector(IFShakeGuideLayer::monitorPic), 0.5);
    
    m_startTime  = WorldController::getInstance()->getTime()/1000;
    if (guideTime == 0) {
        infoStr = _lang("113100");
    }else if (guideTime == 1){
        infoStr = _lang("113108");
    }else if (guideTime == 2){
        infoStr = _lang("113103");
    }else{
        int randContainerArr[] = {113100,113101,113102,113103,113108,113109};
        int randNUm = rand() % 6;
        CCLOG("shakelog: randnum  %d",randNUm);
        infoStr = _lang(CC_ITOA(randContainerArr[randNUm]));
    }
    if (m_forceShake) {
        infoStr = _lang("113103");
    }
    m_hintText->setString(infoStr.c_str());
    
    CCUserDefault::sharedUserDefault()->setIntegerForKey(MSG_SHAKEGUIDETIME, ++guideTime);

    m_shakeSp->stopAllActions();
    
    CCRotateBy * roaction = CCRotateBy::create(0.1f,60);
    CCRepeat * r1 = CCRepeat::create(CCSequence::create(roaction,roaction->reverse(),nullptr),4);
    CCDelayTime * d = CCDelayTime::create(2.0f);
    m_shakeSp->runAction(CCRepeatForever::create(CCSequence::create(r1,d,nullptr)));
    
    m_bgNode->setVisible(false);
    m_bgNode->retain();
    m_bgNode->removeFromParent();
    m_clipNode = CCClipNode::create(modelWidth, 150);
    if (CCCommonUtils::isIosAndroidPad())
    {
        m_clipNode = CCClipNode::create(modelWidth, 320);
    }
    m_clipNode->setAnchorPoint(ccp(0, 0));
    m_clipNode->addChild(m_bgNode);
    m_bgNode->release();
    this->addChild(m_clipNode);
//    auto btnPic1 = CCLoadSprite::createScale9Sprite("Mail_btn03.png");
//    if(btnPic1){
//        btnPic1->setScale(0.8);
//        m_btnNode->addChild(btnPic1);
//    }
    return true;
}