Esempio n. 1
0
    // Displays the menu to |player|. A promise will be returned that will resolve when the dialog
    // has dismissed from their screen, even when they didn't make a selection. The promise will be
    // resolved with NULL when the player disconnects before submitting a response. The |page|
    // argument is one-based -- optimised for display as opposed to array indices.
    async displayForPlayer(player, page = 1) {
        for (; page <= this.pageCount_; ++page) {
            const title = this.buildTitle(page);
            const label = this.buildButtonLabel(page);
            const content = this.buildContent(page);

            const result = await Dialog.displayMenu(
                player, !this.includeHeader(), title, content, 'Select', label);

            if (!result)
                return null;  // the player has disconnected

            if (result.response != Dialog.PRIMARY_BUTTON)
                continue;  // proceed to the next page

            if (result.item < 0 || result.item >= this.pageSize_)
                throw new Error('An out-of-bounds menu item has been selected by the player.');

            const selectedItem = this.items_[((page - 1) * this.pageSize_) + result.item];
            if (selectedItem.listener)
                await selectedItem.listener(player);

            return { player, item: selectedItem.labels };
        }

        // We're out of pages that can be displayed to the player.
        return null;
    }
Esempio n. 2
0
    return new Promise(resolve => {
      let builder = new MenuBuilder(this),
          menu = Dialog.displayMenu(player, builder.isList(), builder.buildCaption(), builder.buildContent(), 'Select', 'Cancel');

      // TODO(Russell): Handle pagination of menus.

      resolve(menu.then(result => {
        if (result.response != Dialog.PRIMARY_BUTTON)
          return null;

        if (result.item < 0 || result.item >= this.items_.length)
          throw new Error('An out-of-bounds menu item has been selected by the player.');

        let item = this.items_[result.item];
        if (item.listener)
          item.listener(player);

        return { player: player, item: item.labels };
      }));
    });
Esempio n. 3
0
 // Displays the message to |player|. A promise will be returned that will resolve when the player
 // has closed the message's dialog. The promise will reject only when the player is not connected,
 // or disconnects while the message is shown on their screen.
 displayForPlayer(player) {
   return Dialog.displayMessage(player, this.title_, this.message_, this.leftButton_, this.rightButton_).then(result => {
     return result.response;
   });
 }