def draw_boardareaarea(self): uc.werase(self.win_board) uc.box(self.win_boardarea, 0, 0) uc.wmove(self.win_boardarea, 1, 2) if self.on_menu: s = self.player.board.__str__() else: s = self.player.board.show_new_ship(self.new_ship_x, self.new_ship_y, self.menu[self.menu_hi].id, self.menu[self.menu_hi].length, self.new_ship_hor) for chr in s: if chr == '~': uc.wattron(self.win_board, uc.COLOR_PAIR(11)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(11)) elif chr == 'O': uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) elif chr == '#': uc.wattron(self.win_board, uc.COLOR_PAIR(13)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(13)) else: uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) uc.wrefresh(self.win_boardarea) uc.update_panels()
def draw(self): if self.game_interface.game_initialized: self.field_data_pull = self.game_interface.game.game_map x = 1 y = 1 for line in self.field_data_pull: for cell in line: if cell == ':': mvwaddstr(self.game_field_window, y, x, cell, GREEN_YELLOW) elif cell == '~': mvwaddstr(self.game_field_window, y, x, cell, BLUE_WHITE) elif cell == '#': mvwaddstr(self.game_field_window, y, x, cell, BLACK_RED) elif cell == 'C': mvwaddstr(self.game_field_window, y, x, cell, BLUE_WHITE) else: mvwaddstr(self.game_field_window, y, x, cell, WHITE_BLACK) x += 1 x = 1 y += 1 wrefresh(self.game_field_window) if self.selector: self.selector.refresh_for_draw() update_panels() doupdate()
def _activate(self): box(self.button_window) mvwaddstr(self.button_window, ((self.height + 1) // 2) - 1, (self.width - len(self.name)) // 2 + 1, self.name) wbkgd(self.button_window, BLUE_WHITE) wrefresh(self.button_window) update_panels() doupdate()
def refresh(self): if self.enabled and not self.blocked: self.draw() box(self.game_field_window) wrefresh(self.game_field_window) update_panels() doupdate()
def show(self, conf): self.started = time.time() self.render() unicurses.wrefresh(self.scr.win) result = self.scr.artifactory.migrate(self, conf) self.render(result) return result
def draw_board(self): uc.wclear(self.win_board1) uc.wclear(self.win_baord2) uc.box(self.win_boardarea, 0, 0) uc.wmove(self.win_boardarea, 1, 2) s1 = self.player.board.__str__() s2 = self.player_enemy.board.__str__() for chr in s1: if chr == '~': uc.wattron(self.win_board, uc.COLOR_PAIR(11)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(11)) elif chr == 'O': uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) elif chr == '#': uc.wattron(self.win_board, uc.COLOR_PAIR(13)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(13)) else: uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) uc.wrefresh(self.win_boardarea) uc.update_panels()
def render(self, line=None): # Overwrites existing if self.max_line_len > self.width: raise SizeError("Content is longer than box.") # New window self.win = uni.newwin(self.height, self.width, self.ypos, self.xpos) # Draw outline if self.outline: uni.box(self.win, 0, 0) # Draw label self.draw_label() # Make panel self.panel = uni.new_panel(self.win) # Track the line number currently written self.current_line = 0 # Print content for line in self.lines: # Print line text on line number ix = list(self.lines).index(line) line_no = ix + self.ypad # Print lines according to the text's index in the list uni.mvwaddstr(self.win, line_no, self.xpad, " " * (self.width - 2)) uni.mvwaddstr(self.win, line_no, self.xpad, line) self.current_line += 1 uni.wrefresh(self.win)
def refresh(self): if self.enabled: for button in self.buttons: button.refresh() box(self.game_menu_interface_window) wrefresh(self.game_menu_interface_window) update_panels() doupdate()
def refresh_for_draw(self): self.building_zone_free = self.parent.game_interface.game.can_be_added(self.x - 1, self.y - 1) box(self.selector_zone, 0, 0) if self.building_zone_free: wbkgd(self.selector_zone, BLACK_GREEN) else: wbkgd(self.selector_zone, BLACK_RED) wrefresh(self.selector_zone)
def draw_title(self): offset_x = 2 offset_y = 1 uc.box(self.win_title, 0, 0) uc.wmove(self.win_title, offset_y, offset_x) uc.waddstr(self.win_title, self.title) uc.wrefresh(self.win_title)
def showCall(self, sel, act): sel['wait'] = True self.render() unicurses.wrefresh(self.scr.win) cont = act(sel) sel['wait'] = False self.render() unicurses.flushinp() return cont != False
def refresh_for_draw(self): self.building_zone_free = self.parent.game_interface.game.can_be_added( self.x - 1, self.y - 1) box(self.selector_zone, 0, 0) if self.building_zone_free: wbkgd(self.selector_zone, BLACK_GREEN) else: wbkgd(self.selector_zone, BLACK_RED) wrefresh(self.selector_zone)
def refresh(self): """Refresh the window.""" self.update() if self.enabled: curses.wmove(self.win, 0, 0) self.draw() # Explicitly check wether clearing to bottom is necessary # Otherwise the most bottom-right character will be blanked if curses.getyx(self.win) != (self.height - 1, self.width - 1): curses.wclrtobot(self.win) curses.wrefresh(self.win)
def building(self, key): if not self.selector: self.selector = GameFieldSelector(self, self.game_field_window) self.selector.key_event(key) if key == 10: if self.selector.building_zone_free: self.game_interface.game.add_tower(self.selector.x - 1, self.selector.y - 1) self.exit_building() elif key == 27: self.exit_building() wrefresh(self.game_field_window) update_panels() doupdate()
def print_menu(menu_win, highlight): x = 2 y = 2 uni.box(menu_win, 0, 0) for i in range(0, n_choices): if (highlight == i + 1): uni.wattron(menu_win, uni.A_REVERSE) uni.mvwaddstr(menu_win, y, x, choices[i]) uni.wattroff(menu_win, uni.A_REVERSE) else: uni.mvwaddstr(menu_win, y, x, choices[i]) y += 1 uni.wrefresh(menu_win)
def refresh(self): if self.enabled: x = 2 y = 2 box(self.game_stat_window, 0, 0) mvwaddstr(self.game_stat_window, y, x, " " * 127) if self.game_interface.game_initialized: for param in self.game_interface.game.player.strings_info: wattron(self.game_stat_window, A_REVERSE) mvwaddstr(self.game_stat_window, y, x, param, RED_WHITE) wattroff(self.game_stat_window, A_REVERSE) x += 5 + len(param) wrefresh(self.game_stat_window) update_panels() doupdate()
def show(self, conf): self.started = time.time() if self.scr.interactive: self.render() unicurses.wrefresh(self.scr.win) result = self.scr.artifactory.migrate(self, conf) if result == True: for step in self.steps: if step[3] > 0: result = 'key', "Migration successful, but errors occurred." break else: result = 'val', "Migration successful!" else: result = 'err', "Migration error: " + result if self.scr.interactive: self.render(result) return result
def draw_board(self): uc.wclear(self.win_board) offset_x = 2 offset_y = 1 uc.box(self.win_boardarea, 0, 0) uc.wmove(self.win_boardarea, offset_y, offset_x) if self.on_menu: s = self.player.board.__str__() else: s = self.player.board.show_new_ship(self.new_ship_x, self.new_ship_y, self.menu[self.menu_hi].id, self.menu[self.menu_hi].length, self.new_ship_hor) uc.init_pair(11, uc.COLOR_BLUE, uc.COLOR_BLACK) uc.init_pair(12, uc.COLOR_WHITE, uc.COLOR_BLACK) uc.init_pair(13, uc.COLOR_RED, uc.COLOR_BLACK) for chr in s: if chr == '~': uc.wattron(self.win_board, uc.COLOR_PAIR(11)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(11)) elif chr == 'O': uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) elif chr == '#': uc.wattron(self.win_board, uc.COLOR_PAIR(13)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(13)) else: uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) uc.wbkgd(self.win_statusbar, uc.COLOR_PAIR(11)) uc.wrefresh(self.win_boardarea) uc.update_panels()
def draw_statusbar(self): uc.wclear(self.win_statusbar) s = '[q] quit ' if self.on_menu: s += '[\u2191\u2193] move ' s += '[\u21B5] select ' else: s += '[\u2190\u2191\u2192\u2193] move ' s += '[r] rotate ' s += '[s] suggest ' s += '[\u21B5] commit ' s += f'{self.num_ships_set}/{len(self.player.ship_list)} set' uc.waddstr(self.win_statusbar, s) uc.init_pair(4, uc.COLOR_WHITE, uc.COLOR_BLUE) uc.wbkgd(self.win_statusbar, uc.COLOR_PAIR(4)) uc.wrefresh(self.win_statusbar)
def _refresh(self): x = 2 y = 2 box(self.menu_window, 0, 0) for i in range(0, len(self.topics)): if self.topics_pointer == i: wattron(self.menu_window, A_REVERSE) mvwaddstr(self.menu_window, y, x, self.topics[i]) wattroff(self.menu_window, A_REVERSE) elif i in self.locked_topics: wattron(self.menu_window, A_UNDERLINE) mvwaddstr(self.menu_window, y, x, self.topics[i]) wattroff(self.menu_window, A_UNDERLINE) else: mvwaddstr(self.menu_window, y, x, self.topics[i]) y += 1 wrefresh(self.menu_window) update_panels() doupdate()
def get_messages(): old_messages = '' while True: if kill_thread: break time.sleep(0.05) while True: try: sock = socket.socket() sock.connect((HOST, PORT)) sock.sendall(bytes(channel + chr(0) + chr(2), "utf-8")) recvd = sock.recv(1024).decode().split('||') count = recvd[0] users = recvd[1].split('|') ctypes.windll.kernel32.SetConsoleTitleA(bytes(channel + ": " + str(count) + " user(s) online", "utf-8")) u.wclear(people_win) u.box(people_win) i = 1 u.mvwaddstr(people_win, i, 1, ' Users in #%s:' % channel) for user in users: i += 1 u.mvwaddstr(people_win, i, 1, ' - ' + user) u.wrefresh(people_win) sock = socket.socket() sock.connect((HOST, PORT)) break except (ConnectionRefusedError, ConnectionResetError): u.mvwaddstr(chat_win, 1, 1, "Can't connect.") time.sleep(1) sock.sendall(bytes(channel + chr(0) + chr(1), "utf-8")) incoming_messages = str(sock.recv(4096), "utf-8") if not incoming_messages == old_messages: i = 0 u.wclear(chat_win) draw_boxes() for message in get_latest(incoming_messages.split('\n')): i += 1 u.mvwaddstr(chat_win, i, 1, message[:78]) u.wrefresh(chat_win) old_messages = incoming_messages time.sleep(0.1)
def close(self): prompt_start_x = self.max_x // 2 - 19 prompt_start_y = self.max_y // 3 if prompt_start_x < 1: prompt_start_x = 1 if prompt_start_y < 1: prompt_start_y = 1 win_prompt = uc.newwin(3, 38, prompt_start_y, prompt_start_x) uc.box(win_prompt, 0, 0) uc.mvwaddstr(win_prompt, 1, 1, 'Do you want to close the game? (y|n)') uc.wbkgd(win_prompt, uc.COLOR_PAIR(1)) uc.wrefresh(win_prompt) answer = uc.wgetch(stdscr) if answer == ord('y') or answer == ord('Y'): uc.endwin() exit() else: uc.delwin(win_prompt)
def init_wins(self): '''Creates win and panel objects. ''' uc.wclear(stdscr) self.max_y, self.max_x = uc.getmaxyx(stdscr) self.win_title = uc.newwin(3, self.max_x, 0, 0) #(h, w, starty, startx) self.win_boardarea = uc.newwin(self.max_y-4, self.max_x, 3, 0) self.win_statusbar = uc.newwin(1, self.max_x, self.max_y-1, 0) x, y = self.player.board.str_size() self.win_board1 = uc.newwin(y, x+2, 0, 0) self.win_board2 = uc.newwin(y, x+2, 0, 0) self.pan_board1 = uc.new_panel(self.win_board1) self.pan_board2 = uc.new_panel(self.win_board2) uc.move_panel(self.pan_board1, 0, 0) uc.move_panel(self.pan_board2, 0, 0) uc.wrefresh(stdscr) self.draw_all()
def draw_shipmenu(self): uc.wclear(self.win_shipmenu) offset_x = 2 offset_y = 1 uc.box(self.win_shipmenu, 0, 0) uc.wmove(self.win_shipmenu, offset_y, offset_x) uc.waddstr(self.win_shipmenu, 'ship menu:') offset_y += 2 for ele in self.menu: if (self.on_menu and self.menu_hi == self.menu.index(ele)): uc.wattron(self.win_shipmenu, uc.A_REVERSE) uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele) uc.wattroff(self.win_shipmenu, uc.A_REVERSE) offset_y += 2 else: uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele) offset_y += 2 uc.wrefresh(self.win_shipmenu)
def init_wins(self): uc.wclear(stdscr) self.max_y, self.max_x = uc.getmaxyx(stdscr) border_x = ceil(self.max_x * 2 / 3) c = int(self.max_x % 2 == 1) self.win_title = uc.newwin(3, self.max_x, 0, 0) #(h, w, starty, startx) self.win_boardarea = uc.newwin(self.max_y - 4, border_x, 3, 0) self.win_shipmenu = uc.newwin(self.max_y - 4, self.max_x - border_x, 3, border_x) self.win_statusbar = uc.newwin(1, self.max_x, self.max_y - 1, 0) x, y = self.player.board.str_size() self.win_board = uc.newwin(y, x + 2, 0, 0) self.pan_board = uc.new_panel(self.win_board) uc.move_panel(self.pan_board, 3 + (self.max_y - 3) // 2 - y // 2, (border_x - 3) // 2 - x // 2) uc.wrefresh(stdscr) self.draw()
def background_change(self): if self.under_choice(): wbkgd(self.button_window, WHITE_BLACK) wrefresh(self.button_window) elif self.locked(): wbkgd(self.button_window, CYAN_WHITE) wrefresh(self.button_window) else: wbkgd(self.button_window, BLUE_WHITE) wrefresh(self.button_window)
def refresh(self): self.render() unicurses.wrefresh(self.scr.win)
def draw_title(self): uc.box(self.win_title, 0, 0) uc.wmove(self.win_title, 1, 2) uc.waddstr(self.win_title, self.str_title) uc.wrefresh(self.win_title)
def refresh(self): if not self.scr.interactive: return self.render() unicurses.wrefresh(self.scr.win)
def create_win(self): local_win = derwin(self.parent_window, self.height, self.width, self.y, self.x) box(local_win, 0, 0) wrefresh(local_win) self.selector_zone = local_win
def destroy_win(self): wborder(self.selector_zone, CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' '), CCHAR(' ')) wrefresh(self.selector_zone) delwin(self.selector_zone)
def refresh(self): self.background_change() box(self.button_window) wrefresh(self.button_window)