Popuplib.Popup easymenu

From EventScripts Community Encyclopedia

Contents

Class: popuplib.Popup_easymenu

Note: Requires EventScripts 2.0
Module: popuplib
EventScripts version: 2.0

Overview

Description

A special type of popup that is used for building menus easily. The scripter only needs to create the menu and add options to it. The number of options is not limited, if you add more than 9, the menu will automatically contain more than 1 page and all controlling is taken care by this class.

Instead of creating in instance of this class directly, use popuplib.easymenu to create it.

Quick Example

This example shows how to create a simple menu and how to get information of the chosen menu item.

import es
import popuplib
 
myPopup = None
 
def menuhandler(userid, choice, popupname):
    ''' This method will be called when the player selects a menu item '''
    es.tell(userid, "Lol, there aren't %ss up there, silly!"%choice)
    # Will print out for example: "Lol, there aren't bananas up there, silly!"
 
def load():
    global myPopup
    # Create a new Popup_easymenu object using the easymenu method from popuplib,
    # Notice the last parameter, which specifies the method to be used for callback:
    myPopup = popuplib.easymenu('example_menu',None, menuhandler)
    
    # Set a title for the menu:
    myPopup.settitle("Select fruit:")
    # add some menu items to it:
    myPopup.addoption('banana', "Banana")
    myPopup.addoption('orange', "Orange")
    myPopup.addoption('coconut', "Coconut")
 
def player_jump(event_var):
    # Let's ask what fruit the player is trying to reach by jumping
    myPopup.send(event_var['userid'])
 
def unload():
    # Script unloading, remove the popup from taking memory
    myPopup.delete()

Methods

delete ()
Deletes the popup from memory
send (users)
Sends the popup to selected user/users
timeout (mode, time)
Sets popup to time out after specified number of seconds
unsend (users)
Remove this popup from users' queue and display (similar to Popuplib.close method functionality)
update (users)
Refresh the popup on users' display if being showed
addoption (item, text, state=1, lang=None)
Adds a new menu item
getPage (userid)
Returns the number of the page the user currently has active
getPageCount (lang=None)
Returns the number of pages in the menu
information (listlevel)
Writes information about the popup to server console
recache (users=[])
Refreshes the popup display cache
sendPage (users, page)
Sends the menu to users with specified page active
setdescription (text, lang=None)
Sets the menu description (shown under title)
setoption (item, text=None, state=None, lang=None)
Edits existing menu option by changing its text and/or state.
settitle (text, pagenumbers=30, lang=None)
Sets a new title for the menu
submenu (choice, menuname)
Specifies another popup to be immediately displayed after choosing the specified menu item
unsendPage (users, pagenumber)
Removes the menu from specified users if their active page is the same as specified

Attributes

name = (as specified during creation)
The global name identifier of this popup
vguititle = name
The title shown in VGUI windows
prepuser = ""
The method or script block to be called just before the popup is displayed to a player
oldskooltov = False
Use EventScripts 1.2-1.3 compatible behavior on timeout (trigger menuselect 10)
displaymode = "normal"
How the popup handles unassigned choices
c_beginsep = "-----------------------------"
Separator between title/description and the menu items
c_pagesep = "-----------------------------"
Separator between the menu items and page controls
c_endsep = ""
Separator between page controls and close item
menuselect = ""
A function or script block to be called every time any input is given to the menu
menuselectfb = (as specified by popuplib.easymenu)
A function or script block to be called when a valid menu item is chosen
editlang = "en"
The language used by the methods editing menu contents

See Also

blog comments powered by Disqus