예제 #1
0
Game::GameLocation* ResourceManager::gameLocation(unsigned int number)
{
    if (_gameLocations.find(number) != _gameLocations.end())
    {
        return _gameLocations.at(number);
    }

    std::istream stream(datFileItem("data/maps.txt"));
    Ini::Parser iniParser(stream);
    auto ini = iniParser.parse();

    std::stringstream ss;
    ss << "map " << std::setw(3) << std::setfill('0') << number;

    auto section = ini->section(ss.str());
    if (!section) return 0;

    Game::GameLocation* location = new Game::GameLocation();

    for (auto property : *section.get())
    {
        std::string name = property.first;
        Logger::critical() << name << std::endl;
        if (name == "lookup_name")
        {
            location->setName(property.second.value());
        }
        else if (name == "map_name")
        {
            location->setFilename("maps/" + property.second.value()+ ".map");
        }
        else if (name == "music")
        {
            location->setMusic(property.second.value());
        }
        else if (name == "pipboy_active")
        {
            location->setPipboy(property.second.boolValue());
        }
        else if (name == "saved")
        {
            location->setSaveable(property.second.boolValue());
        }
    }

    _gameLocations.insert(std::make_pair(number, location));

    return _gameLocations.at(number);
}
//================================================================================================================
LRESULT ToolWindow2DEditorTab::Command(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if (!IsEnabled()) return true;

	//m_EditModeSubPicker.UpdateCommand(wParam, lParam);

	bool gd_created = false;

	switch (LOWORD(wParam))
	{
		case EEditorTypeID::eEditorTabCreateGameDirectory:
		{
			if (m_GameNameTextbox.GetText() == "")
			{
				ZShadeMessageCenter::MsgBoxOK(hwnd, "Must have a game name !!!", "Create Game Directory");
			}
			else
			{
				//Full path of game directory
				string username = CGlobal::GrabUserName();
				BetterString gameFolder = "C:\\Users\\";
				gameFolder += username;
				gameFolder += "\\AppData\\Roaming\\";
				gameFolder += m_GameNameTextbox.GetText();

				m_gameDirectory = CGlobal::CreateGD2D(gameFolder, m_EngineOptions->m_GameType2D);

				// Everything will be loaded below if this flag is true
				gd_created = true;
			}
		}
		break;
		case EEditorTypeID::eEditorTabOpenGameDirectory:
		{
			BROWSEINFO bi = { 0 };

			bi.lpszTitle = "Browse for Folder";
			bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;

			LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

			bool pathFound = false;

			if (pidl != NULL)
			{
				//TCHAR tszPath[MAX_PATH] = _T("\0");
				TCHAR tszPath[MAX_PATH];

				memset(tszPath, 0, MAX_PATH);

				if (SHGetPathFromIDList(pidl, tszPath) == TRUE)
				{
					m_GameNameTextbox.SetText(tszPath);

					pathFound = true;
				}

				// — Free pidl
				CoTaskMemFree(pidl);
			}

			if (pathFound)
			{
				m_gameDirectory = CGlobal::CreateGD2D(m_GameNameTextbox.GetText(), m_EngineOptions->m_GameType2D);

				// Everything will be loaded below if this flag is true
				gd_created = true;
			}
		}
		break;
		case EEditorTypeID::eEditorTabEditModeTile:
		{
			bTileMode = true;
			bSpriteMode = false;
			bMusicMode = false;
			bHardnessMode = false;
			
			UpdateEditSubModeTypeVisible();
			UpdateEditSubModeTypeEnable();
		}
		break;
		case EEditorTypeID::eEditorTabEditModeSprite:
		{
			bTileMode = false;
			bSpriteMode = true;
			bMusicMode = false;
			bHardnessMode = false;
			
			UpdateEditSubModeTypeVisible();
			UpdateEditSubModeTypeEnable();
		}
		break;
		case EEditorTypeID::eEditorTabEditModeMusic:
		{
			bTileMode = false;
			bSpriteMode = false;
			bMusicMode = true;
			bHardnessMode = false;
			
			UpdateEditSubModeTypeVisible();
			UpdateEditSubModeTypeEnable();
			DisableEditSubModeType();
		}
		break;
		case EEditorTypeID::eEditorTabEditModeHardness:
		{
			bTileMode = false;
			bSpriteMode = false;
			bMusicMode = false;
			bHardnessMode = true;
			
			UpdateEditSubModeTypeVisible();
			UpdateEditSubModeTypeEnable();
		}
		break;
		case EEditorTypeID::eEditorTabPlay:
		{
			// Get a new handle to the rendering m_Window for the new game environment
			HWND oldWindow = m_EngineOptions->hwnd;
			string oldWindowName = EnvironmentFactory::Instance()->ActiveEnvironmentName();
			m_EngineOptions->m_inEditor = false;

			//m_EngineOptions->hwnd = iRenderWin->GetHwnd();


			ZShadeINIParser iniParser("ZShadeSandbox.ini", true);
			string env3DType = iniParser.GetString("Editor", "Env3D");
			string game_folder = iniParser.GetString("Editor", "GameFolder");

			// Have the option of playing the current map or the current game
			const int result = ZShadeMessageCenter::MsgBoxYesNo(NULL, "Would you like to play the current map?", "Play Game");

			switch (result)
			{
				case IDYES:// Play current map
				{
					//// Launch the current map for testing
					//EnvironmentFactory::Instance()->CreateEnvironment("MapTestEnv", m_EngineOptions, "BaseGameWindow", "RenderGameWindow", true);

					//EnvironmentFactory::Instance()->ActiveEnvironmentName() = "MapTestEnv";

					//string mn = m_worldTab->ActiveMapName();
					//string wn = m_worldTab->ActiveWorldName();

					//// Load the world and set the map for testing
					////Environment2DMapHelper::LoadWorld(m_ActiveWorldName, false, 0);
					//Environment2DMapHelper::SetActiveRenderedMap(wn, mn);

					//EnvironmentFactory::Instance()->SelectEnvironment("MapTestEnv")->Run();

					//// Get the handle to the original m_Window back
					//// when the game environment returns from the run loop command
					//m_EngineOptions->hwnd = oldWindow;
					//EnvironmentFactory::Instance()->ActiveEnvironmentName() = oldWindowName;
					//m_EngineOptions->m_inEditor = true;
				}
				break;
				case IDNO:// Start the entire game
				{
					// Launch a new game environment
					EnvironmentFactory::Instance()->CreateEnvironment("PlayTestEnv", m_EngineOptions, "BaseGameWindow", "RenderGameWindow", true);

					EnvironmentFactory::Instance()->ActiveEnvironmentName() = "PlayTestEnv";

					EnvironmentFactory::Instance()->SelectEnvironment("PlayTestEnv")->Run();

					// Get the handle to the original m_Window back
					// when the game environment returns from the run loop command
					m_EngineOptions->hwnd = oldWindow;
					EnvironmentFactory::Instance()->ActiveEnvironmentName() = oldWindowName;
					m_EngineOptions->m_inEditor = true;
				}
				break;
			}
		}
		break;
		case EEditorTypeID::eEditorTabMenuButton:
		{
			// Hide the map tool window and go to the menu tool window
			bHideWindow = true;
			
			bEditorTypeMenu = true;
			bEditorTypeHUD = false;
			bEditorTypeMap = false;
		}
		break;
		case EEditorTypeID::eEditorTabHUDButton:
		{
			// Hide the map tool window and go to the hud tool window
			bHideWindow = true;
			
			bEditorTypeHUD = true;
			bEditorTypeMenu = false;
			bEditorTypeMap = false;
		}
		break;
	}

	if (gd_created)
	{
		m_EngineOptions->m_GD2D = m_gameDirectory;

		m_mapEditorSystem2D->SetGameDirectory(m_gameDirectory);

		m_GameDirectoryCreated = true;

		m_EngineOptions->m_inEditor = true;

		UpdateEditSubModeTypeVisible();
		UpdateEditSubModeTypeEnable();

		// Load the stamp tools and display sprites
		m_mapEditorSystem2D->LoadRequiredSprites();

		EnableTabItems();

		// Read the Game.ini file
		ZShadeINIParser iniParser(m_gameDirectory->m_game_ini_path, false);
		string gameType = iniParser.GetString("GAME", "GameType");

		SetGameTypeRC(gameType);

		// Update the ini file with the game folder
		ZShadeINIParser iniSandboxParser("ZShadeSandbox.ini", true);
		iniSandboxParser.WriteString("Editor", "GameFolder", m_GameNameTextbox.GetText());

		//AudioSystem::NewInstance(m_gameDirectory, m_Window->GetHwnd());
		//Scripting::NewInstance(m_mapEditorSystem2D->D3DSystem(), m_gameDirectory);
	}
	
	return true;
}