-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds menus tutorial to wiki #447
Open
srpg
wants to merge
8
commits into
Source-Python-Dev-Team:master
Choose a base branch
from
srpg:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
91b8bba
Fixed typo
srpg a8175e8
Merge branch 'Source-Python-Dev-Team:master' into master
srpg 163b2a2
Merge branch 'Source-Python-Dev-Team:master' into master
srpg 0146523
Merge branch 'Source-Python-Dev-Team:master' into master
srpg 3a12815
Merge branch 'Source-Python-Dev-Team:master' into master
srpg 497bc80
Adds menus tutorial
srpg 5417152
Improved wiki
srpg 3596233
More improvements
srpg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
...s/source-python/docs/source-python/source/developing/module_tutorials/menus.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
Menus | ||
====== | ||
|
||
This page contains tutorials about the :mod:`menus.radio` package. | ||
jordanbriere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
Creating PagedMenu | ||
-------------------------- | ||
|
||
This is a simple example to create paged menu | ||
|
||
.. code-block:: python | ||
|
||
from commands.say import SayCommand | ||
|
||
from menus import PagedMenu | ||
from menus import PagedOption | ||
|
||
from players.entity import Player | ||
|
||
|
||
# Register menu command | ||
@SayCommand(['menu', '/menu', '!menu']) | ||
def say_command(command, index, teamonly): | ||
# Send the menu | ||
build_paged_menu(index) | ||
return False | ||
|
||
def build_paged_menu(index): | ||
# Create the Paged Menu and set title to My Menu | ||
menu = PagedMenu(title='My Menu') | ||
# Add options from 1 to 20 | ||
for i in range(1, 20): | ||
menu.append(PagedOption(f'{i}', i)) | ||
menu.select_callback=my_select_callback | ||
menu.send(index) | ||
|
||
def my_select_callback(menu, index, option): | ||
# Create player object from index | ||
player = Player(index) | ||
# Print the player name who have selected a menu option | ||
print(f'{player.name} have selected a menu option!') | ||
|
||
|
||
Creating SimpleMenu | ||
-------------------------- | ||
|
||
This is a simple example to create simple menu | ||
|
||
.. code-block:: python | ||
|
||
from commands.say import SayCommand | ||
|
||
from menus import SimpleMenu | ||
from menus import SimpleOption | ||
from menus import Text | ||
|
||
from messages import SayText2 | ||
|
||
from players.entity import Player | ||
|
||
# Register menu command | ||
@SayCommand(['menus', '/menus', '!menus']) | ||
def say_menus_command(command, index, teamonly): | ||
# Send the menu | ||
build_simple_menu(index) | ||
return False | ||
|
||
def build_simple_menu(index): | ||
# Create the SimpleMenu | ||
menu = SimpleMenu | ||
jordanbriere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Add in menu text | ||
menu.append(Text('Do you accept the rules?')) | ||
menu.append(Text(' ')) | ||
# Add in menu options | ||
menu.append(SimpleOption(1, 'Yes', 'yes')) | ||
menu.append(SimpleOption(2, 'No', 'no')) | ||
menu.select_callback=my_menu_select_callback | ||
menu.send(index) | ||
|
||
def my_menu_select_callback(menu, index, option): | ||
choice = option.value | ||
# Create player object from index | ||
player = Player(index) | ||
# Player did select yes option | ||
if choice == 'yes': | ||
SayText2('Thank you for accepting the rules!').send(index) | ||
# Player selected no option | ||
else: | ||
player.kick('You have to accept the rules!') | ||
jordanbriere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Creating ListMenu | ||
-------------------------- | ||
|
||
This is a simple example to create list menu | ||
|
||
.. code-block:: python | ||
|
||
from commands.say import SayCommand | ||
|
||
from menus import ListMenu | ||
from menus import Text | ||
|
||
# Register menu command | ||
@SayCommand(['menus', '/menus', '!menus']) | ||
def say_menus_command(command, index, teamonly): | ||
# Send the menu | ||
build_list_menu(index) | ||
return False | ||
|
||
def build_simple_menu(index): | ||
# Create the ListMenu | ||
menu = ListMenu() | ||
# Add in menu text | ||
menu.append(Text('This is a example text')) | ||
menu.send(index) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be all lowercase, so that the presentation is consistent with the other tutorials on the index: