home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Dema / Civilization4 / data1.cab / Civ4DemoComponent / Assets / Python / Screens / CvPediaPromotion.py < prev    next >
Encoding:
Python Source  |  2005-11-09  |  8.2 KB  |  206 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 CvPediaPromotion:
  15.     "Civilopedia Screen for Promotions"
  16.  
  17.     def __init__(self, main):
  18.         self.iPromotion = -1
  19.         self.top = main
  20.     
  21.         self.BUTTON_SIZE = 46
  22.         
  23.         self.X_UNIT_PANE = 50
  24.         self.Y_UNIT_PANE = 80
  25.         self.W_UNIT_PANE = 250
  26.         self.H_UNIT_PANE = 210
  27.  
  28.         self.X_ICON = 98
  29.         self.Y_ICON = 110
  30.         self.W_ICON = 150
  31.         self.H_ICON = 150
  32.         self.ICON_SIZE = 64
  33.  
  34.         self.X_PREREQ_PANE = 330
  35.         self.Y_PREREQ_PANE = 60
  36.         self.W_PREREQ_PANE = 420
  37.         self.H_PREREQ_PANE = 110
  38.  
  39.         self.X_LEADS_TO_PANE = 330
  40.         self.Y_LEADS_TO_PANE = 180
  41.         self.W_LEADS_TO_PANE = self.W_PREREQ_PANE
  42.         self.H_LEADS_TO_PANE = 110
  43.                 
  44.         self.X_SPECIAL_PANE = 330
  45.         self.Y_SPECIAL_PANE = 294
  46.         self.W_SPECIAL_PANE = self.W_PREREQ_PANE
  47.         self.H_SPECIAL_PANE = 380
  48.  
  49.         self.X_UNIT_GROUP_PANE = 50
  50.         self.Y_UNIT_GROUP_PANE = 294
  51.         self.W_UNIT_GROUP_PANE = 250
  52.         self.H_UNIT_GROUP_PANE = 380
  53.         self.DY_UNIT_GROUP_PANE = 25
  54. #        self.ITEMS_MARGIN = 18
  55. #        self.ITEMS_SEPARATION = 2
  56.  
  57.     # Screen construction function
  58.     def interfaceScreen(self, iPromotion):    
  59.             
  60.         self.iPromotion = iPromotion
  61.     
  62.         self.top.deleteAllWidgets()                        
  63.                             
  64.         screen = self.top.getScreen()
  65.         
  66.         bNotActive = (not screen.isActive())
  67.         if bNotActive:
  68.             self.top.setPediaCommonWidgets()
  69.  
  70.         # Header...
  71.         szHeader = u"<font=4b>" + gc.getPromotionInfo(self.iPromotion).getDescription().upper() + u"</font>"
  72.         szHeaderId = self.top.getNextWidgetName()
  73.         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)
  74.         
  75.         # Top
  76.         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_PROMOTION, -1)
  77.  
  78.         if self.top.iLastScreen    != CvScreenEnums.PEDIA_PROMOTION or bNotActive:        
  79.             self.placeLinks()
  80.             self.top.iLastScreen = CvScreenEnums.PEDIA_PROMOTION
  81.             
  82.         # Icon
  83.         screen.addPanel( self.top.getNextWidgetName(), "", "", False, False,
  84.             self.X_UNIT_PANE, self.Y_UNIT_PANE, self.W_UNIT_PANE, self.H_UNIT_PANE, PanelStyles.PANEL_STYLE_BLUE50)
  85.         screen.addPanel(self.top.getNextWidgetName(), "", "", false, false,
  86.             self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, PanelStyles.PANEL_STYLE_MAIN)
  87.         screen.addDDSGFC(self.top.getNextWidgetName(), gc.getPromotionInfo(self.iPromotion).getButton(),
  88.             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 )
  89. #        screen.addDDSGFC(self.top.getNextWidgetName(), gc.getPromotionInfo(self.iPromotion).getButton(), self.X_ICON, self.Y_ICON, self.W_ICON, self.H_ICON, WidgetTypes.WIDGET_GENERAL, self.iPromotion, -1 )
  90.  
  91.         # Place Required promotions
  92.         self.placePrereqs()
  93.  
  94.         # Place Allowing promotions
  95.         self.placeLeadsTo()
  96.                 
  97.         # Place the Special abilities block
  98.         self.placeSpecial()
  99.         
  100.         self.placeUnitGroups()
  101.             
  102.  
  103.     # Place Leads To...
  104.     def placeLeadsTo(self):
  105.  
  106.         screen = self.top.getScreen()
  107.  
  108.         panelName = self.top.getNextWidgetName()
  109.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_LEADS_TO", ()), "", false, true,
  110.                  self.X_LEADS_TO_PANE, self.Y_LEADS_TO_PANE, self.W_LEADS_TO_PANE, self.H_LEADS_TO_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  111.         
  112.         screen.attachLabel(panelName, "", "  ")
  113.         
  114.         for j in range(gc.getNumPromotionInfos()):
  115.             iPrereq = gc.getPromotionInfo(j).getPrereqOrPromotion1()
  116.             if (iPrereq == self.iPromotion):
  117.                 screen.attachImageButton( panelName, "", gc.getPromotionInfo(j).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_PROMOTION, j, 1, False )
  118.             iPrereq = gc.getPromotionInfo(j).getPrereqOrPromotion2()
  119.             if (iPrereq == self.iPromotion):
  120.                 screen.attachImageButton( panelName, "", gc.getPromotionInfo(j).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_PROMOTION, j, 1, False )
  121.                 
  122.     # Place prereqs...
  123.     def placePrereqs(self):
  124.  
  125.         screen = self.top.getScreen()
  126.         
  127.         panelName = self.top.getNextWidgetName()
  128.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_REQUIRES", ()), "", false, true,
  129.                  self.X_PREREQ_PANE, self.Y_PREREQ_PANE, self.W_PREREQ_PANE, self.H_PREREQ_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  130.         
  131.         screen.attachLabel(panelName, "", "  ")
  132.  
  133.         ePromo = gc.getPromotionInfo(self.iPromotion).getPrereqOrPromotion1()
  134.         if (ePromo > -1):
  135.             screen.attachImageButton( panelName, "", gc.getPromotionInfo(ePromo).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_PROMOTION, ePromo, 1, False )
  136.  
  137.             ePromo = gc.getPromotionInfo(self.iPromotion).getPrereqOrPromotion2()
  138.             if (ePromo > -1):
  139.                     screen.attachTextGFC(panelName, "", localText.getText("TXT_KEY_OR", ()), FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1)
  140.                 screen.attachImageButton( panelName, "", gc.getPromotionInfo(ePromo).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_PROMOTION, ePromo, 1, False )
  141.                                 
  142.         eTech = gc.getPromotionInfo(self.iPromotion).getTechPrereq()
  143.         if (eTech > -1):
  144.             screen.attachImageButton( panelName, "", gc.getTechInfo(eTech).getButton(), GenericButtonSizes.BUTTON_SIZE_CUSTOM, WidgetTypes.WIDGET_PEDIA_JUMP_TO_TECH, eTech, 1, False )        
  145.                         
  146.     def placeSpecial(self):
  147.  
  148.         screen = self.top.getScreen()
  149.         
  150.         panelName = self.top.getNextWidgetName()
  151.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_SPECIAL_ABILITIES", ()), "", true, false,
  152.                  self.X_SPECIAL_PANE, self.Y_SPECIAL_PANE, self.W_SPECIAL_PANE, self.H_SPECIAL_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  153.         
  154.         listName = self.top.getNextWidgetName()
  155.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  156.         screen.enableSelect(listName, False)
  157.         
  158.         szSpecialText = CyGameTextMgr().getPromotionHelp(self.iPromotion, True)
  159.         splitText = string.split( szSpecialText, "\n" )
  160.         for special in splitText:
  161.             if len( special ) != 0:
  162.                 screen.appendListBoxString( listName, special, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  163.  
  164.     def placeUnitGroups(self):
  165.         screen = self.top.getScreen()
  166.         
  167.         panelName = self.top.getNextWidgetName()
  168.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_PROMOTION_UNITS", ()), "", true, true,
  169.             self.X_UNIT_GROUP_PANE, self.Y_UNIT_GROUP_PANE, self.W_UNIT_GROUP_PANE, self.H_UNIT_GROUP_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  170.         
  171.         szTable = self.top.getNextWidgetName()
  172.         screen.addTableControlGFC(szTable, 1,
  173.             self.X_UNIT_GROUP_PANE + 10, self.Y_UNIT_GROUP_PANE + 40, self.W_UNIT_GROUP_PANE - 20, self.H_UNIT_GROUP_PANE - 50, False, False, 24, 24, TableStyles.TABLE_STYLE_EMPTY)
  174.         
  175.         i = 0
  176.         for iI in range(gc.getNumUnitCombatInfos()):
  177.             if (0 != gc.getPromotionInfo(self.iPromotion).getUnitCombat(iI)):
  178.                 iRow = screen.appendTableRow(szTable)
  179.                 screen.setTableText(szTable, 0, i, u"<font=4>" + gc.getUnitCombatInfo(iI).getDescription() + u"</font>", gc.getUnitCombatInfo(iI).getButton(), WidgetTypes.WIDGET_PEDIA_JUMP_TO_UNIT_COMBAT, iI, -1, CvUtil.FONT_LEFT_JUSTIFY)
  180.                 i += 1
  181.  
  182.     def placeLinks(self):
  183.  
  184.         screen = self.top.getScreen()
  185.                 
  186.         screen.clearListBoxGFC(self.top.LIST_ID)
  187.         
  188.         # sort techs alphabetically
  189.         listSorted=[(0,0)]*gc.getNumPromotionInfos()
  190.         for j in range(gc.getNumPromotionInfos()):
  191.             listSorted[j] = (gc.getPromotionInfo(j).getDescription(), j)
  192.         listSorted.sort()
  193.             
  194.         iSelected = 0
  195.         for iI in range(gc.getNumPromotionInfos()):
  196.             screen.appendListBoxString( self.top.LIST_ID, listSorted[iI][0], WidgetTypes.WIDGET_PEDIA_JUMP_TO_PROMOTION, listSorted[iI][1], 0, CvUtil.FONT_LEFT_JUSTIFY )
  197.             if listSorted[iI][1] == self.iPromotion:
  198.                 iSelected = iI            
  199.  
  200.         screen.setSelectedListBoxStringGFC(self.top.LIST_ID, iSelected)
  201.  
  202.     # Will handle the input for this screen...
  203.     def handleInput (self, inputClass):
  204.         return 0
  205.  
  206.