Esempio n. 1
0
////////////////////
// Label -> Panel //
////////////////////
void UILabel::AllocateComponent(const TRDescription& inDesc)
{
	string theTitle;
    inDesc.GetTagValue(UITagText, theTitle);

    string theDefaultText;
	LocalizeString(theTitle.c_str(), theDefaultText);
	
    this->mUILabel = new Label(theDefaultText.c_str());
}
Esempio n. 2
0
/////////////////////
// Button -> Label //
/////////////////////
void UIButton::AllocateComponent(const TRDescription& inDesc)
{
    float theXPos, theYPos;
    int theWidth, theHeight;
    UIGetPosition(inDesc, theXPos, theYPos, theWidth, theHeight);
	
	string theTitle;
    inDesc.GetTagValue(UITagText, theTitle);

    string theDefaultText;
	LocalizeString(theTitle.c_str(), theDefaultText);
	
    this->mUIButton = new Button(theDefaultText.c_str(), theXPos*ScreenWidth(), theYPos*ScreenHeight(), theWidth, theHeight);
}
Esempio n. 3
0
bool UILabel::SetClassProperties(const TRDescription& inDesc, Panel* inPanel, CSchemeManager* inSchemeManager)
{
    bool theSuccess = true;
	
    Label* theLabel = (Label*)inPanel;
	
    theSuccess = UIPanel::SetClassProperties(inDesc, inPanel, inSchemeManager);
    
    if(theSuccess)
    {
        string theAlignmentString;
        if(inDesc.GetTagValue(UITagAlignment, theAlignmentString))
        {
            // Convert the alignment from a string to the label enum
            Label::Alignment theAlignment = vgui::Label::a_center;
            UIStringToAlignment(theAlignmentString, theAlignment);
            theLabel->setContentAlignment(theAlignment);
        }
		
        string theTitle;
        if(inDesc.GetTagValue(UITagText, theTitle))
        {
			string theDefaultText("");
			LocalizeString(theTitle.c_str(), theDefaultText);
			
			theLabel->setText((int)theDefaultText.length(), theDefaultText.c_str());
        }
		
		// Get font to use
		std::string theSchemeName;
		if(inDesc.GetTagValue(UITagScheme, theSchemeName))
		{
			const char* theSchemeCString = theSchemeName.c_str();
			SchemeHandle_t theSchemeHandle = inSchemeManager->getSchemeHandle(theSchemeCString);
			Font* theFont = inSchemeManager->getFont(theSchemeHandle);
			if(theFont)
			{
				theLabel->setFont(theFont);
			}
				
			theSuccess = true;
		}
    }
	
    return theSuccess;
}
Esempio n. 4
0
bool ActionButton::GetLabelForMessage(AvHMessageID inMessage, string& outLabel)
{
	bool theSuccess = false;

	// Localize prereq, without IT's prereq
	string theKey = string(kTechNodeLabelPrefix) + MakeStringFromInt((int)inMessage);
	if(LocalizeString(theKey.c_str(), outLabel))
	{
		// Remove it's accelerator if it has one
		//std::remove(outLabel.begin(), outLabel.end(), kAcceleratorCharacter);
		theSuccess = true;
	}
	else
	{
		int a = 0;
	}
	return theSuccess;
}
Esempio n. 5
0
	string Language::LocalizeStringTokens(string str) {
		string newStr;
		ssize_t lastPos = -1;
		size_t pos = str.find_first_of('[');
		while (pos != string::npos) {
			newStr += str.substr(lastPos + 1, (pos - (lastPos + 1)));

			lastPos = str.find_first_of(']', pos);
			if (lastPos == string::npos) {
				newStr = "Error";
				break;
			} else {
				string token = str.substr(pos + 1, (lastPos - pos - 1));
				newStr += LocalizeString(token);
			}

			pos = str.find_first_of('[', lastPos);
		}
		if (lastPos < static_cast<ssize_t>(str.length()))
			newStr += str.substr(lastPos + 1);
		return newStr;
	}
Esempio n. 6
0
//////////////////////////
// StaticLabel -> Label //
//////////////////////////
void UIStaticLabel::AllocateComponent(const TRDescription& inDesc)
{
	string theTitle;
    inDesc.GetTagValue(UITagText, theTitle);

	string theDefaultText("");
	LocalizeString(theTitle.c_str(), theDefaultText);
	
    // Position (normalized screen coords)
    float theXPos = UIDefaultXPos;
    float theYPos = UIDefaultYPos;
    inDesc.GetTagValue(UITagXPos, theXPos);
    inDesc.GetTagValue(UITagYPos, theYPos);
	
    // Width and height (normalized screen coords)
    float theWidth = UIDefaultWidth;
    float theHeight = UIDefaultHeight;
    inDesc.GetTagValue(UITagWidth, theWidth);
    inDesc.GetTagValue(UITagHeight, theHeight);
	
    this->mUIStaticLabel = new StaticLabel(theDefaultText.c_str(), theXPos*ScreenWidth(), theYPos*ScreenHeight(), theWidth*ScreenWidth(), theHeight*ScreenHeight());
}
Esempio n. 7
0
// Look at currently selected units and set our help text.  This is only used for research currently
void AvHCommanderModeHandler::RecalculateBuildResearchText()
{
    this->mBuildResearchText = "";

    if(this->mSelected.size() == 1)
    {
        // Get entity
        int theEntityIndex = *this->mSelected.begin();
        cl_entity_s* theEntity = gEngfuncs.GetEntityByIndex(theEntityIndex);
        if(theEntity)
        {
            bool theIsBuilding, theIsResearching;
            float thePercentage;
            string theHelpPrefix;

            AvHSHUGetBuildResearchState(theEntity->curstate.iuser3, theEntity->curstate.iuser4, theEntity->curstate.fuser1, theIsBuilding, theIsResearching, thePercentage);

            // Special-case for energy
            if(theIsBuilding && theIsResearching && (thePercentage > 0.0f))
            {
                LocalizeString(kEnergyPrefix, theHelpPrefix);

                // Read energy
                int theEnergy = thePercentage*kMarineStructureMaxEnergy;
                this->mBuildResearchText = theHelpPrefix + string(" ") + MakeStringFromInt(theEnergy);
            }
            // Check if it's recycling
            else if(!theIsBuilding && theIsResearching && GetHasUpgrade(theEntity->curstate.iuser4, MASK_RECYCLING))
            {
                LocalizeString("Recycling", this->mBuildResearchText);
            }
            // Check to see if it's being built
            else if((theIsBuilding || theIsResearching) && (thePercentage < 1.0f))
            {
                if(theIsBuilding)
                {
                    // Set help text to "Building: <tech name>"
                    LocalizeString(kBuildingPrefix, theHelpPrefix);
                }
                else if(theIsResearching)
                {
                    // Set help text to "Researching: <tech name>"
                    LocalizeString(kResearchingPrefix, theHelpPrefix);
                }

                string theHelpText;
                AvHMessageID theResearchID = (AvHMessageID)(theEntity->curstate.iuser2);
                if(theResearchID != MESSAGE_NULL)
                {
                    if(ActionButton::GetLabelForMessage(theResearchID, theHelpText))
                    {
                        string theFinalMessage = theHelpPrefix + theHelpText;
                        this->mBuildResearchText = theFinalMessage;
                    }
                }
            }
            else
            {
                if(GetHasUpgrade(theEntity->curstate.iuser4, MASK_BUILDABLE))
                {
                    // Look up name for entity and show it
                    AvHMessageID theResearchID = (AvHMessageID)(theEntity->curstate.iuser2);
                    if(theResearchID != MESSAGE_NULL)
                    {
                        ActionButton::GetLabelForMessage(theResearchID, this->mBuildResearchText);
                    }
                }
                // If we have a resource selected, set the resource level
                else if(theEntity->curstate.iuser3 == AVH_USER3_FUNC_RESOURCE)
                {
                    int theResources = (int)(theEntity->curstate.fuser1/kNormalizationNetworkFactor);
                    if(theResources > 0)
                    {
                        if(LocalizeString(kResourcesTitle, this->mBuildResearchText))
                        {
                            char theResourceMessage[64];
                            sprintf(theResourceMessage, "%d", theResources);
                            this->mBuildResearchText += string(theResourceMessage);
                        }
                    }
                    else
                    {
                        LocalizeString(kResourcesDepletedTitle, this->mBuildResearchText);
                    }
                }
                else if(theEntity->curstate.iuser3 == AVH_USER3_INFANTRYPORTAL)
                {
//					int the = (int)(theEntity->curstate.fuser1/kNormalizationNetworkFactor);
//					if(theResources > 0)
//					{
                    if(LocalizeString(kReinforcementsTitle, this->mBuildResearchText))
                    {
                        // TODO: Read this number correctly
                        //char theMessage[64];
                        //sprintf(theMessage, "%d", 100);
                        //this->mBuildResearchText += string(theMessage);
                    }
//					}
//					else
//					{
//						LocalizeString(kResourcesDepletedTitle, this->mBuildResearchText);
//					}
                }
            }
        }
    }
}
Esempio n. 8
0
// Run through the tech nodes and look up their label and help text, storing them for drawing
void ActionButton::Localize(const AvHTechNodes& inTechNodes)
{
	if(this->mMessageID == MESSAGE_NULL)
	{
		this->setText("");
		this->mHelpText = "";
		this->mCost = 0;
	}
	else
	{
		char theNumber[8];
		sprintf(theNumber, "%d", (int)this->mMessageID);
		string theNumberString(theNumber);

		// If localize string fails, set the label to "<no desc>"
		string theText;
		string theKey = string(kTechNodeLabelPrefix) + theNumberString;
		LocalizeString(theKey.c_str(), theText);
		
		// Localize help string
		this->mHelpText = "";

		if(gHUD.GetHelpForMessage(this->mMessageID, this->mHelpText))
		{
			// Add hotkey accelerator
			if(this->mButtonIndex >= 0)
			{
				char theHotkeyChar = ' ';
				int theCol = this->mButtonIndex % kNumActionButtonCols;
				int theRow = this->mButtonIndex / kNumActionButtonCols;
				if(AvHActionButtons::ButtonIndexToHotKey(theCol, theRow, theHotkeyChar))
				{
					// Display as caps, looks nicer
					theHotkeyChar = toupper(theHotkeyChar);
					string theHotkeyText = string("(") + theHotkeyChar + string(")");
					this->mHelpText += string(" ");
					this->mHelpText += theHotkeyText;
				}
			}

			// new line after hotkey
			this->mHelpText += " \n";

			bool theFirstPrereq = true;

			// If there is a prerequisite that isn't researched, add this to help message
			AvHTechID thePrereqID1;
			AvHTechID thePrereqID2;
			if(inTechNodes.GetPrequisiteForMessage(this->mMessageID, thePrereqID1, thePrereqID2))
			{
				for(int i = 0; i < 2; i++)
				{
					AvHTechID theCurrentPrereq = ((i == 0) ? thePrereqID1 : thePrereqID2);
					if(theCurrentPrereq != TECH_NULL)
					{
						if(!inTechNodes.GetIsTechResearched(theCurrentPrereq))
						{
							//this->mTechEnabled = false;
						
							// Localize "prerequisite:"
							string thePrequisiteText;
							if(LocalizeString(kPrerequisitePrefix, thePrequisiteText))
							{
								// Get message from this tech
								AvHMessageID theMessageWithThisTech = MESSAGE_NULL;
								if(inTechNodes.GetMessageForTech(theCurrentPrereq, theMessageWithThisTech))
								{
									string thePrereqTech;
									if(GetLabelForMessage(theMessageWithThisTech, thePrereqTech))
									{
										// Add extra blank line before first prereq
										if(theFirstPrereq)
										{
											this->mHelpText += " \n";
											this->mHelpText += kTooltipBoldPreString;
											this->mHelpText += thePrequisiteText;
											this->mHelpText += "\n";
											theFirstPrereq = false;
										}

										// Prereqs draw as bold
										this->mHelpText += kTooltipBoldPreString;
										this->mHelpText += " - ";
										this->mHelpText += thePrereqTech;
										this->mHelpText += "\n";
									}
								}
								else
								{
									int a = 0;
								}
							}
						}
					}
				}
			}

			// Blank line between hotkey/prereq and description
			this->mHelpText += " \n";

			// Add description
			AvHUser3 theUser3 = AVH_USER3_NONE;
			if(AvHSHUMessageIDToUser3(this->mMessageID, theUser3))
			{
				string theDescription;
				if(gHUD.GetTranslatedUser3Description(theUser3, true, theDescription))
				{
					this->mHelpText += theDescription;

					this->mHelpText += " \n";
				}
			}
		}
	}	
}