def _check_fade_in(self) -> None: from ba.internal import get_device_value # If we have a touchscreen, we only fade in if we have a player with # an input device that is *not* the touchscreen. # (otherwise it is confusing to see the touchscreen buttons right # next to our display buttons) touchscreen: Optional[ba.InputDevice] = _ba.getinputdevice( 'TouchScreen', '#1', doraise=False) if touchscreen is not None: # We look at the session's players; not the activity's. # We want to get ones who are still in the process of # selecting a character, etc. input_devices = [ p.inputdevice for p in ba.getsession().sessionplayers ] input_devices = [ i for i in input_devices if i and i is not touchscreen ] fade_in = False if input_devices: # Only count this one if it has non-empty button names # (filters out wiimotes, the remote-app, etc). for device in input_devices: for name in ('buttonPunch', 'buttonJump', 'buttonBomb', 'buttonPickUp'): if self._meaningful_button_name( device, get_device_value(device, name)) != '': fade_in = True break if fade_in: break # No need to keep looking. else: # No touch-screen; fade in immediately. fade_in = True if fade_in: self._cancel_timer = None # Didn't need this. self._fade_in_timer = None # Done with this. self._fade_in()
def _rebuild_ui(self) -> None: from ba.internal import get_device_value for widget in self._root_widget.get_children(): widget.delete() # Fill our temp config with present values. self._settings: Dict[str, int] = {} for button in [ 'buttonJump', 'buttonPunch', 'buttonBomb', 'buttonPickUp', 'buttonStart', 'buttonStart2', 'buttonUp', 'buttonDown', 'buttonLeft', 'buttonRight' ]: self._settings[button] = get_device_value(self._input, button) cancel_button = ba.buttonwidget(parent=self._root_widget, autoselect=True, position=(38, self._height - 85), size=(170, 60), label=ba.Lstr(resource='cancelText'), scale=0.9, on_activate_call=self._cancel) save_button = ba.buttonwidget(parent=self._root_widget, autoselect=True, position=(self._width - 190, self._height - 85), size=(180, 60), label=ba.Lstr(resource='saveText'), scale=0.9, text_scale=0.9, on_activate_call=self._save) ba.containerwidget(edit=self._root_widget, cancel_button=cancel_button, start_button=save_button) ba.widget(edit=cancel_button, right_widget=save_button) ba.widget(edit=save_button, left_widget=cancel_button) v = self._height - 74.0 ba.textwidget(parent=self._root_widget, position=(self._width * 0.5, v + 15), size=(0, 0), text=ba.Lstr(resource=self._r + '.configuringText', subs=[('${DEVICE}', self._displayname)]), color=ba.app.ui.title_color, h_align='center', v_align='center', maxwidth=270, scale=0.83) v -= 20 if self._unique_id != '#1': v -= 20 v -= self._spacing ba.textwidget(parent=self._root_widget, position=(0, v + 19), size=(self._width, 50), text=ba.Lstr(resource=self._r + '.keyboard2NoteText'), scale=0.7, maxwidth=self._width * 0.75, max_height=110, color=ba.app.ui.infotextcolor, h_align='center', v_align='top') v -= 40 v -= 10 v -= self._spacing * 2.2 v += 25 v -= 42 h_offs = 160 dist = 70 d_color = (0.4, 0.4, 0.8) self._capture_button(pos=(h_offs, v + 0.95 * dist), color=d_color, button='buttonUp', texture=ba.gettexture('upButton'), scale=1.0) self._capture_button(pos=(h_offs - 1.2 * dist, v), color=d_color, button='buttonLeft', texture=ba.gettexture('leftButton'), scale=1.0) self._capture_button(pos=(h_offs + 1.2 * dist, v), color=d_color, button='buttonRight', texture=ba.gettexture('rightButton'), scale=1.0) self._capture_button(pos=(h_offs, v - 0.95 * dist), color=d_color, button='buttonDown', texture=ba.gettexture('downButton'), scale=1.0) if self._unique_id == '#2': self._capture_button(pos=(self._width * 0.5, v + 0.1 * dist), color=(0.4, 0.4, 0.6), button='buttonStart', texture=ba.gettexture('startButton'), scale=0.8) h_offs = self._width - 160 self._capture_button(pos=(h_offs, v + 0.95 * dist), color=(0.6, 0.4, 0.8), button='buttonPickUp', texture=ba.gettexture('buttonPickUp'), scale=1.0) self._capture_button(pos=(h_offs - 1.2 * dist, v), color=(0.7, 0.5, 0.1), button='buttonPunch', texture=ba.gettexture('buttonPunch'), scale=1.0) self._capture_button(pos=(h_offs + 1.2 * dist, v), color=(0.5, 0.2, 0.1), button='buttonBomb', texture=ba.gettexture('buttonBomb'), scale=1.0) self._capture_button(pos=(h_offs, v - 0.95 * dist), color=(0.2, 0.5, 0.2), button='buttonJump', texture=ba.gettexture('buttonJump'), scale=1.0)
def _rebuild_ui(self) -> None: # pylint: disable=too-many-statements # pylint: disable=too-many-locals from ba.internal import get_device_value # Clear existing UI. for widget in self._root_widget.get_children(): widget.delete() self._textwidgets: Dict[str, ba.Widget] = {} # If we were supplied with settings, we're a secondary joystick and # just operate on that. in the other (normal) case we make our own. if not self._is_secondary: # Fill our temp config with present values (for our primary and # secondary controls). self._settings = {} for skey in [ 'buttonJump', 'buttonJump_B', 'buttonPunch', 'buttonPunch_B', 'buttonBomb', 'buttonBomb_B', 'buttonPickUp', 'buttonPickUp_B', 'buttonStart', 'buttonStart_B', 'buttonStart2', 'buttonStart2_B', 'buttonUp', 'buttonUp_B', 'buttonDown', 'buttonDown_B', 'buttonLeft', 'buttonLeft_B', 'buttonRight', 'buttonRight_B', 'buttonRun1', 'buttonRun1_B', 'buttonRun2', 'buttonRun2_B', 'triggerRun1', 'triggerRun1_B', 'triggerRun2', 'triggerRun2_B', 'buttonIgnored', 'buttonIgnored_B', 'buttonIgnored2', 'buttonIgnored2_B', 'buttonIgnored3', 'buttonIgnored3_B', 'buttonIgnored4', 'buttonIgnored4_B', 'buttonVRReorient', 'buttonVRReorient_B', 'analogStickDeadZone', 'analogStickDeadZone_B', 'dpad', 'dpad_B', 'unassignedButtonsRun', 'unassignedButtonsRun_B', 'startButtonActivatesDefaultWidget', 'startButtonActivatesDefaultWidget_B', 'uiOnly', 'uiOnly_B', 'ignoreCompletely', 'ignoreCompletely_B', 'autoRecalibrateAnalogStick', 'autoRecalibrateAnalogStick_B', 'analogStickLR', 'analogStickLR_B', 'analogStickUD', 'analogStickUD_B', 'enableSecondary', ]: val = get_device_value(self._input, skey) if val != -1: self._settings[skey] = val back_button: Optional[ba.Widget] if self._is_secondary: back_button = ba.buttonwidget(parent=self._root_widget, position=(self._width - 180, self._height - 65), autoselect=True, size=(160, 60), label=ba.Lstr(resource='doneText'), scale=0.9, on_activate_call=self._save) ba.containerwidget(edit=self._root_widget, start_button=back_button, on_cancel_call=back_button.activate) cancel_button = None else: cancel_button = ba.buttonwidget( parent=self._root_widget, position=(51, self._height - 65), autoselect=True, size=(160, 60), label=ba.Lstr(resource='cancelText'), scale=0.9, on_activate_call=self._cancel) ba.containerwidget(edit=self._root_widget, cancel_button=cancel_button) save_button: Optional[ba.Widget] if not self._is_secondary: save_button = ba.buttonwidget( parent=self._root_widget, position=(self._width - (165 if self._is_secondary else 195), self._height - 65), size=((160 if self._is_secondary else 180), 60), autoselect=True, label=ba.Lstr(resource='doneText') if self._is_secondary else ba.Lstr(resource='saveText'), scale=0.9, on_activate_call=self._save) ba.containerwidget(edit=self._root_widget, start_button=save_button) else: save_button = None if not self._is_secondary: v = self._height - 59 ba.textwidget(parent=self._root_widget, position=(0, v + 5), size=(self._width, 25), text=ba.Lstr(resource=self._r + '.titleText'), color=ba.app.ui.title_color, maxwidth=310, h_align='center', v_align='center') v -= 48 ba.textwidget(parent=self._root_widget, position=(0, v + 3), size=(self._width, 25), text=self._name, color=ba.app.ui.infotextcolor, maxwidth=self._width * 0.9, h_align='center', v_align='center') v -= self._spacing * 1 ba.textwidget(parent=self._root_widget, position=(50, v + 10), size=(self._width - 100, 30), text=ba.Lstr(resource=self._r + '.appliesToAllText'), maxwidth=330, scale=0.65, color=(0.5, 0.6, 0.5, 1.0), h_align='center', v_align='center') v -= 70 self._enable_check_box = None else: v = self._height - 49 ba.textwidget(parent=self._root_widget, position=(0, v + 5), size=(self._width, 25), text=ba.Lstr(resource=self._r + '.secondaryText'), color=ba.app.ui.title_color, maxwidth=300, h_align='center', v_align='center') v -= self._spacing * 1 ba.textwidget(parent=self._root_widget, position=(50, v + 10), size=(self._width - 100, 30), text=ba.Lstr(resource=self._r + '.secondHalfText'), maxwidth=300, scale=0.65, color=(0.6, 0.8, 0.6, 1.0), h_align='center') self._enable_check_box = ba.checkboxwidget( parent=self._root_widget, position=(self._width * 0.5 - 80, v - 73), value=self.get_enable_secondary_value(), autoselect=True, on_value_change_call=self._enable_check_box_changed, size=(200, 30), text=ba.Lstr(resource=self._r + '.secondaryEnableText'), scale=1.2) v = self._height - 205 h_offs = 160 dist = 70 d_color = (0.4, 0.4, 0.8) sclx = 1.2 scly = 0.98 dpm = ba.Lstr(resource=self._r + '.pressAnyButtonOrDpadText') dpm2 = ba.Lstr(resource=self._r + '.ifNothingHappensTryAnalogText') self._capture_button(pos=(h_offs, v + scly * dist), color=d_color, button='buttonUp' + self._ext, texture=ba.gettexture('upButton'), scale=1.0, message=dpm, message2=dpm2) self._capture_button(pos=(h_offs - sclx * dist, v), color=d_color, button='buttonLeft' + self._ext, texture=ba.gettexture('leftButton'), scale=1.0, message=dpm, message2=dpm2) self._capture_button(pos=(h_offs + sclx * dist, v), color=d_color, button='buttonRight' + self._ext, texture=ba.gettexture('rightButton'), scale=1.0, message=dpm, message2=dpm2) self._capture_button(pos=(h_offs, v - scly * dist), color=d_color, button='buttonDown' + self._ext, texture=ba.gettexture('downButton'), scale=1.0, message=dpm, message2=dpm2) dpm3 = ba.Lstr(resource=self._r + '.ifNothingHappensTryDpadText') self._capture_button(pos=(h_offs + 130, v - 125), color=(0.4, 0.4, 0.6), button='analogStickLR' + self._ext, maxwidth=140, texture=ba.gettexture('analogStick'), scale=1.2, message=ba.Lstr(resource=self._r + '.pressLeftRightText'), message2=dpm3) self._capture_button(pos=(self._width * 0.5, v), color=(0.4, 0.4, 0.6), button='buttonStart' + self._ext, texture=ba.gettexture('startButton'), scale=0.7) h_offs = self._width - 160 self._capture_button(pos=(h_offs, v + scly * dist), color=(0.6, 0.4, 0.8), button='buttonPickUp' + self._ext, texture=ba.gettexture('buttonPickUp'), scale=1.0) self._capture_button(pos=(h_offs - sclx * dist, v), color=(0.7, 0.5, 0.1), button='buttonPunch' + self._ext, texture=ba.gettexture('buttonPunch'), scale=1.0) self._capture_button(pos=(h_offs + sclx * dist, v), color=(0.5, 0.2, 0.1), button='buttonBomb' + self._ext, texture=ba.gettexture('buttonBomb'), scale=1.0) self._capture_button(pos=(h_offs, v - scly * dist), color=(0.2, 0.5, 0.2), button='buttonJump' + self._ext, texture=ba.gettexture('buttonJump'), scale=1.0) self._advanced_button = ba.buttonwidget( parent=self._root_widget, autoselect=True, label=ba.Lstr(resource=self._r + '.advancedText'), text_scale=0.9, color=(0.45, 0.4, 0.5), textcolor=(0.65, 0.6, 0.7), position=(self._width - 300, 30), size=(130, 40), on_activate_call=self._do_advanced) try: if cancel_button is not None and save_button is not None: ba.widget(edit=cancel_button, right_widget=save_button) ba.widget(edit=save_button, left_widget=cancel_button) except Exception: ba.print_exception('Error wiring up gamepad config window.')
def _update(self) -> None: # pylint: disable=too-many-statements # pylint: disable=too-many-branches # pylint: disable=too-many-locals from ba.internal import get_device_value, get_remote_app_name if self._dead: return punch_button_names = set() jump_button_names = set() pickup_button_names = set() bomb_button_names = set() # We look at the session's players; not the activity's - we want to # get ones who are still in the process of selecting a character, etc. input_devices = [p.get_input_device() for p in ba.getsession().players] input_devices = [i for i in input_devices if i] # If there's no players with input devices yet, try to default to # showing keyboard controls. if not input_devices: kbd = _ba.get_input_device('Keyboard', '#1', doraise=False) if kbd is not None: input_devices.append(kbd) # We word things specially if we have nothing but keyboards. all_keyboards = (input_devices and all(i.name == 'Keyboard' for i in input_devices)) only_remote = (len(input_devices) == 1 and all(i.name == 'Amazon Fire TV Remote' for i in input_devices)) right_button_names = set() left_button_names = set() up_button_names = set() down_button_names = set() # For each player in the game with an input device, # get the name of the button for each of these 4 actions. # If any of them are uniform across all devices, display the name. for device in input_devices: # We only care about movement buttons in the case of keyboards. if all_keyboards: right_button_names.add( device.get_button_name( get_device_value(device, 'buttonRight'))) left_button_names.add( device.get_button_name( get_device_value(device, 'buttonLeft'))) down_button_names.add( device.get_button_name( get_device_value(device, 'buttonDown'))) up_button_names.add( device.get_button_name(get_device_value( device, 'buttonUp'))) # Ignore empty values; things like the remote app or # wiimotes can return these. bname = device.get_button_name( get_device_value(device, 'buttonPunch')) if bname != '': punch_button_names.add(bname) bname = device.get_button_name( get_device_value(device, 'buttonJump')) if bname != '': jump_button_names.add(bname) bname = device.get_button_name( get_device_value(device, 'buttonBomb')) if bname != '': bomb_button_names.add(bname) bname = device.get_button_name( get_device_value(device, 'buttonPickUp')) if bname != '': pickup_button_names.add(bname) # If we have no values yet, we may want to throw out some sane # defaults. if all(not lst for lst in (punch_button_names, jump_button_names, bomb_button_names, pickup_button_names)): # Otherwise on android show standard buttons. if ba.app.platform == 'android': punch_button_names.add('X') jump_button_names.add('A') bomb_button_names.add('B') pickup_button_names.add('Y') run_text = ba.Lstr( value='${R}: ${B}', subs=[('${R}', ba.Lstr(resource='runText')), ('${B}', ba.Lstr(resource='holdAnyKeyText' if all_keyboards else 'holdAnyButtonText'))]) # If we're all keyboards, lets show move keys too. if (all_keyboards and len(up_button_names) == 1 and len(down_button_names) == 1 and len(left_button_names) == 1 and len(right_button_names) == 1): up_text = list(up_button_names)[0] down_text = list(down_button_names)[0] left_text = list(left_button_names)[0] right_text = list(right_button_names)[0] run_text = ba.Lstr(value='${M}: ${U}, ${L}, ${D}, ${R}\n${RUN}', subs=[('${M}', ba.Lstr(resource='moveText')), ('${U}', up_text), ('${L}', left_text), ('${D}', down_text), ('${R}', right_text), ('${RUN}', run_text)]) self._run_text.text = run_text w_text: Union[ba.Lstr, str] if only_remote and self._lifespan is None: w_text = ba.Lstr(resource='fireTVRemoteWarningText', subs=[('${REMOTE_APP_NAME}', get_remote_app_name())]) else: w_text = '' self._extra_text.text = w_text if len(punch_button_names) == 1: self._punch_text.text = list(punch_button_names)[0] else: self._punch_text.text = '' if len(jump_button_names) == 1: tval = list(jump_button_names)[0] else: tval = '' self._jump_text.text = tval if tval == '': self._run_text.position = self._run_text_pos_top self._extra_text.position = (self._run_text_pos_top[0], self._run_text_pos_top[1] - 50) else: self._run_text.position = self._run_text_pos_bottom self._extra_text.position = (self._run_text_pos_bottom[0], self._run_text_pos_bottom[1] - 50) if len(bomb_button_names) == 1: self._bomb_text.text = list(bomb_button_names)[0] else: self._bomb_text.text = '' # Also move our title up/down depending on if this is shown. if len(pickup_button_names) == 1: self._pick_up_text.text = list(pickup_button_names)[0] if self._title_text is not None: self._title_text.position = self._title_text_pos_top else: self._pick_up_text.text = '' if self._title_text is not None: self._title_text.position = self._title_text_pos_bottom