Overhaul save panel.

This commit is contained in:
Paul Chote
2015-05-17 10:54:55 +01:00
parent 445c0d76a2
commit 60f96fcb7b
4 changed files with 207 additions and 174 deletions

View File

@@ -20,24 +20,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public class SaveMapLogic public class SaveMapLogic
{ {
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public SaveMapLogic(Widget widget, Action onExit, World world) public SaveMapLogic(Widget widget, Action onExit, Map map, EditorActorLayer editorActorLayer)
{ {
var newMap = world.Map; var title = widget.Get<TextFieldWidget>("TITLE");
title.Text = map.Title;
var title = widget.GetOrNull<TextFieldWidget>("TITLE"); var author = widget.Get<TextFieldWidget>("AUTHOR");
if (title != null) author.Text = map.Author;
title.Text = newMap.Title;
var description = widget.GetOrNull<TextFieldWidget>("DESCRIPTION"); // TODO: This should use a multi-line textfield once they exist
if (description != null) var description = widget.Get<TextFieldWidget>("DESCRIPTION");
description.Text = newMap.Description; description.Text = map.Description;
var author = widget.GetOrNull<TextFieldWidget>("AUTHOR"); // TODO: This should use a multi-selection dropdown once they exist
if (author != null) var visibilityDropdown = widget.Get<DropDownButtonWidget>("VISIBILITY_DROPDOWN");
author.Text = newMap.Author;
var visibilityDropdown = widget.GetOrNull<DropDownButtonWidget>("CLASS_DROPDOWN");
if (visibilityDropdown != null)
{ {
var mapVisibility = new List<string>(Enum.GetNames(typeof(MapVisibility))); var mapVisibility = new List<string>(Enum.GetNames(typeof(MapVisibility)));
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
@@ -48,75 +44,98 @@ namespace OpenRA.Mods.Common.Widgets.Logic
item.Get<LabelWidget>("LABEL").GetText = () => option; item.Get<LabelWidget>("LABEL").GetText = () => option;
return item; return item;
}; };
visibilityDropdown.Text = Enum.GetName(typeof(MapVisibility), newMap.Visibility);
visibilityDropdown.Text = Enum.GetName(typeof(MapVisibility), map.Visibility);
visibilityDropdown.OnClick = () => visibilityDropdown.OnClick = () =>
visibilityDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapVisibility, setupItem); visibilityDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapVisibility, setupItem);
} }
var pathDropdown = widget.GetOrNull<DropDownButtonWidget>("PATH_DROPDOWN"); var directoryDropdown = widget.Get<DropDownButtonWidget>("DIRECTORY_DROPDOWN");
if (pathDropdown != null)
{ {
var mapFolders = new List<string>(); var mapDirectories = Game.ModData.Manifest.MapFolders.Keys.Select(ff =>
foreach (var mapFolder in Game.ModData.Manifest.MapFolders.Keys)
{ {
var folder = mapFolder; var f = Platform.UnresolvePath(ff);
if (mapFolder.StartsWith("~")) if (f.StartsWith("~"))
folder = mapFolder.Substring(1); f = f.Substring(1);
mapFolders.Add(Platform.ResolvePath(folder)); return f;
} }).ToList();
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{ {
var item = ScrollItemWidget.Setup(template, var item = ScrollItemWidget.Setup(template,
() => pathDropdown.Text == Platform.UnresolvePath(option), () => directoryDropdown.Text == option,
() => { pathDropdown.Text = Platform.UnresolvePath(option); }); () => directoryDropdown.Text = option);
item.Get<LabelWidget>("LABEL").GetText = () => option; item.Get<LabelWidget>("LABEL").GetText = () => option;
return item; return item;
}; };
var userMapFolder = Game.ModData.Manifest.MapFolders.First(f => f.Value == "User").Key; var mapDirectory = Platform.UnresolvePath(Path.GetDirectoryName(map.Path));
if (userMapFolder.StartsWith("~")) var initialDirectory = mapDirectories.FirstOrDefault(f => f == mapDirectory);
userMapFolder = userMapFolder.Substring(1);
pathDropdown.Text = Platform.UnresolvePath(userMapFolder); if (initialDirectory == null)
pathDropdown.OnClick = () => initialDirectory = mapDirectories.First();
pathDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapFolders, setupItem);
directoryDropdown.Text = initialDirectory;
directoryDropdown.OnClick = () =>
directoryDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapDirectories, setupItem);
} }
var filename = widget.GetOrNull<TextFieldWidget>("FILENAME"); var filename = widget.Get<TextFieldWidget>("FILENAME");
if (filename != null) filename.Text = Path.GetFileNameWithoutExtension(map.Path);
filename.Text = Path.GetFileName(world.Map.Path);
var close = widget.GetOrNull<ButtonWidget>("CLOSE"); var fileTypes = new Dictionary<string, string>()
if (close != null) {
{ ".oramap", ".oramap" },
{ "(unpacked)", "" }
};
var typeDropdown = widget.Get<DropDownButtonWidget>("TYPE_DROPDOWN");
{
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
{
var item = ScrollItemWidget.Setup(template,
() => typeDropdown.Text == option,
() => typeDropdown.Text = option);
item.Get<LabelWidget>("LABEL").GetText = () => option;
return item;
};
typeDropdown.Text = Path.GetExtension(map.Path);
if (string.IsNullOrEmpty(typeDropdown.Text))
typeDropdown.Text = fileTypes.First(t => t.Value == "").Key;
typeDropdown.OnClick = () =>
typeDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, fileTypes.Keys, setupItem);
}
var close = widget.Get<ButtonWidget>("BACK_BUTTON");
close.OnClick = () => { Ui.CloseWindow(); onExit(); }; close.OnClick = () => { Ui.CloseWindow(); onExit(); };
var save = widget.GetOrNull<ButtonWidget>("SAVE"); var save = widget.Get<ButtonWidget>("SAVE_BUTTON");
if (save != null && !string.IsNullOrEmpty(filename.Text))
{
var editorLayer = world.WorldActor.Trait<EditorActorLayer>();
save.OnClick = () => save.OnClick = () =>
{ {
newMap.Title = title.Text; if (string.IsNullOrEmpty(filename.Text))
newMap.Description = description.Text; return;
newMap.Author = author.Text;
newMap.Visibility = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text);
newMap.ActorDefinitions = editorLayer.Save();
newMap.PlayerDefinitions = editorLayer.Players.ToMiniYaml();
newMap.RequiresMod = Game.ModData.Manifest.Mod.Id;
var combinedPath = Path.Combine(pathDropdown.Text, filename.Text); map.Title = title.Text;
var resolvedPath = Platform.ResolvePath(combinedPath); map.Description = description.Text;
newMap.Save(resolvedPath); map.Author = author.Text;
map.Visibility = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text);
map.ActorDefinitions = editorActorLayer.Save();
map.PlayerDefinitions = editorActorLayer.Players.ToMiniYaml();
map.RequiresMod = Game.ModData.Manifest.Mod.Id;
var combinedPath = Platform.ResolvePath(Path.Combine(directoryDropdown.Text, filename.Text + fileTypes[typeDropdown.Text]));
map.Save(combinedPath);
// Update the map cache so it can be loaded without restarting the game // Update the map cache so it can be loaded without restarting the game
Game.ModData.MapCache[newMap.Uid].UpdateFromMap(newMap, MapClassification.User); Game.ModData.MapCache[map.Uid].UpdateFromMap(map, MapClassification.User);
Console.WriteLine("Saved current map at {0}", resolvedPath); Console.WriteLine("Saved current map at {0}", combinedPath);
Ui.CloseWindow(); Ui.CloseWindow();
onExit(); onExit();
}; };
} }
} }
}
} }

View File

@@ -101,10 +101,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
saveMapButton.IsVisible = () => world.Type == WorldType.Editor; saveMapButton.IsVisible = () => world.Type == WorldType.Editor;
saveMapButton.OnClick = () => saveMapButton.OnClick = () =>
{ {
hideMenu = true;
Ui.OpenWindow("SAVE_MAP_PANEL", new WidgetArgs() Ui.OpenWindow("SAVE_MAP_PANEL", new WidgetArgs()
{ {
{ "onExit", () => widget.Visible = true }, { "onExit", () => hideMenu = false },
{ "world", world }, { "map", world.Map },
{ "editorActorLayer", world.WorldActor.Trait<EditorActorLayer>() }
}); });
}; };

View File

@@ -74,13 +74,14 @@ Container@NEW_MAP_BG:
Key: return Key: return
Container@SAVE_MAP_PANEL: Background@SAVE_MAP_PANEL:
Logic: SaveMapLogic
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 350 Width: 345
Height: 330 Height: 264
Children: Children:
Label@TITLE: Label@LABEL_TITLE:
Text: Save Map Text: Save Map
Width: PARENT_RIGHT Width: PARENT_RIGHT
Y: 0-25 Y: 0-25
@@ -88,97 +89,103 @@ Container@SAVE_MAP_PANEL:
Contrast: true Contrast: true
Align: Center Align: Center
Background@SAVE_MAP_BACKGROUND: Background@SAVE_MAP_BACKGROUND:
Logic: SaveMapLogic
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 295 Height: 230
Background: panel-black Background: panel-black
Children: Children:
Label@TITLE_LABEL: Label@TITLE_LABEL:
X: 10 X: 10
Y: 39 Y: 14
Width: 95 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Title: Text: Title:
TextField@TITLE: TextField@TITLE:
X: 110 X: 110
Y: 40 Y: 15
Width: 210 Width: 220
MaxLength: 50
Height: 25
Label@DESCRIPTION_LABEL:
X: 10
Y: 79
Width: 95
Height: 25
Align: Right
Text: Description:
TextField@DESCRIPTION:
X: 110
Y: 80
Width: 210
MaxLength: 50 MaxLength: 50
Height: 25 Height: 25
Label@AUTHOR_LABEL: Label@AUTHOR_LABEL:
X: 10 X: 10
Y: 119 Y: 49
Width: 95 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Author: Text: Author:
TextField@AUTHOR: TextField@AUTHOR:
X: 110 X: 110
Y: 120 Y: 50
Width: 210 Width: 220
MaxLength: 50 MaxLength: 50
Height: 25 Height: 25
Label@CLASS_LABEL: Label@DESCRIPTION_LABEL:
X: 10 X: 10
Y: 160 Y: 84
Width: 95 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Class: Text: Description:
DropDownButton@CLASS_DROPDOWN: TextField@DESCRIPTION:
X: 110 X: 110
Y: 160 Y: 85
Width: 210 Width: 220
MaxLength: 50
Height: 25 Height: 25
Label@PATH_LABEL: Label@VISIBILITY_LABEL:
X: 10 X: 10
Y: 199 Y: 119
Width: 40 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Path: Text: Visibility:
DropDownButton@PATH_DROPDOWN: DropDownButton@VISIBILITY_DROPDOWN:
X: 60 X: 110
Y: 200 Y: 120
Width: 270 Width: 220
Height: 25 Height: 25
Font: Regular
Label@DIRECTORY_LABEL:
X: 10
Y: 154
Width: 95
Height: 25
Align: Right
Text: Directory:
DropDownButton@DIRECTORY_DROPDOWN:
X: 110
Y: 155
Width: 220
Height: 25
Font: Regular
Label@FILENAME_LABEL: Label@FILENAME_LABEL:
X: 10 X: 10
Y: 239 Y: 189
Width: 40 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: File: Text: Filename:
TextField@FILENAME: TextField@FILENAME:
X: 60 X: 110
Y: 240 Y: 190
Width: 270 Width: 105
Height: 25 Height: 25
Button@CLOSE: DropDownButton@TYPE_DROPDOWN:
X: 0 X: 220
Y: 294 Y: 190
Width: 110
Height: 25
Font: Regular
Button@BACK_BUTTON:
Y: PARENT_BOTTOM - 35
Width: 140 Width: 140
Height: 35 Height: 35
Text: Close Text: Cancel
Font: Bold Font: Bold
Key: escape Key: escape
Button@SAVE: Button@SAVE_BUTTON:
X: PARENT_RIGHT - WIDTH X: PARENT_RIGHT - 140
Y: 294 Y: PARENT_BOTTOM - 35
Width: 140 Width: 140
Height: 35 Height: 35
Text: Save Text: Save

View File

@@ -75,7 +75,7 @@ Background@SAVE_MAP_PANEL:
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 350 Width: 350
Height: 350 Height: 335
Children: Children:
Label@LABEL_TITLE: Label@LABEL_TITLE:
X: (PARENT_RIGHT - WIDTH)/2 X: (PARENT_RIGHT - WIDTH)/2
@@ -95,86 +95,91 @@ Background@SAVE_MAP_PANEL:
TextField@TITLE: TextField@TITLE:
X: 110 X: 110
Y: 60 Y: 60
Width: 210 Width: 220
MaxLength: 50
Height: 25
Label@DESCRIPTION_LABEL:
X: 10
Y: 99
Width: 95
Height: 25
Align: Right
Text: Description:
TextField@DESCRIPTION:
X: 110
Y: 100
Width: 210
MaxLength: 50 MaxLength: 50
Height: 25 Height: 25
Label@AUTHOR_LABEL: Label@AUTHOR_LABEL:
X: 10 X: 10
Y: 139 Y: 94
Width: 95 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Author: Text: Author:
TextField@AUTHOR: TextField@AUTHOR:
X: 110 X: 110
Y: 140 Y: 95
Width: 210 Width: 220
MaxLength: 50 MaxLength: 50
Height: 25 Height: 25
Label@CLASS_LABEL: Label@DESCRIPTION_LABEL:
X: 10 X: 10
Y: 180 Y: 129
Width: 95 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Class: Text: Description:
DropDownButton@CLASS_DROPDOWN: TextField@DESCRIPTION:
X: 110 X: 110
Y: 180 Y: 130
Width: 210 Width: 220
MaxLength: 50
Height: 25 Height: 25
Label@PATH_LABEL: Label@VISIBILITY_LABEL:
X: 10 X: 10
Y: 219 Y: 164
Width: 40 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: Path: Text: Visibility:
DropDownButton@PATH_DROPDOWN: DropDownButton@VISIBILITY_DROPDOWN:
X: 60 X: 110
Y: 220 Y: 165
Width: 270 Width: 220
Height: 25
Label@DIRECTORY_LABEL:
X: 10
Y: 199
Width: 95
Height: 25
Align: Right
Text: Directory:
DropDownButton@DIRECTORY_DROPDOWN:
X: 110
Y: 200
Width: 220
Height: 25 Height: 25
Label@FILENAME_LABEL: Label@FILENAME_LABEL:
X: 10 X: 10
Y: 259 Y: 234
Width: 40 Width: 95
Height: 25 Height: 25
Align: Right Align: Right
Text: File: Text: Filename:
TextField@FILENAME: TextField@FILENAME:
X: 60 X: 110
Y: 260 Y: 235
Width: 270 Width: 105
Height: 25 Height: 25
Button@CLOSE: DropDownButton@TYPE_DROPDOWN:
X: 30 X: 220
Y: 300 Y: 235
Width: 100 Width: 110
Height: 25 Height: 25
Text: Close Button@SAVE_BUTTON:
Font: Bold X: 80
Key: escape Y: PARENT_BOTTOM - 45
Button@SAVE: Width: 120
X: 210
Y: 300
Width: 100
Height: 25 Height: 25
Text: Save Text: Save
Font: Bold Font: Bold
Button@BACK_BUTTON:
X: 210
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Text: Cancel
Font: Bold
Key: escape
Container@EDITOR_ROOT: Container@EDITOR_ROOT:
Logic: LoadMapEditorLogic Logic: LoadMapEditorLogic