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

  1. ## Sid Meier's Civilization 4
  2. ## Copyright Firaxis Games 2005
  3. ##
  4. ## Alex Mantzaris / Jesse Smith 09-2005
  5. from CvPythonExtensions import *
  6. import CvUtil
  7. import ScreenInput
  8. import CvScreenEnums
  9. import random
  10. import string
  11.  
  12. # globals
  13. gc = CyGlobalContext()
  14. ArtFileMgr = CyArtFileMgr()
  15. localText = CyTranslator()
  16.  
  17. class CvPediaLeader:
  18.     "Civilopedia Screen for Leaders"
  19.  
  20.     def __init__(self, main):
  21.         self.iLeader = -1
  22.         self.top = main
  23.                 
  24.         self.X_LEADERHEAD_PANE = 20
  25.         self.Y_LEADERHEAD_PANE = 65
  26.         self.W_LEADERHEAD_PANE = 370
  27.         self.H_LEADERHEAD_PANE = 390
  28.                 
  29.         self.W_LEADERHEAD = 320
  30.         self.H_LEADERHEAD = 384
  31.         self.X_LEADERHEAD = self.X_LEADERHEAD_PANE + ((self.W_LEADERHEAD_PANE - self.W_LEADERHEAD) / 2)
  32.         self.Y_LEADERHEAD = self.Y_LEADERHEAD_PANE + ((self.H_LEADERHEAD_PANE - self.H_LEADERHEAD) / 2) + 3 # Fudge factor
  33.         
  34.         self.X_HISTORY = self.X_LEADERHEAD_PANE + self.W_LEADERHEAD_PANE + 20
  35.         self.Y_HISTORY = self.Y_LEADERHEAD_PANE + 85
  36.         self.W_HISTORY = 370
  37.         self.H_HISTORY = 550
  38.         
  39.         self.X_TRAITS = 20
  40.         self.Y_TRAITS = self.Y_LEADERHEAD_PANE + self.H_LEADERHEAD_PANE + 5
  41.         self.W_TRAITS = self.W_LEADERHEAD_PANE
  42.         self.H_TRAITS = 240
  43.                 
  44.         self.X_CIV = self.X_LEADERHEAD_PANE + self.W_LEADERHEAD_PANE + 20
  45.         self.Y_CIV = self.Y_LEADERHEAD_PANE + 15
  46.         self.W_CIV = 64
  47.         self.H_CIV = 64
  48.  
  49.         self.X_CIVIC = self.X_HISTORY + self.W_CIV + 10
  50.         self.Y_CIVIC = self.Y_LEADERHEAD_PANE - 5
  51.         self.W_CIVIC = self.W_HISTORY - self.W_CIV - 10
  52.         self.H_CIVIC = 80
  53.  
  54.     # Screen construction function
  55.     def interfaceScreen(self, iLeader):    
  56.             
  57.         self.iLeader = iLeader
  58.     
  59.         self.top.deleteAllWidgets()                        
  60.                             
  61.         screen = self.top.getScreen()
  62.         
  63.         bNotActive = (not screen.isActive())
  64.         if bNotActive:
  65.             self.top.setPediaCommonWidgets()
  66.  
  67.         # Header...
  68.         szHeader = u"<font=4b>" + gc.getLeaderHeadInfo(self.iLeader).getDescription().upper() + u"</font>"
  69.         szHeaderId = self.top.getNextWidgetName()
  70.         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)
  71.         
  72.         # Top
  73.         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_LEADER, -1)
  74.  
  75.         if self.top.iLastScreen    != CvScreenEnums.PEDIA_LEADER or bNotActive:        
  76.             self.placeLinks()
  77.             self.top.iLastScreen = CvScreenEnums.PEDIA_LEADER
  78.         
  79.         # Leaderhead
  80.         leaderPanelWidget = self.top.getNextWidgetName()
  81.         screen.addPanel( leaderPanelWidget, "", "", true, true,
  82.                     self.X_LEADERHEAD_PANE, self.Y_LEADERHEAD_PANE, self.W_LEADERHEAD_PANE, self.H_LEADERHEAD_PANE, PanelStyles.PANEL_STYLE_BLUE50 )
  83.         self.leaderWidget = self.top.getNextWidgetName()
  84.         screen.addLeaderheadGFC(self.leaderWidget, self.iLeader, AttitudeTypes.ATTITUDE_PLEASED,
  85.                     self.X_LEADERHEAD, self.Y_LEADERHEAD, self.W_LEADERHEAD, self.H_LEADERHEAD, WidgetTypes.WIDGET_GENERAL, -1, -1)
  86.         
  87.         self.placeHistory()
  88.         self.placeCivic()
  89.         self.placeCiv()
  90.         self.placeTraits()
  91.                                                     
  92.     def placeCiv(self):
  93.         screen = self.top.getScreen()
  94.  
  95.         for iCiv in range(gc.getNumCivilizationInfos()):
  96.             civ = gc.getCivilizationInfo(iCiv)
  97.             if civ.isLeaders(self.iLeader):
  98.                 screen.setImageButton(self.top.getNextWidgetName(), civ.getButton(), self.X_CIV, self.Y_CIV, self.W_CIV, self.H_CIV, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIV, iCiv, 1)
  99.                                                     
  100.     def placeTraits(self):
  101.         screen = self.top.getScreen()
  102.         
  103.         panelName = self.top.getNextWidgetName()
  104.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_TRAITS", ()), "", true, false,
  105.                                  self.X_TRAITS, self.Y_TRAITS, self.W_TRAITS, self.H_TRAITS, PanelStyles.PANEL_STYLE_BLUE50 )
  106.                 
  107.         listName = self.top.getNextWidgetName()
  108.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  109.         screen.enableSelect(listName, False)
  110.         
  111.         szSpecialText = CyGameTextMgr().parseLeaderTraits(self.iLeader, -1, False, True)
  112.         splitText = string.split( szSpecialText, "\n" )
  113.         for special in splitText:
  114.             if len( special ) != 0:
  115.                 screen.appendListBoxString( listName, special, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  116.         
  117.     def placeCivic(self):        
  118.         screen = self.top.getScreen()
  119.         
  120.         panelName = self.top.getNextWidgetName()
  121.         screen.addPanel( panelName, localText.getText("TXT_KEY_PEDIA_FAV_CIVIC", ()), "", true, true,
  122.                                  self.X_CIVIC, self.Y_CIVIC, self.W_CIVIC, self.H_CIVIC, PanelStyles.PANEL_STYLE_BLUE50 )
  123.         
  124.         listName = self.top.getNextWidgetName()
  125.         screen.attachListBoxGFC( panelName, listName, "", TableStyles.TABLE_STYLE_EMPTY )
  126.         screen.enableSelect(listName, False)
  127.  
  128.         iCivic = gc.getLeaderHeadInfo(self.iLeader).getFavoriteCivic()
  129.         if (-1 != iCivic):
  130.             szCivicText = gc.getCivicInfo(iCivic).getDescription()
  131.             screen.appendListBoxString( listName, szCivicText, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY )
  132.  
  133.     def placeHistory(self):
  134.         screen = self.top.getScreen()
  135.  
  136.         panelName = self.top.getNextWidgetName()
  137.         screen.addPanel( panelName, "", "", true, true,
  138.             self.X_HISTORY, self.Y_HISTORY, self.W_HISTORY, self.H_HISTORY, PanelStyles.PANEL_STYLE_BLUE50 )
  139.         
  140.         historyTextName = self.top.getNextWidgetName()
  141.         CivilopediaText = gc.getLeaderHeadInfo(self.iLeader).getCivilopedia()
  142.         CivilopediaText = u"<font=2>" + CivilopediaText + u"</font>"
  143.         screen.attachMultilineText( panelName, historyTextName, CivilopediaText,
  144.             WidgetTypes.WIDGET_GENERAL,-1,-1, CvUtil.FONT_LEFT_JUSTIFY ) 
  145.  
  146.             
  147.     def placeLinks(self):
  148.         screen = self.top.getScreen()
  149.                 
  150.         screen.clearListBoxGFC(self.top.LIST_ID)
  151.  
  152.         # sort leaders alphabetically
  153.         rowListName=[(0,0)]*gc.getNumLeaderHeadInfos()
  154.         for j in range(gc.getNumLeaderHeadInfos()):
  155.             rowListName[j] = (gc.getLeaderHeadInfo(j).getDescription(), j)
  156.         rowListName.sort()    
  157.         
  158.         i = 0
  159.         iSelected = 0
  160.         for iI in range(gc.getNumLeaderHeadInfos()):
  161.             if gc.getLeaderHeadInfo(rowListName[iI][1]).getFavoriteCivic() != -1:
  162.                 screen.appendListBoxString(self.top.LIST_ID, rowListName[iI][0], WidgetTypes.WIDGET_PEDIA_JUMP_TO_LEADER, rowListName[iI][1], 0, CvUtil.FONT_LEFT_JUSTIFY)
  163.                 if rowListName[iI][1] == self.iLeader:
  164.                     iSelected = i
  165.                 i += 1
  166.         
  167.         screen.setSelectedListBoxStringGFC(self.top.LIST_ID, iSelected)
  168.         
  169.  
  170.     # Will handle the input for this screen...
  171.     def handleInput (self, inputClass):
  172.         if (inputClass.getData() == int(InputTypes.KB_RETURN) or inputClass.getData() == int(InputTypes.KB_ESCAPE)):
  173.             self.top.getScreen().hideScreen()
  174.             return 1
  175.         if (inputClass.getNotifyCode() == NotifyCode.NOTIFY_CLICKED):
  176.             if (inputClass.getFunctionName() == self.LEADER_WIDGET):
  177.                 if (inputClass.getFlags() & MouseFlags.MOUSE_LBUTTONUP):
  178.                     self.top.getScreen().performLeaderheadAction(self.LEADER_WIDGET, 0)
  179.         return 0
  180.  
  181.  
  182.