Beispiel #1
0
    def init_menu_state(self):
        self.batch = pyglet.graphics.Batch()

        label = pyglet.text.Label('AsTeRoIdS',
                                  font_name='Times New Roman',
                                  font_size=36,
                                  x=window.width // 2,
                                  y=3 * window.height // 4,
                                  anchor_x='center',
                                  anchor_y='center',
                                  batch=self.batch,
                                  group=self.foreground)

        def callback1(is_pressed):
            self.init_game_state()
            self.state = 'PLAYING'

        button1 = Button('Start Game', on_press=callback1)

        def callback2(is_pressed):
            exit()

        button2 = Button('Quit', on_press=callback2)
        Manager(VerticalContainer([button1, button2]),
                window=window,
                theme=theme,
                batch=self.batch)

        self.asteroids = self.gen_asteroids(num_ast)
 def __init__(self,
              option_name,
              button_text="",
              is_selected=False,
              parent=None):
     Option.__init__(self, option_name, parent)
     Button.__init__(self, label=button_text, is_pressed=is_selected)
Beispiel #3
0
    def __init__(self,
                 text="",
                 ok="Ok",
                 cancel="Cancel",
                 window=None,
                 batch=None,
                 group=None,
                 theme=None,
                 on_ok=None,
                 on_cancel=None):
        def on_ok_click(_):
            if on_ok is not None:
                on_ok(self)
            self.delete()

        def on_cancel_click(_):
            if on_cancel is not None:
                on_cancel(self)
            self.delete()

        Manager.__init__(self,
                         content=Frame(
                             VerticalContainer([
                                 Label(text),
                                 HorizontalContainer([
                                     Button(ok, on_press=on_ok_click), None,
                                     Button(cancel, on_press=on_cancel_click)
                                 ])
                             ])),
                         window=window,
                         batch=batch,
                         group=group,
                         theme=theme,
                         is_movable=True)
 def __init__(self):
     newgameButton=Button(label="New Game", on_press=self.newGame)
     quitButton=Button(label="Quit Game", on_press=self.quitGame)
     Manager.__init__(self,
         VerticalContainer(content=[newgameButton,Spacer(0,20),quitButton]),
         window=g.gameEngine.window,
         batch=g.guiBatch,
         theme=g.theme,
         is_movable=False)
 def __init__(self):
     quitButton = Button(label="Exit Game",on_press=self.quitGame)
     closeButton = Button(label="Return",on_press=self.close)
     Manager.__init__(self,
         Frame(VerticalContainer(content=[quitButton,closeButton])),
         window=g.gameEngine.window,
         batch=g.guiBatch,
         theme=g.theme,
         is_movable=False)
Beispiel #6
0
 def constructMeneButtons(self):
     for mene in meneList:
         if mene.hp <= 0:
             disabled = True
         else:
             disabled = False
         if g.gameEngine.fightScreen.myMene.ID == mene.ID:
             ispressed = True
             self.selectMeneID = mene.ID
         else:
             ispressed = False
         button = Button("",
                         on_press=self.updateWindow,
                         disabled=disabled,
                         width=TILESIZE * 2,
                         height=TILESIZE * 2,
                         argument=mene.ID,
                         texture=g.gameEngine.resManager.meneSprites[
                             mene.spriteName]["portraitlarge"],
                         is_pressed=ispressed,
                         outline='menewindowbutton')
         nameLabel = Label(mene.name, bold=True, color=g.npcColor)
         lvlLabel = Label("Lvl: %s" % mene.level)
         hpBar = HpBar(height=20,
                       width=64 * 2,
                       maxhp=mene.maxhp,
                       currenthp=mene.hp)
         self.meneCont.append(
             VerticalContainer(content=[button, nameLabel, lvlLabel, hpBar],
                               padding=0))
         self.meneButtons.append(button)
Beispiel #7
0
    def __init__(self,
                 name,
                 title,
                 equipped,
                 icon,
                 client,
                 hit,
                 dam,
                 arm,
                 desc=""):

        self.client = client
        self.name = name
        self.title = title
        icon = Graphic(path=['icons', icon])
        title = Label(self.title)
        stats = HorizontalContainer([
            Label(str(dam), color=[255, 100, 100, 255]),
            Label(str(hit), color=[100, 100, 255, 255]),
            Label(str(arm), color=[100, 255, 100, 255]),
        ])
        button_text = 'Equip '
        if equipped:
            button_text = 'Remove'

        equip_button = Button(label=button_text,
                              is_pressed=equipped,
                              on_press=self.equip)
        use_button = OneTimeButton(label='Use', on_release=self.use)
        drop_button = OneTimeButton(label='Drop', on_release=self.confirm_drop)

        HorizontalContainer.__init__(
            self, [icon, title, stats, equip_button, use_button, drop_button],
            align=HALIGN_LEFT)
Beispiel #8
0
class TestButton(TestPygletGUI):

    def setUp(self):
        TestPygletGUI.setUp(self)
        self.button = Button(label="test")
        self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)

    def test_creation(self):
        self.assertNotEqual(self.button.width, 0)
        self.assertNotEqual(self.button.height, 0)
        self.assertEqual(self.button.is_loaded, True)

    def test_press(self):
        self.button.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.button.is_pressed, True)

    def test_delete(self):
        self.manager.delete()

        self.assertEqual(self.button.is_loaded, False)
Beispiel #9
0
    def init_dead_state(self):
        self.score_label.delete()

        gameover_label = pyglet.text.Label('Game Over',
                                           font_name='Times New Roman',
                                           font_size=36,
                                           x=window.width // 2,
                                           y=3 * window.height // 4,
                                           anchor_x='center',
                                           anchor_y='center',
                                           batch=self.batch)

        text = 'Final Score: ' + str(self.score)
        finalscore_label = pyglet.text.Label(text,
                                             font_name='Times New Roman',
                                             font_size=18,
                                             x=window.width // 2,
                                             y=3 * window.height // 4 - 50,
                                             anchor_x='center',
                                             anchor_y='center',
                                             batch=self.batch)

        def callback1(is_pressed):
            self.init_game_state()
            self.state = 'PLAYING'

        button1 = Button('Start Game', on_press=callback1)

        def callback2(is_pressed):
            exit()

        button2 = Button('Quit', on_press=callback2)
        Manager(VerticalContainer([button1, button2]),
                window=window,
                theme=theme,
                batch=self.batch)
Beispiel #10
0
def create_ui_element(xe: Et, children: []):
    d = parse_attributes(**xe.attrib)
    if xe.tag == VerticalContainer.__name__:
        # align=HALIGN_CENTER, padding=5
        return VerticalContainer(children,
                                 align=d.get('align', 0),
                                 padding=d.get('padding', 5))
    if xe.tag == HorizontalContainer.__name__:
        # align=HALIGN_CENTER, padding=5
        return HorizontalContainer(children,
                                   align=d.get('align', 0),
                                   padding=d.get('padding', 5))
    elif xe.tag == Label.__name__:
        return Label(text=d.get('text'),
                     bold=d.get('bold', False),
                     italic=d.get('italic', False),
                     font_name=d.get('font_name', None),
                     font_size=d.get('font_size', None),
                     color=d.get('color', None),
                     path=d.get('path', None))
    elif xe.tag == Button.__name__:
        return Button(**xe.attrib)
    else:
        raise NotImplemented()
Beispiel #11
0
                       "image": {
                           "source": "button.png",
                           "frame": [6, 6, 3, 3],
                           "padding": [12, 12, 4, 2]
                       }
                   }
               },
               "checkbox": {
                   "checked": {
                       "image": {
                           "source": "checkbox-checked.png"
                       }
                   },
                   "unchecked": {
                       "image": {
                           "source": "checkbox.png"
                       }
                   }
               }
              }, resources_path='../theme/')

# Set up a Manager
Manager(VerticalContainer([Button(label="Persistent button"),
                           OneTimeButton(label="One time button"),
                           Checkbox(label="Checkbox")]),
        window=window,
        batch=batch,
        theme=theme)

pyglet.app.run()
Beispiel #12
0
                "padding": [0, 0, 0, 0]
            }
        }
    },
    resources_path='../theme')

document = pyglet.text.decode_attributed('''
In {bold True}Pyglet-gui{bold False} you can use
{underline (255, 255, 255, 255)}pyglet{underline None}'s documents in a
scrollable window.

You can also {font_name "Courier New"}change fonts{font_name Lucia Grande},
{italic True}italicize your text{italic False} and use all features of Pyglet's document.
''')
so = Document(document, width=300, height=50)


def f(y):
    document = "Hola mundo"
    so.set_text(document + so.get_text())


# Set up a Manager
Manager(so, window=window, batch=batch, theme=theme)
Manager(VerticalContainer([Button(label="Persistent button", on_press=f)]),
        window=window,
        batch=batch,
        theme=theme)

pyglet.app.run()
Beispiel #13
0
 def setUp(self):
     TestPygletGUI.setUp(self)
     self.button = Button(label="test")
     self.manager = Manager(self.button, window=self.window, batch=self.batch, theme=self.theme)
Beispiel #14
0
 def __init__(self, text, is_pressed=False, on_press=None):
     Button.__init__(self, text, is_pressed, on_press)
     HighlightMixin.__init__(self)
Beispiel #15
0
 def unload_graphics(self):
     Button.unload_graphics(self)
     HighlightMixin.unload_graphics(self)
 def __init__(self, text, is_pressed=False, on_press=None):
     Button.__init__(self, text, is_pressed, on_press)
     HighlightMixin.__init__(self)
 def setUp(self):
     TestPygletGUI.setUp(self)
     self.button = Button(label="test")
     GenericButtonTest.setUp(self)
Beispiel #18
0
            "unchecked": {
                "image": {
                    "source": "checkbox.png"
                }
            }
        }
    },
    resources_path='../theme/')


def f(y):
    print("\nholaMundo\n" + str(y))


# Set up a Manager
Manager(VerticalContainer([
    Button(label="Persistent button", on_press=f),
    OneTimeButton(label="One time button"),
    Checkbox(label="Checkbox"),
    GroupButton(group_id='1', label="Group 1:Button 1"),
    GroupButton(group_id='1', label="Group 1:Button 2"),
    GroupButton(group_id='2', label="Group 2:Button 1"),
    GroupButton(group_id='2', label="Group 2:Button 2"),
    GroupButton(group_id='2', label="Group 2:Button 3"),
]),
        window=window,
        batch=batch,
        theme=theme)

pyglet.app.run()
Beispiel #19
0
 def __init__(self, text, is_pressed=False, on_press=None):
     Button.__init__(self, text, is_pressed, on_press)
     FocusMixin.__init__(self)
 def unload_graphics(self):
     Button.unload_graphics(self)
     HighlightMixin.unload_graphics(self)
Beispiel #21
0
 def __init__(self, option_name, button_text="", is_selected=False, parent=None):
     Option.__init__(self, option_name, parent)
     Button.__init__(self, label=button_text, is_pressed=is_selected)
                   "checked": {
                       "image": {
                           "source": "checkbox-checked.png"
                       }
                   },
                   "unchecked": {
                       "image": {
                           "source": "checkbox.png"
                       }
                   }
               }
              }, resources_path='../theme/')

# First line has two big buttons
# second line has three spacers, separated by two small buttons.
# size of the three spacers is the same.
Manager(VerticalContainer([HorizontalContainer([Button(label="Big fat button"),
                                                Button(label="Big fat button")], padding=0),

                           HorizontalContainer([Spacer(),
                                                Button(label="Small"),
                                                Spacer(),
                                                Button(label="Small"),
                                                Spacer()], padding=0)],
                          padding=0),
        window=window,
        batch=batch,
        theme=theme)

pyglet.app.run()
                    "padding": [18, 18, 8, 6]
                },
                "text_color": [0, 0, 0, 255]
            },
            "up": {
                "image": {
                    "source": "button.png",
                    "frame": [6, 5, 6, 3],
                    "padding": [18, 18, 8, 6]
                }
            }
        }
    },
    resources_path='../theme/')

hlay = HorizontalContainer(content=[
    VerticalContainer(
        content=[Button("(1,1)"), Button("(1,2)")]),
    VerticalContainer(
        content=[Button("(2,1)"), Button("(2,2)")])
])

grid = GridContainer([[Button("(1,1)"), Button("(1,2)")],
                      [Button("(2,1)"), Button("(2,2)")]])

vlay = VerticalContainer([hlay, grid])

Manager(vlay, window=window, batch=batch, theme=theme)

pyglet.app.run()
        "button": {
            "down": {
                "image": {
                    "source": "button-down.png",
                    "frame": [8, 6, 2, 2],
                    "padding": [18, 18, 8, 6]
                },
                "text_color": [0, 0, 0, 255]
            },
            "up": {
                "image": {
                    "source": "button.png",
                    "frame": [6, 5, 6, 3],
                    "padding": [18, 18, 8, 6]
                }
            }
        }
    },
    resources_path='../theme/')

# Set up a Manager
Manager(Label("Drag me"), window=window, batch=batch, theme=theme)

Manager(Button("Drag me"),
        window=window,
        batch=batch,
        anchor=ANCHOR_TOP_LEFT,
        theme=theme)

pyglet.app.run()
Beispiel #25
0
                    "region": [0, 16, 16, 16],
                    "frame": [0, 6, 16, 4],
                    "padding": [0, 0, 0, 0]
                },
                "offset": [0, 0]
            },
            "bar": {
                "image": {
                    "source": "vscrollbar.png",
                    "region": [0, 64, 16, 16]
                },
                "padding": [0, 0, 0, 0]
            }
        }
    },
    resources_path='../theme/')

# Set up a Manager
Manager(
    # an horizontal layout with two vertical layouts, each one with a slider.
    Scrollable(
        height=100,
        width=200,
        content=VerticalContainer(content=[Button(str(x))
                                           for x in range(10)])),
    window=window,
    batch=batch,
    theme=theme)

pyglet.app.run()
Beispiel #26
0
    def __init__(self):
        t1=time.time()*1000
        g.meneWindowOpened = True
        label1=Label("My Menes",bold=True,color=g.loginFontColor)
        closeBtn =HighlightedButton("",on_release=self.delete,width=19,height=19,path='delete')
        self.meneCont= []
        self.menes=[]
        self.established=False
        for c in meneList:
            self.menes.append({"name":c.name,
                               "hp":c.hp,
                               "maxhp":c.maxhp,
                               "xp":c.xp,
                               "level":c.level,
                               "power":c.power,
                               "id":c.ID,
                               "defense":c.defense,
                               "speed":c.speed,
                               "attack1":c.attack1,
                               "attack2":c.attack2,
                               "attack3":c.attack3,
                               "attack4":c.attack4,
                               "sprite":c.spriteName,
                               "defaultmene":c.defaultMene})
        #self.menes = [{"name":"Hitler","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'americanbear'},{"name":"Stalin","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'lorslara'},{"name":"Ebin","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'squadlider'},{"name":"Mao","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'mongolbear'},{"name":"Uusi mene","hp":100,"level":1,"power":50,"defense":40,"speed":60,"sprite":'mongol'},{"name":"Hintti","hp":50,"level":15,"power":60,"defense":50,"speed":70,'sprite':'uusimene'}]
        self.selectedMene=getDefaultMeneID()
        
        for i in range(6):
            if i < len(self.menes):
                if self.menes[i]["id"]==self.selectedMene:
                    menebutton = Button("",on_press=self.updateWindow,width=64,height=64, argument=self.menes[i]["id"],texture=g.gameEngine.resManager.meneSprites[self.menes[i]["sprite"]]["portrait"],is_pressed=True,outline='menewindowbutton')
                else:
                    menebutton = Button("",on_press=self.updateWindow,width=64,height=64, argument=self.menes[i]["id"],texture=g.gameEngine.resManager.meneSprites[self.menes[i]["sprite"]]["portrait"],is_pressed=False,outline='menewindowbutton')
                nameLabel = Label(self.menes[i]["name"],bold=True,color=g.npcColor)
                levelLabel = Label("Lvl " + str(self.menes[i]["level"]),color=g.whiteColor,font_size=g.theme["font_size_small"])
                defaultMeneLabel=None
                if self.menes[i]["defaultmene"]==1:
                    defaultMeneLabel= Label('Default Mene',color=g.whiteColor,font_size=g.theme["font_size_small"])
                    #self.meneCont.append(HorizontalContainer(content=[menebutton,VerticalContainer(content=[nameLabel,levelLabel,defaultMeneLabel],align=HALIGN_LEFT)],align=HALIGN_CENTER))
                #else:
                self.meneCont.append(HorizontalContainer(content=[menebutton,VerticalContainer(content=[nameLabel,levelLabel,defaultMeneLabel],align=HALIGN_LEFT)],align=HALIGN_CENTER))
            else:
                
                menebutton = Button("",width=64,height=64,is_pressed=False,path='menewindowbutton',disabled=True)
                self.meneCont.append(menebutton)
       
        self.menelisting = VerticalContainer(content=[label1,VerticalContainer(content=self.meneCont,align=HALIGN_LEFT)])
        
        properties=Label("Mene Properties",bold=True,color=g.loginFontColor)
        #horzCont = HorizontalContainer(content=[properties,closeBtn])
        nameinfoLabel = Label("Name:",color=g.whiteColor)
        self.selectedNAME = Label("Uusi mene",bold=True,color=g.npcColor)
        
        levelinfoLabel = Label("Level:",color=g.whiteColor)
        self.selectedLevel = Label("0",bold=True,color=g.npcColor)
        
        hpinfoLabel = Label("HP:",color=g.whiteColor)
        self.selectedHp = Label("0",bold=True,color=g.npcColor)
        
        xpinfoLabel = Label("XP:",color=g.whiteColor)
        #self.selectedXp = Label("0",bold=True,color=g.npcColor)
        
        attackinfoLabel = Label("Power:",color=g.whiteColor)
        self.selectedAttack = Label("0",bold=True,color=g.npcColor)
        
        self.hpBar = HpBar()
        
        self.defaultButton = HighlightedButton("Set Default Mene :D",argument=None,on_release=makeDefaultMene)
        
        self.xpBar = HpBar(type="xp",height=20,width=100)
        
        defenseinfoLabel = Label("Defense:",color=g.whiteColor)
        self.selectedDefense = Label("0",bold=True,color=g.npcColor)
        
        speedinfoLabel = Label("Speed:",color=g.whiteColor)
        self.selectedSpeed = Label("0",bold=True,color=g.npcColor)
        
        #selectTheme = Theme({'uusimene': {
        #                "image": {
        #                    "source": 'uusimene_front.png'
        #                },
        #                "gui_color": [255,255,255,255]
        #            }
        #        },resources_path=g.dataPath+'/menes/'
        #    )
            
        self.picture = Graphic(texture=g.gameEngine.resManager.meneSprites['uusimene']['front'])
        abilities = ['burger', 'burger']
        #abilityTheme = self.constructAbilityTheme(abilities)
        abilityButtons=[]
        for i in xrange(4):
            #if i<len(abilities):
            #    self.abilityButtons.append(HoverGraphic(width=50,height=50,path=abilities[i],alternative=abilityTheme,outline='abilityoutline',hover=onHover,hoveringType=HOVERING_ABILITY,arguments={'name':'Burger Attack','type':'Attack','info':'Throws a burger at the enemy. Deals X damage.'}))
            #else:
            abilityButtons.append(Graphic(width=50,height=50,path='abilityoutline'))

        
        infoCont1 = VerticalContainer([nameinfoLabel,levelinfoLabel,xpinfoLabel],align=HALIGN_LEFT)
        infoCont2 = VerticalContainer([attackinfoLabel,defenseinfoLabel,speedinfoLabel],align=HALIGN_LEFT)
        statsCont1 = VerticalContainer([self.selectedNAME,self.selectedLevel,self.xpBar],align=HALIGN_LEFT)
        statsCont2 = VerticalContainer([self.selectedAttack,self.selectedDefense,self.selectedSpeed],align=HALIGN_LEFT)
        
        infoAndStatsCont = HorizontalContainer([infoCont1,statsCont1,infoCont2,statsCont2])
        
        self.abilityCont = HorizontalContainer(abilityButtons,padding=10)
        rightFrame = VerticalContainer(content=[properties,self.picture,self.hpBar,infoAndStatsCont,self.abilityCont,self.defaultButton])
        total = HorizontalContainer(content=[self.menelisting,Spacer(30,0),rightFrame,closeBtn],align=VALIGN_TOP)
        Manager.__init__(self,
            Frame(total),
            window=g.screen,
            batch=g.guiBatch,
            is_movable=False,
            anchor=ANCHOR_LEFT,
            offset=(40,int(g.SCREEN_HEIGHT*g.WINDOW_POSY_RELATIVE)),
            theme=g.theme)
        self.changeInfos(self.selectedMene)