PopupDialogInGame not openingt

SlackSystem

Chieftain
Joined
Mar 27, 2023
Messages
1
Hi, I have the following lua code to check the nuclear reactors and give the age of them to the player:
Code:
include("SupportFunctions.lua");
include("PopupDialog.lua");

function GoToCity(pCity)
  UI.LookAtCity(pCity:GetOwner(), pCity:GetID())
end

function ShowNuclearReactorAgingPopup(pCity, iReactorAge)
  print("WarnNuclearReactor.lua: Creating Nuclear Reactor Aging Popup")
  local popupDialog = PopupDialogInGame:new("NuclearReactorAgingPopup");
  print("WarnNuclearReactor.lua: Adding Title")
  popupDialog:AddTitle("Nuclear Reactor Aging");
  print("WarnNuclearReactor.lua: Adding Text")
  popupDialog:AddText("Your nuclear reactor in " .. pCity:GetName() .. " is " .. iReactorAge .. " turns old.");
  print("WarnNuclearReactor.lua: Adding Cancel Button")
  popupDialog:AddCancelButton("Cancel", function() end);
  print("WarnNuclearReactor.lua: Adding Go To City Button")
  popupDialog:AddConfirmButton("Go to City", function() GoToCity(pCity) end);
  print("WarnNuclearReactor.lua: Opening Popup Dialog");
  popupDialog:Open();
end

function OnLocalPlayerTurnBegin()
  print("WarnNuclearReactor.lua: Local player turn begin")
  local pPlayer = Players[0]
  if pPlayer == nil then
    print("WarnNuclearReactor.lua: Local pPlayer is nil")
    return
  end
  local pPlayerCities = pPlayer:GetCities()
  if pPlayerCities == nil then
    print("WarnNuclearReactor.lua: Local pPlayerCities is nil")
    return
  end
  local kFalloutManager = Game.GetFalloutManager()
  if kFalloutManager == nil then
    print("WarnNuclearReactor.lua: Fallout Manager is nil")
    return
  end
  local reactorCount = kFalloutManager:GetReactorCount()
  for i = 0, reactorCount - 1, 1 do
    print("WarnNuclearReactor.lua: Checking reactor " .. i)
    local reactor = kFalloutManager:GetReactorByIndex(i)
    if reactor.Owner == pPlayer:GetID() then
      print("WarnNuclearReactor.lua: Reactor is owned by player")
      local pCity = pPlayerCities:FindID(reactor.CityID)
      if pCity == nil then
        print("WarnNuclearReactor.lua: pCity is nil")
        return
      end
      print("WarnNuclearReactor.lua: Reactor is in " .. pCity:GetName())
      ShowNuclearReactorAgingPopup(pCity, reactor.Age)
    end
  end
end

print("WarnNuclearReactor.lua: Adding OnLocalPlayerTurnBegin to Events.LocalPlayerTurnBegin")
Events.LocalPlayerTurnBegin.Add(OnLocalPlayerTurnBegin);

Ultimately I will not be showing all of those popups I am just doing that for now while developing and debugging. I have added the script in the modinfo file and I am getting the debug messages indicating that the reactors are being checked and the popups are being created and opened but they are not showing up anywhere on the screen. I could find very little information online about creating functional UI elements for civ 6 so I'm hoping someone can help me figure this out?
 
Top Bottom