Ejemplo n.º 1
0
bool TRFactory::WriteDescriptions(const string& inRelativePathFilename, const TRDescriptionList& inDescriptionList, const string& inHeader)
{
    bool theSuccess = false;

    // Open the file for output
    fstream theOutfile;
    theOutfile.open(inRelativePathFilename.c_str(), ios::out);

    if(theOutfile.is_open())
    {
        // Optional: write header
        theOutfile << inHeader << std::endl;

        //theOutfile << "; Generated by Half-life.  Do not edit unless you know what you are doing! " << std::endl;
        //theOutfile << std::endl;

        // For each description
        TRDescriptionList::const_iterator theIter;
        for(theIter = inDescriptionList.begin(); theIter != inDescriptionList.end(); theIter++)
        {
            // Write out that description
            const TRDescription& theDesc = *theIter;
            TRFactory::WriteDescription(theOutfile, theDesc);

            // Write out a blank line to make them look nice and separated
            theOutfile << std::endl;
        }

        theOutfile.close();
        theSuccess = true;
    }

    return theSuccess;
}
Ejemplo n.º 2
0
bool UIManager::Save(const string& outFilename, const string& outHeader)
{
    // Build description list
    TRDescriptionList theDescriptionList;

    UIComponentListType::iterator theCompIter;
    for(theCompIter = this->mComponentList.begin(); theCompIter != this->mComponentList.end(); theCompIter++)
    {
        theDescriptionList.push_back((*theCompIter)->GetDescription());
    }

    // Write it out!
    TRFactory::WriteDescriptions(outFilename, theDescriptionList, outHeader);

	return true;
}
Ejemplo n.º 3
0
bool TRFactory::ReadDescriptions(const string& inRelativePathFilename, TRDescriptionList& outDescriptionList)
{
    bool theSuccess = false;
    bool theDescriptionRead = false;

    // Open file specified by relative path name
    fstream infile;
    infile.open(inRelativePathFilename.c_str(), ios::in);

    if(infile.is_open())
    {
        do
        {
            // Try to read the next description in
            TRDescription theNextDescription;
            theDescriptionRead = ReadDescription(infile, theNextDescription);

            // add it to the description list
            if(theDescriptionRead)
            {
                // Function is successful if at least one description was found
                outDescriptionList.push_back(theNextDescription);
                theSuccess = true;
            }

        } while(theDescriptionRead);

        infile.close();
    }
    return theSuccess;
}
Ejemplo n.º 4
0
bool UIManager::Initialize(const TRDescriptionList& inDesc, CSchemeManager* inSchemeManager)
{
	bool theSuccess = false;

	// Clear out everything in case we have already been used once
	this->Clear();

	// Now loop through entities found 
	for(TRDescriptionList::const_iterator theListIter = inDesc.begin(); theListIter != inDesc.end(); theListIter++)
	{
		// See if the factory knows how to create such a thing. It is giving the memory to us forever so take care of it.
		UIComponent* theCurrentComponent = this->mFactory->BuildComponent(*theListIter, inSchemeManager);

		// Tell it to set all the tags it knows about
		if(theCurrentComponent)
		{
			// Check for named root tag, look up that component and set it
            Panel* theRoot = NULL;
            string theRootName;
            
            if(theListIter->GetTagValue("root", theRootName))
            {
                UIComponent* theUIComponent = NULL;
                theUIComponent = this->GetComponentNamed(theRootName);
                if(theUIComponent)
                {
                    theRoot = theUIComponent->GetComponentPointer();
                }
            }

            // If none specified or it couldn't be found, use default
            if(!theRoot)
            {
                theRoot = (Panel*)VGui_GetPanel();
            }

            // Set the root
   			theCurrentComponent->GetComponentPointer()->setParent(theRoot);

            // Add to menu if specified
            string theMenuName;
            if(theListIter->GetTagValue(UITagMenuAddItem, theMenuName))
            {
                Menu* theParentMenu = NULL;
                if(this->GetVGUIComponentNamed(theMenuName, theParentMenu))
                {
                    theParentMenu->addMenuItem(theCurrentComponent->GetComponentPointer());
                }
            }
            
            // Set up scheme if specified
            if(inSchemeManager)
            {
                this->SetSchemeValues(*theListIter, theCurrentComponent, inSchemeManager);
            }

            // <sigh> If we are currently using the regular VGUI instead of the manager, translate
			// this component out of the way so it doesn't suck up input
			if(this->mUsingVGUI)
			{
				this->TranslateComponent(theCurrentComponent->GetComponentPointer(), true);
			}
			
			// If gamma aware, tell it immediately
			GammaAwareComponent* theGammaAwareComponent = dynamic_cast<GammaAwareComponent*>(theCurrentComponent->GetComponentPointer());
			if(theGammaAwareComponent)
			{
				theGammaAwareComponent->NotifyGammaChange(this->mGammaSlope);
			}

            // Save it. It is now part of the world.
			this->mComponentList.push_back(theCurrentComponent);
			
			// Return success if we found at least one component
			theSuccess = true;
		}
	}
	
	// Build default blank cursor
	this->mBlankCursor = new Cursor(vgui_LoadTGA("blank"), 0, 0);
	
    // Register for notification for all input events
    //this->AddInputSignal(this);
	
	return theSuccess;
}