home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Dema / Civilization4 / data1.cab / Civ4DemoComponent / Assets / Python / Screens / CvPediaBuilding.py < prev    next >
Encoding:
Python Source  |  2005-11-09  |  13.5 KB  |  300 lines

  1. ## Sid Meier's Civilization 4
  2. ## Copyright Firaxis Games 2005
  3. from CvPythonExtensions import *
  4. import CvUtil
  5. import ScreenInput
  6. import CvScreenEnums
  7. import string
  8.  
  9. # globals
  10. gc = CyGlobalContext()
  11. ArtFileMgr = CyArtFileMgr()
  12. localText = CyTranslator()
  13.  
  14. class CvPediaBuilding:
  15.     "Civilopedia Screen for Buildings"
  16.     
  17.     def __init__(self, main):
  18.         self.iBuilding = -1
  19.         self.top = main
  20.  
  21.         self.BUTTON_SIZE = 46
  22.         
  23.         self.X_BUILDING_PANE = 20
  24.         self.Y_BUILDING_PANE = 70
  25.         self.W_BUILDING_PANE = 433
  26.         self.H_BUILDING_PANE = 210
  27.         
  28.         self.X_BUILDING_ANIMATION = 475
  29.         self.Y_BUILDING_ANIMATION = 78
  30.         self.W_BUILDING_ANIMATION = 303
  31.         self.H_BUILDING_ANIMATION = 200
  32.         self.X_ROTATION_BUILDING_ANIMATION = -20
  33.         self.Z_ROTATION_BUILDING_ANIMATION = 30
  34.         self.SCALE_ANIMATION = 1.0
  35.                 
  36.         self.X_STATS_PANE = 210
  37.         self.Y_STATS_PANE = 120
  38.         self.W_STATS_PANE = 250
  39.         self.H_STATS_PANE = 200
  40.                 
  41.         self.X_ICON = 48
  42.         self.Y_ICON = 105
  43.         self.W_ICON = 150
  44.         self.H_ICON = 150
  45.         self.ICON_SIZE = 64
  46.  
  47.         self.X_PREREQ_PANE = 20
  48.         self.Y_PREREQ_PANE = 292
  49.         self.W_PREREQ_PANE = 433
  50.         self.H_PREREQ_PANE = 124
  51.  
  52.         self.X_SPECIAL_PANE = 20
  53.         self.Y_SPECIAL_PANE = 420
  54.         self.W_SPECIAL_PANE = 433
  55.         self.H_SPECIAL_PANE = 278
  56.         
  57.         self.X_HISTORY_PANE = 473
  58.         self.Y_HISTORY_PANE = 292
  59.         self.W_HISTORY_PANE = 304
  60.         self.H_HISTORY_PANE = 407
  61.         
  62.     # Screen construction function
  63.     def interfaceScreen(self, iBuilding):    
  64.             
  65.         self.iBuilding = iBuilding
  66.     
  67.         self.top.deleteAllWidgets()                        
  68.                             
  69.         screen = self.top.getScreen()
  70.         
  71.         bNotActive = (not screen.isActive())
  72.         if bNotActive:
  73.             self.top.setPediaCommonWidgets()
  74.         
  75.         # Header...
  76.         szHeader = u"<font=4b>" + gc.getBuildingInfo(self.iBuilding).getDescription().upper() + u"</font>"
  77.         szHeaderId = self.top.getNextWidgetName()
  78.         screen.setLabel(szHeaderId, "Background", szHeader, CvUtil.FONT_CENTER_JUSTIFY, self.top.X_SCREEN, self.top.Y_TITLE, 0, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL, CivilopediaPageTypes.CIVILOPEDIA_PAGE_BUILDING, iBuilding)
  79.         
  80.         # Top
  81.         screen.setText(self.top.getNextWidgetName(), "Background", self.top.MENU_TEXT, CvUtil.FONT_LEFT_JUSTIFY, self.top.X_MENU, self.top.Y_MENU, 0, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_PEDIA_MAIN, CivilopediaPageTypes.CIVILOPEDIA_PAGE_BUILDING, -1)
  82.  
  83.         if self.top.iLastScreen    != CvScreenEnums.PEDIA_BUILDING or bNotActive:        
  84.             self.placeLinks()
  85.             self.top.iLastScreen = CvScreenEnums.PEDIA_BUILDING
  86.                     
  87.         screen.addPanel( self.top.getNextWidgetName(), "", "", False, False, self.X_BUILDING_PANE, self.Y_BUILDING_PANE, self.W_BUILDING_PANE, self.H_BUILDING_PANE, PanelStyles.PANEL_STYLE_BLUE50)
  88.         
  89.         # Icon
  90.         screen.addPanel(self.top.getNextWidgetName(), "", "", false, false, self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, PanelStyles.PANEL_STYLE_MAIN)
  91.         screen.addDDSGFC(self.top.getNextWidgetName(), gc.getBuildingInfo(self.iBuilding).getButton(), self.X_ICON + self.W_ICON/2 - self.ICON_SIZE/2, self.Y_ICON + self.H_ICON/2 - self.ICON_SIZE/2, self.ICON_SIZE, self.ICON_SIZE, WidgetTypes.WIDGET_GENERAL, -1, -1 )
  92.  
  93.         # Unit animation
  94.         screen.addBuildingGraphicGFC(self.top.getNextWidgetName(), self.iBuilding, self.X_BUILDING_ANIMATION, self.Y_BUILDING_ANIMATION, self.W_BUILDING_ANIMATION, self.H_BUILDING_ANIMATION, WidgetTypes.WIDGET_GENERAL, -1, -1, self.X_ROTATION_BUILDING_ANIMATION, self.Z_ROTATION_BUILDING_ANIMATION, self.SCALE_ANIMATION, True)
  95.  
  96.         self.placeStats()
  97.         
  98.         self.placeRequires()
  99.  
  100.         self.placeSpecial()
  101.         
  102.         self.placeHistory()
  103.  
  104.             
  105.     # Place happiness/health/commerce/great people modifiers
  106.     def placeStats(self):
  107.  
  108.         screen = self.top.getScreen()
  109.                 
  110.         buildingInfo = gc.getBuildingInfo(self.iBuilding)
  111.         
  112.         panelName = self.top.getNextWidgetName()
  113.  
  114.         screen.addListBoxGFC(panelName, "", self.X_STATS_PANE, self.Y_STATS_PANE, self.W_STATS_PANE, self.H_STATS_PANE, TableStyles.TABLE_STYLE_EMPTY)
  115.         screen.enableSelect(panelName, False)
  116.                 
  117.         if (isWorldWonderClass(gc.getBuildingInfo(self.iBuilding).getBuildingClassType())):
  118.             iMaxInstances = gc.getBuildingClassInfo(gc.getBuildingInfo(self.iBuilding).getBuildingClassType()).getMaxGlobalInstances()
  119.             szBuildingType = localText.getText("TXT_KEY_PEDIA_WORLD_WONDER", ())
  120.             if (iMaxInstances > 1):
  121.                 szBuildingType += " " + localText.getText("TXT_KEY_PEDIA_WONDER_INSTANCES", (iMaxInstances,))
  122.                 screen.appendListBoxString(panelName, u"<font=4>" + szBuildingType.upper() + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  123.  
  124.         if (isTeamWonderClass(gc.getBuildingInfo(self.iBuilding).getBuildingClassType())):
  125.             iMaxInstances = gc.getBuildingClassInfo(gc.getBuildingInfo(self.iBuilding).getBuildingClassType()).getMaxTeamInstances()
  126.             szBuildingType = localText.getText("TXT_KEY_PEDIA_TEAM_WONDER", ())
  127.             if (iMaxInstances > 1):
  128.                 szBuildingType += " " + localText.getText("TXT_KEY_PEDIA_WONDER_INSTANCES", (iMaxInstances,))
  129.                 screen.appendListBoxString(panelName, u"<font=4>" + szBuildingType.upper() + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  130.  
  131.         if (isNationalWonderClass(gc.getBuildingInfo(self.iBuilding).getBuildingClassType())):
  132.             iMaxInstances = gc.getBuildingClassInfo(gc.getBuildingInfo(self.iBuilding).getBuildingClassType()).getMaxPlayerInstances()
  133.             szBuildingType = localText.getText("TXT_KEY_PEDIA_NATIONAL_WONDER", ())
  134.             if (iMaxInstances > 1):
  135.                 szBuildingType += " " + localText.getText("TXT_KEY_PEDIA_WONDER_INSTANCES", (iMaxInstances,))
  136.                 screen.appendListBoxString(panelName, u"<font=4>" + szBuildingType.upper() + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  137.  
  138.         if (buildingInfo.getProductionCost() > 0):
  139.             if self.top.iActivePlayer == -1:
  140.                 szCost = localText.getText("TXT_KEY_PEDIA_COST", ((buildingInfo.getProductionCost() * gc.getDefineINT("PROJECT_PRODUCTION_PERCENT"))/100,))
  141.             else:
  142.                 szCost = localText.getText("TXT_KEY_PEDIA_COST", (gc.getPlayer(self.top.iActivePlayer).getBuildingProductionNeeded(self.iBuilding),))
  143.             screen.appendListBoxString(panelName, u"<font=4>" + szCost.upper() + u"%c" % gc.getYieldInfo(YieldTypes.YIELD_PRODUCTION).getChar() + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  144.  
  145.         for k in range(CommerceTypes.NUM_COMMERCE_TYPES):
  146.             if (buildingInfo.getObsoleteSafeCommerceChange(k) != 0):
  147.                 if (buildingInfo.getObsoleteSafeCommerceChange(k) > 0):
  148.                     szSign = "+"
  149.                 else:
  150.                     szSign = ""
  151.                     
  152.                 szCommerce = gc.getCommerceInfo(k).getDescription() + ": "
  153.                 
  154.                 szText1 = szCommerce.upper() + szSign + str(buildingInfo.getObsoleteSafeCommerceChange(k))
  155.                 szText2 = szText1 + (u"%c" % (gc.getCommerceInfo(k).getChar()))
  156.                 screen.appendListBoxString(panelName, u"<font=4>" + szText2 + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  157.  
  158.         if (buildingInfo.getHappiness() > 0):
  159.             szText = localText.getText("TXT_KEY_PEDIA_HAPPY", (buildingInfo.getHappiness(),)).upper()
  160.             screen.appendListBoxString(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.HAPPY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  161.             
  162.         elif (buildingInfo.getHappiness() < 0):
  163.             szText = localText.getText("TXT_KEY_PEDIA_UNHAPPY", (-buildingInfo.getHappiness(),)).upper()
  164.             screen.appendListBoxString(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.UNHAPPY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  165.  
  166.         if (buildingInfo.getHealth() > 0):
  167.             szText = localText.getText("TXT_KEY_PEDIA_HEALTHY", (buildingInfo.getHealth(),)).upper()
  168.             screen.appendListBoxString(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.HEALTHY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  169.             
  170.         elif (buildingInfo.getHealth() < 0):
  171.             szText = localText.getText("TXT_KEY_PEDIA_UNHEALTHY", (-buildingInfo.getHealth(),)).upper()
  172.             screen.appendListBoxString(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.UNHEALTHY_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  173.         
  174.         if (buildingInfo.getGreatPeopleRateChange() != 0):
  175.             szText = localText.getText("TXT_KEY_PEDIA_GREAT_PEOPLE", (buildingInfo.getGreatPeopleRateChange(),)).upper()
  176.             screen.appendListBoxString(panelName, u"<font=4>" + szText + u"%c" % CyGame().getSymbolID(FontSymbols.GREAT_PEOPLE_CHAR) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  177.             
  178.     # Place prereqs (techs, resources)
  179.     def placeRequires(self):
  180.  
  181.         screen = self.top.getScreen()
  182.         
  183.         panelName = self.top.getNextWidgetName()
  184.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_REQUIRES", ()), "", false, true,
  185.                                  self.X_PREREQ_PANE, self.Y_PREREQ_PANE, self.W_PREREQ_PANE, self.H_PREREQ_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  186.                         
  187.         screen.attachLabel(panelName, "", "  ")
  188.  
  189.         # add tech buttons
  190.         for iPrereq in range(gc.getNumTechInfos()):
  191.             if isTechRequiredForBuilding(iPrereq, self.iBuilding):
  192.                 screen.attachImageButton( panelName, "", gc.getTechInfo(iPrereq).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iPrereq, 1, False )
  193.  
  194.         # add resource buttons
  195.         iPrereq = gc.getBuildingInfo(self.iBuilding).getPrereqAndBonus()
  196.         if (iPrereq >= 0):
  197.             screen.attachImageButton( panelName, "", gc.getBonusInfo(iPrereq).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BONUS, iPrereq, -1, False )
  198.             
  199.         for k in range(gc.getNUM_BUILDING_PREREQ_OR_BONUSES()):
  200.             iPrereq = gc.getBuildingInfo(self.iBuilding).getPrereqOrBonuses(k)
  201.             if (iPrereq >= 0):
  202.                 screen.attachImageButton( panelName, "", gc.getBonusInfo(iPrereq).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BONUS, iPrereq, -1, False )
  203.                 
  204.         # add religion button
  205.         iPrereq = gc.getBuildingInfo(self.iBuilding).getPrereqReligion()
  206.         if (iPrereq >= 0):
  207.             screen.attachImageButton( panelName, "", gc.getReligionInfo(iPrereq).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_RELIGION, iPrereq, -1, False )
  208.         
  209.     # Place Special abilities
  210.     def placeSpecial(self):
  211.  
  212.         screen = self.top.getScreen()
  213.         
  214.         panelName = self.top.getNextWidgetName()
  215.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_SPECIAL_ABILITIES", ()), "", true, false,
  216.                                  self.X_SPECIAL_PANE, self.Y_SPECIAL_PANE, self.W_SPECIAL_PANE, self.H_SPECIAL_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  217.         
  218.         listName = self.top.getNextWidgetName()
  219.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  220.         screen.enableSelect(listName, False)
  221.         
  222.         szSpecialText = CyGameTextMgr().getBuildingHelp(self.iBuilding, True, False, False, None)
  223.         splitText = string.split( szSpecialText, "\n" )
  224.         for special in splitText:
  225.             if len( special ) != 0:
  226.                 screen.appendListBoxString( listName, special, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  227.  
  228.     def placeHistory(self):
  229.         
  230.         screen = self.top.getScreen()
  231.         
  232.         panelName = self.top.getNextWidgetName()
  233.         screen.addPanel( panelName, "History", "", True, True,
  234.                         self.X_HISTORY_PANE, self.Y_HISTORY_PANE,
  235.                         self.W_HISTORY_PANE, self.H_HISTORY_PANE,
  236.                         PanelStyles.PANEL_STYLE_BLUE50 )
  237.         
  238.         textName = self.top.getNextWidgetName()
  239. #        screen.attachMultilineText( panelName, textName, gc.getBuildingInfo(self.iBuilding).getCivilopedia(),WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
  240.         screen.addMultilineText( textName, gc.getBuildingInfo(self.iBuilding).getCivilopedia(), self.X_HISTORY_PANE + 15, self.Y_HISTORY_PANE + 40,
  241.             self.W_HISTORY_PANE - (15 * 2), self.H_HISTORY_PANE - (15 * 2) - 25, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
  242.         
  243.     def placeLinks(self):
  244.  
  245.         screen = self.top.getScreen()
  246.                         
  247.         screen.clearListBoxGFC(self.top.LIST_ID)
  248.  
  249.         listSorted = self.getBuildingSortedList()
  250.                 
  251.         iSelected = 0
  252.         i = 0
  253.         for iI in range(len(listSorted)):
  254.             if (not gc.getBuildingInfo(listSorted[iI][1]).isGraphicalOnly()):
  255.                 screen.appendListBoxString(self.top.LIST_ID, listSorted[iI][0], WidgetTypes.WIDGET_PEDIA_JUMP_TO_BUILDING, listSorted[iI][1], 0, CvUtil.FONT_LEFT_JUSTIFY)
  256.                 if listSorted[iI][1] == self.iBuilding:
  257.                     iSelected = i
  258.                 i += 1            
  259.  
  260.         screen.setSelectedListBoxStringGFC(self.top.LIST_ID, iSelected)
  261.             
  262.     def getBuildingType(self, iBuilding):
  263.         if (isWorldWonderClass(gc.getBuildingInfo(iBuilding).getBuildingClassType())):
  264.             return (3)            
  265.  
  266.         if (isTeamWonderClass(gc.getBuildingInfo(iBuilding).getBuildingClassType())):
  267.             return (2)
  268.  
  269.         if (isNationalWonderClass(gc.getBuildingInfo(iBuilding).getBuildingClassType())):
  270.             return (1)
  271.  
  272.         # Regular building
  273.         return (0)
  274.         
  275.     def getBuildingSortedList(self):
  276.         listOfAllTypes = []
  277.         for iBuildingType in range(4):        
  278.             listBuildings = []
  279.             iCount = 0
  280.             for iBuilding in range(gc.getNumBuildingInfos()):
  281.                 if (self.getBuildingType(iBuilding) == iBuildingType):
  282.                     listBuildings.append(iBuilding)
  283.                     iCount += 1
  284.             
  285.             listSorted = [(0,0)] * iCount
  286.             iI = 0
  287.             for iBuilding in listBuildings:
  288.                 listSorted[iI] = (gc.getBuildingInfo(iBuilding).getDescription(), iBuilding)
  289.                 iI += 1
  290.             listSorted.sort()
  291.             for i in range(len(listSorted)):
  292.                 listOfAllTypes.append(listSorted[i])
  293.         return listOfAllTypes
  294.         
  295.                                                     
  296.     # Will handle the input for this screen...
  297.     def handleInput (self, inputClass):
  298.         return 0
  299.  
  300.