Move NullLoadScreen, DefaultLoadScreen and LoadWidgetAtGameStart to Mods.Common

This commit is contained in:
reaperrr
2014-11-07 15:13:58 +01:00
parent 2ab8b28bcf
commit 0807b7009b
5 changed files with 6 additions and 6 deletions

View File

@@ -0,0 +1,75 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common
{
public class DefaultLoadScreen : ILoadScreen
{
Stopwatch lastUpdate = Stopwatch.StartNew();
Renderer r;
Rectangle stripeRect;
float2 logoPos;
Sprite stripe, logo;
string[] messages;
public void Init(Manifest m, Dictionary<string, string> info)
{
// Avoid standard loading mechanisms so we
// can display the loadscreen as early as possible
r = Game.Renderer;
if (r == null)
return;
messages = info["Text"].Split(',');
var s = new Sheet(Platform.ResolvePath(info["Image"]));
logo = new Sprite(s, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha);
stripe = new Sprite(s, new Rectangle(256, 0, 256, 256), TextureChannel.Alpha);
stripeRect = new Rectangle(0, r.Resolution.Height / 2 - 128, r.Resolution.Width, 256);
logoPos = new float2(r.Resolution.Width / 2 - 128, r.Resolution.Height / 2 - 128);
}
public void Display()
{
if (r == null)
return;
// Update text at most every 0.5 seconds
if (lastUpdate.Elapsed.TotalSeconds < 0.5)
return;
if (r.Fonts == null)
return;
lastUpdate.Restart();
var text = messages.Random(Game.CosmeticRandom);
var textSize = r.Fonts["Bold"].Measure(text);
r.BeginFrame(int2.Zero, 1f);
WidgetUtils.FillRectWithSprite(stripeRect, stripe);
r.RgbaSpriteRenderer.DrawSprite(logo, logoPos);
r.Fonts["Bold"].DrawText(text, new float2(r.Resolution.Width - textSize.X - 20, r.Resolution.Height - textSize.Y - 20), Color.White);
r.EndFrame(new NullInputHandler());
}
public void StartGame()
{
Game.TestAndContinue();
}
}
}

View File

@@ -0,0 +1,41 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common
{
public class LoadWidgetAtGameStartInfo : ITraitInfo
{
public readonly string Widget = null;
public readonly bool ClearRoot = true;
public object Create(ActorInitializer init) { return new LoadWidgetAtGameStart(this); }
}
public class LoadWidgetAtGameStart: IWorldLoaded
{
readonly LoadWidgetAtGameStartInfo Info;
public LoadWidgetAtGameStart(LoadWidgetAtGameStartInfo Info)
{
this.Info = Info;
}
public void WorldLoaded(World world, WorldRenderer wr)
{
// Clear any existing widget state
if (Info.ClearRoot)
Ui.ResetAll();
Game.LoadWidget(world, Info.Widget, Ui.Root, new WidgetArgs());
}
}
}

View File

@@ -0,0 +1,36 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common
{
public class NullLoadScreen : ILoadScreen
{
public void Init(Manifest m, Dictionary<string, string> info) {}
public void Display()
{
if (Game.Renderer == null)
return;
// Draw a black screen
Game.Renderer.BeginFrame(int2.Zero, 1f);
Game.Renderer.EndFrame( new NullInputHandler() );
}
public void StartGame()
{
Ui.ResetAll();
}
}
}

View File

@@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CommonTraitsInterfaces.cs" />
<Compile Include="DefaultLoadScreen.cs" />
<Compile Include="Effects\Beacon.cs" />
<Compile Include="Effects\Bullet.cs" />
<Compile Include="Effects\Contrail.cs" />
@@ -75,10 +76,12 @@
<Compile Include="Graphics\TextRenderable.cs" />
<Compile Include="Graphics\VoxelActorPreview.cs" />
<Compile Include="Graphics\VoxelRenderable.cs" />
<Compile Include="LoadWidgetAtGameStart.cs" />
<Compile Include="ModChooserLoadScreen.cs" />
<Compile Include="Modifiers\DisabledOverlay.cs" />
<Compile Include="Modifiers\HiddenUnderFog.cs" />
<Compile Include="Modifiers\UpgradeOverlay.cs" />
<Compile Include="NullLoadScreen.cs" />
<Compile Include="Orders\DeployOrderTargeter.cs" />
<Compile Include="Orders\EnterAlliedActorTargeter.cs" />
<Compile Include="Orders\UnitOrderTargeter.cs" />