MOTD ticker. ScrollingText Widget
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
<ProductVersion>9.0.30729</ProductVersion>
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid>
|
<ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
@@ -230,6 +230,7 @@
|
|||||||
<Compile Include="Traits\Valued.cs" />
|
<Compile Include="Traits\Valued.cs" />
|
||||||
<Compile Include="Traits\World\BibLayer.cs" />
|
<Compile Include="Traits\World\BibLayer.cs" />
|
||||||
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
||||||
|
<Compile Include="Widgets\ScrollingTextWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||||
|
|||||||
31
OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs
Normal file → Executable file
31
OpenRA.Game/Widgets/Delegates/MainMenuButtonsDelegate.cs
Normal file → Executable file
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Server;
|
using OpenRA.Server;
|
||||||
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace OpenRA.Widgets.Delegates
|
namespace OpenRA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
@@ -27,6 +29,8 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
|
|
||||||
var version = widget.GetWidget<LabelWidget>("VERSION_STRING");
|
var version = widget.GetWidget<LabelWidget>("VERSION_STRING");
|
||||||
|
|
||||||
|
var motd = widget.GetWidget<ScrollingTextWidget>("MOTD_SCROLLER");
|
||||||
|
|
||||||
if (FileSystem.Exists("VERSION"))
|
if (FileSystem.Exists("VERSION"))
|
||||||
{
|
{
|
||||||
var s = FileSystem.Open("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.OnVersion += v => { if (!string.IsNullOrEmpty(v)) version.Text += "\nLatest: " + v; };
|
||||||
MasterServerQuery.GetCurrentVersion(Game.Settings.Server.MasterServer);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
99
OpenRA.Game/Widgets/ScrollingTextWidget.cs
Executable file
99
OpenRA.Game/Widgets/ScrollingTextWidget.cs
Executable file
@@ -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<string> GetText;
|
||||||
|
public Func<string> 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); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -171,4 +171,4 @@ namespace OpenRA.Widgets
|
|||||||
return (d.Includes(s) != val) ? d ^ s : d;
|
return (d.Includes(s) != val) ? d ^ s : d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,39 @@ Background@MAINMENU_BG:
|
|||||||
Height:290
|
Height:290
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:MainMenuButtonsDelegate
|
||||||
Children:
|
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:
|
Label@MAINMENU_LABEL_TITLE:
|
||||||
Id:MAINMENU_LABEL_TITLE
|
Id:MAINMENU_LABEL_TITLE
|
||||||
X:0
|
X:0
|
||||||
|
|||||||
@@ -6,6 +6,39 @@ Background@MAINMENU_BG:
|
|||||||
Height:290
|
Height:290
|
||||||
Delegate:MainMenuButtonsDelegate
|
Delegate:MainMenuButtonsDelegate
|
||||||
Children:
|
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:
|
Label@MAINMENU_LABEL_TITLE:
|
||||||
Id:MAINMENU_LABEL_TITLE
|
Id:MAINMENU_LABEL_TITLE
|
||||||
X:0
|
X:0
|
||||||
|
|||||||
Reference in New Issue
Block a user