def setup(self): MenuView.setup(self) width, height = self.controller.window.width, self.controller.window.height self.layout = VerticalLayout(0, 0) self.text_input = TextWidget(self.controller.window, G.IP_ADDRESS, 0, 0, width=160, height=20, font_name='Arial', batch=self.batch) self.controller.window.push_handlers(self.text_input) self.text_input.focus() def text_input_callback(symbol, modifier): G.IP_ADDRESS = self.text_input.text self.text_input.push_handlers(key_released=text_input_callback) button = self.Button(caption=G._("Connect to server"), on_click=self.controller.start_multiplayer_game) self.layout.add(button) self.buttons.append(button) button= self.Button(caption=G._("Launch server"), on_click=self.launch_server) self.layout.add(button) self.buttons.append(button) button= self.Button(caption=G._("Done"), on_click=self.controller.main_menu) self.layout.add(button) self.buttons.append(button) self.label = Label('Play Multiplayer', font_name='ChunkFive Roman', font_size=25, x=width/2, y=self.frame.y + self.frame.height, anchor_x='center', anchor_y='top', color=(255, 255, 255, 255), batch=self.batch, group=self.labels_group) self.on_resize(width, height)
def setup(self): MenuView.setup(self) width, height = self.controller.window.width, self.controller.window.height self.layout = VerticalLayout(0, 0) textures_enabled = len(G.texture_pack_list.available_texture_packs) > 1 self.text_input = TextWidget(self.controller.window, G.USERNAME, 0, 0, width=160, height=20, font_name='Arial', batch=self.batch) self.controller.window.push_handlers(self.text_input) self.text_input.focus() self.text_input.caret.mark = len(self.text_input.document.text) # Don't select the whole text def text_input_callback(symbol, modifier): G.USERNAME = self.text_input.text self.text_input.push_handlers(key_released=text_input_callback) hl = HorizontalLayout(0, 0) sb = self.Scrollbar(x=0, y=0, width=300, height=40, sb_width=20, sb_height=40, caption="Music") hl.add(sb) def change_sound_volume(pos): print(G.EFFECT_VOLUME) G.EFFECT_VOLUME = float(float(pos) / 100) sb = self.Scrollbar(x=0, y=0, width=300, height=40, sb_width=20, sb_height=40, caption="Sound", pos=int(G.EFFECT_VOLUME * 100), on_pos_change=change_sound_volume) hl.add(sb) self.layout.add(hl) hl = HorizontalLayout(0, 0) button = self.Button(width=300, caption=G._("Controls..."), on_click=self.controller.controls) hl.add(button) self.buttons.append(button) button = self.Button(width=300, caption=G._("Textures"), on_click=self.controller.textures, enabled=textures_enabled) hl.add(button) self.buttons.append(button) self.layout.add(hl) button = self.Button(width=610, caption=G._("Done"), on_click=self.controller.main_menu) self.layout.add(button) self.buttons.append(button) self.label = Label('Options', font_name='ChunkFive Roman', font_size=25, x=width/2, y=self.frame.y + self.frame.height, anchor_x='center', anchor_y='top', color=(255, 255, 255, 255), batch=self.batch, group=self.labels_group) self.on_resize(width, height)
def setup(self): if G.SINGLEPLAYER: try: print 'Starting internal server...' # TODO: create world menu G.SAVE_FILENAME = "world" start_server(internal=True) sock = socket.socket() sock.connect(("localhost", 1486)) except socket.error as e: print "Socket Error:", e #Otherwise back to the main menu we go return False except Exception as e: print 'Unable to start internal server' import traceback traceback.print_exc() return False else: try: #Make sure the address they want to connect to works ipport = G.IP_ADDRESS.split(":") if len(ipport) == 1: ipport.append(1486) sock = socket.socket() sock.connect((tuple(ipport))) except socket.error as e: print "Socket Error:", e #Otherwise back to the main menu we go return False self.init_gl() sky_rotation = -20.0 # -20.0 # TERRAIN_CHOICE = self.biome_generator.get_biome_type(sector[0], sector[2]) default_skybox = 'skydome.jpg' #if TERRAIN_CHOICE == G.NETHER: # default_skybox = 'skydome_nether.jpg' #else: # default_skybox = 'skybox.jpg' print 'loading ' + default_skybox self.skydome = Skydome( 'resources/' + default_skybox, #'resources/skydome.jpg', 0.7, 100.0, sky_rotation, ) self.player_ids = { } # Dict of all players this session, indexes are their ID's [0: first Player on server,] self.focus_block = Block(width=1.05, height=1.05) self.earth = vec(0.8, 0.8, 0.8, 1.0) self.white = vec(1.0, 1.0, 1.0, 1.0) self.ambient = vec(1.0, 1.0, 1.0, 1.0) self.polished = GLfloat(100.0) self.crack_batch = pyglet.graphics.Batch() #if G.DISABLE_SAVE and world_exists(G.game_dir, G.SAVE_FILENAME): # open_world(self, G.game_dir, G.SAVE_FILENAME) self.world = World() self.packetreceiver = PacketReceiver(self.world, self, sock) self.world.packetreceiver = self.packetreceiver G.CLIENT = self.packetreceiver self.packetreceiver.start() #Get our position from the server self.packetreceiver.request_spawnpos() #Since we don't know it yet, lets disable self.update, or we'll load the wrong chunks and fall self.update_disabled = self.update self.update = lambda dt: None #We'll re-enable it when the server tells us where we should be self.player = Player(game_mode=G.GAME_MODE) print('Game mode: ' + self.player.game_mode) self.item_list = ItemSelector(self, self.player, self.world) self.inventory_list = InventorySelector(self, self.player, self.world) self.item_list.on_resize(self.window.width, self.window.height) self.inventory_list.on_resize(self.window.width, self.window.height) self.text_input = TextWidget(self.window, '', 0, 0, self.window.width, visible=False, font_name=G.CHAT_FONT) self.text_input.push_handlers(on_toggled=self.on_text_input_toggled, key_released=self.text_input_callback) self.chat_box = TextWidget(self.window, '', 0, self.text_input.y + self.text_input.height + 50, self.window.width / 2, height=min(300, self.window.height / 3), visible=False, multi_line=True, readonly=True, font_name=G.CHAT_FONT, text_color=(255, 255, 255, 255), background_color=(0, 0, 0, 100), enable_escape=True) self.camera = Camera3D(target=self.player) if G.HUD_ENABLED: self.label = pyglet.text.Label('', font_name='Arial', font_size=8, x=10, y=self.window.height - 10, anchor_x='left', anchor_y='top', color=(255, 255, 255, 255)) #if G.DEBUG_TEXT_ENABLED: # self.debug_text = TextWidget(self.window, '', # 0, self.window.height - 300, # 500, 300, # visible=True, multi_line=True, readonly=True, # font_name='Arial', font_size=10, # text_color=(255, 255, 255, 255), # background_color=(0, 0, 0, 0)) pyglet.clock.schedule_interval_soft(self.world.process_queue, 1.0 / G.MAX_FPS) pyglet.clock.schedule_interval_soft(self.world.hide_sectors, 10.0, self.player) return True