Update submenu code

This was SVN commit r10107.
This commit is contained in:
WhiteTreePaladin 2011-08-27 15:21:12 +00:00
parent 8729d1115d
commit 2915e9a85e
2 changed files with 116 additions and 121 deletions

View File

@ -1,4 +1,5 @@
var userReportEnabledText; // contains the original version with "$status" placeholder
var currentSubmenu; // contains placeholdersubmenu
function init()
{
@ -7,6 +8,7 @@ function init()
global.curr_music.loop();
userReportEnabledText = getGUIObjectByName("userReportEnabledText").caption;
currentSubmenu = "submenuSinglePlayer";
}
var t0 = new Date;
@ -99,32 +101,21 @@ function onTick()
}
// Update the submenu
var MARGIN = 4;
var currentSubmenu;
function updateSubmenu(buttonName, newSubmenu, numButtons)
function updateSubmenu(newSubmenu, position, buttonHeight, numButtons)
{
// hide old submenu if possible
if (null != currentSubmenu)
{
const MARGIN = 4;
// remove old submenu
getGUIObjectByName(currentSubmenu).hidden = true;
}
// save new submenu
// switch to new submenu
currentSubmenu = newSubmenu;
// unhide new submenu
getGUIObjectByName(currentSubmenu).hidden = false;
// find position of new submenu
var sourceButton = getGUIObjectByName(buttonName);
var verticalOffset = getGUIObjectByName("mainMenuButtons").size.top;
var buttonHeight = sourceButton.size.bottom - sourceButton.size.top;
var top = verticalOffset + sourceButton.size.top - MARGIN;
var bottom = verticalOffset + sourceButton.size.bottom + buttonHeight * (numButtons-1) + MARGIN;
// set position of new submenu
var submenu = getGUIObjectByName("submenu");
var top = position - MARGIN;
var bottom = position + (buttonHeight * numButtons) + MARGIN;
submenu.size = submenu.size.left + " " + top + " " + submenu.size.right + " " + bottom;
submenu.hidden = false;

View File

@ -205,7 +205,7 @@ Status: $status.
>
Single Player
<action on="Press"><![CDATA[
updateSubmenu("menuSinglePlayerButton", "submenuSinglePlayer", 3);
updateSubmenu("submenuSinglePlayer", (this.parent.size.top+this.size.top), (this.size.bottom-this.size.top), 3);
]]></action>
</object>
@ -219,7 +219,7 @@ Status: $status.
>
Multiplayer
<action on="Press"><![CDATA[
updateSubmenu("menuMultiplayerButton", "submenuMultiplayer", 2);
updateSubmenu("submenuMultiplayer", (this.parent.size.top+this.size.top), (this.size.bottom-this.size.top), 2);
]]></action>
</object>
@ -233,7 +233,7 @@ Status: $status.
>
Tools <![CDATA[&]]> Options
<action on="Press"><![CDATA[
updateSubmenu("menuToolsAndOptionsButton", "submenuToolsAndOptions", 2);
updateSubmenu("submenuToolsAndOptions", (this.parent.size.top+this.size.top), (this.size.bottom-this.size.top), 2);
]]></action>
</object>
@ -361,7 +361,7 @@ Get involved at: wildfiregames.com/0ad
<!--
==========================================
- MAIN MENU SIDE PANEL
- SUBMENU
==========================================
-->
@ -370,15 +370,19 @@ Get involved at: wildfiregames.com/0ad
type="image"
hidden="true"
>
<!-- hides the submenu when the mouse leaves the mainMenuButtons or submenu -->
<action on="MouseEnter">
<![CDATA[getGUIObjectByName("submenu").hidden = true;;]]>
<![CDATA[getGUIObjectByName("submenu").hidden = true;]]>
</action>
<!-- submenu -->
<object
name="submenu"
type="image"
style="MainMenuPanel"
size="298 50%-100 538 50%+100"
>
<!-- submenuSinglePlayer -->
<object name="submenuSinglePlayer"
type="image"
size="4 4 100%-4 100%-4"
@ -415,7 +419,7 @@ Get involved at: wildfiregames.com/0ad
</object>
</object>
<!-- submenuMultiplayer -->
<object name="submenuMultiplayer"
type="image"
size="4 4 100%-4 100%-4"
@ -438,6 +442,7 @@ Get involved at: wildfiregames.com/0ad
</object>
</object>
<!-- submenuToolsAndOptions -->
<object name="submenuToolsAndOptions"
type="image"
size="4 4 100%-4 100%-4"
@ -448,7 +453,7 @@ Get involved at: wildfiregames.com/0ad
<object name="submenuOptionsButton"
style="StoneButtonFancy"
type="button"
size="4 0 100%-4 32"
size="0 0 100% 32"
tooltip_style="pgToolTip"
tooltip="This will take you to the options menu. It does not work now, but someday it will."
enabled="false"
@ -463,7 +468,7 @@ Get involved at: wildfiregames.com/0ad
<object name="submenuEditorButton"
style="StoneButtonFancy"
type="button"
size="4 32 100%-4 64"
size="0 32 100% 64"
tooltip_style="pgToolTip"
tooltip="Open the Atlas Scenario Editor in a new window. You can run this more reliably by starting the game with the command-line argument &quot;-editor&quot;."
>
@ -476,9 +481,8 @@ Get involved at: wildfiregames.com/0ad
]]></action>
</object>
</object>
</object>
</object> <!-- end of screen -->
</object><!-- end of submenu -->
</object><!-- end of submenu screen -->