Add click sounds to ingame buttons

This commit is contained in:
Paul Chote
2011-07-09 17:56:47 +12:00
parent 195aecec0e
commit 47ba4cb285
5 changed files with 31 additions and 4 deletions

View File

@@ -22,6 +22,8 @@ namespace OpenRA.Widgets
public bool Depressed = false; public bool Depressed = false;
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth"); public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
public string Font = ChromeMetrics.Get<string>("ButtonFont"); public string Font = ChromeMetrics.Get<string>("ButtonFont");
public string ClickSound = null;
public string ClickDisabledSound = null;
public Func<string> GetText; public Func<string> GetText;
public Func<bool> IsDisabled = () => false; public Func<bool> IsDisabled = () => false;
public Action<MouseInput> OnMouseDown = _ => {}; public Action<MouseInput> OnMouseDown = _ => {};
@@ -65,7 +67,12 @@ namespace OpenRA.Widgets
return false; return false;
if (!IsDisabled()) if (!IsDisabled())
{
OnKeyPress(e); OnKeyPress(e);
Sound.Play(ClickSound);
}
else
Sound.Play(ClickDisabledSound);
return true; return true;
} }
@@ -94,9 +101,13 @@ namespace OpenRA.Widgets
{ {
OnMouseDown(mi); OnMouseDown(mi);
Depressed = true; Depressed = true;
Sound.Play(ClickSound);
} }
else else
{
LoseFocus(mi); LoseFocus(mi);
Sound.Play(ClickDisabledSound);
}
} }
else if (mi.Event == MouseInputEvent.Move && Focused) else if (mi.Event == MouseInputEvent.Move && Focused)
Depressed = RenderBounds.Contains(mi.Location.X, mi.Location.Y); Depressed = RenderBounds.Contains(mi.Location.X, mi.Location.Y);

View File

@@ -271,7 +271,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
chatPanel.AddChild(template); chatPanel.AddChild(template);
chatPanel.ScrollToBottom(); chatPanel.ScrollToBottom();
Sound.Play("scold2.aud"); Sound.Play("scold1.aud");
} }
void UpdateCurrentMap() void UpdateCurrentMap()

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public class ProductionPaletteWidget : Widget public class ProductionPaletteWidget : Widget
{ {
public readonly int Columns = 3; public readonly int Columns = 3;
public readonly string TabClick = "button.aud"; public readonly string TabClick = null;
public readonly string TooltipContainer; public readonly string TooltipContainer;
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP"; public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";

View File

@@ -19,7 +19,7 @@ Container@INGAME_ROOT:
DrawBackground: False DrawBackground: False
RemoveTime:250 RemoveTime:250
UseContrast: yes UseContrast: yes
Notification: scold2.aud Notification: scold1.aud
ChatEntry@CHAT_ENTRY: ChatEntry@CHAT_ENTRY:
Id:CHAT_ENTRY Id:CHAT_ENTRY
X:250 X:250
@@ -137,6 +137,8 @@ Container@PLAYER_WIDGETS:
Font:Bold Font:Bold
TooltipText: Menu TooltipText: Menu
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -154,6 +156,8 @@ Container@PLAYER_WIDGETS:
Font:Bold Font:Bold
TooltipText: Sell TooltipText: Sell
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -170,6 +174,8 @@ Container@PLAYER_WIDGETS:
Font:Bold Font:Bold
TooltipText: Repair TooltipText: Repair
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -247,6 +253,8 @@ Container@PLAYER_WIDGETS:
Key: y Key: y
TooltipText: Buildings TooltipText: Buildings
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -261,6 +269,8 @@ Container@PLAYER_WIDGETS:
Key: u Key: u
TooltipText: Defense TooltipText: Defense
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -275,6 +285,8 @@ Container@PLAYER_WIDGETS:
Key: i Key: i
TooltipText: Infantry TooltipText: Infantry
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -289,6 +301,8 @@ Container@PLAYER_WIDGETS:
Key: o Key: o
TooltipText: Vehicles TooltipText: Vehicles
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON
@@ -303,6 +317,8 @@ Container@PLAYER_WIDGETS:
Key: p Key: p
TooltipText: Aircraft TooltipText: Aircraft
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
ClickSound:button.aud
ClickDisabledSound:scold2.aud
Children: Children:
Image: Image:
Id:ICON Id:ICON

View File

@@ -3,4 +3,4 @@
Metrics: Metrics:
ButtonDepth: 0 ButtonDepth: 0
ButtonFont: Bold ButtonFont: Bold
CheckboxPressedState: true CheckboxPressedState: true