def new_response(response): if len(response)==0: response = ["Error, no response received."] for x in response: if " you won" in x or "You die" in x: root.remove_widget(textBox) text.focus = False label = Label(text=x, halign='left', size_hint=(1,None), font_name = self.god_font) label.bind(size=label.setter('text_size')) resize_one(label) grid.add_widget(label) if "Game loaded with username " in response[-1]: grid.clear_widgets() grid.add_widget(label) game = Game() new_response(game.start()) load_command(userInput()) elif Save.counter>0: load_command(userInput())
def build(self): #Window.softinput_mode = 'resize' #apparently doesn't work on iOS right now? keyboarder = BoxLayout(size_hint=(1,None), height = 0) root = BoxLayout(orientation='vertical', padding=20, spacing=10) scroll = ScrollView(effect_cls='ScrollEffect') grid = GridLayout(cols=1,size_hint_y=None) grid.bind(minimum_height=grid.setter('height')) def resize_all(window,width,height): newHeight = width/self.window_width_to_label_height newFontSize = width/self.window_width_to_label_height/self.label_height_to_font_size for l in grid.children: l.height = newHeight l.font_size = newFontSize def resize_one(l): l.height = Window.width/self.window_width_to_label_height l.font_size = Window.width/self.window_width_to_label_height/self.label_height_to_font_size Window.bind(on_resize=resize_all) game = Game() scroll.add_widget(grid) root.add_widget(scroll) textBox = BoxLayout(orientation='horizontal', spacing=20, size_hint=(1,None), height=70) textBox.add_widget(Label(text='>', size_hint=(None,None), color = self.user_input_color, height=70, width=20, font_name = self.user_font)) text = MyTextInput(text='', multiline=False, size_hint=(1,None), height=60, background_color=(0,0,0,1), foreground_color=self.user_input_color, cursor_color = self.user_input_color, font_name = self.user_font) def new_response(response): if len(response)==0: response = ["Error, no response received."] for x in response: if " you won" in x or "You die" in x: root.remove_widget(textBox) text.focus = False label = Label(text=x, halign='left', size_hint=(1,None), font_name = self.god_font) label.bind(size=label.setter('text_size')) resize_one(label) grid.add_widget(label) if "Game loaded with username " in response[-1]: grid.clear_widgets() grid.add_widget(label) game = Game() new_response(game.start()) load_command(userInput()) elif Save.counter>0: load_command(userInput()) new_response(game.start()) def keyboardHere(a,b,c,d,e): pass#new_response(["KEYBOARD HEIGHT: "+str(Window.keyboard_height)]) Window.bind(on_keyboard=keyboardHere) def on_command(instance): text.commandIndex = 0 command = text.text if " " in command: if command[0:command.index(" ")]!="save" and command[0:command.index(" ")]!="load" and Save.saveInput: Save.inputs.append(command) else: if command!="save" and command!="load" and Save.saveInput: Save.inputs.append(command) if Save.saveInput: for line in wrap(command, int(Save.maxWrap*self.user_maxWrap)).splitlines(): label = Label(text=line, halign='left', size_hint=(1,None), height=45, color=self.user_input_color, font_name = self.user_font) label.bind(size=label.setter('text_size')) resize_one(label) grid.add_widget(label) text.text = '' if Save.currentFunction[0]!=None: f = Save.currentFunction[0] new_response(prin(f(command))) else: new_response(parse(game.pc, command)) scroll.scroll_y = 0 Clock.schedule_once(focus) def load_command(command): for line in wrap(command, int(Save.maxWrap*self.user_maxWrap)).splitlines(): label = Label(text=line, halign='left', size_hint=(1,None), height=45, color=self.user_input_color, font_name = self.user_font) label.bind(size=label.setter('text_size')) resize_one(label) grid.add_widget(label) text.text = '' if Save.currentFunction[0]!=None: f = Save.currentFunction[0] new_response(prin(f(command))) else: new_response(parse(game.pc, command)) scroll.scroll_y = 0 def focus(self,*args): text.focus = True text.bind(on_text_validate=on_command) textBox.add_widget(text) root.add_widget(textBox) root.add_widget(keyboarder) return root