예제 #1
0
    def change_colors(self,wid,ev):
        self.fhq.active = False
        if self.pc.portrait_gen:
            cchan = self.pc.portrait_gen.color_channels
        else:
            cchan = gears.color.CHARACTER_COLOR_CHANNELS
        myui = cosplay.ColorEditor(self.pc.get_portrait(add_color=False), 0,
                                   channel_filters=cchan, colors=self.pc.colors)
        pbge.my_state.widgets.append(myui)
        myui.finished = False
        myui.children.append(
            pbge.widgets.LabelWidget(150, 220, 80, 16, text="Done", justify=0, on_click=self.color_done,
                                     draw_border=True, data=myui))

        keepgoing = True
        while keepgoing and not myui.finished and not pbge.my_state.got_quit:
            ev = pbge.wait_event()
            if ev.type == pbge.TIMEREVENT:
                pbge.my_state.view()
                pbge.my_state.do_flip()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    keepgoing = False

        self.pc.colors = myui.colors
        self.portrait = self.pc.get_portrait(self.pc, force_rebuild=True)

        pbge.my_state.widgets.remove(myui)
        pygame.event.clear()
        self.fhq.active = True
        self.info.update()
        pbge.my_state.view.regenerate_avatars([self.pc,])
예제 #2
0
    def browse(self, camp):
        # Run the UI. Return a DoInvocation action if an invocation
        # was chosen, or None if the invocation was cancelled.
        myui = self(camp)
        while myui.keep_browsing:
            gdi = pbge.wait_event()
            myui.update(gdi)

        myui.dispose()
예제 #3
0
    def go( self ):
        # Perform this character's turn.
        #Start by making a hotmap centered on PC, to see how far can move.
        #hm = hotmaps.MoveMap( self.scene, chara )

        # How this is gonna work: There are several modes that can be switched
        #  between: movement, attack, use skill, etc. Each mode is gonna get
        #  a handler. The radio buttons widget determines what mode is current.
        #  Then, this routine routes the input to the correct UI handler.

        buttons_to_add = [(6,7,self.switch_movement,'Movement'),(2,3,self.switch_attack,'Attack'),]
        if self.pc.get_skill_library():
            buttons_to_add.append((8,9,self.switch_skill,'Skills'))
        if self.pc.get_program_library():
            buttons_to_add.append((10, 11, self.switch_programs, 'Programs'))
        buttons_to_add.append((4,5,self.end_turn,'End Turn'))
        self.my_radio_buttons = pbge.widgets.RadioButtonWidget( 8, 8, 220, 40,
         sprite=pbge.image.Image('sys_combat_mode_buttons.png',40,40),
         buttons=buttons_to_add,
         anchor=pbge.frects.ANCHOR_UPPERLEFT )
        pbge.my_state.widgets.append(self.my_radio_buttons)

        self.movement_ui = movementui.MovementUI( self.camp, self.pc )
        self.attack_ui = targetingui.TargetingUI(self.camp,self.pc)
        #self.attack_ui.deactivate()
        self.skill_ui = invoker.InvocationUI(self.camp,self.pc,self.pc.get_skill_library)
        self.program_ui = programsui.ProgramsUI(self.camp,self.pc)

        self.active_ui = self.movement_ui

        keep_going = True
        while self.camp.fight.still_fighting() and (self.camp.fight.cstat[self.pc].action_points > 0 or self.camp.fight.cstat[self.pc].mp_remaining > 0):
            # Get input and process it.
            gdi = pbge.wait_event()

            self.active_ui.update( gdi, self )

            if gdi.type == pygame.KEYDOWN:
                if gdi.unicode == u"Q":
                    keep_going = False
                    self.camp.fight.no_quit = False
                elif gdi.unicode == u"c":
                    pbge.my_state.view.focus( self.pc.pos[0], self.pc.pos[1] )
                elif gdi.key == pygame.K_ESCAPE:
                    mymenu = configedit.PopupGameMenu()
                    mymenu(self.camp.fight)


        pbge.my_state.widgets.remove(self.my_radio_buttons)
        self.movement_ui.dispose()
        self.attack_ui.dispose()
        self.skill_ui.dispose()
        self.program_ui.dispose()
예제 #4
0
    def explo_invoke(cls, explo, pc, build_library_function, source=None):
        # Run the UI. Return a DoInvocation action if an invocation
        # was chosen, or None if the invocation was cancelled.
        myui = cls(explo.camp, pc, build_library_function, source)
        myui.activate()
        while myui.keep_exploring and len(myui.targets) < myui.num_targets:
            gdi = pbge.wait_event()
            myui.update(gdi, None)

        myui.dispose()

        if myui.invo and len(myui.targets) >= myui.num_targets and myui.invo.can_be_invoked(myui.pc, False):
            return exploration.DoInvocation(explo, pc, myui.get_firing_pos(), myui.invo, myui.targets, myui.record)
예제 #5
0
    def create_and_invoke(cls, redraw):
        # Run the UI. Return a DoInvocation action if an invocation
        # was chosen, or None if the invocation was cancelled.
        myui = cls()
        pbge.my_state.widgets.append(myui)
        pbge.my_state.view = redraw
        keepgoing = True
        while keepgoing and not myui.finished and not pbge.my_state.got_quit:
            ev = pbge.wait_event()
            if ev.type == pbge.TIMEREVENT:
                redraw()
                pbge.my_state.do_flip()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    keepgoing = False

        pbge.my_state.widgets.remove(myui)
예제 #6
0
    def create_and_invoke(cls, camp):
        # Run the UI. Return a DoInvocation action if an invocation
        # was chosen, or None if the invocation was cancelled.
        myui = cls(camp)
        pbge.my_state.widgets.append(myui)
        myui.children.append(pbge.widgets.LabelWidget(150,220,80,16,text="Done",justify=0,on_click=myui.done_button,draw_border=True))

        keepgoing = True
        while keepgoing and not myui.finished and not pbge.my_state.got_quit:
            ev = pbge.wait_event()
            if ev.type == pbge.TIMEREVENT:
                pbge.my_state.view()
                pbge.my_state.do_flip()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    keepgoing = False

        pbge.my_state.widgets.remove(myui)
예제 #7
0
    def explo_invoke(cls, redraw):
        # Run the UI. Return a DoInvocation action if an invocation
        # was chosen, or None if the invocation was cancelled.
        myui = cls(pbge.image.Image("card_m_osmund.png",400,600),0,channel_filters=gears.color.CHARACTER_COLOR_CHANNELS)
        pbge.my_state.widgets.append(myui)
        keepgoing = True
        while keepgoing:
            ev = pbge.wait_event()
            if ev.type == pbge.TIMEREVENT:
                redraw()
                pbge.my_state.do_flip()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    keepgoing = False
                elif ev.key == pygame.K_F1:
                    pygame.image.save(myui.display_sprite.bitmap, pbge.util.user_dir("out.png"))

        pbge.my_state.widgets.remove(myui)
        return myui.colors
예제 #8
0
    def open_backpack(self,wid,ev):
        self.fhq.active = False
        myui = backpack.BackpackWidget(self.camp,self.pc)
        pbge.my_state.widgets.append(myui)
        myui.finished = False
        myui.children.append(
            pbge.widgets.LabelWidget(150, 220, 80, 16, text="Done", justify=0, on_click=self.bp_done,
                                     draw_border=True, data=myui))

        keepgoing = True
        while keepgoing and not myui.finished and not pbge.my_state.got_quit:
            ev = pbge.wait_event()
            if ev.type == pbge.TIMEREVENT:
                pbge.my_state.view()
                pbge.my_state.do_flip()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    keepgoing = False

        pbge.my_state.widgets.remove(myui)
        pygame.event.clear()
        self.info.update()
        self.fhq.active = True
예제 #9
0
    def color_edit(self,wid,ev):
        self.active = False
        myui = cosplay.ColorEditor(self.pc.portrait_gen.build_portrait(self.pc,add_color=False),0,channel_filters=self.pc.portrait_gen.color_channels,colors=self.pc.colors)
        pbge.my_state.widgets.append(myui)
        myui.finished = False
        myui.children.append(pbge.widgets.LabelWidget(150,220,80,16,text="Done",justify=0,on_click=self.color_done,draw_border=True,data=myui))

        keepgoing = True
        while keepgoing and not myui.finished and not pbge.my_state.got_quit:
            ev = pbge.wait_event()
            if ev.type == pbge.TIMEREVENT:
                pbge.my_state.view()
                pbge.my_state.do_flip()
            elif ev.type == pygame.KEYDOWN:
                if ev.key == pygame.K_ESCAPE:
                    keepgoing = False

        self.pc.colors = myui.colors
        self.portrait = self.pc.portrait_gen.build_portrait(self.pc,force_rebuild=True)

        pbge.my_state.widgets.remove(myui)
        pygame.event.clear()
        self.active = True
예제 #10
0
    def go(self):
        self.no_quit = True
        self.order = None

        global current_explo
        current_explo = self

        self.update_scene()
        # self.scene.update_party_position(self.camp)

        # Clear the event queue, in case switching scenes took a long time.
        pygame.event.clear([pbge.TIMEREVENT, pygame.KEYDOWN])

        # Do one view first, just to prep the model map and mouse tile.
        self.view()
        pbge.my_state.do_flip()
        # self.record_count = 120

        del pbge.my_state.notifications[:]
        pbge.BasicNotification(str(self.scene))

        # Do a start trigger, unless we're in combat.
        if not self.camp.fight:
            if hasattr(self.scene, "exploration_music"):
                pbge.my_state.start_music(self.scene.exploration_music)
            self.camp.check_trigger("START")
            self.camp.check_trigger("ENTER", self.scene)
        self.camp.check_trigger("UPDATE")
        self.update_npcs()

        while self.keep_exploring():
            first_pc_pos = self.camp.first_active_pc().pos
            if self.camp.fight:
                self.camp.check_trigger("STARTCOMBAT")
                self.order = None
                self.camp.fight.go(self)
                if pbge.my_state.got_quit or not self.camp.fight.no_quit:
                    self.no_quit = False
                    self.camp.fight.no_quit = True
                    break
                else:
                    self.camp.fight = None
                    self.camp.check_trigger("ENDCOMBAT")

            # Get input and process it.
            gdi = pbge.wait_event()

            if not self.keep_exploring():
                pass
            elif gdi.type == pbge.TIMEREVENT:
                self.view.overlays.clear()
                self.threat_viewer.update(self.view, self.threat_tiles)
                self.view()

                # Display info for this tile.
                my_info = self.scene.get_tile_info(self.view)
                if my_info:
                    my_info.view_display()

                pbge.my_state.do_flip()

                if self.record_count > 0:
                    pygame.image.save(
                        pbge.my_state.screen,
                        pbge.util.user_dir(
                            "exanim_{}.png".format(100000 -
                                                   self.record_count)))
                    self.record_count -= 1

                self.time += 1
                if hasattr(self.scene, "exploration_music"):
                    pbge.my_state.start_music(self.scene.exploration_music)

                if self.order:
                    if not self.order(self):
                        self.order = None
                    # self.update_npcs()
                    pcpos = {pc.pos for pc in self.camp.get_active_party()}
                    if pcpos.intersection(self.threat_tiles):
                        self.update_npcs()

                if self.time % 80 == 0:
                    self.update_npcs()

                if self.time % 150 == 0:
                    self.update_enchantments()

                if self.time > 0 and self.time % (pbge.util.config.getint(
                        "GENERAL", "frames_per_second") * 30) == 0:
                    self.camp.check_trigger("HALFMINUTE")

            elif not self.order:
                # Set the mouse cursor on the map.
                # self.view.overlays[ self.view.mouse_tile ] = maps.OVERLAY_CURSOR

                if gdi.type == pygame.KEYDOWN:
                    if pbge.my_state.is_key_for_action(gdi, "quit_game"):
                        # self.camp.save(self.screen)
                        self.no_quit = False
                    elif pbge.my_state.is_key_for_action(gdi, "center_on_pc"):
                        pc = self.camp.first_active_pc()
                        pbge.my_state.view.focus(pc.pos[0], pc.pos[1])

                    elif pbge.my_state.is_key_for_action(gdi, "memo_browser"):
                        memos.MemoBrowser(self.camp)()

                    elif pbge.my_state.is_key_for_action(gdi, "field_hq"):
                        fieldhq.FieldHQ.create_and_invoke(self.camp)

                    elif pbge.my_state.is_key_for_action(gdi, "inventory"):
                        fieldhq.backpack.BackpackWidget.create_and_invoke(
                            self.camp, self.camp.pc.get_root())

                    elif gdi.key == pygame.K_ESCAPE:
                        mymenu = configedit.PopupGameMenu()
                        mymenu(self)

                    elif pbge.my_state.is_key_for_action(gdi, "cursor_click"):
                        if gdi.mod & pygame.KMOD_SHIFT:
                            pc = self.scene.get_main_actor(
                                self.view.mouse_tile)
                            ExploMenu(self, pc)
                        else:
                            self.click_left()

                    elif gdi.unicode == "R" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        print(self.camp.renown)
                    elif gdi.unicode == "A" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.record_count = 30

                    elif gdi.unicode == "X" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        pc = self.camp.first_active_pc()
                        myinvo = pbge.effects.Invocation(
                            fx=geffects.DoCrash(),
                            area=pbge.scenes.targetarea.SingleTarget())
                        myinvo.invoke(self.camp, None, [
                            pc.pos,
                        ], pbge.my_state.view.anim_list)
                        pbge.my_state.view.handle_anim_sequence()

                    elif gdi.unicode == "K" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for lm in self.camp.get_active_party():
                            pc: gears.base.Being = lm.get_pilot()
                            pc.hp_damage += 99999999999999

                    elif gdi.unicode == "J" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        # Experimenting with JSON serialization. It isn't going well.
                        GHEncoder.save_by_json(self.camp)

                    elif gdi.unicode == "&" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for x in range(self.scene.width):
                            for y in range(self.scene.height):
                                self.scene.set_visible(x, y, True)

                    elif gdi.unicode == "!" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.egg.credits += 1000000
                        for mpc in self.camp.get_active_party():
                            pc = mpc.get_pilot()
                            if pc:
                                for skill in pc.statline:
                                    if skill in gears.stats.ALL_SKILLS:
                                        pc.statline[skill] += 10

                    elif gdi.key == pygame.K_F1 and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        pygame.image.save(pbge.my_state.screen,
                                          pbge.util.user_dir("screenshot.png"))

                    elif gdi.unicode == "@" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.scene.contents:
                            if hasattr(thing, "pos"):
                                print("{}: {}".format(thing, thing.pos))

                    elif gdi.unicode == "*" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.camp.all_contents(self.camp):
                            if isinstance(thing, gears.base.Character):
                                print("{}: {}/{}".format(
                                    thing, thing.faction,
                                    thing.scene.get_root_scene()))

                    elif gdi.unicode == "+" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.pc.inv_com.append(
                            gears.selector.get_design_by_full_name("Meat"))

                    elif gdi.unicode == "P" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for thing in self.camp.active_plots():
                            print("{}".format(thing.__class__.__name__))
                    elif gdi.unicode == "C" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        myfac = self.camp.faction_relations.get(
                            self.scene.get_metro_scene().faction)
                        print(myfac.enemies)
                    elif gdi.unicode == "L" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for pc in self.camp.get_active_party():
                            if hasattr(pc, "relationship"
                                       ) and pc.relationship and hasattr(
                                           pc, "renown"):
                                print("{} {} {} OK:{}".format(
                                    pc, pc.renown, pc.relationship.hilights(),
                                    pc.relationship.can_do_development()))
                    elif gdi.unicode == "V" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for pc in list(self.camp.party):
                            if pc in self.scene.contents and isinstance(
                                    pc, gears.base.Mecha
                            ) and not pc.is_operational():
                                pc.free_pilots()
                                print(pc)
                                self.camp.party.remove(pc)
                    elif gdi.unicode == "F" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        for k in self.camp.faction_relations.keys():
                            if self.camp.is_unfavorable_to_pc(k):
                                print("{}: Enemy".format(k))
                            elif self.camp.is_favorable_to_pc(k):
                                print("{}: Ally".format(k))

                    elif gdi.unicode == "E" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        mymenu = pbge.rpgmenu.AlertMenu(
                            "Do you want to end this campaign?")
                        mymenu.add_item("Yes, time to quit.", True)
                        mymenu.add_item("No, I pressed the wrong key.", False)
                        if mymenu.query():
                            self.camp.eject()

                    elif gdi.unicode == "O" and pbge.util.config.getboolean(
                            "GENERAL", "dev_mode_on"):
                        self.camp.version = "v0.100"

                elif gdi.type == pygame.QUIT:
                    # self.camp.save(self.screen)
                    self.no_quit = False

                elif gdi.type == pygame.MOUSEBUTTONUP:
                    if gdi.button == 1:
                        self.click_left()
                    else:
                        pc = self.scene.get_main_actor(self.view.mouse_tile)
                        ExploMenu(self, pc)

        if not self.no_quit:
            self.camp.save()
        else:
            self.camp.check_trigger("END")

        current_explo = None
예제 #11
0
    def go(self):
        self.no_quit = True
        self.order = None

        self.update_scene()
        # Clear the event queue, in case switching scenes took a long time.
        pygame.event.clear([pbge.TIMEREVENT, pygame.KEYDOWN])

        # Do one view first, just to prep the model map and mouse tile.
        self.view()
        pbge.my_state.do_flip()

        # Do a start trigger, unless we're in combat.
        if not self.camp.fight:
            self.camp.check_trigger("START")

        while self.keep_exploring():
            first_pc_pos = self.camp.first_active_pc().pos
            if self.camp.fight:
                self.camp.check_trigger("STARTCOMBAT")
                self.order = None
                self.camp.fight.go()
                if pbge.my_state.got_quit or not self.camp.fight.no_quit:
                    self.no_quit = False
                    break
                self.camp.fight = None
                self.camp.check_trigger("ENDCOMBAT")

            # Get input and process it.
            gdi = pbge.wait_event()

            if not self.keep_exploring():
                pass
            elif gdi.type == pbge.TIMEREVENT:
                self.view.overlays.clear()
                self.view.overlays[self.view.mouse_tile] = (self.mapcursor, 0)
                self.view()

                # Display info for this tile.
                my_info = self.scene.get_tile_info(self.view.mouse_tile)
                if my_info:
                    my_info.popup()

                pbge.my_state.do_flip()

                #self.time += 1
                if hasattr(self.scene, "exploration_music"):
                    pbge.my_state.start_music(self.scene.exploration_music)

                if self.order:
                    if not self.order(self):
                        self.order = None

                self.update_npcs()

                #if self.time % 150 == 0:
                #    self.update_enchantments()

            elif not self.order:
                # Set the mouse cursor on the map.
                #self.view.overlays[ self.view.mouse_tile ] = maps.OVERLAY_CURSOR

                if gdi.type == pygame.KEYDOWN:
                    if gdi.unicode == u"Q":
                        #self.camp.save(self.screen)
                        self.no_quit = False
                    elif gdi.unicode == u"c":
                        pc = self.camp.first_active_pc()
                        pbge.my_state.view.focus(pc.pos[0], pc.pos[1])
                    elif gdi.key == pygame.K_ESCAPE:
                        mymenu = configedit.PopupGameMenu()
                        mymenu(self)

                elif gdi.type == pygame.QUIT:
                    #self.camp.save(self.screen)
                    self.no_quit = False

                elif gdi.type == pygame.MOUSEBUTTONUP:
                    if gdi.button == 1:
                        # Left mouse button.
                        if (self.view.mouse_tile != self.camp.pc.get_root().pos
                            ) and self.scene.on_the_map(*self.view.mouse_tile):
                            npc = self.view.modelmap.get(self.view.mouse_tile)
                            if npc and npc[0].is_operational(
                            ) and self.scene.is_an_actor(npc[0]):
                                self.order = TalkTo(self, npc[0])
                                self.view.overlays.clear()
                            else:
                                self.order = MoveTo(self, self.view.mouse_tile)
                                self.view.overlays.clear()
예제 #12
0
    def go(self):
        # Perform this character's turn.
        #Start by making a hotmap centered on PC, to see how far can move.
        #hm = hotmaps.MoveMap( self.scene, chara )

        # How this is gonna work: There are several modes that can be switched
        #  between: movement, attack, use skill, etc. Each mode is gonna get
        #  a handler. The radio buttons widget determines what mode is current.
        #  Then, this routine routes the input to the correct UI handler.

        buttons_to_add = [
            (6, 7, self.switch_movement, 'Movement'),
            (2, 3, self.switch_attack, 'Attack'),
        ]
        has_skills = self.pc.get_skill_library(True)
        if has_skills:
            buttons_to_add.append((8, 9, self.switch_skill, 'Skills'))
        has_programs = self.pc.get_program_library()
        if has_programs:
            buttons_to_add.append((10, 11, self.switch_programs, 'Programs'))
        buttons_to_add.append((4, 5, self.end_turn, 'End Turn'))
        self.my_radio_buttons = pbge.widgets.RadioButtonWidget(
            8,
            8,
            220,
            40,
            sprite=pbge.image.Image('sys_combat_mode_buttons.png', 40, 40),
            buttons=buttons_to_add,
            anchor=pbge.frects.ANCHOR_UPPERLEFT)
        pbge.my_state.widgets.append(self.my_radio_buttons)

        self.top_shelf_funs = dict()
        self.bottom_shelf_funs = dict()
        self.movement_ui = movementui.MovementUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf)
        self.bottom_shelf_funs[self.movement_ui] = self.switch_attack
        self.attack_ui = targetingui.TargetingUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf)
        self.top_shelf_funs[self.attack_ui] = self.switch_movement
        if has_skills:
            self.bottom_shelf_funs[self.attack_ui] = self.switch_skill
        elif has_programs:
            self.bottom_shelf_funs[self.attack_ui] = self.switch_programs
        #self.attack_ui.deactivate()
        self.skill_ui = invoker.InvocationUI(
            self.camp,
            self.pc,
            self._get_skill_library,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf)
        self.top_shelf_funs[self.skill_ui] = self.switch_attack
        if has_programs:
            self.bottom_shelf_funs[self.skill_ui] = self.switch_programs
        self.program_ui = programsui.ProgramsUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf)
        if has_skills:
            self.top_shelf_funs[self.program_ui] = self.switch_skill
        else:
            self.top_shelf_funs[self.program_ui] = self.switch_attack

        self.active_ui = self.movement_ui

        keep_going = True
        while self.camp.fight.still_fighting() and (
                self.camp.fight.cstat[self.pc].action_points > 0
                or self.camp.fight.cstat[self.pc].mp_remaining > 0):
            # Get input and process it.
            gdi = pbge.wait_event()

            self.active_ui.update(gdi, self)

            if gdi.type == pygame.KEYDOWN:
                if gdi.unicode == "Q":
                    keep_going = False
                    self.camp.fight.no_quit = False
                elif gdi.unicode == "c":
                    pbge.my_state.view.focus(self.pc.pos[0], self.pc.pos[1])
                elif gdi.key == pygame.K_ESCAPE:
                    mymenu = configedit.PopupGameMenu()
                    mymenu(self.camp.fight)

        pbge.my_state.widgets.remove(self.my_radio_buttons)
        self.movement_ui.dispose()
        self.attack_ui.dispose()
        self.skill_ui.dispose()
        self.program_ui.dispose()
예제 #13
0
    def go( self ):
        self.no_quit = True
        self.order = None

        self.update_scene()
        #self.scene.update_party_position(self.camp)

        # Clear the event queue, in case switching scenes took a long time.
        pygame.event.clear([pbge.TIMEREVENT,pygame.KEYDOWN])

        # Do one view first, just to prep the model map and mouse tile.
        self.view()
        pbge.my_state.do_flip()

        # Do a start trigger, unless we're in combat.
        if not self.camp.fight:
            self.camp.check_trigger( "START" )
            self.camp.check_trigger( "ENTER", self.scene )


        while self.keep_exploring():
            first_pc_pos=self.camp.first_active_pc().pos
            if self.camp.fight:
                self.camp.check_trigger( "STARTCOMBAT" )
                self.order = None
                self.camp.fight.go()
                if pbge.my_state.got_quit or not self.camp.fight.no_quit:
                    self.no_quit = False
                    self.camp.fight.no_quit = True
                    break
                else:
                    self.camp.fight = None
                    self.camp.check_trigger( "ENDCOMBAT" )

            # Get input and process it.
            gdi = pbge.wait_event()

            if not self.keep_exploring():
                pass
            elif gdi.type == pbge.TIMEREVENT:
                self.view.overlays.clear()
                self.view.overlays[ self.view.mouse_tile ] = (self.mapcursor,0)
                self.view()

                # Display info for this tile.
                my_info = self.scene.get_tile_info(self.view.mouse_tile)
                if my_info:
                    my_info.popup()

                pbge.my_state.do_flip()

                self.time += 1
                if hasattr(self.scene,"exploration_music"):
                    pbge.my_state.start_music(self.scene.exploration_music)

                if self.order:
                    if not self.order( self ):
                        self.order = None

                self.update_npcs()
                if self.time % 150 == 0:
                    self.update_enchantments()

            elif not self.order:
                # Set the mouse cursor on the map.
                #self.view.overlays[ self.view.mouse_tile ] = maps.OVERLAY_CURSOR

                if gdi.type == pygame.KEYDOWN:
                    if gdi.unicode == u"Q":
                        #self.camp.save(self.screen)
                        self.no_quit = False
                    elif gdi.unicode == u"c":
                        pc = self.camp.first_active_pc()
                        pbge.my_state.view.focus( pc.pos[0], pc.pos[1] )
                    elif gdi.unicode == u"X":
                        self.camp.save()
                    elif gdi.unicode == u"m":
                        memobrowser.MemoBrowser.browse(self.camp)
                    elif gdi.unicode == u"R":
                        print self.camp.scene.get_root_scene()

                    elif gdi.unicode == u"&":
                        for x in range(self.scene.width):
                            for y in range(self.scene.height):
                                self.scene.set_visible(x,y,True)
                    elif gdi.unicode == u"H":
                        fieldhq.FieldHQ.create_and_invoke(self.camp)
                    elif gdi.key == pygame.K_ESCAPE:
                        mymenu = configedit.PopupGameMenu()
                        mymenu(self)

                elif gdi.type == pygame.QUIT:
                    #self.camp.save(self.screen)
                    self.no_quit = False

                elif gdi.type == pygame.MOUSEBUTTONUP:
                    if gdi.button == 1:
                        # Left mouse button.
                        if ( self.view.mouse_tile != self.camp.pc.get_root().pos ) and self.scene.on_the_map( *self.view.mouse_tile ):
                            npc = self.view.modelmap.get(self.view.mouse_tile)
                            if npc and npc[0].is_operational() and self.scene.is_an_actor(npc[0]):
                                npteam = self.scene.local_teams.get(npc[0])
                                if npteam and self.scene.player_team.is_enemy(npteam):
                                    self.activate_foe(npc[0])
                                elif not isinstance(npc[0],gears.base.Prop):
                                    self.order = TalkTo( self, npc[0] )
                                    self.view.overlays.clear()
                            else:
                                self.order = MoveTo( self, self.view.mouse_tile )
                                self.view.overlays.clear()
                    else:
                        pc = self.scene.get_main_actor(self.view.mouse_tile)
                        ExploMenu(self,pc)

        if not self.no_quit:
            self.camp.check_trigger("END")
            self.camp.save()
예제 #14
0
    def go(self):
        # Perform this character's turn.
        #Start by making a hotmap centered on PC, to see how far can move.
        #hm = hotmaps.MoveMap( self.scene, chara )

        # How this is gonna work: There are several modes that can be switched
        #  between: movement, attack, use skill, etc. Each mode is gonna get
        #  a handler. The radio buttons widget determines what mode is current.
        #  Then, this routine routes the input to the correct UI handler.
        # Create all the UIs first. Then create the top_shelf and bottom_shelf switch lists based
        # on which UIs this character needs.
        self.all_funs = dict()
        self.all_uis = list()

        buttons_to_add = [
            (6, 7, self.switch_movement, 'Movement'),
            (2, 3, self.switch_attack, 'Attack'),
        ]

        self.movement_ui = movementui.MovementUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf)
        self.all_uis.append(self.movement_ui)
        self.all_funs[self.movement_ui] = self.switch_movement

        self.attack_ui = targetingui.TargetingUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf,
            name="attacks")
        self.all_uis.append(self.attack_ui)
        self.all_funs[self.attack_ui] = self.switch_attack

        has_skills = self.pc.get_skill_library(True)
        self.skill_ui = invoker.InvocationUI(
            self.camp,
            self.pc,
            self._get_skill_library,
            top_shelf_fun=self.switch_top_shelf,
            name="skills",
            bottom_shelf_fun=self.switch_bottom_shelf)
        if has_skills:
            buttons_to_add.append((8, 9, self.switch_skill, 'Skills'))
            self.all_uis.append(self.skill_ui)
            self.all_funs[self.skill_ui] = self.switch_skill

        has_programs = self.pc.get_program_library()
        self.program_ui = programsui.ProgramsUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf,
            name="programs")
        if has_programs:
            buttons_to_add.append((10, 11, self.switch_programs, 'Programs'))
            self.all_uis.append(self.program_ui)
            self.all_funs[self.program_ui] = self.switch_programs

        has_usables = self.pc.get_usable_library()
        self.usable_ui = usableui.UsablesUI(
            self.camp,
            self.pc,
            top_shelf_fun=self.switch_top_shelf,
            bottom_shelf_fun=self.switch_bottom_shelf,
            name="usables")
        if has_usables:
            buttons_to_add.append((12, 13, self.switch_usables, 'Usables'))
            self.all_uis.append(self.usable_ui)
            self.all_funs[self.usable_ui] = self.switch_usables

        buttons_to_add.append((4, 5, self.end_turn, 'End Turn'))
        self.my_radio_buttons = pbge.widgets.RadioButtonWidget(
            8,
            8,
            220,
            40,
            sprite=pbge.image.Image('sys_combat_mode_buttons.png', 40, 40),
            buttons=buttons_to_add,
            anchor=pbge.frects.ANCHOR_UPPERLEFT)
        pbge.my_state.widgets.append(self.my_radio_buttons)

        # Add the top_shelf and bottom_shelf functions
        self.top_shelf_funs = dict()
        self.bottom_shelf_funs = dict()
        for t in range(len(self.all_uis)):
            if t > 0:
                self.top_shelf_funs[self.all_uis[t]] = self.all_funs[
                    self.all_uis[t - 1]]
            if t < (len(self.all_uis) - 1):
                self.bottom_shelf_funs[self.all_uis[t]] = self.all_funs[
                    self.all_uis[t + 1]]

        self.active_ui = self.movement_ui

        keep_going = True
        while self.camp.fight.still_fighting() and (
                self.pc in self.camp.scene.contents) and (
                    self.camp.fight.cstat[self.pc].action_points > 0
                    or self.camp.fight.cstat[self.pc].mp_remaining > 0):
            # Get input and process it.
            gdi = pbge.wait_event()

            self.active_ui.update(gdi, self)

            if gdi.type == pygame.KEYDOWN:
                if gdi.unicode.isalpha() and gdi.mod & pygame.KMOD_ALT:
                    # Record a hotkey.
                    self.record_hotkey(gdi.unicode)
                elif gdi.unicode.isalpha() and pbge.util.config.has_option(
                        "HOTKEYS", gdi.unicode):
                    self.find_this_option(
                        pbge.util.config.get("HOTKEYS", gdi.unicode))
                elif gdi.unicode == "Q":
                    keep_going = False
                    self.camp.fight.no_quit = False
                elif gdi.unicode == "c":
                    self.focus_on_pc()
                elif gdi.key == pygame.K_ESCAPE:
                    mymenu = configedit.PopupGameMenu()
                    mymenu(self.camp.fight)
            elif gdi.type == pygame.MOUSEBUTTONUP:
                if gdi.button == 3:
                    self.pop_menu()

        pbge.my_state.widgets.remove(self.my_radio_buttons)
        pbge.my_state.view.overlays.clear()

        for ui in self.all_uis:
            ui.dispose()