*title* text for promotions?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
This seems simple, but I can't figure it out. I want to dynamically change the name of a promotion during the game. I have added:
Code:
void CvPromotionInfo::setText(const TCHAR* szText)				
{
	m_szTextKey = szText; 
}
And I can see this is working as demonstrated by:
Code:
	pPromo = self.gc.getPromotionInfo(iPromo)
	sName = pPromo.getText()
But, the hover help for the promo in the lower left corner of the screen does not update as shown here:
attachment.php

The blue text "Promote Unit (Combat I)" is using the original name from the xml, not the new name I have set. This is not what I want. I have tried to find how this text is set, but I cannot find it. The text "Promote Unit" is the xml tag TXT_KEY_COMMAND_PROMOTION, and there is a related COMMAND_PROMOTION. This is used in CvDLLWidgetData.cpp, which looks promising:
Code:
			if (GC.getActionInfo(widgetDataStruct.m_iData1).getCommandType() == COMMAND_PROMOTION)
			{
				GAMETEXT.parsePromotionHelp(szBuffer, ((PromotionTypes)(GC.getActionInfo(widgetDataStruct.m_iData1).getCommandData())));
			}
But, that builds the white text, and not the blue text. If I can find how the blue text is built, I am sure I can see what additional code I should add. I cannot find any other useful looking references to COMMAND_PROMOTION in CvGameCoreDLL/* or python/*/*.

Where is this blue text built?
 

Attachments

  • hover-help.gif
    hover-help.gif
    22 KB · Views: 220
I didn't spend the time to test it but could CvGameTextMgr::setPromotionHelp be what you are looking for?
 
Thanks for the suggestion. That also seems to return what I've called the white text, rather than the blue text. I looked a little further into the code, and there is some kind of caching going on:
Code:
const wchar* CvInfoBase::getDescription(uint uiForm) const
{
	while(m_aCachedDescriptions.size() <= uiForm)
	{
		m_aCachedDescriptions.push_back(gDLL->getObjectText(m_szTextKey, m_aCachedDescriptions.size()));
	}
	
	return m_aCachedDescriptions[uiForm];
}
I don't understand that since I don't know how uiForm is used. But anyway, there is a function which I thought would help:
Code:
void CvInfoBase::reset()
{
	//clear cache
	m_aCachedDescriptions.clear();
	m_szCachedText.clear();
	m_szCachedHelp.clear();
	m_szCachedStrategy.clear();
	m_szCachedCivilopedia.clear();
}
So, I added a call of reset() to the end of my setText function posted above.

However that did not make any difference. The blue text in the screenshot is still not updated according to m_szTextKey.

Can anybody suggest a place to look?
 
How did you write your reset precisely? You might be calling it on the wrong target.

pPromo.reset() should be the proper form, for the test python you had printed before.

Alternatively, you could re-write the function which uses the cache to instead fetch the description fresh each time (just initialize a new variable of the same type as the cache variable and use it instead. Since the starting size is certainly shorter than uiForm, it'll always load the current value, then return it. Minor performance hit that way, but it'd work)
 
Here is precisely what I wrote:
Code:
void CvPromotionInfo::setText(const TCHAR* szText)				
{
	m_szTextKey = szText; 
	reset(); 
}
The main problem is that I cannot tell what code is printing the text that I want to change. If I can see how it gets printed, I am sure I can fix the actual problem. Can you help me to understand where the blue text gets printed? I cannot find any references to TXT_KEY_COMMAND_PROMOTION or COMMAND_PROMOTION which may be doing it, and that is the only place where the text "Promote Unit" appears in the xml.

I don't understand the caching well enough to rewrite it. I understand standard data structures well, but I don't understand how uiForm is used in the getDescription code I posted above. It seems to be calling the same getObjectText, the exact same way, multiple times to fill up a list. But that doesn't make any sense to me at all. Can you help me understand that function, or how their caching works in general?
 
It may be that I don't understand what you want to do, but I still think you need to look at CvGameTextMgr::setPromotionHelp.

It creates the blue text using:
szTempBuffer.Format( SETCOLR L"%s" ENDCOLR , TEXT_COLOR("COLOR_HIGHLIGHT_TEXT"), promo.getDescription());

Try changing it to:
szTempBuffer.Format( SETCOLR L"%s" ENDCOLR , TEXT_COLOR("COLOR_HIGHLIGHT_TEXT"), promo.getText());
 
It is very curious. I have made two changes in CvGameTextMgr.cpp as an experiment:
Code:
void CvGameTextMgr::setPromotionHelp(CvWStringBuffer &szBuffer, PromotionTypes ePromotion, bool bCivilopediaText)
{
	szBuffer.append("DA1");
	if (!bCivilopediaText) [...]
Code:
void CvGameTextMgr::parsePromotionHelp(CvWStringBuffer &szBuffer, PromotionTypes ePromotion, const wchar* pcNewline)
{
	PROFILE_FUNC();

	CvWString szText, szText2;
	int iI;

	szBuffer.append("DA2");

	if (NO_PROMOTION == ePromotion) [...]
I would expect to see the strings DA1 and DA2 appearing in the hover help. But we see only DA2, affecting the white text. So I am still puzzled about how to affect the blue text.
 

Attachments

  • blue-text.gif
    blue-text.gif
    22.1 KB · Views: 77
When I change:
szTempBuffer.Format( SETCOLR L"%s" ENDCOLR , TEXT_COLOR("COLOR_HIGHLIGHT_TEXT"), promo.getDescription());

to:
szTempBuffer.Format( SETCOLR L"%s" ENDCOLR , TEXT_COLOR("COLOR_HIGHLIGHT_TEXT"), "Testing 1,2,3....");

The blue text changes to "Testing 1,2,3....". Isn't that what you want?
 
I have made the exact change you suggest, and I do not get the effect you describe. In my post above, I put the string "DA1" onto the beginning of the string in setPromotionHelp, and nothing happened, but the string "DA2" I added in parsePromotionHelp shows up at the beginning of the white text.

When I make your suggested change, there is no effect on the blue text. This is consistent with my previous result where adding "DA1" did not show up anywhere.

I am doing this in a vanilla mod except for BBAI 0.84, which seems unlikely to affect anything. What mod are you doing this in?
 
I'm trying it within my mod called Civ4 Panzer General. The SDK is a heavily edited version of of RevDCM (I forget which version). As far as I know I didn't change anything that has to do with promotion text. I checked an older SDK that I think is vanilla and it has the same szTempBuffer.Format line. "COLOR_HIGHLIGHT_TEXT" is the blue text color and promo.getDescription() looks like it returns the blue text, so it makes sense that changing that line would change the blue text. I wonder why it isn't working for you?
 
I just noticed something - you are appending "DA1" to szBuffer at the beginning of the function. szTempBuffer.Format then erases the "DA1" and creates a new string.
 
I read the code slightly differently:
Code:
		szTempBuffer.Format( SETCOLR L"%s" ENDCOLR , TEXT_COLOR("COLOR_HIGHLIGHT_TEXT"), "Testing 1,2,3");
		szBuffer.append(szTempBuffer);
If I had been writing to szTempBuffer, then I agree that the Format would wipe out my text. But I am writing to szBuffer, to which the Format string gets *appended*. Anyway, when I make the same change as you, I see no result.

I have a lead, but I have not found the complete solution yet. The blue and white text I am looking at is not a *promotion* help at all. It is a hotkey. Are you sure that the specific hover help you are looking at is what appears when you hover the mouse over the tiny promotion icon in the bottom left of the screen? Also you can give a unit experience with WB so that it has promotion command icons, and hover over those. These show the same help. Are you perhaps hovering over something else? My instructions may have been unclear.

The text "Promote Unit (xxx)" is created by CvHotkeyInfo::getHotKeyDescription(). When I edit this string, *now* I see the edit coming in the blue text. I have to figure out the relationship between the hotkey description key and the promotion key, but this seems promising.
 
My apologies, I thought you where talking about the help text for a promotion, not the text created by a promotion action button (or whatever they are called).
 
Could this be the link that you are looking for? It's located in CvXMLLoadUtility::SetGlobalActionInfo.

Code:
else if ((ActionSubTypes)piActionInfoTypeList[piOrderedIndex[i]] == ACTIONSUBTYPE_PROMOTION)
		{
			GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).setCommandType(FindInInfoClass("COMMAND_PROMOTION"));
			GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).setActionInfoIndex(i);
			GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).setHotKeyDescription(GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).getTextKeyWide(), GC.getCommandInfo((CommandTypes)(GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).getCommandType())).getTextKeyWide(), CreateHotKeyFromDescription(GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).getHotKey(), GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).isShiftDown(), GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).isAltDown(), GC.getPromotionInfo((PromotionTypes)piIndexList[piOrderedIndex[i]]).isCtrlDown()));
		}

The last line is the important one.
 
No, *my* apologies, I should have been more clear in the OP about what I was hovering over. Anyway, as a result of the discussion, I have additionally set m_szHotKeyAltDescriptionKey and m_szHotKeyDescriptionKey in my CvPromotion::setText(). This gives me the hover help over the command / action / whatever thingie.

Success!
 
Back
Top Bottom