Пример #1
0
UISystem::UISystem() 
{
	//Read all styles and widgets 

	s_rootWidget = new GroupWidget();

	std::vector<std::string> out_styles;
	FindAllFilesOfType("Data/Styles/", "*", out_styles);

	for (auto it = out_styles.begin(); it != out_styles.end(); ++it) {
		std::string filePath = *it;
		ReadStyleFile(filePath);
	}

	std::vector<std::string> out_widgets;
	FindAllFilesOfType("Data/Widgets/", "*", out_widgets);

	for (auto it = out_widgets.begin(); it != out_widgets.end(); ++it) {
		std::string filePath = *it;
		ReadWidgetFile(filePath);
	}

	WidgetStyle wid;
	NamedProperties defaultProps;
	NamedProperties allProps;

	KeyFrameAnimation<RGBA> animColor;
	animColor.AddAnimationFrameAtParameter(RGBA(50, 255, 50, 255), 0.f);
	//defaultProps.Set("color", animColor);

	KeyFrameAnimation<Vec2> offsetAnim;
	offsetAnim.AddAnimationFrameAtParameter(Vec2(100.f, 500.f), 0.f);
	allProps.Set("offset", offsetAnim);

	KeyFrameAnimation<RGBA> animColor2;
	animColor2.AddAnimationFrameAtParameter(RGBA(255, 0, 0, 255), 0.f);
	allProps.Set("color", animColor2);

	wid.AddProperty(UI_STATE_DEFAULT, defaultProps);
	wid.AddGeneralProperty(allProps);
	WidgetBase* widget = AddStyledWidgetExplicitly("Button", "Default", wid, s_rootWidget);

	std::string name;
	widget->GetPropertyForCurrentState("name", name);

	//ToggleWidgetVisibility(name);
	ToggleWidgetEnabled(name);


}
Пример #2
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool EnumerateFiles( const std::string& directory, const std::string& searchPattern, Strings& out_filesFound, bool recurseSubFolders )
{
    if (recurseSubFolders)
        return FindAllFilesOfTypeRecursive( directory, searchPattern, out_filesFound );
    else
        return FindAllFilesOfType( directory, searchPattern, out_filesFound );
}
Пример #3
0
///=====================================================
/// 
///=====================================================
void Game::UpdateQuestState(OpenGLRenderer* renderer){
	const MapGeneratorRegistry* registry = MapGeneratorRegistration::GetGeneratorRegistry();
	char questLetter = 'A';

	for (MapGeneratorRegistry::const_iterator registryIter = registry->cbegin(); registryIter != registry->cend(); ++registryIter){
		if (s_theInputSystem->GetKeyWentDown(questLetter)){
			m_mapGenerator = (registryIter->second)->CreateMapGenerator(registryIter->first);
			if (m_mapGenerator != nullptr){
				m_map = m_mapGenerator->CreateMap(renderer);
				if (m_map != nullptr){ //go to Generating
					SetState(Generating);

					m_titleRenderer.ClearText();
					m_titleRenderer.PrintText("Generating Map");
					break;
				}
				else{
					delete m_mapGenerator;
					m_mapGenerator = nullptr;
				}
			}
		}
		++questLetter;
	}
	if (s_theInputSystem->GetKeyWentDown(VK_TAB)){
		m_autoGenerateMap = !m_autoGenerateMap;
		m_bottomMessageRenderer.ClearText();

		if (m_autoGenerateMap){
			m_bottomMessageRenderer.PrintText("AutoGenerate: ON", RGBAchars::GREEN);
		}
		else{
			m_bottomMessageRenderer.PrintText("AutoGenerate: OFF", RGBAchars::RED);
		}
	}
	else if (s_theInputSystem->GetKeyWentDown(VK_ESCAPE)){ //go back to Main Menu
		SetState(MainMenu);

		m_titleRenderer.ClearText();
		m_titleRenderer.PrintText("Dagger", RGBAchars::RED);

		std::vector<std::string> unused;
		bool hasSavedGame = FindAllFilesOfType("Data/Saves/", "saveGame.xml", unused);

		m_menuRenderer.ToggleRenderFromCenter();
		m_menuRenderer.ClearText();
		m_menuRenderer.PrintText("N) New Game");
		if (hasSavedGame)
			m_menuRenderer.PrintText("L) Load Game");
		m_menuRenderer.PrintText("Q) Quit");

		m_bottomMessageRenderer.ClearText();
	}
}
Пример #4
0
///=====================================================
/// 
///=====================================================
bool NPCFactory::LoadAllNPCFactories(OpenGLRenderer* renderer){
	std::vector<std::string> factories;
	bool foundFiles = FindAllFilesOfType("Data/NPCs/", "*.npc.xml", factories);
	RECOVERABLE_ASSERT(foundFiles == true);

	for (std::vector<std::string>::const_iterator factoryIter = factories.cbegin(); factoryIter != factories.cend(); ++factoryIter){
		XMLNode npcNode = XMLNode::parseFile(factoryIter->c_str(), "NPC");

		NPCFactory* newFactory = new NPCFactory(npcNode, renderer);

		s_factories.emplace(GetStringID(newFactory->m_npcBlueprint->m_name), newFactory);
	}

	return foundFiles;
}
Пример #5
0
///=====================================================
/// 
///=====================================================
void Game::UpdateGameOverState(){
	if (s_theInputSystem->GetKeyWentDown(VK_ESCAPE)){ //go back to Main Menu
		SetState(MainMenu);
		m_titleRenderer.ClearText();
		m_titleRenderer.PrintText("Dagger", RGBAchars::RED);

		std::vector<std::string> unused;
		bool hasSavedGame = FindAllFilesOfType("Data/Saves/", "saveGame.xml", unused);

		m_menuRenderer.ClearText();
		m_menuRenderer.PrintText("N) New Game");
		if (hasSavedGame)
			m_menuRenderer.PrintText("L) Load Game");
		m_menuRenderer.PrintText("Q) Quit");

		m_bottomMessageRenderer.ClearText();

		s_theMessageBar->m_messages.clear();
	}
}
Пример #6
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool FindAllFilesOfTypeRecursive( const std::string& directory, const std::string& searchPattern, Strings& out_filesFound )
{
#ifdef WIN32

    _finddata_t fd;

    std::string searchPath = directory + "*";
    intptr_t searchHandle = _findfirst( searchPath.c_str(), &fd );

    if (searchHandle != -1)
    {
        do
        {
            if (fd.attrib & _A_SUBDIR && strcmp( fd.name, ".." ) != 0 /*&& strcmp( fd.name, "." )*/ )
            {
                if (strcmp( fd.name, "." ) == 0 )
                {
                    FindAllFilesOfType( directory, searchPattern, out_filesFound );
                }
                else
                {
                    FindAllFilesOfTypeRecursive( directory + fd.name + "/", searchPattern, out_filesFound );
//                     ConsolePrintf( "Recursive: %s\n", fd.name );
                }
            }
        } while (_findnext( searchHandle, &fd ) == 0);

    }
    else return false;

    if (_findclose( searchHandle ) == 0 && out_filesFound.size() != 0)
        return true;
    return false;
#else
    return false;
#endif

}
Пример #7
0
///=====================================================
/// 
///=====================================================
void Game::Startup(OpenGLRenderer* renderer){
	srand((unsigned int)time(NULL));
	Faction::LoadFactions();

	bool loadedNPCs = NPCFactory::LoadAllNPCFactories(renderer);
	if (!loadedNPCs)
		return;

	bool loadedItems = ItemFactory::LoadAllItemFactories(renderer);
	if (!loadedItems)
		return;

	bool loadedFeatures = FeatureFactory::LoadAllFeatureFactories(renderer);
	if (!loadedFeatures)
		return;

	std::vector<std::string> unused;
	bool hasSavedGame = FindAllFilesOfType("Data/Saves/", "saveGame.xml", unused);

	m_titleRenderer.Startup(renderer);
	m_titleRenderer.ToggleCursor();
	m_titleRenderer.ToggleRenderFromCenter();

	m_titleRenderer.PrintText("Dagger", RGBAchars::RED);


	m_menuRenderer.Startup(renderer);
	m_menuRenderer.ToggleCursor();
	m_menuRenderer.ToggleRenderFromCenter();
	
	m_menuRenderer.PrintText("N) New Game");
	if (hasSavedGame)
		m_menuRenderer.PrintText("L) Load Game");
	m_menuRenderer.PrintText("Q) Quit");

	m_bottomMessageRenderer.Startup(renderer);
	m_bottomMessageRenderer.ToggleCursor();
	m_bottomMessageRenderer.ToggleRenderFromCenter();

	m_statusBar.Startup(renderer);
	m_messageBar.Startup(renderer);

	//Create HUD decoration
	bool wasCreated = m_HUDMaterial.CreateProgram(renderer, "Data/Shaders/basic2DNoTexture.vert", "Data/Shaders/basic2DNoTexture.frag");
	if (wasCreated == false){
		m_isRunning = false;
		return;
	}

	Vertex2D_PCT boxVerts[4] = {
		Vertex2D_PCT(Vec2(100.0f, 100.0f), Vec2(0.0f, 1.0f)),
		Vertex2D_PCT(Vec2(1500.0f, 100.0f), Vec2(1.0f, 1.0f)),
		Vertex2D_PCT(Vec2(100.0f, 800.0f), Vec2(0.0f, 0.0f)),
		Vertex2D_PCT(Vec2(1500.0f, 800.0f), Vec2(1.0f, 0.0f))
	};

	int boxIndeces[8] = {
		0, 1, 1, 3, 3, 2, 2, 0
	};

	renderer->GenerateBuffer((GLuint*)&m_HUDBufferID);
	renderer->SendVertexDataToBuffer(&boxVerts, sizeof(Vertex2D_PCT) * 4, m_HUDBufferID);

	renderer->GenerateBuffer((GLuint*)&m_HUDIndexBufferID);
	renderer->SendVertexDataToBuffer(&boxIndeces, sizeof(int) * 8, m_HUDIndexBufferID);

	m_HUDVaoID = renderer->CreateVAOBasic();

	m_HUDMaterial.BindVertexData(m_HUDBufferID, Vertex2D_PCT());
	m_HUDMaterial.CreateSampler(renderer, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
	m_HUDMaterial.SetBaseShape(GL_LINES);

	UniformMatrix* projection = (UniformMatrix*)m_HUDMaterial.CreateUniform("projection");
	FATAL_ASSERT(projection != nullptr);
	projection->m_data.push_back(renderer->CreateOrthographicMatrix());
}