Search in sources :

Example 1 with ButtonBook

use of gartham.c10ver.response.menus.ButtonBook in project c10ver by Gartham.

the class DungeonGame method start.

public void start(DungeonCover... dungeons) {
    EmbedBuilder eb = new EmbedBuilder();
    eb.setColor(new Color(0x5E2A03));
    eb.setTitle("World Selector").setDescription("Select a world to explore " + target.getAsMention() + ":").setImage(dungeons[0].graphic).setFooter("Page 1 of " + dungeons.length);
    var bb = new ButtonBook(buttonProcessor);
    bb.add("\u2705");
    bb.setTarget(target);
    bb.setMaxPage(dungeons.length - 1);
    bb.setEdgeButtons(true);
    bb.setPageHandler((t, e) -> e.getHook().editOriginalEmbeds(eb.setImage(dungeons[t].graphic).setFooter("Page " + (t + 1) + " of " + (bb.getMaxPage() + 1)).build()).queue());
    var abb = bb.attachAndSend(channel.sendMessageEmbeds(eb.build()));
    abb.setHandler(t -> {
        t.deferEdit().complete();
        abb.unregister();
        startDungeon(t);
    });
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ButtonBook(gartham.c10ver.response.menus.ButtonBook) Color(java.awt.Color)

Example 2 with ButtonBook

use of gartham.c10ver.response.menus.ButtonBook in project c10ver by Gartham.

the class DungeonGame method promptDungeon.

/**
 * Returns an {@link Action} of prompting the target user in the specified
 * channel for what dungeon they would like to play. The returned {@link Action}
 * sends the built prompt to the user and waits for a reply from the user,
 * returning the selected page.
 *
 * @param dungeons The {@link DungeonCover}s to show to the user in the prompt.
 * @return A new {@link Action} that, when invoked, prompts the user and waits
 *         until the user has answered. The answer is the page number (dungeon
 *         number) that the user has selected).
 */
public Action<Integer> promptDungeon(DungeonCover... dungeons) {
    EmbedBuilder eb = new EmbedBuilder();
    eb.setColor(new Color(0x5E2A03));
    eb.setTitle("World Selector").setDescription("Select a world to explore " + target.getAsMention() + ":").setImage(dungeons[0].graphic).setFooter("Page 1 of " + dungeons.length);
    var bb = new ButtonBook(buttonProcessor);
    bb.add("\u2705");
    bb.setTarget(target);
    bb.setMaxPage(dungeons.length - 1);
    bb.setEdgeButtons(true);
    bb.setPageHandler((t, e) -> e.getHook().editOriginalEmbeds(eb.setImage(dungeons[t].graphic).setFooter("Page " + (t + 1) + " of " + (bb.getMaxPage() + 1)).build()).queue());
    return new Action<>() {

        private int res;

        @Override
        public Integer perform() {
            synchronized (this) {
                var abb = bb.attachAndSend(channel.sendMessageEmbeds(eb.build()));
                abb.setHandler(t -> {
                    synchronized (this) {
                        res = abb.getPage();
                        notify();
                        t.deferEdit().complete();
                        abb.unregister();
                    }
                });
                try {
                    wait();
                } catch (InterruptedException e) {
                }
            }
            return res;
        }
    };
// abb.setHandler(t -> {
// 
// t.getInteraction().editComponents(abb.disabledButtonView()).queue();
// 
// });
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Action(gartham.apps.garthchat.api.execution.Action) ButtonBook(gartham.c10ver.response.menus.ButtonBook) Color(java.awt.Color)

Aggregations

ButtonBook (gartham.c10ver.response.menus.ButtonBook)2 Color (java.awt.Color)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 Action (gartham.apps.garthchat.api.execution.Action)1