Should be a simple UI button mod question

Grakl

Chieftain
Joined
May 19, 2006
Messages
63
Location
South Dakota (People live here ><)
Hello, maybe someone can shed some light on an issue I'm having on my mod. What I'm trying to do is add a UI button in the "City" view that allows me to make a city I own a puppet. Sounds easy right?

Alright, I've included "CityView.xml" and CityView.lua" in my ModBuddy project. Here's the current updates to CityView.xml

Code:
<GridButton ID="PuppetizeCityButton" Anchor="C,B" Size="280,36" Offset="0,250" Style="BaseButton" ToolTip="Make Puppet" Hidden="0">
          <Label ID="PuppetizeCityLabel" Anchor="C,C" Offset="0,-2" String="Make Puppet" Color0="255.255.200.255" Color1="0.0.0.128" Color2="255.255.200.255" Font="TwCenMT24" FontStyle="SoftShadow"/>
</GridButton>

That part works, which is fantastic. When I load my mod and start a game. BAM! There's a button that says "Make Puppet". Good deal. Now, just to make baby steps I want to change the text of my new "Make Puppet" button when I click some other button. For my test, I used "OnBuyPlotClick" in the CityView.lua.

Code:
function OnBuyPlotClick()
	
	local city = UI.GetHeadSelectedCity();
	
	if (city == nil) then
		return;
	end;
	
	UI.SetInterfaceMode(InterfaceModeTypes.INTERFACEMODE_PURCHASE_PLOT);
	UpdateWorkingHexes();
	
	--Controls.PuppetizeCityLabel:SetText("Boosh");
	Controls.EndTurnText:SetText("Boosh");
	
	--Network.SendCityBuyPlot(city:GetID(), -1, -1);
	--UpdateBuyPlotButton();
end

Now, as you can see, I have a "Controls.PuppetizeCityLabel:SetText("")" commented out. It simply doesn't work. The uncommented line "Controls.EndTurnText:SetText("")" does though. It does in fact change the "End Turn" button text to "Boosh". So I know the lua changes are taking affect.

Does anyone have any idea why my own control isn't being affected? Thanks for any help.
 
The control you created is a Label, but I'm going to assume the EndTurnText is a TextButton. SetText only works for TextButtons, you need to use the SetString for a label.

However as you want this click-able best to change it to a TextButton in your XML file.
Code:
<GridButton ID="PuppetizeCityButton" Anchor="C,B" Size="280,36" Offset="0,250" Style="BaseButton" ToolTip="Make Puppet" Hidden="0">
          <TextButton ID="PuppetizeCityLabel" Anchor="C,C" Offset="0,-2" String="Make Puppet" Color0="255.255.200.255" Color1="0.0.0.128" Color2="255.255.200.255" Font="TwCenMT24" FontStyle="SoftShadow"/>
</GridButton>

That should now change the text when you click the other button. Unfortunately this is as far as my tinkering has got me also. Linking a button to a specific Lua function I have yet to work out.
 
I appreciate the help, but I tried your suggestion to no avail. I couldn't tell you when SetString() is supposed to be used or when SetText() is. I modeled my "PuppetizeCityButton" on the "ReturnToMapButton" in XML. Here's the ReturnToMapButton code:

Code:
<GridButton Anchor="C,B" Size="280,36" Offset="0,84" ID="ReturnToMapButton" Style="BaseButton" ToolTip="TXT_KEY_CITYVIEW_RETURN_TT">
		<Label Anchor="C,C" Offset="0,-2" String="TXT_KEY_CITYVIEW_RETURN_TO_MAP" Color0="255.255.200.255" Color1="0.0.0.128" Color2="255.255.200.255" Font="TwCenMT20" FontStyle="Shadow" ID="EndTurnText"/>
	</GridButton>

As you can see it has a Label control. In my CityView.lua I can call:

Code:
Controls.EndTurnText:SetText("Boosh");

and it will set the text correctly. Regardless, I tried your suggestion, I changed the Label to a TextButton and uncommented my SetText() call for my "PuppetizeCityLabel" and it didn't work. What's even more interesting is that the *working* call to change the "EndTurnText" didn't work either. So it's not like it just failed to change the text, it invalidated all the code after it. I'll assume the rest of the function failed, but who knows, maybe the rest of the file fails to do anything?

Edit: I changed my control back to a Label and changed SetText() to SetString() and the mod poofs from my mod list. Clearly something failed there. I don't know the syntax of SetString(). Needs more investigation.
 
Back
Top Bottom