Example #1
0
    def __init__(self):
        ScriptWidget.__init__(self)
        ActionListener.__init__(self)

        self.scrollStyle = resources.objectManager().getResourceObject(
            '/world/skin/quest/dark').scrollStyle
        if not self.scrollStyle:
            self.scrollStyle = engine.defaultSkin.scrollStyle

        font = resources.objectManager().getResourceObject('/fonts/default')
        self.smallFont = resources.loadFont(font.path, 12, font.antialiasing)
        self.font = resources.loadFont(font)
        self.buttonFont = resources.loadFont(
            resources.objectManager().getResourceObject('/fonts/ranger-bold'))

        self.buttonSounds = (engine.defaultSkin.buttonStyle.clickSound,\
                             engine.defaultSkin.buttonStyle.enterSound,\
                             engine.defaultSkin.buttonStyle.leaveSound)

        self.bg = Sprite("DATA/FormLoadQuest/2BG.gi")
        self.bg.layer = -1
        self.addChild(self.bg)
        self.width = int(self.bg.width)
        self.height = int(self.bg.height)

        self.bg2 = Sprite("DATA/FormLoadQuest/2ImageBG.gi")
        self.bg2.layer = -3
        self.bg2.position = (640, 15)
        self.addChild(self.bg2)

        self.image = None

        self.descNode = WidgetNode()
        self.descScroll = ScrollArea(self.scrollStyle, self.descNode)
        self.descScroll.position = (631, 280)
        self.descScroll.geometry = (280, 243)
        self.addWidget(self.descScroll)

        self.desc = ColorLabel()
        self.desc.font = self.font
        self.desc.position = (0, 5)
        self.desc.wordWrap = True
        self.desc.setFixedWidth(280)
        self.desc.textColor = Color(0.0, 0.0, 0.0)
        self.desc.selectionColor = Color(0.0, 0.0, 1.0)
        self.descWidget = LabelWidget(self.desc)
        self.descNode.addWidget(self.descWidget)

        self.node = WidgetNode()

        self.scroll = ScrollArea(self.scrollStyle, self.node)
        self.scroll.position = (40, 145)
        self.scroll.geometry = (528, 460)
        self.addWidget(self.scroll)

        self.startButton = Button('DATA/FormSave2/2SaveN.gi', '',
                                  'DATA/FormSave2/2SaveD.gi')
        self.startButton.sounds = (self.buttonSounds[0], '', '')
        self.startButton.text = _('Start', 'FormLoadQuest.Start',
                                  'OpenSR-World')
        self.startButton.font = self.buttonFont
        self.startButton.color = Color.fromString('#002842')
        self.startButton.position = (638, 574)
        self.startButton.layer = 1
        self.startButton.addListener(self)
        self.addWidget(self.startButton)

        self.cancelButton = Button('DATA/FormSave2/2CancelN.gi', '',
                                   'DATA/FormSave2/2CancelD.gi')
        self.cancelButton.sounds = (self.buttonSounds[0], '', '')
        self.cancelButton.text = _('Cancel', 'FormLoadQuest.Cancel',
                                   'OpenSR-World')
        self.cancelButton.font = self.buttonFont
        self.cancelButton.color = Color.fromString('#002842')
        self.cancelButton.position = (638, 626)
        self.cancelButton.layer = 1
        self.cancelButton.addListener(self)
        self.addWidget(self.cancelButton)

        self.closeButton = Button('DATA/FormSave2/2CloseN.gi',
                                  'DATA/FormSave2/2CloseA.gi',
                                  'DATA/FormSave2/2CloseD.gi')
        self.closeButton.sounds = self.buttonSounds
        self.closeButton.position = (891, 601)
        self.closeButton.layer = 1
        self.closeButton.addListener(self)
        self.addWidget(self.closeButton)

        self.buttons = {}
        self.loadQuests()

        self.selected = None

        first = None
        i = 0
        for q in self.quests:
            b = Button("DATA/FormLoadQuest/2SlotNormal.gi",
                       "DATA/FormLoadQuest/2SlotOnMouse.gi",
                       "DATA/FormLoadQuest/2SlotOnPress.gi")
            b.position = (0, 5 + i * (b.height + 5))
            self.node.addWidget(b)
            self.buttons[b] = i
            b.addListener(self)
            if i == 0:
                first = b

            nl = Label(q.name)
            nl.font = self.font
            nl.origin = (SpriteXOrigin.POSITION_X_LEFT,
                         SpriteYOrigin.POSITION_Y_CENTER)
            nl.position = (15, int(5 + i * (b.height + 5) + b.height / 2))
            nl.layer = 1
            nl.color = Color.fromString("#A5B68C")
            self.node.addChild(nl)

            if q.length < 1:
                diff = "DATA/FormLoadQuest/2D1.gi"
            elif q.length < 2:
                diff = "DATA/FormLoadQuest/2D2.gi"
            elif q.length < 3:
                diff = "DATA/FormLoadQuest/2D3.gi"
            elif q.length < 4:
                diff = "DATA/FormLoadQuest/2D4.gi"
            else:
                diff = "DATA/FormLoadQuest/2D5.gi"

            diffIcon = Sprite(diff)
            diffIcon.origin = (SpriteXOrigin.POSITION_X_LEFT,
                               SpriteYOrigin.POSITION_Y_CENTER)
            diffIcon.position = (int(b.width / 2.2),
                                 int(5 + i * (b.height + 5) + b.height / 2))
            diffIcon.layer = 1
            self.node.addChild(diffIcon)

            gl = Label(q.genre)
            gl.font = self.smallFont
            gl.origin = (SpriteXOrigin.POSITION_X_LEFT,
                         SpriteYOrigin.POSITION_Y_CENTER)
            gl.position = (int(b.width / 2.2) + 5 + diffIcon.width,
                           int(5 + i * (b.height + 5) + b.height / 2))
            gl.layer = 1
            gl.color = Color.fromString("#A5B68C")
            gl.wordWrap = True
            gl.setFixedWidth(b.width - int(b.width / 2.2) - 5 - diffIcon.width)
            self.node.addChild(gl)

            i += 1

        self.select(first)
Example #2
0
class QuestSelectionWidget(ScriptWidget, ActionListener):
    def __init__(self):
        ScriptWidget.__init__(self)
        ActionListener.__init__(self)

        self.scrollStyle = resources.objectManager().getResourceObject(
            '/world/skin/quest/dark').scrollStyle
        if not self.scrollStyle:
            self.scrollStyle = engine.defaultSkin.scrollStyle

        font = resources.objectManager().getResourceObject('/fonts/default')
        self.smallFont = resources.loadFont(font.path, 12, font.antialiasing)
        self.font = resources.loadFont(font)
        self.buttonFont = resources.loadFont(
            resources.objectManager().getResourceObject('/fonts/ranger-bold'))

        self.buttonSounds = (engine.defaultSkin.buttonStyle.clickSound,\
                             engine.defaultSkin.buttonStyle.enterSound,\
                             engine.defaultSkin.buttonStyle.leaveSound)

        self.bg = Sprite("DATA/FormLoadQuest/2BG.gi")
        self.bg.layer = -1
        self.addChild(self.bg)
        self.width = int(self.bg.width)
        self.height = int(self.bg.height)

        self.bg2 = Sprite("DATA/FormLoadQuest/2ImageBG.gi")
        self.bg2.layer = -3
        self.bg2.position = (640, 15)
        self.addChild(self.bg2)

        self.image = None

        self.descNode = WidgetNode()
        self.descScroll = ScrollArea(self.scrollStyle, self.descNode)
        self.descScroll.position = (631, 280)
        self.descScroll.geometry = (280, 243)
        self.addWidget(self.descScroll)

        self.desc = ColorLabel()
        self.desc.font = self.font
        self.desc.position = (0, 5)
        self.desc.wordWrap = True
        self.desc.setFixedWidth(280)
        self.desc.textColor = Color(0.0, 0.0, 0.0)
        self.desc.selectionColor = Color(0.0, 0.0, 1.0)
        self.descWidget = LabelWidget(self.desc)
        self.descNode.addWidget(self.descWidget)

        self.node = WidgetNode()

        self.scroll = ScrollArea(self.scrollStyle, self.node)
        self.scroll.position = (40, 145)
        self.scroll.geometry = (528, 460)
        self.addWidget(self.scroll)

        self.startButton = Button('DATA/FormSave2/2SaveN.gi', '',
                                  'DATA/FormSave2/2SaveD.gi')
        self.startButton.sounds = (self.buttonSounds[0], '', '')
        self.startButton.text = _('Start', 'FormLoadQuest.Start',
                                  'OpenSR-World')
        self.startButton.font = self.buttonFont
        self.startButton.color = Color.fromString('#002842')
        self.startButton.position = (638, 574)
        self.startButton.layer = 1
        self.startButton.addListener(self)
        self.addWidget(self.startButton)

        self.cancelButton = Button('DATA/FormSave2/2CancelN.gi', '',
                                   'DATA/FormSave2/2CancelD.gi')
        self.cancelButton.sounds = (self.buttonSounds[0], '', '')
        self.cancelButton.text = _('Cancel', 'FormLoadQuest.Cancel',
                                   'OpenSR-World')
        self.cancelButton.font = self.buttonFont
        self.cancelButton.color = Color.fromString('#002842')
        self.cancelButton.position = (638, 626)
        self.cancelButton.layer = 1
        self.cancelButton.addListener(self)
        self.addWidget(self.cancelButton)

        self.closeButton = Button('DATA/FormSave2/2CloseN.gi',
                                  'DATA/FormSave2/2CloseA.gi',
                                  'DATA/FormSave2/2CloseD.gi')
        self.closeButton.sounds = self.buttonSounds
        self.closeButton.position = (891, 601)
        self.closeButton.layer = 1
        self.closeButton.addListener(self)
        self.addWidget(self.closeButton)

        self.buttons = {}
        self.loadQuests()

        self.selected = None

        first = None
        i = 0
        for q in self.quests:
            b = Button("DATA/FormLoadQuest/2SlotNormal.gi",
                       "DATA/FormLoadQuest/2SlotOnMouse.gi",
                       "DATA/FormLoadQuest/2SlotOnPress.gi")
            b.position = (0, 5 + i * (b.height + 5))
            self.node.addWidget(b)
            self.buttons[b] = i
            b.addListener(self)
            if i == 0:
                first = b

            nl = Label(q.name)
            nl.font = self.font
            nl.origin = (SpriteXOrigin.POSITION_X_LEFT,
                         SpriteYOrigin.POSITION_Y_CENTER)
            nl.position = (15, int(5 + i * (b.height + 5) + b.height / 2))
            nl.layer = 1
            nl.color = Color.fromString("#A5B68C")
            self.node.addChild(nl)

            if q.length < 1:
                diff = "DATA/FormLoadQuest/2D1.gi"
            elif q.length < 2:
                diff = "DATA/FormLoadQuest/2D2.gi"
            elif q.length < 3:
                diff = "DATA/FormLoadQuest/2D3.gi"
            elif q.length < 4:
                diff = "DATA/FormLoadQuest/2D4.gi"
            else:
                diff = "DATA/FormLoadQuest/2D5.gi"

            diffIcon = Sprite(diff)
            diffIcon.origin = (SpriteXOrigin.POSITION_X_LEFT,
                               SpriteYOrigin.POSITION_Y_CENTER)
            diffIcon.position = (int(b.width / 2.2),
                                 int(5 + i * (b.height + 5) + b.height / 2))
            diffIcon.layer = 1
            self.node.addChild(diffIcon)

            gl = Label(q.genre)
            gl.font = self.smallFont
            gl.origin = (SpriteXOrigin.POSITION_X_LEFT,
                         SpriteYOrigin.POSITION_Y_CENTER)
            gl.position = (int(b.width / 2.2) + 5 + diffIcon.width,
                           int(5 + i * (b.height + 5) + b.height / 2))
            gl.layer = 1
            gl.color = Color.fromString("#A5B68C")
            gl.wordWrap = True
            gl.setFixedWidth(b.width - int(b.width / 2.2) - 5 - diffIcon.width)
            self.node.addChild(gl)

            i += 1

        self.select(first)

    def select(self, button):
        if button == None:
            return

        if self.selected == button:
            return

        if self.selected != None:
            self.selected.removeListener(self)
            self.node.removeWidget(self.selected)
            i = self.buttons[self.selected]
            del self.buttons[self.selected]

            self.selected = Button("DATA/FormLoadQuest/2SlotNormal.gi",
                                   "DATA/FormLoadQuest/2SlotOnMouse.gi",
                                   "DATA/FormLoadQuest/2SlotOnPress.gi")
            self.selected.position = (0, 5 + i * (self.selected.height + 5))
            self.node.addWidget(self.selected)
            self.selected.addListener(self)
            self.buttons[self.selected] = i

        button.removeListener(self)
        self.node.removeWidget(button)
        i = self.buttons[button]
        del self.buttons[button]

        self.selected = Button("DATA/FormLoadQuest/2SlotActive.gi")
        self.selected.position = (0, 5 + i * (self.selected.height + 5))
        self.node.addWidget(self.selected)
        self.buttons[self.selected] = i
        self.selected.addListener(self)

        #if self.image != None:
        #self.removeChild(self.image)

        #self.image = Sprite(self.quests[i].image)
        #self.image.layer = -2
        #self.image.position = (640, 15)
        #self.image.geometry = (200, 228)
        #self.addChild(self.image)

        self.selectedQuest = self.quests[i].id

        text = resources.datRoot()['PlanetQuest']['StartText'][
            self.quests[i].id].value

        text = text.replace("<Player>", '\\cS' + self.rangerName + '\\cR')
        text = text.replace("<CurPlanet>", '\\cS' + self.fromPlanet + '\\cR')
        text = text.replace("<CurStar>", '\\cS' + self.fromStar + '\\cR')
        text = text.replace("<ToPlanet>", '\\cS' + self.toPlanet + '\\cR')
        text = text.replace("<ToStar>", '\\cS' + self.toStar + '\\cR')
        text = text.replace("<FromPlanet>", '\\cS' + self.fromPlanet + '\\cR')
        text = text.replace("<FromStar>", '\\cS' + self.fromStar + '\\cR')

        self.desc.text = text
        self.descScroll.markToUpdate()

    def loadQuests(self):
        dat = resources.datRoot()

        self.rangerName = dat['FormLoadQuest']['PRanger'].value
        self.toPlanet = dat['FormLoadQuest']['PToPlanet'].value
        self.toStar = dat['FormLoadQuest']['PToStar'].value
        self.fromPlanet = dat['FormLoadQuest']['PFromPlanet'].value
        self.fromStar = dat['FormLoadQuest']['PFromStar'].value

        self.quests = []
        for q in dat['PlanetQuest']['List']:
            info = QuestInfo()
            info.id = q.name
            info.name = q['Name'].value
            info.genre = q['Genre'].value
            info.group = int(q['Group'].value)
            info.access = int(q['Access'].value)
            info.length = int(q['Length'].value)
            info.image = getCacheDATPath(q['Image'].value)
            info.difficulty = int(q['Dif'].value)
            self.quests.append(info)

    def dispose(self):
        for k in self.buttons.keys():
            k.removeListener(self)
        self.cancelButton.removeListener(self)
        self.startButton.removeListener(self)
        self.closeButton.removeListener(self)

    def processLogic(self, dt):
        ScriptWidget.processLogic(self, dt)

    def actionPerformed(self, action):
        if action.type != Action.Type.BUTTON_CLICKED:
            return

        if action.source in self.buttons:
            self.select(action.source)
        elif action.source == self.startButton:
            self.action(Action(self, Action.Type.DIALOG_ACCEPT))
        elif action.source == self.cancelButton:
            self.action(Action(self, Action.Type.DIALOG_CANCEL))
        elif action.source == self.closeButton:
            self.action(Action(self, Action.Type.DIALOG_CANCEL))
Example #3
0
class QuestSelectionWidget(ScriptWidget, ActionListener):
    def __init__(self):
        ScriptWidget.__init__(self)
        ActionListener.__init__(self)
        
        self.scrollStyle = resources.objectManager().getResourceObject('/world/skin/quest/dark').scrollStyle
        if not self.scrollStyle:
            self.scrollStyle = engine.defaultSkin.scrollStyle
            
        font = resources.objectManager().getResourceObject('/fonts/default')
        self.smallFont = resources.loadFont(font.path, 12, font.antialiasing)
        self.font = resources.loadFont(font)
        self.buttonFont = resources.loadFont(resources.objectManager().getResourceObject('/fonts/ranger-bold'))
        
        self.buttonSounds = (engine.defaultSkin.buttonStyle.clickSound,\
                             engine.defaultSkin.buttonStyle.enterSound,\
                             engine.defaultSkin.buttonStyle.leaveSound)
        
        self.bg = Sprite("DATA/FormLoadQuest/2BG.gi")
        self.bg.layer = -1
        self.addChild(self.bg)
        self.width = int(self.bg.width)
        self.height = int(self.bg.height)
        
        self.bg2 = Sprite("DATA/FormLoadQuest/2ImageBG.gi")
        self.bg2.layer = -3
        self.bg2.position = (640, 15)
        self.addChild(self.bg2)
        
        self.image = None
        
        self.descNode = WidgetNode()
        self.descScroll = ScrollArea(self.scrollStyle, self.descNode)
        self.descScroll.position = (631, 280)
        self.descScroll.geometry = (280, 243)
        self.addWidget(self.descScroll)
        
        self.desc = ColorLabel()
        self.desc.font = self.font
        self.desc.position = (0, 5)
        self.desc.wordWrap = True
        self.desc.setFixedWidth(280)
        self.desc.textColor = Color(0.0, 0.0, 0.0)
        self.desc.selectionColor = Color(0.0, 0.0, 1.0)
        self.descWidget = LabelWidget(self.desc)
        self.descNode.addWidget(self.descWidget)
        
        self.node = WidgetNode()
        
        self.scroll = ScrollArea(self.scrollStyle, self.node)
        self.scroll.position = (40, 145)
        self.scroll.geometry = (528, 460)
        self.addWidget(self.scroll)
        
        self.startButton = Button('DATA/FormSave2/2SaveN.gi', '', 'DATA/FormSave2/2SaveD.gi')
        self.startButton.sounds = (self.buttonSounds[0], '', '')
        self.startButton.text = _('Start', 'FormLoadQuest.Start', 'OpenSR-World')
        self.startButton.font = self.buttonFont
        self.startButton.color = Color.fromString('#002842')
        self.startButton.position = (638, 574)
        self.startButton.layer = 1
        self.startButton.addListener(self)
        self.addWidget(self.startButton)
        
        self.cancelButton = Button('DATA/FormSave2/2CancelN.gi', '', 'DATA/FormSave2/2CancelD.gi')
        self.cancelButton.sounds = (self.buttonSounds[0], '', '')
        self.cancelButton.text = _('Cancel', 'FormLoadQuest.Cancel', 'OpenSR-World')
        self.cancelButton.font = self.buttonFont
        self.cancelButton.color = Color.fromString('#002842')
        self.cancelButton.position = (638, 626)
        self.cancelButton.layer = 1
        self.cancelButton.addListener(self)
        self.addWidget(self.cancelButton)
        
        self.closeButton = Button('DATA/FormSave2/2CloseN.gi', 'DATA/FormSave2/2CloseA.gi', 'DATA/FormSave2/2CloseD.gi')
        self.closeButton.sounds = self.buttonSounds
        self.closeButton.position = (891, 601)
        self.closeButton.layer = 1
        self.closeButton.addListener(self)
        self.addWidget(self.closeButton)
        
        self.buttons = {}       
        self.loadQuests()
        
        self.selected = None
        
        first = None
        i = 0
        for q in self.quests:
            b = Button("DATA/FormLoadQuest/2SlotNormal.gi", "DATA/FormLoadQuest/2SlotOnMouse.gi", "DATA/FormLoadQuest/2SlotOnPress.gi")
            b.position = (0, 5 + i * (b.height + 5))
            self.node.addWidget(b)
            self.buttons[b] = i
            b.addListener(self)
            if i == 0:
                first = b
            
            nl = Label(q.name)
            nl.font = self.font
            nl.origin = (SpriteXOrigin.POSITION_X_LEFT, SpriteYOrigin.POSITION_Y_CENTER)
            nl.position = (15, int(5 + i * (b.height + 5) + b.height / 2))
            nl.layer = 1
            nl.color = Color.fromString("#A5B68C")
            self.node.addChild(nl)
            
            if q.length < 1:
                diff = "DATA/FormLoadQuest/2D1.gi"
            elif q.length < 2:
                diff = "DATA/FormLoadQuest/2D2.gi"
            elif q.length < 3:
                diff = "DATA/FormLoadQuest/2D3.gi"
            elif q.length < 4:
                diff = "DATA/FormLoadQuest/2D4.gi"
            else:
                diff = "DATA/FormLoadQuest/2D5.gi"
                
            diffIcon = Sprite(diff)
            diffIcon.origin = (SpriteXOrigin.POSITION_X_LEFT, SpriteYOrigin.POSITION_Y_CENTER)
            diffIcon.position = (int(b.width / 2.2), int(5 + i * (b.height + 5) + b.height / 2))
            diffIcon.layer = 1
            self.node.addChild(diffIcon)
            
            gl = Label(q.genre)
            gl.font = self.smallFont
            gl.origin = (SpriteXOrigin.POSITION_X_LEFT, SpriteYOrigin.POSITION_Y_CENTER)
            gl.position = (int(b.width / 2.2) + 5 + diffIcon.width, int(5 + i * (b.height + 5) + b.height / 2))
            gl.layer = 1
            gl.color = Color.fromString("#A5B68C")
            gl.wordWrap = True
            gl.setFixedWidth(b.width - int(b.width / 2.2) - 5 - diffIcon.width)
            self.node.addChild(gl)
            
            i += 1
            
        self.select(first)
    
    def select(self, button):
        if button == None:
            return

        if self.selected == button:
            return

        if self.selected != None:
            self.selected.removeListener(self)
            self.node.removeWidget(self.selected)
            i = self.buttons[self.selected]
            del self.buttons[self.selected]
            
            self.selected = Button("DATA/FormLoadQuest/2SlotNormal.gi", "DATA/FormLoadQuest/2SlotOnMouse.gi", "DATA/FormLoadQuest/2SlotOnPress.gi")
            self.selected.position = (0, 5 + i * (self.selected.height + 5))
            self.node.addWidget(self.selected)
            self.selected.addListener(self)
            self.buttons[self.selected] = i
        
        button.removeListener(self)
        self.node.removeWidget(button)
        i = self.buttons[button]
        del self.buttons[button]
        
        self.selected = Button("DATA/FormLoadQuest/2SlotActive.gi")
        self.selected.position = (0, 5 + i * (self.selected.height + 5))
        self.node.addWidget(self.selected)
        self.buttons[self.selected] = i
        self.selected.addListener(self)
        
        #if self.image != None:
            #self.removeChild(self.image)
            
        #self.image = Sprite(self.quests[i].image)
        #self.image.layer = -2
        #self.image.position = (640, 15)
        #self.image.geometry = (200, 228)
        #self.addChild(self.image)
        
        self.selectedQuest = self.quests[i].id
        
        text = resources.datRoot()['PlanetQuest']['StartText'][self.quests[i].id].value
        
        text = text.replace("<Player>", '\\cS' + self.rangerName + '\\cR')
        text = text.replace("<CurPlanet>", '\\cS' + self.fromPlanet + '\\cR')
        text = text.replace("<CurStar>", '\\cS' + self.fromStar + '\\cR')
        text = text.replace("<ToPlanet>", '\\cS' + self.toPlanet + '\\cR')
        text = text.replace("<ToStar>", '\\cS' + self.toStar + '\\cR')
        text = text.replace("<FromPlanet>", '\\cS' + self.fromPlanet + '\\cR')
        text = text.replace("<FromStar>", '\\cS' + self.fromStar + '\\cR')
        
        self.desc.text = text
        self.descScroll.markToUpdate()
        
        
    def loadQuests(self):
        dat = resources.datRoot()
        
        self.rangerName = dat['FormLoadQuest']['PRanger'].value
        self.toPlanet = dat['FormLoadQuest']['PToPlanet'].value
        self.toStar = dat['FormLoadQuest']['PToStar'].value
        self.fromPlanet = dat['FormLoadQuest']['PFromPlanet'].value
        self.fromStar = dat['FormLoadQuest']['PFromStar'].value
        
        self.quests = []                
        for q in dat['PlanetQuest']['List']:
            info = QuestInfo()
            info.id = q.name
            info.name = q['Name'].value
            info.genre = q['Genre'].value
            info.group = int(q['Group'].value)
            info.access = int(q['Access'].value)
            info.length = int(q['Length'].value)
            info.image = getCacheDATPath(q['Image'].value)
            info.difficulty = int(q['Dif'].value)
            self.quests.append(info)
            
    def dispose(self):
        for k in self.buttons.keys():
            k.removeListener(self)
        self.cancelButton.removeListener(self)
        self.startButton.removeListener(self)
        self.closeButton.removeListener(self)
            
    def processLogic(self, dt):
        ScriptWidget.processLogic(self, dt)
           
    def actionPerformed(self, action):
        if action.type != Action.Type.BUTTON_CLICKED:
            return
        
        if action.source in self.buttons:
            self.select(action.source)
        elif action.source == self.startButton:
            self.action(Action(self, Action.Type.DIALOG_ACCEPT))
        elif action.source == self.cancelButton:
            self.action(Action(self, Action.Type.DIALOG_CANCEL))
        elif action.source == self.closeButton:
            self.action(Action(self, Action.Type.DIALOG_CANCEL))
Example #4
0
 def __init__(self):
     ScriptWidget.__init__(self)
     ActionListener.__init__(self)
     
     self.scrollStyle = resources.objectManager().getResourceObject('/world/skin/quest/dark').scrollStyle
     if not self.scrollStyle:
         self.scrollStyle = engine.defaultSkin.scrollStyle
         
     font = resources.objectManager().getResourceObject('/fonts/default')
     self.smallFont = resources.loadFont(font.path, 12, font.antialiasing)
     self.font = resources.loadFont(font)
     self.buttonFont = resources.loadFont(resources.objectManager().getResourceObject('/fonts/ranger-bold'))
     
     self.buttonSounds = (engine.defaultSkin.buttonStyle.clickSound,\
                          engine.defaultSkin.buttonStyle.enterSound,\
                          engine.defaultSkin.buttonStyle.leaveSound)
     
     self.bg = Sprite("DATA/FormLoadQuest/2BG.gi")
     self.bg.layer = -1
     self.addChild(self.bg)
     self.width = int(self.bg.width)
     self.height = int(self.bg.height)
     
     self.bg2 = Sprite("DATA/FormLoadQuest/2ImageBG.gi")
     self.bg2.layer = -3
     self.bg2.position = (640, 15)
     self.addChild(self.bg2)
     
     self.image = None
     
     self.descNode = WidgetNode()
     self.descScroll = ScrollArea(self.scrollStyle, self.descNode)
     self.descScroll.position = (631, 280)
     self.descScroll.geometry = (280, 243)
     self.addWidget(self.descScroll)
     
     self.desc = ColorLabel()
     self.desc.font = self.font
     self.desc.position = (0, 5)
     self.desc.wordWrap = True
     self.desc.setFixedWidth(280)
     self.desc.textColor = Color(0.0, 0.0, 0.0)
     self.desc.selectionColor = Color(0.0, 0.0, 1.0)
     self.descWidget = LabelWidget(self.desc)
     self.descNode.addWidget(self.descWidget)
     
     self.node = WidgetNode()
     
     self.scroll = ScrollArea(self.scrollStyle, self.node)
     self.scroll.position = (40, 145)
     self.scroll.geometry = (528, 460)
     self.addWidget(self.scroll)
     
     self.startButton = Button('DATA/FormSave2/2SaveN.gi', '', 'DATA/FormSave2/2SaveD.gi')
     self.startButton.sounds = (self.buttonSounds[0], '', '')
     self.startButton.text = _('Start', 'FormLoadQuest.Start', 'OpenSR-World')
     self.startButton.font = self.buttonFont
     self.startButton.color = Color.fromString('#002842')
     self.startButton.position = (638, 574)
     self.startButton.layer = 1
     self.startButton.addListener(self)
     self.addWidget(self.startButton)
     
     self.cancelButton = Button('DATA/FormSave2/2CancelN.gi', '', 'DATA/FormSave2/2CancelD.gi')
     self.cancelButton.sounds = (self.buttonSounds[0], '', '')
     self.cancelButton.text = _('Cancel', 'FormLoadQuest.Cancel', 'OpenSR-World')
     self.cancelButton.font = self.buttonFont
     self.cancelButton.color = Color.fromString('#002842')
     self.cancelButton.position = (638, 626)
     self.cancelButton.layer = 1
     self.cancelButton.addListener(self)
     self.addWidget(self.cancelButton)
     
     self.closeButton = Button('DATA/FormSave2/2CloseN.gi', 'DATA/FormSave2/2CloseA.gi', 'DATA/FormSave2/2CloseD.gi')
     self.closeButton.sounds = self.buttonSounds
     self.closeButton.position = (891, 601)
     self.closeButton.layer = 1
     self.closeButton.addListener(self)
     self.addWidget(self.closeButton)
     
     self.buttons = {}       
     self.loadQuests()
     
     self.selected = None
     
     first = None
     i = 0
     for q in self.quests:
         b = Button("DATA/FormLoadQuest/2SlotNormal.gi", "DATA/FormLoadQuest/2SlotOnMouse.gi", "DATA/FormLoadQuest/2SlotOnPress.gi")
         b.position = (0, 5 + i * (b.height + 5))
         self.node.addWidget(b)
         self.buttons[b] = i
         b.addListener(self)
         if i == 0:
             first = b
         
         nl = Label(q.name)
         nl.font = self.font
         nl.origin = (SpriteXOrigin.POSITION_X_LEFT, SpriteYOrigin.POSITION_Y_CENTER)
         nl.position = (15, int(5 + i * (b.height + 5) + b.height / 2))
         nl.layer = 1
         nl.color = Color.fromString("#A5B68C")
         self.node.addChild(nl)
         
         if q.length < 1:
             diff = "DATA/FormLoadQuest/2D1.gi"
         elif q.length < 2:
             diff = "DATA/FormLoadQuest/2D2.gi"
         elif q.length < 3:
             diff = "DATA/FormLoadQuest/2D3.gi"
         elif q.length < 4:
             diff = "DATA/FormLoadQuest/2D4.gi"
         else:
             diff = "DATA/FormLoadQuest/2D5.gi"
             
         diffIcon = Sprite(diff)
         diffIcon.origin = (SpriteXOrigin.POSITION_X_LEFT, SpriteYOrigin.POSITION_Y_CENTER)
         diffIcon.position = (int(b.width / 2.2), int(5 + i * (b.height + 5) + b.height / 2))
         diffIcon.layer = 1
         self.node.addChild(diffIcon)
         
         gl = Label(q.genre)
         gl.font = self.smallFont
         gl.origin = (SpriteXOrigin.POSITION_X_LEFT, SpriteYOrigin.POSITION_Y_CENTER)
         gl.position = (int(b.width / 2.2) + 5 + diffIcon.width, int(5 + i * (b.height + 5) + b.height / 2))
         gl.layer = 1
         gl.color = Color.fromString("#A5B68C")
         gl.wordWrap = True
         gl.setFixedWidth(b.width - int(b.width / 2.2) - 5 - diffIcon.width)
         self.node.addChild(gl)
         
         i += 1
         
     self.select(first)
Example #5
0
    def __init__(self):
        ScriptWidget.__init__(self)
        ActionListener.__init__(self)

        self.background = Sprite("DATA/FormOptions2/2Bg.gi")
        self.background.width = engine.screenWidth
        self.background.height = engine.screenHeight
        self.background.layer = -2
        self.addChild(self.background)

        deltaY = engine.screenHeight - 768
        deltaX = engine.screenWidth - 1024

        self.formBg = NinePatch("ORC/settings_bg.9.json")
        self.formBg.geometry = (self.formBg.width + deltaX,
                                self.formBg.height + deltaY)
        self.formBg.position = (math.floor(
            (engine.screenWidth - self.formBg.width) / 2) - 10, 32)
        self.formBg.layer = -1
        self.addChild(self.formBg)

        self.formTop = NinePatch("ORC/settings_top.9.json")
        self.formTop.width = self.formTop.width + deltaX
        self.formTop.position = (math.floor(
            (engine.screenWidth - self.formTop.width) / 2), 0)
        self.formTop.layer = -1
        self.addChild(self.formTop)

        self.formBottom = NinePatch("ORC/settings_bottom.9.json")
        self.formBottom.width = self.formBottom.width + deltaX
        self.formBottom.position = (math.floor(
            (engine.screenWidth - self.formTop.width) /
            2), engine.screenHeight - self.formBottom.height)
        self.formBottom.layer = -1
        self.addChild(self.formBottom)

        self.buttonNode = WidgetNode()
        self.buttonNode.position = (self.formBg.position.x + 80,
                                    self.formBg.position.y + 120)
        self.addWidget(self.buttonNode)

        self.spaceButton = Button("DATA/FormOptions2/2SpaceN.gi",
                                  "DATA/FormOptions2/2SpaceN.gi",
                                  "DATA/FormOptions2/2SpaceD.gi")
        self.spaceButton.position = (self.formBg.position.x + 26,
                                     self.formBg.position.y + 10)
        self.addWidget(self.spaceButton)

        self.okButton = Button("DATA/FormOptions2/2OkN.gi",
                               "DATA/FormOptions2/2OkA.gi",
                               "DATA/FormOptions2/2OkD.gi")
        self.okButton.position = (self.formBottom.position.x + 607 + deltaX,
                                  self.formBottom.position.y + 22)
        self.okButton.addListener(self)
        self.setSoundsDefault(self.okButton)
        self.addWidget(self.okButton)

        self.cancelButton = Button("DATA/FormOptions2/2CancelN.gi",
                                   "DATA/FormOptions2/2CancelA.gi",
                                   "DATA/FormOptions2/2CancelD.gi")
        self.cancelButton.position = (self.formBottom.position.x + 674 +
                                      deltaX, self.formBottom.position.y + 22)
        self.cancelButton.addListener(self)
        self.setSoundsDefault(self.cancelButton)
        self.addWidget(self.cancelButton)

        self.autoButton = Button("DATA/FormOptions2/2AutoN.gi",
                                 "DATA/FormOptions2/2AutoA.gi",
                                 "DATA/FormOptions2/2AutoD.gi")
        self.autoButton.position = (self.formBottom.position.x + 102,
                                    self.formBottom.position.y + 22)
        self.setSoundsDefault(self.autoButton)
        self.addWidget(self.autoButton)
        self.highButton = Button("DATA/FormOptions2/2HighN.gi",
                                 "DATA/FormOptions2/2HighA.gi",
                                 "DATA/FormOptions2/2HighD.gi")
        self.highButton.position = (self.formBottom.position.x + 176,
                                    self.formBottom.position.y + 4)
        self.setSoundsDefault(self.highButton)
        self.addWidget(self.highButton)
        self.mediumButton = Button("DATA/FormOptions2/2MediumN.gi",
                                   "DATA/FormOptions2/2MediumA.gi",
                                   "DATA/FormOptions2/2MediumD.gi")
        self.mediumButton.position = (self.formBottom.position.x + 170,
                                      self.formBottom.position.y + 33)
        self.setSoundsDefault(self.mediumButton)
        self.addWidget(self.mediumButton)
        self.lowButton = Button("DATA/FormOptions2/2LowN.gi",
                                "DATA/FormOptions2/2LowA.gi",
                                "DATA/FormOptions2/2LowD.gi")
        self.lowButton.position = (self.formBottom.position.x + 161,
                                   self.formBottom.position.y + 58)
        self.setSoundsDefault(self.lowButton)
        self.addWidget(self.lowButton)

        self.graphicsButton = Button("DATA/FormOptions2/2PageN.gi",
                                     "DATA/FormOptions2/2PageA.gi",
                                     "DATA/FormOptions2/2PageD.gi")
        self.graphicsButton.font = engine.coreFont
        self.graphicsButton.text = _("Graphics", "FormCfgSettings.GGraph")
        self.graphicsButton.color = Color(0.75, 0.85, 1.0)
        self.graphicsButton.position = (0, 0)
        self.setSoundsDefault(self.graphicsButton)
        self.buttonNode.addWidget(self.graphicsButton)

        self.paramNode = WidgetNode()

        self.widthLabel = Label(_("Width:"))
        self.paramNode.addChild(self.widthLabel)
        self.widthEdit = LineEdit(engine.defaultSkin.lineEditStyle)
        self.paramNode.addWidget(self.widthEdit)
        self.heightLabel = Label(_("Height:"))
        self.paramNode.addChild(self.heightLabel)
        self.heightEdit = LineEdit(engine.defaultSkin.lineEditStyle)
        self.paramNode.addWidget(self.heightEdit)

        self.fullscreen = CheckBox(engine.defaultSkin.checkBoxStyle,
                                   _("Fullscreen mode"))
        self.paramNode.addWidget(self.fullscreen)
        self.useShaders = CheckBox(engine.defaultSkin.checkBoxStyle,
                                   _("Use shaders"))
        self.paramNode.addWidget(self.useShaders)

        self.widthEdit.width = 50
        self.widthEdit.position = (100, 5)
        self.widthLabel.position = (
            5, 5 + (self.widthEdit.height - self.widthLabel.font.size))
        self.heightEdit.width = 50
        self.heightEdit.position = (270, 5)
        self.heightLabel.position = (
            170, 5 + (self.widthEdit.height - self.widthLabel.font.size))
        self.fullscreen.position = (5, self.widthEdit.height + 15)
        self.useShaders.position = (5, self.fullscreen.position.y +
                                    self.fullscreen.height + 5)

        self.scroll = ScrollArea(engine.defaultSkin.scrollStyle,
                                 self.paramNode)
        self.scroll.position = (self.formBg.position.x + 257,
                                self.formBg.position.y + 149)
        self.scroll.geometry = (426 + deltaX, 439 + deltaY)
        self.addWidget(self.scroll)

        # RadioButton example
        #self.group = OpenSR.Engine.RadioButtonGroup()
        #self.r1 = OpenSR.Engine.RadioButton(engine.defaultSkin().radioButtonStyle, "Yes")
        #self.r2 = OpenSR.Engine.RadioButton(engine.defaultSkin().radioButtonStyle, "No")
        #self.r3 = OpenSR.Engine.RadioButton(engine.defaultSkin().radioButtonStyle, "I dunno lol")

        #self.r2.setPosition(0, self.r1.height + 5)
        #self.r3.setPosition(0, self.r2.position.y + self.r2.height + 5)

        #self.group.addRadioButton(self.r1)
        #self.group.addRadioButton(self.r2)
        #self.group.addRadioButton(self.r3)
        #self.group.setPosition(0, 300)

        #self.paramNode.addWidget(self.group)

        self.loadSettings()