Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically generate lobby Map Options UI. #14359

Merged
merged 9 commits into from Dec 12, 2017

Conversation

pchote
Copy link
Member

@pchote pchote commented Nov 14, 2017

This PR completes the work the work started with #11364 by dynamically generating the map options bin based on the selected map/mod rules.

Custom maps can remove/rearrange existing options by adjusting the *Visible and *DisplayOrder yaml fields, or add their own (see ScriptLobbyDropdown/#14325/#14245).

This also adds descriptive tooltips to the default options.

@pchote pchote changed the title Unhardcode lobby checkboxes Dynamically generate lobby Map Options UI. Nov 14, 2017
@pchote pchote force-pushed the unhardcode-lobby-checkboxes branch 2 times, most recently from 25c2554 to c744b13 Compare November 14, 2017 17:58
@reaperrr
Copy link
Contributor

c744b13 is a bit out of my league, but the other commits and the in-game result look fine, so 👍

reaperrr
reaperrr previously approved these changes Nov 15, 2017
@reaperrr
Copy link
Contributor

I think this should go into the playtest, moving to milestone.

@reaperrr reaperrr added this to the Next + 1 milestone Nov 17, 2017
Copy link
Member

@abcdefg30 abcdefg30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from Exodus to Infiltration and changing the difficulty and speed dropdowns while the rules have not loaded leads to a crash (which I could not reproduce on bleed):

OpenRA engine version {DEV_VERSION}
Red Alert mod version {DEV_VERSION}
Date: 2017-11-19 00:09:19Z
Operating System: Windows (Microsoft Windows NT 6.2.9200.0)
Runtime Version: .NET CLR 4.0.30319.42000
Exception of type `System.InvalidOperationException`: Collection was modified. Enumeration operation may not execute. (Die Sammlung wurde geändert. Der Enumerationsvorgang kann möglicherweise nicht ausgeführt werden.)
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at OpenRA.Widgets.Widget.TickOuter() in \OpenRA\OpenRA.Game\Widgets\Widget.cs:Line 463.
   at OpenRA.Widgets.Ui.Tick() in \OpenRA\OpenRA.Game\Widgets\Widget.cs:Line 88.
   at OpenRA.Sync.<>c__DisplayClass5.<CheckSyncUnchanged>b__4() in \OpenRA\OpenRA.Game\Sync.cs:Line 166.
   at OpenRA.Sync.CheckSyncUnchanged[T](World world, Func`1 fn) in \OpenRA\OpenRA.Game\Sync.cs:Line 174.
   at OpenRA.Sync.CheckSyncUnchanged(World world, Action fn) in \OpenRA\OpenRA.Game\Sync.cs:Line 166.
   at OpenRA.Game.InnerLogicTick(OrderManager orderManager) in \OpenRA\OpenRA.Game\Game.cs:Line 566.
   at OpenRA.Game.LogicTick() in \OpenRA\OpenRA.Game\Game.cs:Line 633.
   at OpenRA.Game.Loop() in \OpenRA\OpenRA.Game\Game.cs:Line 763.
   at OpenRA.Game.Run() in \OpenRA\OpenRA.Game\Game.cs:Line 803.
   at OpenRA.Program.Run(String[] args) in \OpenRA\OpenRA.Game\Support\Program.cs:Line 136.
   at OpenRA.Program.Main(String[] args) in \OpenRA\OpenRA.Game\Support\Program.cs:Line 40.

row.Bounds.Y = optionsContainer.Bounds.Height;
optionsContainer.Bounds.Height += row.Bounds.Height;
foreach (var child in row.Children)
if (child is CheckboxWidget)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use an is and a second cast instead of as and a null check here and below?

Copy link
Member Author

@pchote pchote Nov 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It saves having to define intermediate variables and adding a bunch of {}s.

@@ -9,9 +9,13 @@ Player:
PowerManager:
AllyRepair:
PlayerResources:
DefaultCashDisplayOrder: 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to restate the default. We tend to avoid that in other places.

@pchote
Copy link
Member Author

pchote commented Nov 19, 2017

Fixed.

@@ -37,7 +43,10 @@ IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
var startingCash = SelectableCash.ToDictionary(c => c.ToString(), c => "$" + c.ToString());

if (startingCash.Any())
yield return new LobbyOption("startingcash", "Starting Cash", new ReadOnlyDictionary<string, string>(startingCash), DefaultCash.ToString(), DefaultCashLocked);
yield return new LobbyOption("startingcash", "Starting Cash", "Change the amount of cash that you start with",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move those descriptions to .yaml too. Not sure about others, but for crates at least it says random bonuses or penalties but some mods may have only bonuses for example. Or just wanna change the wording a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.

@reaperrr reaperrr modified the milestones: Next + 1, Next release Nov 19, 2017
reaperrr
reaperrr previously approved these changes Dec 2, 2017
@penev92
Copy link
Member

penev92 commented Dec 4, 2017

All the random UI-related properties in random TraitInfos really don't sit well with me.
Can we have them as part of the ILobbyOptions interface and give them proper names like LobbyVisible/LobbyDescription/LobbyLocked/etc. ?
And since that's still not quite "proper", I'd actually prefer to see them gone from the respective traits and into a specialized one if possible (but too much of a scope creep for this PR).

public readonly bool FogLocked = false;

[Desc("Display the fog checkbox in the lobby.")]
public readonly bool FogVisible = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be so confusing...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to agree here, can't we call those FogCheckboxVisible, ShroudCheckboxVisible and so on?

Copy link
Member Author

@pchote pchote Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without renaming all the other fields related to these across all the traits that use them + associated upgrade rules. Considering that this PR has been sitting cold for three weeks, and that I have a big rework of the upgrade rules in the works, i'm not willing to do this myself. If this is a blocker for this PR, then please push an amendment over this if you want to address it yourself, or we can close it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you close this then please also revert the superstupid "hey-we're-overlooking-how-hacky-these-are-cuz-guy-is-newcomer" checkbox PRs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a blocker for this PR, then please push an amendment over this if you want to address it yourself, or we can close it.

It would have been nicer, but it's not a blocker to me, and Fog + Shroud are the only ambiguous cases anyway. My +1 still stands.

@pchote
Copy link
Member Author

pchote commented Dec 4, 2017

All the random UI-related properties in random TraitInfos really don't sit well with me.
Can we have them as part of the ILobbyOptions interface and give them proper names like LobbyVisible/LobbyDescription/LobbyLocked/etc. ?
And since that's still not quite "proper", I'd actually prefer to see them gone from the respective traits and into a specialized one if possible (but too much of a scope creep for this PR).

The whole point is to allow individual traits to control their visibility in the options bin via yaml. Making them part of the interface would break FieldLoader/yaml integration, and moving them to another trait would require a new set of plumbing to link them to the traits they control.

penev92
penev92 previously requested changes Dec 7, 2017
Copy link
Member

@penev92 penev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything seems to work, but I have a bunch of style nits.

P.S.: Eh, I thought I'd do the upgrade rules but ... just rename the bool properties that you're adding now, leave the old ones.


[Translate]
[Desc("Description of the starting cash option in the lobby.")]
public readonly string Description = "Change the amount of cash that you start with";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... that PLAYERS start with.

@@ -26,6 +34,12 @@ public class PlayerResourcesInfo : ITraitInfo, ILobbyOptions
[Desc("Force the DefaultCash option by disabling changes in the lobby.")]
public readonly bool DefaultCashLocked = false;

[Desc("Display the DefaultCash option in the lobby.")]
public readonly bool DefaultCashVisible = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsDefaultCashVisible, please.

@@ -26,6 +34,12 @@ public class PlayerResourcesInfo : ITraitInfo, ILobbyOptions
[Desc("Force the DefaultCash option by disabling changes in the lobby.")]
public readonly bool DefaultCashLocked = false;

[Desc("Display the DefaultCash option in the lobby.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm... "Whether to display", to sound a bit better?

@@ -17,22 +17,52 @@ namespace OpenRA.Traits
[Desc("Required for shroud and fog visibility checks. Add this to the player actor.")]
public class ShroudInfo : ITraitInfo, ILobbyOptions
{
[Translate]
[Desc("Label for the fog checkbox in the lobby.")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one in PlayerResources starts with "Display name for ... ". Would be nice for consistency.

[Desc("Default value of the fog checkbox in the lobby.")]
public bool FogEnabled = true;
public readonly bool FogEnabled = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsFogEnabled, please.


Widget row = null;
Queue<CheckboxWidget> checkboxColumns = new Queue<CheckboxWidget>();
Queue<DropDownButtonWidget> dropdownColumns = new Queue<DropDownButtonWidget>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var for the two queues, please.

{
if (!checkboxColumns.Any())
{
row = checkboxTemplate.Clone() as Widget;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as Widget is redundant.

optionsContainer = widget.Get("LOBBY_OPTIONS");
optionsContainer.IsVisible = () => validOptions;
checkboxTemplate = optionsContainer.Get("CHECKBOX_ROW_TEMPLATE");
dropdownTemplate = optionsContainer.Get("DROPDOWN_ROW_TEMPLATE");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename these to *RowTemplate for easier readability (I may be sleepy, but it took more than it should have to understand the below code).

checkbox.GetText = () => option.Name;
if (option.Description != null)
checkbox.GetTooltipText = () => option.Description;
checkbox.IsVisible = () => true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing empty line after if.

checkbox.IsVisible = () => true;
checkbox.IsChecked = () => optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Enabled;
checkbox.IsDisabled = () => configurationDisabled() ||
optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Locked;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious line break?

@pchote
Copy link
Member Author

pchote commented Dec 9, 2017

There have been major changes, so @reaperrr please reconfirm your 👍

@pchote
Copy link
Member Author

pchote commented Dec 11, 2017

Rebased.

@pchote pchote dismissed penev92’s stale review December 11, 2017 19:20

Changes have been addressed.

abcdefg30
abcdefg30 previously approved these changes Dec 11, 2017
@pchote
Copy link
Member Author

pchote commented Dec 12, 2017

Rebased.

abcdefg30
abcdefg30 previously approved these changes Dec 12, 2017
Copy link
Member

@abcdefg30 abcdefg30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(PR was only rebased.)

@reaperrr reaperrr merged commit 3ad6a87 into OpenRA:bleed Dec 12, 2017
@pchote
Copy link
Member Author

pchote commented Dec 13, 2017

I suspect that something went wrong with the rebase or was maybe just missed with the last round of testing. The ordering of the lobby options has regressed on all mods, and the debug menu is no longer enabled by default in TS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants