def render_config_menu(): if not State.get().config_menu: return Render.get().ortho_perspective() config_menu = State.get().config_menu # text = config_menu.items[config_menu.index] # otw, th = Render.get().text(text, title_font, # -1.0, -0.93, 2.0, color=(1.0, 1.0, 1.0, 0.36 * strength)) # x = 0.0 + otw / 2 + CONFIG_SEPARATION # for i in range(config_menu.index + 1, len(config_menu.items)): # text = config_menu.items[i] # tw, th = Render.get().text(text, title_font, # x, -0.93, color=(1.0, 1.0, 1.0, 0.36 * strength)) # x += tw + CONFIG_SEPARATION # x = 0.0 - otw / 2 - CONFIG_SEPARATION x = -0.55 y = 0.8 for i in range(len(config_menu.items)): text = config_menu.items[i].upper() # tw, th = Render.get().measure_text(text, title_font) # x -= tw + CONFIG_SEPARATION y -= 0.15 if i == config_menu.index and config_menu == State.get().navigatable: color = (1.0, 1.0, 1.0, 1.0) else: color = (1.0, 1.0, 1.0, 0.33) Render.get().text(text, Font.subtitle_font, x, y, color=color)
def go_back(): c_menu = State.get().history[-1] if hasattr(c_menu, "go_back"): c_menu.go_back() return State.get().history.pop() set_current_menu(State.get().history[-1])
def swap_buffers(): # global fps_str # # Render.get().ortho_perspective() # #glPushMatrix() # #glTranslatef(0.0, 0.0, 0.5) # # #if not fps_str: # # fps_str = "WHY?" # # if Render.get().display_fps or True: # if fps_str: # Render.get().text(fps_str, Font.main_path_font, # -1.74, 0.82, h=0.1, color=(0.25, 0.25, 0.25, 1.0)) # #glPopMatrix() # # # FIXME: Why does not minimize from fullscreen work on ATI unless we # render # # something here? # glBindTexture(GL_TEXTURE_2D, 0) # glPushMatrix() # glTranslate(2000.0, 0.0, 0.0) # glBegin(GL_QUADS) # glVertex2f(0.0, 0.0) # glVertex2f(1.0, 0.0) # glVertex2f(1.0, 1.0) # glVertex2f(0.0, 1.0) # glEnd() # glPopMatrix() # # #fs_emu_blending(False) # #glEnable(GL_DEPTH_TEST) # # #if Render.get().display_sync: # # glFinish() # # #pygame.display.flip() # print("FIXME: not flipping") # # if Render.get().display_sync: # # give up time slice # time.sleep(0.001) # glFinish() # # if Render.get().display_fps: # t = get_current_time() # render_times.append(t) # t0 = render_times.popleft() # if t0 > 0 and State.get().frame_number % 5 == 0: # time_diff = t - t0 # #print("{0:0.2f}".format(300.0 / time_diff)) # fps = FPS_FRAMES / time_diff # if fps >= 100: # fps_str = "FPS: {0:0.0f}".format(fps) # else: # fps_str = "FPS: {0:0.1f}".format(fps) # #Render.get().text(fps_str, Font.title_font, # # -1.0, 0.90, 2.0, shadow=True) State.get().frame_number += 1 Render.get().delete_textures()
def render(self): Transition.value = 0.0 if Transition.start > 0: Transition.value = (State.get().time - Transition.start) / \ (Transition.end - Transition.start) # prevent render from stopping when animating Render.get().dirty = True # transition goes from 1.0 ... 0.0 Transition.value = 1.0 - Transition.value # finished = 0 if Transition.value <= 0.0: Transition.value = 0.0 # finished = 1.0 Transition.start = 0 Transition.on_finish() return last_menu = State.get().history[-2] self.last_menu_data = last_menu.render() # self.top_menu_transition = transition # glClear(GL_DEPTH_BUFFER_BIT) # print(transition) # glEnable(GL_DEPTH_TEST) # glDepthMask(True) # render_wall(transition) # render_screen(transition) # if finished: # # FIXME: defer to later via an event or similar? return None
def activate(self, menu): from arcade.glui.window import create_main_menu new_menu = create_main_menu() # State.get().history = [new_menu] State.get().history.append(new_menu) from arcade.glui.window import set_current_menu set_current_menu(new_menu)
def run_game(self): new_menu = LaunchMenu(self.items[0], self.controller) State.get().history.append(new_menu) # FIXME from arcade.glui.window import set_current_menu set_current_menu(new_menu)
def activate(self, menu): from arcade.glui.window import create_main_menu new_menu = create_main_menu() # State.get().history = [new_menu] State.get().history.append(new_menu) from arcade.glui.window import set_current_menu set_current_menu(new_menu)
def render(self): Transition.value = 0.0 if Transition.start > 0: Transition.value = (State.get().time - Transition.start) / \ (Transition.end - Transition.start) # prevent render from stopping when animating Render.get().dirty = True # transition goes from 1.0 ... 0.0 Transition.value = 1.0 - Transition.value # finished = 0 if Transition.value <= 0.0: Transition.value = 0.0 # finished = 1.0 Transition.start = 0 Transition.on_finish() return last_menu = State.get().history[-2] self.last_menu_data = last_menu.render() # self.top_menu_transition = transition # glClear(GL_DEPTH_BUFFER_BIT) # print(transition) # glEnable(GL_DEPTH_TEST) # glDepthMask(True) # render_wall(transition) # render_screen(transition) # if finished: # # FIXME: defer to later via an event or similar? return None
def run_game(self): new_menu = LaunchMenu(self.items[0], self.controller) State.get().history.append(new_menu) # FIXME from arcade.glui.window import set_current_menu set_current_menu(new_menu)
def go_back(self): print("LaunchMenu.go_back") if self.state in [STATE_STARTING, STATE_PREPARING]: if self.gc_runner: self.gc_runner.abort() self.state = STATE_ABORTING if self.state in [STATE_ABORTED]: State.get().history.pop() set_current_menu(State.get().history[-1])
def go_back(self): print("LaunchMenu.go_back") if self.state in [STATE_STARTING, STATE_PREPARING]: if self.gc_runner: self.gc_runner.abort() self.state = STATE_ABORTING if self.state in [STATE_ABORTED]: State.get().history.pop() set_current_menu(State.get().history[-1])
def enter_menu(result, replace=False): print("enter_menu", result, "replace", replace) print(" menu parent_menu", result.parent_menu) if replace: State.get().history.pop() c_menu = State.get().history[-1] result.parents[:] = c_menu.parents result.parents.append(c_menu) print(" menu parents ", result.parents) State.get().history.append(result) set_current_menu(result)
def render_bottom_bar_text(item): strength = 0.9 x = 544 y = 290 title = item.title.upper() if title: Render.get().text(title, Font.title_font, x, y, 1920 - x - 170, shadow=True, color=(1.0, 1.0, 1.0, 1.0 * strength)) year_text = str(getattr(State.get().current_menu.selected_item, "year", "") or "").upper() if year_text: tw, th = Render.get().measure_text(year_text, Font.title_font) Render.get().text(year_text, Font.title_font, 1920 - 30 - tw, y, 0, shadow=True, color=(1.0, 1.0, 1.0, 1.0 * strength)) color = (0x6e / 0xff, 0x8b / 0xff, 0x96 / 0xff, 1.0) y = 258 text_str = "" companies = set() publisher_text = (getattr(State.get().current_menu.selected_item, "publisher", "") or "").upper() for text in publisher_text.split("/"): text = text.strip() if text: if text not in companies: text_str = text_str + u" \u00b7 " + text companies.add(text) developer_text = (getattr(State.get().current_menu.selected_item, "developer", "") or "").upper() for text in developer_text.split("/"): text = text.strip() if text: if text not in companies: text_str = text_str + u" \u00b7 " + text companies.add(text) if len(text_str) > 3: text_str = text_str[3:] # remove initial middle dot Render.get().text(text_str, Font.subtitle_font, x, y, 0, shadow=True, color=color) platform_str = str( getattr(State.get().current_menu.selected_item, "platform", "") or "") if platform_str: platform_str = PlatformHandler.get_platform_name(platform_str).upper() if len(platform_str) >= 3: tw, th = Render.get().measure_text(platform_str, Font.subtitle_font) Render.get().text(platform_str, Font.subtitle_font, 1920 - 30 - tw, y, 0, shadow=True, color=color) return
def set_selected_index(self, index, immediate=False): self._selected_index = index if immediate: self.reset_position() else: p1 = self.position + self.cur_scroll_speed * 0.040 self._position_animation = AnimateValueBezier( (self, "position"), self.position, State.get().time, p1, State.get().time + 0.040, index, State.get().time + 0.080, index, State.get().time + 0.200) self.configuration_index = 0
def set_selected_index(self, index, immediate=False): self._selected_index = index if immediate: self.reset_position() else: p1 = self.position + self.cur_scroll_speed * 0.040 self._position_animation = AnimateValueBezier( (self, "position"), self.position, State.get().time, p1, State.get().time + 0.040, index, State.get().time + 0.080, index, State.get().time + 0.200) self.configuration_index = 0
def show_input(): # print("Create input menu, controller = ", id(self.controller)) # new_menu = InputMenu(self.game_item, self.controller) # State.get().history.append(new_menu) # # FIXME # from .window import set_current_menu # set_current_menu(new_menu) print("Create input menu, runner = ", id(self.runner)) new_menu = InputMenu(self.game_item, self.runner) State.get().history.append(new_menu) # FIXME from arcade.glui.window import set_current_menu set_current_menu(new_menu)
def show_input(): # print("Create input menu, controller = ", id(self.controller)) # new_menu = InputMenu(self.game_item, self.controller) # State.get().history.append(new_menu) # # FIXME # from .window import set_current_menu # set_current_menu(new_menu) print("Create input menu, runner = ", id(self.runner)) new_menu = InputMenu(self.game_item, self.runner) State.get().history.append(new_menu) # FIXME from arcade.glui.window import set_current_menu set_current_menu(new_menu)
def render(self): Render.get().hd_perspective() if self.throbber_start_time == 0: self.throbber_start_time = State.get().time dt = State.get().time - self.throbber_start_time # run animation with 15 fps self.throbber_progress = int(dt * 15) bg_fade = (State.get().time - State.get().dialog_time) / 0.5 if bg_fade > 1.0: bg_fade = 1.0 elif bg_fade < 0.0: bg_fade = 0.0 fs_emu_texturing(False) fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) gl.glDepthMask(False) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1020) gl.glVertex2f(0, 1020) gl.glEnd() gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade * 0.5) gl.glVertex2f(0, 1020) gl.glVertex2f(1920, 1020) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd() # y = 0.0 # tw, th = Render.get().text("LAUNCHING GAME", self.title_font, # 0.0, y, w=32 / 9, h=self.height, # color=(1.0, 1.0, 1.0, 1.0), halign=0.0) # fs_emu_blending(True) # if bg_fade > 0.5: # self.throbber_opacity = (bg_fade - 0.5) / 0.5 # #self.throbber_opacity = bg_fade # self.render_throbber() # if bg_fade == 1.0: if State.get().time - State.get().dialog_time > 1.0: # gradually show over 1/4 second self.throbber_opacity = ( State.get().time - State.get().dialog_time - 1.0) * 4 if self.throbber_opacity > 1.0: self.throbber_opacity = 1.0 self.render_throbber() gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthMask(True) # fs_emu_texturing(1) # fs_emu_blending(0) # print("Setting dirty..") Render.get().dirty = True
def render(self): Render.get().hd_perspective() if self.throbber_start_time == 0: self.throbber_start_time = State.get().time dt = State.get().time - self.throbber_start_time # run animation with 15 fps self.throbber_progress = int(dt * 15) bg_fade = (State.get().time - State.get().dialog_time) / 0.5 if bg_fade > 1.0: bg_fade = 1.0 elif bg_fade < 0.0: bg_fade = 0.0 fs_emu_texturing(False) fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) gl.glDepthMask(False) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1020) gl.glVertex2f(0, 1020) gl.glEnd() gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade * 0.5) gl.glVertex2f(0, 1020) gl.glVertex2f(1920, 1020) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd() # y = 0.0 # tw, th = Render.get().text("LAUNCHING GAME", self.title_font, # 0.0, y, w=32 / 9, h=self.height, # color=(1.0, 1.0, 1.0, 1.0), halign=0.0) # fs_emu_blending(True) # if bg_fade > 0.5: # self.throbber_opacity = (bg_fade - 0.5) / 0.5 # #self.throbber_opacity = bg_fade # self.render_throbber() # if bg_fade == 1.0: if State.get().time - State.get().dialog_time > 1.0: # gradually show over 1/4 second self.throbber_opacity = (State.get().time - State.get().dialog_time - 1.0) * 4 if self.throbber_opacity > 1.0: self.throbber_opacity = 1.0 self.render_throbber() gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthMask(True) # fs_emu_texturing(1) # fs_emu_blending(0) # print("Setting dirty..") Render.get().dirty = True
def set_current_menu(menu): if not isinstance(menu, SearchResultsMenu): menu.search_text = "" global current_menu if len(menu) == 0: menu.append(NoItem()) current_menu = menu State.get().current_menu = menu if menu.navigatable: State.get().navigatable = menu.navigatable else: State.get().navigatable = menu State.get().top_menu = menu.top State.get().down_navigatable = None Render.get().dirty = True
def render_top_right(self, selected=False): state = State.get() mouse_state = state.mouse_item == self mouse_pressed_state = mouse_state and state.mouse_press_item == self self.render_top_background( selected, style=TOP_ITEM_LEFT, mouse_state=mouse_state, mouse_pressed_state=mouse_pressed_state, ) gl.glDisable(gl.GL_DEPTH_TEST) fs_emu_blending(True) if Settings.instance()["video_sync"] == "1": r = 1.0 g = 1.0 b = 1.0 alpha = 1.0 else: r = 1.0 g = 1.0 b = 1.0 alpha = 0.33 x = self.x + 20 BitmapFont.title_font.render(self.title, x, self.y + 14, r=r, g=g, b=b, alpha=alpha) gl.glEnable(gl.GL_DEPTH_TEST)
def _do_run(self): # if fs.windows: # pass # elif fs.macosx: # pass # else: # # prevent flashing mouse cursor when launching programs # # by moving cursor to the bottom right of the screen # import gtk.gdk # display = gtk.gdk.display_get_default() # screen = display.get_default_screen() # display.warp_pointer(screen, screen.get_width() - 1, # screen.get_height() - 1) # size = get_fullscreen_size() # pygame.mouse.set_cursor((8, 1), (0, 0), (0,), (0,)) # pygame.mouse.set_visible(True) # pygame.mouse.set_pos(size[0] - 1, size[1] - 0) state = State.get() try: print("state.game_running = True") state.game_running = True self.controller.run() self.controller.wait() finally: print("state.game_running = False") state.game_running = False self.controller.finish()
def _do_run(self): # if fs.windows: # pass # elif fs.macosx: # pass # else: # # prevent flashing mouse cursor when launching programs # # by moving cursor to the bottom right of the screen # import gtk.gdk # display = gtk.gdk.display_get_default() # screen = display.get_default_screen() # display.warp_pointer(screen, screen.get_width() - 1, # screen.get_height() - 1) # size = get_fullscreen_size() # pygame.mouse.set_cursor((8, 1), (0, 0), (0,), (0,)) # pygame.mouse.set_visible(True) # pygame.mouse.set_pos(size[0] - 1, size[1] - 0) state = State.get() try: print("state.game_running = True") state.game_running = True process = self.controller.run() process.wait() finally: print("state.game_running = False") state.game_running = False self.controller.finish()
def show_exception(): import traceback backtrace = traceback.format_exc() State.get().dialog = ErrorDialog(sys.exc_info()[1], backtrace) show_error_state = {"stop": False} while not show_error_state["stop"]: def input_func(button): if button == "BACK": show_error_state["stop"] = True # FIXME from arcade.glui.window import main_loop_iteration if main_loop_iteration(input_func=input_func): break State.get().dialog.destroy() State.get().dialog = None
def update(self, t=None): t = t or State.get().time progress = (t - self.from_time) / (self.to_time - self.from_time) progress = max(0.0, min(1.0, progress)) setattr(self.what[0], self.what[1], self.from_value + progress * (self.to_value - self.from_value)) return t < self.to_time
def character_press(char): print("character press", repr(char)) if State.get().current_game: # or isinstance(current_menu, GameMenu): print("ignoring key press", repr(char)) return # global char_buffer char_buffer = current_menu.search_text global char_buffer_last_updated char_buffer_last_updated = State.get().time # return Render.get().dirty = True if char == "RETURN": print(char_buffer, len(char_buffer)) print("returning false") return False elif char == "BACKSPACE" or char == u"\b": char_buffer = char_buffer[:-1] if len(char_buffer) <= 2: char_buffer = "" handle_search_menu_on_character_press(char_buffer) return True elif len(char) == 1: char_buffer += char handle_search_menu_on_character_press(char_buffer) if 1 <= len(char_buffer) <= 2: jump_to_item = -1 for i, item in enumerate(current_menu.items): # FIXME: a bit hack-y this, should check sort_name # instead (need to store this in items then) # also, should use binary search and not sequential search... searches = [char_buffer, "the " + char_buffer, "a " + char_buffer] check = item.name.lower() for s in searches: if check.startswith(s): jump_to_item = i break if jump_to_item >= 0: current_menu.set_selected_index(jump_to_item, immediate=True) return True else: raise Exception(repr(char))
def activate(self): result = self.selected_item.activate(State.get().current_menu) # FIXME: from arcade.glui.menu import Menu if isinstance(result, Menu): # FIXME: from arcade.glui.window import enter_menu enter_menu(result)
def update(self, t=None): t = t or State.get().time progress = (t - self.from_time) / ( self.to_time - self.from_time) progress = max(0.0, min(1.0, progress)) setattr(self.what[0], self.what[1], self.from_value + progress * (self.to_value - self.from_value)) return t < self.to_time
def activate(self): result = self.selected_item.activate(State.get().current_menu) # FIXME: from arcade.glui.menu import Menu if isinstance(result, Menu): # FIXME: from arcade.glui.window import enter_menu enter_menu(result)
def show_exception(): import traceback backtrace = traceback.format_exc() State.get().dialog = ErrorDialog(sys.exc_info()[1], backtrace) show_error_state = {"stop": False} while not show_error_state["stop"]: def input_func(button): if button == "BACK": show_error_state["stop"] = True # FIXME from arcade.glui.window import main_loop_iteration if main_loop_iteration(input_func=input_func): break State.get().dialog.destroy() State.get().dialog = None
def set_ingame_status(): # State.get().fade_start = State.get().time # State.get().fade_end = State.get().time + 86400.0 * 365.0 # State.get().fade_from = (0.0, 0.0, 0.0, 0.0) # State.get().fade_to = (0.0, 0.0, 0.0, 0.0) # State.get().fade_splash = False print("State.get().currently_ingame = True") State.get().currently_ingame = True
def set_items_brightness(brightness, duration=1.0, delay=0.0): State.get().items_brightness_anim = AnimateValueBezier( (State, "items_brightness"), State.get().items_brightness, State.get().time + delay, State.get().items_brightness, State.get().time + delay, brightness, State.get().time + delay + duration, brightness, State.get().time + delay + duration)
def render_global_fade(): t = State.get().time if State.get().fade_end >= t >= State.get().fade_start: a = (t - State.get().fade_start) / ( State.get().fade_end - State.get().fade_start) if a < 0.0: a = 0.0 elif a > 1.0: a = 1.0 Render.get().hd_perspective() gl.glPushMatrix() gl.glTranslatef(0.0, 0.0, 0.99999) fs_emu_blending(True) fs_emu_texturing(True) if State.get().fade_splash: Texture.splash.render( (1920 - Texture.splash.w) // 2, (1080 - Texture.splash.h) // 2, Texture.splash.w, Texture.splash.h, opacity=(1.0 - a)) c = [0, 0, 0, (1.0 - a)] # for i in range(4): # c[i] = State.get().fade_from[i] + \ # (State.get().fade_to[i] - State.get().fade_from[i]) * a # * (a) render_fade(*c) gl.glPopMatrix() Render.get().dirty = True
def render_top_right(self, selected=False): state = State.get() mouse_state = state.mouse_item == self mouse_pressed_state = mouse_state and state.mouse_press_item == self self.render_top_background(selected, style=TOP_ITEM_LEFT, mouse_state=mouse_state, mouse_pressed_state=mouse_pressed_state) self.render_top(self.get_top_right_text(), selected)
def update(self, t=None): t = t or State.get().time for anim in self.anim_seq: if t > anim.max_time: continue anim.update(t) break else: return self.anim_seq[-1].update() return True
def update(self, t=None): x0, t0, x1, t1, x2, t2, x3, t3 = self.params t = t or State.get().time if t < t0: t = t0 elif t > t3: t = t3 x = Bezier.interpolate(self.curve, t) setattr(self.what[0], self.what[1], x) return t < t3
def update(self, t=None): t = t or State.get().time for anim in self.anim_seq: if t > anim.max_time: continue anim.update(t) break else: return self.anim_seq[-1].update() return True
def update(self, t=None): x0, t0, x1, t1, x2, t2, x3, t3 = self.params t = t or State.get().time if t < t0: t = t0 elif t > t3: t = t3 x = Bezier.interpolate(self.curve, t) setattr(self.what[0], self.what[1], x) return t < t3
def do_render(): if current_menu is None: return current_menu.update() if RunTransition.value > 0.99: # do not render anything when running a game return if State.get().currently_ingame: # print("currently ingame") return # try to exploit parallelism by uploading texture while rendering TextureManager.get().load_textures(1) # clear mouseover rects -these will be calculated during rendering Mouse.items[:] = [] Render.get().standard_perspective() # scanning = GameScanner.scanning data = current_menu.render() current_menu.render_transparent(data) # if GameScanner.is_scanning(): if False: render_scanning_status() State.get().was_scanning = True else: render_config_menu() if State.get().was_scanning: print("State.get().was_scanning") State.get().was_scanning = False # reload current menu # if current_menu.parent_menu: # result = current_menu.parent_menu.selected_item.activate( # current_menu.parent_menu) # if isinstance(result, Menu): # #if len(result) == 0: # # result.append(NoItem()) # result.parent_menu = current_menu.parent_menu # print("set new menu (rescanned games)") # set_current_menu(result) recreate_main_menu_if_necessary() render_top() if State.get().dialog: State.get().dialog.render() render_global_fade() NotificationRender.render() if RunTransition.value > 0.0: render_fade(a=RunTransition.value)
def render_top_right(self, selected=False): state = State.get() mouse_state = state.mouse_item == self mouse_pressed_state = mouse_state and state.mouse_press_item == self self.render_top_background( selected, style=TOP_ITEM_LEFT, mouse_state=mouse_state, mouse_pressed_state=mouse_pressed_state, ) self.render_top(self.get_top_right_text(), selected)
def update(cls, t=None): t = t or State.get().time deleted = [] for ref_obj in cls.animation_list: obj = ref_obj() if obj is None: deleted.append(ref_obj) else: if not obj.update(t): deleted.append(ref_obj) for d in deleted: cls.animation_list.remove(d)
def update(cls, t=None): t = t or State.get().time deleted = [] for ref_obj in cls.animation_list: obj = ref_obj() if obj is None: deleted.append(ref_obj) else: if not obj.update(t): deleted.append(ref_obj) for d in deleted: cls.animation_list.remove(d)
def render_top_left(self, selected=False): state = State.get() mouse_state = state.mouse_item == self mouse_pressed_state = mouse_state and state.mouse_press_item == self self.render_top_background(selected, mouse_state=mouse_state, mouse_pressed_state=mouse_pressed_state) # fs_emu_blending(True) if selected: texture = Texture.add_selected else: texture = Texture.add texture.render(self.x, self.y, texture.w, texture.h)
def render_top_left(self, selected=False): state = State.get() mouse_state = state.mouse_item == self mouse_pressed_state = mouse_state and state.mouse_press_item == self self.render_top_background(selected, mouse_state=mouse_state, mouse_pressed_state=mouse_pressed_state) # fs_emu_blending(True) if selected: texture = Texture.add_selected else: texture = Texture.add texture.render(self.x, self.y, texture.w, texture.h)
def update_state(self): if self.state == STATE_STARTING: self.gc_runner = GameCenterRunner(controller=self.controller) # prepare will unpack the game and prepare game files self.gc_runner.prepare() self.state = STATE_PREPARING self.throbber.throbber_start_time = 0 elif self.state == STATE_PREPARING: if self.gc_runner.error: pass elif self.gc_runner.done: self.wait_run_time = State.get().time FadeDialog(self.wait_run_time).show() self.state = STATE_WAITRUN elif self.state == STATE_WAITRUN: if State.get().time - self.wait_run_time > FADE_TIME: set_ingame_status() self.gc_runner.run() self.state = STATE_RUNNING elif self.state == STATE_RUNNING: InputHandler.set_inhibited(True) if self.gc_runner.error: pass elif self.gc_runner.done: self.state = STATE_STOPPING elif self.state == STATE_STOPPING: InputHandler.set_inhibited(False) State.get().history.pop() State.get().history.pop() State.get().history.pop() set_current_menu(State.get().history[-1]) back_to_menu_from_game() Dialog.get_current().close() from arcade.glui.window import main_window main_window.restore_window_if_necessary() elif self.state == STATE_ABORTING: pass
def render_bottom_bar_screens(item): global last_item_id global item_time if id(item) != last_item_id: last_item_id = id(item) item_time = State.get().time gl.glColor3f(1.0, 1.0, 1.0) fs_emu_texturing(True) fs_emu_blending(False) for i in range(3, -1, -1): if State.get().time - item_time > 0.1 + 0.05 * i: texture = item.get_screen_texture(2 + i) else: texture = None if texture: # coords = (0, texture.w, texture.h, 0) coords = COORDS else: texture, coords = static() # While rendering static, we must continue rendering. Render.get().dirty = True texture.bind() texture_rectangle(4 + 539 + 345 * i, 34, 308, 193, 0.2, *coords) if State.get().time - item_time > 0.1: texture = item.get_screen_texture(1) else: texture = None if texture: coords = COORDS else: texture, coords = static() # While rendering static, we must continue rendering. Render.get().dirty = True texture.bind() texture_rectangle(34, 34, 472, 295, 0.2, *coords)
def update_state(self): if self.state == STATE_STARTING: self.gc_runner = GameCenterRunner(controller=self.controller) # prepare will unpack the game and prepare game files self.gc_runner.prepare() self.state = STATE_PREPARING self.throbber.throbber_start_time = 0 elif self.state == STATE_PREPARING: if self.gc_runner.error: pass elif self.gc_runner.done: self.wait_run_time = State.get().time FadeDialog(self.wait_run_time).show() self.state = STATE_WAITRUN elif self.state == STATE_WAITRUN: if State.get().time - self.wait_run_time > FADE_TIME: set_ingame_status() self.gc_runner.run() self.state = STATE_RUNNING elif self.state == STATE_RUNNING: InputHandler.set_inhibited(True) if self.gc_runner.error: pass elif self.gc_runner.done: self.state = STATE_STOPPING elif self.state == STATE_STOPPING: InputHandler.set_inhibited(False) State.get().history.pop() State.get().history.pop() State.get().history.pop() set_current_menu(State.get().history[-1]) back_to_menu_from_game() Dialog.get_current().close() from arcade.glui.window import main_window main_window.restore_window_if_necessary() elif self.state == STATE_ABORTING: pass
def render_bottom_bar_screens(item): global last_item_id global item_time if id(item) != last_item_id: last_item_id = id(item) item_time = State.get().time gl.glColor3f(1.0, 1.0, 1.0) fs_emu_texturing(True) fs_emu_blending(False) for i in range(3, -1, -1): if State.get().time - item_time > 0.1 + 0.05 * i: texture = item.get_screen_texture(2 + i) else: texture = None if texture: # coords = (0, texture.w, texture.h, 0) coords = COORDS else: texture, coords = static() # While rendering static, we must continue rendering. Render.get().dirty = True texture.bind() texture_rectangle(4 + 539 + 345 * i, 34, 308, 193, 0.2, *coords) if State.get().time - item_time > 0.1: texture = item.get_screen_texture(1) else: texture = None if texture: coords = COORDS else: texture, coords = static() # While rendering static, we must continue rendering. Render.get().dirty = True texture.bind() texture_rectangle(34, 34, 472, 295, 0.2, *coords)
def render_item_gloss(alpha, ratio=1.0, brightness=1.0, area=None): if State.get().max_ratio: ratio = min(State.get().max_ratio, ratio) if State.get().force_portrait and ratio > 1.0: ratio = 1.0 / ratio ba = brightness * alpha gl.glColor4f(ba, ba, ba, alpha) fs_emu_blending(True) fs_emu_texturing(True) creating_list = DisplayLists.call_or_create("gloss", ratio) if not creating_list: return gl.glPolygonOffset(0.0, -4.0) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) gl.glDepthMask(False) # glBindTexture(GL_TEXTURE_2D, Texture.gloss) texture = Texture.gloss texture.bind() area = area or 0.8 height = math.sqrt(area / ratio) width = ratio * height gl.glTranslatef(-width / 2.0, -0.5, 0.0) gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0.0, 1.0) gl.glVertex3f(0.0, 0.0, 0.0) gl.glTexCoord(1.0, 1.0) gl.glVertex3f(width, 0.0, 0.0) gl.glTexCoord(1.0, 0.0) gl.glVertex3f(width, height, 0.0) gl.glTexCoord(0.0, 0.0) gl.glVertex3f(0.0, height, 0.0) gl.glEnd() gl.glPolygonOffset(0.0, 0.0) gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glDepthMask(True) # fs_emu_blending(False) if creating_list: gl.glEndList()
def get_current_position(self): t = State.get().time if self.last_scroll_time == t: pass elif self.last_scroll_time - t < 1.0: self.cur_scroll_speed = (self.position - self.last_scroll_pos) / ( t - self.last_scroll_time) else: self.cur_scroll_speed = 0 self.last_scroll_pos = self.position self.last_scroll_time = t # print "speed", self.cur_scroll_speed return self.position
def render_top_right(self, selected=False): state = State.get() mouse_state = state.mouse_item == self mouse_pressed_state = mouse_state and state.mouse_press_item == self self.render_top_background(selected, style=TOP_ITEM_LEFT, mouse_state=mouse_state, mouse_pressed_state=mouse_pressed_state) fs_emu_blending(True) if selected: texture = self.selected_texture else: texture = self.normal_texture # texture.render(self.x, self.y, self.w, self.h) texture.render(self.x + (self.w - texture.w) / 2, self.y + (self.h - texture.h) / 2, texture.w, texture.h)
def active(self): """Check whether the user interface is active or not. If not active, we do not want to force regular/timed refresh event.""" state = State.get() # print("state.game_running", state.game_running) if state.game_running: # print("inactive") return False # print(state.idle_from) # if state.idle_from and state.idle_from < get_current_time(): # print(InputHandler.peek_button()) if not InputHandler.peek_button(): if not state.dirty: if not AnimationSystem.is_active(): self.idle_counter += 1 if self.idle_counter < 16: # We render 1 frame per second when "idling". We need # to "render" regularly, because some state is updated # during the render phase. return False self.idle_counter = 0 return True
def render_transparent(self, data): last_menu = State.get().history[-2] last_menu.render_transparent(self.last_menu_data) if Transition.value < 1.0: opacity = 1.0 - Transition.value opacity *= 1.25 if opacity > 1.0: opacity = 1.0 Render.get().hd_perspective() gl.glDisable(gl.GL_DEPTH_TEST) fs_emu_texturing(False) fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, opacity) gl.glVertex2f(0.0, 0.0) gl.glVertex2f(1920.0, 0.0) gl.glVertex2f(1920.0, 1020.0) gl.glVertex2f(0.0, 1020.0) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST) self.config_list.render(Transition.value)
def activate(self): # Hack for variants if self.index > 4: # Put chosen configuration at the top temp_config = self.game_item.configurations[0] # temp_config = self.game_item.configurations[self.index - 4 + 1] self.game_item.configurations[0] = self.game_item.configurations[ self.index - 4] self.game_item.configurations[self.index - 4] = temp_config # Put chosen variant item at the top temp = self.items[3] self.items[3] = self.items[self.index] self.items[self.index] = temp # Select play game option self.index = 1 # Hackish, please clean up... print("ACTIVE CONFIGURATION:", self.game_item.configurations[0]) State.get().current_menu.create_context() State.get().current_menu.create_controller() self.runner = State.get().current_menu.runner return result = self.items[self.index].activate() if result == "PLAY": # noinspection PyDecorator # @staticmethod def show_input(): # print("Create input menu, controller = ", id(self.controller)) # new_menu = InputMenu(self.game_item, self.controller) # State.get().history.append(new_menu) # # FIXME # from .window import set_current_menu # set_current_menu(new_menu) print("Create input menu, runner = ", id(self.runner)) new_menu = InputMenu(self.game_item, self.runner) State.get().history.append(new_menu) # FIXME from arcade.glui.window import set_current_menu set_current_menu(new_menu) exit_transition.start = State.get().time exit_transition.end = exit_transition.start + 0.5 exit_transition.on_finish = show_input
def __init__(self, item): Menu.__init__(self) self.runner = None self.platform_handler = None self.last_menu_data = None self.temp_fix_configs(item) self.items.append(item) if self.use_game_center_item(): self.top.left.append(GameCenterItem()) # self.top.left.append(HomeItem()) # self.top.left.append(MenuItem(item.title)) self.top.set_selected_index( len(self.top.left) + len(self.top.right) - 1) self.context = None self.controller = None self.create_context() self.create_controller() print("GameMenu.__init__: controller is", self.controller) self.config_list = GameConfigList(self.runner, item) self.info_panel = GameInfoPanel() self.config_list.info_panel = self.info_panel # self.config_list.controller = self.controller self.info_panel.config_list = self.config_list self.navigatable = self.config_list # reset transitions enter_transition.start = State.get().time enter_transition.end = enter_transition.start + 0.2 exit_transition.start = 0
def activate(self): result = self.items[self.index].activate() if result == "PLAY": # noinspection PyDecorator @staticmethod def show_input(): # print("Create input menu, controller = ", id(self.controller)) # new_menu = InputMenu(self.game_item, self.controller) # State.get().history.append(new_menu) # # FIXME # from .window import set_current_menu # set_current_menu(new_menu) print("Create input menu, runner = ", id(self.runner)) new_menu = InputMenu(self.game_item, self.runner) State.get().history.append(new_menu) # FIXME from arcade.glui.window import set_current_menu set_current_menu(new_menu) Transition.start = State.get().time Transition.end = Transition.start + 0.4 Transition.on_finish = show_input
def go_right(self, count=1): State.get().navigatable = self.config_list
def post_quit_event(): State.get().quit = True
def render(self, transition=1.0): Render.get().hd_perspective() # w = 560 # h = 92 # x = 1920 - w * transition # y = 1080 - 60 - h # y = 1080 - 60 - h - 44 # z = -0.9 # item_top = 1080 - 90 - 50 # item_left = 1920 - 560 + 40 dx = Texture.sidebar_background_shadow.w * (1.0 - transition) gl.glPushMatrix() gl.glTranslate(0.0, 0.0, 0.7) # glTranslated((1.0 - transition) * g_tex_sidebar_background->width, # 0, 0) # fs_emu_set_texture(g_tex_sidebar_background) # fs_emu_render_texture_with_size(g_tex_sidebar_background, # 1920 - g_tex_sidebar_background->width, # 0, g_tex_sidebar_background->width, # g_tex_sidebar_background->height) # fs_emu_render_sidebar() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.sidebar_background_shadow.render( 1920 - Texture.sidebar_background_shadow.w * transition, 0, Texture.sidebar_background_shadow.w, Texture.sidebar_background_shadow.h, ) if transition > 1.0: padding = 1920 Texture.sidebar_background.render( 1920 - Texture.sidebar_background_shadow.w * transition + Texture.sidebar_background_shadow.w, 0, 1920 + padding, Texture.sidebar_background.h, ) gl.glDepthMask(True) gl.glPopMatrix() y = SIDEBAR_START_Y for i, item in enumerate(self.items): if item.group: if i > 0: y -= GROUP_SPACING selected = i == self.index and State.get().navigatable == self # z = 0.71 fs_emu_texturing(False) gl.glDisable(gl.GL_DEPTH_TEST) if selected: fg_color = [1.0, 1.0, 1.0, 1.0] # gl.glBegin(gl.GL_QUADS) # # gl.glColor3f(0.00, 0x99 / 0xff, 0xcc / 0xff) # gl.glVertex3f(x, y - 18, z) # gl.glVertex3f(x + w, y - 18, z) # gl.glVertex3f(x + w, y + h - 4, z) # gl.glVertex3f(x, y + h - 4, z) # # glColor3f(0.6, 0.6, 0.6) # # glVertex3f(x, y + 4, z) # # glVertex3f(x + w, y + 4, z) # # glVertex3f(x + w, y + h, z) # # glVertex3f(x, y + h, z) # gl.glEnd() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.item_background.render(1920 - 540 + 13 + dx, y - 18) gl.glDepthMask(True) else: fg_color = [1.0, 1.0, 1.0, 1.0] # glBegin(GL_QUADS) # glColor3f(0.4, 0.4, 0.4) # glVertex3f(x, y, z) # glVertex3f(x + w, y, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x, y + 4, z) # glEnd() # fs_emu_texturing(True) if i > 0: fg_color[3] *= 0.35 text = item.title # FIXME: REMOVE # fs_emu_blending(False) # fs_emu_blending(True) if item.group: BitmapFont.menu_font.render( text, HEADING_TEXT_LEFT + dx, y + 14, r=0.0, g=0x99 / 0xFF, b=0xCC / 0xFF, ) x, _ = BitmapFont.menu_font.measure(text) x += HEADING_TEXT_LEFT + 12 fs_emu_blending(True) fs_emu_texturing(True) # gl.glDepthMask(False) Texture.heading_strip.render(x + dx, y + 14, 1920 - x, 32) else: BitmapFont.menu_font.render(text, ITEM_TEXT_LEFT + dx, y + 14) gl.glEnable(gl.GL_DEPTH_TEST) # text = item.title.upper() # tw, th = Render.get().text(text, Font.main_path_font, # x + 40, y + 43, color=fg_color) # text = item.subtitle.upper() # fg_color[3] = fg_color[3] * 0.4 # text = item.title.upper() # tw, th = Render.get().text(text, Font.list_subtitle_font, # x + 40, y + 18, color=fg_color) y -= 54 # Gradually erase menu items when transitioning if transition > 1.0: gl.glDisable(gl.GL_DEPTH_TEST) # tr = (transition - 1.0) / 3.0 alpha = max(0.0, (transition - 1.0) / 2.0) Texture.sidebar_background.render( 1920 - Texture.sidebar_background_shadow.w * transition + 200, 0, 1920, Texture.sidebar_background.h, opacity=alpha, ) gl.glEnable(gl.GL_DEPTH_TEST)