def __init__(self): DirectFrame.__init__(self, parent=base.a2dTopRight, pos=(-0.2235, 0.0, -0.457)) gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui.bam') self['image'] = gui.find('**/FriendsBox_Open') self.headingText = OnscreenText(text="", parent=self, pos=(0.01, 0.2), fg=(0.1, 0.1, 0.4, 1.0), scale=0.04) self.frameForNames = DirectScrolledList( frameSize=(0.0, 0.35, 0, 0.35), incButton_geom=(gui.find('**/FndsLst_ScrollUp'), gui.find('**/FndsLst_ScrollDN'), gui.find('**/FndsLst_ScrollUp_Rllvr'), gui.find('**/FndsLst_ScrollUp')), incButton_relief=None, incButton_hpr=(0, 0, 180), incButton_pos=(0.17, 0, -0.04), decButton_geom=(gui.find('**/FndsLst_ScrollUp'), gui.find('**/FndsLst_ScrollDN'), gui.find('**/FndsLst_ScrollUp_Rllvr'), gui.find('**/FndsLst_ScrollUp')), decButton_relief=None, decButton_pos=(0.17, 0, 0.395), pos=(-0.1625, 0.0, -0.27), parent=self, numItemsVisible=9, forceHeight=0.04, itemFrame_frameSize=(-0.15, 0.15, 0, -0.35), itemFrame_pos=(0, 0, 0.3275), itemFrame_relief=None, relief=None) self.fwdBtn = CIGlobals.makeDirectionalBtn(1, self, (0.17, 0.0, -0.38), command=self.doState) self.backBtn = CIGlobals.makeDirectionalBtn(0, self, (-0.15, 0.0, -0.38), command=self.doState) self.closeBtn = DirectButton(geom=CIGlobals.getCancelBtnGeom(), relief=None, parent=self, command=self.exitClicked) self.closeBtn.setPos(0.015, 0.0, -0.375) gui.removeNode() del gui self.hide() self.friends = {} self.onlineFriends = {} self.fsm = ClassicFSM.ClassicFSM('FriendsList', [ State.State('off', self.enterOff, self.exitOff), State.State('onlineFriendsList', self.enterOnlineFriendsList, self.exitOnlineFriendsList), State.State('allFriendsList', self.enterAllFriendsList, self.exitAllFriendsList) ], 'off', 'off') self.fsm.enterInitialState() self.accept('gotFriendsList', self.handleFriendsList)
def __init__(self, parent, options, pos=(0, 0, 0), command=None, widgetName="", choiceTextScale=0.08, desc="", settingKeyName=None, mode=AUTO, requirement=None): """ Generates an ordered choice widget with the specified parameters. Parameters: parent: Pretty much self-explanatory, this is the parent of the widget. If an object with a `book` attribute is passed in, it will use that instead. options: A list of options that the user can select with the GUI. pos: Pretty much self-explanatory. command: Function that should be executed whenever a game setting is updated. The newly saved choice is passed to the specified function. widgetName: The label shown to the left of the widget identifying what the widget is for. choiceTextScale: The scale of the text which displays which option the user has currently selected. desc: Optional description of what the choices displayed by this widget are for. settingKeyName: The name of the key inside of the game settings map that this choice widget works with. This MUST be set if trying to simulate a game setting changer widget. mode: This is the kind of widget this is going to be. Use one of the following: - AUTO: - The system will attempt to figure out what the type of choices are available. * 2 options automatically looks like a true/false widget * - MULTICHOICE: - This overrides the system in case there are two options but true/false functionality isn't wanted. - DEGREE: - This means that the choice widget deals with x in front of some sort of degree value that should - be stripped away when selecting choices. This is used for the antialiasing choice widget. """ self.requirement = requirement self.options = options self.command = command self.currentChoiceIndex = 0 self.origChoice = None self.userChoice = None self.settingKeyName = settingKeyName self.mode = mode # Let's update the options if we specified a setting key name. if self.settingKeyName and len(self.settingKeyName) > 0: settingsMgr = CIGlobals.getSettingsMgr() settingInst = settingsMgr.getSetting(self.settingKeyName) if not settingInst: raise ValueError("Setting \"{0}\" could not be found!".format( self.settingKeyName)) else: self.options = settingInst.getOptions() desc = settingInst.getDescription() widgetParent = parent if hasattr(parent, 'book'): widgetParent = parent.book DirectFrame.__init__(self, parent=widgetParent, pos=pos) bg = loader.loadModel('phase_3/models/gui/ChatPanel.bam') self.selFrame = DirectFrame(pos=(0.4, 0, 0), frameColor=(1.0, 1.0, 1.0, 1.0), image=bg, relief=None, image_scale=(0.22, 0.11, 0.11), image_pos=(-0.107, 0.062, 0.062), parent=self) self.choiceText = OnscreenText(text="Hello!", align=TextNode.ACenter, parent=self.selFrame, pos=(0, -0.01), scale=choiceTextScale) self.fwdBtn = CIGlobals.makeDirectionalBtn(1, self.selFrame, pos=(0.2, 0, 0), command=self.__goFwd) self.bckBtn = CIGlobals.makeDirectionalBtn(0, self.selFrame, pos=(-0.2, 0, 0), command=self.__goBck) self.lbl = OnscreenText(text=widgetName + ":", pos=(-0.7, 0, 0), align=TextNode.ALeft, parent=self) if len(desc) > 0: self.desc = OnscreenText(text=desc, pos=(0.0, -0.1, 0.0), parent=self.selFrame, scale=0.05, bg=DESC_BACKGROUND_COLOR, mayChange=False) self.desc.setBin('gui-popup', 40) self.desc.hide() # Let's bind our events on the selection frame for the description. self.selFrame['state'] = DGG.NORMAL self.selFrame.bind(DGG.ENTER, self.__setDescVisible, extraArgs=[True]) self.selFrame.bind(DGG.EXIT, self.__setDescVisible, extraArgs=[False]) self.initialiseoptions(ChoiceWidget) self.reset() bg.detachNode() del bg