コード例 #1
0
    def __init__(self, rect: Rect, color: Optional[Color]):
        super().__init__(rect, color)
        self.main = None
        self.nicks = []
        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.sock = socket.socket()
        self.sock.bind((config['server']['ip'], config['server']['port']))
        self.sock.listen(1)

        manager = Manager()
        self.connection_list = manager.dict()
        self.new_connections = manager.list()
        self.receive_list = manager.list()

        self.connection_process = Process(
            target=connection_function,
            args=(self.sock, self.connection_list, self.new_connections,
                  self.receive_list))
        self.connection_process.start()

        self.parent_conn, self.child_conn = Pipe()
        self.send_process = Process(target=send_function,
                                    args=(self.connection_list,
                                          self.child_conn))
        self.send_process.daemon = True
        self.send_process.start()
コード例 #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.dialogs = []
        with open('assets/dialogs.json') as json_file:
            for dialog_json in json.load(json_file):
                self.dialogs.append(DialogModel(**dialog_json))

        self.current_dialog: Optional[DialogModel] = None
        self.message_delay = 45

        self.message_queue = []
        self.timer = self.message_delay
        self.responses = UIElement(Rect(0, 0, 0, 0),
                                   None,
                                   absolute_anchor=Anchor.BOTTOM_RIGHT,
                                   relative_anchor=Anchor.BOTTOM_RIGHT)
        self.append_child(self.responses)

        self.messages_count = 0
        self.messages_container = MessagesScroll(
            Rect(0, 10, self.relative_bounds.w * 0.99,
                 self.relative_bounds.h * 0.9),
            Color('beige'),
            absolute_anchor=Anchor.TOP_CENTER,
            relative_anchor=Anchor.TOP_CENTER,
            max_offset=0)
        self.append_child(self.messages_container)

        self.on_dialog_started('initial')
コード例 #3
0
ファイル: client.py プロジェクト: RustyGuard/BO4OK-v2
    def __init__(self, rect: Rect, color: Optional[Color]):
        super().__init__(rect, color)
        self.main = None
        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.sock = socket.socket()
        self.sock.connect(('localhost', 9090))
        print('Connected')

        manager = Manager()
        self.receive_list = manager.list()
        self.socket_process = Process(target=listen,
                                      args=(self.sock, self.receive_list))
        self.socket_process.start()

        self.parent_conn, self.child_conn = Pipe()
        self.send_process = Process(target=send_function,
                                    args=(self.sock, self.child_conn))
        self.send_process.daemon = True
        self.send_process.start()

        self.parent_conn.send(
            (['nick', "".join(random.sample(list(ascii_letters), 5))], None))
コード例 #4
0
 def __init__(self):
     UIScene.__init__(self, "play")
     self.map_p = UIElement(UIConfig.MAP_X, UIConfig.MAP_Y, UIConfig.MAP_W,
                            UIConfig.MAP_H)
     self.stat_p = UIElement(UIConfig.STAT_X, UIConfig.STAT_Y,
                             UIConfig.STAT_W, UIConfig.STAT_H, "Stats")
     self.msg_p = UIElement(UIConfig.MSG_X, UIConfig.MSG_Y, UIConfig.MSG_W,
                            UIConfig.MSG_H, "Messages")
     self.skl_p = UIElement(UIConfig.SKL_X, UIConfig.SKL_Y, UIConfig.SKL_W,
                            UIConfig.SKL_H, "Skills")
     self.info_p = UIElement(UIConfig.INFO_X, UIConfig.INFO_Y,
                             UIConfig.INFO_W, UIConfig.INFO_H, "Info")
コード例 #5
0
    def __init__(self, rect: Rect, color: Optional[Color], sock,
                 connection_list, receive_list, parent_conn, child_conn,
                 send_process, nicks):
        mod_loader.import_mods()

        super().__init__(rect, color)

        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.sock = sock
        self.connection_list = connection_list
        self.receive_list = receive_list
        self.child_conn = child_conn
        self.parent_conn = parent_conn
        self.send_process = send_process

        self.game = Game(Game.Side.SERVER,
                         mod_loader,
                         self.parent_conn,
                         nicks,
                         -1,
                         connection_list=self.connection_list)

        self.minimap_elem = UIImage(
            Rect(0, config['screen']['size'][1] - 388, 0, 0),
            'assets/sprite/minimap.png')

        self.minimap = Minimap(self.game)
        self.minimap_elem.append_child(self.minimap)

        self.append_child(self.minimap_elem)
        self.game.create_unit('warrior', (0, 0))
        self.game.create_unit('fortress', (500, 0))
        self.game.create_unit('fortress', (-500, 0))
        self.game.create_unit('archer', (-25, -25))
        self.game.create_unit('archer', (25, -25))
        self.game.create_unit('archer', (-25, 25))
        self.game.create_unit('archer', (25, 25))
コード例 #6
0
ファイル: label.py プロジェクト: DGmoN/Genger
 def __init__(self, Text=""):
     UIElement.__init__(self)
     self.text = Text
コード例 #7
0
ファイル: label.py プロジェクト: DGmoN/Genger
 def render(self, surface):
     UIElement.render(self, surface)
     from display import Window
     text = Window.get_font_provider().render(self.text)
     surface.blit(text, (5, 5))
コード例 #8
0
ファイル: slideBar.py プロジェクト: DGmoN/Genger
 def render(self, surface):
     UIElement.render(self, surface)
     from pygame import draw
     w, h = self.size
     draw.rect(surface, (255,255,255), (w * self.level, 0, 5, h))
コード例 #9
0
ファイル: slideBar.py プロジェクト: DGmoN/Genger
 def __init__(self, onChange):
     UIElement.__init__(self)
     self.level = 0.5
     self.focused = False
     self.onChange = onChange
コード例 #10
0
class PlayScene(UIScene):
    def __init__(self):
        UIScene.__init__(self, "play")
        self.map_p = UIElement(UIConfig.MAP_X, UIConfig.MAP_Y, UIConfig.MAP_W,
                               UIConfig.MAP_H)
        self.stat_p = UIElement(UIConfig.STAT_X, UIConfig.STAT_Y,
                                UIConfig.STAT_W, UIConfig.STAT_H, "Stats")
        self.msg_p = UIElement(UIConfig.MSG_X, UIConfig.MSG_Y, UIConfig.MSG_W,
                               UIConfig.MSG_H, "Messages")
        self.skl_p = UIElement(UIConfig.SKL_X, UIConfig.SKL_Y, UIConfig.SKL_W,
                               UIConfig.SKL_H, "Skills")
        self.info_p = UIElement(UIConfig.INFO_X, UIConfig.INFO_Y,
                                UIConfig.INFO_W, UIConfig.INFO_H, "Info")

    def render_map(self):
        m = GAME.cur_map
        p = GAME.player
        start_x, start_y = m.cam(p.x, p.y)
        fg = None
        bg = None
        glyph = 0
        wall = GameMap.TILES['#']
        for x in range(start_x, start_x + UIConfig.MAP_W):
            for y in range(start_y, start_y + UIConfig.MAP_H):
                t = m.get_tile(x, y)
                neis = m.neighbors_int(x, y)
                if t.name == "null" and neis > 0:
                    bg = m.wall_color
                    glyph = wall.ascii
                elif t.name == "floor":
                    bg = m.floor_color
                    glyph = t.ascii
                else:
                    fg = t.fg
                    bg = t.bg
                    glyph = t.ascii
                if neis > 0:
                    screen_x, screen_y = m.to_screen(x, y, p.x, p.y)
                    self.map_p.put(screen_x, screen_y, glyph, fg, bg)

        for e in sorted(GAME.cur_things, key=lambda a: a.layer, reverse=True):
            ps_x, ps_y = m.to_screen(e.x, e.y, e.x, e.y)
            if 0 <= ps_x < UIConfig.MAP_W and 0 <= ps_y < UIConfig.MAP_H:
                self.map_p.put(ps_x, ps_y, e.glyph, e.color)

    def render_skills(self):
        self.skl_p.border()

    def render_stats(self):
        self.stat_p.border()

    def render_msgs(self):
        self.msg_p.border()

    def render_info(self):
        self.info_p.border()

    def render(self):
        self.render_skills()
        self.render_info()
        self.render_msgs()
        self.render_info()
        self.render_stats()
        self.render_map()

    def handle_input(self, key, shift):
        moves = {
            terminal.TK_KP_8: 'N',
            terminal.TK_UP: 'N',
            terminal.TK_KP_9: 'NE',
            terminal.TK_KP_6: 'E',
            terminal.TK_RIGHT: 'E',
            terminal.TK_KP_3: 'SE',
            terminal.TK_KP_2: 'S',
            terminal.TK_DOWN: 'S',
            terminal.TK_KP_1: 'SW',
            terminal.TK_KP_4: 'W',
            terminal.TK_LEFT: 'W',
            terminal.TK_KP_7: 'NW'
        }

        d = moves.get(key, None)

        if d:
            GAME.player.move_by(d)
        else:
            print(f'Key {key} was pressed.')

    def enter(self):
        player = Entity(layer=4, color='cyan', map_id="mines")
        player.set_player()
        player.ai.push(PlayerAI())
        player.move(1, 1)
        wolf = make_creature('wolf', color='yellow', map_id="mines")
        mines = generate_caves(85, 85, "Mines", "mines")
        GAME.add_map(mines)
        GAME.add(player)
        GAME.add(wolf)
        GAME.cur_map_id = "mines"
        UIScene.enter(self)
コード例 #11
0
class DialogWindow(UIElement):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.dialogs = []
        with open('assets/dialogs.json') as json_file:
            for dialog_json in json.load(json_file):
                self.dialogs.append(DialogModel(**dialog_json))

        self.current_dialog: Optional[DialogModel] = None
        self.message_delay = 45

        self.message_queue = []
        self.timer = self.message_delay
        self.responses = UIElement(Rect(0, 0, 0, 0),
                                   None,
                                   absolute_anchor=Anchor.BOTTOM_RIGHT,
                                   relative_anchor=Anchor.BOTTOM_RIGHT)
        self.append_child(self.responses)

        self.messages_count = 0
        self.messages_container = MessagesScroll(
            Rect(0, 10, self.relative_bounds.w * 0.99,
                 self.relative_bounds.h * 0.9),
            Color('beige'),
            absolute_anchor=Anchor.TOP_CENTER,
            relative_anchor=Anchor.TOP_CENTER,
            max_offset=0)
        self.append_child(self.messages_container)

        self.on_dialog_started('initial')

    def get_dialog(self, name: str) -> DialogModel:
        for dialog in self.dialogs:
            if dialog.name == name:
                return dialog
        raise ValueError(f'No dialog with name = {name}')

    @property
    def current_dialog_name(self):
        return self.current_dialog.name if self.current_dialog else None

    def on_dialog_started(self, name: str):
        self.current_dialog = self.get_dialog(name)
        self.responses.clear_children()
        if self.current_dialog.messages:
            for msg in self.current_dialog.messages:
                self.message_queue.append(msg)
        else:
            self.on_dialog_ended()

    def on_dialog_ended(self):
        if self.current_dialog.next_dialog:
            self.on_dialog_started(self.current_dialog.next_dialog)
            return

        if self.current_dialog.responses:
            self.show_response_buttons(self.current_dialog.responses)

        self.current_dialog = None

    def response(self, btn, dialog_name, messages):
        for msg in messages:
            self.message_queue.append(msg)

        self.on_dialog_started(dialog_name)

        self.messages_container.scroll_to_bottom()

    def update(self, event):
        if event.type == EVENT_UPDATE:
            if not self.message_queue or not self.current_dialog:
                return

            self.timer -= 1
            if self.timer > 0:
                return

            self.timer = self.message_delay

            self.messages_container.add_message(self.message_queue.pop(0))
            if not self.message_queue:
                self.on_dialog_ended()

        super().update(event)

    def show_response_buttons(self, responses: list[DialogResponse]):
        for i, response in enumerate(responses):
            btn = UIButton(Rect(-5 - i * 150, -5, 145, 25),
                           Color(response.button_color),
                           self.response,
                           response.next_dialog,
                           response.messages,
                           relative_anchor=Anchor.BOTTOM_RIGHT,
                           absolute_anchor=Anchor.BOTTOM_RIGHT,
                           text=response.text,
                           text_color=Color(response.text_color))

            self.responses.append_child(btn)
コード例 #12
0
ファイル: panel.py プロジェクト: DGmoN/Genger
 def __init__(self):
     UIElement.__init__(self)
     self.addContextListner("size", self.reposition)
     self.layout = Layout()
コード例 #13
0
ファイル: client.py プロジェクト: RustyGuard/BO4OK-v2
    def __init__(self, rect: Rect, color: Optional[Color], sock, receive_list,
                 socket_process, parent_conn, child_conn, send_process, nicks,
                 team_id):
        super().__init__(rect, color)

        self.sock = sock
        self.receive_list = receive_list
        self.socket_process = socket_process
        self.parent_conn = parent_conn
        self.child_conn = child_conn
        self.send_process = send_process

        mod_loader.import_mods()

        config.reload()

        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.game = Game(Game.Side.CLIENT, mod_loader, self.parent_conn, nicks,
                         team_id)

        self.minimap = Minimap(self.game)
        self.minimap_elem = UIImage(
            Rect(0, config['screen']['size'][1] - 388, 0, 0),
            'assets/sprite/minimap.png')
        self.minimap_elem.append_child(self.minimap)

        self.minimap_elem.append_child(
            ResourceMenu(self.game.current_player, Rect(45, 108, 0, 0),
                         Font('assets/fonts/arial.ttf', 25)))

        menu_parent = UIElement(Rect(0, 0, 0, 0), None)
        self.append_child(menu_parent)
        menu_parent.append_child(self.minimap_elem)
        menu_parent.append_child(BuildMenu(self.relative_bounds, self.game))
        menu_parent.append_child(ProduceMenu(self.relative_bounds, self.game))
コード例 #14
0
 def __init__(self):
     UIElement.__init__(self)
     MouseObservable.__init__(self)
     self.setSize((140, 140))
     self.background.color = (200, 200, 200, 255)