|
|
@@ -1,5 +1,4 @@
|
|
|
// Urho3D editor UI-element handling
|
|
|
-
|
|
|
UIElement@ editorUIElement;
|
|
|
XMLFile@ uiElementDefaultStyle;
|
|
|
Array<String> availableStyles;
|
|
|
@@ -99,20 +98,23 @@ void OpenUILayout(const String&in fileName)
|
|
|
// Check if the UI element has been opened before
|
|
|
if (editorUIElement.GetChild(FILENAME_VAR, Variant(fileName)) !is null)
|
|
|
{
|
|
|
- log.Warning("UI element is already opened: " + fileName);
|
|
|
+ MessageBox("UI element is already opened.\n" + fileName);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Always load from the filesystem, not from resource paths
|
|
|
if (!fileSystem.FileExists(fileName))
|
|
|
{
|
|
|
- log.Error("No such file: " + fileName);
|
|
|
+ MessageBox("No such file.\n" + fileName);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
File file(fileName, FILE_READ);
|
|
|
if (!file.open)
|
|
|
+ {
|
|
|
+ MessageBox("Could not open file.\n" + fileName);
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
// Add the UI layout's resource path in case it's necessary
|
|
|
SetResourcePath(GetPath(fileName), true, true);
|
|
|
@@ -141,6 +143,8 @@ void OpenUILayout(const String&in fileName)
|
|
|
|
|
|
ClearEditActions();
|
|
|
}
|
|
|
+ else
|
|
|
+ MessageBox("Could not load UI layout successfully!\nSee Urho3D.log for more detail.");
|
|
|
|
|
|
suppressUIElementChanges = false;
|
|
|
}
|
|
|
@@ -149,6 +153,26 @@ bool CloseUILayout()
|
|
|
{
|
|
|
ui.cursor.shape = CS_BUSY;
|
|
|
|
|
|
+ if (messageBoxCallback is null)
|
|
|
+ {
|
|
|
+ for (uint i = 0; i < selectedUIElements.length; ++i)
|
|
|
+ {
|
|
|
+ UIElement@ element = GetTopLevelUIElement(selectedUIElements[i]);
|
|
|
+ if (element !is null && element.vars[MODIFIED_VAR].GetBool())
|
|
|
+ {
|
|
|
+ uiMessageBox = MessageBox("UI layout has been modified.\nContinue to close?", "Warning");
|
|
|
+ Button@ cancelButton = uiMessageBox.window.GetChild("CancelButton", true);
|
|
|
+ cancelButton.visible = true;
|
|
|
+ cancelButton.focus = true;
|
|
|
+ SubscribeToEvent(uiMessageBox, "MessageACK", "HandleMessageAcknowledgement");
|
|
|
+ messageBoxCallback = @CloseUILayout;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ messageBoxCallback = null;
|
|
|
+
|
|
|
suppressUIElementChanges = true;
|
|
|
|
|
|
for (uint i = 0; i < selectedUIElements.length; ++i)
|
|
|
@@ -172,6 +196,26 @@ bool CloseAllUILayouts()
|
|
|
{
|
|
|
ui.cursor.shape = CS_BUSY;
|
|
|
|
|
|
+ if (messageBoxCallback is null)
|
|
|
+ {
|
|
|
+ for (uint i = 0; i < editorUIElement.numChildren; ++i)
|
|
|
+ {
|
|
|
+ UIElement@ element = editorUIElement.children[i];
|
|
|
+ if (element !is null && element.vars[MODIFIED_VAR].GetBool())
|
|
|
+ {
|
|
|
+ uiMessageBox = MessageBox("UI layout has been modified.\nContinue to close?", "Warning");
|
|
|
+ Button@ cancelButton = uiMessageBox.window.GetChild("CancelButton", true);
|
|
|
+ cancelButton.visible = true;
|
|
|
+ cancelButton.focus = true;
|
|
|
+ SubscribeToEvent(uiMessageBox, "MessageACK", "HandleMessageAcknowledgement");
|
|
|
+ messageBoxCallback = @CloseAllUILayouts;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ messageBoxCallback = null;
|
|
|
+
|
|
|
suppressUIElementChanges = true;
|
|
|
|
|
|
editorUIElement.RemoveAllChildren();
|
|
|
@@ -197,7 +241,10 @@ bool SaveUILayout(const String&in fileName)
|
|
|
|
|
|
File file(fileName, FILE_WRITE);
|
|
|
if (!file.open)
|
|
|
+ {
|
|
|
+ MessageBox("Could not open file.\n" + fileName);
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
UIElement@ element = GetTopLevelUIElement(editUIElement);
|
|
|
if (element is null)
|
|
|
@@ -246,13 +293,16 @@ void LoadChildUIElement(const String&in fileName)
|
|
|
|
|
|
if (!fileSystem.FileExists(fileName))
|
|
|
{
|
|
|
- log.Error("No such file: " + fileName);
|
|
|
+ MessageBox("No such file.\n" + fileName);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
File file(fileName, FILE_READ);
|
|
|
if (!file.open)
|
|
|
+ {
|
|
|
+ MessageBox("Could not open file.\n" + fileName);
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
XMLFile@ xmlFile = XMLFile();
|
|
|
xmlFile.Load(file);
|
|
|
@@ -294,7 +344,10 @@ bool SaveChildUIElement(const String&in fileName)
|
|
|
|
|
|
File file(fileName, FILE_WRITE);
|
|
|
if (!file.open)
|
|
|
+ {
|
|
|
+ MessageBox("Could not open file.\n" + fileName);
|
|
|
return false;
|
|
|
+ }
|
|
|
|
|
|
XMLFile@ elementData = XMLFile();
|
|
|
XMLElement rootElem = elementData.CreateRoot("element");
|
|
|
@@ -322,13 +375,16 @@ void SetUIElementDefaultStyle(const String&in fileName)
|
|
|
// Always load from the filesystem, not from resource paths
|
|
|
if (!fileSystem.FileExists(fileName))
|
|
|
{
|
|
|
- log.Error("No such file: " + fileName);
|
|
|
+ MessageBox("No such file.\n" + fileName);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
File file(fileName, FILE_READ);
|
|
|
if (!file.open)
|
|
|
+ {
|
|
|
+ MessageBox("Could not open file.\n" + fileName);
|
|
|
return;
|
|
|
+ }
|
|
|
|
|
|
uiElementDefaultStyle = XMLFile();
|
|
|
uiElementDefaultStyle.Load(file);
|