def __init__(self, tile): super().__init__() # dict from localmap self.tile = tile #print(self.tile) if self.tile is not None: self.terrain = glooey.Image( pyglet.resource.image( str(self.tile["terrain"].ident) + ".png")) self.insert(self.terrain, 0) if self.tile["furniture"] is not None: self.furniture = glooey.Image( pyglet.resource.image( str(self.tile["furniture"].ident) + ".png")) self.insert(self.furnitureg, 1) # only one item is ever shown if len(self.tile["items"]) > 0: self.item = glooey.Image( pyglet.resource.image( str(self.tile["items"][0].ident) + ".png")) self.insert(self.item, 2) if self.tile["creature"] is not None: self.creature = glooey.Image( pyglet.resource.image( str(self.tile["creature"].tile_ident) + ".png")) self.insert(self.creature, 3)
def __init__(self): super().__init__() self.current_level = 0 self.seed = random.randint(1000000000000000,9000000000000000) print('using seed', str(self.seed)) self.current_room_x = 2 self.current_room_y = 2 self.current_room = None self.dungeon = dict() self.dungeon[self.current_level] = DungeonLevel(self.current_level) self.player = Player() # setup player according to chosen starting weapon and stats # find the current room the player is in for room in self.dungeon[self.current_level].rooms: if room.x == self.current_room_x: if room.y == self.current_room_y: self.current_room = room # insert our custom Background into an OrderedGroup self.insert(CustomBackground(), 0) # init and fill mapgrids. self.bg_map_grid = glooey.Grid(0, 0, 0, 0) for tile in self.current_room.tiles: # draw bg of current room self.bg_map_grid[tile.x, tile.y] = glooey.Image(tile.bg) self.fg_map_grid = glooey.Grid(0, 0, 0, 0) for tile in self.current_room.tiles: # draw fg of current room self.fg_map_grid[tile.x, tile.y] = glooey.Image(tile.fg) # insert mapgrids into our ordered groups. self.insert(self.bg_map_grid, 1) self.insert(self.fg_map_grid, 2) # draw monsters and player on a grid self.creature_map_grid = glooey.Grid(0, 0, 0, 0) for creature in self.current_room.characters: self.creature_map_grid[creature.x, creature.y] = creature.image self.insert(self.creature_map_grid, 3) # draw player stats self.stats_box = StatsBox() self.insert(self.stats_box, 4)
def main(): np.random.seed(0) window = pyglet.window.Window(width=1295, height=975) gui = glooey.Gui(window) grid = glooey.Grid(2, 2) grid.set_padding(5) scene = create_scene1() widget = SceneWidget(scene) grid[0, 0] = widget scene = create_scene2() widget = SceneWidget(scene) grid[0, 1] = widget image = pyglet.image.load('images/beach.jpg') widget = glooey.Image(image) grid[1, 0] = widget hbox = glooey.HBox() widget = glooey.Button(text='yes') widget.push_handlers(on_click=lambda w: print(f'[{w.text}] clicked!')) hbox.add(widget) widget = glooey.Button(text='no') widget.push_handlers(on_click=lambda w: print(f'[{w.text}] clicked!')) hbox.add(widget) grid[1, 1] = hbox gui.add(grid) pyglet.app.run()
def __init__(self): # create window with padding self.width, self.height = 480 * 3, 360 window = self._create_window(width=self.width, height=self.height) gui = glooey.Gui(window) hbox = glooey.HBox() hbox.set_padding(5) # scene widget for changing camera location scene = create_scene() self.scene_widget1 = trimesh.viewer.SceneWidget(scene) self.scene_widget1._angles = [np.deg2rad(45), 0, 0] hbox.add(self.scene_widget1) # scene widget for changing scene scene = trimesh.Scene() geom = trimesh.path.creation.box_outline((0.6, 0.6, 0.6)) scene.add_geometry(geom) self.scene_widget2 = trimesh.viewer.SceneWidget(scene) hbox.add(self.scene_widget2) # integrate with other widget than SceneWidget self.image_widget = glooey.Image() hbox.add(self.image_widget) gui.add(hbox) pyglet.clock.schedule_interval(self.callback, 1. / 20) pyglet.app.run()
def __init__(self, position, name=None): super().__init__() self.x = position[0] self.y = position[1] if name != None: self.name = checkNameAvailability(name) self.name_label = Text(self.name) else: self.name = checkNameAvailability("Names") self.name_label = Text(self.name) self.add_back(Slot()) self.grid = glooey.Grid(5, 5) self.grid.set_cell_alignment('center') self.board = glooey.Board() self.remove_button = DelButton(position) self.options_button = OptionsButton(position) self.grid.set_row_height(1, 20) self.grid.set_row_height(2, 5) self.grid.set_row_height(3, 20) self.grid.set_col_width(1, 200) self.grid.set_col_width(3, 200) self.grid[1, 1] = self.player_one_input = TextInput() self.grid[1, 3] = self.player_two_input = TextInput() self.grid[3, 1] = Text("Player 1 Name") self.grid[3, 2] = glooey.Image( pyglet.resource.texture( "Widgets/Textures/SelectWidgetDialog/PlayerName.png")) self.grid[3, 3] = Text("Player 2 Name") self.board.add(self.remove_button, bottom=50, left_percent=.8) self.board.add(self.options_button, bottom=50, left_percent=.7) self.board.add(self.name_label, bottom_percent=.9, center_x_percent=.5) self.add_front(self.grid) self.add_front(self.board)
#!/usr/bin/env python3 import pyglet import glooey import run_demos window = pyglet.window.Window() gui = glooey.Gui(window) widget = glooey.Image() gui.add(widget) @run_demos.on_space(gui) # def test_image(): widget.image = pyglet.image.load('assets/misc/star_5.png') yield "Show a green star." widget.image = pyglet.image.load('assets/misc/star_7.png') yield "Show a orange star." pyglet.app.run()
def display_scenes(data, height=480, width=640, tile=None, caption=None): import glooey scenes = None scenes_group = None scenes_ggroup = None if isinstance(data, types.GeneratorType): next_data = next(data) if isinstance(next_data, types.GeneratorType): scenes = next(next_data) scenes_group = next_data scenes_ggroup = data else: scenes = next_data scenes_group = data else: scenes = data if tile is None: nrow, ncol = _get_tile_shape(len(scenes), hw_ratio=height / width) else: nrow, ncol = tile configs = [ pyglet.gl.Config(sample_buffers=1, samples=4, depth_size=24, double_buffer=True), pyglet.gl.Config(double_buffer=True), ] for config in configs: try: window = pyglet.window.Window( height=height * nrow, width=width * ncol, caption=caption, config=config, ) break except pyglet.window.NoSuchConfigException: pass window.rotate = 0 if scenes_group: window.play = False window.next = False window.scenes_group = scenes_group window.scenes_ggroup = scenes_ggroup @window.event def on_key_press(symbol, modifiers): if modifiers == 0: if symbol == pyglet.window.key.Q: window.on_close() elif window.scenes_group and symbol == pyglet.window.key.S: window.play = not window.play elif symbol == pyglet.window.key.Z: for name in scenes: if isinstance(widgets[name], trimesh.viewer.SceneWidget): widgets[name].reset_view() if symbol == pyglet.window.key.N: if modifiers == 0: window.next = True elif window.scenes_ggroup and \ modifiers == pyglet.window.key.MOD_SHIFT: try: window.scenes_group = next(window.scenes_ggroup) window.next = True except StopIteration: return if symbol == pyglet.window.key.R: # rotate camera window.rotate = not window.rotate # 0/1 if modifiers == pyglet.window.key.MOD_SHIFT: window.rotate *= -1 def callback(dt): if window.rotate: for widget in widgets.values(): if isinstance(widget, trimesh.viewer.SceneWidget): scene = widget.scene camera = scene.camera axis = tf.transform_points([[0, 1, 0]], camera.transform, translate=False)[0] camera.transform = tf.rotation_matrix( np.deg2rad(window.rotate), axis, point=scene.centroid, ) @ camera.transform widget.view['ball']._n_pose = camera.transform return if window.scenes_group and (window.next or window.play): try: scenes = next(window.scenes_group) for key, widget in widgets.items(): if isinstance(widget, trimesh.viewer.SceneWidget): widget.scene.geometry.update(scenes[key].geometry) widget.scene.graph.load( scenes[key].graph.to_edgelist()) widget._draw() elif isinstance(widget, glooey.Image): widget.set_image(numpy_to_image(scenes[key])) except StopIteration: window.play = False window.next = False gui = glooey.Gui(window) grid = glooey.Grid() grid.set_padding(5) widgets = {} trackball = None for i, (name, scene) in enumerate(scenes.items()): vbox = glooey.VBox() vbox.add(glooey.Label(text=name, color=(255, ) * 3), size=0) if isinstance(scene, trimesh.Scene): widgets[name] = trimesh.viewer.SceneWidget(scene) if trackball is None: trackball = widgets[name].view['ball'] else: widgets[name].view['ball'] = trackball elif isinstance(scene, np.ndarray): widgets[name] = glooey.Image(numpy_to_image(scene), responsive=True) else: raise TypeError(f'unsupported type of scene: {scene}') vbox.add(widgets[name]) grid[i // ncol, i % ncol] = vbox gui.add(grid) pyglet.clock.schedule_interval(callback, 1 / 30) pyglet.app.run() pyglet.clock.unschedule(callback)
def display_scenes( data, height=480, width=640, tile=None, caption=None, rotate=False, rotation_scaling=1, ): import glooey scenes = None scenes_group = None scenes_ggroup = None if isinstance(data, types.GeneratorType): next_data = next(data) if isinstance(next_data, types.GeneratorType): scenes_ggroup = data scenes_group = next_data scenes = next(next_data) else: scenes_group = data scenes = next_data else: scenes = data scenes.pop("__clear__", False) if tile is None: nrow, ncol = _get_tile_shape(len(scenes), hw_ratio=height / width) else: nrow, ncol = tile configs = [ pyglet.gl.Config(sample_buffers=1, samples=4, depth_size=24, double_buffer=True), pyglet.gl.Config(double_buffer=True), ] HEIGHT_LABEL_WIDGET = 19 PADDING_GRID = 1 for config in configs: try: window = pyglet.window.Window( height=(height + HEIGHT_LABEL_WIDGET) * nrow, width=(width + PADDING_GRID * 2) * ncol, caption=caption, config=config, ) break except pyglet.window.NoSuchConfigException: pass window.rotate = rotate window._clear = False if scenes_group: window.play = False window.next = False window.scenes_group = scenes_group window.scenes_ggroup = scenes_ggroup def usage(): return """\ Usage: q: quit s: play / pause z: reset view n: next r: rotate view (clockwise) R: rotate view (anti-clockwise)\ """ @window.event def on_key_press(symbol, modifiers): if symbol == pyglet.window.key.Q: window.on_close() elif window.scenes_group and symbol == pyglet.window.key.S: window.play = not window.play elif symbol == pyglet.window.key.Z: for name in scenes: if isinstance(widgets[name], trimesh.viewer.SceneWidget): widgets[name].reset_view() elif symbol == pyglet.window.key.N: if (window.scenes_ggroup and modifiers == pyglet.window.key.MOD_SHIFT): try: window.scenes_group = next(window.scenes_ggroup) window.next = True window._clear = True except StopIteration: return else: window.next = True elif symbol == pyglet.window.key.C: camera_transform_ids = set() for key, widget in widgets.items(): if isinstance(widget, trimesh.viewer.SceneWidget): camera_transform_id = id(widget.scene.camera_transform) if camera_transform_id in camera_transform_ids: continue camera_transform_ids.add(camera_transform_id) print(f"{key}:") camera_transform = widget.scene.camera_transform print(repr(from_opengl_transform(camera_transform))) elif symbol == pyglet.window.key.R: # rotate camera window.rotate = not window.rotate # 0/1 if modifiers == pyglet.window.key.MOD_SHIFT: window.rotate *= -1 elif symbol == pyglet.window.key.H: print(usage()) def callback(dt): if window.rotate: for widget in widgets.values(): if isinstance(widget, trimesh.viewer.SceneWidget): axis = tf.transform_points( [[0, 1, 0]], widget.scene.camera_transform, translate=False, )[0] widget.scene.camera_transform[...] = (tf.rotation_matrix( np.deg2rad(window.rotate * rotation_scaling), axis, point=widget.scene.centroid, ) @ widget.scene.camera_transform) widget.view["ball"]._n_pose = widget.scene.camera_transform return if window.scenes_group and (window.next or window.play): try: scenes = next(window.scenes_group) clear = scenes.get("__clear__", False) or window._clear window._clear = False for key, widget in widgets.items(): scene = scenes[key] if isinstance(widget, trimesh.viewer.SceneWidget): assert isinstance(scene, trimesh.Scene) if clear: widget.clear() widget.scene = scene else: widget.scene.geometry.update(scene.geometry) widget.scene.graph.load(scene.graph.to_edgelist()) widget.scene.camera_transform[ ...] = scene.camera_transform widget.view[ "ball"]._n_pose = widget.scene.camera_transform widget._draw() elif isinstance(widget, glooey.Image): widget.set_image(numpy_to_image(scene)) except StopIteration: print("Reached the end of the scenes") window.play = False window.next = False gui = glooey.Gui(window) grid = glooey.Grid() grid.set_padding(PADDING_GRID) widgets = {} trackball = None for i, (name, scene) in enumerate(scenes.items()): vbox = glooey.VBox() vbox.add(glooey.Label(text=name, color=(255, ) * 3), size=0) if isinstance(scene, trimesh.Scene): widgets[name] = trimesh.viewer.SceneWidget(scene) if trackball is None: trackball = widgets[name].view["ball"] else: widgets[name].view["ball"] = trackball elif isinstance(scene, np.ndarray): widgets[name] = glooey.Image(numpy_to_image(scene), responsive=True) else: raise TypeError(f"unsupported type of scene: {scene}") vbox.add(widgets[name]) grid[i // ncol, i % ncol] = vbox gui.add(grid) pyglet.clock.schedule_interval(callback, 1 / 30) pyglet.app.run() pyglet.clock.unschedule(callback)
class Over(glooey.Background): custom_image = pyglet.resource.image('res/PNG/GUI/pa_down2.png') class Down(glooey.Background): custom_image = pyglet.resource.image('res/PNG/GUI/pa_down2.png') class Start_New_Button(TitleScreen_Button): def __init__(self, text, client): super().__init__(text) self.client = client stack = glooey.Stack() stack.custom_alignment = 'fill' bg = glooey.Image(pyglet.image.load("res/PNG/GUI/title menu.png")) bg.custom_alignment = 'fill' stack.add(bg) board = glooey.Board() board.custom_alignment = 'fill' vbox = TitleScreen_Grid() vbox.alignment = 'right' stack.add(vbox) class Main_Window2(pyglet.window.Window): def __init__(self, width, height): conf = Config(sample_buffers=1, samples=4, depth_size=16,