Beispiel #1
0
 def _copy(self) -> None:
     if not ba.clipboard_is_supported():
         ba.screenmessage('Clipboard not supported on this platform.',
                          color=(1, 0, 0))
         return
     ba.clipboard_set_text('\n'.join(self._printed_lines))
     ba.screenmessage(f'{len(self._printed_lines)} lines copied.')
Beispiel #2
0
    def _build_host_tab(self) -> None:
        # pylint: disable=too-many-branches
        # pylint: disable=too-many-statements

        if _ba.get_account_state() != 'signed_in':
            ba.textwidget(parent=self._container,
                          size=(0, 0),
                          h_align='center',
                          v_align='center',
                          maxwidth=200,
                          scale=0.8,
                          color=(0.6, 0.56, 0.6),
                          position=(self._c_width * 0.5, self._c_height * 0.5),
                          text=ba.Lstr(resource='notSignedInErrorText'))
            self._showing_not_signed_in_screen = True
            return
        self._showing_not_signed_in_screen = False

        # At first we don't want to show anything until we've gotten a state.
        # Update: In this situation we now simply show our existing state
        # but give the start/stop button a loading message and disallow its
        # use. This keeps things a lot less jumpy looking and allows selecting
        # playlists/etc without having to wait for the server each time
        # back to the ui.
        if self._waiting_for_initial_state and bool(False):
            ba.textwidget(
                parent=self._container,
                size=(0, 0),
                h_align='center',
                v_align='center',
                maxwidth=200,
                scale=0.8,
                color=(0.6, 0.56, 0.6),
                position=(self._c_width * 0.5, self._c_height * 0.5),
                text=ba.Lstr(
                    value='${A}...',
                    subs=[('${A}', ba.Lstr(resource='store.loadingText'))],
                ),
            )
            return

        # If we're not currently hosting and hosting requires tickets,
        # Show our count (possibly with a link to purchase more).
        if (not self._waiting_for_initial_state
                and self._hostingstate.party_code is None
                and self._hostingstate.tickets_to_host_now != 0):
            if not ba.app.ui.use_toolbars:
                if ba.app.allow_ticket_purchases:
                    self._get_tickets_button = ba.buttonwidget(
                        parent=self._container,
                        position=(self._c_width - 210 + 125,
                                  self._c_height - 44),
                        autoselect=True,
                        scale=0.6,
                        size=(120, 60),
                        textcolor=(0.2, 1, 0.2),
                        label=ba.charstr(ba.SpecialChar.TICKET),
                        color=(0.65, 0.5, 0.8),
                        on_activate_call=self._on_get_tickets_press)
                else:
                    self._ticket_count_text = ba.textwidget(
                        parent=self._container,
                        scale=0.6,
                        position=(self._c_width - 210 + 125,
                                  self._c_height - 44),
                        color=(0.2, 1, 0.2),
                        h_align='center',
                        v_align='center')
                # Set initial ticket count.
                self._update_currency_ui()

        v = self._c_height - 90
        if self._hostingstate.party_code is None:
            ba.textwidget(
                parent=self._container,
                size=(0, 0),
                h_align='center',
                v_align='center',
                maxwidth=self._c_width * 0.9,
                scale=0.7,
                flatness=1.0,
                color=(0.5, 0.46, 0.5),
                position=(self._c_width * 0.5, v),
                text=ba.Lstr(
                    resource='gatherWindow.privatePartyCloudDescriptionText'))

        v -= 100
        if self._hostingstate.party_code is None:
            # We've got no current party running; show options to set one up.
            ba.textwidget(parent=self._container,
                          size=(0, 0),
                          h_align='right',
                          v_align='center',
                          maxwidth=200,
                          scale=0.8,
                          color=(0.6, 0.56, 0.6),
                          position=(self._c_width * 0.5 - 210, v),
                          text=ba.Lstr(resource='playlistText'))
            self._host_playlist_button = ba.buttonwidget(
                parent=self._container,
                size=(400, 70),
                color=(0.6, 0.5, 0.6),
                textcolor=(0.8, 0.75, 0.8),
                label=self._hostingconfig.playlist_name,
                on_activate_call=self._playlist_press,
                position=(self._c_width * 0.5 - 200, v - 35),
                up_widget=self._host_sub_tab_text,
                autoselect=True)

            # If it appears we're coming back from playlist selection,
            # re-select our playlist button.
            if ba.app.ui.selecting_private_party_playlist:
                ba.containerwidget(edit=self._container,
                                   selected_child=self._host_playlist_button)
                ba.app.ui.selecting_private_party_playlist = False
        else:
            # We've got a current party; show its info.
            ba.textwidget(
                parent=self._container,
                size=(0, 0),
                h_align='center',
                v_align='center',
                maxwidth=600,
                scale=0.9,
                color=(0.7, 0.64, 0.7),
                position=(self._c_width * 0.5, v + 90),
                text=ba.Lstr(resource='gatherWindow.partyServerRunningText'))
            ba.textwidget(parent=self._container,
                          size=(0, 0),
                          h_align='center',
                          v_align='center',
                          maxwidth=600,
                          scale=0.7,
                          color=(0.7, 0.64, 0.7),
                          position=(self._c_width * 0.5, v + 50),
                          text=ba.Lstr(resource='gatherWindow.partyCodeText'))
            ba.textwidget(parent=self._container,
                          size=(0, 0),
                          h_align='center',
                          v_align='center',
                          scale=2.0,
                          color=(0.0, 1.0, 0.0),
                          position=(self._c_width * 0.5, v + 10),
                          text=self._hostingstate.party_code)

            # Also action buttons to copy it and connect to it.
            if ba.clipboard_is_supported():
                cbtnoffs = 10
                self._host_copy_button = ba.buttonwidget(
                    parent=self._container,
                    size=(140, 40),
                    color=(0.6, 0.5, 0.6),
                    textcolor=(0.8, 0.75, 0.8),
                    label=ba.Lstr(resource='gatherWindow.copyCodeText'),
                    on_activate_call=self._host_copy_press,
                    position=(self._c_width * 0.5 - 150, v - 70),
                    autoselect=True)
            else:
                cbtnoffs = -70
            self._host_connect_button = ba.buttonwidget(
                parent=self._container,
                size=(140, 40),
                color=(0.6, 0.5, 0.6),
                textcolor=(0.8, 0.75, 0.8),
                label=ba.Lstr(resource='gatherWindow.manualConnectText'),
                on_activate_call=self._host_connect_press,
                position=(self._c_width * 0.5 + cbtnoffs, v - 70),
                autoselect=True)

        v -= 120

        # Line above the main action button:

        # If we don't want to show anything until we get a state:
        if self._waiting_for_initial_state:
            pass
        elif self._hostingstate.unavailable_error is not None:
            # If hosting is unavailable, show the associated reason.
            ba.textwidget(
                parent=self._container,
                size=(0, 0),
                h_align='center',
                v_align='center',
                maxwidth=self._c_width * 0.9,
                scale=0.7,
                flatness=1.0,
                color=(1.0, 0.0, 0.0),
                position=(self._c_width * 0.5, v),
                text=ba.Lstr(translate=('serverResponses',
                                        self._hostingstate.unavailable_error)))
        elif self._hostingstate.free_host_minutes_remaining is not None:
            # If we've been pre-approved to start/stop for free, show that.
            ba.textwidget(
                parent=self._container,
                size=(0, 0),
                h_align='center',
                v_align='center',
                maxwidth=self._c_width * 0.9,
                scale=0.7,
                flatness=1.0,
                color=((0.7, 0.64, 0.7) if self._hostingstate.party_code else
                       (0.0, 1.0, 0.0)),
                position=(self._c_width * 0.5, v),
                text=ba.Lstr(
                    resource='gatherWindow.startStopHostingMinutesText',
                    subs=[(
                        '${MINUTES}',
                        f'{self._hostingstate.free_host_minutes_remaining:.0f}'
                    )]))
        else:
            # Otherwise tell whether the free cloud server is available
            # or will be at some point.
            if self._hostingstate.party_code is None:
                if self._hostingstate.tickets_to_host_now == 0:
                    ba.textwidget(
                        parent=self._container,
                        size=(0, 0),
                        h_align='center',
                        v_align='center',
                        maxwidth=self._c_width * 0.9,
                        scale=0.7,
                        flatness=1.0,
                        color=(0.0, 1.0, 0.0),
                        position=(self._c_width * 0.5, v),
                        text=ba.Lstr(
                            resource=
                            'gatherWindow.freeCloudServerAvailableNowText'))
                else:
                    if self._hostingstate.minutes_until_free_host is None:
                        ba.textwidget(
                            parent=self._container,
                            size=(0, 0),
                            h_align='center',
                            v_align='center',
                            maxwidth=self._c_width * 0.9,
                            scale=0.7,
                            flatness=1.0,
                            color=(1.0, 0.6, 0.0),
                            position=(self._c_width * 0.5, v),
                            text=ba.Lstr(
                                resource=
                                'gatherWindow.freeCloudServerNotAvailableText')
                        )
                    else:
                        availmins = self._hostingstate.minutes_until_free_host
                        ba.textwidget(
                            parent=self._container,
                            size=(0, 0),
                            h_align='center',
                            v_align='center',
                            maxwidth=self._c_width * 0.9,
                            scale=0.7,
                            flatness=1.0,
                            color=(1.0, 0.6, 0.0),
                            position=(self._c_width * 0.5, v),
                            text=ba.Lstr(resource='gatherWindow.'
                                         'freeCloudServerAvailableMinutesText',
                                         subs=[('${MINUTES}',
                                                f'{availmins:.0f}')]))

        v -= 100

        if (self._waiting_for_start_stop_response
                or self._waiting_for_initial_state):
            btnlabel = ba.Lstr(resource='oneMomentText')
        else:
            if self._hostingstate.unavailable_error is not None:
                btnlabel = ba.Lstr(
                    resource='gatherWindow.hostingUnavailableText')
            elif self._hostingstate.party_code is None:
                ticon = _ba.charstr(ba.SpecialChar.TICKET)
                nowtickets = self._hostingstate.tickets_to_host_now
                if nowtickets > 0:
                    btnlabel = ba.Lstr(
                        resource='gatherWindow.startHostingPaidText',
                        subs=[('${COST}', f'{ticon}{nowtickets}')])
                else:
                    btnlabel = ba.Lstr(
                        resource='gatherWindow.startHostingText')
            else:
                btnlabel = ba.Lstr(resource='gatherWindow.stopHostingText')

        disabled = (self._hostingstate.unavailable_error is not None
                    or self._waiting_for_initial_state)
        waiting = self._waiting_for_start_stop_response
        self._host_start_stop_button = ba.buttonwidget(
            parent=self._container,
            size=(400, 80),
            color=((0.6, 0.6, 0.6) if disabled else
                   (0.5, 1.0, 0.5) if waiting else None),
            enable_sound=False,
            label=btnlabel,
            textcolor=((0.7, 0.7, 0.7) if disabled else None),
            position=(self._c_width * 0.5 - 200, v),
            on_activate_call=self._start_stop_button_press,
            autoselect=True)