Allow saving maps with multiple visibility options
This commit is contained in:
@@ -52,24 +52,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var author = widget.Get<TextFieldWidget>("AUTHOR");
|
||||
author.Text = map.Author;
|
||||
|
||||
// TODO: This should use a multi-selection dropdown once they exist
|
||||
var visibilityDropdown = widget.Get<DropDownButtonWidget>("VISIBILITY_DROPDOWN");
|
||||
{
|
||||
var mapVisibility = new List<string>(Enum.GetNames(typeof(MapVisibility)));
|
||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template,
|
||||
() => visibilityDropdown.Text == option,
|
||||
() => { visibilityDropdown.Text = option; });
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option;
|
||||
return item;
|
||||
};
|
||||
var visibilityPanel = Ui.LoadWidget("MAP_SAVE_VISIBILITY_PANEL", null, new WidgetArgs());
|
||||
var visOptionTemplate = visibilityPanel.Get<CheckboxWidget>("VISIBILITY_TEMPLATE");
|
||||
visibilityPanel.RemoveChildren();
|
||||
|
||||
visibilityDropdown.Text = Enum.GetName(typeof(MapVisibility), map.Visibility);
|
||||
visibilityDropdown.OnClick = () =>
|
||||
visibilityDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 210, mapVisibility, setupItem);
|
||||
foreach (MapVisibility visibilityOption in Enum.GetValues(typeof(MapVisibility)))
|
||||
{
|
||||
// To prevent users from breaking the game only show the 'Shellmap' option when it is already set.
|
||||
if (visibilityOption == MapVisibility.Shellmap && !map.Visibility.HasFlag(visibilityOption))
|
||||
continue;
|
||||
|
||||
var checkbox = (CheckboxWidget)visOptionTemplate.Clone();
|
||||
checkbox.GetText = () => visibilityOption.ToString();
|
||||
checkbox.IsChecked = () => map.Visibility.HasFlag(visibilityOption);
|
||||
checkbox.OnClick = () => map.Visibility ^= visibilityOption;
|
||||
visibilityPanel.AddChild(checkbox);
|
||||
}
|
||||
|
||||
var visibilityDropdown = widget.Get<DropDownButtonWidget>("VISIBILITY_DROPDOWN");
|
||||
visibilityDropdown.OnMouseDown = _ =>
|
||||
{
|
||||
visibilityDropdown.RemovePanel();
|
||||
visibilityDropdown.AttachPanel(visibilityPanel);
|
||||
};
|
||||
|
||||
var writableDirectories = new List<SaveDirectory>();
|
||||
SaveDirectory selectedDirectory = null;
|
||||
|
||||
@@ -157,7 +163,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
map.Title = title.Text;
|
||||
map.Author = author.Text;
|
||||
map.Visibility = (MapVisibility)Enum.Parse(typeof(MapVisibility), visibilityDropdown.Text);
|
||||
|
||||
if (actorDefinitions != null)
|
||||
map.ActorDefinitions = actorDefinitions;
|
||||
|
||||
@@ -134,6 +134,7 @@ Background@SAVE_MAP_PANEL:
|
||||
Y: 85
|
||||
Width: 220
|
||||
Height: 25
|
||||
Text: Map Visibility
|
||||
Font: Regular
|
||||
Label@DIRECTORY_LABEL:
|
||||
X: 10
|
||||
@@ -181,6 +182,16 @@ Background@SAVE_MAP_PANEL:
|
||||
Text: Save
|
||||
Font: Bold
|
||||
|
||||
ScrollPanel@MAP_SAVE_VISIBILITY_PANEL:
|
||||
Width: 220
|
||||
Height: 64
|
||||
Children:
|
||||
Checkbox@VISIBILITY_TEMPLATE:
|
||||
X: 5
|
||||
Width: PARENT_RIGHT - 29
|
||||
Height: 20
|
||||
Font: Regular
|
||||
|
||||
Container@EDITOR_ROOT:
|
||||
Logic: LoadMapEditorLogic
|
||||
Children:
|
||||
|
||||
@@ -127,6 +127,7 @@ Background@SAVE_MAP_PANEL:
|
||||
Y: 130
|
||||
Width: 220
|
||||
Height: 25
|
||||
Text: Map Visibility
|
||||
Label@DIRECTORY_LABEL:
|
||||
X: 10
|
||||
Y: 164
|
||||
@@ -172,6 +173,16 @@ Background@SAVE_MAP_PANEL:
|
||||
Font: Bold
|
||||
Key: escape
|
||||
|
||||
ScrollPanel@MAP_SAVE_VISIBILITY_PANEL:
|
||||
Width: 220
|
||||
Height: 64
|
||||
Children:
|
||||
Checkbox@VISIBILITY_TEMPLATE:
|
||||
X: 5
|
||||
Width: PARENT_RIGHT - 29
|
||||
Height: 20
|
||||
Font: Regular
|
||||
|
||||
Container@EDITOR_ROOT:
|
||||
Logic: LoadMapEditorLogic
|
||||
Children:
|
||||
|
||||
Reference in New Issue
Block a user