#1050 Extract generic PlayMusicOnMapLoad trait from cnc shellmap script
This commit is contained in:
@@ -17,23 +17,13 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class CncShellmapScriptInfo : ITraitInfo
|
||||
{
|
||||
public string Music = "map1";
|
||||
public object Create(ActorInitializer init) { return new CncShellmapScript(this); }
|
||||
}
|
||||
class CncShellmapScriptInfo : TraitInfo<CncShellmapScript> { }
|
||||
|
||||
class CncShellmapScript: IWorldLoaded, ITick
|
||||
{
|
||||
CncShellmapScriptInfo Info;
|
||||
Dictionary<string, Actor> Actors;
|
||||
static int2 ViewportOrigin;
|
||||
|
||||
public CncShellmapScript(CncShellmapScriptInfo info)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
var b = w.Map.Bounds;
|
||||
@@ -42,30 +32,19 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
Actors = w.WorldActor.Trait<SpawnMapActors>().Actors;
|
||||
|
||||
LoopMusic();
|
||||
|
||||
SetViewport();
|
||||
}
|
||||
|
||||
void LoopMusic()
|
||||
{
|
||||
if (!Game.Settings.Game.ShellmapMusic ||
|
||||
Info.Music == null ||
|
||||
!Rules.Music.ContainsKey(Info.Music))
|
||||
return;
|
||||
|
||||
Sound.PlayMusicThen(Rules.Music[Info.Music], () => LoopMusic());
|
||||
}
|
||||
|
||||
void SetViewport()
|
||||
{
|
||||
var t = (ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed;
|
||||
var loc = ViewportOrigin + new float2(-15,4) * float2.FromAngle( (float)t );
|
||||
Game.viewport.Center(loc);
|
||||
}
|
||||
|
||||
|
||||
int ticks = 0;
|
||||
float speed = 4f;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
SetViewport();
|
||||
|
||||
@@ -358,6 +358,7 @@
|
||||
<Compile Include="HarvesterHuskModifier.cs" />
|
||||
<Compile Include="ThrowsParticle.cs" />
|
||||
<Compile Include="Crates\HideMapCrateAction.cs" />
|
||||
<Compile Include="World\PlayMusicOnMapLoad.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
45
OpenRA.Mods.RA/World/PlayMusicOnMapLoad.cs
Normal file
45
OpenRA.Mods.RA/World/PlayMusicOnMapLoad.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class PlayMusicOnMapLoadInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Music = null;
|
||||
public readonly bool Loop = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new PlayMusicOnMapLoad(this); }
|
||||
}
|
||||
|
||||
class PlayMusicOnMapLoad : IWorldLoaded
|
||||
{
|
||||
PlayMusicOnMapLoadInfo Info;
|
||||
|
||||
public PlayMusicOnMapLoad(PlayMusicOnMapLoadInfo info) { Info = info; }
|
||||
|
||||
public void WorldLoaded(World w) { PlayMusic(); }
|
||||
|
||||
void PlayMusic()
|
||||
{
|
||||
var onComplete = Info.Loop ? (Action)PlayMusic : () => {};
|
||||
|
||||
if (Game.Settings.Game.ShellmapMusic &&
|
||||
Rules.Music.ContainsKey(Info.Music))
|
||||
Sound.PlayMusicThen(Rules.Music[Info.Music], onComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,6 +1012,9 @@ Rules:
|
||||
-SpawnMPUnits:
|
||||
-MPStartLocations:
|
||||
-CrateSpawner:
|
||||
PlayMusicOnMapLoad:
|
||||
Music: map1
|
||||
Loop: true
|
||||
CncShellmapScript:
|
||||
LoadWidgetAtGameStart:
|
||||
Widget: MENU_BACKGROUND
|
||||
|
||||
Reference in New Issue
Block a user