//----------------------------------------------------------------------------
bool ResourceManager::AddTexPack (const std::string &texPackPath)
{
	if (mTexPacks.find(texPackPath) != mTexPacks.end())
		return false;

	int bufferSize = 0;
	char *buffer = 0;
	if (GetBuffer(texPackPath, bufferSize, buffer))
	{
		std::string outPath;
		std::string outBaseName;
		std::string outExt;
		StringHelp::SplitFullFilename(texPackPath, outPath, outBaseName, outExt);

		XMLData data;
		if (data.LoadBuffer(buffer, bufferSize))
		{
			XMLNode rootNode = data.GetRootNode();
			std::string imagePath = rootNode.AttributeToString("imagePath");
			int width = rootNode.AttributeToInt("width");
			int height = rootNode.AttributeToInt("height");
			TexPack pack;
			pack.ImagePath = imagePath;
			pack.Width = width;
			pack.Height = height;

			XMLNode childNode = rootNode.IterateChild();
			while (!childNode.IsNull())
			{
				std::string eleName;
				int x = 0;
				int y = 0;
				int w = 0;
				int h = 0;
				int oX = 0;
				int oY = 0;
				int oW = 0;
				int oH = 0;
				bool rolated = false;

				if (childNode.HasAttribute("n"))
					eleName = childNode.AttributeToString("n");
				if (childNode.HasAttribute("x"))
					x = childNode.AttributeToInt("x");
				if (childNode.HasAttribute("y"))
					y = childNode.AttributeToInt("y");
				if (childNode.HasAttribute("w"))
					w = childNode.AttributeToInt("w");
				if (childNode.HasAttribute("h"))
					h = childNode.AttributeToInt("h");
				if (childNode.HasAttribute("oX"))
					oX = childNode.AttributeToInt("oX");
				if (childNode.HasAttribute("oY"))
					oY = childNode.AttributeToInt("oY");
				if (childNode.HasAttribute("oW"))
					oW = childNode.AttributeToInt("oW");
				if (childNode.HasAttribute("oH"))
					oH = childNode.AttributeToInt("oH");
				if (childNode.HasAttribute("r"))
					rolated = (std::string(childNode.AttributeToString("r"))=="y");
				
				TexPackElement ele;
				ele.X = x;
				ele.Y = y;
				ele.W = w;
				ele.H = h;
				ele.OX = oX;
				ele.OY = oY;
				ele.OW = oW;
				ele.OH = oH;
				ele.Rolated = rolated;
				ele.TexWidth = width;
				ele.TexHeight = height;
				ele.ElementName = eleName;
				ele.ImagePathFull = outPath+imagePath;

				pack.Elements.push_back(ele);

				std::string allStr = texPackPath+eleName;
				mPackElements[allStr] = ele;

				childNode = rootNode.IterateChild(childNode);
			}

			mTexPacks[texPackPath] = pack;
		}

		delete1(buffer);

		return true;
	}

	return false;
}
Example #2
0
//----------------------------------------------------------------------------
bool Project::Load(const std::string &filename)
{
    std::string name;
    int width = 0;
    int height = 0;
    std::string sceneFilename;
    std::string uiFilename;
    std::string languageFilename;

    char *buffer = 0;
    int bufferSize = 0;
    if (PX2_RM.LoadBuffer(filename, bufferSize, buffer))
    {
        XMLData data;
        if (data.LoadBuffer(buffer, bufferSize))
        {
            XMLNode rootNode = data.GetRootNode();

            // general
            XMLNode generalNode = rootNode.GetChild("general");
            if (!generalNode.IsNull())
            {
                name = generalNode.AttributeToString("name");

                SetScreenOrientation(_FromSOStr(generalNode.AttributeToString("screenorientation")));

                width = generalNode.AttributeToInt("width");
                height = generalNode.AttributeToInt("height");

                std::string colorStr = generalNode.AttributeToString("backcolor");
                StringTokenizer stk(colorStr, ",");
                Float4 color = Float4::MakeColor(
                                   StringHelp::StringToInt(stk[0]),
                                   StringHelp::StringToInt(stk[1]),
                                   StringHelp::StringToInt(stk[2]),
                                   StringHelp::StringToInt(stk[3]));

                std::string projcolorStr = generalNode.AttributeToString("projcolor");
                StringTokenizer stkprojcolor(projcolorStr, ",");
                Float4 projcolor = Float4::MakeColor(
                                       StringHelp::StringToInt(stkprojcolor[0]),
                                       StringHelp::StringToInt(stkprojcolor[1]),
                                       StringHelp::StringToInt(stkprojcolor[2]),
                                       StringHelp::StringToInt(stkprojcolor[3]));

                Sizef size = Sizef((float)width, (float)height);
                SetName(name);
                SetSize(size);
                mViewRect = Rectf(0.0f, 0.0f, size.Width, size.Height);
                SetBackgroundColor(color);
                SetProjBackgroundColor(projcolor);
            }

            // scene
            XMLNode sceneNode = rootNode.GetChild("scene");
            if (!sceneNode.IsNull())
            {
                sceneFilename = sceneNode.AttributeToString("filename");
                SetSceneFilename(sceneFilename);
            }

            XMLNode renderNode = rootNode.GetChild("render_setting");
            if (!renderNode.IsNull())
            {
            }

            // language
            XMLNode languageNode = rootNode.GetChild("language");

            // publish
            XMLNode publishNode = rootNode.GetChild("publish");

            // setting
            XMLNode settingNode = rootNode.GetChild("setting");
            if (!settingNode.IsNull())
            {
                if (settingNode.HasAttribute("uicamerapercent"))
                    mEdit_UICameraPercent = settingNode.AttributeToFloat("uicamerapercent");
            }

            // split file names
            std::string outPath;
            std::string outBaseName;
            std::string outExt;
            StringHelp::SplitFullFilename(filename, outPath, outBaseName, outExt);

            // ui
            mUIFilename = outPath + outBaseName + "_ui.px2obj";
        }
    }
    else
    {
        return false;
    }

    return true;
}