Zegangani
King
- Joined
- Oct 9, 2020
- Messages
- 898
Hey Guys! I wanted to edit the tooltip in the Tech/CivicsTree of Buildings to show more informations (ie. Production Cost, Maintenance, ResourceCost...) just like the one of Units. I am new to lua and just starting to learn it, sp i got the tooltip to show the ProductionCost and the Maintenance Amount but not the strategicresources required for the buildings and their strategicresource maintenance.
So here is what i did:
( ToolTipHelper.lua )
(ToolTipLoader_Expansion2)
I tryed everything to get this to work, with no result, except that the code do not crush get errors or something. So i would really apreciate it if someone helps me with this.
So here is what i did:
( ToolTipHelper.lua )
Code:
local cost = building.Cost or 0;
if(cost ~= 0 and building.MustPurchase == false) then
local yield = GameInfo.Yields["YIELD_PRODUCTION"];
if(yield) then
table.insert(toolTipLines, "[NEWLINE]" .. Locale.Lookup("LOC_TOOLTIP_BASE_COST", cost, yield.IconString, yield.Name));
end
end
AddBuildingStrategicResourceTooltip(buildingHash, toolTipLines);
AddBuildingResourceMaintenanceTooltip(buildingHash, toolTipLines);
local maintenance = building.Maintenance or 0;
if(maintenance ~= 0) then
local yield = GameInfo.Yields["YIELD_GOLD"];
if(yield) then
table.insert(toolTipLines, Locale.Lookup("LOC_TOOLTIP_MAINTENANCE", maintenance, yield.IconString, yield.Name));
end
end
(ToolTipLoader_Expansion2)
Code:
BASE_AddBuildingStrategicResourceTooltip = AddBuildingStrategicResourceTooltip;
BASE_AddBuildingResourceMaintenanceTooltip = AddBuildingResourceMaintenanceTooltip;
AddBuildingStrategicResourceTooltip = function(buildingHash, tooltipLines)
local buildingReference:table = GameInfo.Buildings[buildingHash];
if (buildingReference ~= nil) then
local buildingType:string = buildingReference.BuildingType;
if (pBuildQueue ~= nil ) then
local StartProductionCost = pBuildQueue:GetBuildingResourceCost(buildingReference.Index);
if (resource ~= nil) then
local resourceIcon = "[ICON_" .. resource.ResourceType .. "]";
return Locale.Lookup("LOC_UNIT_PRODUCTION_RESOURCE_COST", StartProductionCost, resourceIcon, resource.Name);
end
else
if (GameInfo.Building_ResourceCosts~= nil) then
for row in GameInfo.Building_ResourceCosts() do
if (row.BuildingType == BuildingType) then
local resource = GameInfo.Resources[row.ResourceType];
local StartProductionCost = row.StartProductionCost;
local resourceIcon = "[ICON_" .. resource.ResourceType .. "]";
return Locale.Lookup("LOC_UNIT_PRODUCTION_RESOURCE_COST", StartProductionCost, resourceIcon, resource.Name);
end
end
end
end
end
return "";
end
-- ===========================================================================
AddBuildingResourceMaintenanceTooltip = function(buildingHash, tooltipLines)
local buildingReference:table = GameInfo.Buildings[buildingHash];
if (buildingReference ~= nil) then
local buildingType:string = buildingReference.BuildingType;
if (GameInfo.Building_ResourceCosts~= nil) then
for row in GameInfo.Building_ResourceCosts() do
if (row.BuildingType == BuildingType) then
local PerTurnMaintenanceCost = row.PerTurnMaintenanceCost;
if (PerTurnMaintenanceCost > 0) then
local resource = GameInfo.Resources[row.ResourceType];
if (resource ~= nil) then
local fuelName = Locale.Lookup(resource.Name);
local iconName:string = "[ICON_" .. row.ResourceType .. "]";
return Locale.Lookup("LOC_UNIT_PRODUCTION_FUEL_CONSUMPTION", PerTurnMaintenanceCost, iconName, fuelName);
end
end
end
end
end
end
return "";
end
I tryed everything to get this to work, with no result, except that the code do not crush get errors or something. So i would really apreciate it if someone helps me with this.