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)
{
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+"?";
var deleteFunction = deleteFunction = function ()
@ -871,7 +871,7 @@ function performCommand(entity, commandName)
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;
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()
{
var devCommands = getGUIObjectByName("devCommands");
var text = devCommands.hidden? "opened." : "closed.";
submitChatDirectly("The Developer Overlay was " + text);
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;
menu.hidden = true;
var settings = getGUIObjectByName("settingsDialogPanel");
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()
{
var chatWindow = getGUIObjectByName("chatDialogPanel");
var chatInput = getGUIObjectByName("chatInput");
if (chatWindow.hidden)
chatInput.focus(); // Grant focus to the input area
else
chatInput.caption = ""; // Clear chat input
chatWindow.hidden = !chatWindow.hidden;
menu.hidden = true;
g_SessionDialog.close();
}
function togglePause()
{
var pauseOverlay = getGUIObjectByName("pauseOverlay");
if (pauseOverlay.hidden)
{
setPaused(true);
getGUIObjectByName("pauseButtonText").caption = "Unpause";
}
else
{
setPaused(false);
getGUIObjectByName("pauseButtonText").caption = "Pause";
}
pauseOverlay.hidden = !pauseOverlay.hidden;
menu.hidden = true;
g_SessionDialog.close();
}
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()
{
if (!menu.hidden)
{
menu.hidden = true;
}
else if (!chatWindow.hidden)
{
chatWindow.hidden = true;
chatInput.caption = "";
}
else if (!settingsWindow.hidden)
{
settingsWindow.hidden = true;
console.write("test");
}
var sessionDialog = getGUIObjectByName("sessionDialog");
if (!sessionDialog.hidden)
g_SessionDialog.close();
else
getGUIObjectByName("chatDialogPanel").hidden = true;
}

View File

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

View File

@ -141,32 +141,6 @@
</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 -->
<!-- ================================ ================================ -->
@ -199,14 +173,14 @@
</object>
<!-- 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">
<action on="Press">submitChatInput();</action>
</object>
<object size="32 100%-44 144 100%-12" type="button" style="wheatButton">
Cancel
<action on="Press">toggleChatWindow();</action>
<action on="Press">closeChat();</action>
</object>
<object size="100%-144 100%-44 100%-32 100%-12" type="button" style="wheatButton">
Send
@ -215,49 +189,72 @@
</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 -->
<!-- ================================ ================================ -->
<object name="menuPanel"
<object name="menuDialogPanel"
size="50%-74 50%-180 50%+74 50%+20"
type="image"
sprite="genericPanel"
hidden="true"
z="60"
z="30"
>
<object size="0 0 100% 32" type="text" style="largeBoldCenteredText">Menu</object >
<object size="0 32 100% 100%">
<!-- Settings button -->
<object type="button"
name="settingsButton"
style="wheatButtonFancy"
size="50%-60 0 50%+60 32"
tooltip_style="snToolTip"
>
<object size="0 0 100% 100%" type="text" style="centeredText" name="settingsButtonText" ghost="true">Settings</object>
<action on="Press">toggleSettingsWindow();</action>
</object>
<!-- Settings button -->
<object type="button"
name="settingsButton"
style="wheatButtonFancy"
size="50%-56 0 50%+56 32"
tooltip_style="snToolTip"
>
<object size="0 0 100% 100%" type="text" style="centeredText" name="settingsButtonText" ghost="true">Settings</object>
<action on="Press">openSettingsDialog();</action>
</object>
<!-- Chat button -->
<object type="button"
name="chatButton"
style="wheatButtonFancy"
size="50%-60 32 50%+60 64"
size="50%-56 32 50%+56 64"
tooltip_style="snToolTip"
>
<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>
<!-- Pause Button -->
<object type="button"
style="wheatButtonFancy"
name="pauseButton"
size="50%-60 64 50%+60 96"
size="50%-56 64 50%+56 96"
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>
</object>
@ -265,82 +262,50 @@
<object type="button"
name="menuExitButton"
style="wheatButtonFancy"
size="50%-60 96 50%+60 128"
size="50%-56 96 50%+56 128"
tooltip_style="snToolTip"
>
<object size="0 0 100% 100%" type="text" style="centeredText" name="exitButtonText" ghost="true" font="serif-14">Quit</object>
<action on="Press">
toggleMenu();
openExitGameDialog();
</action>
</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>
<!-- ================================ ================================ -->
<!-- Settings Window -->
<!-- ================================ ================================ -->
<object name="settingsWindow"
<object name="settingsDialogPanel"
sprite="genericPanel"
type="image"
size="50%-180 50%-200 50%+180 50%+50"
hidden="true"
z="30"
>
<object size="0 0 100% 32" type="text" style="largeBoldCenteredText">Settings</object >
<object name="settingsOptions"
size="30 36 100%-30 180"
type="image"
sprite="genericPanel"
>
<!-- 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 / 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 -->
<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">
<action on="Load">if (renderer.fancyWater) this.checked = true; else this.checked = false;</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>
<!-- Settings / Water -->
<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">
<action on="Load">if (renderer.fancyWater) this.checked = true; else this.checked = false;</action>
<action on="Press">renderer.fancyWater = this.checked;</action>
</object>
<object name="settingsOKButton"
style="wheatButtonFancy"
type="button"
size="50%-50 100%-52 50%+50 100%-20"
>
<object size="0 0 100% 100%" type="text" style="centeredText" name="settingsOKButtonText" ghost="true">OK</object>
<action on="Press">toggleSettingsWindow();</action>
<!-- 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>
@ -409,7 +374,7 @@
tooltip_style="snToolTip"
>
<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 TOP PANEL -->

View File

@ -255,7 +255,9 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
else if (guiName == "Command")
{
//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)
{

View File

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