Hiding popups at specific times

TK_civftcs

Chieftain
Joined
Jul 4, 2015
Messages
23
Location
Finland
Hello everyone, I'm new to modding ciV. Nice to be here. After some weeks of exploring different problems by google and trial-error, I decided to save my time by just asking people directly when the next arises.

The problem was solved. Check 4th post in thread if interested.

Currently I'm working with a script that gives a player free technologies, and I would like to hide the TechAwardPopup that comes as a byproduct of getting a new technology. I need to hide the tech-popups only when granting the free techs. I've tried the following solutions:

First, DequeuePopup inside the function that gives the techs:
Code:
function SpawnTechs(pPlayer, year)
    *stuff that gives the technology I want, this part is working*
    UIManager:DequeuePopup(ContextPtr:LookUpControl("/InGame/TechAwardPopup"));
end

Second, changing the GameEvent which gets called when a popup needs to appear:
Code:
function HideTechPopup(popupInfo)
      UIManager:DequeuePopup(ContextPtr:LookUpControl("/InGame/TechAwardPopup"));
end

GameEvents.PlayerDoTurn.Add( function(iPlayer)
        *Stuff*
	local Year = Game.GetGameTurnYear();
	if (*Conditions to spawn tech*) then	
                *More stuff*
                Events.SerialEventGameMessagePopup.Add( HideTechPopup )
		SpawnTechs(Players[iPlayer], Year);
                Events.SerialEventGameMessagePopup.Remove( HideTechPopup )
                *Code stuff*
	end
end)

Any help is appreciated, as neither of the solutions have worked. The technologies are starting technologies to civs, I'm working on a "historical spawn date" -functionality. I have read through the existing HSD mod by Gedemon, but I want to do things slightly differently.

Thanks,
TK
 
Code:
local bHideTech = false;

function HideTechPopup(popupInfo)
      if bHideTech then
UIManager:DequeuePopup(ContextPtr:LookUpControl("/InGame/TechAwardPopup"));
     end
end
Events.SerialEventGameMessagePopup.Add( HideTechPopup )

GameEvents.PlayerDoTurn.Add( function(iPlayer)
        *Stuff*
	local Year = Game.GetGameTurnYear();
	if (*Conditions to spawn tech*) then	
                *More stuff*
                bHideTech = true;
		SpawnTechs(Players[iPlayer], Year);
                bHideTech = false;
                *Code stuff*
	end
end)
Try this. Should be working.
There is also NoRewardPopup option that adds notifications instead techpopup. Remember to take care about them as well.

Good luck.
 
Hey, LastSword,

Thanks a many. :) So as a general rule of thumb one should not attempt to add a "function A" to an event by a call inside "function B." This will save my time on more than just this occasion! -- if it works. I'll return to edit this post once I've tried it out. Anyways, thanks.
 
It appears the bug was way more elusive than I thought at first. I have a feeling that the ciV -engine runs "Events" one at a time, no matter what. If an event gets called while other is running, it goes to a queue. This resulted in your solution, LastSword, almost working but not quite.

Proof to back the hypothesis:
Code:
Code:
local HideTech = false;

Events.SerialEventGameMessagePopup.Add( function (popupInfo)
        print("DEBUG");
	if HideTech then print("TRUE"); end
	if not HideTech then print("FALSE"); end
        UIManager:DequeuePopup(ContextPtr:LookUpControl("/InGame/TechAwardPopup"));
end)

GameEvents.PlayerDoTurn.Add( function(iPlayer)
	*Blabla*
		HideTech = true
		SpawnTechs(Players[iPlayer], Year); -- During this function popups are generated, and thus MessagePopup -event is called.
		HideTech = false

		GiveCultureAndGold(Players[iPlayer]);
		print(GameInfo.StartLocs[g_SpawnCivID].Type .. " spawned!");
		g_SpawnCivID = g_SpawnCivID + 1;
	end
end)
Resulting lua-log:
Code:
[12667.296] SpawnDates: SpawnTechs called.
[12667.312] SpawnDates: GiveCultureAndGold called.
[12667.312] SpawnDates: CIVILIZATION_GREECE spawned!
[12667.905] SpawnDates: DEBUG
[12667.905] SpawnDates: FALSE

Removing the "HideTech = false" located after the SpawnTechs -line results in a lua-log where "TRUE" gets printed. UImanager was called outside ifs to see if the syntax was correct, which it was. I proceeded to move the UImanager -call into the if-condition, thus fixing the code.
 
Top Bottom