Expose common actor Inits in the map editor.
This commit is contained in:
@@ -31,14 +31,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly LabelWidget typeLabel;
|
||||
readonly TextFieldWidget actorIDField;
|
||||
readonly LabelWidget actorIDErrorLabel;
|
||||
readonly DropDownButtonWidget ownersDropDown;
|
||||
|
||||
readonly Widget initContainer;
|
||||
readonly Widget buttonContainer;
|
||||
|
||||
readonly Widget sliderOptionTemplate;
|
||||
readonly Widget dropdownOptionTemplate;
|
||||
|
||||
readonly int editPanelPadding; // Padding between right edge of actor and the edit panel.
|
||||
readonly long scrollVisibleTimeout = 100; // Delay after scrolling map before edit widget becomes visible again.
|
||||
long lastScrollTime = 0;
|
||||
PlayerReference selectedOwner;
|
||||
|
||||
ActorIDStatus actorIDStatus = ActorIDStatus.Normal;
|
||||
ActorIDStatus nextActorIDStatus = ActorIDStatus.Normal;
|
||||
@@ -78,11 +80,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
typeLabel = actorEditPanel.Get<LabelWidget>("ACTOR_TYPE_LABEL");
|
||||
actorIDField = actorEditPanel.Get<TextFieldWidget>("ACTOR_ID");
|
||||
|
||||
ownersDropDown = actorEditPanel.Get<DropDownButtonWidget>("OWNERS_DROPDOWN");
|
||||
|
||||
initContainer = actorEditPanel.Get("ACTOR_INIT_CONTAINER");
|
||||
buttonContainer = actorEditPanel.Get("BUTTON_CONTAINER");
|
||||
|
||||
sliderOptionTemplate = initContainer.Get("SLIDER_OPTION_TEMPLATE");
|
||||
dropdownOptionTemplate = initContainer.Get("DROPDOWN_OPTION_TEMPLATE");
|
||||
initContainer.RemoveChildren();
|
||||
|
||||
var deleteButton = actorEditPanel.Get<ButtonWidget>("DELETE_BUTTON");
|
||||
var closeButton = actorEditPanel.Get<ButtonWidget>("CLOSE_BUTTON");
|
||||
|
||||
@@ -137,34 +141,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (actorIDStatus != ActorIDStatus.Normal)
|
||||
SetActorID(world, initialActorID);
|
||||
};
|
||||
|
||||
// Setup owners drop down
|
||||
selectedOwner = editorActorLayer.Players.Players.Values.First();
|
||||
Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () =>
|
||||
{
|
||||
ownersDropDown.Text = option.Name;
|
||||
ownersDropDown.TextColor = option.Color.RGB;
|
||||
selectedOwner = option;
|
||||
|
||||
CurrentActor.Owner = selectedOwner;
|
||||
CurrentActor.ReplaceInit(new OwnerInit(selectedOwner.Name));
|
||||
});
|
||||
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
|
||||
item.GetColor = () => option.Color.RGB;
|
||||
return item;
|
||||
};
|
||||
|
||||
ownersDropDown.OnClick = () =>
|
||||
{
|
||||
var owners = editorActorLayer.Players.Players.Values.OrderBy(p => p.Name);
|
||||
ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
|
||||
};
|
||||
|
||||
ownersDropDown.Text = selectedOwner.Name;
|
||||
ownersDropDown.TextColor = selectedOwner.Color.RGB;
|
||||
}
|
||||
|
||||
void SetActorID(World world, string actorId)
|
||||
@@ -206,10 +182,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (CurrentActor != actor)
|
||||
{
|
||||
lastScrollTime = 0; // Ensure visible
|
||||
selectedOwner = actor.Owner;
|
||||
ownersDropDown.Text = selectedOwner.Name;
|
||||
ownersDropDown.TextColor = selectedOwner.Color.RGB;
|
||||
|
||||
CurrentActor = actor;
|
||||
|
||||
initialActorID = actorIDField.Text = actor.ID;
|
||||
@@ -222,6 +194,96 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
actorSelectBorder.Bounds.Width = actor.Bounds.Width * 2;
|
||||
actorSelectBorder.Bounds.Height = actor.Bounds.Height * 2;
|
||||
nextActorIDStatus = ActorIDStatus.Normal;
|
||||
|
||||
// Remove old widgets
|
||||
var oldInitHeight = initContainer.Bounds.Height;
|
||||
initContainer.Bounds.Height = 0;
|
||||
initContainer.RemoveChildren();
|
||||
|
||||
// Add owner dropdown
|
||||
var ownerContainer = dropdownOptionTemplate.Clone();
|
||||
ownerContainer.Get<LabelWidget>("LABEL").GetText = () => "Owner";
|
||||
var ownerDropdown = ownerContainer.Get<DropDownButtonWidget>("OPTION");
|
||||
var selectedOwner = actor.Owner;
|
||||
|
||||
Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () =>
|
||||
{
|
||||
selectedOwner = option;
|
||||
CurrentActor.Owner = selectedOwner;
|
||||
CurrentActor.ReplaceInit(new OwnerInit(selectedOwner.Name));
|
||||
});
|
||||
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
|
||||
item.GetColor = () => option.Color.RGB;
|
||||
return item;
|
||||
};
|
||||
|
||||
ownerDropdown.GetText = () => selectedOwner.Name;
|
||||
ownerDropdown.GetColor = () => selectedOwner.Color.RGB;
|
||||
ownerDropdown.OnClick = () =>
|
||||
{
|
||||
var owners = editorActorLayer.Players.Players.Values.OrderBy(p => p.Name);
|
||||
ownerDropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
|
||||
};
|
||||
|
||||
initContainer.Bounds.Height += ownerContainer.Bounds.Height;
|
||||
initContainer.AddChild(ownerContainer);
|
||||
|
||||
// Add new children for inits
|
||||
var options = actor.Info.TraitInfos<IEditorActorOptions>()
|
||||
.SelectMany(t => t.ActorOptions(actor.Info, worldRenderer.World))
|
||||
.OrderBy(o => o.DisplayOrder);
|
||||
|
||||
foreach (var o in options)
|
||||
{
|
||||
if (o is EditorActorSlider)
|
||||
{
|
||||
var so = (EditorActorSlider)o;
|
||||
var sliderContainer = sliderOptionTemplate.Clone();
|
||||
sliderContainer.Bounds.Y = initContainer.Bounds.Height;
|
||||
initContainer.Bounds.Height += sliderContainer.Bounds.Height;
|
||||
sliderContainer.Get<LabelWidget>("LABEL").GetText = () => so.Name;
|
||||
|
||||
var slider = sliderContainer.Get<SliderWidget>("OPTION");
|
||||
slider.MinimumValue = so.MinValue;
|
||||
slider.MaximumValue = so.MaxValue;
|
||||
slider.Ticks = so.Ticks;
|
||||
|
||||
slider.GetValue = () => so.GetValue(actor);
|
||||
slider.OnChange += value => so.OnChange(actor, value);
|
||||
|
||||
initContainer.AddChild(sliderContainer);
|
||||
}
|
||||
else if (o is EditorActorDropdown)
|
||||
{
|
||||
var ddo = (EditorActorDropdown)o;
|
||||
var dropdownContainer = dropdownOptionTemplate.Clone();
|
||||
dropdownContainer.Bounds.Y = initContainer.Bounds.Height;
|
||||
initContainer.Bounds.Height += dropdownContainer.Bounds.Height;
|
||||
dropdownContainer.Get<LabelWidget>("LABEL").GetText = () => ddo.Name;
|
||||
|
||||
var dropdown = dropdownContainer.Get<DropDownButtonWidget>("OPTION");
|
||||
Func<KeyValuePair<string, string>, ScrollItemWidget, ScrollItemWidget> dropdownSetup = (option, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template,
|
||||
() => ddo.GetValue(actor) == option.Key,
|
||||
() => ddo.OnChange(actor, option.Key));
|
||||
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Value;
|
||||
return item;
|
||||
};
|
||||
|
||||
dropdown.GetText = () => ddo.Labels[ddo.GetValue(actor)];
|
||||
dropdown.OnClick = () => dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, ddo.Labels, dropdownSetup);
|
||||
|
||||
initContainer.AddChild(dropdownContainer);
|
||||
}
|
||||
}
|
||||
|
||||
actorEditPanel.Bounds.Height += initContainer.Bounds.Height - oldInitHeight;
|
||||
buttonContainer.Bounds.Y += initContainer.Bounds.Height - oldInitHeight;
|
||||
}
|
||||
|
||||
actorSelectBorder.Bounds.X = origin.X;
|
||||
|
||||
Reference in New Issue
Block a user