Difference between revisions of "Menus"
(Created page with '== Menus == The menus of Opensurge include the title screen, the options screen, and the custom quests section. Each of these menus can be customized to give the user a customiz…') |
(→Case study: Modifying the menu background.) |
||
Line 22: | Line 22: | ||
=== Case study: Modifying the menu background. === | === Case study: Modifying the menu background. === | ||
− | Now that we have constructed our own custom menu, we now want it to display our own background. This can be accomplished by modifying the menu. | + | Now that we have constructed our own custom menu, we now want it to display our own background. This can be accomplished by modifying the '''themes/menu.bg''' file so that it points to our own images and changing the data values to match our own animations. For example: |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | // --------------------------------------------------------------------------- | |
− | // | + | // Open Surge Engine |
− | + | // http://opensnc.sourceforge.net | |
− | + | // | |
− | + | // File: themes/menu.bg | |
− | + | // Desc: this background is displayed on the main menu | |
− | + | // Author: OS Team | |
− | + | // --------------------------------------------------------------------------- | |
− | + | ||
− | + | background | |
− | + | { | |
− | + | initial_position 0 0 | |
− | + | scroll_speed 0 0 | |
− | + | behavior LINEAR -30 -30 | |
− | + | repeat_x TRUE | |
− | + | repeat_y TRUE | |
− | + | ||
− | { | + | sprite |
− | + | { | |
− | + | source_file images/squarebg.png | |
− | + | source_rect 0 0 48 48 | |
− | + | frame_size 48 48 | |
− | + | ||
− | + | animation | |
+ | { | ||
+ | repeat TRUE | ||
+ | fps 8 | ||
+ | data 0 | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | // logo | ||
+ | background | ||
+ | { | ||
+ | initial_position 0 0 | ||
+ | scroll_speed 0 0 | ||
+ | behavior DEFAULT | ||
+ | repeat_x TRUE | ||
+ | repeat_y TRUE | ||
+ | |||
+ | sprite | ||
+ | { | ||
+ | source_file images/title.png | ||
+ | source_rect 0 0 320 240 | ||
+ | frame_size 320 240 | ||
+ | |||
+ | animation | ||
+ | { | ||
+ | repeat TRUE | ||
+ | fps 8 | ||
+ | data 0 | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | You can change it to achieve the effect of changing the Menu screen greatly. See also: [[Backgrounds]] | ||
=== Case study: scripting your own menu. === | === Case study: scripting your own menu. === |
Revision as of 20:59, 10 March 2011
Contents
Menus
The menus of Opensurge include the title screen, the options screen, and the custom quests section. Each of these menus can be customized to give the user a customized experience.
Menus can be modified by modifying a .lng file found in the languages folder of your Opensurge directory. In this case, we will be modifying the English language file in the main menu section to be more suited for our own experience. (A note to modders: modifying the .lng file will allow you to define constants and change any text which may be found in the original game. Without programming knowledge, however, it is impossible to change the number of items which are displayed on a menu or where they point to. If you wish for more control over menus which the player sees then I recommend using scripting to create your own custom menus. This process will be discussed later in this document. Also, modifying one language file will not modify the others, so if you wish for your mod to display correctly in several languages you will have to modify them as well.)
The original code:
MENU_1PGAME "START GAME" MENU_CUSTOMQUESTS "EXTRAS" MENU_OPTIONS "OPTIONS" MENU_EXIT "EXIT"
The above code defines several constants, which are basically values which do not change while the program is running and which the end-user cannot normally modify. You can define your own named constants for use in scripting in these .lng files, however unless you have a pressing reason to do so it is best to simply use variables and textout in your objects.
Our modified version:
MENU_1PGAME "SINGLE PLAYER" MENU_CUSTOMQUESTS "ADDONS" MENU_OPTIONS "OPTIONS" MENU_EXIT "QUIT"
In the above file, we have modified the text contained within the constants, therefore we have modified the text which will be displayed on the main menu of the Opensurge game. If you wish to try this out for yourself, please feel free to modify your own .lng files and change the values which are stored in these constants.
Now that we have constructed our own custom menu, we now want it to display our own background. This can be accomplished by modifying the themes/menu.bg file so that it points to our own images and changing the data values to match our own animations. For example:
// --------------------------------------------------------------------------- // Open Surge Engine // http://opensnc.sourceforge.net // // File: themes/menu.bg // Desc: this background is displayed on the main menu // Author: OS Team // --------------------------------------------------------------------------- background { initial_position 0 0 scroll_speed 0 0 behavior LINEAR -30 -30 repeat_x TRUE repeat_y TRUE sprite { source_file images/squarebg.png source_rect 0 0 48 48 frame_size 48 48 animation { repeat TRUE fps 8 data 0 } } } // logo background { initial_position 0 0 scroll_speed 0 0 behavior DEFAULT repeat_x TRUE repeat_y TRUE sprite { source_file images/title.png source_rect 0 0 320 240 frame_size 320 240 animation { repeat TRUE fps 8 data 0 } } }
You can change it to achieve the effect of changing the Menu screen greatly. See also: Backgrounds
This is the best way to ensure that you completely control what the user sees, and what events will happen when they choose something on your menu. Please note, this method is the most advanced and will require knowledge of the scripting system to fully use, please study the API reference and tutorials found on the wiki before continuing.
Our menu code:
// ----------------------------------------------------- // menu.obj // This is a custom menu // Originally designed for: An example // Version 0.1 // Author: lunarrush // ----------------------------------------------------- object "custom_menu" { requires 0.2.0 always_active detach_from_camera state "main" { disable_player_movement set_absolute_position 0 0 //Because our hotspot is in the top right corner ;) set_animation "MY_MENU_BACKGROUND" 0 let "$zindex = 9000" set_zindex $zindex textout "hud" 0 0 "<color=6d7dec>Game</color>" textout "hud" 0 10 "Quit" on_button_pressed "up" "highlight_quit" on_button_pressed "down" "highlight_quit" on_button_pressed "fire3" "game" } state "highlight_quit" { textout "hud" 0 0 "Game" textout "hud" 0 10 "<color=6d7dec>Quit</color>" on_button_pressed "up" "main" on_button_pressed "down" "main" on_button_pressed "fire3" "quit" } state "game" { enable_player_movement destroy } state "quit" { ask_to_leave change_state "main" } }
The above script will create a custom menu when placed in game, however you will have to replace "MY_MENU_BACKGROUND" with an actual defined sprite. It can also be customized to make a menu system, just remember that the larger the menu is the more difficult it will be to create using object scripting.