• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Change difficulty names?

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
How do I change difficulty names or descriptions?

I tried just altering the database values, but found it doesn't work for the "select difficulty" window. So I opened it up and found this:

PHP:
for info in GameInfo.HandicapInfos() do
    local controlTable = {};
    ContextPtr:BuildInstanceForControl( "ItemInstance", controlTable, Controls.Stack );
    IconHookup( info.PortraitIndex, 64, info.IconAtlas, controlTable.Icon );
    controlTable.Help:SetText( Locale.ConvertTextKey( info.Help ) );
    controlTable.Name:SetText( Locale.ConvertTextKey( info.Description ) );
    controlTable.Button:SetToolTipString( Locale.ConvertTextKey( info.Help ) );
    controlTable.Button:SetVoid1( info.ID );
    controlTable.Button:RegisterCallback( Mouse.eLClick, DifficultySelected );
end

Since it's outside the functions it loads before mods load. I think I need to update the Name/Help/Tooltip values for each button in GameSetupScreen's ShowHideHandler function. How do I access a button's fields from within the parent file?
 
Most of the setup UI is not moddable unless you're willing to create alternate versions of the UI lua/xml. I've done this in my own mod, replacing the entire Advanced Setup screen with a custom version, so that I could get a bunch of extra changes made (like defaulting the difficulty to Prince, hiding maps that aren't compatible with my mod, and so on). But it's surprising how many things DON'T need that sort of modification; you can add new game options, for instance, and it'll simply tack them onto the end of the list.

Thalassicus said:
Since it's outside the functions it loads before mods load.

That's not true. The moment you go through the Mods/Single Player menu, your mod has loaded. Since the handicaps are not set until it reaches the Setup or Advanced Setup screens, your mod will definitely be in memory at that point. So in your particular case, modifying the handicap labels in the XML will show up in the setup screens, assuming you haven't made some other mistake.
 
Changes appear correctly on the left side of the window (selected difficulty) but not the right side (difficulty selection box). They both scan the same variable, so if it's not a preloading issue... what could it be?
 
They both scan the same variable, so if it's not a preloading issue... what could it be?

Well, it's possible that they're NOT scanning the same variable; I'd have to look through the actual UI code to be sure. There are quite a few places where the existing UI uses two separate keys for the same text string, or two separate arrays for each variable, so it's possible that you're changing one (the one used by the bit of code you posted) and not the other (used by some other bit of code). So far I've only found three Lua constructs that aren't updated by any XML changes:
> The PreGame structure, which is really annoying when you're trying to do something like disable the option to use a certain victory condition (like, say, removing the space race victory in a mod that adds three new future eras). PreGame does acknowledge some XML things, but not others.
> Each map script carries certain mod information with it (like the default on/off states for each victory type), which can sometimes override your XML. Mostly this applies to scenario maps; the generic map scripts don't cause problems.
> There are a bunch of explicit arrays (VictoryTypes, ResourceTypes, TerrainTypes, etc.) that aren't moddable from the XML. This might be what's causing the problems in your case; there might be a HandicapTypes array that isn't being modified by the XML, even if GameInfo.Handicaps is. Again, I'd have to see the actual UI code, which I can't do until I get home from work tonight.

There are also a few absolutely hard-coded bits of Lua, like within AssignStartingPlots; no matter what the XML says, ASP assumes certain numbers of pixels for each map size, and hard-codes things like the number of natural wonders to place, to where adding a new map size within the XML wouldn't actually do what you wanted. Likewise, the Tech Tree code is hard-set to use seven Eras, the Civilopedia is hard-set to have 23 categories on the Concepts page, the Policies code is hard-set to use 10 branches, the Victory Progress page assumes six spaceship parts, and so on. It's possible that the names of the handicaps are hard-coded, and it's also possible that it's not actually displaying a text key at all, but is instead displaying a .jpg image or something that just happens to look like text.
 
When I change the "Help" filelds of the "HandicapInfos" table, this section of code correctly shows the new values on the left side of the GameSetupScreen:
PHP:
function SetDifficulty()
  -- Set Difficulty Slot
  local info = GameInfo.HandicapInfos[ PreGame.GetHandicap( 0 ) ];
  if ( info ~= nil ) then
    IconHookup( info.PortraitIndex, 128, info.IconAtlas, Controls.DifficultyIcon );
    Controls.DifficultyHelp:SetText( Locale.ConvertTextKey( info.Help ) );
    Controls.DifficultyName:SetText( Locale.ConvertTextKey("TXT_KEY_AD_HANDICAP_SETTING", Locale.ConvertTextKey( info.Description ) ) );
  end
end

This section of code in the SelectDifficulty box on the right side of the game setup screen does not show the new values:
PHP:
for info in GameInfo.HandicapInfos() do
  local controlTable = {};
  ContextPtr:BuildInstanceForControl( "ItemInstance", controlTable, Controls.Stack );
  IconHookup( info.PortraitIndex, 64, info.IconAtlas, controlTable.Icon );
  controlTable.Help:SetText( Locale.ConvertTextKey( info.Help ) );
  controlTable.Name:SetText( Locale.ConvertTextKey( info.Description ) );
  controlTable.Button:SetToolTipString( Locale.ConvertTextKey( info.Help ) );
  controlTable.Button:SetVoid1( info.ID );
  controlTable.Button:RegisterCallback( Mouse.eLClick, DifficultySelected );
end
They both set their text directly from the same fields in the database. It doesn't appear to involve the pregame table, map scripts, explicit arrays, or hardcoding.
 
They both set their text directly from the same fields in the database. It doesn't appear to involve the pregame table, map scripts, explicit arrays, or hardcoding.

I looked through the code myself, and by all appearances it SHOULD update both fields when your mod is loaded. SelectDifficulty shouldn't be ignoring your mod's changes, but apparently it is.

The only thing I can think of here is that because the ChangeDifficulty script DOES involve the PreGame table (the part where it sets the default difficulty), it might be something that's explicitly loaded before mods are since otherwise there'd be the (remote) possibility of having no difficulties to default to. If that's true, then the same would also apply to altering map sizes and such, which'd be easy enough to test.
 
The reason I think the part outside the function is a problem is because I suspect it's a cache issue. Changes I make in the database often have a delayed reaction on these screens. Altered civ unique item icons are often blank until I select a civ. The loading screen typically has outdated tooltips.

So this goes back to my original question... how can I access those button's fields from within a function in the parent file, to update the text when the screen is displayed?
 
Back
Top Bottom