//================================================================================================================ void MenuEditorSystem::AddMenuBackground() { if (BetterString(m_BackgroundImageName) != "") { string spritesPath = ""; switch (m_EngineOptions->m_DimType) { case ZSHADE_2D: { spritesPath = m_mainGameDirectory2D->m_sprites_path; } break; case ZSHADE_3D: { // Need to figure out where the images are loaded from in 3D //spritesPath = m_mainGameDirectory3D->m_sprites_path; } break; } m_Updated = true; ZShadeSandboxGraphics::Image* image = new ZShadeSandboxGraphics::Image( m_D3DSystem, m_BackgroundImageName, spritesPath, 0, 0, m_EngineOptions->m_screenWidth, m_EngineOptions->m_screenHeight); EnvironmentMenuHelper::AddBackground(image); } }
//================================================================================================================ void HUDEditorSystem::AddImage() { if (m_HUDCreated && editType == ET_Image && action == A_Place) { if (BetterString(m_SelectedImageImageName) != "") { m_Updated = true; string hud_sprites_path; switch (m_EngineOptions->m_DimType) { case ZSHADE_2D: { hud_sprites_path = m_mainGameDirectory2D->m_hud_path; } break; case ZSHADE_3D: { hud_sprites_path = m_mainGameDirectory3D->m_hud_path; } break; } EnvironmentHUDHelper::AddImage( hud_sprites_path, m_SelectedImageImageName, m_SelectedMousePos.x, m_SelectedMousePos.y, 64, 64 ); } } }
//================================================================================================================ void ToolWindow2DEditorTab::SetGameTypeRC(string val) { if (BetterString(val) == "Topdown") { m_platformer = false; m_EngineOptions->m_GameType2D = TOPDOWN; SendMessage(m_GameTypeRC.GetButtonHandle(0), BM_SETCHECK, BST_CHECKED, 0); SendMessage(m_GameTypeRC.GetButtonHandle(1), BM_SETCHECK, BST_UNCHECKED, 0); m_GameTypeRC.Enable(false); } else if (BetterString(val) == "Platformer") { m_platformer = true; m_EngineOptions->m_GameType2D = PLATFORMER; SendMessage(m_GameTypeRC.GetButtonHandle(0), BM_SETCHECK, BST_UNCHECKED, 0); SendMessage(m_GameTypeRC.GetButtonHandle(1), BM_SETCHECK, BST_CHECKED, 0); m_GameTypeRC.Enable(false); } }
//================================================================================================================ void MenuEditorSystem::OnMouseMove(WPARAM btnState, int x, int y) { // Start a left button drag of an item if ((btnState & MK_LBUTTON) != 0) { m_SelectedMousePos.x = x; m_SelectedMousePos.y = y; m_leftButtonDown = true; // If applicable, Add a button if (BetterString(m_SelectedButtonImageName) != "") { AddButton(); } // If applicable, Add a text AddText(); } else { m_leftButtonDown = false; } m_MouseMovePos = SnapToGrid(x, y); // Move a button or text display cover if (editType == ET_Button && (action == A_Place || action == A_Move)) { if (m_displaySpriteCover == NULL) { if (BetterString(m_SelectedButtonImageName) != "") { m_displaySpriteCover = new Sprite(m_D3DSystem); m_displaySpriteCover->Initialize(m_mainGameDirectory->m_menu_sprites_path, m_SelectedButtonImageName, XMFLOAT3(m_MouseMovePos.x, m_MouseMovePos.y, 0), 80, 30, PhysicsType::STATIC); } } } }
//================================================================================================================ void MenuEditorSystem::AddText() { if (editType == ET_Text && action == A_Place) { ZShadeSandboxGraphics::Text* t = new ZShadeSandboxGraphics::Text(); t->SetD3D(m_D3DSystem); t->Initialize(); t->TextName() = BetterString("Text"); t->CreateShadow(); t->ChangeFont(L"Times New Roman", 12, FontStyle::BoldItalic, true); t->TextTransform() = XMMatrixTranslation(m_SelectedMousePos.x, m_SelectedMousePos.y, 0); t->TextColor() = XMFLOAT4(1, 0, 0, 1); m_Updated = true; EnvironmentMenuHelper::AddMenuText(m_ActiveMenuName, t); } }
//================================================================================================================ void MenuEditorSystem::OnMouseDown(WPARAM btnState, int x, int y) { // Start a left button drag of an item if ((btnState & MK_LBUTTON) != 0) { m_leftButtonDown = true; m_SelectedMousePos.x = x; m_SelectedMousePos.y = y; // If applicable, Add a button if (BetterString(m_SelectedButtonImageName) != "") { AddButton(); } // If applicable, Add a text AddText(); } }
//================================================================================================================ void MenuEditorSystem::AddButton() { if (editType == ET_Button && action == A_Place) { if (BetterString(m_SelectedButtonImageName) != "") { m_Updated = true; string menu_sprites_path; switch (m_EngineOptions->m_DimType) { case ZSHADE_2D: { menu_sprites_path = m_mainGameDirectory2D->m_menu_sprites_path; } break; case ZSHADE_3D: { menu_sprites_path = m_mainGameDirectory3D->m_menu_sprites_path; } break; } EnvironmentMenuHelper::AddButton( menu_sprites_path, m_SelectedButtonImageName, m_SelectedButtonImageName, m_SelectedButtonImageName, m_SelectedButtonImageName, m_SelectedMousePos.x, m_SelectedMousePos.y ); } } }
//================================================================================================================ void MenuEditorSystem::UpdateDisplaySprite(float x, float y) { if (m_MenuCreated && editType == ET_Button && action == A_Place) { if (m_displaySpriteCover == NULL) { if (BetterString(m_SelectedButtonImageName) != "") { string menuSpritesPath = ""; switch (m_EngineOptions->m_DimType) { case ZSHADE_2D: { menuSpritesPath = m_mainGameDirectory2D->m_menu_sprites_path; } break; case ZSHADE_3D: { menuSpritesPath = m_mainGameDirectory3D->m_menu_sprites_path; } break; } m_displaySpriteCover = new Sprite(m_D3DSystem); m_displaySpriteCover->Initialize(menuSpritesPath, m_SelectedButtonImageName, XMFLOAT3(x, y, 0), 80, 30, PhysicsType::STATIC); } } else { m_displaySpriteCover->TopLeftPosition() = XMFLOAT3(x, y, 0); } } if (m_MenuCreated && editType == ET_Button && action == A_Clone) { //Render the selected sprite from the sprite cache with the mouse cursor if (m_selected_button_cover) { if (m_cloneDisplaySpriteCover != 0) { //Need to remove the current display sprite if there is one m_cloneDisplaySpriteCover = 0; } string menuSpritesPath = ""; switch (m_EngineOptions->m_DimType) { case ZSHADE_2D: { menuSpritesPath = m_mainGameDirectory2D->m_menu_sprites_path; } break; case ZSHADE_3D: { menuSpritesPath = m_mainGameDirectory3D->m_menu_sprites_path; } break; } m_displaySpriteCover = m_SelectedButtonSprite->ToSprite(menuSpritesPath); m_selected_button_cover = false; } if (m_cloneDisplaySpriteCover != 0) { m_cloneDisplaySpriteCover->TopLeftPosition().x = x; m_cloneDisplaySpriteCover->TopLeftPosition().y = y; } } if (m_MenuCreated && editType == ET_Text && action == A_Clone) { //Render the selected sprite from the sprite cache with the mouse cursor if (m_selected_text_cover) { if (m_cloneDisplayTextSprite != 0) { //Need to remove the current display sprite if there is one m_cloneDisplayTextSprite = 0; } m_cloneDisplayTextSprite = m_SelectedTextSprite->Clone(); m_selected_text_cover = false; } if (m_cloneDisplayTextSprite != 0) { m_cloneDisplayTextSprite->TextTransform() = XMMatrixTranslation(x, y, 0); } } }
//=============================================================================================================================== ID3D11ShaderResourceView* TextureManager::CreateTexture2DArraySRV(std::vector<std::string>& filenames) { // // Load the texture elements individually from file. These textures // won't be used by the GPU (0 bind flags), they are just used to // load the image data from file. We use the STAGING usage so the // CPU can read the resource. // UINT size = filenames.size(); HRESULT result; std::vector<ID3D11Texture2D*> srcTex(size); for(UINT i = 0; i < size; ++i) { unique_ptr<wchar_t> name = BetterString(filenames[i].c_str()).ToWideStr(); // ReleaseAndGetAddressOf result = CreateDDSTextureFromFileEx(mD3DSystem->GetDevice11(), name.get(), 0u, D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, 0,//D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ, 0, false, reinterpret_cast<ID3D11Resource**>(&srcTex[i]), nullptr, nullptr); if (FAILED(result)) { return 0; } } // // Create the texture array. Each element in the texture // array has the same format/dimensions. // D3D11_TEXTURE2D_DESC texElementDesc; srcTex[0]->GetDesc(&texElementDesc); /* Usage: D3D11_USAGE_DEFAULT - Video RAM D3D11_USAGE_STAGING - in the system RAM and cannot be used by the GPU at all D3D11_USAGE_DYNAMIC - CPU- and GPU-addressable RAM D3D11_USAGE_IMMUTABLE */ D3D11_TEXTURE2D_DESC texArrayDesc; texArrayDesc.Width = texElementDesc.Width; texArrayDesc.Height = texElementDesc.Height; texArrayDesc.MipLevels = texElementDesc.MipLevels; texArrayDesc.ArraySize = size; texArrayDesc.Format = texElementDesc.Format; texArrayDesc.SampleDesc.Count = 1; texArrayDesc.SampleDesc.Quality = 0; texArrayDesc.Usage = D3D11_USAGE_DEFAULT; texArrayDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; texArrayDesc.CPUAccessFlags = 0;// D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ; texArrayDesc.MiscFlags = 0; ID3D11Texture2D* texArray = 0; mD3DSystem->GetDevice11()->CreateTexture2D(&texArrayDesc, 0, &texArray); // // Copy individual texture elements into texture array. // // for each texture element... for(UINT texElement = 0; texElement < size; ++texElement) { // for each mipmap level... for(UINT mipLevel = 0; mipLevel < texElementDesc.MipLevels; ++mipLevel) { mD3DSystem->GetDeviceContext()->CopySubresourceRegion(texArray, D3D11CalcSubresource(mipLevel, texElement, texElementDesc.MipLevels), 0, 0, 0, srcTex[texElement], mipLevel, nullptr); } } // Release the temporary Video Memory used per texture for (UINT i = 0; i < size; ++i) SAFE_RELEASE(srcTex[i]); // // Create a resource view to the texture array. // D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; viewDesc.Format = texArrayDesc.Format; viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; viewDesc.Texture2DArray.MostDetailedMip = 0; viewDesc.Texture2DArray.MipLevels = texArrayDesc.MipLevels; viewDesc.Texture2DArray.FirstArraySlice = 0; viewDesc.Texture2DArray.ArraySize = size; ID3D11ShaderResourceView* texArraySRV = 0; mD3DSystem->GetDevice11()->CreateShaderResourceView(texArray, &viewDesc, &texArraySRV); // // Cleanup - we only need the resource view. // SAFE_RELEASE(texArray); // Return the new texture array return texArraySRV; }
//=============================================================================================================================== bool ZShadeXMLLoader::LoadMapXML(string& mapname, string filename, GameDirectory2D* gd, D3D* d3d, TopdownMap*& map, bool inEditor) { XMLParser xmlParser(filename); const char* map_name_str = xmlParser.ReadElement("map_name"); const char* xml_sprite_str = xmlParser.ReadElement("xml_sprite"); const char* map_type_str = xmlParser.ReadElement("map_type"); const char* row_size_str = xmlParser.ReadElement("row_size"); const char* col_size_str = xmlParser.ReadElement("col_size"); const char* vision_str = xmlParser.ReadElement("vision"); const char* music_str = xmlParser.ReadElement("music"); int row_size = atoi(row_size_str); int col_size = atoi(col_size_str); d3d->GetEngineOptions()->SECTION_ROW_SIZE = row_size; d3d->GetEngineOptions()->SECTION_COL_SIZE = col_size; d3d->GetEngineOptions()->SetTileMax(); bool fow_enabled; int fow_radius; bool fow_flashlight; xmlParser.ReadAttribute("Fow", "enabled", fow_enabled); xmlParser.ReadAttribute("Fow", "radius", fow_radius); xmlParser.ReadAttribute("Fow", "flashlight", fow_flashlight); MapLoadData mld; mld.mapVision = atoi(vision_str); mld.mapMusicName = string(music_str); ArrayElementXMLParser tilesParser(xmlParser.Element()); tilesParser.ReadArrayElement("Tiles", "Tile"); do { string eName = tilesParser.ReadArrayElementValue(); string eIDAtt = tilesParser.ReadArrayElementAttribute("id"); string eImageNameAtt = tilesParser.ReadArrayElementAttribute("image"); const char* x_str = tilesParser.ReadArrayChildElement("x"); const char* y_str = tilesParser.ReadArrayChildElement("y"); const char* animation_str = tilesParser.ReadArrayChildElement("animation"); const char* anim_speed_str = tilesParser.ReadArrayChildElement("anim_speed"); const char* hard_str = tilesParser.ReadArrayChildElement("hard"); int x = atoi(x_str); int y = atoi(y_str); int anim_speed = atoi(anim_speed_str); int hard = atoi(hard_str); mld.imageNames.push_back(eImageNameAtt); mld.animProfileNames.push_back(string(animation_str)); mld.animSpeeds.push_back(anim_speed); mld.hards.push_back(hard); } while (tilesParser.ArrayElementNotNull("Tile")); Map2DType mt; if (BetterString(map_type_str) == "Regular") mt = Map2DType::REGULAR; else if (BetterString(map_type_str) == "Isometric") mt = Map2DType::ISOMETRIC; map = new TopdownMap(d3d, mt, gd); if (!map) return false; map->InEditor() = inEditor; map->Initialize(row_size, mld); // Set the FOW data map->FOW() = fow_enabled; map->FOWRadius() = fow_radius; map->FOWFlashlight() = fow_flashlight; //BetterString str(gd->m_xml_sprites_path); //str += "\\"; //str += xml_sprite_str; //Load the sprites onto the map LoadSpritesXML(xml_sprite_str, gd, d3d, map); return true; }
//=============================================================================================================================== bool ZShadeXMLLoader::LoadHUDXML(string filename, GameDirectory2D* gd, EngineOptions* eo, D3D* d3d, HUD*& hs) { XMLParser xmlParser(filename); const char* hud_size_str = xmlParser.ReadElement("hud_size"); BetterString hud_splite_str(hud_size_str); vector<string> split_str = hud_splite_str.split('x'); int width = atoi(split_str[0].c_str()); int height = atoi(split_str[1].c_str()); if (hs == 0) { hs = new HUD(d3d); } hs->Width() = width; hs->Height() = height; ArrayElementXMLParser imagesParser(xmlParser.Element()); imagesParser.ReadArrayElement("Images", "Image"); do { string eName = imagesParser.ReadArrayElementValue(); string eIDAtt = imagesParser.ReadArrayElementAttribute("id"); const char* x_str = imagesParser.ReadArrayChildElement("image_x"); const char* y_str = imagesParser.ReadArrayChildElement("image_y"); const char* image_width_str = imagesParser.ReadArrayChildElement("image_width"); const char* image_height_str = imagesParser.ReadArrayChildElement("image_height"); const char* image_name_str = imagesParser.ReadArrayChildElement("image_name"); ZShadeSandboxGraphics::Image* im = new ZShadeSandboxGraphics::Image( d3d, string(image_name_str), gd->m_hud_path, atof(x_str), atof(y_str), atoi(image_width_str), atoi(image_height_str) ); hs->AddImage(im); } while (imagesParser.ArrayElementNotNull("Image")); ArrayElementXMLParser textsParser(xmlParser.Element()); textsParser.ReadArrayElement("Texts", "Text"); do { string eName = textsParser.ReadArrayElementValue(); string eIDAtt = textsParser.ReadArrayElementAttribute("id"); const char* x_str = textsParser.ReadArrayChildElement("text_x"); const char* y_str = textsParser.ReadArrayChildElement("text_y"); const char* text_str = textsParser.ReadArrayChildElement("text"); const char* text_font_str = textsParser.ReadArrayChildElement("text_font"); const char* text_color_str = textsParser.ReadArrayChildElement("text_color"); const char* shadow_str = textsParser.ReadArrayChildElement("shadow"); const char* optional_background_str = textsParser.ReadArrayChildElement("optional_background"); XMFLOAT3 color = ZShadeSandboxGlobal::Convert::ConvertToFloat3(string(text_color_str)); bool shadow = (string(shadow_str) == "1") ? true : false; ZShadeSandboxGraphics::Text* t = new ZShadeSandboxGraphics::Text(); t->SetD3D(d3d); t->Initialize(); t->TextName() = BetterString(text_str); if (shadow) { t->CreateShadow(); } t->ChangeFont(L"Times New Roman", atoi(text_font_str), FontStyle::BoldItalic, true); t->TextTransform() = XMMatrixTranslation(atof(x_str), atof(y_str), 0); t->TextColor() = XMFLOAT4(color.x, color.y, color.z, 1); hs->AddText(t); } while (textsParser.ArrayElementNotNull("Text")); return true; }
//=============================================================================================================================== bool ZShadeXMLLoader::LoadMaterialXML(string basePath, string filename, D3D* d3d) { XMLParser xmlParser(filename); const char* material_name_str = xmlParser.ReadElement("Name"); const char* enable_shadowmap_str = xmlParser.ReadElement("EnableShadowMap"); const char* enable_ssao_str = xmlParser.ReadElement("EnableSSAO"); const char* enable_transparency_str = xmlParser.ReadElement("EnableTransparency"); const char* enable_lighting_str = xmlParser.ReadElement("EnableLighting"); const char* detail_brightness_str = xmlParser.ReadElement("DetailBrightness"); const char* alpha_to_coverage_str = xmlParser.ReadElement("AlphaToCoverage"); const char* ambient_color_str = xmlParser.ReadElement("AmbientColor"); const char* diffuse_color_str = xmlParser.ReadElement("DiffuseColor"); const char* specular_color_str = xmlParser.ReadElement("SpecularColor"); const char* emissive_color_str = xmlParser.ReadElement("EmissiveColor"); const char* specular_power_str = xmlParser.ReadElement("SpecularPower"); const char* specular_intensity_str = xmlParser.ReadElement("SpecularIntensity"); const char* emissive_str = xmlParser.ReadElement("Emissivity"); const char* reflectivity_str = xmlParser.ReadElement("Reflectivity"); const char* transmissivity_str = xmlParser.ReadElement("Transmissivity"); const char* transmission_filter_str = xmlParser.ReadElement("TransmissionFilter"); const char* alpha_str = xmlParser.ReadElement("Alpha"); const char* refraction_index_str = xmlParser.ReadElement("RefractionIndex"); const char* no_dist_tess_factor_str = xmlParser.ReadElement("NoDistTessFactor"); const char* min_tess_dist_str = xmlParser.ReadElement("MinTessDist"); const char* max_tess_dist_str = xmlParser.ReadElement("MaxTessDist"); const char* min_tess_factor_str = xmlParser.ReadElement("MinTessFactor"); const char* max_tess_factor_str = xmlParser.ReadElement("MaxTessFactor"); const char* enable_dist_tess_str = xmlParser.ReadElement("EnableDistTess"); const char* illumination_model_str = xmlParser.ReadElement("IlluminationModel"); vector<string> diffuseArrayTextureNames; ArrayElementXMLParser diffuseArrayParser(xmlParser.Element()); diffuseArrayParser.ReadArrayElement("DiffuseArray", "Texture"); do { string eName = diffuseArrayParser.ReadArrayElementValue(); string eIDAtt = diffuseArrayParser.ReadArrayElementAttribute("id"); const char* tex_name_str = diffuseArrayParser.ReadArrayChildElement("TexName"); diffuseArrayTextureNames.push_back(string(tex_name_str)); } while (diffuseArrayParser.ArrayElementNotNull("Texture")); const char* diffuse_texture_str = xmlParser.ReadElement("DiffuseTexture"); const char* ambient_texture_str = xmlParser.ReadElement("AmbientTexture"); const char* specular_texture_str = xmlParser.ReadElement("SpecularTexture"); const char* emissive_texture_str = xmlParser.ReadElement("EmissiveTexture"); const char* detail_texture_str = xmlParser.ReadElement("DetailTexture"); const char* normal_texture_str = xmlParser.ReadElement("NormalTexture"); const char* blend_texture_str = xmlParser.ReadElement("BlendTexture"); const char* alpha_texture_str = xmlParser.ReadElement("AlphaTexture"); string name(material_name_str); bool enableShadowMap = (BetterString(enable_shadowmap_str) == "true") ? true : false; bool enableSSAO = (BetterString(enable_ssao_str) == "true") ? true : false; bool enableTransparency = (BetterString(enable_transparency_str) == "true") ? true : false; bool enableLighting = (BetterString(enable_lighting_str) == "true") ? true : false; float detailBrightness = atof(detail_brightness_str); XMFLOAT3 alphaToCoverage = ZShadeSandboxGlobal::Convert::ConvertToFloat3(alpha_to_coverage_str); XMFLOAT4 ambientColor = ZShadeSandboxGlobal::Convert::ConvertToFloat4(ambient_color_str); XMFLOAT4 diffuseColor = ZShadeSandboxGlobal::Convert::ConvertToFloat4(diffuse_color_str); XMFLOAT4 specularColor = ZShadeSandboxGlobal::Convert::ConvertToFloat4(specular_color_str); XMFLOAT4 emissiveColor = ZShadeSandboxGlobal::Convert::ConvertToFloat4(emissive_color_str); float specularPower = atof(specular_power_str); float specularIntensity = atof(specular_intensity_str); float emissive = atof(emissive_str); float reflectivity = atof(reflectivity_str); float transmissivity = atof(transmissivity_str); float alpha = atof(alpha_str); XMFLOAT3 transmissionFilter = ZShadeSandboxGlobal::Convert::ConvertToFloat3(transmission_filter_str); float refractionIndex = atof(refraction_index_str); float noDistTessFactor = atof(no_dist_tess_factor_str); float minTessDist = atof(min_tess_dist_str); float maxTessDist = atof(max_tess_dist_str); float minTessFactor = atof(min_tess_factor_str); float maxTessFactor = atof(max_tess_factor_str); bool enableDistTess = (BetterString(enable_dist_tess_str) == "true") ? true : false; int illuminationModel = atoi(illumination_model_str); string diffuseTextureName(diffuse_texture_str); string ambientTextureName(ambient_texture_str); string specularTextureName(specular_texture_str); string emissiveTextureName(emissive_texture_str); string detailTextureName(detail_texture_str); string normalTextureName(normal_texture_str); string blendTextureName(blend_texture_str); string alphaTextureName(alpha_texture_str); // // Load the material into the material manager // ZShadeSandboxLighting::ShaderMaterial* material = new ZShadeSandboxLighting::ShaderMaterial(d3d, name); material->bHasShadowMap = enableShadowMap; material->bHasSSAOMap = enableSSAO; material->bHasTransparency = enableTransparency; material->bEnableLighting = enableLighting; material->fDetailBrightness = detailBrightness; material->vAlphaToCoverageValue = alphaToCoverage; material->vAmbientColor = ambientColor; material->vDiffuseColor = diffuseColor; material->vSpecularColor = specularColor; material->vEmissiveColor = emissiveColor; bool hasDiffuseArrayTexture; (BetterString(diffuseArrayTextureNames[0]) == "NONE") ? hasDiffuseArrayTexture = false : hasDiffuseArrayTexture = true; if (hasDiffuseArrayTexture) material->CreateTexture2DArray(diffuseArrayTextureNames); material->fSpecularPower = specularPower; material->fSpecularIntensity = specularIntensity; material->fEmissivity = emissive; material->fReflectivity = reflectivity; material->fTransmissivity = transmissivity; material->fAlpha = alpha; material->vTransmissionFilter = transmissionFilter; material->fRefractionIndex = refractionIndex; material->fNoDistTessFactor = noDistTessFactor; material->fMinTessDist = minTessDist; material->fMaxTessDist = maxTessDist; material->fMinTessFactor = minTessFactor; material->fMaxTessFactor = maxTessFactor; material->bEnableDistTess = enableDistTess; material->iIlluminationModel = illuminationModel; bool hasDiffuseTexture; (BetterString(diffuseTextureName) == "NONE") ? hasDiffuseTexture = false : hasDiffuseTexture = true; if (hasDiffuseTexture) material->AddDiffuseTexture(basePath, diffuseTextureName); bool hasAmbientTexture; (BetterString(ambientTextureName) == "NONE") ? hasAmbientTexture = false : hasAmbientTexture = true; if (hasAmbientTexture) material->AddAmbientTexture(basePath, ambientTextureName); bool hasSpecularTexture; (BetterString(specularTextureName) == "NONE") ? hasSpecularTexture = false : hasSpecularTexture = true; if (hasSpecularTexture) material->AddSpecularTexture(basePath, specularTextureName); bool hasEmissiveTexture; (BetterString(emissiveTextureName) == "NONE") ? hasEmissiveTexture = false : hasEmissiveTexture = true; if (hasEmissiveTexture) material->AddEmissiveTexture(basePath, emissiveTextureName); bool hasDetailTexture; (BetterString(detailTextureName) == "NONE") ? hasDetailTexture = false : hasDetailTexture = true; if (hasDetailTexture) material->AddDetailMapTexture(basePath, detailTextureName); bool hasNormalMapTexture; (BetterString(normalTextureName) == "NONE") ? hasNormalMapTexture = false : hasNormalMapTexture = true; if (hasNormalMapTexture) material->AddNormalMapTexture(basePath, normalTextureName); bool hasBlendMapTexture; (BetterString(blendTextureName) == "NONE") ? hasBlendMapTexture = false : hasBlendMapTexture = true; if (hasBlendMapTexture) material->AddBlendMapTexture(basePath, blendTextureName); bool hasAlphaMapTexture; (BetterString(alphaTextureName) == "NONE") ? hasAlphaMapTexture = false : hasAlphaMapTexture = true; if (hasAlphaMapTexture) material->AddAlphaMapTexture(basePath, alphaTextureName); material->bHasDiffuseArrayTexture = hasDiffuseArrayTexture; material->bHasDiffuseTexture = hasDiffuseTexture; material->bHasAmbientTexture = hasAmbientTexture; material->bHasSpecularTexture = hasSpecularTexture; material->bHasEmissiveTexture = hasEmissiveTexture; material->bHasDetailMapTexture = hasDetailTexture; material->bHasNormalMapTexture = hasNormalMapTexture; material->bHasBlendMapTexture = hasBlendMapTexture; material->bHasAlphaMapTexture = hasAlphaMapTexture; MaterialManager::Instance()->Add(material); return true; }
//=============================================================================================================================== bool ZShadeXMLLoader::LoadMenuXML(string menufilename, GameDirectory2D* gd, EngineOptions* eo, D3D* d3d, MenuSystem*& ms) { XMLParser xmlParser(menufilename); const char* menu_name_str = xmlParser.ReadElement("menu_name"); const char* menu_size_str = xmlParser.ReadElement("menu_size"); const char* menu_type_str = xmlParser.ReadElement("menu_type"); const char* background_name_str = xmlParser.ReadElement("menu_background"); string background_name(background_name_str); BetterString split_b_str(menu_size_str); vector<string> split_str = split_b_str.split('x'); int menu_width = atoi(split_str[0].c_str()); int menu_height = atoi(split_str[1].c_str()); ZShadeSandboxEnvironment::EMenuType::Type menuType; if (strcmp(menu_type_str, "MainMenu") == 0) menuType = ZShadeSandboxEnvironment::EMenuType::eMainMenu; else if (strcmp(menu_type_str, "InGameMenu") == 0) menuType = ZShadeSandboxEnvironment::EMenuType::eInGameMenu; ZShadeSandboxEnvironment::Menu* m = new ZShadeSandboxEnvironment::Menu(d3d); m->MenuName() = string(menu_name_str); m->Width() = menu_width; m->Height() = menu_height; m->GetMenuType() = menuType; if (background_name != "") { ZShadeSandboxGraphics::Image* im = new ZShadeSandboxGraphics::Image(d3d, background_name, gd->m_sprites_path, 0, 0, menu_width, menu_height); m->AddBackground( im ); } ms->AddMenu(m); int st = ZShadeSandboxGraphics::EScriptType::eNone; ArrayElementXMLParser buttonsParser(xmlParser.Element()); buttonsParser.ReadArrayElement("Buttons", "Button"); do { string eName = buttonsParser.ReadArrayElementValue(); string eIDAtt = buttonsParser.ReadArrayElementAttribute("id"); const char* x_str = buttonsParser.ReadArrayChildElement("button_x"); const char* y_str = buttonsParser.ReadArrayChildElement("button_y"); const char* width_str = buttonsParser.ReadArrayChildElement("button_width"); const char* height_str = buttonsParser.ReadArrayChildElement("button_height"); const char* text_str = buttonsParser.ReadArrayChildElement("button_text"); const char* normal_image_str = buttonsParser.ReadArrayChildElement("normal_image"); const char* pushed_image_str = buttonsParser.ReadArrayChildElement("pushed_image"); const char* highlighted_image_str = buttonsParser.ReadArrayChildElement("highlighted_image"); const char* disabled_image_str = buttonsParser.ReadArrayChildElement("disabled_image"); const char* script_type_str = buttonsParser.ReadArrayChildElement("script_type"); const char* tag_str = buttonsParser.ReadArrayChildElement("tag"); if (strcmp(script_type_str, "start") == 0) st = ZShadeSandboxGraphics::EScriptType::eStart; if (strcmp(script_type_str, "resume") == 0) st = ZShadeSandboxGraphics::EScriptType::eResume; if (strcmp(script_type_str, "continue") == 0) st = ZShadeSandboxGraphics::EScriptType::eContinue; if (strcmp(script_type_str, "options") == 0) st = ZShadeSandboxGraphics::EScriptType::eOptions; if (strcmp(script_type_str, "exit") == 0) st = ZShadeSandboxGraphics::EScriptType::eExit; if (strcmp(script_type_str, "none") == 0) st = ZShadeSandboxGraphics::EScriptType::eNone; ZShadeSandboxGraphics::Button* b = new ZShadeSandboxGraphics::Button( d3d, ZShadeSandboxGlobal::Convert::ConvertStringToCharPointer(string(text_str)), false, atof(x_str), atof(y_str), atoi(width_str), atoi(height_str), gd->m_menu_sprites_path, string(normal_image_str), string(pushed_image_str), string(highlighted_image_str), string(disabled_image_str), "white.png", "blue.png", "yellow.png", "black.png" ); b->ScriptType() = st; b->Tag() = string(tag_str); switch (st) { case ZShadeSandboxGraphics::EScriptType::eStart: b->GetScript() = Scripting::GetScript("start"); break; case ZShadeSandboxGraphics::EScriptType::eResume: b->GetScript() = Scripting::GetScript("resume"); break; case ZShadeSandboxGraphics::EScriptType::eContinue: b->GetScript() = Scripting::GetScript("continue"); break; case ZShadeSandboxGraphics::EScriptType::eOptions: b->GetScript() = Scripting::GetScript("options"); break; case ZShadeSandboxGraphics::EScriptType::eExit: b->GetScript() = Scripting::GetScript("exit"); break; } m->AddButton(b); } while (buttonsParser.ArrayElementNotNull("Button")); ArrayElementXMLParser textsParser(xmlParser.Element()); textsParser.ReadArrayElement("Texts", "Text"); do { string eName = textsParser.ReadArrayElementValue(); string eIDAtt = textsParser.ReadArrayElementAttribute("id"); const char* x_str = textsParser.ReadArrayChildElement("text_x"); const char* y_str = textsParser.ReadArrayChildElement("text_y"); const char* text_str = textsParser.ReadArrayChildElement("text"); const char* text_font_str = textsParser.ReadArrayChildElement("text_font"); const char* text_color_str = textsParser.ReadArrayChildElement("text_color"); const char* shadow_str = textsParser.ReadArrayChildElement("shadow"); const char* optional_background_str = textsParser.ReadArrayChildElement("optional_background"); XMFLOAT3 color = ZShadeSandboxGlobal::Convert::ConvertToFloat3(string(text_color_str)); bool shadow = (string(shadow_str) == "1") ? true : false; ZShadeSandboxGraphics::Text* t = new ZShadeSandboxGraphics::Text(); t->SetD3D(d3d); t->Initialize(); t->TextName() = BetterString(text_str); if (shadow) { t->CreateShadow(); } t->ChangeFont(L"Times New Roman", atoi(text_font_str), FontStyle::BoldItalic, true); t->TextTransform() = XMMatrixTranslation(atof(x_str), atof(y_str), 0); t->TextColor() = XMFLOAT4(color.x, color.y, color.z, 1); m->AddText(t); } while (textsParser.ArrayElementNotNull("Text")); return true; }