Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/usmpgames/menustate.py
blob: fa20ad051946ed7a13ba4fce726d4bce8f729a0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-

import pygame, jmenu, sys
from applicationstate import *
from application import *
from infostate import *

class MenuState(InfoState):
    
    def __init__(self, background = None, cookie = None):
        InfoState.__init__(self,  None,  background, cookie)
        self._menu_options = []
        self._menu_states = []
        self.pos = ('center', 'center')
        self.font = None
        self.light = 10
        self.fontSize = 32
        self.color = (0, 0, 0)
        self.justify = True
        
    def add_menu_option(self,  option,  state):
        self._menu_options.append( option )
        self._menu_states.append( state )

    def render(self,  ms):
	InfoState.render(self, ms)
        selection = jmenu.run(
            self._menu_options,
            color = self.color, 
            size = self.fontSize, 
            font = self.font,
            light = self.light,
            justify = self.justify,
            pos = self.pos)
        try:
            index = self._menu_options.index( selection )
            Application.instance().push_state( self._menu_states[index] )
        except:
            Application.instance().pop_state()

    def input(self,  ms):
	pass

    def entering_state(self, fromStack, cookie):
	ApplicationState.entering_state(self, fromStack, cookie)