def show(self): """Shows the dialog and enters an event-handling loop.""" from code.g import play_music self.visible = True self.key_down = None self.start_timer() # Pretend to jiggle the mouse pointer, to force buttons to update their # selected state. Dialog.top.maybe_update() self.fake_mouse() # Force a timer tick at the start to make sure everything's initialized. if self.needs_timer: self.handle(pygame.event.Event(pygame.USEREVENT)) Dialog.top.maybe_update() pygame.display.flip() while True: # Update handles updates of all kinds to all widgets, as needed. Dialog.top.maybe_update() play_music() event = pygame.event.wait() result = self.handle(event) if result != constants.NO_RESULT: self.visible = False return result self.stop_timer()
def on_tick(self, event): if not g.pl.intro_shown: g.pl.intro_shown = True self.show_intro() self.leftovers += g.curr_speed / float(gg.FPS) if self.leftovers < 1: return self.needs_rebuild = True secs = int(self.leftovers) self.leftovers %= 1 old_speed = g.curr_speed # Run this tick. mins_passed = g.pl.give_time(secs) if old_speed != g.curr_speed: self.find_speed_button() # Update the day/night image every minute of game time, or at # midnight if going fast. if g.curr_speed == 0 or (mins_passed and g.curr_speed < 100000) \ or (g.curr_speed>=100000 and g.pl.time_hour==0): self.map.needs_rebuild = True lost = g.pl.lost_game() if lost > 0: g.play_music("lose") self.show_message(g.strings["lost_nobases"] if lost == 1 else g.strings["lost_sus"]) raise constants.ExitDialog
def set_sound(self, value): if value: self.sound_toggle.text = _("YES") else: self.sound_toggle.text = _("NO") if g.nosound == (not value): # No transition requested, bail out return g.nosound = not value if g.nosound: if g.mixerinit: pygame.mixer.music.stop() else: g.play_sound("click") g.play_music(g.music_class) # force music switch at same dir
def on_tick(self, event): old_speed = g.curr_speed if not g.pl.intro_shown: g.pl.intro_shown = True self.needs_warning = False self.show_story_section("Intro") if self.needs_warning: self.warnings.show_dialog() self.needs_warning = False mins_passed = 0 if g.curr_speed != 0: self.leftovers += g.curr_speed / float(gg.FPS) if self.leftovers < 1: return self.needs_rebuild = True secs = int(self.leftovers) self.leftovers %= 1 # Run this tick. mins_passed = g.pl.give_time(secs) if old_speed != g.curr_speed: self.find_speed_button() # Update the day/night image every minute of game time, or at # midnight if going fast. if g.curr_speed == 0 or (mins_passed and g.curr_speed < 100000) \ or (g.curr_speed>=100000 and g.pl.time_hour==0): self.map.needs_rebuild = True lost = g.pl.lost_game() if lost > 0: lost_story = ["", "Lost No Bases", "Lost Suspicion"] g.play_music("lose") self.show_story_section(lost_story[lost]) raise constants.ExitDialog