Re-add a mini lobby options menu to missionbrowser
This commit is contained in:
committed by
Matthias Mailänder
parent
aebb97967d
commit
38d4719073
@@ -68,6 +68,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ScrollItemWidget headerTemplate;
|
||||
readonly ScrollItemWidget template;
|
||||
|
||||
readonly Widget miniOptions;
|
||||
readonly DropDownButtonWidget difficultyButton;
|
||||
readonly DropDownButtonWidget gameSpeedButton;
|
||||
readonly string unsetDifficulty;
|
||||
readonly string defaultTooltop;
|
||||
|
||||
// For remembering options
|
||||
// TODO: this should be persistent across game sessions
|
||||
string selectedDifficulty;
|
||||
string selectedGameSpeed;
|
||||
|
||||
bool minifiedOptions = true;
|
||||
MapPreview selectedMap;
|
||||
PlayingVideo playingVideo;
|
||||
readonly Dictionary<string, string> missionOptions = new();
|
||||
@@ -125,6 +137,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
stopInfoVideoButton.IsVisible = () => playingVideo == PlayingVideo.Info;
|
||||
stopInfoVideoButton.OnClick = () => StopVideo(videoPlayer);
|
||||
|
||||
miniOptions = widget.GetOrNull("MISSION_MINIFIED_OPTIONS");
|
||||
if (miniOptions != null)
|
||||
{
|
||||
miniOptions.IsVisible = () => minifiedOptions;
|
||||
difficultyButton = miniOptions.GetOrNull<DropDownButtonWidget>("DIFFICULTY");
|
||||
gameSpeedButton = miniOptions.GetOrNull<DropDownButtonWidget>("GAMESPEED");
|
||||
unsetDifficulty = FluentProvider.GetMessage(difficultyButton.Text);
|
||||
defaultTooltop = FluentProvider.GetMessage(difficultyButton.TooltipText);
|
||||
}
|
||||
|
||||
var allPreviews = new List<MapPreview>();
|
||||
missionList.RemoveChildren();
|
||||
|
||||
@@ -204,16 +226,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
|
||||
var tabContainer = widget.Get("MISSION_TABS");
|
||||
tabContainer.IsVisible = () => true;
|
||||
tabContainer.IsVisible = () => !minifiedOptions;
|
||||
|
||||
var optionsTab = tabContainer.Get<ButtonWidget>("OPTIONS_TAB");
|
||||
optionsTab.IsHighlighted = () => panel == PanelType.Options;
|
||||
optionsTab.IsDisabled = () => false;
|
||||
optionsTab.OnClick = () => panel = PanelType.Options;
|
||||
|
||||
var missionTab = tabContainer.Get<ButtonWidget>("MISSIONINFO_TAB");
|
||||
missionTab.IsHighlighted = () => panel == PanelType.MissionInfo;
|
||||
missionTab.IsDisabled = () => false;
|
||||
missionTab.OnClick = () => panel = PanelType.MissionInfo;
|
||||
}
|
||||
|
||||
@@ -319,6 +339,44 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
.Where(o => o.IsVisible)
|
||||
.OrderBy(o => o.DisplayOrder).ToArray();
|
||||
|
||||
minifiedOptions = allOptions.All(o => o.Id == "difficulty" || o.Id == "gamespeed");
|
||||
if (minifiedOptions)
|
||||
BuildMinifiedOptions(allOptions);
|
||||
else
|
||||
BuildOptions(allOptions);
|
||||
}
|
||||
|
||||
void SetMapDifficulty(LobbyOption option)
|
||||
{
|
||||
selectedDifficulty ??= option.DefaultValue;
|
||||
if (option.Values.ContainsKey(selectedDifficulty))
|
||||
missionOptions[option.Id] = selectedDifficulty;
|
||||
else
|
||||
missionOptions[option.Id] = option.DefaultValue;
|
||||
}
|
||||
|
||||
void SetMapSpeed(LobbyOption option)
|
||||
{
|
||||
selectedGameSpeed ??= option.DefaultValue;
|
||||
if (option.Values.ContainsKey(selectedGameSpeed))
|
||||
missionOptions[option.Id] = selectedGameSpeed;
|
||||
else
|
||||
missionOptions[option.Id] = option.DefaultValue;
|
||||
}
|
||||
|
||||
void OnOptionSelected(string optionId, string value)
|
||||
{
|
||||
// Only remember when the user manually changes the value
|
||||
if (optionId == "difficulty")
|
||||
selectedDifficulty = value;
|
||||
else if (optionId == "gamespeed")
|
||||
selectedGameSpeed = value;
|
||||
|
||||
missionOptions[optionId] = value;
|
||||
}
|
||||
|
||||
void BuildOptions(LobbyOption[] allOptions)
|
||||
{
|
||||
Widget row = null;
|
||||
var checkboxColumns = new Queue<CheckboxWidget>();
|
||||
var dropdownColumns = new Queue<DropDownButtonWidget>();
|
||||
@@ -364,7 +422,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
foreach (var option in allOptions.Where(o => o is not LobbyBooleanOption))
|
||||
{
|
||||
missionOptions[option.Id] = option.DefaultValue;
|
||||
if (option.Id == "difficulty")
|
||||
SetMapDifficulty(option);
|
||||
else if (option.Id == "gamespeed")
|
||||
SetMapSpeed(option);
|
||||
else
|
||||
missionOptions[option.Id] = option.DefaultValue;
|
||||
|
||||
if (dropdownColumns.Count == 0)
|
||||
{
|
||||
@@ -378,42 +441,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
optionsContainer.AddChild(row);
|
||||
}
|
||||
|
||||
var dropdown = dropdownColumns.Dequeue();
|
||||
var val = dropdownColumns.Dequeue();
|
||||
SetupDropdown(val, option);
|
||||
|
||||
dropdown.GetText = () =>
|
||||
{
|
||||
if (option.Values.TryGetValue(missionOptions[option.Id], out var value))
|
||||
return value;
|
||||
|
||||
return FluentProvider.GetMessage(NotAvailable);
|
||||
};
|
||||
|
||||
if (option.Description != null)
|
||||
{
|
||||
var (text, desc) = LobbyUtils.SplitOnFirstToken(option.Description);
|
||||
dropdown.GetTooltipText = () => text;
|
||||
dropdown.GetTooltipDesc = () => desc;
|
||||
}
|
||||
|
||||
dropdown.IsVisible = () => true;
|
||||
dropdown.IsDisabled = () => option.IsLocked;
|
||||
|
||||
dropdown.OnMouseDown = _ =>
|
||||
{
|
||||
ScrollItemWidget SetupItem(KeyValuePair<string, string> c, ScrollItemWidget template)
|
||||
{
|
||||
bool IsSelected() => missionOptions[option.Id] == c.Key;
|
||||
void OnClick() => missionOptions[option.Id] = c.Key;
|
||||
|
||||
var item = ScrollItemWidget.Setup(template, IsSelected, OnClick);
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => c.Value;
|
||||
return item;
|
||||
}
|
||||
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", option.Values.Count * 30, option.Values, SetupItem);
|
||||
};
|
||||
|
||||
var label = row.GetOrNull<LabelWidget>(dropdown.Id + "_DESC");
|
||||
var label = row.GetOrNull<LabelWidget>(val.Id + "_DESC");
|
||||
if (label != null)
|
||||
{
|
||||
label.GetText = () => option.Name + ":";
|
||||
@@ -422,6 +453,76 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
void BuildMinifiedOptions(LobbyOption[] allOptions)
|
||||
{
|
||||
if (difficultyButton != null)
|
||||
{
|
||||
var mapDifficulty = allOptions.FirstOrDefault(sld => sld.Id == "difficulty");
|
||||
if (mapDifficulty != null)
|
||||
{
|
||||
SetMapDifficulty(mapDifficulty);
|
||||
SetupDropdown(difficultyButton, mapDifficulty);
|
||||
}
|
||||
else
|
||||
{
|
||||
difficultyButton.IsDisabled = () => true;
|
||||
difficultyButton.GetText = () => unsetDifficulty;
|
||||
difficultyButton.GetTooltipText = () => defaultTooltop;
|
||||
}
|
||||
}
|
||||
|
||||
if (gameSpeedButton != null)
|
||||
{
|
||||
var gameSpeed = allOptions.FirstOrDefault(sld => sld.Id == "gamespeed");
|
||||
if (gameSpeed != null)
|
||||
{
|
||||
SetMapSpeed(gameSpeed);
|
||||
SetupDropdown(gameSpeedButton, gameSpeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameSpeedButton.IsDisabled = () => true;
|
||||
gameSpeedButton.GetText = () => FluentProvider.GetMessage(NotAvailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetupDropdown(DropDownButtonWidget dropdown, LobbyOption option)
|
||||
{
|
||||
dropdown.GetText = () =>
|
||||
{
|
||||
if (option.Values.TryGetValue(missionOptions[option.Id], out var value))
|
||||
return value;
|
||||
|
||||
return FluentProvider.GetMessage(NotAvailable);
|
||||
};
|
||||
|
||||
if (option.Description != null)
|
||||
{
|
||||
var (text, desc) = LobbyUtils.SplitOnFirstToken(option.Description);
|
||||
dropdown.GetTooltipText = () => text;
|
||||
dropdown.GetTooltipDesc = () => desc;
|
||||
}
|
||||
|
||||
dropdown.IsVisible = () => true;
|
||||
dropdown.IsDisabled = () => option.IsLocked;
|
||||
|
||||
dropdown.OnMouseDown = _ =>
|
||||
{
|
||||
ScrollItemWidget SetupItem(KeyValuePair<string, string> c, ScrollItemWidget template)
|
||||
{
|
||||
bool IsSelected() => missionOptions[option.Id] == c.Key;
|
||||
void OnClick() => OnOptionSelected(option.Id, c.Key);
|
||||
|
||||
var item = ScrollItemWidget.Setup(template, IsSelected, OnClick);
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => c.Value;
|
||||
return item;
|
||||
}
|
||||
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", option.Values.Count * 30, option.Values, SetupItem);
|
||||
};
|
||||
}
|
||||
|
||||
float cachedSoundVolume;
|
||||
float cachedMusicVolume;
|
||||
void MuteSounds()
|
||||
|
||||
@@ -68,6 +68,44 @@ Container@MISSIONBROWSER_PANEL:
|
||||
IgnoreMouseOver: True
|
||||
IgnoreMouseInput: True
|
||||
ShowSpawnPoints: False
|
||||
Container@MISSION_MINIFIED_OPTIONS:
|
||||
Width: PARENT_WIDTH
|
||||
Height: PARENT_HEIGHT
|
||||
Visible: False
|
||||
Children:
|
||||
LabelForInput@DIFFICULTY_DESC:
|
||||
Y: PARENT_HEIGHT - HEIGHT + 2
|
||||
Width: 56
|
||||
Height: 25
|
||||
Align: Right
|
||||
Text: dropdown-missionbrowser-difficulty.label
|
||||
For: DIFFICULTY
|
||||
DropDownButton@DIFFICULTY:
|
||||
X: 61
|
||||
Y: PARENT_HEIGHT - HEIGHT + 2
|
||||
Width: 120
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Text: label-missionbrowser-normal-difficulty
|
||||
TooltipText: dropdown-missionbrowser-difficulty.description
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
LabelForInput@GAMESPEED_DESC:
|
||||
X: PARENT_WIDTH - WIDTH - 125
|
||||
Y: PARENT_HEIGHT - HEIGHT + 2
|
||||
Width: 120
|
||||
Height: 25
|
||||
Align: Right
|
||||
Text: dropdown-missionbrowser-gamespeed
|
||||
For: GAMESPEED
|
||||
DropDownButton@GAMESPEED:
|
||||
X: PARENT_WIDTH - WIDTH
|
||||
Y: PARENT_HEIGHT - HEIGHT + 2
|
||||
Width: 120
|
||||
Height: 25
|
||||
Font: Regular
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
Container@MISSION_TABS:
|
||||
Width: PARENT_WIDTH
|
||||
Y: PARENT_HEIGHT - 31
|
||||
|
||||
@@ -519,6 +519,12 @@ button-missionbrowser-panel-stop-briefing-video = Stop Briefing
|
||||
button-missionbrowser-panel-start-info-video = Watch Info Video
|
||||
button-missionbrowser-panel-stop-info-video = Stop Info Video
|
||||
button-missionbrowser-panel-play = Play
|
||||
dropdown-missionbrowser-difficulty =
|
||||
.label = Difficulty
|
||||
.description = The difficulty of the mission
|
||||
|
||||
dropdown-missionbrowser-gamespeed = Speed:
|
||||
label-missionbrowser-normal-difficulty = Normal
|
||||
|
||||
## multiplayer-browser.yaml
|
||||
image-bg-password-protected-tooltip = Requires Password
|
||||
|
||||
@@ -76,6 +76,44 @@ Background@MISSIONBROWSER_PANEL:
|
||||
Height: 31
|
||||
Font: Bold
|
||||
Text: button-missionbrowser-panel-mission-options
|
||||
Container@MISSION_MINIFIED_OPTIONS:
|
||||
Width: PARENT_WIDTH
|
||||
Height: PARENT_HEIGHT
|
||||
Visible: False
|
||||
Children:
|
||||
LabelForInput@DIFFICULTY_DESC:
|
||||
Y: PARENT_HEIGHT - HEIGHT
|
||||
Width: 56
|
||||
Height: 25
|
||||
Align: Right
|
||||
Text: dropdown-missionbrowser-difficulty.label
|
||||
For: DIFFICULTY
|
||||
DropDownButton@DIFFICULTY:
|
||||
X: 61
|
||||
Y: PARENT_HEIGHT - HEIGHT
|
||||
Width: 135
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Text: label-missionbrowser-normal-difficulty
|
||||
TooltipText: dropdown-missionbrowser-difficulty.description
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
LabelForInput@GAMESPEED_DESC:
|
||||
X: PARENT_WIDTH - WIDTH - 115
|
||||
Y: PARENT_HEIGHT - HEIGHT
|
||||
Width: 120
|
||||
Height: 25
|
||||
Align: Right
|
||||
Text: dropdown-missionbrowser-gamespeed
|
||||
For: GAMESPEED
|
||||
DropDownButton@GAMESPEED:
|
||||
X: PARENT_WIDTH - WIDTH
|
||||
Y: PARENT_HEIGHT - HEIGHT
|
||||
Width: 110
|
||||
Height: 25
|
||||
Font: Regular
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
Container@MISSION_DETAIL:
|
||||
Y: 212
|
||||
Width: PARENT_WIDTH
|
||||
|
||||
@@ -350,6 +350,12 @@ button-missionbrowser-panel-stop-info-video = Stop Info Video
|
||||
button-missionbrowser-panel-play = Play
|
||||
button-missionbrowser-panel-mission-info = Mission Info
|
||||
button-missionbrowser-panel-mission-options = Options
|
||||
dropdown-missionbrowser-difficulty =
|
||||
.label = Difficulty
|
||||
.description = The difficulty of the mission
|
||||
|
||||
dropdown-missionbrowser-gamespeed = Speed:
|
||||
label-missionbrowser-normal-difficulty = Normal
|
||||
|
||||
## multiplayer-browser.yaml
|
||||
image-multiplayer-panel-password-protected-tooltip = Requires Password
|
||||
|
||||
@@ -144,6 +144,45 @@ Background@MISSIONBROWSER_PANEL:
|
||||
Visible: False
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
Container@MISSION_MINIFIED_OPTIONS:
|
||||
X: 220
|
||||
Width: PARENT_WIDTH - 220
|
||||
Height: PARENT_HEIGHT
|
||||
Visible: False
|
||||
Children:
|
||||
LabelForInput@DIFFICULTY_DESC:
|
||||
Y: PARENT_HEIGHT - 80
|
||||
Width: 56
|
||||
Height: 25
|
||||
Align: Right
|
||||
Text: dropdown-missionbrowser-difficulty.label
|
||||
For: DIFFICULTY
|
||||
DropDownButton@DIFFICULTY:
|
||||
X: 71
|
||||
Y: PARENT_HEIGHT - 80
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Text: label-missionbrowser-normal-difficulty
|
||||
TooltipText: dropdown-missionbrowser-difficulty.description
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
LabelForInput@GAMESPEED_DESC:
|
||||
X: PARENT_WIDTH - 140 - WIDTH - 35
|
||||
Y: PARENT_HEIGHT - 80
|
||||
Width: 56
|
||||
Height: 25
|
||||
Align: Right
|
||||
Text: dropdown-missionbrowser-gamespeed
|
||||
For: GAMESPEED
|
||||
DropDownButton@GAMESPEED:
|
||||
X: PARENT_WIDTH - 160
|
||||
Y: PARENT_HEIGHT - 80
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
PanelRoot: MISSION_DROPDOWN_PANEL_ROOT
|
||||
TooltipContainer: TOOLTIP_CONTAINER
|
||||
Button@START_BRIEFING_VIDEO_BUTTON:
|
||||
X: 20
|
||||
Y: PARENT_HEIGHT - 45
|
||||
|
||||
Reference in New Issue
Block a user