Skip to content

Commit 5417152

Browse files
committed
Improved wiki
1 parent 497bc80 commit 5417152

File tree

1 file changed

+40
-39
lines changed
  • addons/source-python/docs/source-python/source/developing/module_tutorials

1 file changed

+40
-39
lines changed
Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Menus
22
======
33

4-
This page contains tutorials about the :mod:`menus.radio` package.
4+
This page contains tutorials about the :mod:`menus` package.
55

66

77
Creating PagedMenu
@@ -11,6 +11,8 @@ This is a simple example to create paged menu
1111

1212
.. code-block:: python
1313
14+
import random
15+
1416
from commands.say import SayCommand
1517
1618
from menus import PagedMenu
@@ -23,23 +25,25 @@ This is a simple example to create paged menu
2325
@SayCommand(['menu', '/menu', '!menu'])
2426
def say_command(command, index, teamonly):
2527
# Send the menu
26-
build_paged_menu(index)
28+
menu.send(index)
2729
return False
2830
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)
31+
menu = PagedMenu(title='Welcome menu', description='Choose an option:', select_callback=my_select_callback)
32+
33+
# Add options from 1 to 20
34+
for i in range(1, 20):
35+
menu.append(PagedOption(f'{i}', i))
3736
3837
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!')
38+
'''
39+
Called whenever a selection was made.
40+
'''
41+
42+
# Shuffle the menu : D
43+
random.shuffle(menu)
44+
45+
# Make it sticky
46+
return menu
4347
4448
4549
Creating SimpleMenu
@@ -49,6 +53,8 @@ This is a simple example to create simple menu
4953

5054
.. code-block:: python
5155
56+
import time
57+
5258
from commands.say import SayCommand
5359
5460
from menus import SimpleMenu
@@ -63,31 +69,29 @@ This is a simple example to create simple menu
6369
@SayCommand(['menus', '/menus', '!menus'])
6470
def say_menus_command(command, index, teamonly):
6571
# Send the menu
66-
build_simple_menu(index)
72+
menu.send(index)
6773
return False
6874
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)
75+
76+
menu = SimpleMenu()
77+
# Tell the current time
78+
menu.append(Text(f"Current Time: {time.strftime('%H:%M:%S')}"))
79+
# Add empty line
80+
menu.append(Text(' '))
81+
menu.append(Text('Do you accept the rules?'))
82+
menu.append(Text(' '))
83+
# Add in menu options
84+
menu.append(SimpleOption(1, 'Yes', 'yes'))
85+
menu.append(SimpleOption(2, 'No', 'no'))
86+
menu.select_callback=my_menu_select_callback
87+
8088
8189
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':
90+
if option.value == 'yes':
8791
SayText2('Thank you for accepting the rules!').send(index)
8892
# Player selected no option
8993
else:
90-
player.kick('You have to accept the rules!')
94+
Player(index).kick('You have to accept the rules!')
9195
9296
Creating ListMenu
9397
--------------------------
@@ -105,12 +109,9 @@ This is a simple example to create list menu
105109
@SayCommand(['menus', '/menus', '!menus'])
106110
def say_menus_command(command, index, teamonly):
107111
# Send the menu
108-
build_list_menu(index)
112+
menu.send(index)
109113
return False
110114
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)
115+
menu = ListMenu()
116+
# Add in menu text
117+
menu.append(Text('This is a example text'))

0 commit comments

Comments
 (0)