def __init__(self, closeButton=True): g.selectMeneWindowOpened = True self.currentMeneID = g.currMeneID self.selectMeneID = None self.meneCont = [] self.meneButtons = [] self.closeButton = closeButton self.constructMeneButtons() selectButton = HighlightedButton("Select Mene", on_release=self.selectMene, width=150, height=30) if closeButton: closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') cont = VerticalContainer(content=[ HorizontalContainer(content=[Spacer(0, 0), closeBtn]), HorizontalContainer(content=self.meneCont), Spacer(0, 10), selectButton ]) else: cont = VerticalContainer(content=[ HorizontalContainer(content=self.meneCont), Spacer(0, 10), selectButton ]) Manager.__init__(self, Frame(cont), window=g.screen, batch=g.guiBatch, is_movable=False, offset=(0, 0), theme=g.theme)
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)
def __init__(self, ability1=None, ability2=None, ability3=None, ability4=None): self.a1 = ability1 self.a2 = ability2 self.a3 = ability3 self.a4 = ability4 #self.abilityCont=[] abilityButtons = [] for i in xrange(4): abilityButtons.append( Graphic(width=100, height=100, path='abilityoutline')) self.abilityCont = HorizontalContainer(content=abilityButtons, align=VALIGN_BOTTOM) Manager.__init__(self, self.abilityCont, window=g.screen, batch=g.guiBatch, is_movable=False, anchor=ANCHOR_BOTTOM, offset=(0, 0), theme=g.theme) self.constructAbilityButtons()
def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Controller.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalContainer([ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalContainer([ self.book, Label(title, path=["section"]), ]), path=["section", "center"]), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(self.folding_content) VerticalContainer.__init__(self, content=layout, align=align)
def __init__(self,name,text,a=0): if text[0]=='>': color=g.greentextColor else: color=g.postColor if a>0: if a==ADMIN_MODERATOR: nameColor=g.modColor appendix='#Mod#' elif a==ADMIN_ADMIN: nameColor=g.adminColor appendix='#Admin#' else: nameColor=g.adminColor appendix='#Owner#' else: nameColor=g.nameColor appendix='' if appendix: horz=HorizontalContainer(content=[Label(name,bold=True,color=nameColor),Label(appendix+':',color=nameColor),Label(text,color=color)]) else: horz=HorizontalContainer(content=[Label(name+':',bold=True,color=nameColor),Label(text,color=color)]) Manager.__init__(self, Frame(horz), window=g.screen, batch=g.chatBubbleBatch, anchor=ANCHOR_BOTTOM_LEFT, is_movable=False, offset=(0,0), theme=g.chatTheme)
def __init__(self, name, title, icon, client, dam, hit, arm, gold, desc=""): self.client = client self.name = name self.title = title icon = Graphic(path=['icons', icon]) title = Label(self.title) gold = Label("%sg" % gold, color=[230, 244, 68, 255]) 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]), ]) take_button = OneTimeButton(label='Take', on_release=self.take) HorizontalContainer.__init__(self, [icon, title, gold, stats, take_button], align=HALIGN_LEFT)
def setUp(self): super(TestHorizontalContainer, self).setUp() self.container = HorizontalContainer([Viewer(width=50, height=50), Viewer(width=50, height=50)]) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
def bagHoverTemplate(money, es): moneyTmp = money / 100.0 moneyCont = HorizontalContainer( content=[Label("%.2f" % moneyTmp), Graphic("euro")]) esCont = HorizontalContainer( content=[Label("%s" % es), Graphic('es_icon')]) return VerticalContainer(content=[esCont, moneyCont], align=HALIGN_RIGHT)
def __init__(self): g.postWindowOpened = True label1 = Label("Notifications", bold=True, color=g.loginFontColor) closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') self.postCont = [] #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=self.menes[0]["name"] for c in g.mails: label = Label(c["s"], bold=True, color=g.guiNameColor, font_size=g.theme["font_size"] + 2) label1 = Label(c["t"][:16] + '...', color=g.whiteColor) deleteBtn = HighlightedButton("", on_release=self.deletemail, width=14, height=14, path='delete_alt', argument=c["id"]) openBtn = HighlightedButton("", on_release=self.openmail, width=20, height=21, path='mailopen', argument=c["id"]) self.postCont.append( VerticalContainer(content=[ HorizontalContainer(content=[openBtn, label, deleteBtn]), label1 ], align=HALIGN_LEFT)) self.vertCont = VerticalContainer(self.postCont, align=VALIGN_TOP) self.report = Document("", is_fixed_size=True, height=g.SCREEN_HEIGHT / 2, width=g.SCREEN_WIDTH / 5) self.scrollable = Scrollable(content=self.vertCont, height=g.SCREEN_HEIGHT / 2, width=g.SCREEN_WIDTH / 5) total = HorizontalContainer( content=[self.scrollable, self.report, 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) if len(self.postCont) > 0: self.openmail(self.postCont[0]._content[0]._content[0].arg)
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, title, align=HALIGN_CENTER): if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False HorizontalContainer.__init__(self, content=[ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(Label(title, path=["section"]), path=['section', 'center']), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0)
def __init__(self, window, batch, space, level, height, width): self.space = space self.level = level self.height = height self.width = width progress_text = "Progress: ..." self.progress_doc = Document(progress_text, width=width / 2) objective_doc = Document(level.objective, width=width / 2) left_frame = Frame(VerticalContainer( [objective_doc, None, self.progress_doc]), is_expandable=True) self.left_container = VerticalContainer([left_frame]) victory_formula = level.victory_condition[0] info_frame = self.create_info_frame(victory_formula) self.info_container = VerticalContainer([info_frame]) container = HorizontalContainer( [self.left_container, self.info_container]) self.manager = Manager(container, window=window, batch=batch, group=RenderingOrder.hud, anchor=ANCHOR_BOTTOM_LEFT, theme=theme, is_movable=False) self.window = window self.window.push_handlers(on_draw=self.on_draw) self.tick = 0 self.init_effects(space, level)
def __init__(self, client, inventory=[]): self.client = client invitems = [] for name, value in inventory.items(): title = value['title'] icon = value['icon'] dam = value['dam'] hit = value['hit'] arm = value['arm'] gold = value['value'] invitems.append( Frame(ContainerItem(name, title, icon, self.client, dam, hit, arm, gold), is_expandable=True)) self.container_inventory_list = Scrollable(height=256, width=512, is_fixed_size=True, content=VerticalContainer( invitems, align=HALIGN_LEFT)) self.exit_button = OneTimeButton(label='Close', on_release=self.close) self.inventory_container = HorizontalContainer( [self.container_inventory_list, self.exit_button]) Manager.__init__(self, Frame(self.inventory_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True)
def setUp(self): super().setUp() self.container = HorizontalContainer([Viewer(width=50, height=50), Viewer(width=50, height=50)]) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Controller.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalContainer([Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalContainer([ self.book, Label(title, path=["section"]), ]), path=["section", "center"]), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(self.folding_content) VerticalContainer.__init__(self, content=layout, align=align)
def __init__(self, name, level, hp, maxhp): self.nameLabel = Label(name, color=g.whiteColor, font_size=g.theme["font_size"] + 2, bold=True) self.levelLabel = Label('Lvl: ' + str(level), color=g.whiteColor, font_size=g.theme["font_size"] + 2, bold=True) self.hpBar = HpBar() Manager.__init__( self, VerticalContainer(content=[ HorizontalContainer( content=[self.nameLabel, None, self.levelLabel]), self.hpBar ], align=HALIGN_LEFT), window=g.screen, batch=g.guiBatch, is_movable=False, anchor=ANCHOR_BOTTOM_LEFT, offset=(0, 0), theme=g.theme) self.hpBar.setHP(hp, maxhp)
def __init__(self, title, content): VerticalContainer.__init__(self, content=[ HorizontalContainer([Graphic(path=["titlebar", "left"], is_expandable=True), Frame(Label(title, path=["titlebar"]), path=["titlebar", "center"]), Graphic(path=["titlebar", "right"], is_expandable=True), ], align=VALIGN_BOTTOM, padding=0), Frame(content, path=["titlebar", "frame"], is_expandable=True), ], padding=0)
def __init__(self): g.reportWindowOpened = True getReport() label1 = Label("Send Ticket", bold=True, color=g.loginFontColor) closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') horzCont = HorizontalContainer(content=[label1, None, closeBtn]) #self.infoLabel = Label("No reports founds") self.reportInput = TextInput(text="", padding=5, length=16, max_length=400, width=g.SCREEN_WIDTH / 3, height=g.SCREEN_HEIGHT / 3, multiline=True) clearBtn = HighlightedButton("Clear", on_release=self.clear, width=120, height=30) deleteBtn = HighlightedButton("Delete", on_release=self.remove, width=120, height=30) sendBtn = HighlightedButton("Send", on_release=self.send, width=120, height=30) buttons = HorizontalContainer(content=[clearBtn, deleteBtn, sendBtn]) frame = Frame( VerticalContainer(content=[horzCont, self.reportInput, buttons])) Manager.__init__(self, frame, window=g.screen, batch=g.guiBatch, is_movable=False, theme=g.theme) frame.expand(g.SCREEN_WIDTH / 2, height=g.SCREEN_HEIGHT / 4 * 3)
def __init__(self): g.ignoreWindowOpened = True label1 = Label("Ignore List", bold=True, color=g.loginFontColor) closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') title = [label1, None, closeBtn] ignores = [] for c in ignoreList: ignores.append(c) ignores.sort() ignoreCont = [] for c in ignores: label = HighlightedButton(c, width=150, height=24, path='baroutline_btn', on_release=self.constructSelect, argument=c, align=HALIGN_LEFT, font_color=g.guiNameColor) ignoreCont.append(label) #label=Label(c,bold=True,color=g.nameColorLighter) #removeBtn = HighlightedButton("",on_release=self.removeIgnore,width=24,height=24,path='ignoreremove',argument=c) #ignoreCont.append(HorizontalContainer(content=[label,removeBtn])) addBtn = HighlightedButton("Ignore Player", on_release=addIgnorePopup, width=100, height=24) horzCont = HorizontalContainer(content=title) frame = Frame( VerticalContainer(content=[ horzCont, Scrollable(height=400, width=400, content=VerticalContainer(content=ignoreCont, align=HALIGN_LEFT, padding=0)), addBtn ])) Manager.__init__( self, frame, 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)
def __init__(self, client, quests): self.client = client quest_list = [] for quest in quests: quest_title = Label(quest['title']) quest_container = HorizontalContainer([quest_title]) quest_list.append(quest_container) close_button = OneTimeButton(label="Close", on_release=self.close) quest_container = VerticalContainer(quest_list) button_container = HorizontalContainer([close_button]) questlog_container = VerticalContainer( [quest_container, button_container]) Manager.__init__(self, Frame(questlog_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True)
def setUp(self): TestPygletGUI.setUp(self) self.widgets = [] for i in range(2): self.widgets.append(Viewer(width=100, height=50)) for i in range(2): self.widgets.append(Viewer(width=20, height=50)) self.container = VerticalContainer([ HorizontalContainer([self.widgets[0], self.widgets[1]], padding=0), HorizontalContainer([ Spacer(), self.widgets[2], Spacer(), self.widgets[3], Spacer() ], padding=0) ], padding=0) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
def manager(self): self.managerList += [ Manager(HorizontalContainer( [OneTimeButton(label="Continuar", on_release=self.nextWindow)]), window=self, batch=self.batch, theme=getTheme(), anchor=ANCHOR_BOTTOM_RIGHT, offset=(-80, 5), is_movable=False) ] self.managerList += [ Manager(VerticalContainer([ Checkbox(label="El CPU Inicia ", on_press=self.setCPUStarts, is_pressed=self.CPUStarts), Checkbox(label="El CPU es blancas", on_press=self.setCPUPlayWhite, is_pressed=self.CPUPlayWhite), Label(""), Label("Enroque de negras"), Checkbox(label="Lado de la Reina ", on_press=self.setBlackQueenCastling, is_pressed=self.blackQueenCastling), Checkbox(label="Lado del Rey ", on_press=self.setBlackKingCastling, is_pressed=self.blackKingCastling), Label(""), Label("Enroque de blancas"), Checkbox(label="Lado de la Reina ", on_press=self.setWhiteQueenCastling, is_pressed=self.whiteQueenCastling), Checkbox(label="Lado del Rey ", on_press=self.setWhiteKingCastling, is_pressed=self.whiteKingCastling) ]), window=self, batch=self.batch, theme=getTheme(), anchor=ANCHOR_RIGHT, offset=(-50, -95), is_movable=False) ]
def initNameMene(self): def sendMeneName(event): self.menename = self.nameInput.get_text() if len(self.menename) > 0: self.saveBtn.disabled = True self.naming = True label = Label("Name Your Mene", color=g.postColor, font_size=18, bold=True) #meneTheme = Theme({g.spriteName: { # "image": { # "source": g.spriteName+'_front.png' # }, # "gui_color": [255,255,255,255] # } # },resources_path=g.dataPath+'/menes/' #) #picture = Graphic(g.spriteName,alternative=meneTheme) picture = Graphic( texture=g.gameEngine.resManager.meneSprites[g.spriteName]['front']) self.nameInput = TextInput(text="", padding=2, length=12, max_length=12, width=200, font_size=16) self.saveBtn = HighlightedButton(label="Save", on_release=sendMeneName, width=100, height=40, font_size=16) frame = Frame(VerticalContainer(content=[ label, picture, HorizontalContainer([self.nameInput, self.saveBtn]) ]), path='frame_npc_talk') self.meneMan = Manager(frame, window=self.screen, batch=g.guiBatch, theme=g.theme, offset=(0, 0), is_movable=False)
def manager(self): Manager(Label(""), window=self, batch=self.batch, theme=getTheme()) Manager(Frame(self.document), window=self, batch=self.batch, theme=getTheme(), anchor=ANCHOR_TOP_RIGHT, offset=(-10, -75), is_movable=False) Manager(HorizontalContainer([ OneTimeButton(label="Guardar", on_release=self.saveGame), OneTimeButton(label="Volver", on_release=self.onclose) ]), window=self, batch=self.batch, theme=getTheme(), anchor=ANCHOR_BOTTOM_RIGHT, offset=(-50, 15), is_movable=False) self.document.set_text("")
def __init__(self, text="", ok="Ok", cancel="Cancel", window=None, batch=None, group=None, theme=None, on_ok=None, on_cancel=None, argument=None,offset=(0,0)): self.arg=argument def on_ok_click(_): if on_ok is not None: on_ok(self.arg) self.delete() def on_cancel_click(_): if on_cancel is not None: on_cancel(self.arg) self.delete() Manager.__init__(self, content=Frame( VerticalContainer([ Label(text), HorizontalContainer([HighlightedButton(ok, on_release=on_ok_click), HighlightedButton(cancel, on_release=on_cancel_click)] )]) ), window=window, batch=batch, group=group, theme=theme, is_movable=True,offset=offset)
def __init__(self, client): self.client = client self.message_container = VerticalContainer(content=[], align=HALIGN_LEFT) self.messages = Scrollable(height=100, width=300, is_fixed_size=True, content=self.message_container) self.text_input = TextInput("", length=20, max_length=256) self.send_button = OneTimeButton("Send", on_release=self.submit_message) self.enter_field = HorizontalContainer( [self.text_input, self.send_button]) self.chat_window = VerticalContainer([self.messages, self.enter_field]) Manager.__init__(self, Frame(self.chat_window, path='chatFrame'), window=self.client.window, theme=UI_THEME, is_movable=True, anchor=ANCHOR_BOTTOM_LEFT)
def __init__(self, client, name, title, dialog): self.client = client self.name = name title = Label(title, font_size=12) dialog = pyglet.text.decode_text(dialog) document = Document(dialog, width=300, height=100) accept_button = OneTimeButton(label="Ok, I'll do it!", on_release=self.accept) reject_button = OneTimeButton(label="No, Thanks.", on_release=self.reject) text_container = VerticalContainer([title, document]) button_container = HorizontalContainer([accept_button, reject_button]) quest_container = VerticalContainer([text_container, button_container]) Manager.__init__(self, Frame(quest_container, is_expandable=True), window=self.client.window, theme=UI_THEME, is_movable=True)
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()
def __init__(self): g.adminWindowOpened = True label1=Label("Admin Menu",bold=True,color=g.loginFontColor) closeBtn = closeBtn =HighlightedButton("",on_release=self.delete,width=19,height=19,path='delete') adminSayBtn=HighlightedButton("Admin say",on_release=self.adminSay,width=120,height=25) muteBtn=HighlightedButton("Mute player",on_release=self.mutePlayer,width=120,height=25) unmuteBtn=HighlightedButton("Unmute player",on_release=self.unmutePlayer,width=120,height=25) teleportBtn=HighlightedButton("Teleport player",on_release=self.teleportPlayer,width=120,height=25) banBtn=HighlightedButton("Ban player",on_release=self.banPlayer,width=120,height=25) unbanBtn=HighlightedButton("Unban player",on_release=self.unbanPlayer,width=120,height=25) reportBtn=HighlightedButton("Reports",on_release=self.reports,width=120,height=25) #addBtn = HighlightedButton("",on_release=self.addFriend,width=24,height=24,path='friendadd') horzCont = HorizontalContainer(content=[label1,closeBtn]) frame = Frame(VerticalContainer(content=[horzCont,adminSayBtn,muteBtn,unmuteBtn,teleportBtn,banBtn,unbanBtn,reportBtn])) Manager.__init__(self, frame, 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)
def __init__(self): g.keybindingsWindowOpened = True self.resW = g.SCREEN_WIDTH self.resH = g.SCREEN_HEIGHT self.fullscreen = g.FULLSCREEN self.vsync = g.VSYNC self.screenSelected = g.SCREENSELECTED screens = pyglet.window.get_platform().get_default_display( ).get_screens() screenopts = [] for i in range(len(screens)): screenopts.append(str(i)) if int(self.screenSelected) >= 0 and int( self.screenSelected) < len(screens): screenopts.insert(0, str(self.screenSelected)) options = [] modes = pyglet.window.get_platform().get_default_display( ).get_default_screen().get_modes() for i in modes: if i.width >= 1024 and i.height >= 720: opt = str(int(i.width)) + ':' + str(int(i.height)) if opt not in options: options.append(opt) options.insert(0, str(g.SCREEN_WIDTH) + ':' + str(g.SCREEN_HEIGHT)) titleText = Label("Video Settings", color=g.loginFontColor, font_size=g.theme["font_size"] + 2) windowTypeInfo = Label("Window mode") if g.FULLSCREEN: windowType = Dropdown(['Fullscreen', 'Windowed'], on_select=self.selection) else: windowType = Dropdown(['Windowed', 'Fullscreen'], on_select=self.selection) horz = HorizontalContainer([windowTypeInfo, windowType]) resolutionInfo = Label("Resolution") resolutionType = Dropdown(options, on_select=self.resSelect) horz1 = HorizontalContainer([resolutionInfo, resolutionType]) vsyncBtn = Checkbox("VSync", on_press=self.vsyncSelect, is_pressed=self.vsync, align=HALIGN_LEFT) resolutionInfo = Label("Monitor") resolutionType = Dropdown(screenopts, on_select=self.screenSelect) horz3 = HorizontalContainer([resolutionInfo, resolutionType]) discardBtn = HighlightedButton(label="Discard", on_release=self.delete, width=120, height=30) saveBtn = HighlightedButton(label="Save", on_release=self.onSave, width=120, height=30) horzBtn = HorizontalContainer([discardBtn, saveBtn]) Manager.__init__(self, Frame( VerticalContainer([ titleText, horz, horz1, vsyncBtn, horz3, horzBtn ])), window=g.screen, batch=g.guiBatch, theme=g.theme, is_movable=False)
class FoldingSection(VerticalContainer, Controller): def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Controller.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalContainer([Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalContainer([ self.book, Label(title, path=["section"]), ]), path=["section", "center"]), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(self.folding_content) VerticalContainer.__init__(self, content=layout, align=align) def set_manager(self, manager): Controller.set_manager(self, manager) self.header.set_manager(manager) self.header.parent = self for item in self._content: if item == self.header: continue item.set_manager(self._manager) item.parent = self def _get_image_path(self): if self.is_open: return ["section", "opened"] else: return ["section", "closed"] def hit_test(self, x, y): return self.header.is_inside(x, y) def on_mouse_press(self, x, y, button, modifiers): self.is_open = not self.is_open self.book._path = self._get_image_path() self.book.reload() if self.is_open: self.add(self.folding_content) else: self.remove(self.folding_content) def delete(self): if not self.is_open: self.folding_content.delete() self.folding_content = None VerticalContainer.delete(self)
def __init__(self, name, text, actionType=0): g.npcTalkWindowOpened = True g.cursorRound = -1 self.name = name sendTalkToNpc(name) if actionType == NPC_ACTIONTYPE_SHOP: namecolor = g.npcColor postcolor = g.whiteColor path = 'frame_npc_talk_shop' else: namecolor = g.npcColorLighter postcolor = g.postColor path = 'frame_npc_talk' label1 = Label(name, color=namecolor, bold=True) closeBtn = HighlightedButton("", on_release=self.delete, width=19, height=19, path='delete') horzCont = HorizontalContainer(content=[label1, None, closeBtn]) self.yourmoney = None w1 = int(300 * (g.SCREEN_WIDTH / 1920.)) + 50 h1 = int(500 * (g.SCREEN_HEIGHT / 1080.)) textArr = text.split('\n\n') realText = "" for c in textArr: if c[0] == '>': realText += '{color ' + str( g.greentextColor) + '}' + c + '\n\n' else: realText += '{color ' + str(postcolor) + '}' + c + '\n\n' realText = realText[:-2] document = pyglet.text.decode_attributed(realText) self.textArea = Document(document, width=w1, height=h1, background=False, font_size=g.chatTheme["font_size"], font_name=g.chatTheme["font"]) if actionType == NPC_ACTIONTYPE_HEAL: healButton = HighlightedButton("Heal my menes", on_release=self.healButton) okButton = HighlightedButton("Goodbye", on_release=self.delete) cont = VerticalContainer(content=[ horzCont, self.textArea, HorizontalContainer([healButton, okButton]) ]) elif actionType == NPC_ACTIONTYPE_SHOP: #TODO: When more items, do a loop that adds then dynamically instead of statically like this disabled = False if Items["es"]["cost"] > g.moneyAmount: # print "TAPAHTU" disabled = True self.esButton = AbilityButton( width=50, height=50, argument=Items["es"]["id"], disabled=disabled, on_press=buyItem, texture=g.gameEngine.resManager.items[Items["es"]["sprite"]], outline='abilityoutline', hover=onHover, hoveringType=HOVERING_ITEM, arguments={ 'name': Items["es"]["name"], 'info': Items["es"]["info"], "args": () }) nameLabel = Label(Items["es"]["name"], color=g.npcColor) esCost = Items["es"]["cost"] / 100.0 costLabel = Label("%.2f" % esCost) euroPicture = Graphic("euro") costCont = HorizontalContainer(content=[costLabel, euroPicture]) infoCont = VerticalContainer( content=[Spacer(), nameLabel, costCont], align=HALIGN_LEFT) itemCont = HorizontalContainer(content=[self.esButton, infoCont]) moneyTmp = g.moneyAmount / 100.0 self.yourmoney = Label('%.2f' % moneyTmp) yourmoneyCont = HorizontalContainer( content=[self.yourmoney, Graphic("euro")]) self.yourES = Label('%s' % g.esAmount) yourESCont = HorizontalContainer( content=[self.yourES, Graphic("es_icon")]) okButton = HighlightedButton("Goodbye", on_release=self.delete) cont = VerticalContainer(content=[ horzCont, self.textArea, itemCont, Spacer(0, 20), HorizontalContainer(content=[ Spacer(), VerticalContainer(content=[yourmoneyCont, yourESCont], align=HALIGN_RIGHT) ]), okButton ]) else: okButton = HighlightedButton("Goodbye", on_release=self.delete) cont = VerticalContainer( content=[horzCont, self.textArea, okButton]) frame = Frame(cont, path=path) Manager.__init__( self, frame, 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)
class TestHorizontalContainer(TestPygletGUI): """ This test case tests basic functionality of an horizontal container. """ def setUp(self): super().setUp() self.container = HorizontalContainer([Viewer(width=50, height=50), Viewer(width=50, height=50)]) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme) def _test_content_position(self): """ Tests the position of the two widgets within the container. """ # first widget x is the left x (container.x) self.assertEqual(self.container.content[0].x, self.container.x) # second widget x is the left x (container.x + container.content[0].width) # plus the padding (self.container.padding) self.assertEqual(self.container.content[1].x, self.container.x + self.container.content[0].width + self.container.padding) def test_top_down_draw(self): """ Tests that the manager's size was set according to the child size. """ # manager size is correct self.assertEqual(self.manager.width, 100 + self.container.padding) self.assertEqual(self.manager.height, 50) # widget is centered in the window self.assertEqual(self.container.x, self.window.width/2 - self.container.width/2) self.assertEqual(self.container.y, self.window.height/2 - self.container.height/2) self._test_content_position() def test_bottom_up_draw(self): """ Tests that the manager's size is modified if we set a new size to the widget. """ self.container.content[0].width = 60 self.container.content[0].height = 60 self.container.content[0].parent.reset_size() # manager width was set self.assertEqual(self.manager.width, 110 + self.container.padding) # container height was set self.assertEqual(self.container.height, 60) # container and manager were re-centered in the window self.assertEqual(self.container.x, self.window.width/2 - self.container.width/2) self.assertEqual(self.manager.y, self.window.height/2 - self.manager.height/2) self._test_content_position() def test_add_widget(self): self.container.add(Viewer(width=50, height=50)) self.assertEqual(self.manager.width, 150 + 2*self.container.padding) self.assertEqual(self.manager.height, 50) self._test_content_position() def test_remove_widget(self): self.container.remove(self.container.content[0]) self.assertEqual(self.manager.width, 50 + self.container.padding) self.assertEqual(self.manager.height, 50) def tearDown(self): self.manager.delete() super().tearDown()
class FoldingSection(VerticalContainer, Controller): def __init__(self, title, content=None, is_open=True, align=HALIGN_CENTER): Controller.__init__(self) if align == HALIGN_LEFT: left_expand = False right_expand = True elif align == HALIGN_CENTER: left_expand = True right_expand = True else: # HALIGN_RIGHT left_expand = True right_expand = False self.is_open = is_open self.folding_content = content self.book = Graphic(self._get_image_path()) self.header = HorizontalContainer([ Graphic(path=["section", "left"], is_expandable=left_expand), Frame(HorizontalContainer([ self.book, Label(title, path=["section"]), ]), path=["section", "center"]), Graphic(path=["section", "right"], is_expandable=right_expand), ], align=VALIGN_BOTTOM, padding=0) layout = [self.header] if self.is_open: layout.append(self.folding_content) VerticalContainer.__init__(self, content=layout, align=align) def set_manager(self, manager): Controller.set_manager(self, manager) self.header.set_manager(manager) self.header.parent = self for item in self._content: if item == self.header: continue item.set_manager(self._manager) item.parent = self def _get_image_path(self): if self.is_open: return ["section", "opened"] else: return ["section", "closed"] def hit_test(self, x, y): return self.header.is_inside(x, y) def on_mouse_press(self, x, y, button, modifiers): self.is_open = not self.is_open self.book._path = self._get_image_path() self.book.reload() if self.is_open: self.add(self.folding_content) else: self.remove(self.folding_content) def delete(self): if not self.is_open: self.folding_content.delete() self.folding_content = None VerticalContainer.delete(self)