Ejemplo n.º 1
0
 def __init__(self, rect):
     Window.__init__(self, rect)
     self.text_rect = self.inner_rect.inflate(-32, -32)  # テキストを表示する矩形
     self.text = []  # メッセージ
     self.cur_page = 0  # 現在表示しているページ
     self.max_page = 0  # 最終ページ
     self.msg_engine = MessageEngine()  # メッセージエンジン
     self.cursor = load_image(os.path.join("data", "cursor.png"))  # カーソル画像
Ejemplo n.º 2
0
 def __init__(self, rect):
     Window.__init__(self, rect)
     self.text_rect = self.inner_rect.inflate(-32, -32)  # テキストを表示する矩形
     self.text = []  # メッセージ
     self.cur_page = 0  # 現在表示しているページ
     self.cur_pos = 0  # 現在ページで表示した最大文字数
     self.next_flag = False  # 次ページがあるか?
     self.hide_flag = False  # 次のキー入力でウィンドウを消すか?
     self.msg_engine = MessageEngine()  # メッセージエンジン
     self.cursor = load_image(os.path.join("data", "cursor.png"))  # カーソル画像
     self.frame = 0
Ejemplo n.º 3
0
def main():
    pygame.init()
    screen = pygame.display.set_mode(SCREEN_RECT.size)
    pygame.display.set_caption("Map Editor")
    palette = MapchipPalette(screen)
    cursor = Cursor()
    fieldMap = Map(screen, cursor, palette)
    cursor.set_map(fieldMap)
    messageEngine = MessageEngine()
    clock = pygame.time.Clock()
    state = STATE_MAP

    while True:
        clock.tick(60)
        screen.fill((0, 0, 0))
        if state == STATE_MAP:
            cursor.update()
            fieldMap.update()
            fieldMap.draw()
            draw_selection(messageEngine, screen, palette, cursor, fieldMap)
        elif state == STATE_PALETTE:
            if palette.update():
                state = STATE_MAP
                pygame.event.clear()
                continue
            palette.draw()
        pygame.display.update()

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                elif event.key == K_SPACE:
                    if state == STATE_MAP:
                        state = STATE_PALETTE
                    elif state == STATE_PALETTE:
                        palette.paletteIdx = (palette.paletteIdx +
                                              1) % palette.numPalette
                        if palette.paletteIdx == 0:
                            state = STATE_MAP
                elif event.key == K_g:
                    fieldMap.showGrid = not fieldMap.showGrid
                elif event.key == K_1:
                    fieldMap.layer = fieldMap.LAYER_BOTTOM
                elif event.key == K_2:
                    fieldMap.layer = fieldMap.LAYER_TOP
                elif event.key == K_3:
                    fieldMap.layer = fieldMap.LAYER_BOTH
            elif event.type == MOUSEBUTTONDOWN:
                if event.button in [4, 5]:  # mouse scroll
                    palette.handle_mouse(event.button)
Ejemplo n.º 4
0
class MessageWindow(Window):
    """メッセージウィンドウ"""
    MAX_CHARS_PER_LINE = 20  # 1行の最大文字数
    MAX_LINES_PER_PAGE = 3  # 1行の最大行数(4行目は▼用)
    MAX_CHARS_PER_PAGE = 20 * 3  # 1ページの最大文字数
    MAX_LINES = 30  # メッセージを格納できる最大行数
    LINE_HEIGHT = 8  # 行間の大きさ
    animcycle = 24

    def __init__(self, rect):
        Window.__init__(self, rect)
        self.text_rect = self.inner_rect.inflate(-32, -32)  # テキストを表示する矩形
        self.text = []  # メッセージ
        self.cur_page = 0  # 現在表示しているページ
        self.cur_pos = 0  # 現在ページで表示した最大文字数
        self.next_flag = False  # 次ページがあるか?
        self.hide_flag = False  # 次のキー入力でウィンドウを消すか?
        self.msg_engine = MessageEngine()  # メッセージエンジン
        self.cursor = load_image(os.path.join("data", "cursor.png"))  # カーソル画像
        self.frame = 0

    def set(self, message):
        """メッセージをセットしてウィンドウを画面に表示する"""
        self.cur_pos = 0
        self.cur_page = 0
        self.next_flag = False
        self.hide_flag = False
        # 全角スペースで初期化
        self.text = [' '] * (self.MAX_LINES * self.MAX_CHARS_PER_LINE)
        # メッセージをセット
        p = 0
        for i in range(len(message)):
            ch = message[i]
            if ch == "/":  # /は改行文字
                self.text[p] = "/"
                p += self.MAX_CHARS_PER_LINE
                p = (p // self.MAX_CHARS_PER_LINE) * self.MAX_CHARS_PER_LINE
            elif ch == "%":  # \fは改ページ文字
                self.text[p] = "%"
                p += self.MAX_CHARS_PER_PAGE
                p = (p // self.MAX_CHARS_PER_PAGE) * self.MAX_CHARS_PER_PAGE
            else:
                self.text[p] = ch
                p += 1
        self.text[p] = "$"  # 終端文字
        self.show()

    def update(self):
        """メッセージウィンドウを更新する
        メッセージが流れるように表示する"""
        if self.is_visible:
            if self.next_flag == False:
                self.cur_pos += 1  # 1文字流す
                # テキスト全体から見た現在位置
                p = self.cur_page * self.MAX_CHARS_PER_PAGE + self.cur_pos
                if self.text[p] == "/":  # 改行文字
                    self.cur_pos += self.MAX_CHARS_PER_LINE
                    self.cur_pos = (self.cur_pos // self.MAX_CHARS_PER_LINE
                                    ) * self.MAX_CHARS_PER_LINE
                elif self.text[p] == "%":  # 改ページ文字
                    self.cur_pos += self.MAX_CHARS_PER_PAGE
                    self.cur_pos = (self.cur_pos // self.MAX_CHARS_PER_PAGE
                                    ) * self.MAX_CHARS_PER_PAGE
                elif self.text[p] == "$":  # 終端文字
                    self.hide_flag = True
                # 1ページの文字数に達したら▼を表示
                if self.cur_pos % self.MAX_CHARS_PER_PAGE == 0:
                    self.next_flag = True
        self.frame += 1

    def draw(self, screen):
        """メッセージを描画する
        メッセージウィンドウが表示されていないときは何もしない"""
        Window.draw(self, screen)
        if self.is_visible == False: return
        # 現在表示しているページのcur_posまでの文字を描画
        for i in range(self.cur_pos):
            ch = self.text[self.cur_page * self.MAX_CHARS_PER_PAGE + i]
            if ch == "/" or ch == "%" or ch == "$": continue  # 制御文字は表示しない
            dx = self.text_rect[0] + MessageEngine.FONT_WIDTH * (
                i % self.MAX_CHARS_PER_LINE)
            dy = self.text_rect[1] + (self.LINE_HEIGHT +
                                      MessageEngine.FONT_HEIGHT) * (
                                          i // self.MAX_CHARS_PER_LINE)
            self.msg_engine.draw_character(screen, (dx, dy), ch)
        # 最後のページでない場合は▼を表示
        if (not self.hide_flag) and self.next_flag:
            if self.frame // self.animcycle % 2 == 0:
                dx = self.text_rect[0] + (
                    self.MAX_CHARS_PER_LINE // 2
                ) * MessageEngine.FONT_WIDTH - MessageEngine.FONT_WIDTH // 2
                dy = self.text_rect[1] + (self.LINE_HEIGHT +
                                          MessageEngine.FONT_HEIGHT) * 3
                screen.blit(self.cursor, (dx, dy))

    def next(self):
        """メッセージを先に進める"""
        # 現在のページが最後のページだったらウィンドウを閉じる
        if self.hide_flag:
            self.hide()
        # ▼が表示されてれば次のページへ
        if self.next_flag:
            self.cur_page += 1
            self.cur_pos = 0
            self.next_flag = False
Ejemplo n.º 5
0
class MessageWindow(Window):
    """メッセージウィンドウ"""
    MAX_CHARS_PER_LINE = 20  # 1行の最大文字数
    MAX_LINES_PER_PAGE = 3  # 1行の最大行数(4行目は▼用)
    MAX_CHARS_PER_PAGE = 20 * 3  # 1ページの最大文字数
    MAX_LINES = 30  # メッセージを格納できる最大行数
    LINE_HEIGHT = 8  # 行間の大きさ

    def __init__(self, rect):
        Window.__init__(self, rect)
        self.text_rect = self.inner_rect.inflate(-32, -32)  # テキストを表示する矩形
        self.text = []  # メッセージ
        self.cur_page = 0  # 現在表示しているページ
        self.max_page = 0  # 最終ページ
        self.msg_engine = MessageEngine()  # メッセージエンジン
        self.cursor = load_image(os.path.join("data", "cursor.png"))  # カーソル画像

    def set(self, message):
        """メッセージをセットしてウィンドウを画面に表示する"""
        self.cur_page = 0
        # 全角スペースで初期化
        self.text = [' '] * (self.MAX_LINES * self.MAX_CHARS_PER_LINE)
        # メッセージをセット
        p = 0
        for i in range(len(message)):
            ch = message[i]
            if ch == "/":  # /は改行文字
                self.text[p] = "/"
                p += self.MAX_CHARS_PER_LINE
                p = (p // self.MAX_CHARS_PER_LINE) * self.MAX_CHARS_PER_LINE
            elif ch == "%":  # \fは改ページ文字
                self.text[p] = "%"
                p += self.MAX_CHARS_PER_PAGE
                p = (p // self.MAX_CHARS_PER_PAGE) * self.MAX_CHARS_PER_PAGE
            else:
                self.text[p] = ch
                p += 1
        self.max_page = p // self.MAX_CHARS_PER_PAGE
        self.show()

    def draw(self, screen):
        """メッセージを描画する
        メッセージウィンドウが表示されていないときは何もしない"""
        Window.draw(self, screen)
        if self.is_visible == False: return
        # 現在のページ(curPage)1ページ分の内容を描画
        for i in range(self.MAX_CHARS_PER_PAGE):
            ch = self.text[self.cur_page * self.MAX_CHARS_PER_PAGE + i]
            if ch == "/" or ch == "%": continue  # 制御文字は表示しない
            dx = self.text_rect[0] + MessageEngine.FONT_WIDTH * (
                i % self.MAX_CHARS_PER_LINE)
            dy = self.text_rect[1] + (self.LINE_HEIGHT +
                                      MessageEngine.FONT_HEIGHT) * (
                                          i // self.MAX_CHARS_PER_LINE)
            self.msg_engine.draw_character(screen, (dx, dy), ch)
        # 最後のページでない場合は▼を表示
        if self.cur_page < self.max_page:
            dx = self.text_rect[0] + (
                self.MAX_CHARS_PER_LINE //
                2) * MessageEngine.FONT_WIDTH - MessageEngine.FONT_WIDTH / 2
            dy = self.text_rect[1] + (self.LINE_HEIGHT +
                                      MessageEngine.FONT_HEIGHT) * 3
            screen.blit(self.cursor, (dx, dy))

    def next(self):
        """メッセージを先に進める"""
        # 現在のページが最後のページだったらウィンドウを閉じる
        if self.cur_page == self.max_page:
            self.hide()
        self.cur_page += 1