public override void Undo(BHAV bhav, UIBHAVEditor editor) { var newInst = new BHAVInstruction[bhav.Instructions.Length + 1]; byte index = 0; for (int i = 0; i < newInst.Length; i++) { if (i == Primitive.InstPtr) newInst[i] = Primitive.Instruction; else { var inst = bhav.Instructions[index++]; newInst[i] = inst; if (inst.TruePointer < 252 && inst.TruePointer >= Primitive.InstPtr) inst.TruePointer++; if (inst.FalsePointer < 252 && inst.FalsePointer >= Primitive.InstPtr) inst.FalsePointer++; } } foreach (var prim in FromTrue) { prim.TrueUI = Primitive; prim.Instruction.TruePointer = Primitive.InstPtr; } foreach (var prim in FromFalse) { prim.FalseUI = Primitive; prim.Instruction.FalsePointer = Primitive.InstPtr; } bhav.Instructions = newInst; editor.BHAVView.Primitives.Add(Primitive); editor.BHAVView.RealPrim.Insert(Primitive.InstPtr, Primitive); editor.BHAVView.Add(Primitive); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { if (NewPrimitive.Type != PrimBoxType.Primitive) { editor.BHAVView.Primitives.Add(NewPrimitive); editor.BHAVView.Add(NewPrimitive); } else { var newInst = new BHAVInstruction[bhav.Instructions.Length + 1]; for (int i = 0; i < bhav.Instructions.Length; i++) { newInst[i] = bhav.Instructions[i]; } newInst[newInst.Length - 1] = NewPrimitive.Instruction; NewPrimitive.InstPtr = (byte)(newInst.Length - 1); bhav.Instructions = newInst; editor.BHAVView.AddPrimitive(NewPrimitive); NewPrimitive.UpdateDisplay(); Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); } }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { var newInst = new BHAVInstruction[bhav.Instructions.Length - 1]; byte index = 0; for (int i = 0; i < bhav.Instructions.Length; i++) { if (i != Primitive.InstPtr) { var inst = bhav.Instructions[i]; newInst[index++] = inst; if (inst.TruePointer < 253 && inst.TruePointer > Primitive.InstPtr) inst.TruePointer--; if (inst.FalsePointer < 253 && inst.FalsePointer > Primitive.InstPtr) inst.FalsePointer--; } } foreach (var prim in FromTrue) { prim.TrueUI = null; prim.Instruction.TruePointer = 253; } foreach (var prim in FromFalse) { prim.FalseUI = null; prim.Instruction.FalsePointer = 253; } bhav.Instructions = newInst; editor.BHAVView.RemovePrimitive(Primitive); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { //primitive we added should be at the end var newInst = new BHAVInstruction[bhav.Instructions.Length - 1]; for (int i = 0; i < newInst.Length; i++) { newInst[i] = bhav.Instructions[i]; } bhav.Instructions = newInst; editor.BHAVView.RemovePrimitive(NewPrimitive); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { var newInst = new BHAVInstruction[bhav.Instructions.Length + 1]; for (int i = 0; i < bhav.Instructions.Length; i++) { newInst[i] = bhav.Instructions[i]; } newInst[newInst.Length - 1] = NewPrimitive.Instruction; NewPrimitive.InstPtr = (byte)(newInst.Length - 1); bhav.Instructions = newInst; editor.BHAVView.AddPrimitive(NewPrimitive); NewPrimitive.UpdateDisplay(); FSO.SimAntics.VM.BHAVChanged(bhav); }
/// <summary> /// Reads a BHAV from a stream. /// </summary> /// <param name="iff">Iff instance.</param> /// <param name="stream">A Stream instance holding a BHAV chunk.</param> public override void Read(IffFile iff, System.IO.Stream stream) { using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN)) { var version = io.ReadUInt16(); uint count = 0; if (version == 0x8000) { count = io.ReadUInt16(); io.Skip(8); } else if (version == 0x8001) { count = io.ReadUInt16(); var unknown = io.ReadBytes(8); } else if (version == 0x8002) { count = io.ReadUInt16(); this.Type = io.ReadByte(); this.Args = io.ReadByte(); this.Locals = io.ReadUInt16(); this.Flags = io.ReadUInt16(); io.Skip(2); } else if (version == 0x8003) { this.Type = io.ReadByte(); this.Args = io.ReadByte(); this.Locals = io.ReadByte(); io.Skip(2); this.Flags = io.ReadUInt16(); count = io.ReadUInt32(); } Instructions = new BHAVInstruction[count]; for (var i = 0; i < count; i++) { var instruction = new BHAVInstruction(); instruction.Opcode = io.ReadUInt16(); instruction.TruePointer = io.ReadByte(); instruction.FalsePointer = io.ReadByte(); instruction.Operand = io.ReadBytes(8); Instructions[i] = instruction; } } }
/// <summary> /// Reads a BHAV from a stream. /// </summary> /// <param name="iff">Iff instance.</param> /// <param name="stream">A Stream instance holding a BHAV chunk.</param> public override void Read(IffFile iff, System.IO.Stream stream) { using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN)) { var version = io.ReadUInt16(); uint count = 0; if (version == 0x8000) { count = io.ReadUInt16(); io.Skip(8); } else if (version == 0x8001) { count = io.ReadUInt16(); var unknown = io.ReadBytes(8); } else if (version == 0x8002) { count = io.ReadUInt16(); this.Type = io.ReadByte(); this.Args = io.ReadByte(); this.Locals = io.ReadUInt16(); this.Flags = io.ReadUInt16(); io.Skip(2); } else if (version == 0x8003) { this.Type = io.ReadByte(); this.Args = io.ReadByte(); this.Locals = io.ReadByte(); io.Skip(2); this.Flags = io.ReadUInt16(); count = io.ReadUInt32(); } Instructions = new BHAVInstruction[count]; for (var i = 0; i < count; i++) { var instruction = new BHAVInstruction(); instruction.Opcode = io.ReadUInt16(); instruction.TruePointer = io.ReadByte(); instruction.FalsePointer = io.ReadByte(); instruction.Operand = io.ReadBytes(8); Instructions[i] = instruction; } } }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { if (NewPrimitive.Type != PrimBoxType.Primitive) { editor.BHAVView.Primitives.Remove(NewPrimitive); editor.BHAVView.Remove(NewPrimitive); } else { //primitive we added should be at the end var newInst = new BHAVInstruction[bhav.Instructions.Length - 1]; for (int i = 0; i < newInst.Length; i++) { newInst[i] = bhav.Instructions[i]; } bhav.Instructions = newInst; editor.BHAVView.RemovePrimitive(NewPrimitive); Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); } }
public PrimitiveBox(BHAVInstruction inst, byte ptr, BHAVContainer master) { Type = PrimBoxType.Primitive; Instruction = inst; Descriptor = PrimitiveRegistry.GetDescriptor(inst.Opcode); Operand = (VMPrimitiveOperand)Activator.CreateInstance(Descriptor.OperandType); Operand.Read(inst.Operand); InstPtr = ptr; Nodes = new PrimitiveNode[2]; Nodes[0] = new PrimitiveNode(); Nodes[0].Type = NodeType.False; Nodes[1] = new PrimitiveNode(); Nodes[1].Type = NodeType.True; Title = new UILabel(); Title.Alignment = TextAlignment.Middle | TextAlignment.Center; Title.Y = 0; Title.X = 0; this.Add(Title); Title.CaptionStyle = TextStyle.DefaultLabel.Clone(); Title.CaptionStyle.Font = FSO.Client.GameFacade.EdithFont; Title.CaptionStyle.Size = 14; BodyTextStyle = TextStyle.DefaultLabel.Clone(); BodyTextStyle.Font = FSO.Client.GameFacade.EdithFont; BodyTextStyle.Size = 12; this.Add(Nodes[0]); this.Add(Nodes[1]); HitTest = ListenForMouse(new Rectangle(0, 0, Width, Height), new UIMouseEvent(MouseEvents)); Master = master; UpdateDisplay(); }