Example #1
0
bool SoliderIconPanel::init()
{
    if (!RelativeBox::init())
    {
        return false;
    }
    
    this->setContentSize(Size(91, 326));
    
    for (int i = 0; i < 3; i++)
    {
        ValueMap data;
        data.insert(pair<string, Value>("filePath", Value(filePath[i])));
        data.insert(pair<string, Value>("arms", Value((int)armsType[i])));
        SoliderIcon* soliderIcon = SoliderIcon::create(data);
        Size soliderIconSize = soliderIcon->getContentSize();
        auto layoutParameter = RelativeLayoutParameter::create();
        layoutParameter->setAlign(RelativeLayoutParameter::RelativeAlign::PARENT_TOP_CENTER_HORIZONTAL);
        layoutParameter->setMargin(Margin(0, i * (102 + 10), 0, 0));
        soliderIcon->setLayoutParameter(layoutParameter);
        soliderIcon->addListener(this);
        _icons.pushBack(soliderIcon);
        this->addChild(soliderIcon);
    }
    
    return true;
}
Example #2
0
void HeroEnety::GoDead(){
	if(mStateEunm == StateEunm::Dead) { return; }
	mStateEunm = StateEunm::Dead;
	HeroManager::getInstance()->del(this);
    
    if (SoldierTypeID == 3)
    {
        ValueMap data;
        data.insert(std::make_pair("raid", Value(roadID)));
        bool isLeft = false;
        if (mRaceEunm == RaceEunm::Red)
        {
            isLeft = true;
        }
        data.insert(std::make_pair("isLeft", Value(isLeft)));
        
        std::string eventName = "missionary_dead";
        EventCustom event = EventCustom(eventName);
        event.setUserData((void *)(&data));
        Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
    }
    
	return;
	auto callback = CallFuncN::create( CC_CALLBACK_0(HeroEnety::deadcallback,this));
	auto dt = DelayTime::create(1);
	auto fo = FadeOut::create(1);
	//auto d = Sequence::create((Animate*)Action_Dead, dt, callback, nullptr);
	auto d = Sequence::create(fo, dt, callback,nullptr);
	this->runAction(d);
}
Example #3
0
void HeroEnety::attainBase(RaceEunm race)
{
    ValueMap data;
    float fractionOffset, humanResOffset, HPOffset;
    switch (mMentalEnum) {
        case MentalEnum::Normal:
            fractionOffset = SacrificeValueWhenNormal;
            humanResOffset = HumanPowerWhenNormal;
            HPOffset = HitPointWhenNormal;
            break;
        case MentalEnum::Captured:
            fractionOffset = SacrificeValueWhenCaptured;
            humanResOffset = HumanPowerWhenCaptured;
            HPOffset = HitPointWhenCaptured;
            break;
        default:
            break;
    }
    data.insert(std::make_pair("fractionOffset", Value(fractionOffset)));
    data.insert(std::make_pair("humanResOffset", Value(humanResOffset)));
    data.insert(std::make_pair("HPOffset", Value(HPOffset)));
    data.insert(std::make_pair("RaceEunm", Value(race)));
    
    std::string eventName = "event_arrive_base";
    EventCustom event = EventCustom(eventName);
    event.setUserData((void *)(&data));
    Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
}
Example #4
0
//把达成条件的结果保存到相应用户数据中
void UnLockSystem::UnLockData(ValueMapIntMultiKey* vmi)
{
    ValueMap* vm;
    for (auto iter = vmi->begin(); iter != vmi->end(); iter++)
    {
        switch (iter->first)
        {
            case 100700001: //解锁建造建筑
            {
                vm = &UserData::getInstance()->GetUserData(UserDataEnum::MakeBuild)->asValueMap();
                vm->insert(pair<string, Value>(StringUtils::format("%d", iter->second.asInt()), Value(0)));
                break;
            }
            case 100700002: //解锁制作物品
            {
                vm = &UserData::getInstance()->GetUserData(UserDataEnum::MakeItem)->asValueMap();
                vm->insert(pair<string, Value>(StringUtils::format("%d", iter->second.asInt()), Value(true)));
                break;
            }
            case 100700003: //解锁商店物品
            {
                vm = &UserData::getInstance()->GetUserData(UserDataEnum::ShopItem)->asValueMap();
                vm->insert(pair<string, Value>(StringUtils::format("%d", iter->second.asInt()), Value(true)));
                break;
            }
            case 100700006: //解锁生产
            {
                vm = &UserData::getInstance()->GetUserData(UserDataEnum::Production)->asValueMap();
                vm->insert(pair<string, Value>(StringUtils::format("%d", iter->second.asInt()), Value(0)));
                break;
            }
            default:
                CCLOGERROR("UnLock Type Error typeId:%d", iter->first);
                break;
        }
    }
//    UserData::getInstance()->SaveUserData();
    UserData::getInstance()->SaveCorUserData(false);
    
}
Example #5
0
NamedValues::ValueMap NamedValues::GetValueMap() const
{
    ValueMap vmap;

    auto ientry = m_impl->m_valueEntries.begin();
    for ( ; m_impl->m_valueEntries.end() != ientry; ++ ientry )
    {
        const std::string name = ientry->first;
        
        Detail::ConstNamedValueRef valueRef( name, &( ientry->second ));

        vmap.insert( std::make_pair( name, valueRef.AsString() ));
    }

    return vmap;
}
Example #6
0
static void set_custom_pages_argument(ValueMap &arguments) {
    Dustbin &dustbin = Dustbin::get_instance();
    const std::shared_ptr<Model> &model = dustbin.get_model();
    if (!model) {
        return;
    }
    std::vector<CustomPage> pages;
    Json::Value pages_json(Json::arrayValue);
    model->get_pages(pages, false);
    for (auto &page: pages) {
        Json::Value page_json;
        page_json["id"] = page.id;
        page_json["title"] = page.title;
        page_json["order"] = page.order;
        pages_json.append(page_json);
    }
    arguments.insert(std::make_pair("custom_pages", pages_json));
}
    string paramValueNumber(AstNode* nodep) {
	// Given a compilcated object create a number to use for param module assignment
	// Ideally would be relatively stable if design changes (not use pointer value),
	// and must return same value given same input node
	// Return must presently be numberic so doesn't collide with 'small' alphanumeric parameter names
	ValueMap::iterator it = m_valueMap.find(nodep);
	if (it != m_valueMap.end()) {
	    return cvtToStr(it->second);
	} else {
	    static int BUCKETS = 1000;
	    V3Hash hash (nodep->name());
	    int bucket = hash.hshval() % BUCKETS;
	    int offset = 0;
	    NextValueMap::iterator it = m_nextValueMap.find(bucket);
	    if (it != m_nextValueMap.end()) { offset = it->second; it->second = offset + 1; }
	    else { m_nextValueMap.insert(make_pair(bucket, offset + 1)); }
	    int num = bucket + offset * BUCKETS;
	    m_valueMap.insert(make_pair(nodep, num));
	    return cvtToStr(num);
	}
    }
// the XML parser calls here with all the elements
void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
{    
    CC_UNUSED_PARAM(ctx);
    TMXMapInfo *tmxMapInfo = this;
    std::string elementName = name;
    ValueMap attributeDict;
    if (atts && atts[0])
    {
        for (int i = 0; atts[i]; i += 2)
        {
            std::string key = atts[i];
            std::string value = atts[i+1];
            attributeDict.insert(std::make_pair(key, Value(value)));
        }
    }
    if (elementName == "map")
    {
        std::string version = attributeDict["version"].asString();
        if ( version != "1.0")
        {
            CCLOG("cocos2d: TMXFormat: Unsupported TMX version: %s", version.c_str());
        }
        std::string orientationStr = attributeDict["orientation"].asString();
        if (orientationStr == "orthogonal") {
            tmxMapInfo->setOrientation(TMXOrientationOrtho);
        }
        else if (orientationStr  == "isometric") {
            tmxMapInfo->setOrientation(TMXOrientationIso);
        }
        else if (orientationStr == "hexagonal") {
            tmxMapInfo->setOrientation(TMXOrientationHex);
        }
        else if (orientationStr == "staggered") {
            tmxMapInfo->setOrientation(TMXOrientationStaggered);
        }
        else {
            CCLOG("cocos2d: TMXFomat: Unsupported orientation: %d", tmxMapInfo->getOrientation());
        }

        Size s;
        s.width = attributeDict["width"].asFloat();
        s.height = attributeDict["height"].asFloat();
        tmxMapInfo->setMapSize(s);

        s.width = attributeDict["tilewidth"].asFloat();
        s.height = attributeDict["tileheight"].asFloat();
        tmxMapInfo->setTileSize(s);

        // The parent element is now "map"
        tmxMapInfo->setParentElement(TMXPropertyMap);
    } 
    else if (elementName == "tileset") 
    {
        // If this is an external tileset then start parsing that
        std::string externalTilesetFilename = attributeDict["source"].asString();
        if (externalTilesetFilename != "")
        {
            _externalTilesetFilename = externalTilesetFilename;

            // Tileset file will be relative to the map file. So we need to convert it to an absolute path
            if (_TMXFileName.find_last_of("/") != string::npos)
            {
                string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
                externalTilesetFilename = dir + externalTilesetFilename;
            }
            else 
            {
                externalTilesetFilename = _resources + "/" + externalTilesetFilename;
            }
            externalTilesetFilename = FileUtils::getInstance()->fullPathForFilename(externalTilesetFilename);
            
            _currentFirstGID = attributeDict["firstgid"].asInt();
            if (_currentFirstGID < 0)
            {
                _currentFirstGID = 0;
            }
            _recordFirstGID = false;
            
            tmxMapInfo->parseXMLFile(externalTilesetFilename);
        }
        else
        {
            TMXTilesetInfo *tileset = new (std::nothrow) TMXTilesetInfo();
            tileset->_name = attributeDict["name"].asString();
            
            if (_recordFirstGID)
            {
                // unset before, so this is tmx file.
                tileset->_firstGid = attributeDict["firstgid"].asInt();
                
                if (tileset->_firstGid < 0)
                {
                    tileset->_firstGid = 0;
                }
            }
            else
            {
                tileset->_firstGid = _currentFirstGID;
                _currentFirstGID = 0;
            }
            
            tileset->_spacing = attributeDict["spacing"].asInt();
            tileset->_margin = attributeDict["margin"].asInt();
            Size s;
            s.width = attributeDict["tilewidth"].asFloat();
            s.height = attributeDict["tileheight"].asFloat();
            tileset->_tileSize = s;

            tmxMapInfo->getTilesets().pushBack(tileset);
            tileset->release();
        }
    }
    else if (elementName == "tile")
    {
        if (tmxMapInfo->getParentElement() == TMXPropertyLayer)
        {
            TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
            Size layerSize = layer->_layerSize;
            uint32_t gid = static_cast<uint32_t>(attributeDict["gid"].asInt());
            int tilesAmount = layerSize.width*layerSize.height;
            
            if (_xmlTileIndex < tilesAmount)
            {
                layer->_tiles[_xmlTileIndex++] = gid;
            }
        }
        else
        {
            TMXTilesetInfo* info = tmxMapInfo->getTilesets().back();
            tmxMapInfo->setParentGID(info->_firstGid + attributeDict["id"].asInt());
            tmxMapInfo->getTileProperties()[tmxMapInfo->getParentGID()] = Value(ValueMap());
            tmxMapInfo->setParentElement(TMXPropertyTile);
        }
    }
    else if (elementName == "layer")
    {
        TMXLayerInfo *layer = new (std::nothrow) TMXLayerInfo();
        layer->_name = attributeDict["name"].asString();

        Size s;
        s.width = attributeDict["width"].asFloat();
        s.height = attributeDict["height"].asFloat();
        layer->_layerSize = s;

        Value& visibleValue = attributeDict["visible"];
        layer->_visible = visibleValue.isNull() ? true : visibleValue.asBool();

        Value& opacityValue = attributeDict["opacity"];
        layer->_opacity = opacityValue.isNull() ? 255 : (unsigned char)(255.0f * opacityValue.asFloat());

        float x = attributeDict["x"].asFloat();
        float y = attributeDict["y"].asFloat();
        layer->_offset.set(x, y);

        tmxMapInfo->getLayers().pushBack(layer);
        layer->release();

        // The parent element is now "layer"
        tmxMapInfo->setParentElement(TMXPropertyLayer);
    } 
    else if (elementName == "objectgroup")
    {
        TMXObjectGroup *objectGroup = new (std::nothrow) TMXObjectGroup();
        objectGroup->setGroupName(attributeDict["name"].asString());
        Vec2 positionOffset;
        positionOffset.x = attributeDict["x"].asFloat() * tmxMapInfo->getTileSize().width;
        positionOffset.y = attributeDict["y"].asFloat() * tmxMapInfo->getTileSize().height;
        objectGroup->setPositionOffset(positionOffset);

        tmxMapInfo->getObjectGroups().pushBack(objectGroup);
        objectGroup->release();

        // The parent element is now "objectgroup"
        tmxMapInfo->setParentElement(TMXPropertyObjectGroup);
    }
    else if (elementName == "image")
    {
        TMXTilesetInfo* tileset = tmxMapInfo->getTilesets().back();

        // build full path
        std::string imagename = attributeDict["source"].asString();
        tileset->_originSourceImage = imagename;

        if (_TMXFileName.find_last_of("/") != string::npos)
        {
            string dir = _TMXFileName.substr(0, _TMXFileName.find_last_of("/") + 1);
            tileset->_sourceImage = dir + imagename;
        }
        else 
        {
            tileset->_sourceImage = _resources + (_resources.size() ? "/" : "") + imagename;
        }
    } 
    else if (elementName == "data")
    {
        std::string encoding = attributeDict["encoding"].asString();
        std::string compression = attributeDict["compression"].asString();

        if (encoding == "")
        {
            tmxMapInfo->setLayerAttribs(tmxMapInfo->getLayerAttribs() | TMXLayerAttribNone);
            
            TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
            Size layerSize = layer->_layerSize;
            int tilesAmount = layerSize.width*layerSize.height;

            uint32_t *tiles = (uint32_t*) malloc(tilesAmount*sizeof(uint32_t));
            // set all value to 0
            memset(tiles, 0, tilesAmount*sizeof(int));

            layer->_tiles = tiles;
        }
        else if (encoding == "base64")
        {
            int layerAttribs = tmxMapInfo->getLayerAttribs();
            tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribBase64);
            tmxMapInfo->setStoringCharacters(true);

            if (compression == "gzip")
            {
                layerAttribs = tmxMapInfo->getLayerAttribs();
                tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribGzip);
            } else
            if (compression == "zlib")
            {
                layerAttribs = tmxMapInfo->getLayerAttribs();
                tmxMapInfo->setLayerAttribs(layerAttribs | TMXLayerAttribZlib);
            }
            CCASSERT( compression == "" || compression == "gzip" || compression == "zlib", "TMX: unsupported compression method" );
        }
    } 
    else if (elementName == "object")
    {
        TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();

        // The value for "type" was blank or not a valid class name
        // Create an instance of TMXObjectInfo to store the object and its properties
        ValueMap dict;
        // Parse everything automatically
        const char* keys[] = {"name", "type", "width", "height", "gid"};
        
        for (const auto& key : keys)
        {
            Value value = attributeDict[key];
            dict[key] = value;
        }

        // But X and Y since they need special treatment
        // X
        int x = attributeDict["x"].asInt();
        // Y
        int y = attributeDict["y"].asInt();
        
        Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y  - objectGroup->getPositionOffset().y - attributeDict["height"].asInt());
        p = CC_POINT_PIXELS_TO_POINTS(p);
        dict["x"] = Value(p.x);
        dict["y"] = Value(p.y);
        
        int width = attributeDict["width"].asInt();
        int height = attributeDict["height"].asInt();
        Size s(width, height);
        s = CC_SIZE_PIXELS_TO_POINTS(s);
        dict["width"] = Value(s.width);
        dict["height"] = Value(s.height);

        // Add the object to the objectGroup
        objectGroup->getObjects().push_back(Value(dict));

        // The parent element is now "object"
        tmxMapInfo->setParentElement(TMXPropertyObject);
    } 
    else if (elementName == "property")
    {
        if ( tmxMapInfo->getParentElement() == TMXPropertyNone ) 
        {
            CCLOG( "TMX tile map: Parent element is unsupported. Cannot add property named '%s' with value '%s'",
                  attributeDict["name"].asString().c_str(), attributeDict["value"].asString().c_str() );
        } 
        else if ( tmxMapInfo->getParentElement() == TMXPropertyMap )
        {
            // The parent element is the map
            Value value = attributeDict["value"];
            std::string key = attributeDict["name"].asString();
            tmxMapInfo->getProperties().insert(std::make_pair(key, value));
        }
        else if ( tmxMapInfo->getParentElement() == TMXPropertyLayer )
        {
            // The parent element is the last layer
            TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
            Value value = attributeDict["value"];
            std::string key = attributeDict["name"].asString();
            // Add the property to the layer
            layer->getProperties().insert(std::make_pair(key, value));
        }
        else if ( tmxMapInfo->getParentElement() == TMXPropertyObjectGroup ) 
        {
            // The parent element is the last object group
            TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
            Value value = attributeDict["value"];
            std::string key = attributeDict["name"].asString();
            objectGroup->getProperties().insert(std::make_pair(key, value));
        }
        else if ( tmxMapInfo->getParentElement() == TMXPropertyObject )
        {
            // The parent element is the last object
            TMXObjectGroup* objectGroup = tmxMapInfo->getObjectGroups().back();
            ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();

            std::string propertyName = attributeDict["name"].asString();
            dict[propertyName] = attributeDict["value"];
        }
        else if ( tmxMapInfo->getParentElement() == TMXPropertyTile ) 
        {
            ValueMap& dict = tmxMapInfo->getTileProperties().at(tmxMapInfo->getParentGID()).asValueMap();

            std::string propertyName = attributeDict["name"].asString();
            dict[propertyName] = attributeDict["value"];
        }
    }
    else if (elementName == "polygon") 
    {
        // find parent object's dict and add polygon-points to it
        TMXObjectGroup* objectGroup = _objectGroups.back();
        ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();

        // get points value string
        std::string value = attributeDict["points"].asString();
        if (!value.empty())
        {
            ValueVector pointsArray;
            pointsArray.reserve(10);

            // parse points string into a space-separated set of points
            stringstream pointsStream(value);
            string pointPair;
            while (std::getline(pointsStream, pointPair, ' '))
            {
                // parse each point combo into a comma-separated x,y point
                stringstream pointStream(pointPair);
                string xStr, yStr;
                
                ValueMap pointDict;

                // set x
                if (std::getline(pointStream, xStr, ','))
                {
                    int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
                    pointDict["x"] = Value(x);
                }

                // set y
                if (std::getline(pointStream, yStr, ','))
                {
                    int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
                    pointDict["y"] = Value(y);
                }
                
                // add to points array
                pointsArray.push_back(Value(pointDict));
            }
            
            dict["points"] = Value(pointsArray);
        }
    } 
    else if (elementName == "polyline")
    {
        // find parent object's dict and add polyline-points to it
        TMXObjectGroup* objectGroup = _objectGroups.back();
        ValueMap& dict = objectGroup->getObjects().rbegin()->asValueMap();
        
        // get points value string
        std::string value = attributeDict["points"].asString();
        if (!value.empty())
        {
            ValueVector pointsArray;
            pointsArray.reserve(10);
            
            // parse points string into a space-separated set of points
            stringstream pointsStream(value);
            string pointPair;
            while (std::getline(pointsStream, pointPair, ' '))
            {
                // parse each point combo into a comma-separated x,y point
                stringstream pointStream(pointPair);
                string xStr, yStr;
                
                ValueMap pointDict;
                
                // set x
                if (std::getline(pointStream, xStr, ','))
                {
                    int x = atoi(xStr.c_str()) + (int)objectGroup->getPositionOffset().x;
                    pointDict["x"] = Value(x);
                }
                
                // set y
                if (std::getline(pointStream, yStr, ','))
                {
                    int y = atoi(yStr.c_str()) + (int)objectGroup->getPositionOffset().y;
                    pointDict["y"] = Value(y);
                }
                
                // add to points array
                pointsArray.push_back(Value(pointDict));
            }
            
            dict["polylinePoints"] = Value(pointsArray);
        }
    }
}
Example #9
0
FeatValues FeatValues::operator*(int r)
{
  ValueMap map;
  BOOST_FOREACH(auto const& p, value_map_) {
    map.insert(std::make_pair(p.first, p.second*r));
  }
Example #10
0
FeatValues FeatValues::cheltenham()
{
  ValueMap map;
  map.insert(std::make_pair(std::make_pair(Feat::pagat, false), 1));
  map.insert(std::make_pair(std::make_pair(Feat::pagat, true), 2));
  map.insert(std::make_pair(std::make_pair(Feat::uhu, false), 1));
  map.insert(std::make_pair(std::make_pair(Feat::uhu, true), 3));
  map.insert(std::make_pair(std::make_pair(Feat::kakadu, false), 1));
  map.insert(std::make_pair(std::make_pair(Feat::kakadu, true), 4));
  map.insert(std::make_pair(std::make_pair(Feat::king_ultimo, false), 1));
  map.insert(std::make_pair(std::make_pair(Feat::king_ultimo, true), 2));
  map.insert(std::make_pair(std::make_pair(Feat::forty_five, false), 0));
  map.insert(std::make_pair(std::make_pair(Feat::forty_five, true), 2));
  map.insert(std::make_pair(std::make_pair(Feat::valat, false), 4));
  map.insert(std::make_pair(std::make_pair(Feat::valat, true), 8));
  return FeatValues(map);
}
void MapTerrainParser:: startElement(void *ctx, const char *name, const char **atts)
{
    CC_UNUSED_PARAM(ctx);
    
    string elementName(name);
    ValueMap attributeDict;
    if (atts && atts[0])
    {
        for(int i = 0; atts[i]; i += 2)
        {
            std::string key = (char*)atts[i];
            std::string value = (char*)atts[i+1];
            attributeDict.insert(std::make_pair(key, Value(value)));
        }
    }
    
    if (elementName == "map") {
        
        _layerTerrainInfo.clear();
        
    } else if (elementName == "tileset") {
        
        // create a new LayerTerrainInfo object.
        if (_terraininfo != nullptr)
            CC_SAFE_RELEASE_NULL(_terraininfo);
        
        
        _terraininfo = LayerTerrainInfo::create();
        CC_SAFE_RETAIN(_terraininfo);
        _terraininfo->setName(attributeDict["name"].asString());
        
        
    } else if (elementName == "terraintypes") {
        
        // <terraintypes> tag start
        _terraintypes = {};
        
    } else if (elementName == "terrain") {
        // get terrain types of current tile set in order
        _terraintypes.push_back(attributeDict["name"]);
        
    } else if (elementName == "tile") {
 
        std::vector<string> data;
        split(attributeDict["terrain"].asString(), ",", data);
        Value value;
        
        // entire tile have only one terrain type
        for (int i =0; i<data.size(); i++)
        {
            if (!data[i].empty()) {
                value = data[i];
                break;
            }
        }
        
        auto tileTerrain = LayerTerrainInfo::TileTerrain::create(attributeDict["id"].asInt(), value);
        //
        _tileTerrainInfo.pushBack(tileTerrain);
    }
}