Add skin property image.frames and image.index.
This commit is contained in:
@@ -29,19 +29,12 @@ namespace Cryville.Crtr.Components {
|
|||||||
return Rect.width / Rect.height;
|
return Rect.width / Rect.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool _loaded;
|
|
||||||
Material _mat;
|
Material _mat;
|
||||||
public void Bind(Material mat) {
|
public void Bind(Material mat) {
|
||||||
_loaded = true;
|
|
||||||
_mat = mat;
|
_mat = mat;
|
||||||
Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
public void Load() {
|
|
||||||
_loaded = true;
|
|
||||||
Reload();
|
|
||||||
}
|
|
||||||
public void Reload() {
|
public void Reload() {
|
||||||
if (!_loaded) return;
|
|
||||||
if (!string.IsNullOrEmpty(FrameName)) {
|
if (!string.IsNullOrEmpty(FrameName)) {
|
||||||
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
if (ChartPlayer.frames.ContainsKey(FrameName)) {
|
||||||
Frame = ChartPlayer.frames[FrameName];
|
Frame = ChartPlayer.frames[FrameName];
|
||||||
@@ -60,7 +53,9 @@ namespace Cryville.Crtr.Components {
|
|||||||
|
|
||||||
public class SpritePlane : SpriteBase {
|
public class SpritePlane : SpriteBase {
|
||||||
public SpritePlane() {
|
public SpritePlane() {
|
||||||
SubmitProperty("frame", new PropOp.String(v => Frame = v));
|
SubmitProperty("frame", new PropOp.String(v => { Frames = new string[] { v }; Index = 0; }));
|
||||||
|
SubmitProperty("frames", new PropOp.StringArray(v => Frames = v));
|
||||||
|
SubmitProperty("index", new PropOp.Integer(v => Index = v));
|
||||||
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v, v => (FitMode)v));
|
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v, v => (FitMode)v));
|
||||||
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));
|
||||||
}
|
}
|
||||||
@@ -83,35 +78,53 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SpriteInfo frameInfo = new SpriteInfo();
|
int m_index;
|
||||||
|
public int Index {
|
||||||
public string Frame {
|
get { return m_index; }
|
||||||
get { return frameInfo.FrameName; }
|
|
||||||
set {
|
set {
|
||||||
frameInfo.FrameName = value;
|
m_index = value;
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SpriteInfo[] m_frames = new SpriteInfo[0];
|
||||||
|
public string[] Frames {
|
||||||
|
set {
|
||||||
|
m_frames = new SpriteInfo[value.Length];
|
||||||
|
for (int i = 0; i < value.Length; i++) {
|
||||||
|
m_frames[i] = new SpriteInfo() { FrameName = value[i] };
|
||||||
|
}
|
||||||
|
OnFrameUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected SpriteInfo CurrentFrame {
|
||||||
|
get {
|
||||||
|
if (m_index < 0) m_index = 0;
|
||||||
|
else if (m_index >= m_frames.Length) m_index = m_frames.Length - 1;
|
||||||
|
return m_frames[m_index];
|
||||||
|
}
|
||||||
|
}
|
||||||
protected void OnFrameUpdate() {
|
protected void OnFrameUpdate() {
|
||||||
if (!mesh.Initialized) return;
|
if (!mesh.Initialized) return;
|
||||||
if (frameInfo.Frame == null) {
|
if (CurrentFrame.Frame == null) {
|
||||||
mesh.Renderer.enabled = false;
|
mesh.Renderer.enabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mesh.Renderer.enabled = true;
|
mesh.Renderer.enabled = true;
|
||||||
|
mesh.Renderer.material.mainTexture = CurrentFrame.Frame.Texture;
|
||||||
UpdateUV();
|
UpdateUV();
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
UpdateZIndex();
|
UpdateZIndex();
|
||||||
}
|
}
|
||||||
protected virtual void UpdateUV() {
|
protected virtual void UpdateUV() {
|
||||||
if (frameInfo.Frame == null) {
|
var frame = CurrentFrame;
|
||||||
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frameInfo.FrameName);
|
if (frame.Frame == null) {
|
||||||
|
Logger.Log("main", 4, "Skin", "Unable to load texture {0}", frame.FrameName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector2[] muv = OriginalUV;
|
Vector2[] muv = OriginalUV;
|
||||||
Vector2[] uv = new Vector2[muv.Length];
|
Vector2[] uv = new Vector2[muv.Length];
|
||||||
for (int i = 0; i < uv.Length; i++) {
|
for (int i = 0; i < uv.Length; i++) {
|
||||||
uv[i] = frameInfo.Frame.GetUV(muv[i]);
|
uv[i] = frame.Frame.GetUV(muv[i]);
|
||||||
}
|
}
|
||||||
mesh.Mesh.uv = uv;
|
mesh.Mesh.uv = uv;
|
||||||
}
|
}
|
||||||
@@ -124,7 +137,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
UpdateOpacity();
|
UpdateOpacity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void UpdateOpacity() {
|
protected void UpdateOpacity() {
|
||||||
if (!mesh.Initialized) return;
|
if (!mesh.Initialized) return;
|
||||||
var c = mesh.Renderer.material.color;
|
var c = mesh.Renderer.material.color;
|
||||||
c.a = _opacity;
|
c.a = _opacity;
|
||||||
@@ -144,7 +157,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateScale() {
|
protected override void UpdateScale() {
|
||||||
if (frameInfo.Frame == null) return;
|
if (CurrentFrame.Frame == null) return;
|
||||||
base.UpdateScale();
|
base.UpdateScale();
|
||||||
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
if (m_fit != FitMode.none && Scale.x != Scale.y) m_fit = FitMode.none;
|
||||||
}
|
}
|
||||||
@@ -153,8 +166,8 @@ namespace Cryville.Crtr.Components {
|
|||||||
get {
|
get {
|
||||||
switch (m_fit) {
|
switch (m_fit) {
|
||||||
case FitMode.none: return Vector3.one;
|
case FitMode.none: return Vector3.one;
|
||||||
case FitMode.width: return new Vector3(1, 1, 1 / frameInfo.Ratio);
|
case FitMode.width: return new Vector3(1, 1, 1 / CurrentFrame.Ratio);
|
||||||
case FitMode.height: return new Vector3(frameInfo.Ratio, 1, 1);
|
case FitMode.height: return new Vector3(CurrentFrame.Ratio, 1, 1);
|
||||||
default: throw new NotSupportedException("Unsupported fit mode");
|
default: throw new NotSupportedException("Unsupported fit mode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +175,6 @@ namespace Cryville.Crtr.Components {
|
|||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
InternalInit();
|
InternalInit();
|
||||||
frameInfo.Bind(mesh.Renderer.material);
|
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
UpdateOpacity();
|
UpdateOpacity();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ namespace Cryville.Crtr.Components {
|
|||||||
Vector2[] muv = OriginalUV;
|
Vector2[] muv = OriginalUV;
|
||||||
Vector2[] uv = new Vector2[muv.Length];
|
Vector2[] uv = new Vector2[muv.Length];
|
||||||
|
|
||||||
var or = frameInfo.Ratio;
|
var frame = CurrentFrame;
|
||||||
|
var or = frame.Ratio;
|
||||||
var sr = Scale.x / Scale.y;
|
var sr = Scale.x / Scale.y;
|
||||||
var b = new Vector2(
|
var b = new Vector2(
|
||||||
(or / sr) * _border.x,
|
(or / sr) * _border.x,
|
||||||
@@ -71,7 +72,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
case 3: y = 1; break;
|
case 3: y = 1; break;
|
||||||
default: throw new NotSupportedException("Built-in resource corrupted");
|
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||||
}
|
}
|
||||||
uv[i] = frameInfo.Frame.GetUV(x, y);
|
uv[i] = frame.Frame.GetUV(x, y);
|
||||||
bx -= 0.5f; y -= 0.5f;
|
bx -= 0.5f; y -= 0.5f;
|
||||||
vert[i] = new Vector3(bx, 0, y);
|
vert[i] = new Vector3(bx, 0, y);
|
||||||
}
|
}
|
||||||
@@ -80,9 +81,9 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
frameInfo.Load();
|
|
||||||
InternalInit("quad_scale3h");
|
InternalInit("quad_scale3h");
|
||||||
OnFrameUpdate();
|
OnFrameUpdate();
|
||||||
|
UpdateOpacity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ namespace Cryville.Crtr.Components {
|
|||||||
verts.Clear();
|
verts.Clear();
|
||||||
uvs.Clear();
|
uvs.Clear();
|
||||||
foreach (var f in m_frames) {
|
foreach (var f in m_frames) {
|
||||||
f.Value.Load();
|
|
||||||
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
|
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
|
||||||
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height for text component");
|
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height for text component");
|
||||||
var tex = f.Value.Frame.Texture;
|
var tex = f.Value.Frame.Texture;
|
||||||
|
|||||||
@@ -60,6 +60,24 @@ namespace Cryville.Crtr {
|
|||||||
_cb(GetOperand(0).AsString());
|
_cb(GetOperand(0).AsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class StringArray : PropOp {
|
||||||
|
readonly Action<string[]> _cb;
|
||||||
|
public StringArray(Action<string[]> cb) { _cb = cb; }
|
||||||
|
protected unsafe override void Execute() {
|
||||||
|
var op = GetOperand(0);
|
||||||
|
int arrtype; int len;
|
||||||
|
op.GetArraySuffix(out arrtype, out len);
|
||||||
|
if (arrtype != PdtInternalType.String) throw new InvalidCastException("Not an array of strings");
|
||||||
|
var result = new string[len];
|
||||||
|
int o = 0;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
string v = op.AsString(o);
|
||||||
|
o += v.Length * sizeof(char) + sizeof(int);
|
||||||
|
result[i] = v;
|
||||||
|
}
|
||||||
|
_cb(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
public class TargetString : PropOp {
|
public class TargetString : PropOp {
|
||||||
readonly Func<RTargetString> _cb;
|
readonly Func<RTargetString> _cb;
|
||||||
public TargetString(Func<RTargetString> cb) { _cb = cb; }
|
public TargetString(Func<RTargetString> cb) { _cb = cb; }
|
||||||
|
|||||||
Reference in New Issue
Block a user