|
| 1 | +Menus |
| 2 | +====== |
| 3 | + |
| 4 | +This page contains tutorials about the :mod:`menus.radio` package. |
| 5 | + |
| 6 | + |
| 7 | +Creating PagedMenu |
| 8 | +-------------------------- |
| 9 | + |
| 10 | +This is a simple example to create paged menu |
| 11 | + |
| 12 | +.. code-block:: python |
| 13 | +
|
| 14 | + from commands.say import SayCommand |
| 15 | +
|
| 16 | + from menus import PagedMenu |
| 17 | + from menus import PagedOption |
| 18 | +
|
| 19 | + from players.entity import Player |
| 20 | +
|
| 21 | +
|
| 22 | + # Register menu command |
| 23 | + @SayCommand(['menu', '/menu', '!menu']) |
| 24 | + def say_command(command, index, teamonly): |
| 25 | + # Send the menu |
| 26 | + build_paged_menu(index) |
| 27 | + return False |
| 28 | +
|
| 29 | + def build_paged_menu(index): |
| 30 | + # Create the Paged Menu and set title to My Menu |
| 31 | + menu = PagedMenu(title='My Menu') |
| 32 | + # Add options from 1 to 20 |
| 33 | + for i in range(1, 20): |
| 34 | + menu.append(PagedOption(f'{i}', i)) |
| 35 | + menu.select_callback=my_select_callback |
| 36 | + menu.send(index) |
| 37 | +
|
| 38 | + def my_select_callback(menu, index, option): |
| 39 | + # Create player object from index |
| 40 | + player = Player(index) |
| 41 | + # Print the player name who have selected a menu option |
| 42 | + print(f'{player.name} have selected a menu option!') |
| 43 | +
|
| 44 | +
|
| 45 | +Creating SimpleMenu |
| 46 | +-------------------------- |
| 47 | + |
| 48 | +This is a simple example to create simple menu |
| 49 | + |
| 50 | +.. code-block:: python |
| 51 | +
|
| 52 | + from commands.say import SayCommand |
| 53 | +
|
| 54 | + from menus import SimpleMenu |
| 55 | + from menus import SimpleOption |
| 56 | + from menus import Text |
| 57 | +
|
| 58 | + from messages import SayText2 |
| 59 | +
|
| 60 | + from players.entity import Player |
| 61 | +
|
| 62 | + # Register menu command |
| 63 | + @SayCommand(['menus', '/menus', '!menus']) |
| 64 | + def say_menus_command(command, index, teamonly): |
| 65 | + # Send the menu |
| 66 | + build_simple_menu(index) |
| 67 | + return False |
| 68 | +
|
| 69 | + def build_simple_menu(index): |
| 70 | + # Create the SimpleMenu |
| 71 | + menu = SimpleMenu |
| 72 | + # Add in menu text |
| 73 | + menu.append(Text('Do you accept the rules?')) |
| 74 | + menu.append(Text(' ')) |
| 75 | + # Add in menu options |
| 76 | + menu.append(SimpleOption(1, 'Yes', 'yes')) |
| 77 | + menu.append(SimpleOption(2, 'No', 'no')) |
| 78 | + menu.select_callback=my_menu_select_callback |
| 79 | + menu.send(index) |
| 80 | +
|
| 81 | + def my_menu_select_callback(menu, index, option): |
| 82 | + choice = option.value |
| 83 | + # Create player object from index |
| 84 | + player = Player(index) |
| 85 | + # Player did select yes option |
| 86 | + if choice == 'yes': |
| 87 | + SayText2('Thank you for accepting the rules!').send(index) |
| 88 | + # Player selected no option |
| 89 | + else: |
| 90 | + player.kick('You have to accept the rules!') |
| 91 | +
|
| 92 | +Creating ListMenu |
| 93 | +-------------------------- |
| 94 | + |
| 95 | +This is a simple example to create list menu |
| 96 | + |
| 97 | +.. code-block:: python |
| 98 | +
|
| 99 | + from commands.say import SayCommand |
| 100 | +
|
| 101 | + from menus import ListMenu |
| 102 | + from menus import Text |
| 103 | +
|
| 104 | + # Register menu command |
| 105 | + @SayCommand(['menus', '/menus', '!menus']) |
| 106 | + def say_menus_command(command, index, teamonly): |
| 107 | + # Send the menu |
| 108 | + build_list_menu(index) |
| 109 | + return False |
| 110 | +
|
| 111 | + def build_simple_menu(index): |
| 112 | + # Create the ListMenu |
| 113 | + menu = ListMenu() |
| 114 | + # Add in menu text |
| 115 | + menu.append(Text('This is a example text')) |
| 116 | + menu.send(index) |
0 commit comments