Files
OpenRA/OpenRA.Mods.Cnc/Traits/Render/WithVoxelBody.cs
let5sne.win10 9cf6ebb986
Some checks failed
Continuous Integration / Linux (.NET 8.0) (push) Has been cancelled
Continuous Integration / Windows (.NET 8.0) (push) Has been cancelled
Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 21:46:54 +08:00

69 lines
2.3 KiB
C#

#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits.Render
{
[Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")]
public class WithVoxelBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
{
public readonly string Sequence = "idle";
public readonly WVec Offset;
[Desc("Defines if the Voxel should have a shadow.")]
public readonly bool ShowShadow = true;
public override object Create(ActorInitializer init) { return new WithVoxelBody(init.Self, this); }
public IEnumerable<ModelAnimation> RenderPreviewVoxels(IModelCache cache,
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
{
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
var model = cache.GetModelSequence(image, Sequence);
yield return new ModelAnimation(model, () => Offset,
() => body.QuantizeOrientation(orientation(), facings),
() => false, () => 0, ShowShadow);
}
}
public class WithVoxelBody : ConditionalTrait<WithVoxelBodyInfo>, IAutoMouseBounds
{
readonly ModelAnimation modelAnimation;
readonly RenderVoxels rv;
public WithVoxelBody(Actor self, WithVoxelBodyInfo info)
: base(info)
{
var body = self.Trait<BodyOrientation>();
rv = self.Trait<RenderVoxels>();
var model = rv.Renderer.ModelCache.GetModelSequence(rv.Image, info.Sequence);
modelAnimation = new ModelAnimation(model, () => info.Offset,
() => body.QuantizeOrientation(self.Orientation),
() => IsTraitDisabled, () => 0, info.ShowShadow);
rv.Add(modelAnimation);
}
Rectangle IAutoMouseBounds.AutoMouseoverBounds(Actor self, WorldRenderer wr)
{
return modelAnimation.ScreenBounds(self.CenterPosition, wr, rv.Info.Scale);
}
}
}