home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Dema / Civilization4 / data1.cab / Civ4DemoComponent / Assets / Python / Screens / CvPediaImprovement.py < prev    next >
Encoding:
Python Source  |  2005-11-09  |  11.0 KB  |  268 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 CvPediaImprovement:
  15.     "Civilopedia Screen for tile Improvements"
  16.  
  17.     def __init__(self, main):
  18.         self.iImprovement = -1
  19.         self.top = main
  20.         
  21.         self.X_UPPER_PANE = 20
  22.         self.Y_UPPER_PANE = 65
  23.         self.W_UPPER_PANE = 433
  24.         self.H_UPPER_PANE = 210
  25.         
  26.         self.X_IMPROVENEMT_ANIMATION = 475
  27.         self.Y_IMPROVENEMT_ANIMATION = 73
  28.         self.W_IMPROVENEMT_ANIMATION = 303
  29.         self.H_IMPROVENEMT_ANIMATION = 200
  30.         self.X_ROTATION_IMPROVENEMT_ANIMATION = -20
  31.         self.Z_ROTATION_IMPROVENEMT_ANIMATION = 30
  32.         self.SCALE_ANIMATION = 0.8
  33.         
  34.         self.X_ICON = 165
  35.         self.Y_ICON = 100
  36.         self.W_ICON = 150
  37.         self.H_ICON = 150
  38.         self.ICON_SIZE = 64
  39.         
  40.         self.X_IMPROVEMENTS_PANE = self.X_UPPER_PANE
  41.         self.Y_IMPROVEMENTS_PANE = self.Y_UPPER_PANE + self.H_UPPER_PANE + 20
  42.         self.W_IMPROVEMENTS_PANE = 500
  43.         self.H_IMPROVEMENTS_PANE = 135
  44.         
  45.         self.X_BONUS_YIELDS_PANE = self.X_IMPROVEMENTS_PANE + self.W_IMPROVEMENTS_PANE + 25
  46.         self.Y_BONUS_YIELDS_PANE = self.Y_UPPER_PANE + self.H_UPPER_PANE + 20
  47.         self.W_BONUS_YIELDS_PANE = 230
  48.         self.H_BONUS_YIELDS_PANE = 402
  49.         
  50.         self.X_REQUIRES = self.X_UPPER_PANE
  51.         self.Y_REQUIRES = self.Y_IMPROVEMENTS_PANE + self.H_IMPROVEMENTS_PANE + 20
  52.         self.W_REQUIRES = 500
  53.         self.H_REQUIRES = 110
  54.         
  55.         self.X_EFFECTS = self.X_UPPER_PANE
  56.         self.Y_EFFECTS = self.Y_REQUIRES + self.H_REQUIRES + 20
  57.         self.W_EFFECTS = 500
  58.         self.H_EFFECTS = 120
  59.         
  60.     # Screen construction function
  61.     def interfaceScreen(self, iImprovement):    
  62.             
  63.         self.iImprovement = iImprovement
  64.     
  65.         self.top.deleteAllWidgets()                        
  66.                             
  67.         screen = self.top.getScreen()
  68.         
  69.         bNotActive = (not screen.isActive())
  70.         if bNotActive:
  71.             self.top.setPediaCommonWidgets()
  72.  
  73.         # Header...
  74.         szHeader = u"<font=4b>" + gc.getImprovementInfo(self.iImprovement).getDescription().upper() + u"</font>"
  75.         szHeaderId = self.top.getNextWidgetName()
  76.         screen.setLabel(szHeaderId, "Background", szHeader, CvUtil.FONT_CENTER_JUSTIFY, self.top.X_SCREEN, self.top.Y_TITLE, 0, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
  77.         
  78.         # Top
  79.         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_IMPROVEMENT, -1)
  80.  
  81.         if self.top.iLastScreen    != CvScreenEnums.PEDIA_IMPROVEMENT or bNotActive:        
  82.             self.placeLinks()
  83.             self.top.iLastScreen = CvScreenEnums.PEDIA_IMPROVEMENT
  84.             
  85.         # Icon
  86.         screen.addPanel( self.top.getNextWidgetName(), "", "", False, False,
  87.             self.X_UPPER_PANE, self.Y_UPPER_PANE, self.W_UPPER_PANE, self.H_UPPER_PANE, PanelStyles.PANEL_STYLE_BLUE50)
  88.         screen.addPanel(self.top.getNextWidgetName(), "", "", false, false,
  89.             self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, PanelStyles.PANEL_STYLE_MAIN)
  90.         screen.addDDSGFC(self.top.getNextWidgetName(), gc.getImprovementInfo(self.iImprovement).getButton(),
  91.             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.         # Bonus animation
  94.         screen.addImprovementGraphicGFC(self.top.getNextWidgetName(), self.iImprovement, self.X_IMPROVENEMT_ANIMATION, self.Y_IMPROVENEMT_ANIMATION, self.W_IMPROVENEMT_ANIMATION, self.H_IMPROVENEMT_ANIMATION, WidgetTypes.WIDGET_GENERAL, -1, -1, self.X_ROTATION_IMPROVENEMT_ANIMATION, self.Z_ROTATION_IMPROVENEMT_ANIMATION, self.SCALE_ANIMATION, True)
  95.                                 
  96.         self.placeSpecial()
  97.         
  98.         self.placeBonusYield()
  99.  
  100.         self.placeYield()
  101.         
  102.         self.placeRequires()
  103.             
  104.     def placeYield(self):
  105.     
  106.         screen = self.top.getScreen()
  107.         
  108.         panelName = self.top.getNextWidgetName()
  109.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_CATEGORY_IMPROVEMENT", ()), "", true, true,
  110.                  self.X_IMPROVEMENTS_PANE, self.Y_IMPROVEMENTS_PANE, self.W_IMPROVEMENTS_PANE, self.H_IMPROVEMENTS_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  111.         
  112.         listName = self.top.getNextWidgetName()
  113.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  114.         screen.enableSelect(listName, False)
  115.         
  116.         info = gc.getImprovementInfo(self.iImprovement)
  117.         
  118.         for k in range(YieldTypes.NUM_YIELD_TYPES):
  119.             iYieldChange = gc.getImprovementInfo(self.iImprovement).getYieldChange(k)
  120.             if (iYieldChange != 0):                                        
  121.                 szYield = u""
  122.                 if (iYieldChange > 0):
  123.                     sign = "+"
  124.                 else:
  125.                     sign = ""
  126.                     
  127.                 szYield += (u"%s: %s%i%c" % (gc.getYieldInfo(k).getDescription(), sign, iYieldChange, gc.getYieldInfo(k).getChar()))
  128.                 screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  129.             
  130.         for k in range(YieldTypes.NUM_YIELD_TYPES):
  131.             iYieldChange = gc.getImprovementInfo(self.iImprovement).getIrrigatedYieldChange(k)
  132.             if (iYieldChange != 0):
  133.                 szYield = localText.getText("TXT_KEY_PEDIA_IRRIGATED_YIELD", (gc.getYieldInfo(k).getTextKey(), iYieldChange, gc.getYieldInfo(k).getChar()))
  134.                 screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  135.             
  136.         for k in range(YieldTypes.NUM_YIELD_TYPES):
  137.             iYieldChange = gc.getImprovementInfo(self.iImprovement).getHillsYieldChange(k)
  138.             if (iYieldChange != 0):                                        
  139.                 szYield = localText.getText("TXT_KEY_PEDIA_HILLS_YIELD", (gc.getYieldInfo(k).getTextKey(), iYieldChange, gc.getYieldInfo(k).getChar()))    
  140.                 screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  141.             
  142.         for k in range(YieldTypes.NUM_YIELD_TYPES):
  143.             szYield = u""
  144.             iYieldChange = gc.getImprovementInfo(self.iImprovement).getRiverSideYieldChange(k)
  145.             if (iYieldChange != 0):                                        
  146.                 szYield = localText.getText("TXT_KEY_PEDIA_RIVER_YIELD", (gc.getYieldInfo(k).getTextKey(), iYieldChange, gc.getYieldInfo(k).getChar()))    
  147.                 screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  148.  
  149.         for iTech in range(gc.getNumTechInfos()):
  150.             for k in range(YieldTypes.NUM_YIELD_TYPES):
  151.                 szYield = u""
  152.                 iYieldChange = gc.getImprovementInfo(self.iImprovement).getTechYieldChanges(iTech, k)
  153.                 if (iYieldChange != 0):                                        
  154.                     szYield = localText.getText("TXT_KEY_PEDIA_TECH_YIELD", (gc.getYieldInfo(k).getTextKey(), iYieldChange, gc.getYieldInfo(k).getChar(), gc.getTechInfo(iTech).getDescription()))
  155.                     screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  156.  
  157.         for iCivic in range(gc.getNumCivicInfos()):
  158.             for k in range(YieldTypes.NUM_YIELD_TYPES):
  159.                 szYield = u""
  160.                 iYieldChange = gc.getCivicInfo(iCivic).getImprovementYieldChanges(self.iImprovement, k)
  161.                 if (iYieldChange != 0):                                        
  162.                     szYield = localText.getText("TXT_KEY_PEDIA_TECH_YIELD", (gc.getYieldInfo(k).getTextKey(), iYieldChange, gc.getYieldInfo(k).getChar(), gc.getCivicInfo(iCivic).getDescription()))    
  163.                     screen.appendListBoxString( listName, szYield, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  164.  
  165.     def placeBonusYield(self):
  166.         
  167.         screen = self.top.getScreen()
  168.         
  169.         panelName = self.top.getNextWidgetName()
  170.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_BONUS_YIELDS", ()), "", true, true,
  171.                  self.X_BONUS_YIELDS_PANE, self.Y_BONUS_YIELDS_PANE, self.W_BONUS_YIELDS_PANE, self.H_BONUS_YIELDS_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  172.         
  173.         info = gc.getImprovementInfo(self.iImprovement)
  174.     
  175.  
  176.         for j in range(gc.getNumBonusInfos()):
  177.             bFirst = True
  178.             szYield = u""
  179.             bEffect = False
  180.             for k in range(YieldTypes.NUM_YIELD_TYPES):
  181.                 iYieldChange = info.getImprovementBonusYield(j, k)
  182.                 if (iYieldChange != 0):
  183.                     bEffect = True
  184.                     iYieldChange += info.getYieldChange(k)
  185.                     if (bFirst):
  186.                         bFirst = False
  187.                     else:
  188.                         szYield += u", "
  189.                                                 
  190.                     if (iYieldChange > 0):
  191.                         sign = u"+"
  192.                     else:
  193.                         sign = u""
  194.                         
  195.                     szYield += (u"%s%i%c" % (sign, iYieldChange, gc.getYieldInfo(k).getChar()))
  196.             if (bEffect):
  197.                 childPanelName = self.top.getNextWidgetName()
  198.                 screen.attachPanel(panelName, childPanelName, "", "", False, False, PanelStyles.PANEL_STYLE_EMPTY)
  199.  
  200.                 screen.attachLabel(childPanelName, "", "  ")
  201.                 screen.attachImageButton( childPanelName, "", gc.getBonusInfo(j).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BONUS, j, 1, False )
  202.                 screen.attachLabel(childPanelName, "", u"<font=4>" + szYield + u"</font>")
  203.         
  204.     
  205.     def placeRequires(self):
  206.         
  207.         screen = self.top.getScreen()
  208.         
  209.         panelName = self.top.getNextWidgetName()
  210.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_REQUIRES", ()), "", false, true,
  211.                  self.X_REQUIRES, self.Y_REQUIRES, self.W_REQUIRES, self.H_REQUIRES, PanelStyles.PANEL_STYLE_BLUE50 )
  212.         
  213.         screen.attachLabel(panelName, "", "  ")
  214.         
  215.         for iBuild in range(gc.getNumBuildInfos()):
  216.             if (gc.getBuildInfo(iBuild).getImprovement() == self.iImprovement):     
  217.                 iTech = gc.getBuildInfo(iBuild).getTechPrereq()
  218.                 if (iTech > -1):
  219.                     screen.attachImageButton( panelName, "", gc.getTechInfo(iTech).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iTech, 1, False )
  220.  
  221.     def placeSpecial(self):
  222.         
  223.         screen = self.top.getScreen()
  224.         
  225.         panelName = self.top.getNextWidgetName()
  226.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_EFFECTS", ()), "", true, false,
  227.                  self.X_EFFECTS, self.Y_EFFECTS, self.W_EFFECTS, self.H_EFFECTS, PanelStyles.PANEL_STYLE_BLUE50 )
  228.                 
  229.         listName = self.top.getNextWidgetName()
  230.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  231.         screen.enableSelect(listName, False)
  232.         
  233.         szSpecialText = CyGameTextMgr().getImprovementHelp(self.iImprovement, True)
  234.         splitText = string.split( szSpecialText, "\n" )
  235.         for special in splitText:
  236.             if len( special ) != 0:
  237.                 screen.appendListBoxString( listName, special, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  238.                                         
  239.     def placeLinks(self):
  240.  
  241.         screen = self.top.getScreen()
  242.  
  243.         screen.clearListBoxGFC(self.top.LIST_ID)
  244.         
  245.         # sort Improvements alphabetically
  246.         rowListName=[(0,0)]*gc.getNumImprovementInfos()
  247.         for j in range(gc.getNumImprovementInfos()):
  248.             rowListName[j] = (gc.getImprovementInfo(j).getDescription(), j)
  249.         rowListName.sort()    
  250.             
  251.         iSelected = 0
  252.         i = 0
  253.         for iI in range(gc.getNumImprovementInfos()):
  254.             if (not gc.getImprovementInfo(rowListName[iI][1]).isGraphicalOnly()):
  255.                 screen.appendListBoxString(self.top.LIST_ID, rowListName[iI][0], WidgetTypes.WIDGET_PEDIA_JUMP_TO_IMPROVEMENT, rowListName[iI][1], 0, CvUtil.FONT_LEFT_JUSTIFY)
  256.                 if rowListName[iI][1] == self.iImprovement:
  257.                     iSelected = i
  258.                 i += 1
  259.                     
  260.         screen.setSelectedListBoxStringGFC(self.top.LIST_ID, iSelected)
  261.             
  262.  
  263.     # Will handle the input for this screen...
  264.     def handleInput (self, inputClass):
  265.         return 0
  266.  
  267.  
  268.