home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Dema / Civilization4 / data1.cab / Civ4DemoComponent / Assets / Python / Screens / CvPediaFeature.py < prev    next >
Encoding:
Python Source  |  2005-11-09  |  5.5 KB  |  149 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 CvPediaFeature:
  15.     "Civilopedia Screen for Terrain Features"
  16.  
  17.     def __init__(self, main):
  18.         self.iFeature = -1
  19.         self.top = main
  20.         
  21.         self.X_ICON_PANE = 20 + 30
  22.         self.Y_ICON_PANE = 70 + 30
  23.         self.W_ICON_PANE = 433
  24.         self.H_ICON_PANE = 210
  25.  
  26.         self.X_ICON = 48 + 30
  27.         self.Y_ICON = 105 + 30
  28.         self.W_ICON = 150
  29.         self.H_ICON = 150
  30.         self.ICON_SIZE = 64
  31.         
  32.         self.X_STATS_PANE = 215 + 30
  33.         self.Y_STATS_PANE = 140 + 20
  34.         self.W_STATS_PANE = 230
  35.         self.H_STATS_PANE = 120
  36.         
  37.         self.X_SPECIAL_PANE = 50
  38.         self.Y_SPECIAL_PANE = 320
  39.         self.W_SPECIAL_PANE = 690
  40.         self.H_SPECIAL_PANE = 350
  41.  
  42.     # Screen construction function
  43.     def interfaceScreen(self, iFeature):    
  44.             
  45.         self.iFeature = iFeature
  46.     
  47.         self.top.deleteAllWidgets()                        
  48.                             
  49.         screen = self.top.getScreen()
  50.         
  51.         bNotActive = (not screen.isActive())
  52.         if bNotActive:
  53.             self.top.setPediaCommonWidgets()
  54.  
  55.         # Header...
  56.         szHeader = u"<font=4b>" + gc.getFeatureInfo(self.iFeature).getDescription().upper() + u"</font>"
  57.         szHeaderId = self.top.getNextWidgetName()
  58.         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)
  59.         
  60.         # Top
  61.         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_FEATURE, -1)
  62.  
  63.         if self.top.iLastScreen    != CvScreenEnums.PEDIA_FEATURE or bNotActive:        
  64.             self.placeLinks()
  65.             self.top.iLastScreen = CvScreenEnums.PEDIA_FEATURE
  66.                         
  67.         # Icon
  68.         screen.addPanel( self.top.getNextWidgetName(), "", "", False, False,
  69.             self.X_ICON_PANE, self.Y_ICON_PANE, self.W_ICON_PANE, self.H_ICON_PANE, PanelStyles.PANEL_STYLE_BLUE50)
  70.         screen.addPanel(self.top.getNextWidgetName(), "", "", false, false,
  71.             self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, PanelStyles.PANEL_STYLE_MAIN)
  72.         screen.addDDSGFC(self.top.getNextWidgetName(), gc.getFeatureInfo(self.iFeature).getButton(),
  73.             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 )
  74. #        screen.addDDSGFC(self.top.getNextWidgetName(), gc.getFeatureInfo(self.iFeature).getButton(), self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, WidgetTypes.WIDGET_GENERAL, self.iFeature, -1 )
  75.  
  76.         self.placeStats()
  77.  
  78.         self.placeSpecial()
  79.  
  80.         return
  81.  
  82.     def placeStats(self):
  83.     
  84.         screen = self.top.getScreen()
  85.         
  86.         panelName = self.top.getNextWidgetName()
  87.         screen.addListBoxGFC(panelName, "", self.X_STATS_PANE, self.Y_STATS_PANE, self.W_STATS_PANE, self.H_STATS_PANE, TableStyles.TABLE_STYLE_EMPTY)
  88. #        screen.addPanel( panelName, "", "", true, true, self.X_STATS_PANE, self.Y_STATS_PANE, self.W_STATS_PANE, self.H_STATS_PANE, PanelStyles.PANEL_STYLE_EMPTY )
  89.         screen.enableSelect(panelName, False)
  90.         
  91.         for k in range(YieldTypes.NUM_YIELD_TYPES):
  92.             iYieldChange = gc.getFeatureInfo(self.iFeature).getYieldChange(k)
  93.             if (iYieldChange != 0):                                        
  94.                 if (iYieldChange > 0):
  95.                     sign = "+"
  96.                 else:
  97.                     sign = ""
  98.                     
  99.                 szYield = (u"%s: %s%i " % (gc.getYieldInfo(k).getDescription().upper(), sign, iYieldChange))
  100.  
  101.                 screen.appendListBoxString(panelName, u"<font=4>" + szYield + (u"%c" % gc.getYieldInfo(k).getChar()) + u"</font>", WidgetTypes.WIDGET_GENERAL, 0, 0, CvUtil.FONT_LEFT_JUSTIFY)
  102. #                screen.attachTextGFC(panelName, "", szYield + (u"%c" % gc.getYieldInfo(k).getChar()), FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
  103.  
  104.     def placeSpecial(self):
  105.         
  106.         screen = self.top.getScreen()
  107.         
  108.         panelName = self.top.getNextWidgetName()
  109.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_SPECIAL_ABILITIES", ()), "", true, false, self.X_SPECIAL_PANE, self.Y_SPECIAL_PANE, self.W_SPECIAL_PANE, self.H_SPECIAL_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  110.         
  111.         listName = self.top.getNextWidgetName()
  112.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  113.         screen.enableSelect(listName, False)
  114.         
  115.         szSpecialText = CyGameTextMgr().getFeatureHelp(self.iFeature, True)
  116.         splitText = string.split( szSpecialText, "\n" )
  117.         for special in splitText:
  118.             if len( special ) != 0:
  119.                 screen.appendListBoxString( listName, special, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  120.                 
  121.     def placeLinks(self):
  122.  
  123.         screen = self.top.getScreen()
  124.                 
  125.         screen.clearListBoxGFC(self.top.LIST_ID)
  126.         
  127.         # sort resources alphabetically
  128.         listSorted=[(0,0)]*gc.getNumFeatureInfos()
  129.         for j in range(gc.getNumFeatureInfos()):
  130.             listSorted[j] = (gc.getFeatureInfo(j).getDescription(), j)
  131.         listSorted.sort()    
  132.             
  133.         iSelected = 0
  134.         i = 0
  135.         for iI in range(gc.getNumFeatureInfos()):
  136.             if (not gc.getFeatureInfo(listSorted[iI][1]).isGraphicalOnly()):
  137.                 screen.appendListBoxString( self.top.LIST_ID, listSorted[iI][0], WidgetTypes.WIDGET_PEDIA_JUMP_TO_FEATURE, listSorted[iI][1], 0, CvUtil.FONT_LEFT_JUSTIFY )
  138.                 if listSorted[iI][1] == self.iFeature:
  139.                     iSelected = i
  140.                 i += 1
  141.                     
  142.         screen.setSelectedListBoxStringGFC(self.top.LIST_ID, iSelected)
  143.                 
  144.     # Will handle the input for this screen...
  145.     def handleInput (self, inputClass):
  146.         return 0
  147.  
  148.  
  149.