def setup_selections(self, title, selections, select_cb): if self._selection_frame: self._selection_frame.destroy() self._selection_frame = None for i in self._selection_items: i.destroy() self._selection_items = [] num_items = len(selections) frame_size = num_items / 10.0 + 0.06 self._selection_frame = gui.Frame(parent=self.root, frame_color=(0.8, 0.8, 0.8, 0.5), frame_size=(-0.25, 0.25, 0.0, frame_size), pos=(0, 0, -1.0)) gui.Label(parent=self._selection_frame, text=title, text_scale=(0.05, 0.05), frame_color=(0, 0, 0, 0), pos=(0, 0, frame_size)) for idx, selection in enumerate(selections): btn = gui.Button(parent=self.root, style='button_combat', command=select_cb, extra_args=[idx], text=selection, frame_size=(-0.25, 0.25, -0.04, 0.04), pos=(0, 0, (0.1 * num_items - 1.02) - 0.1 * idx)) self._selection_items.append(btn)
def _create_pc_frame(self, n): frame = gui.Frame(parent=self.root_right, frame_color=(0.8, 0.8, 0.8, 0.5), frame_size=(-0.4, 0.4, -0.075, 0.075), pos=(-0.45 - 0.05 * n, 0, -0.55 - 0.175 * n)) frame.label = gui.Label(parent=frame, text='', text_scale=(0.04, 0.04), text_align=p3d.TextNode.ALeft, frame_color=(0, 0, 0, 0), pos=(-0.375, 0, 0.04)) frame.hpbar = gui.WaitBar( parent=frame, value=100, text='0/0', text_scale=(0.025, 0.025), text_pos=(0, -0.01), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 0.8), frame_color=(0, 0, 0, 1), frame_size=(-0.35, 0.35, -0.015, 0.015), ) frame.attacklabel = gui.Label( parent=frame, text='', text_scale=(0.03, 0.03), text_align=p3d.TextNode.ALeft, pos=(-0.375, 0, -0.05), ) return frame
def __init__(self): super().__init__() self._selection_items = [] gui.Frame(parent=self.root_full, style='title_bg') gui.Label(parent=self.root, style='text_title', text='Prototype Hydrogen', pos=(0.0, 0.0, 0.8))
def __init__(self): super().__init__() self._selection_items = [] self._mech_frames = [] self._back_btn = None gui.Frame(parent=self.root_full, frame_color=(0.8, 0.8, 0.8, 0.8), frame_size=(-1.0, 1.0, -1.0, 1.0))
def __init__(self): for idx, root in enumerate(self._roots): setattr( self, root[0], gui.Frame( parent=getattr(base, root[1]), #frame_color=(0.2 * (idx+1), 0, 0, 0.5), frame_color=(0, 0, 0, 0), frame_size=(-1, 1, -1, 1), pos=(0, 0, 0))) if gui.global_theme is None: gui.global_theme = gui.Theme.from_file('style.theme')
def setup_status(self, mechs, back_cb=None, back_args=[]): for i in self._mech_frames: i.destroy() self._mech_frames = [] if self._back_btn: self._back_btn.destroy() for idx, mech in enumerate(mechs): frame = gui.Frame(parent=self.root, frame_color=(0.3, 0.3, 0.3, 0.5), frame_size=(-0.9, 0.9, -0.20, 0.20), pos=(0.0, 0.0, 0.70 - 0.50 * idx)) frame.label = gui.Label(parent=frame, style='text_base', text=mech.name, pos=(-0.85, 0, 0.15)) frame.hp = gui.Label(parent=frame, style='text_base', text="HP: {}".format(mech.health), pos=(-0.80, 0, 0.05)) frame.attack = gui.Label(parent=frame, style='text_base', text="ATK: {}".format(mech.health), pos=(-0.30, 0, 0.05)) frame.roles = gui.Label(parent=frame, style='text_base', text="Roles: {}".format(', '.join( mech.roles)), pos=(-0.80, 0, -0.05)) self._mech_frames.append(frame) if back_cb: self._back_btn = gui.Button(parent=self.root, style='button_general', command=back_cb, extra_args=back_args, text='Back', frame_size=(-0.25, 0.25, -0.04, 0.04), pos=(-0.2, 0, -0.9))
def _create_ec_frame(self, n, empty=False): frame_per_column = 12 col = n // frame_per_column row = n % frame_per_column frame = gui.Frame(parent=self.root_left, frame_color=(0.8, 0.8, 0.8, 0.5), frame_size=(-0.2, 0.2, -0.08, 0.08), pos=(0.215 + 0.405 * col, 0, -1.075 + 0.167 * frame_per_column - 0.167 * row)) if not empty: frame.label = gui.Label(parent=frame, text='', text_scale=(0.035, 0.035), text_align=p3d.TextNode.ALeft, frame_color=(0, 0, 0, 0), pos=(-0.175, 0, 0.025)) frame.hpbar = gui.WaitBar( parent=frame, value=100, text='0/0', text_scale=(0.025, 0.025), text_pos=(0, -0.006), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 0.8), frame_color=(0, 0, 0, 1), frame_size=(-0.15, 0.15, -0.01, 0.01), ) frame.attacklabel = gui.Label( parent=frame, text='', text_scale=(0.025, 0.025), text_align=p3d.TextNode.ALeft, pos=(-0.175, 0, -0.05), ) return frame
def main(): pygame.init() screen = pygame.display.set_mode((800, 600)) input = gui.Input() the_gui = gui.Gui(input) input.addMouseListener(the_gui) input.addKeyboardListener(the_gui) box = gui.Box() box.setPosition(0, 0) box.setDimensions(10, 10) box.setPaddings(Pad(1, 2, 3, 4)) box.setBorders(Pad(10, 10, 4, 4)) box.setMargins(Pad(9, 10, 11, 12)) container = gui.Container() the_gui.addWidget(container) container.addWidget(box) content_area = box.getContentArea() padded_area = box.getPaddedArea() bordered_area = box.getBorderedArea() whole_area = box.getWholeArea() # Testing parenting: frame = gui.Frame() frame.setPosition(0, 0) #frame.setMargins(EqualPad(4)) frame.setBorders(EqualPad(1)) frame.setPaddings(Pad(2, 2, 20, 2)) frame.setDimensions(200, 200) #frame.setLayout(gui.GridLayout(3,4)) #frame.setLayout(gui.GridLayout(2, 4, Align.TOP)) frame.setLayout(gui.VerticalLayout()) the_gui.addWidget(frame) for i in range(0, 8): box = gui.Box() box.setPosition(0, 0) #size = 10 + random.randint(0,4) width = i * 5 height = i * 5 box.setBorders(Pad(1, 1, 1, 1)) box.setMargins(Pad(5, 5, 5, 5)) frame.addWidget(box) box.setDimensions(width, height) # Testing clipping: frame = gui.Frame() frame.setPosition(340, 0) frame.setMargins(Pad(4, 4, 4, 4)) frame.setBorders(Pad(1, 1, 1, 1)) frame.setDimensions(80, 200) frame.setPaddings(EqualPad(15)) the_gui.addWidget(frame) inner_frame = gui.Frame() inner_frame.setPosition(40, 0) inner_frame.setMargins(Pad(4, 4, 4, 4)) inner_frame.setBorders(Pad(1, 1, 1, 1)) inner_frame.setDimensions(180, 100) frame.addWidget(inner_frame) inner_frame.setLayout(gui.GridLayout(3, 5)) for i in range(0, 12): col = i % 3 row = i / 3 box2 = gui.Box() box2.setPosition(0, 0) #size = 10 + random.randint(0,4) width = col * 10 height = row * 5 box2.setDimensions(width, height) box2.setBorders(Pad(1, 1, 1, 1)) box2.setMargins(Pad(5, 5, 5, 5)) inner_frame.addWidget(box2) img = gui.loadImage("res/aircraft.png") image_widget = gui.Image(img) image_widget.setPosition(0, 0) image_widget.setBorders(Pad(3, 3, 3, 3)) image_widget.setDimensions(100, 100) inner_frame.addWidget(image_widget) # Testing ImageButton img_default = gui.loadImage("res/truck.png") img_pressed = gui.loadImage("res/truck_bnw.png") img_button = gui.ImageButton(img_default, img_pressed) img_button.setPosition(20, 200) img_button.setDimensions(30, 30) the_gui.addWidget(img_button) # Testing elements alignment: frame = gui.Frame() frame.setDimensions(200, 200) frame.setLayout(gui.GridLayout(2, 6)) frame.setPosition(0, 300) the_gui.addWidget(frame) run = True while (run): for event in pygame.event.get(): if event.type == pygame.QUIT: run = False input.handleEvent(event) screen.fill((255, 255, 255)) the_gui.draw(screen) pygame.display.flip() pygame.quit()