Ejemplo n.º 1
0
class StoryMenuBar(SogalForm):
    '''
    The menu in story mode
    '''


    def __init__(self):
        self.topdistance = 0.3
        self.rightdistance = 0.3
        #self.rightdistance = 2
        
        SogalForm.__init__(self,
                           fading = True, 
                           fading_position_offset = (0.5,0,0),
                           fading_duration = 0.3,
                           enableMask = True,
                           backgroundColor = (0,0,0,0.25))
        self.reparentTo(aspect2d,sort = 99)
        self._buttonbox = VLayout(parent = self,margin = 0.05)
        self._currentInterval = None
        
        self.resetPos() 
        
        self.bar = NodePath('menubar')
        self.bar.reparentTo(self)
        self.setTransparency(TransparencyAttrib.MAlpha)
        self.accept('window-event', self.resetPos)
    
    def focused(self):
        self.accept('mouse3', self.hide)
        self.accept('escape', self.hide)
        SogalForm.focused(self)
    
    def defocused(self):
        self.ignore('mouse3')
        self.ignore('escape')
        SogalForm.defocused(self)
        
    def resetPos(self,arg = None):
        aspect = base.getAspectRatio()  # @UndefinedVariable
        if aspect > 1:
            self.setPos(1*aspect-self.rightdistance,0,1-self.topdistance)
        elif aspect: 
            self.setPos(1-self.rightdistance,0,1-self.topdistance)
            
    def show(self):
        SogalForm.show(self)
       
    
    def hide(self):
        if self.hasFocus():
            self.removeFocus()
            SogalForm.hide(self)

    def destroy(self):
        SogalForm.destroy(self)
        
    def reloadTheme(self):
        for btn in self._buttonbox:
            di = base.getStyle('button')
            for key in di:
                btn[key] = di[key]
    
    def addButton(self,**args):
        '''Add a button and return it'''
        btn = DirectButton(parent = self.bar,**dict(base.getStyle()['button'], frameSize = BUTTON_SIZE,**args))  # @UndefinedVariable
        
        self._buttonbox.append(btn)
        #self.vbox.pack(btn)
        return btn

    
        
Ejemplo n.º 2
0
class SaveForm(SogalForm):
    '''
    Form of saving
    '''
    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self,
                           fading=True,
                           fading_duration=0.5,
                           enableMask=True,
                           backgroundColor=color_themes.ilia_bgColor)
        self.reparentTo(aspect2d, sort=102)
        self.frame = DirectScrolledFrame(
            parent=self,
            canvasSize=SAVE_CANVAS_SIZE,
            frameSize=FRAMESIZE,
            autoHideScrollBars=AUTO_HIDE_SCROLLBARS,
            **color_themes.ilia_frame)

        self.labels = []
        self.labelDict = {}
        self.vbox = VLayout(parent=self.frame.getCanvas(), margin=vspacing)
        hbox = None
        self.__dumped = None
        for i in range(1, MAX_SAVE + 1):
            fname = 'save' + str(i)
            head = str(i)
            label = SaveLoadLabel(command=self.save,
                                  always_enable=True,
                                  fileName=fname,
                                  head=head,
                                  extraArgs=[fname],
                                  style=color_themes.ilia_button)
            self.labels.append(label)
            self.labelDict[label.getFileName()] = label
            if not hbox:
                hbox = HLayout(margin=hspacing)
                self.vbox.append(hbox)
                hbox.append(label)
            else:
                hbox.append(label)
                hbox = None

    def roll(self, value):
        self.frame.verticalScroll.setValue(
            self.frame.verticalScroll.getValue() + value * SAVE_ROLL_SPEED)

    def setData(self, dumped, message):
        self.__dumped = dumped
        self.__message = message

    def reload(self):
        for label in self.labels:
            label.reload()

    def reloadMember(self, key):
        if self.labelDict.has_key(key):
            self.labelDict[key].reload()

    def save(self, fname):
        if self.labelDict[fname].getExists():
            ConfirmDialog(text='要覆盖吗?不覆盖吗?',
                          command=self.confirmedSave,
                          extraArgs=[fname],
                          style='ilia')
        else:
            self.confirmedSave(fname)

    def confirmedSave(self, fname):
        if not self.__dumped:
            return
        else:
            messenger.send('save_data', [self.__dumped, fname, self.__message])

    def focused(self):
        self.accept('mouse3', self.hide)
        self.accept('escape', self.hide)
        self.accept('wheel_up', self.roll, [-1.0])
        self.accept('wheel_down', self.roll, [1.0])
        self.accept('arrow_up-repeat', self.roll, [-1.0])
        self.accept('arrow_down-repeat', self.roll, [1.0])
        self.accept('arrow_up', self.roll, [-1.0])
        self.accept('arrow_down', self.roll, [1.0])
        self.accept('w-repeat', self.roll, [-1.0])
        self.accept('s-repeat', self.roll, [1.0])
        self.accept('w', self.roll, [-1.0])
        self.accept('s', self.roll, [1.0])

    def defocused(self):
        self.ignore('mouse3')
        self.ignore('escape')
        self.ignore('wheel_up')
        self.ignore('wheel_down')
        self.ignore('arrow_up-repeat')
        self.ignore('arrow_down-repeat')
        self.ignore('arrow_up')
        self.ignore('arrow_down')
        self.ignore('w-repeat')
        self.ignore('s-repeat')
        self.ignore('w')
        self.ignore('s')
Ejemplo n.º 3
0
class LoadForm(SogalForm):
    '''
    Form of saving
    '''
    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self,
                           fading=True,
                           fading_duration=0.5,
                           enableMask=True,
                           backgroundColor=color_themes.sirius_bgColor)
        self.reparentTo(aspect2d, sort=102)

        self.frame = DirectScrolledFrame(
            parent=self,
            canvasSize=LOAD_CANVAS_SIZE,
            frameSize=FRAMESIZE,
            autoHideScrollBars=AUTO_HIDE_SCROLLBARS,
            **color_themes.sirius_frame)

        self.labels = []
        self.labelDict = {}
        self.vbox = VLayout(parent=self.frame.getCanvas(), margin=vspacing)

        hbox = None
        self.__dumped = None

        pos2 = MAX_SAVE + runtime_data.MAX_QUICKSAVE
        pos3 = MAX_SAVE + runtime_data.MAX_QUICKSAVE + runtime_data.MAX_AUTOSAVE
        for i in range(1, pos3 + 1):
            if i <= MAX_SAVE:
                fname = 'save' + str(i)
                head = str(i)
            elif MAX_SAVE < i <= pos2:
                index = i - MAX_SAVE
                fname = 'quick_save' + str(index)
                head = 'Quick Save ' + str(index)
            elif pos2 < i <= pos3:
                index = i - pos2
                fname = 'auto_save' + str(index)
                head = 'Auto Save ' + str(index)

            label = SaveLoadLabel(command=self.load,
                                  always_enable=False,
                                  fileName=fname,
                                  head=head,
                                  extraArgs=[fname],
                                  style=color_themes.sirius_button)
            self.labels.append(label)
            self.labelDict[label.getFileName()] = label
            if not hbox:
                hbox = HLayout(margin=hspacing)
                self.vbox.append(hbox)
                hbox.append(label)
            else:
                hbox.append(label)
                hbox = None

    def roll(self, value):
        self.frame.verticalScroll.setValue(
            self.frame.verticalScroll.getValue() + value * LOAD_ROLL_SPEED)

    def setData(self, dumped, message):
        self.__dumped = dumped
        self.__message = message

    def reload(self):
        for label in self.labels:
            label.reload()

    def reloadMember(self, key):
        if self.labelDict.has_key(key):
            self.labelDict[key].reload()

    def load(self, fname):
        if base.isStarted():
            ConfirmDialog(text='读取进度吗?',
                          command=self.confirmedLoad,
                          style='sirius',
                          extraArgs=[fname])
        else:
            self.confirmedLoad(fname)

    def confirmedLoad(self, fname):
        messenger.send('load_data', [fname])
        self.hide()

    def focused(self):
        self.accept('mouse3', self.hide)
        self.accept('wheel_up', self.roll, [-1.0])
        self.accept('wheel_down', self.roll, [1.0])
        self.accept('arrow_up-repeat', self.roll, [-1.0])
        self.accept('arrow_down-repeat', self.roll, [1.0])
        self.accept('arrow_up', self.roll, [-1.0])
        self.accept('arrow_down', self.roll, [1.0])
        self.accept('w-repeat', self.roll, [-1.0])
        self.accept('s-repeat', self.roll, [1.0])
        self.accept('w', self.roll, [-1.0])
        self.accept('s', self.roll, [1.0])

    def defocused(self):
        self.ignore('mouse3')
        self.ignore('wheel_up')
        self.ignore('wheel_down')
        self.ignore('arrow_up-repeat')
        self.ignore('arrow_down-repeat')
        self.ignore('arrow_up')
        self.ignore('arrow_down')
        self.ignore('w-repeat')
        self.ignore('s-repeat')
        self.ignore('w')
        self.ignore('s')
Ejemplo n.º 4
0
class SogalDialog(SogalForm):
    '''
    A dialog that derived from SogalForm
    (Which contains a DirectDialog)
    '''
    def __init__(
            self,
            enableMask=True,  #NOTE THAT IT IS TRUE BY DEFAULT
            autoDestroy=True,
            sortType=0,  #0 for horizontal, 1 for vertical
            margin=0.2,
            textList=['OK', 'Cancel'],
            enablesList=None,
            command=None,
            frameSize=(-0.6, 0.6, -0.45, 0.45),
            buttonSize=BUTTON_SIZE,
            text='',
            textPos=(0, 0.2),
            startPos=(-0.4, 0, -0.2),
            extraArgs=[],
            style=None,
            fadeScreen=0.5,
            backgroundColor=None,
            **kwargs):
        if backgroundColor:
            bgColor = backgroundColor
        elif fadeScreen is not None:
            bgColor = (0, 0, 0, fadeScreen)
        else:
            bgColor = None

        SogalForm.__init__(self,
                           enableMask=enableMask,
                           backgroundColor=bgColor,
                           **kwargs)
        if enableMask:
            self.reparentTo(aspect2d, sort=1000)
        if not style:
            self.__style = base.getStyle()
        else:
            self.__style = color_themes.styles[style]

        self.__frame = DirectFrame(parent=self,
                                   frameSize=frameSize,
                                   **self.__style['hardframe'])
        self.__buttonList = []  #DirectButton(parent = self, s)
        self.__text = OnscreenText(parent=self,
                                   text=text,
                                   pos=textPos,
                                   **self.__style['text'])
        self.__command = command
        self.__autoDestroy = autoDestroy
        self._extraArgs = extraArgs

        if sortType == 0:
            self.__box = HLayout(margin=margin)
        else:
            self.__box = VLayout(margin=margin)
        self.__box.reparentTo(self)
        self.__box.setPos(startPos)

        for i in range(len(textList)):
            btn = DirectButton(text=textList[i],
                               command=self.buttonCommand(i),
                               frameSize=buttonSize,
                               **self.__style['button'])
            self.__buttonList.append(btn)
            self.__box.append(btn)

        if enablesList:
            for i in range(len(enablesList)):
                if i >= len(self.__buttonList):
                    break
                if enablesList[i]:
                    self.__buttonList[i]['state'] = DGG.NORMAL
                else:
                    self.__buttonList[i]['state'] = DGG.DISABLED

        self.show()

    def buttonCommand(self, i):
        commandindex = i

        def process():
            if self.__command:
                self.__command(commandindex, *self._extraArgs)
            if self.__autoDestroy:
                self.close()

        return process

    def close(self):
        for btn in self.__buttonList:
            btn['state'] = DGG.DISABLED
        if self._getFading():
            seq = Sequence(
                Func(self.hide),
                Wait(self._getFadingDuration() + 2),
                Func(self.destroy),
            )
            seq.start()
        else:
            self.destroy()

    def destroy(self):
        for btn in self.__buttonList:
            btn.destroy()
        self.__frame.destroy()
        self.__box.removeNode()
        SogalForm.destroy(self)
Ejemplo n.º 5
0
class StoryMenuBar(SogalForm):
    '''
    The menu in story mode
    '''
    def __init__(self):
        self.topdistance = 0.3
        self.rightdistance = 0.3
        #self.rightdistance = 2

        SogalForm.__init__(self,
                           fading=True,
                           fading_position_offset=(0.5, 0, 0),
                           fading_duration=0.3,
                           enableMask=True,
                           backgroundColor=(0, 0, 0, 0.25))
        self.reparentTo(aspect2d, sort=99)
        self._buttonbox = VLayout(parent=self, margin=0.05)
        self._currentInterval = None

        self.resetPos()

        self.bar = NodePath('menubar')
        self.bar.reparentTo(self)
        self.setTransparency(TransparencyAttrib.MAlpha)
        self.accept('window-event', self.resetPos)

    def focused(self):
        self.accept('mouse3', self.hide)
        self.accept('escape', self.hide)
        SogalForm.focused(self)

    def defocused(self):
        self.ignore('mouse3')
        self.ignore('escape')
        SogalForm.defocused(self)

    def resetPos(self, arg=None):
        aspect = base.getAspectRatio()  # @UndefinedVariable
        if aspect > 1:
            self.setPos(1 * aspect - self.rightdistance, 0,
                        1 - self.topdistance)
        elif aspect:
            self.setPos(1 - self.rightdistance, 0, 1 - self.topdistance)

    def show(self):
        SogalForm.show(self)

    def hide(self):
        if self.hasFocus():
            self.removeFocus()
            SogalForm.hide(self)

    def destroy(self):
        SogalForm.destroy(self)

    def reloadTheme(self):
        for btn in self._buttonbox:
            di = base.getStyle('button')
            for key in di:
                btn[key] = di[key]

    def addButton(self, **args):
        '''Add a button and return it'''
        btn = DirectButton(parent=self.bar,
                           **dict(base.getStyle()['button'],
                                  frameSize=BUTTON_SIZE,
                                  **args))  # @UndefinedVariable

        self._buttonbox.append(btn)
        #self.vbox.pack(btn)
        return btn
Ejemplo n.º 6
0
class MainMenu(SogalForm):
    '''
    main menu class
    '''
    def __init__(self, entry='ifselectionjumptest'):
        '''
        Constructor
        '''
        self.entry = entry
        self.closed = True

        SogalForm.__init__(self,
                           fading=True,
                           fading_duration=1.0,
                           backgroundImage=None,
                           backgroundColor=(0, 0, 0, 1),
                           enableMask=True,
                           hiddenFunc=self.closedFunc,
                           shownFunc=self.openedFunc)

        self.addButtonBar()

        self.fadinglock = Lock(
        )  #This lock is to prevent open or close failure when the main menu is on fading

    def addButtonBar(self):
        self.bar = VLayout(margin=0.1)
        self.bar.reparentTo(self)

    def addButtons(self):
        '''
        override this if you want custom buttons
        '''
        #TODO:Continue Button 注意继续的位置可能是从硬盘上读入的也可能是从游戏中返回标题画面的 也有可能是在游戏正常结束之后所以没有Continue数据
        self.addButton(text='New Game',
                       state=DGG.NORMAL,
                       command=self._startGame)
        self.addButton(text='Load', state=DGG.NORMAL, command=self._load)
        self.addButton(text='Options', state=DGG.NORMAL, command=self._config)
        #TODO:Gallery Button
        self.addButton(text='Exit', state=DGG.NORMAL, command=self._exit)

    def close(self):
        '''Called by SogalBase. Do something and hide, you will need it if you want a more complex main menu'''
        self.fadinglock.acquire()

        if self.closed:
            return
        SogalForm.hide(self)
        self.closed = True
        if self.bar:
            for btn in self.bar:
                btn['state'] = DGG.DISABLED

    def open(self):
        '''Called by SogalBase. Do something and show, you will need it if you want a more complex main menu'''
        self.fadinglock.acquire()

        if not self.closed:
            return
        SogalForm.show(self)
        self.addButtons()
        self.closed = False

    def show(self):
        #redirect show/hide to open/close
        self.open()

    def hide(self):
        #redirect show/hide to open/close
        self.close()

    def closedFunc(self):
        self.cleanup()
        self.fadinglock.release()

    def cleanup(self):
        for btn in self.bar:
            btn.destroy()
        self.bar.removeNode()
        self.addButtonBar()

    def openedFunc(self):
        self.fadinglock.release()

    def addButton(self, **args):
        '''Add a button and return it'''
        btn = DirectButton(**dict(base.getStyle()['mainMenuButton'],
                                  frameSize=BUTTON_SIZE,
                                  **args))  # @UndefinedVariable

        self.bar.append(btn)
        #self.vbox.pack(btn)
        return btn

    def _startGame(self, scene=None):
        if self.closed:
            return
        if not scene:
            messenger.send('start_game', [self.entry])
        else:
            messenger.send('start_game', [scene])

    def _load(self):
        if self.closed:
            return
        messenger.send('load_game')

    def _exit(self):
        if self.closed:
            return
        messenger.send('exit_game')

    def _config(self):
        messenger.send('config_form')
Ejemplo n.º 7
0
class MainMenu(SogalForm):
    '''
    main menu class
    '''



    
    
    def __init__(self, entry = 'ifselectionjumptest'):
        '''
        Constructor
        '''
        self.entry = entry
        self.closed = True
        
        SogalForm.__init__(self, fading = True, fading_duration = 1.0, backgroundImage = None, backgroundColor = (0,0,0,1), 
                           enableMask = True,
                           hiddenFunc = self.closedFunc, shownFunc = self.openedFunc)
        

        self.addButtonBar()
        
        self.fadinglock = Lock()        #This lock is to prevent open or close failure when the main menu is on fading

        
    def addButtonBar(self):
        self.bar = VLayout(margin= 0.1)
        self.bar.reparentTo(self)        
        


    
    
    def addButtons(self):
        '''
        override this if you want custom buttons
        '''
        #TODO:Continue Button 注意继续的位置可能是从硬盘上读入的也可能是从游戏中返回标题画面的 也有可能是在游戏正常结束之后所以没有Continue数据
        self.addButton(text = 'New Game', state = DGG.NORMAL, command = self._startGame)
        self.addButton(text = 'Load', state = DGG.NORMAL, command = self._load)
        self.addButton(text = 'Options', state = DGG.NORMAL, command = self._config)
        #TODO:Gallery Button
        self.addButton(text = 'Exit', state = DGG.NORMAL, command = self._exit)       

            
    def close(self):
        '''Called by SogalBase. Do something and hide, you will need it if you want a more complex main menu'''
        self.fadinglock.acquire()
        
        if self.closed:
            return
        SogalForm.hide(self)
        self.closed = True
        if self.bar:
            for btn in self.bar:
                btn['state'] = DGG.DISABLED
        
    def open(self):
        '''Called by SogalBase. Do something and show, you will need it if you want a more complex main menu'''
        self.fadinglock.acquire()
        
        if not self.closed:
            return
        SogalForm.show(self)
        self.addButtons()
        self.closed = False
    
    def show(self):
        #redirect show/hide to open/close
        self.open()
    
    def hide(self):
        #redirect show/hide to open/close
        self.close()
        
    def closedFunc(self):
        self.cleanup()
        self.fadinglock.release()
    
    def cleanup(self):
        for btn in self.bar:
            btn.destroy()
        self.bar.removeNode()
        self.addButtonBar()
    
    def openedFunc(self):
        self.fadinglock.release()
        
    def addButton(self,**args):
        '''Add a button and return it'''
        btn = DirectButton(**dict(base.getStyle()['mainMenuButton'], frameSize = BUTTON_SIZE,**args))  # @UndefinedVariable
        
        self.bar.append(btn)
        #self.vbox.pack(btn)
        return btn
        
    def _startGame(self, scene = None):
        if self.closed:
            return
        if not scene:
            messenger.send('start_game', [self.entry])
        else:
            messenger.send('start_game', [scene])
            
    def _load(self):
        if self.closed:
            return
        messenger.send('load_game')
        
    def _exit(self):
        if self.closed:
            return
        messenger.send('exit_game')
        
    def _config(self):
        messenger.send('config_form')
Ejemplo n.º 8
0
class LoadForm(SogalForm):
    '''
    Form of saving
    '''

    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self, fading = True, fading_duration = 0.5, enableMask = True,backgroundColor=color_themes.sirius_bgColor)
        self.reparentTo(aspect2d,sort = 102)

        self.frame = DirectScrolledFrame(parent = self, canvasSize = LOAD_CANVAS_SIZE, 
                                         frameSize = FRAMESIZE, 
                                         autoHideScrollBars = AUTO_HIDE_SCROLLBARS,
                                         **color_themes.sirius_frame)
 
        self.labels = []
        self.labelDict = {}
        self.vbox = VLayout(parent = self.frame.getCanvas(), margin = vspacing)
        
        hbox = None
        self.__dumped = None
        
        pos2 = MAX_SAVE + runtime_data.MAX_QUICKSAVE
        pos3 = MAX_SAVE + runtime_data.MAX_QUICKSAVE + runtime_data.MAX_AUTOSAVE
        for i in range(1,  pos3 + 1):
            if i <= MAX_SAVE:
                fname = 'save' + str(i)
                head = str(i)
            elif MAX_SAVE < i <= pos2:
                index = i - MAX_SAVE
                fname = 'quick_save' + str(index)
                head = 'Quick Save ' + str(index)
            elif pos2 < i <= pos3:
                index = i - pos2
                fname = 'auto_save' + str(index)
                head = 'Auto Save ' + str(index)
                
            label = SaveLoadLabel(command = self.load, always_enable = False,
                                  fileName = fname, head = head, extraArgs = [fname],style = color_themes.sirius_button)
            self.labels.append(label)
            self.labelDict[label.getFileName()] = label
            if not hbox:
                hbox = HLayout(margin = hspacing)
                self.vbox.append(hbox)
                hbox.append(label)
            else:
                hbox.append(label)
                hbox = None
                
        
    def roll(self,value):
        self.frame.verticalScroll.setValue(self.frame.verticalScroll.getValue() + value * LOAD_ROLL_SPEED)
                
    def setData(self,dumped,message):
        self.__dumped = dumped
        self.__message = message
        
    def reload(self):
        for label in self.labels:
            label.reload()
            
    def reloadMember(self,key):
        if self.labelDict.has_key(key):
            self.labelDict[key].reload()
            
    def load(self,fname):
        if base.isStarted():
            ConfirmDialog(text= '读取进度吗?', command = self.confirmedLoad, style = 'sirius', extraArgs = [fname])
        else: 
            self.confirmedLoad(fname)
            
    def confirmedLoad(self,fname):
        messenger.send('load_data',[fname])  
        self.hide()
            
        
    def focused(self):
        self.accept('mouse3', self.hide)
        self.accept('wheel_up', self.roll, [-1.0])
        self.accept('wheel_down', self.roll, [1.0])
        self.accept('arrow_up-repeat', self.roll, [-1.0])
        self.accept('arrow_down-repeat', self.roll, [1.0])
        self.accept('arrow_up', self.roll, [-1.0])
        self.accept('arrow_down', self.roll, [1.0])
        self.accept('w-repeat', self.roll, [-1.0])
        self.accept('s-repeat', self.roll, [1.0])
        self.accept('w', self.roll, [-1.0])
        self.accept('s', self.roll, [1.0])
        
    def defocused(self):
        self.ignore('mouse3')
        self.ignore('wheel_up')
        self.ignore('wheel_down')
        self.ignore('arrow_up-repeat')
        self.ignore('arrow_down-repeat')
        self.ignore('arrow_up')
        self.ignore('arrow_down')
        self.ignore('w-repeat')
        self.ignore('s-repeat')
        self.ignore('w')
        self.ignore('s')
Ejemplo n.º 9
0
class SaveForm(SogalForm):
    '''
    Form of saving
    '''

    def __init__(self):
        '''
        Constructor
        '''
        SogalForm.__init__(self, fading = True, fading_duration = 0.5, enableMask = True,backgroundColor= color_themes.ilia_bgColor)
        self.reparentTo(aspect2d,sort = 102)
        self.frame = DirectScrolledFrame(parent = self, canvasSize = SAVE_CANVAS_SIZE, 
                                         frameSize = FRAMESIZE, 
                                         autoHideScrollBars = AUTO_HIDE_SCROLLBARS,
                                         **color_themes.ilia_frame)

        self.labels = []
        self.labelDict = {}
        self.vbox = VLayout(parent = self.frame.getCanvas(), margin = vspacing)
        hbox = None
        self.__dumped = None
        for i in range(1,MAX_SAVE + 1):
            fname = 'save' + str(i)
            head = str(i)
            label = SaveLoadLabel(command = self.save, always_enable = True, fileName = fname, head = head,extraArgs = [fname],style = color_themes.ilia_button)
            self.labels.append(label)
            self.labelDict[label.getFileName()] = label
            if not hbox:
                hbox = HLayout(margin = hspacing)
                self.vbox.append(hbox)
                hbox.append(label)
            else:
                hbox.append(label)
                hbox = None
                
    def roll(self,value):
        self.frame.verticalScroll.setValue(self.frame.verticalScroll.getValue() + value * SAVE_ROLL_SPEED)
                
    def setData(self,dumped,message):
        self.__dumped = dumped
        self.__message = message
        
    def reload(self):
        for label in self.labels:
            label.reload()
    
    def reloadMember(self,key):
        if self.labelDict.has_key(key):
            self.labelDict[key].reload()
    
    def save(self,fname):
        if self.labelDict[fname].getExists():
            ConfirmDialog(text= '要覆盖吗?不覆盖吗?', command = self.confirmedSave, extraArgs = [fname], style = 'ilia')
        else: 
            self.confirmedSave(fname)
    
    def confirmedSave(self,fname):
        if not self.__dumped:
            return
        else:
            messenger.send('save_data',[self.__dumped, fname, self.__message])
            
        
    def focused(self):
        self.accept('mouse3', self.hide)
        self.accept('escape', self.hide)
        self.accept('wheel_up', self.roll, [-1.0])
        self.accept('wheel_down', self.roll, [1.0])
        self.accept('arrow_up-repeat', self.roll, [-1.0])
        self.accept('arrow_down-repeat', self.roll, [1.0])
        self.accept('arrow_up', self.roll, [-1.0])
        self.accept('arrow_down', self.roll, [1.0])
        self.accept('w-repeat', self.roll, [-1.0])
        self.accept('s-repeat', self.roll, [1.0])
        self.accept('w', self.roll, [-1.0])
        self.accept('s', self.roll, [1.0])
        
    def defocused(self):
        self.ignore('mouse3')
        self.ignore('escape')
        self.ignore('wheel_up')
        self.ignore('wheel_down')
        self.ignore('arrow_up-repeat')
        self.ignore('arrow_down-repeat')
        self.ignore('arrow_up')
        self.ignore('arrow_down')
        self.ignore('w-repeat')
        self.ignore('s-repeat')
        self.ignore('w')
        self.ignore('s')
Ejemplo n.º 10
0
class SogalDialog(SogalForm):
    '''
    A dialog that derived from SogalForm
    (Which contains a DirectDialog)
    '''
    def __init__(self,
                 enableMask = True, #NOTE THAT IT IS TRUE BY DEFAULT
                 autoDestroy = True,
                 sortType = 0, #0 for horizontal, 1 for vertical
                 margin = 0.2,
                 textList = ['OK','Cancel'],
                 enablesList = None,
                 command = None,
                 frameSize = (-0.6,0.6,-0.45,0.45),
                 buttonSize = BUTTON_SIZE,
                 text = '',
                 textPos = (0,0.2),
                 startPos = (-0.4,0,-0.2),
                 extraArgs = [],
                 style = None,
                 fadeScreen = 0.5,
                 backgroundColor = None,
                 **kwargs):
        if backgroundColor:
            bgColor = backgroundColor
        elif fadeScreen is not None:
            bgColor = (0,0,0,fadeScreen)
        else:
            bgColor = None
        
        SogalForm.__init__(self,enableMask = enableMask,backgroundColor=bgColor, **kwargs)
        if enableMask:
            self.reparentTo(aspect2d, sort = 1000)
        if not style:
            self.__style = base.getStyle()
        else:
            self.__style = color_themes.styles[style]
        
        self.__frame = DirectFrame(parent = self,frameSize = frameSize,**self.__style['hardframe'])
        self.__buttonList = []#DirectButton(parent = self, s)
        self.__text = OnscreenText(parent = self,text = text ,pos = textPos, **self.__style['text'])
        self.__command = command
        self.__autoDestroy = autoDestroy
        self._extraArgs = extraArgs
        
        if sortType == 0:
            self.__box = HLayout(margin = margin)
        else: self.__box = VLayout(margin = margin)
        self.__box.reparentTo(self)
        self.__box.setPos(startPos)
        
        for i in range(len(textList)):
            btn = DirectButton(text = textList[i], command = self.buttonCommand(i),frameSize = buttonSize, **self.__style['button'])
            self.__buttonList.append(btn)
            self.__box.append(btn)
            
        if enablesList:
            for i in range(len(enablesList)):
                if i >= len(self.__buttonList):
                    break
                if enablesList[i]:
                    self.__buttonList[i]['state'] = DGG.NORMAL
                else: self.__buttonList[i]['state'] = DGG.DISABLED
                
        self.show()
        
    def buttonCommand(self, i):
        commandindex = i
        def process():
            if self.__command:
                self.__command(commandindex, *self._extraArgs)
            if self.__autoDestroy:
                self.close()
        return process

    def close(self):
        for btn in self.__buttonList:
            btn['state'] = DGG.DISABLED
        if self._getFading():
            seq = Sequence(Func(self.hide),
                           Wait(self._getFadingDuration()+2),
                           Func(self.destroy),
                           )
            seq.start()
        else: self.destroy()        
    
            
    def destroy(self):
        for btn in self.__buttonList:
            btn.destroy()
        self.__frame.destroy()
        self.__box.removeNode()
        SogalForm.destroy(self)