Move IsDisabled checking for OnMouseDown into ButtonWidget. Remove unnecessary bool plumbing.
This commit is contained in:
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
GetText = () => world.LocalPlayer.Stances[ pp ].ToString(),
|
||||
};
|
||||
|
||||
myStance.OnMouseDown = mi => { ShowDropDown(pp, myStance); return true; };
|
||||
myStance.OnMouseDown = mi => ShowDropDown(pp, myStance);
|
||||
|
||||
bg.AddChild(myStance);
|
||||
controls.Add(myStance);
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
bool ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client)
|
||||
void ShowSlotDropDown(DropDownButtonWidget dropdown, Session.Slot slot, Session.Client client)
|
||||
{
|
||||
var options = new List<SlotDropDownOption>()
|
||||
{
|
||||
@@ -253,10 +253,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client)
|
||||
void ShowRaceDropDown(DropDownButtonWidget dropdown, Session.Client client)
|
||||
{
|
||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (race, itemTemplate) =>
|
||||
{
|
||||
@@ -271,10 +270,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
|
||||
dropdown.ShowDropDown("RACE_DROPDOWN_TEMPLATE", 150, CountryNames.Keys.ToList(), setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client)
|
||||
void ShowTeamDropDown(DropDownButtonWidget dropdown, Session.Client client)
|
||||
{
|
||||
Func<int, ScrollItemWidget, ScrollItemWidget> setupItem = (ii, itemTemplate) =>
|
||||
{
|
||||
@@ -287,10 +285,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var options = Graphics.Util.MakeArray(Map.PlayerCount, i => i).ToList();
|
||||
dropdown.ShowDropDown("TEAM_DROPDOWN_TEMPLATE", 150, options, setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShowColorDropDown(DropDownButtonWidget color, Session.Client client)
|
||||
void ShowColorDropDown(DropDownButtonWidget color, Session.Client client)
|
||||
{
|
||||
var colorChooser = Game.modData.WidgetLoader.LoadWidget( new WidgetArgs() { {"worldRenderer", worldRenderer} }, null, "COLOR_CHOOSER" );
|
||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||
@@ -319,7 +316,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
|
||||
color.AttachPanel(colorChooser);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
@@ -383,14 +379,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var color = template.GetWidget<DropDownButtonWidget>("COLOR");
|
||||
color.IsDisabled = () => s.LockColor;
|
||||
color.OnMouseDown = _ => { if (s.LockColor) return true; return ShowColorDropDown(color, c); };
|
||||
color.OnMouseDown = _ => ShowColorDropDown(color, c);
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => c.ColorRamp.GetColor(0);
|
||||
|
||||
var faction = template.GetWidget<DropDownButtonWidget>("FACTION");
|
||||
faction.IsDisabled = () => s.LockRace;
|
||||
faction.OnMouseDown = _ => { if (s.LockRace) return true; return ShowRaceDropDown(faction, c); };
|
||||
faction.OnMouseDown = _ => ShowRaceDropDown(faction, c);
|
||||
|
||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => CountryNames[c.Country];
|
||||
@@ -400,7 +396,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
var team = template.GetWidget<DropDownButtonWidget>("TEAM");
|
||||
team.IsDisabled = () => s.LockTeam;
|
||||
team.OnMouseDown = _ => { if (s.LockTeam) return true; return ShowTeamDropDown(team, c); };
|
||||
team.OnMouseDown = _ => ShowTeamDropDown(team, c);
|
||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||
|
||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
});
|
||||
}
|
||||
|
||||
static bool ShowModsDropDown(DropDownButtonWidget dropdown)
|
||||
static void ShowModsDropDown(DropDownButtonWidget dropdown)
|
||||
{
|
||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (m, itemTemplate) =>
|
||||
{
|
||||
@@ -86,9 +86,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
};
|
||||
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 150, Mod.AllMods.Keys.ToList(), setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (sell != null)
|
||||
{
|
||||
sell.Pressed = () => world.OrderGenerator is SellOrderGenerator;
|
||||
sell.OnMouseDown = mi => { world.ToggleInputMode<SellOrderGenerator>(); return true; };
|
||||
sell.OnMouseDown = mi => world.ToggleInputMode<SellOrderGenerator>();
|
||||
}
|
||||
|
||||
var powerdown = moneybin.GetWidget<OrderButtonWidget>("POWER_DOWN");
|
||||
if (powerdown != null)
|
||||
{
|
||||
powerdown.Pressed = () => world.OrderGenerator is PowerDownOrderGenerator;
|
||||
powerdown.OnMouseDown = mi => { world.ToggleInputMode<PowerDownOrderGenerator>(); return true; };
|
||||
powerdown.OnMouseDown = mi => world.ToggleInputMode<PowerDownOrderGenerator>();
|
||||
}
|
||||
|
||||
var repair = moneybin.GetWidget<OrderButtonWidget>("REPAIR");
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
repair.Enabled = () => { return RepairOrderGenerator.PlayerIsAllowedToRepair( world ); };
|
||||
repair.Pressed = () => world.OrderGenerator is RepairOrderGenerator;
|
||||
repair.OnMouseDown = mi => { world.ToggleInputMode<RepairOrderGenerator>(); return true; };
|
||||
repair.OnMouseDown = mi => world.ToggleInputMode<RepairOrderGenerator>();
|
||||
repair.GetLongDesc = () => { return repair.Enabled() ? repair.LongDesc : repair.LongDesc + "\n\nRequires: Construction Yard"; };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user