def _generate_ui(self): self.noise_bar = ui.Bar(Vector2(config.SCREEN_SIZE[0] * 0.1, config.ROOM_SIZE.y + config.UI_SIZE.y * 0.1), \ Vector2(config.UI_SIZE.x * 0.8, config.UI_SIZE.y * 0.2), config.NOISE_COLOR) text_x = config.SCREEN_SIZE[0] * 0.05 noise_text = ui.Text( "Bruit :", Vector2(text_x, config.ROOM_SIZE.y + config.UI_SIZE.y * 0.2), 30) self.life_text = ui.Text( "", Vector2(text_x, config.ROOM_SIZE.y + config.UI_SIZE.y * 0.5), 30) self.uis = [self.noise_bar, self.life_text, noise_text]
def display_quit(self): self.remove_all() self.append( ui.Box(self, (10, 39), (80, 22), constants.button_box_color)) self.append( ui.Text(self, i18n.get_text(self.language, 1105), (10, 40), (80, 10), self.fonts, constants.text_color, 1)) self.quit_yes = ui.TextBox(self, i18n.get_text(self.language, 100), (10, 50), (40, 10), self.fonts, constants.text_color, 11, constants.stop_icon) self.quit_no = ui.TextBox(self, i18n.get_text(self.language, 101), (50, 50), (40, 10), self.fonts, constants.text_color, 11, constants.go_next_icon) self.append(self.quit_yes) self.append(self.quit_no) self.page_type = "DIALOG_BOX_QUIT" self.draw() return [self.screen.get_rect()]
def __init__(self, state: State, api_server): self.state = state self.state.push_handlers(self) self.campaign = state.campaign self.campaign.push_handlers(self) self.api_server = api_server self.api_server.push_handlers(self) self.window = pyglet.window.Window(resizable=True) self.window.push_handlers(self) self.focus_manager = ui.FocusManager(self.window) self.map = Map(state) char_panel = ui.VStackLayout(ui.HStackLayout( ui.Text(get_text=state.get_current_char_name, font_size=24, padding=8, valign='bottom'), ui.Image(get_image=state.get_current_char_image, min_width=70, flex_width=False), ).set_min_height(70).set_flex_height(False), ui.Spacer(min_height=15, flex_height=False), healthbar.HealthBar( self.focus_manager, get_char=state.get_current_char), flex_height=False, get_hidden=state.no_selected_char) self.layout = ui.RootLayout( self.window, ui.HStackLayout( ui.VStackLayout( char_panel, chat.ChatText(self.campaign, multiline=True), chat.ChatInput(self.state, self.api_server, self.focus_manager, min_height=100, flex_height=False)).set_background( colors.GREY_900).set_min_width( 300).set_flex_width(False), self.map)) print(self.layout) # Make sure that on_draw is called regularly. pyglet.clock.schedule_interval(lambda _: None, 1 / 120)
def cmd_line_on_enter(value): command = value.strip().split(' ') head = command[0] tail = ' '.join(command[1:]) if value in ['q', 'quit', 'exit']: client.stop() ui.window.exit() elif head in ['cw', 'chat', 'chatwith']: client.chat_with(tail) elif value in ['users']: ui.msg_list.append_child( ui.Text(str(client.get_contacts()['users'][0]))) ui.toggle_mode(ui.NORMAL_MODE) return 0
def display_restart(self): if (self.restart_text == None): self.restart_text = ui.Text(self, i18n.get_text(self.language, 210), constant_restart_text_pos, constant_restart_text_size, self.fonts, constant_hud_color, 1) self.append(self.restart_text) return self.restart_text.draw() else: return []
def update(self) : ui.Page.update(self) # showing the pictures for differences (pos_original, size_original) = self.game.original_box self.original_image = ui.Image(self, pos_original, size_original, self.game.original_image_file) self.append(self.original_image) (pos_modified, size_modified) = self.game.modified_box self.modified_image = ui.Image(self, pos_modified, size_modified, self.game.modified_image_file) if ((self.game.original_width != None) and (self.game.original_height != None)) : self.modified_image.original_size = (self.game.original_width, self.game.original_height) # masking some differences for difference_to_mask in self.game.differences_to_mask : difference_to_mask.mask_difference(self.modified_image, self.original_image) self.append(self.modified_image) # components which have to be found for difference_to_find in self.game.differences_to_find : difference_to_find_component = difference_to_find.create_component_to_find(self) self.append(difference_to_find_component) self.differences_to_find_components.append(difference_to_find_component) # memorize number of differences to find and show display self.number_differences_to_find = len(self.differences_to_find_components) self.number_differences_found = 0 text_number_differences = '%(found)d / %(tofind)d' %{'found' : self.number_differences_found, 'tofind' : self.number_differences_to_find} self.text_number_differences = ui.Text(self, text_number_differences, (46, 46), (8, 8), self.fonts, constants.text_color, 1) self.append(self.text_number_differences) self.draw_back()
def select_level(self, levels): self.append(self.second_background_image) self.go_back_icon = ui.Image(self, constants.go_left_icon_pos, constants.go_left_icon_size, constants.go_left_icon) self.append(self.go_back_icon) self.append( ui.Rounded_Box(self, (10, 10), (80, 83), constants.button_box_color)) self.append( ui.Text(self, i18n.get_text(self.language, 1106), (10, 25), (80, 10), self.fonts, constants.text_color, 1)) step_x = 80.0 / len(levels) offset_x = 50.0 - (step_x * (len(levels) / 2.0)) index = 0 for level in levels: level_image = ui.Image(self, (offset_x, 51), (step_x, 23), level.get_difficulty_level_image()) level_image.set_associated_object(level) offset_x = offset_x + step_x self.append(level_image) index = index + 1 self.page_type = "SELECT_LEVEL" self.draw() return [self.screen.get_rect()]
def __init__(self, focus_manager, get_char, padding=8, **kwargs): self._editing = False self.hp_input = ui.TextInput(focus_manager, min_width=40, font_size=20, flex_width=0, form_background=colors.GREY_900, get_hidden=self.is_not_editing) self.maxhp_input = ui.TextInput(focus_manager, min_width=40, font_size=20, flex_width=0, form_background=colors.GREY_900, get_hidden=self.is_not_editing) self.health_text = HealthText(get_char, is_editing=self.is_editing) self.text_hstack = ui.HStackLayout(ui.Spacer(), self.hp_input, self.health_text, self.maxhp_input, ui.Spacer()) super().__init__(ui.Text(text='HIT POINTS', font_size=8, kerning=2, min_height=14, align='center', color=(255, 255, 255, 255), padding=0, multiline=True, flex_height=False), ui.LayersLayout( HealthBarImpl(get_char, padding=padding, min_height=30, flex_height=False), self.text_hstack), min_height=50, flex_height=False, **kwargs)
def read(self, filename): """Read area data from a data file into an Area object""" # Open the area file fin = open(filename, 'r') # Read each object from the file for line in fin.readlines(): line = line.split(' ') # Get the name, coordinates, and properties of the object name = line[0] x = float(line[1]) y = float(line[2]) properties = ''.join(line[3:]).strip('\n') # Create a blank object obj = None # Audio/visual stuff if name == "Background": obj = Background(img=pyglet.image.load(properties), x=x, y=y, batch=self.batch, group=self.background) if name == "MusicPlayer": self.music = music.MusicPlayer(name=properties) continue # Heroes if name == "Player": obj = heroes.CaptainZero(x=x, y=y, batch=self.batch, group=self.foreground) # Objects if name == "Ground": properties = str2list(properties) n_horiz = int(properties[0]) n_vert = int(properties[1]) print(n_horiz, n_vert) for i in range(0, n_vert): for j in range(0, n_horiz): if obj != None: self.objects.append(obj) obj = tiles.Ground(x=x + (32 * j), y=y + (32 * i), batch=self.batch, group=self.foreground) # Villains # Enemies if name == "InfinityMook": obj = enemies.InfinityMook(x=x, y=y, batch=self.batch, group=self.foreground) # NPCs # Items # UI if name == "Text": properties = str2list(properties) obj = ui.Text(text=properties[0], size=int(properties[1]), color=properties[2], x=x, y=y, batch=self.batch, group=self.foreground) if name == "Button": properties = str2list(properties) click_mod_func = properties[1].split('.') module = __import__(click_mod_func[0]) on_click = eval("module." + click_mod_func[1]) obj = ui.Button(img=pyglet.image.load(properties[0]), x=x, y=y, on_click=on_click, batch=self.batch, group=self.foreground) self.objects.append(obj)
pResume() def pExit(): ui.Screen.current = screen # Set up UI encoder = rotaryio.IncrementalEncoder(board.A5, board.A4) button = digitalio.DigitalInOut(board.A3) ui.Screen.setEncoder(encoder, button) ui.Screen.setDisplay(d) screen = ui.Screen(True) button = ui.Button(screen, 38, 32, 38, 16, "Pong", func) framerate = ui.Text(screen, 0, 8, int(1 / loopTime), max_glyphs=3) num1 = ui.SingleDigitNumberSelector(screen, 116 - 24, 32) num2 = ui.SingleDigitNumberSelector(screen, 116, 32) num3 = ui.SingleDigitNumberSelector(screen, 140, 32) num4 = ui.SingleDigitNumberSelector(screen, 140 + 24, 32) pong = ui.Screen() # back = ui.Button(pong, 128, 32, 38, 16, 11, "Back", func2) p = game.Pong(d, encoder) pPress = False pmenu = ui.Screen() resume = ui.Button(pmenu, 48, 32, 68, 16, "Resume", pResume) restart = ui.Button(pmenu, 128, 32, 68, 16, "Restart", pRestart) exit = ui.Button(pmenu, 256 - 48, 32, 68, 16, "Exit", pExit)
def display_main_menu(self): self.remove_all() self.quit_icon = ui.Image(self, constants.stop_icon_pos, constants.stop_icon_size, constants.stop_icon) self.append(self.quit_icon) self.options_icon = ui.Image(self, constants.options_icon_pos, constants.options_icon_size, constants.options_icon_file) self.options_icon.set_associated_text(i18n.get_text( self.language, 105)) self.append(self.options_icon) self.listen_to_mouse_over(self.options_icon) self.tag_icons = [] for tag_def in self.tag_defs: tag = tag_def.tag games_with_this_tag = self.games_list.get_games_by_tag_and_language( tag, self.language) if (len(games_with_this_tag) > 0): image_filename = tag_def.image_filename text = tag_def.get_text(self.language) tag_icon = ui.Image(self, (0, 0), (11, 11), image_filename) tag_icon.set_associated_text(text) self.append(tag_icon) self.listen_to_mouse_over(tag_icon) tag_icon.set_associated_object(tag_def) self.tag_icons.append(tag_icon) self.igloo_image = ui.Image_Absolute( self, self.igloo_page.surface_to_zoom_rect.topleft, self.igloo_page.surface_to_zoom_rect.size, self.igloo_page.igloo_reduced_surface) self.igloo_image.set_associated_text(i18n.get_text( self.language, 1020)) self.append(self.igloo_image) self.listen_to_mouse_over(self.igloo_image) self.init_country_flags() (igloo_width, igloo_height) = constants.igloo_size self.language_image = ui.Image( self, (((self.igloo_page.flag_mast_pos_x * igloo_width) / 100.0), constants.main_flag_pos_y + ((self.igloo_page.flag_mast_pos_y * igloo_height) / 100.0)), constants.main_flag_size, i18n.countries_prefix + self.countries[self.country_index] + i18n.countries_suffix, 255, 100, "BOTTOMLEFT") self.language_image.outline(constants.flag_outline_color, constants.flag_outline_width) self.language_image.set_associated_text( i18n.get_text(self.language, self.language)) self.append(self.language_image) self.listen_to_mouse_over(self.language_image) # will play the sound of the 'next' language when the user clicks the language textbox next_lang_index = constants.supported_languages.index( self.language) + 1 if (next_lang_index >= len(constants.supported_languages)): next_lang_index = 0 self.language_image.associated_sounds = i18n.language_sound[ constants.supported_languages[next_lang_index]] circle_icons = Circle_icons(self, self.omnitux_logo_image.rect.center, self.omnitux_logo_image.rect.size, 2.1, len(self.tag_icons)) for tag_icon in self.tag_icons: tag_icon.set_center_abs(circle_icons.get_center()) self.append( ui.Text(self, i18n.get_text(self.language, 1102), (0, 94), (100, 3), self.fonts, constants.text_color, 1)) self.append( ui.Text(self, i18n.get_text(self.language, 1103), (0, 97), (100, 3), self.fonts, constants.text_color, 1)) self.page_type = "MAIN" return [self.screen.get_rect()]
def updateWindow(self): for x in range(len(self.window.getChildren())): self.window.getChildren()[0].destroy() for x in range(len(self._items)): _text = ui.Text(self.window, pos = (16, 16 + x * 12), text = self._items[x]._name)
def update(self): ui.Page.update(self) # finish the background self.omnitux_logo_image = ui.Image(self, (35, 25), (30, 30), constants.omnitux_logo) self.append_back(self.omnitux_logo_image) self.append_back( ui.Image(self, constant_topimage_pos, constant_topimage_size, constant_topimage_file, 255, 100, "FILL")) self.append_back( ui.Image(self, constant_bottomimage_pos, constant_bottomimage_size, constant_bottomimage_file, 255, 100, "FILL")) self.draw_back() self.go_back_icon = ui.Image(self, constants.go_left_icon_pos, constants.go_left_icon_size, constants.go_left_icon) self.append(self.go_back_icon) # screen resolution self.append( ui.Text(self, i18n.get_text(self.language, 200), constant_resolution_text_pos, constant_resolution_text_size, self.fonts, constant_hud_color, 2)) self.resolution_minus = ui.TextBox(self, "-", constant_resolution_minus_pos, constant_resolution_minus_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.resolution_minus) (self.globalvars.screen_width, self.globalvars.screen_height) = (self.screen.get_size()) self.resolution_value = ui.TextBox( self, str(self.globalvars.screen_width) + "x" + str(self.globalvars.screen_height), constant_resolution_value_pos, constant_resolution_value_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.resolution_value) self.resolution_plus = ui.TextBox(self, "+", constant_resolution_plus_pos, constant_resolution_plus_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.resolution_plus) self.available_resolutions = pygame.display.list_modes() self.current_resolution_index = self.available_resolutions.index( (self.globalvars.screen_width, self.globalvars.screen_height)) # music volume self.append( ui.Text(self, i18n.get_text(self.language, 201), constant_music_text_pos, constant_music_text_size, self.fonts, constant_hud_color, 2)) self.music_minus = ui.TextBox(self, "-", constant_music_minus_pos, constant_music_minus_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.music_minus) self.music_value = ui.TextBox( self, str(int(self.globalvars.music_volume * 100)) + "%", constant_music_value_pos, constant_music_value_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.music_value) self.music_plus = ui.TextBox(self, "+", constant_music_plus_pos, constant_music_plus_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.music_plus) # igloo yes/no self.append( ui.Text(self, i18n.get_text(self.language, 1020), constant_igloo_text_pos, constant_igloo_text_size, self.fonts, constant_hud_color, 2)) self.display_igloo = ui.TextBox( self, i18n.bool_to_text(self.language, self.globalvars.display_igloo), constant_display_igloo_pos, constant_display_igloo_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) self.append(self.display_igloo) # "no stress" vs "arcade" => commented until the feature will be developped #### self.append(ui.Text(self, i18n.get_text(self.language, 220), constant_arcade_mode_text_pos, constant_arcade_mode_text_size, self.fonts, constant_hud_color, 2)) self.arcade_mode = ui.TextBox( self, i18n.bool_to_text(self.language, self.globalvars.arcade_mode), constant_arcade_mode_pos, constant_arcade_mode_size, self.fonts, constant_negative_hud_color, 1, None, 255, constant_hud_color) #### self.append(self.arcade_mode) self.draw()
import ui, caesar, vernam, aes import rsa_encryption as rsa #Defining the menu page, menu = ui.Page(Caesar=ui.Button("Caesar Cipher", 50, 325, 250, 100), Vernam=ui.Button("Vernam Cipher", 724, 325, 250, 100), RSA=ui.Button("RSA", 50, 575, 250, 100), AES=ui.Button("AES", 724, 575, 250, 100), subtitle1=ui.Text("Simple Ciphers", (512, 250), ui.subtitle_font), subtitle2=ui.Text("Complex Ciphers", (512, 500), ui.subtitle_font), explanation=ui.Text("A program for teaching people about encryption", (512, 150), ui.header3)) #Defining the back to menu button that is used across all the pages. back_button = ui.Button("Menu", 50, 35, 150, 100, function_to_call=menu.run_page) #Defining the Caesar cipher page caesar_page = ui.Page(back_button, encrypt_text_box = ui.Textbox(360, 250, 300, 50, ui.screen, 20), encrypt_shift_box = ui.Textbox(360, 400, 300, 50, ui.screen, 15, True, 2, "1", True), plaintext_title = ui.Text("Plaintext:", (512, 200), ui.subtitle_font), shift_title=ui.Text("Shift:", (512, 350), ui.subtitle_font), clear_textbox_button = ui.Button("Clear Boxes", 730, 300, 175, 100), encrypt_button = ui.Button("Encrypt!", 330, 535, 150, 100, to_return=True), decrypt_button = ui.Button("Decrypt!", 550, 535, 150, 100, to_return=True), ciphertext = ui.OutputBox(50, 650, 924, 100), ciphertext_label = ui.Text("Output:", (125, 630), ui.header3)) #Defining all of the buttons functions and linked textboxes and output boxes for the Caesar cipher page menu.Caesar.function = caesar_page.run_page caesar_page.clear_textbox_button.function = caesar_page.clear_textboxes caesar_page.encrypt_button.dedi_output_box = caesar_page.ciphertext caesar_instance = caesar.Caesar caesar_page.encrypt_button.function = caesar_instance.caesar caesar_page.encrypt_button.linked_textboxes = [caesar_page.encrypt_text_box, caesar_page.encrypt_shift_box]
def display_scores(self): self.remove_all() (init_score_x, score_y) = constants.highscore_pos (score_width, score_height) = constants.highscore_size step = score_height / constants.max_highscores if (self.scores != None): if (len(self.scores.scores) > 0): name_ratio = 0.50 if (self.scores.scores[0].count_good == True): good_answers_ratio = 0.15 else: name_ratio = name_ratio + 0.15 good_answers_ratio = 0 if (self.scores.scores[0].count_wrong == True): wrong_answers_ratio = 0.15 else: name_ratio = name_ratio + 0.15 wrong_answers_ratio = 0 if (self.scores.scores[0].record_time == True): time_ratio = 0.20 else: name_ratio = name_ratio + 0.20 time_ratio = 0 index_color = 0 for score in self.scores.scores: color = constants.legend_text_colors[index_color] index_color = index_color + 1 if (index_color >= len(constants.legend_text_colors)): index_color = 0 score_x = init_score_x name = score.get_name() good_answers = str(score.get_good_answers_value()) wrong_answers = str(score.get_wrong_answers_value()) time = score.get_time_toString() self.append( ui.Text(self, name, (score_x, score_y), (score_width * name_ratio, step), self.fonts, color, 0)) score_x = score_x + score_width * name_ratio if (good_answers_ratio != 0): self.append( ui.Text(self, good_answers, (score_x, score_y), (score_width * good_answers_ratio, step), self.fonts, color, 1)) score_x = score_x + score_width * good_answers_ratio if (wrong_answers_ratio != 0): self.append( ui.Text(self, wrong_answers, (score_x, score_y), (score_width * wrong_answers_ratio, step), self.fonts, color, 1)) score_x = score_x + score_width * wrong_answers_ratio if (time_ratio != 0): self.append( ui.Text(self, time, (score_x, score_y), (score_width * time_ratio, step), self.fonts, color, 1)) score_y = score_y + step