public TransformationManager(Vector3 pos) { Position = pos; Orientation = Quaternion.Identity; ScaleValue = new Vector3(1, 1, 1); BeenModified = true; }
public TransformationManager(Vector3 pos, Vector3 axis, float angle, float scale) { Position = pos; Orientation = Quaternion.FromAxisAngle(axis, angle); ScaleValue = new Vector3(scale, scale, scale); BeenModified = true; }
public TransformationManager(Vector3 pos, Quaternion orient) { Position = pos; Orientation = orient; ScaleValue = new Vector3(1, 1, 1); BeenModified = true; }
public TransformationManager(Vector3 pos, Quaternion orient, Vector3 scale) { Position = new ValuePointer<Vector3>(pos); Orientation = orient; ScaleValue = scale; BeenModified = true; }
public void DefaultCollectionValue_GetAt() { DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); IValuable <G> value = Mock.Of <IValuable <G> >(); Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >() { { new DefaultDoubleValue <G>(0), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(1), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultDoubleValue <G>(2), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(4), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultIntValue <G>(5), new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }, { new DefaultLongValue <G>(3), new ValuePointer <G> { Value = value } } }; DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider); ValuePointer <G> result = sut.GetAt(new DefaultIntValue <G>(5), valueProvider); Assert.Equal(value, result.Value); }
public void DefaultValueProvider_GetCollection_WithList() { ValuePointer <G>[] values = new ValuePointer <G>[] { new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() }, new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() }, new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() }, new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() }, new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() }, new ValuePointer <G> { Value = Mock.Of <IValuable <G> >() } }; DefaultValueProvider <G> sut = new DefaultValueProvider <G>(); ICollectionValue <G> result = sut.GetCollection(values, null); Assert.Equal(6, result.Size); }
public void DefinedStaticConstruction() { object s = ""; ValuePointer definedStatic = new ValuePointer(() => s, (o) => s = o, typeof(string), false); definedStatic.Setter("definedStatic.Setter"); Assert.AreEqual("definedStatic.Setter", s); Assert.IsFalse(definedStatic.IsDynamic); }
private ValuePointerWatchdog GetWatchdog(ValuePointer valuePointer) { if (!_watchdogDictionary.ContainsKey(valuePointer)) { _watchdogDictionary.Add(valuePointer, new ValuePointerWatchdog(valuePointer)); } return _watchdogDictionary[valuePointer]; }
public void VarConstruction() { object s = ""; ValuePointer var = new ValuePointer(() => s, (o) => s = o, null, false); var.Setter(1); Assert.AreEqual(1, s); Assert.IsNull(var.DeclaredType); Assert.IsFalse(var.IsDynamic); var.UpdateToCurrentType(); Assert.IsNotNull(var.DeclaredType); try { var.Setter("Var.Setter"); Assert.Fail(); } catch { } }
private int GetRowUnderMouse(UpdateState update) { var mouse = this.GetMousePosition(update.MouseState); var estRow = (int)Math.Floor(mouse.Y / RowHeight) + ScrollOffset; if (estRow >= 0 && estRow < Items.Count) { /** Is this row enabled? **/ var row = Items[estRow]; if (ValuePointer.Get<Boolean>(row.Disabled) && AllowDisabledSelection == false) { return -1; } return estRow; } return -1; }
public void DynamicConstruction() { object s = ""; ValuePointer dynamic = new ValuePointer(() => s, (o) => s = o, null, true); Assert.IsTrue(dynamic.IsDynamic); Assert.IsNull(dynamic.DeclaredType); dynamic.Setter("dynamic.Setter"); Assert.IsTrue(dynamic.IsDynamic); Assert.IsNull(dynamic.DeclaredType); dynamic.UpdateToCurrentType(); Assert.IsTrue(dynamic.IsDynamic); try { dynamic.Setter(123); } catch { Assert.Fail(); } }
public void IncompatibleStaticConstruction() { object s = ""; ValuePointer incompatibleStatic = new ValuePointer(() => s, (o) => s = o, typeof(int), false); Assert.AreEqual(typeof(int), incompatibleStatic.DeclaredType); Assert.IsFalse(incompatibleStatic.IsDynamic); incompatibleStatic.Setter(1); Assert.AreEqual(1, s); Assert.AreEqual(typeof(int), incompatibleStatic.DeclaredType); try { incompatibleStatic.Setter("Fail"); Assert.Fail(); } catch { } }
public void ViewFields(ValuePointer point) { // This method is only used during debugging and development. It allows the inspection of the values // and fields of a `ValuePointer` which is handy for traversing the memory structure of Escape Goat 2. LogWriter.WriteLine(point.Type.Name.ToString()); foreach (var field in point.Type.Fields) { string output; if (field.HasSimpleValue) { output = field.GetValue(point.Address).ToString(); } else { output = field.GetAddress(point.Address).ToString("X"); } LogWriter.WriteLine(" +{0,2:X2} {1} {2} = {3}", field.Offset, field.Type.Name, field.Name, output); } }
public void DefaultGroupValue_Get_Existing() { string pointerName = "grouppointername"; DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>(); DeclaredValuePointer <G> groupPointer = new DeclaredValuePointer <G>("group", valueProvider.Null) { Identifier = pointerName }; List <DeclaredValuePointer <G> > groupPointers = new List <DeclaredValuePointer <G> >() { new DeclaredValuePointer <G>("group"), groupPointer, new DeclaredValuePointer <G>("group") }; Dictionary <string, int> pointerMap = new Dictionary <string, int> { { pointerName, 1 } }; G groupState = Mock.Of <G>(m => m.GroupPointers == groupPointers && m.PointerMap == pointerMap); DefaultStringValue <G> key = new DefaultStringValue <G>(pointerName); DefaultGroupValue <G> sut = new DefaultGroupValue <G>(groupState); ValuePointer <G> result = sut.Get(key, false, valueProvider) as ValuePointer <G>; Assert.Equal(groupPointer, result); }
public Value(BinaryReader reader, Entry parent, int index) { this.parent = parent; this.index = index; type = (Type)reader.ReadByte(); char[] strData = new char[0x1B]; for (int i = 0; i < strData.Length; i++) strData[i] = (char)reader.ReadByte(); name = new string(strData); switch (type) { case Type.Registry: ValueRegistry = reader.ReadInt32(); break; case Type.Integer: ValueInteger = reader.ReadInt32(); break; case Type.String: { ValuePointer p = new ValuePointer(); p.Read(reader); long prevOff = reader.BaseStream.Position; reader.BaseStream.Position = p.block * 0x20; char[] str = new char[p.length]; for (int i = 0; i < str.Length; i++) str[i] = (char)reader.ReadByte(); ValueString = new string(str); reader.BaseStream.Position = prevOff; } break; case Type.Data: { ValuePointer p = new ValuePointer(); p.Read(reader); long prevOff = reader.BaseStream.Position; reader.BaseStream.Position = p.block * 0x20; ValueData = new byte[p.length]; for (int i = 0; i < ValueData.Length; i++) ValueData[i] = reader.ReadByte(); reader.BaseStream.Position = prevOff; } break; } }
public void IncompatibleDynamicConstruction() { object s = ""; ValuePointer incompatibleDynamic = new ValuePointer(() => s, (o) => s = o, typeof(int), true); Assert.IsTrue(incompatibleDynamic.IsDynamic); Assert.AreEqual(typeof(int), incompatibleDynamic.DeclaredType); incompatibleDynamic.Setter("dynamic.Setter"); Assert.IsTrue(incompatibleDynamic.IsDynamic); incompatibleDynamic.UpdateToCurrentType(); Assert.AreEqual(typeof(string), incompatibleDynamic.DeclaredType); Assert.IsTrue(incompatibleDynamic.IsDynamic); try { incompatibleDynamic.Setter(123); Assert.Fail(); } catch { } }
public TransformationManager SetScale(float x, float y, float z) { ScaleValue = new Vector3(x, y, z); BeenModified = true; return this; }
//---------------/ public TransformationManager SetScale(float scale) { ScaleValue = new Vector3(scale, scale, scale); BeenModified = true; return this; }
//---------------/ //---------------/ public TransformationManager Scale(float x, float y, float z) { ScaleValue *= new Vector3(x, y, z); BeenModified = true; LastUpdated = DateTime.Now; FireOnUpdate(); return this; }
public void FuncPointerConstruction() { object s = 123; object func = null; ValuePointer funcPointer = new ValuePointer(() => func, (o) => func = o, typeof(Func<object>), false); funcPointer.Setter(new Func<object> (() => s)); object obj = ((Func<object>)funcPointer.Getter())(); Assert.AreEqual(s, obj); //Check that we got the correct object }
private void _Draw(UISpriteBatch batch) { for (var i = 0; i < NumVisibleRows; i++) { var rowIndex = i + ScrollOffset; if (!(rowIndex < m_Items.Count)) { /** Out of bounds **/ continue; } var row = m_Items[rowIndex]; var rowY = i * RowHeight; var columnX = 0; var selected = rowIndex == m_SelectedRow; var hover = rowIndex == m_HoverRow; if (selected) { /** Draw selection background **/ var white = TextureGenerator.GetPxWhite(batch.GraphicsDevice); DrawLocalTexture(batch, white, null, new Vector2(0, rowY), new Vector2(m_Width, RowHeight), m_SelectionFillColor); } var ts = TextStyle; if (row.CustomStyle != null) { ts = row.CustomStyle; } TextStyle style = null; var isDisabled = ValuePointer.Get <Boolean>(row.Disabled); if (ts != null) { style = ts.Normal; if (ValuePointer.Get <Boolean>(row.UseDisabledStyleByDefault)) { style = ts.Disabled; } if (selected) { style = ts.Selected; } else if (hover) { style = ts.Highlighted; } else if (isDisabled) { style = ts.Disabled; } } for (var x = 0; x < row.Columns.Length; x++) { var columnValue = row.Columns[x]; var columnSpec = m_Columns[x]; var columnBounds = new Rectangle(0, 0, columnSpec.Width, RowHeight); if (columnValue is FSO.Content.Model.ITextureRef) { columnValue = ((FSO.Content.Model.ITextureRef)columnValue).Get(batch.GraphicsDevice); } if (columnValue is string) { DrawLocalString(batch, style.TruncateToWidth((string)columnValue, columnSpec.Width), new Vector2(columnX, rowY), style, columnBounds, columnSpec.Alignment); } else if (columnValue is Texture2D) { var tex = (Texture2D)columnValue; var texWidthDiv4 = tex.Width / 4; /** We assume its a 4 state button **/ Rectangle from = new Rectangle(texWidthDiv4 * columnSpec.TextureDefaultFrame, 0, texWidthDiv4, tex.Height); if (selected) { from.X = texWidthDiv4 * columnSpec.TextureSelectedFrame; } else if (hover) { from.X = texWidthDiv4 * columnSpec.TextureHoverFrame; } else if (isDisabled) { from.X = texWidthDiv4 * columnSpec.TextureDisabledFrame; } var destWidth = texWidthDiv4; var destHeight = tex.Height; if (columnSpec.TextureBounds != null && columnSpec.TextureBounds.HasValue) { var boundsX = columnSpec.TextureBounds.Value.X; var boundsY = columnSpec.TextureBounds.Value.Y; if (!columnSpec.TextureMaintainAspectRatio) { destWidth = (int)boundsX; destHeight = (int)boundsY; } else { if (destWidth > destHeight) { destWidth = (int)boundsX; destHeight = (int)(((float)tex.Height / (float)texWidthDiv4) * destWidth); } else { destHeight = (int)boundsY; destWidth = (int)(((float)texWidthDiv4 / (float)tex.Height) * destHeight); } } } var to = new Vector2(columnX, rowY); if ((columnSpec.Alignment & TextAlignment.Middle) == TextAlignment.Middle) { to.Y = rowY + ((RowHeight - destHeight) / 2); } else if ((columnSpec.Alignment & TextAlignment.Bottom) == TextAlignment.Bottom) { to.Y = rowY + ((RowHeight - destHeight)); } if ((columnSpec.Alignment & TextAlignment.Center) == TextAlignment.Center) { to.X = columnX + ((columnBounds.Width - destWidth) / 2); } else if ((columnSpec.Alignment & TextAlignment.Right) == TextAlignment.Right) { to.X = columnX + (columnBounds.Width - destWidth); } DrawLocalTexture(batch, (Texture2D)columnValue, from, to, new Vector2((float)destWidth / (float)texWidthDiv4, (float)destHeight / (float)tex.Height)); } else if (columnValue is UIContainer) { var container = (UIContainer)columnValue; container.Position = this.Position + new Vector2(columnX, rowY); container.Parent = this.Parent; container.InvalidateMatrix(); container.PreDraw(batch); container.Draw(batch); container.Parent = null; } else if (columnValue != null) { //Convert it to a string DrawLocalString(batch, (string)columnValue.ToString(), new Vector2(columnX, rowY), style, columnBounds, columnSpec.Alignment); } columnX += columnSpec.Width; } } }
internal static void AddVariable(string name, ValuePointer valuePointer) { _variableStore.Add(name, valuePointer); }
public TransformationManager(Vector3 pos, Quaternion orient, Vector3 scale) { Position = new ValuePointer<Vector3>(pos); Orientation = orient; ScaleValue = scale; BeenModified = true; LastUpdated = DateTime.Now; FireOnUpdate(); }
//---------------/ public TransformationManager SetOrientation(Quaternion orient) { Orientation = orient; BeenModified = true; return this; }
internal ValuePointerWatchdog(ValuePointer watchedPointer) { _watchedPointer = watchedPointer; }
public TransformationManager SetScale(float scale) { ScaleValue = new Vector3(scale, scale, scale); BeenModified = true; LastUpdated = DateTime.Now; FireOnUpdate(); return this; }
//---------------/ public TransformationManager SetScale(Vector3 scale) { ScaleValue = scale; BeenModified = true; return this; }
public TransformationManager Translate(float x, float y, float z) { Position += new Vector3(x, y, z); BeenModified = true; return this; }
/*public TransformationManager SetOrientation(float pitch, float yaw, float roll) { Orientation = Quaternion.FromEulerAngles(pitch, yaw, roll); BeenModified = true; return this; }*/ //---------------/ public TransformationManager SetPosition(Vector3 pos) { Position = pos; BeenModified = true; return this; }
public void ActionPointerConstruction() { object s = 123; object func = null; ValuePointer funcPointer = new ValuePointer(() => func, (o) => func = o, typeof(Action<object>), false); funcPointer.Setter(new Action<object>((val) => s = val)); ((Action<object>)funcPointer.Getter())(12); Assert.AreEqual(12, s); //Check that the action correctly set 12 }
/// <summary> /// Adds a variable to the session variable store /// </summary> /// <param name="name"></param> /// <param name="pointer"></param> public void AddVariable(string name, ValuePointer pointer) { _variableStore.Add(name, pointer); }
//---------------/ public TransformationManager Translate(Vector3 pos) { Position += pos; BeenModified = true; return this; }
//---------------/ public TransformationManager Rotate(Quaternion orient) { Orientation = Quaternion.Multiply(Orientation, orient); BeenModified = true; return this; }
public TransformationManager Scale(Vector3 scale) { ScaleValue *= scale; BeenModified = true; LastUpdated = DateTime.Now; FireOnUpdate(); return this; }