Silent Creating Custom Menu: Difference between revisions
Line 21: | Line 21: | ||
loadMenu { "ui/rules.menu" } | loadMenu { "ui/rules.menu" } | ||
} | } | ||
</pre> | |||
The custom_main.menu defined in the menus_server_custom.txt in this example, could look like this: | |||
<pre> | |||
#include "ui/menudef.h" | |||
// Defines // | |||
#define WINDOW_X 16 | |||
#define WINDOW_Y 232 | |||
#define WINDOW_WIDTH 160 | |||
#define WINDOW_HEIGHT 60 | |||
#define GROUP_NAME "grpCustomMain" | |||
// Macros // | |||
#include "ui/menumacros.h" | |||
// Main Menu // | |||
menuDef { | |||
name "custom_main" | |||
visible 0 | |||
fullscreen 0 | |||
rect WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT | |||
style 0 | |||
onEsc { | |||
close custom_main ; | |||
} | |||
// Window // | |||
WINDOW( "^7Example", 232 ) | |||
// Buttons // | |||
BUTTON( 6, 32, WINDOW_WIDTH-12, 18, "^7Rules", .3, 14, close custom_main ; open rules ) | |||
} | |||
</pre> | </pre> | ||
Revision as of 12:55, 13 September 2015
Customized Server Menus
Starting from silEnT 0.9.0, server admins have the option to have a second, server customized menu. This is opposed to editing the official menus.
The second menu is always opened automatically if present when player opens the menus by pressing ESC. If the user clicks either menu, the official or the server custom menu, the other menu automatically closes. The server custom menus have the same commands as the official menus, with the exception that onOpen event can not be defined. If onOpen is defined, it is ignored.
Following is an example of a server custom menu:
Example
Customized server menu has one requirement, there must be a file called menus_server_custom.txt. This file is used exactly like the old menus.txt. It defines the .menu files that are loaded for the custom menu. An example:
// menu defs // { loadMenu { "ui/custom_main.menu" } loadMenu { "ui/rules.menu" } }
The custom_main.menu defined in the menus_server_custom.txt in this example, could look like this:
#include "ui/menudef.h" // Defines // #define WINDOW_X 16 #define WINDOW_Y 232 #define WINDOW_WIDTH 160 #define WINDOW_HEIGHT 60 #define GROUP_NAME "grpCustomMain" // Macros // #include "ui/menumacros.h" // Main Menu // menuDef { name "custom_main" visible 0 fullscreen 0 rect WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT style 0 onEsc { close custom_main ; } // Window // WINDOW( "^7Example", 232 ) // Buttons // BUTTON( 6, 32, WINDOW_WIDTH-12, 18, "^7Rules", .3, 14, close custom_main ; open rules ) }
The resulting files need to be packed into a zip file that is renamed to pk3 so that all the menu files and the "menus_server_custom.txt" are in and under ui directory.
Properties
- When user opens the menus, both the official menu and the server customized menu are opened. The menus are opened in a way that the official menu is always on top in case the two menus overlap.
- If user clicks a button in either menu, the other menu is automatically closed by the mod. This also includes the case when user presses ESC to close the menus.
- The onOpen event is ignored in the custom menus.
- Menu files in the etmain directory or the official menus can not be modified and the server refuses to start if it detects such modifications.