diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 46e8e670aa..5de01b3dca 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -3,7 +3,7 @@ Debug x86 - 9.0.30729 + 9.0.21022 2.0 {0DFB103F-2962-400F-8C6D-E2C28CCBA633} WinExe @@ -230,6 +230,7 @@ + diff --git a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs old mode 100644 new mode 100755 index 9ec576034c..31cf6032df --- a/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs +++ b/OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs @@ -10,6 +10,8 @@ using OpenRA.FileFormats; using OpenRA.Server; +using System.Net; +using System.IO; namespace OpenRA.Widgets.Delegates { @@ -27,6 +29,8 @@ namespace OpenRA.Widgets.Delegates var version = widget.GetWidget("VERSION_STRING"); + var motd = widget.GetWidget("MOTD_SCROLLER"); + if (FileSystem.Exists("VERSION")) { var s = FileSystem.Open("VERSION"); @@ -35,6 +39,33 @@ namespace OpenRA.Widgets.Delegates MasterServerQuery.OnVersion += v => { if (!string.IsNullOrEmpty(v)) version.Text += "\nLatest: " + v; }; MasterServerQuery.GetCurrentVersion(Game.Settings.Server.MasterServer); } + else + { + version.Text = "Dev Build"; + } + + if (motd != null) + { + motd.Text = "Welcome to OpenRA. MOTD unable to be loaded from server."; + + string URL = "http://open-ra.org/master/motd.php?v=" + version.Text; + + WebRequest req = WebRequest.Create(URL); + StreamReader reader = null; + try + { + reader = new StreamReader(req.GetResponse().GetResponseStream()); + } + catch (WebException e) + { + reader.Close(); + return; + } + var result = reader.ReadToEnd(); + reader.Close(); + + motd.Text = result; + } } } } diff --git a/OpenRA.Game/Widgets/ScrollingTextWidget.cs b/OpenRA.Game/Widgets/ScrollingTextWidget.cs new file mode 100755 index 0000000000..ca54b92b69 --- /dev/null +++ b/OpenRA.Game/Widgets/ScrollingTextWidget.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; + +namespace OpenRA.Widgets +{ + class ScrollingTextWidget : Widget + { + public string Text = ""; + public string Background = null; + + public bool Bold = false; + + public int ScrollLength = 200; + + // ticks per single letter scroll + public int ScrollRate = 4; + + private string ScrollBuffer = ""; + + private int ScrollLocation = 0; + private int ScrollTick = 0; + + public Func GetText; + public Func GetBackground; + + public ScrollingTextWidget() + : base() + { + GetText = () => Text; + GetBackground = () => Background; + } + + protected ScrollingTextWidget(ScrollingTextWidget other) + : base(other) + { + Text = other.Text; + GetText = other.GetText; + Bold = other.Bold; + GetBackground = other.GetBackground; + } + + public override void Tick(World world) + { + UpdateScrollBuffer(); + } + + private void UpdateScrollBuffer() + { + ScrollTick++; + + if (ScrollTick < ScrollRate) + { + return; + } + + ScrollTick = 0; + ScrollBuffer = ""; + + if (Text.Substring(Text.Length - 4, 3) != " ") + { + Text += " "; + } + + int tempScrollLocation = ScrollLocation; + for (int i = 0; i < ScrollLength; ++i) + { + ScrollBuffer += Text.Substring(tempScrollLocation, 1); + tempScrollLocation = (tempScrollLocation + 1) % Text.Length; + } + + ScrollLocation = (ScrollLocation + 1) % Text.Length; + } + + public override void DrawInner(World world) + { + var bg = GetBackground(); + + if (bg != null) + WidgetUtils.DrawPanel(bg, RenderBounds); + + var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; + var text = GetText(); + if (text == null) + return; + + int2 textSize = font.Measure(text); + int2 position = RenderOrigin + new int2(0, (Bounds.Height - textSize.Y) / 2); + + Game.Renderer.EnableScissor(position.X, position.Y, Bounds.Width, Bounds.Height); + font.DrawText(ScrollBuffer, position, Color.White); + Game.Renderer.DisableScissor(); + } + + public override Widget Clone() { return new ScrollingTextWidget(this); } + } +} diff --git a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs index 36d8f8ddd5..fcf9f73197 100755 --- a/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportScrollControllerWidget.cs @@ -171,4 +171,4 @@ namespace OpenRA.Widgets return (d.Includes(s) != val) ? d ^ s : d; } } -} \ No newline at end of file +} diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index b26327a0bf..8ea192dd5c 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -6,6 +6,39 @@ Background@MAINMENU_BG: Height:290 Delegate:MainMenuButtonsDelegate Children: + Background@MOTD_BG: + Id:MOTD_BG + X:0 - PARENT_LEFT + WINDOW_RIGHT/3 + Y:0 - PARENT_TOP + 44 + Width:WINDOW_RIGHT/3 + Height:30 + Background:dialog4 + Children: + ScrollingText@MOTD_SCROLLER: + Id:MOTD_SCROLLER + X:15 + Y:2 + Width:PARENT_RIGHT - 30 + Height:25 + ScrollRate:8 + Text:This is a super duper huge long Scrolling Test + Background@MOTD_LABEL_BG + Id:MOTD_LABEL_BG + X:0 - PARENT_LEFT + (WINDOW_RIGHT/16)*7 + Y:0 - PARENT_TOP + 15 + Width:(WINDOW_RIGHT/16)*2 + Height:30 + Background:dialog4 + Children: + Label@MOTD_LABEL + Id:MOTD_LABEL + X:0 + Y:2 + Width:(WINDOW_RIGHT/16)*2 + Height:25 + Text:Message of the Day + Align:Center + Bold:True Label@MAINMENU_LABEL_TITLE: Id:MAINMENU_LABEL_TITLE X:0 diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index 78b1936070..76228caec5 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -6,6 +6,39 @@ Background@MAINMENU_BG: Height:290 Delegate:MainMenuButtonsDelegate Children: + Background@MOTD_BG: + Id:MOTD_BG + X:0 - PARENT_LEFT + WINDOW_RIGHT/3 + Y:0 - PARENT_TOP + 44 + Width:WINDOW_RIGHT/3 + Height:30 + Background:dialog4 + Children: + ScrollingText@MOTD_SCROLLER: + Id:MOTD_SCROLLER + X:15 + Y:2 + Width:PARENT_RIGHT - 30 + Height:25 + ScrollRate:8 + Text:This is a super duper huge long Scrolling Test + Background@MOTD_LABEL_BG + Id:MOTD_LABEL_BG + X:0 - PARENT_LEFT + (WINDOW_RIGHT/16)*7 + Y:0 - PARENT_TOP + 15 + Width:(WINDOW_RIGHT/16)*2 + Height:30 + Background:dialog4 + Children: + Label@MOTD_LABEL + Id:MOTD_LABEL + X:0 + Y:2 + Width:(WINDOW_RIGHT/16)*2 + Height:25 + Text:Message of the Day + Align:Center + Bold:True Label@MAINMENU_LABEL_TITLE: Id:MAINMENU_LABEL_TITLE X:0