Go to the documentation of this file.00001 '''
00002 ProficienciesWindow()
00003
00004 implements the proficiencies interface for players: display current points distribution and totals
00005 and facilitate assignment of unspent points
00006
00007 Anoria (c) Gsk 2010
00008 '''
00009
00010 import BigWorld
00011 import GUI
00012
00013 import AnGUI
00014 from Listener import Listener
00015 from config import request
00016 from config.consts import PROFICIENCY_CODES
00017
00018 class ProficienciesWindow(Listener):
00019
00020 def __init__(self):
00021 Listener.__init__(self, self.__class__)
00022 self.Gui = GUI.load("gui/proficiencies.gui")
00023 self.totalPoints = 0
00024 self.unspentPoints = 0
00025 self.proficienciesList = []
00026
00027
00028 self.edits = False
00029 self.unspentPointsEdit = 0
00030 self.proficienciesListEdit = []
00031
00032 self.choices = {}
00033 self.setListen()
00034
00035 def setListen(self):
00036 ''' listen to all our child components that can generate AnGUI events '''
00037 index = 0
00038 for name, child in self.Gui.children:
00039 child.script.name = name
00040 if hasattr(child.script, 'canActivate'):
00041 if child.script.canActivate:
00042 AnGUI.service.addListener(self, AnGUI.GuiEvent(child.script.name, 'ACTIVATE'))
00043 if name[0:2] == 'p_':
00044 self.choices[name] = index
00045 index += 1
00046
00047 def updateTitle(self, edit=False):
00048 ''' update the points display in the window title bar '''
00049 if edit:
00050 unspentPoints = self.unspentPointsEdit
00051 else:
00052 unspentPoints = self.unspentPoints
00053
00054 self.Gui.title.text.text = "Proficiencies %d/%d" % (unspentPoints, self.totalPoints)
00055
00056 def resetEdits(self):
00057 ''' reset all changes the player has done in the edit state '''
00058 if not self.edits: return
00059 self.edits = True
00060 self.updateProficiencies(self.proficienciesList)
00061 self.proficienciesListEdit = self.proficienciesList[:]
00062 self.unspentPointsEdit = self.unspentPoints
00063 self.updateTitle()
00064 self.setFocus(True)
00065
00066
00067 def handleGuiEvent(self, guiEvent):
00068
00069 name = guiEvent.name
00070 if name == 'button_accept':
00071 self.setVisible(False)
00072 self.unspentPoints = self.unspentPointsEdit
00073 player = BigWorld.player()
00074 player.unspentProficiencyPoints = self.unspentPoints
00075
00076 list = []
00077 i = 0
00078
00079 for n in self.proficienciesListEdit:
00080 delta = n - self.proficienciesList[i]
00081
00082 i += 1
00083 if delta > 0:
00084 list.append(delta)
00085 else:
00086 list.append(0)
00087
00088 self.proficienciesList = self.proficienciesListEdit[:]
00089 player.base.rpcClientRequest(request.REQ_POINTS_ASSIGN, list)
00090 elif name == 'button_cancel':
00091 self.resetEdits()
00092 self.setVisible(False)
00093 elif name in self.choices.keys():
00094 self.doPointAssign(name)
00095
00096 def doPointAssign(self, proficiencyName):
00097 if not self.unspentPointsEdit > 0: return
00098 self.edits = True
00099 proficiencyCode = PROFICIENCY_CODES.index(proficiencyName)
00100 self.proficienciesListEdit[proficiencyCode] += 1
00101 self.unspentPointsEdit -= 1
00102 self.setFocus(True)
00103 self.updateTitle(edit=True)
00104 index = self.choices[proficiencyName]
00105 component = self.Gui.children[index][1]
00106 component.text.text = '%d/5' % (self.proficienciesListEdit[proficiencyCode])
00107
00108 def updateProficiencies(self, proficienciesList):
00109 ''' update all the proficieny entries in the window to match the passed in proficienciesList '''
00110 i=0
00111 for val in proficienciesList:
00112 name = PROFICIENCY_CODES[i]
00113 componentIndex = self.choices[name]
00114 component = self.Gui.children[componentIndex][1]
00115 component.text.text = '%d/5' % (val)
00116 i += 1
00117
00118 def setPoints(self, unspent, total, list=None):
00119 ''' used by avatar to update us '''
00120 self.unspentPoints = unspent
00121 self.unspentPointsEdit = unspent
00122 self.totalPoints = total
00123 if list != None:
00124 self.proficienciesList = list[:]
00125 self.proficienciesListEdit = list[:]
00126 self.updateTitle()
00127 self.setFocus(True)
00128
00129 def setFocus(self, state):
00130 ''' @param state: enable or disable focus of child components
00131 @return None
00132
00133 enable or disable child components' highlight and clickable states
00134 this finds all clickable components and enables those that would be valid for the
00135 player to select given his current proficiency point numbers (unspent/total) '''
00136
00137
00138 if not self.unspentPointsEdit > 0:
00139 state = False
00140
00141
00142 maxRanks = 2 + self.totalPoints/4
00143
00144 for name, child in self.Gui.children:
00145 if name in PROFICIENCY_CODES:
00146 proficiencyCode = PROFICIENCY_CODES.index(name)
00147 else:
00148 continue
00149
00150
00151 curRanks = self.proficienciesListEdit[proficiencyCode]
00152 if hasattr(child.script, 'canActivate'):
00153 if child.script.canActivate:
00154 if curRanks < maxRanks:
00155 child.focus = state
00156 else:
00157 child.focus = False
00158 if hasattr(child.script, 'canHighlight'):
00159 if child.script.canHighlight:
00160 if curRanks < maxRanks:
00161 child.crossFocus = state
00162 else:
00163 child.crossFocus = False
00164
00165
00166 def toggleActive(self):
00167 if self.Gui.visible:
00168 self.setVisible(False)
00169 self.resetEdits()
00170 else:
00171 self.setVisible(True)
00172
00173 def setVisible(self, state):
00174 self.Gui.visible = state
00175
00176 def setXpBar(self, value):
00177 clipper = self.Gui.xp_bar.clipper
00178 clipper.value = value