From fc44d082dcbea2a97ef9052e95d26def9f8f83e6 Mon Sep 17 00:00:00 2001 From: steelphase Date: Mon, 29 Sep 2014 21:54:04 -0400 Subject: [PATCH] Scroll Panel Sound Adds sound to Up, Down, and Thumb Button --- OpenRA.Game/Widgets/ScrollPanelWidget.cs | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/OpenRA.Game/Widgets/ScrollPanelWidget.cs b/OpenRA.Game/Widgets/ScrollPanelWidget.cs index 445f8fc8df..8403ef675e 100644 --- a/OpenRA.Game/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Game/Widgets/ScrollPanelWidget.cs @@ -43,6 +43,8 @@ namespace OpenRA.Widgets protected bool UpPressed; protected bool DownPressed; + protected bool UpDisabled; + protected bool DownDisabled; protected bool ThumbPressed; protected Rectangle upButtonRect; protected Rectangle downButtonRect; @@ -56,6 +58,8 @@ namespace OpenRA.Widgets // The current value is the actual list offset at the moment float currentListOffset; + readonly Ruleset modRules; + // Setting "smooth" to true will only update the target list offset. // Setting "smooth" to false will also set the current list offset, // i.e. it will scroll immediately. @@ -71,8 +75,11 @@ namespace OpenRA.Widgets currentListOffset = value; } - public ScrollPanelWidget() + [ObjectCreator.UseCtor] + public ScrollPanelWidget(Ruleset modRules) { + this.modRules = modRules; + Layout = new ListLayout(this); } @@ -126,26 +133,26 @@ namespace OpenRA.Widgets thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight); var upHover = Ui.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos); - var upDisabled = thumbHeight == 0 || currentListOffset >= 0; + UpDisabled = thumbHeight == 0 || currentListOffset >= 0; var downHover = Ui.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos); - var downDisabled = thumbHeight == 0 || currentListOffset <= Bounds.Height - ContentHeight; + DownDisabled = thumbHeight == 0 || currentListOffset <= Bounds.Height - ContentHeight; var thumbHover = Ui.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos); WidgetUtils.DrawPanel(Background, backgroundRect); WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect); - ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover, false); - ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover, false); + ButtonWidget.DrawBackground("button", upButtonRect, UpDisabled, UpPressed, upHover, false); + ButtonWidget.DrawBackground("button", downButtonRect, DownDisabled, DownPressed, downHover, false); if (thumbHeight > 0) ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, HasMouseFocus && thumbHover, thumbHover, false); - var upOffset = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth; - var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth; + var upOffset = !UpPressed || UpDisabled ? 4 : 4 + ButtonDepth; + var downOffset = !DownPressed || DownDisabled ? 4 : 4 + ButtonDepth; - WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", UpPressed || upDisabled ? "up_pressed" : "up_arrow"), + WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", UpPressed || UpDisabled ? "up_pressed" : "up_arrow"), new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset)); - WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", DownPressed || downDisabled ? "down_pressed" : "down_arrow"), + WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", DownPressed || DownDisabled ? "down_pressed" : "down_arrow"), new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset)); Game.Renderer.EnableScissor(backgroundRect.InflateBy(-1, -1, -1, -1)); @@ -281,6 +288,9 @@ namespace OpenRA.Widgets ThumbPressed = thumbRect.Contains(mi.Location); if (ThumbPressed) lastMouseLocation = mi.Location; + + if (mi.Event == MouseInputEvent.Down && ((UpPressed && !UpDisabled) || (DownPressed && !DownDisabled) || ThumbPressed)) + Sound.PlayNotification(modRules, null, "Sounds", "ClickSound", null); } return UpPressed || DownPressed || ThumbPressed;