home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Dema / Civilization4 / data1.cab / Civ4DemoComponent / Assets / Python / Screens / CvPediaCivic.py < prev    next >
Encoding:
Python Source  |  2005-11-09  |  7.0 KB  |  181 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 CvPediaCivic:
  15.     "Civilopedia Screen for Civics"
  16.  
  17.     def __init__(self, main):
  18.         self.iCivic = -1
  19.         self.top = main
  20.         
  21.         self.X_MAIN_PANE = 45
  22.         self.Y_MAIN_PANE = 85
  23.         self.W_MAIN_PANE = 433
  24.         self.H_MAIN_PANE = 210
  25.  
  26.         self.X_ICON = 78
  27.         self.Y_ICON = 120
  28.         self.W_ICON = 150
  29.         self.H_ICON = 150
  30.         self.ICON_SIZE = 64
  31.  
  32.         self.X_STATS_PANE = self.X_ICON + self.W_ICON + 20
  33.         self.Y_STATS_PANE = 165
  34.         self.W_STATS_PANE = 250
  35.         self.H_STATS_PANE = 200
  36.  
  37.         self.X_REQUIRES = self.X_MAIN_PANE + self.W_MAIN_PANE + 20
  38.         self.Y_REQUIRES = 185
  39.         self.W_REQUIRES = 250
  40.         self.H_REQUIRES = 110
  41.  
  42.         self.X_SPECIAL = self.X_MAIN_PANE
  43.         self.Y_SPECIAL = self.Y_MAIN_PANE + self.H_MAIN_PANE + 10
  44.         self.W_SPECIAL = 705
  45.         self.H_SPECIAL = 130
  46.  
  47.         self.X_TEXT = self.X_MAIN_PANE
  48.         self.Y_TEXT = self.Y_SPECIAL + self.H_SPECIAL + 20
  49.         self.W_TEXT = 705
  50.         self.H_TEXT = 220
  51.         
  52.     # Screen construction function
  53.     def interfaceScreen(self, iCivic):    
  54.             
  55.         self.iCivic = iCivic
  56.     
  57.         self.top.deleteAllWidgets()                        
  58.                             
  59.         screen = self.top.getScreen()
  60.         
  61.         bNotActive = (not screen.isActive())
  62.         if bNotActive:
  63.             self.top.setPediaCommonWidgets()
  64.  
  65.         # Header...
  66.         szHeader = u"<font=4b>" + gc.getCivicInfo(self.iCivic).getDescription().upper() + u"</font>"
  67.         szHeaderId = self.top.getNextWidgetName()
  68.         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)
  69.         
  70.         # Top
  71.         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_CIVIC, -1)
  72.  
  73.         if self.top.iLastScreen    != CvScreenEnums.PEDIA_CIVIC or bNotActive:        
  74.             self.placeLinks()
  75.             self.top.iLastScreen = CvScreenEnums.PEDIA_CIVIC
  76.  
  77.             
  78.         # Icon
  79.         screen.addPanel( self.top.getNextWidgetName(), "", "", False, False,
  80.             self.X_MAIN_PANE, self.Y_MAIN_PANE, self.W_MAIN_PANE, self.H_MAIN_PANE, PanelStyles.PANEL_STYLE_BLUE50)
  81.         screen.addPanel(self.top.getNextWidgetName(), "", "", false, false,
  82.             self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, PanelStyles.PANEL_STYLE_MAIN)
  83.         screen.addDDSGFC(self.top.getNextWidgetName(), gc.getCivicInfo(self.iCivic).getButton(),
  84.             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 )
  85. #        screen.addDDSGFC(self.top.getNextWidgetName(), gc.getCivicInfo(self.iCivic).getButton(), self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, WidgetTypes.WIDGET_GENERAL, self.iCivic, -1 )
  86.         
  87.         self.placeStats()
  88.         self.placeSpecial()
  89.         self.placeRequires()
  90.         self.placeText()
  91.         
  92.     def placeStats(self):
  93.                             
  94.         screen = self.top.getScreen()
  95.  
  96.         panelName = self.top.getNextWidgetName()
  97.         screen.addListBoxGFC(panelName, "",
  98.             self.X_STATS_PANE, self.Y_STATS_PANE, self.W_STATS_PANE, self.H_STATS_PANE, TableStyles.TABLE_STYLE_EMPTY)
  99.         screen.enableSelect(panelName, False)
  100.  
  101.         # Civic Category
  102.         iCivicOptionType = gc.getCivicInfo(self.iCivic).getCivicOptionType()
  103.         if (iCivicOptionType != -1):
  104.             screen.appendListBoxString(panelName, u"<font=4>" + gc.getCivicOptionInfo(iCivicOptionType).getDescription().upper() + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  105. #            screen.setText(self.top.getNextWidgetName(), "Background", gc.getCivicOptionInfo(iCivicOptionType).getDescription().upper(), CvUtil.FONT_LEFT_JUSTIFY, self.X_STATS_PANE, self.Y_STATS_PANE-35, 0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
  106.  
  107.         # Upkeep
  108.         pUpkeepInfo = gc.getUpkeepInfo(gc.getCivicInfo(self.iCivic).getUpkeep())
  109.         if (pUpkeepInfo):
  110.             screen.appendListBoxString(panelName, u"<font=4>" + pUpkeepInfo.getDescription().upper() + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  111. #            screen.setText(self.top.getNextWidgetName(), "Background", pUpkeepInfo.getDescription().upper(), CvUtil.FONT_LEFT_JUSTIFY, self.X_STATS_PANE, self.Y_STATS_PANE, 0, FontTypes.TITLE_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 )
  112.         
  113.     def placeRequires(self):
  114.         
  115.         screen = self.top.getScreen()
  116.         
  117.         panelName = self.top.getNextWidgetName()
  118.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_REQUIRES", ()), "", false, true,
  119.                  self.X_REQUIRES, self.Y_REQUIRES, self.W_REQUIRES, self.H_REQUIRES, PanelStyles.PANEL_STYLE_BLUE50 )
  120.         screen.enableSelect(panelName, False)
  121.         screen.attachLabel(panelName, "", "  ")
  122.         
  123.         iTech = gc.getCivicInfo(self.iCivic).getTechPrereq()
  124.         if (iTech > -1):
  125.             screen.attachImageButton( panelName, "", gc.getTechInfo(iTech).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, iTech, 1, False )
  126.             
  127.     def placeSpecial(self):
  128.         
  129.         screen = self.top.getScreen()
  130.         
  131.         panelName = self.top.getNextWidgetName()
  132.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_EFFECTS", ()), "", true, false,
  133.                  self.X_SPECIAL, self.Y_SPECIAL, self.W_SPECIAL, self.H_SPECIAL, PanelStyles.PANEL_STYLE_BLUE50 )
  134.                 
  135.         listName = self.top.getNextWidgetName()
  136.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  137.         screen.enableSelect(listName, False)
  138.         
  139.         szSpecialText = CyGameTextMgr().parseCivicInfo(self.iCivic, True, False)
  140.         splitText = string.split( szSpecialText, "\n" )
  141.         for special in splitText:
  142.             if len( special ) != 0:
  143.                 screen.appendListBoxString( listName, special, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  144.         
  145.     def placeText(self):
  146.         
  147.         screen = self.top.getScreen()
  148.         
  149.         panelName = self.top.getNextWidgetName()
  150.         screen.addPanel( panelName, "", "", true, true,
  151.                  self.X_TEXT, self.Y_TEXT, self.W_TEXT, self.H_TEXT, PanelStyles.PANEL_STYLE_BLUE50 )
  152.  
  153.         szText = gc.getCivicInfo(self.iCivic).getCivilopedia()
  154.         screen.attachMultilineText( panelName, "Text", szText, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
  155.         
  156.     def placeLinks(self):
  157.  
  158.         screen = self.top.getScreen()
  159.                 
  160.         screen.clearListBoxGFC(self.top.LIST_ID)
  161.         
  162.         # sort Improvements alphabetically
  163.         listSorted=[(0,0)]*gc.getNumCivicInfos()
  164.         for j in range(gc.getNumCivicInfos()):
  165.             listSorted[j] = (gc.getCivicInfo(j).getDescription(), j)
  166.         listSorted.sort()    
  167.  
  168.         iSelected = 0            
  169.         for iI in range(gc.getNumCivicInfos()):
  170.             screen.appendListBoxString(self.top.LIST_ID, listSorted[iI][0], WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIVIC, listSorted[iI][1], 0, CvUtil.FONT_LEFT_JUSTIFY )
  171.             if listSorted[iI][1] == self.iCivic:
  172.                 iSelected = iI            
  173.  
  174.         screen.setSelectedListBoxStringGFC(self.top.LIST_ID, iSelected)
  175.             
  176.     # Will handle the input for this screen...
  177.     def handleInput (self, inputClass):
  178.         return 0
  179.  
  180.  
  181.