1
0
forked from 0ad/0ad

Made settings and menu use new dialog

Made chat and ESC hotkey interact better with the dialog
Made command icons reference individual icons rather than sheets
Removed menu object cache

This was SVN commit r8715.
This commit is contained in:
WhiteTreePaladin 2010-11-27 19:46:12 +00:00
parent bbe49141ec
commit 0b0cd938d5
6 changed files with 144 additions and 171 deletions

View File

@ -862,7 +862,7 @@ function performCommand(entity, commandName)
if (selection.length > 0) if (selection.length > 0)
{ {
var message = selection.length > 1? "Are you sure you want to delete all of the units you have selected?" : var message = selection.length > 1? "Are you sure you want to delete the " + selection.length + " units you have selected?" :
"Are you sure you want to delete: "+unitName+"?"; "Are you sure you want to delete: "+unitName+"?";
var deleteFunction = deleteFunction = function () var deleteFunction = deleteFunction = function ()
@ -871,7 +871,7 @@ function performCommand(entity, commandName)
Engine.PostNetworkCommand({"type": "delete-entity", "entity": ent}); Engine.PostNetworkCommand({"type": "delete-entity", "entity": ent});
}; };
g_SessionDialog.open("Delete", message, null, 170, 80, deleteFunction); g_SessionDialog.open("Delete", message, null, 340, 160, deleteFunction);
} }
break; break;
case "unload-all": case "unload-all":

View File

@ -1,81 +1,81 @@
// Cache these objects for future access
var devCommands;
var menu;
var settingsWindow;
var chatWindow;
var chatInput;
var pauseOverlay;
function cacheMenuObjects()
{
devCommands = getGUIObjectByName("devCommands");
menu = getGUIObjectByName("menuPanel");
settingsWindow = getGUIObjectByName("settingsWindow");
chatWindow = getGUIObjectByName("chatWindow");
chatInput = getGUIObjectByName("chatInput");
pauseOverlay = getGUIObjectByName("pauseOverlay");
}
function toggleDeveloperOverlay() function toggleDeveloperOverlay()
{ {
var devCommands = getGUIObjectByName("devCommands");
var text = devCommands.hidden? "opened." : "closed."; var text = devCommands.hidden? "opened." : "closed.";
submitChatDirectly("The Developer Overlay was " + text); submitChatDirectly("The Developer Overlay was " + text);
devCommands.hidden = !devCommands.hidden; devCommands.hidden = !devCommands.hidden;
} }
function toggleMenu() function openMenuDialog()
{ {
menu.hidden = !menu.hidden; var menu = getGUIObjectByName("menuDialogPanel");
g_SessionDialog.open("Menu", null, menu, 148, 224, null);
} }
function toggleSettingsWindow() function openSettingsDialog()
{ {
settingsWindow.hidden = !settingsWindow.hidden; var settings = getGUIObjectByName("settingsDialogPanel");
menu.hidden = true; g_SessionDialog.open("Settings", null, settings, 340, 224, null);
}
function openChat()
{
getGUIObjectByName("chatInput").focus(); // Grant focus to the input area
getGUIObjectByName("chatDialogPanel").hidden = false;
g_SessionDialog.close();
}
function closeChat()
{
getGUIObjectByName("chatInput").caption = ""; // Clear chat input
getGUIObjectByName("chatDialogPanel").hidden = true;
g_SessionDialog.close();
} }
function toggleChatWindow() function toggleChatWindow()
{ {
var chatWindow = getGUIObjectByName("chatDialogPanel");
var chatInput = getGUIObjectByName("chatInput");
if (chatWindow.hidden) if (chatWindow.hidden)
chatInput.focus(); // Grant focus to the input area chatInput.focus(); // Grant focus to the input area
else else
chatInput.caption = ""; // Clear chat input chatInput.caption = ""; // Clear chat input
chatWindow.hidden = !chatWindow.hidden; chatWindow.hidden = !chatWindow.hidden;
menu.hidden = true; g_SessionDialog.close();
} }
function togglePause() function togglePause()
{ {
var pauseOverlay = getGUIObjectByName("pauseOverlay");
if (pauseOverlay.hidden) if (pauseOverlay.hidden)
{
setPaused(true); setPaused(true);
getGUIObjectByName("pauseButtonText").caption = "Unpause";
}
else else
{
setPaused(false); setPaused(false);
getGUIObjectByName("pauseButtonText").caption = "Pause";
}
pauseOverlay.hidden = !pauseOverlay.hidden; pauseOverlay.hidden = !pauseOverlay.hidden;
menu.hidden = true; g_SessionDialog.close();
} }
function openExitGameDialog() function openExitGameDialog()
{ {
g_SessionDialog.open("Confirmation", "Do you really want to quit?", null, 160, 70, leaveGame); g_SessionDialog.open("Confirmation", "Do you really want to quit?", null, 320, 140, leaveGame);
} }
function escapeKeyAction() function escapeKeyAction()
{ {
if (!menu.hidden) var sessionDialog = getGUIObjectByName("sessionDialog");
{
menu.hidden = true; if (!sessionDialog.hidden)
} g_SessionDialog.close();
else if (!chatWindow.hidden) else
{ getGUIObjectByName("chatDialogPanel").hidden = true;
chatWindow.hidden = true;
chatInput.caption = "";
}
else if (!settingsWindow.hidden)
{
settingsWindow.hidden = true;
console.write("test");
}
} }

View File

@ -81,8 +81,6 @@ function init(initData, hotloadData)
g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" }; g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" };
getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem; getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem;
cacheMenuObjects();
onSimulationUpdate(); onSimulationUpdate();
} }

View File

@ -141,32 +141,6 @@
</object> </object>
</object> </object>
<!-- ================================ ================================ -->
<!-- Session Dialog -->
<!-- ================================ ================================ -->
<object name="sessionDialog"
sprite="genericPanel"
type="image"
size="50%-180 50%-200 50%+180 50%+50"
hidden="true"
>
<object name="sessionDialogTitle" size="0 0 100% 32" type="text" style="largeBoldCenteredText">Title</object >
<object name="sessionDialogMessage" size="10 10 100%-10 100%-48" type="text" style="dialogText"/>
<object name="sessionDialogPanel" size="10 10 100%-10 100%-48" type="image"/>
<object size="0 100%-48 100% 100%">
<object name="sessionDialogConfirm" size="32 100%-44 144 100%-12" type="button" style="wheatButton">
OK
<action on="Press"></action>
</object>
<object name="sessionDialogCancel" size="100%-144 100%-44 100%-32 100%-12" type="button" style="wheatButton">
Cancel
<action on="Press">g_SessionDialog.close();</action>
</object>
</object>
</object>
<!-- ================================ ================================ --> <!-- ================================ ================================ -->
<!-- Pause Overlay --> <!-- Pause Overlay -->
<!-- ================================ ================================ --> <!-- ================================ ================================ -->
@ -199,14 +173,14 @@
</object> </object>
<!-- Chat window --> <!-- Chat window -->
<object name="chatWindow" size="50%-200 50%-46 50%+200 50%+46" type="image" hidden="true" z="40" sprite="genericPanel"> <object name="chatDialogPanel" size="50%-200 50%-46 50%+200 50%+46" type="image" hidden="true" sprite="genericPanel">
<object name="chatInput" size="16 12 100%-16 36" type="input" style="chatInput" max_length="80"> <object name="chatInput" size="16 12 100%-16 36" type="input" style="chatInput" max_length="80">
<action on="Press">submitChatInput();</action> <action on="Press">submitChatInput();</action>
</object> </object>
<object size="32 100%-44 144 100%-12" type="button" style="wheatButton"> <object size="32 100%-44 144 100%-12" type="button" style="wheatButton">
Cancel Cancel
<action on="Press">toggleChatWindow();</action> <action on="Press">closeChat();</action>
</object> </object>
<object size="100%-144 100%-44 100%-32 100%-12" type="button" style="wheatButton"> <object size="100%-144 100%-44 100%-32 100%-12" type="button" style="wheatButton">
Send Send
@ -215,49 +189,72 @@
</object> </object>
<!-- ================================ ================================ -->
<!-- Session Dialog -->
<!-- ================================ ================================ -->
<object name="sessionDialog"
sprite="genericPanel"
type="image"
size="50%-180 50%-200 50%+180 50%+50"
hidden="true"
z="30"
>
<object name="sessionDialogTitle" size="0 10 100% 36" type="text" style="largeBoldCenteredText">Title</object >
<object name="sessionDialogMessage" size="10 36 100%-10 100%-48" type="text" style="dialogText"/>
<object name="sessionDialogPanel" size="30 40 100%-30 100%-64" type="image"/>
<object size="0 100%-48 100% 100%">
<object name="sessionDialogConfirm" size="32 100%-44 144 100%-12" type="button" style="wheatButton">
OK
<action on="Press"></action>
</object>
<object name="sessionDialogCancel" size="100%-144 100%-44 100%-32 100%-12" type="button" style="wheatButton">
Cancel
<action on="Press">g_SessionDialog.close();</action>
</object>
</object>
</object>
<!-- ================================ ================================ --> <!-- ================================ ================================ -->
<!-- Menu --> <!-- Menu -->
<!-- ================================ ================================ --> <!-- ================================ ================================ -->
<object name="menuPanel" <object name="menuDialogPanel"
size="50%-74 50%-180 50%+74 50%+20" size="50%-74 50%-180 50%+74 50%+20"
type="image" type="image"
sprite="genericPanel"
hidden="true" hidden="true"
z="60" z="30"
> >
<object size="0 0 100% 32" type="text" style="largeBoldCenteredText">Menu</object > <!-- Settings button -->
<object type="button"
<object size="0 32 100% 100%"> name="settingsButton"
<!-- Settings button --> style="wheatButtonFancy"
<object type="button" size="50%-56 0 50%+56 32"
name="settingsButton" tooltip_style="snToolTip"
style="wheatButtonFancy" >
size="50%-60 0 50%+60 32" <object size="0 0 100% 100%" type="text" style="centeredText" name="settingsButtonText" ghost="true">Settings</object>
tooltip_style="snToolTip" <action on="Press">openSettingsDialog();</action>
> </object>
<object size="0 0 100% 100%" type="text" style="centeredText" name="settingsButtonText" ghost="true">Settings</object>
<action on="Press">toggleSettingsWindow();</action>
</object>
<!-- Chat button --> <!-- Chat button -->
<object type="button" <object type="button"
name="chatButton" name="chatButton"
style="wheatButtonFancy" style="wheatButtonFancy"
size="50%-60 32 50%+60 64" size="50%-56 32 50%+56 64"
tooltip_style="snToolTip" tooltip_style="snToolTip"
> >
<object size="0 0 100% 100%" type="text" style="centeredText" name="chatButtonText" ghost="true">Chat</object> <object size="0 0 100% 100%" type="text" style="centeredText" name="chatButtonText" ghost="true">Chat</object>
<action on="Press">toggleChatWindow();</action> <action on="Press">openChat();</action>
</object> </object>
<!-- Pause Button --> <!-- Pause Button -->
<object type="button" <object type="button"
style="wheatButtonFancy" style="wheatButtonFancy"
name="pauseButton" name="pauseButton"
size="50%-60 64 50%+60 96" size="50%-56 64 50%+56 96"
tooltip_style="snToolTip" tooltip_style="snToolTip"
> >
<object size="0 0 100% 100%" type="text" ghost="true" style="centeredText">Pause</object> <object name="pauseButtonText" size="0 0 100% 100%" type="text" ghost="true" style="centeredText">Pause</object>
<action on="Press">togglePause();</action> <action on="Press">togglePause();</action>
</object> </object>
@ -265,82 +262,50 @@
<object type="button" <object type="button"
name="menuExitButton" name="menuExitButton"
style="wheatButtonFancy" style="wheatButtonFancy"
size="50%-60 96 50%+60 128" size="50%-56 96 50%+56 128"
tooltip_style="snToolTip" tooltip_style="snToolTip"
> >
<object size="0 0 100% 100%" type="text" style="centeredText" name="exitButtonText" ghost="true" font="serif-14">Quit</object> <object size="0 0 100% 100%" type="text" style="centeredText" name="exitButtonText" ghost="true" font="serif-14">Quit</object>
<action on="Press"> <action on="Press">
toggleMenu();
openExitGameDialog(); openExitGameDialog();
</action> </action>
</object> </object>
<!-- Cancel Button -->
<object type="button"
style="wheatButtonFancy"
name="menuCancelButton"
size="50%-60 128 50%+60 160"
tooltip_style="snToolTip"
>
<object size="0 0 100% 100%" type="text" ghost="true" style="centeredText">Cancel</object>
<action on="Press">this.parent.parent.hidden=true;</action>
</object>
</object>
</object> </object>
<!-- ================================ ================================ --> <!-- ================================ ================================ -->
<!-- Settings Window --> <!-- Settings Window -->
<!-- ================================ ================================ --> <!-- ================================ ================================ -->
<object name="settingsWindow" <object name="settingsDialogPanel"
sprite="genericPanel" sprite="genericPanel"
type="image" type="image"
size="50%-180 50%-200 50%+180 50%+50" size="50%-180 50%-200 50%+180 50%+50"
hidden="true" hidden="true"
z="30"
> >
<object size="0 0 100% 32" type="text" style="largeBoldCenteredText">Settings</object > <!-- Settings / shadows -->
<object size="0 10 100%-80 35" type="text" style="settingsText" ghost="true">Enable Shadows</object>
<object name="settingsOptions" <object name="shadowsCheckbox" size="100%-56 15 100%-30 40" type="checkbox" style="wheatCrossBox" checked="true">
size="30 36 100%-30 180" <action on="Load">if (renderer.shadows) this.checked = true; else this.checked = false;</action>
type="image" <action on="Press">renderer.shadows = this.checked;</action>
sprite="genericPanel" </object>
>
<!-- Settings / shadows -->
<object size="0 10 100%-80 35" type="text" style="settingsText" ghost="true">Enable Shadows</object>
<object name="shadowsCheckbox" size="100%-56 15 100%-30 40" type="checkbox" style="wheatCrossBox" checked="true">
<action on="Load">if (renderer.shadows) this.checked = true; else this.checked = false;</action>
<action on="Press">renderer.shadows = this.checked;</action>
</object>
<!-- Settings / Water --> <!-- Settings / Water -->
<object size="0 35 100%-80 60" type="text" style="settingsText" ghost="true">Enable Water Reflections</object> <object size="0 35 100%-80 60" type="text" style="settingsText" ghost="true">Enable Water Reflections</object>
<object name="fancyWaterCheckbox" size="100%-56 40 100%-30 65" type="checkbox" style="wheatCrossBox" checked="true"> <object name="fancyWaterCheckbox" size="100%-56 40 100%-30 65" type="checkbox" style="wheatCrossBox" checked="true">
<action on="Load">if (renderer.fancyWater) this.checked = true; else this.checked = false;</action> <action on="Load">if (renderer.fancyWater) this.checked = true; else this.checked = false;</action>
<action on="Press">renderer.fancyWater = this.checked;</action> <action on="Press">renderer.fancyWater = this.checked;</action>
</object>
<!-- Settings / Music-->
<object size="0 60 100%-80 85" type="text" style="settingsText" ghost="true">Enable Music</object>
<object size="100%-56 65 100%-30 90" type="checkbox" style="wheatCrossBox" checked="true">
<action on="Press">if (this.checked) startMusic(); else stopMusic();</action>
</object>
<!-- Settings / Dev Overlay -->
<object size="0 85 100%-80 110" type="text" style="settingsText" ghost="true">Developer Overlay</object>
<object size="100%-56 90 100%-30 115" type="checkbox" style="wheatCrossBox" checked="false">
<action on="Press">toggleDeveloperOverlay();</action>
</object>
</object> </object>
<object name="settingsOKButton" <!-- Settings / Music-->
style="wheatButtonFancy" <object size="0 60 100%-80 85" type="text" style="settingsText" ghost="true">Enable Music</object>
type="button" <object size="100%-56 65 100%-30 90" type="checkbox" style="wheatCrossBox" checked="true">
size="50%-50 100%-52 50%+50 100%-20" <action on="Press">if (this.checked) startMusic(); else stopMusic();</action>
> </object>
<object size="0 0 100% 100%" type="text" style="centeredText" name="settingsOKButtonText" ghost="true">OK</object>
<action on="Press">toggleSettingsWindow();</action> <!-- Settings / Dev Overlay -->
<object size="0 85 100%-80 110" type="text" style="settingsText" ghost="true">Developer Overlay</object>
<object size="100%-56 90 100%-30 115" type="checkbox" style="wheatCrossBox" checked="false">
<action on="Press">toggleDeveloperOverlay();</action>
</object> </object>
</object> </object>
@ -409,7 +374,7 @@
tooltip_style="snToolTip" tooltip_style="snToolTip"
> >
<object size="0 0 100% 100%" type="image" sprite="menuButton" name="menuButtonText" ghost="true">MENU</object> <object size="0 0 100% 100%" type="image" sprite="menuButton" name="menuButtonText" ghost="true">MENU</object>
<action on="Press">toggleMenu();</action> <action on="Press">openMenuDialog();</action>
</object> <!-- END OF MENU --> </object> <!-- END OF MENU -->
</object> <!-- END OF TOP PANEL --> </object> <!-- END OF TOP PANEL -->

View File

@ -255,7 +255,9 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
else if (guiName == "Command") else if (guiName == "Command")
{ {
//icon.cell_id = i; //icon.cell_id = i;
icon.cell_id = getCommandCellId(item); //icon.cell_id = getCommandCellId(item);
icon.sprite = "stretched:session/icons/single/" + getCommandImage(item);
} }
else if (template.icon) else if (template.icon)
{ {

View File

@ -10,28 +10,34 @@ var g_SessionDialog = new SessionDialog();
function SessionDialog() function SessionDialog()
{ {
this.panel = {}; this.referencedPanel = {};
} }
SessionDialog.prototype.open = function(title, message, panel, x, y, confirmFunction) SessionDialog.prototype.open = function(title, message, referencedPanel, x, y, confirmFunction)
{ {
getGUIObjectByName("sessionDialogTitle").caption = title; // hide previous panel referencedPanel if applicable
if (this.referencedPanel)
this.referencedPanel.hidden = true
if (message) // set dialog title if applicable
getGUIObjectByName("sessionDialogMessage").caption = message; getGUIObjectByName("sessionDialogTitle").caption = title? title : "";
else
getGUIObjectByName("sessionDialogMessage").caption = "";
if(panel) // set dialog message if applicable
getGUIObjectByName("sessionDialogMessage").caption = message? message : "";
// set panel reference if applicable
if(referencedPanel)
{ {
this.panel = panel; referencedPanel.size = "50%-" + ((x/2)-30) + " 50%-" + ((y/2)-44) + " 50%+" + ((x/2)-30) + " 50%+" + ((y/2)-52);
panel.hidden = false; referencedPanel.hidden = false;
this.referencedPanel = referencedPanel;
} }
// set confirm function if applicable
if (confirmFunction) if (confirmFunction)
{ {
var buttonFunction = function () { var buttonFunction = function () {
this.close(panel); // "this" is defined as SessionDialog in this context this.close(referencedPanel); // "this" is defined as SessionDialog in this context
confirmFunction(); confirmFunction();
}; };
@ -41,14 +47,16 @@ SessionDialog.prototype.open = function(title, message, panel, x, y, confirmFunc
confirmButton.hidden = false; confirmButton.hidden = false;
confirmButton.size = "32 100%-44 144 100%-12"; confirmButton.size = "32 100%-44 144 100%-12";
getGUIObjectByName("sessionDialogCancel").size = "100%-144 100%-44 100%-32 100%-12"; getGUIObjectByName("sessionDialogCancel").size = "100%-144 100%-44 100%-32 100%-12";
getGUIObjectByName("sessionDialogCancel").caption = "Cancel";
} }
else else
{ {
getGUIObjectByName("sessionDialogConfirm").hidden = true; getGUIObjectByName("sessionDialogConfirm").hidden = true;
getGUIObjectByName("sessionDialogCancel").size = "50%-56 100%-44 50%+56 100%-12"; getGUIObjectByName("sessionDialogCancel").size = "50%-56 100%-44 50%+56 100%-12";
getGUIObjectByName("sessionDialogCancel").caption = "Close";
} }
getGUIObjectByName("sessionDialog").size = "50%-" + x + " 50%-" + y + " 50%+" + x + " 50%+" + y; getGUIObjectByName("sessionDialog").size = "50%-" + x/2 + " 50%-" + y/2 + " 50%+" + x/2 + " 50%+" + y/2;
getGUIObjectByName("sessionDialog").hidden = false; getGUIObjectByName("sessionDialog").hidden = false;
}; };
@ -56,8 +64,8 @@ SessionDialog.prototype.open = function(title, message, panel, x, y, confirmFunc
SessionDialog.prototype.close = function() SessionDialog.prototype.close = function()
{ {
getGUIObjectByName("sessionDialog").hidden = true; getGUIObjectByName("sessionDialog").hidden = true;
if (this.panel) if (this.referencedPanel)
this.panel.hidden = true; this.referencedPanel.hidden = true;
}; };
//-------------------------------- -------------------------------- -------------------------------- //-------------------------------- -------------------------------- --------------------------------
@ -243,16 +251,16 @@ function getFormationCellId(formationName)
} }
} }
function getCommandCellId(commandName) function getCommandImage(commandName)
{ {
switch (commandName) switch (commandName)
{ {
case "delete": case "delete":
return 1; return "kill_small.png";
case "unload-all": case "unload-all":
return 2; return "garrison.png";
default: default:
return -1; return "";
} }
} }