public void DestroyDetail(DetailObject detail) { this.sender.Send(NetworkPhrase.DestroyDetail, (s) => { s.Write(detail.ID); }); }
static public bool EditDetailItem(int masterKey, int key, string value) { DetailObject item = Find(masterKey).Items.Find(d => d.Key == key); if (item == null) { return(false); } item.Value = value; return(true); }
static public bool DeleteDetailItem(int masterKey, int key) { MasterObject masterItem = Find(masterKey); if (masterItem == null) { return(false); } DetailObject item = masterItem.Items.Find(d => d.Key == key); if (item == null) { return(false); } masterItem.Items.Remove(item); return(true); }
public void CreateDetail(DetailObject detail) { this.sender.Send(NetworkPhrase.CreateDetail, (s) => { bool hasShape = detail.Shape != null; s.Write(detail.ID); if (detail.Parent != null) s.Write(detail.Parent.ID); else s.Write(-1); s.Write(detail.Model ?? ""); s.Write(detail.Position); s.Write(detail.Rotation); s.Write(hasShape); if(hasShape == true) { var shape = (BoxShape)detail.Shape; s.Write(shape.Size.TK()); } }); }
public DetailInteractionEventArgs(DetailObject detail, Interaction interaction, IActor actor) : base(actor) { this.Detail = detail; this.Interaction = interaction; }
private void loadDetailtoList() { detail = new List <DetailObject>(); Contact selected = App.selectedContact; String path; if (isLightTheme()) { path = ForwardContact_Constant.PATH_ICON_LIGHT; } else { path = ForwardContact_Constant.PATH_ICON; } //DisplayName if (selected.DisplayName != null && selected.DisplayName != "") { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_DISPLAYNAME; temp.Content = "Name: " + selected.DisplayName; detail.Add(temp); } //Phone if (selected.PhoneNumbers != null && selected.PhoneNumbers.Count() != 0) { foreach (ContactPhoneNumber acct in selected.PhoneNumbers) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_PHONE; temp.Content = "Phone (" + acct.Kind + "): " + acct.PhoneNumber; detail.Add(temp); } } //Email if (selected.EmailAddresses != null && selected.EmailAddresses.Count() != 0) { foreach (ContactEmailAddress acct in selected.EmailAddresses) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_EMAIL; temp.Content = "Email (" + acct.Kind + "): " + acct.EmailAddress; detail.Add(temp); } } //Account if (selected.Accounts != null && selected.Accounts.Count() != 0) { foreach (Account acct in selected.Accounts) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_ACCOUNT; temp.Content = "Account: " + acct.Name; detail.Add(temp); } } //Address if (selected.Addresses != null && selected.Addresses.Count() != 0) { foreach (ContactAddress acct in selected.Addresses) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_ADDRESS; temp.Content = "Address " + "(" + acct.Kind + "): " + acct.PhysicalAddress.AddressLine1 + " " + acct.PhysicalAddress.AddressLine2 + " " + acct.PhysicalAddress.City + " " + acct.PhysicalAddress.StateProvince + " " + acct.PhysicalAddress.CountryRegion + " " + acct.PhysicalAddress.PostalCode; detail.Add(temp); } } //Birthday if (selected.Birthdays != null && selected.Birthdays.Count() != 0) { foreach (DateTime acct in selected.Birthdays) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_BIRTHDAY; temp.Content = "Birthday: " + acct.ToLongDateString(); detail.Add(temp); } } //Company if (selected.Companies != null && selected.Companies.Count() != 0) { foreach (ContactCompanyInformation acct in selected.Companies) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_COMPANY; temp.Content = "Company: " + acct.CompanyName; if (acct.JobTitle != "" && acct.JobTitle != null) { temp.Content += " (" + acct.JobTitle + ")"; } detail.Add(temp); } } //Websites if (selected.Websites != null && selected.Websites.Count() != 0) { foreach (String acct in selected.Websites) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_SIGNNIFICANT; temp.Content = "Website: " + acct; detail.Add(temp); } } //Children if (selected.Children != null && selected.Children.Count() != 0) { foreach (String acct in selected.Children) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_BIRTHDAY; temp.Content = "Children: " + acct; detail.Add(temp); } } //SignificantOthers if (selected.SignificantOthers != null && selected.SignificantOthers.Count() != 0) { foreach (String acct in selected.SignificantOthers) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_SIGNNIFICANT; temp.Content = "Significant Others: " + acct; detail.Add(temp); } } //Notes if (selected.Notes != null && selected.Notes.Count() != 0) { foreach (String acct in selected.Notes) { DetailObject temp = new DetailObject(); temp.IconSource = path + ForwardContact_Constant.ICON_NOTES; temp.Content = "Note: " + acct; detail.Add(temp); } } listDetail.ItemsSource = detail; }
private void RenderDetail(Camera cam, DetailObject detail, double time) { Matrix4 world = detail.Transform; Matrix4 worldViewProjection = world * cam.CreateViewMatrix() * cam.CreateProjectionMatrix(this.Aspect); GL.UniformMatrix4(this.objectShader["uWorld"], false, ref world); GL.UniformMatrix4(this.objectShader["uWorldViewProjection"], false, ref worldViewProjection); var model = this.GetModelFromName(detail.Model); if (model != null) { model.Render(cam, time); } }
public override void UpdateFrame(IGameInputDriver input, double time) { this.fps = (int)(1.0f / time); this.totalTime += time; this.network.Dispatch(); foreach (var proxy in this.proxies) proxy.Value.UpdateFrame(input, time); if (input.GetButtonDown(Key.Q)) { this.currentTool = (this.currentTool + 1) % this.tools.Count; } if (this.player != null) { this.player.Tool = this.tools[this.currentTool].Item2; this.player.UpdateFrame(input, time); var previous = this.selectedDetail; this.selectedDetail = null; this.visibleDetails.Clear(); var from = this.player.Eye; foreach (var detail in this.world.Details) { // Ignore all details without interactions. // How stupid was I when i forgot this? if (detail.Interactions.Count == 0) continue; // Check for visibility with trace var to = detail.WorldPosition; var dir = (to - from).Normalized(); var hit = this.world.Trace(from.Jitter(), dir.Jitter(), TraceOptions.IgnoreDynamic); if ((hit != null) && ((hit.Body?.Tag as DetailObject) != detail)) continue; var dist = (detail.WorldPosition - from).Length; if (dist > 3.5f) // TODO: Implement settings value continue; var center = this.player.Camera.WorldToScreen(detail.WorldPosition, this.Aspect); if ((center.X < -0.6) || (center.X > 0.6)) continue; /* Maybe opt in this later, but it should decrease usability of doors. if ((center.Y < -1.0) || (center.Y > 1.0)) continue; */ this.visibleDetails.Add(detail); if (this.selectedDetail != null) { var currentCenter = this.player.Camera.WorldToScreen(this.selectedDetail.WorldPosition, this.Aspect).Xy.Length; if (currentCenter < center.Xy.Length) continue; } this.selectedDetail = detail; } this.visibleDetails.Remove(this.selectedDetail); // Reset interaction on change if (previous != this.selectedDetail) this.selectedDetailInteraction = 0; if (this.selectedDetail != null) { // Detail interaction selection with moues wheel. int c = this.selectedDetail.Interactions.Count; if (c > 1) { if (input.MouseWheel > 0) this.selectedDetailInteraction -= 1; if (input.MouseWheel < 0) this.selectedDetailInteraction += 1; while (this.selectedDetailInteraction < 0) this.selectedDetailInteraction += c; while (this.selectedDetailInteraction >= c) this.selectedDetailInteraction -= c; } // Detail interaction with Key.E if (input.GetButtonDown(Key.E)) { if (this.selectedDetail.Interactions.Count > 0) { this.Server.TriggerInteraction( this.selectedDetail, this.selectedDetail.Interactions[this.selectedDetailInteraction]); } } } } lock (typeof(World)) { this.world.Step((float)time, true); } this.networkUpdateCounter++; if (this.networkUpdateCounter > 5) { this.sender.SetPlayer(this.player.FeetPosition, this.player.BodyRotation); this.networkUpdateCounter = 0; } }
private void CreateDetail(BinaryReader reader) { int id = reader.ReadInt32(); int parentID = reader.ReadInt32(); string model = reader.ReadString(); var pos = reader.ReadVector3(); var rot = reader.ReadQuaternion(); Shape shape = null; bool hasShape = reader.ReadBoolean(); if (hasShape == true) { var shapeSize = reader.ReadVector3(); shape = DetailHelper.CreateShape(shapeSize); } var parent = this.world.GetDetail(parentID); DetailObject obj = new DetailObject(parent, id, shape); obj.Position = pos; obj.Rotation = rot; obj.Model = model.Length > 0 ? model : null; this.world.RegisterDetail(obj); }
private List<DetailObject> GetChildren(DetailObject obj) { List<DetailObject> children = new List<DetailObject>(); foreach (var detail in this.details) { if (detail.Parent == obj) children.Add(detail); } return children; }
public void TriggerInteraction(DetailObject detail, Interaction interaction) { this.sender.Send(NetworkPhrase.TriggerInteraction, (s) => { s.Write(detail.ID); s.Write(interaction.ID); }); }
public void UpdateDetail(DetailObject detail) { this.sender.Send(NetworkPhrase.UpdateDetail, (s) => { s.Write(detail.ID); s.Write(detail.Position); s.Write(detail.Rotation); }); }
public void SetInteractions(DetailObject detail) { this.sender.Send(NetworkPhrase.SetInteractions, (s) => { s.Write(detail.ID); s.Write(detail.Interactions.Count); foreach (var interaction in detail.Interactions) { s.Write(interaction.ID); s.Write(interaction.Name); } }); }
private void OnDetailRemoved(DetailObject obj) { if (this.DetailRemoved != null) this.DetailRemoved(this, new DetailEventArgs(obj)); // Destroy all child objects in the object tree as well foreach (var child in GetChildren(obj)) { this.RemoveDetail(child.ID); } }
private void OnDetailCreated(DetailObject obj) { if (this.DetailCreated != null) this.DetailCreated(this, new DetailEventArgs(obj)); }
public void Load(Stream fs, bool leaveOpen) { // Reset whole world foreach (var block in blocks.ToArray()) { this[block.X, block.Y, block.Z] = null; } Action<bool> assert = (b) => { if (!b) throw new InvalidDataException(); }; using (var br = new BinaryReader(fs, Encoding.UTF8, leaveOpen)) { assert(br.ReadString() == "BLOCKWORLD"); int major = br.ReadByte(); int minor = br.ReadByte(); assert(major == 1); int typeCount = br.ReadInt32(); Type[] types = new Type[typeCount]; for (int i = 0; i < typeCount; i++) { string typeName = br.ReadString(); types[i] = Type.GetType(typeName); if (types[i] == null) throw new TypeLoadException("Could not find type " + typeName); } long blockCount = br.ReadInt64(); for (long i = 0; i < blockCount; i++) { int x = br.ReadInt32(); int y = br.ReadInt32(); int z = br.ReadInt32(); Type type = types[br.ReadInt32()]; var block = Activator.CreateInstance(type) as Block; block.Deserialize(br); this[x, y, z] = block; } // Details are stored here as well if(minor == 1) { int detailCount = br.ReadInt32(); for (int i = 0; i < detailCount; i++) { int id = br.ReadInt32(); string model = br.ReadString(); int parentID = br.ReadInt32(); var position = br.ReadVector3(); var rotation = br.ReadQuaternion(); Shape shape = null; bool hasShape = br.ReadBoolean(); if (hasShape) { var size = br.ReadVector3(); shape = new BoxShape(size.Jitter()); } DetailObject detail = new DetailObject(this.GetDetail(parentID), id, shape); if (string.IsNullOrWhiteSpace(model) == false) detail.Model = model; detail.Position = position; detail.Rotation = rotation; this.RegisterDetail(detail); int behaviourCount = br.ReadInt32(); for (int j = 0; j < behaviourCount; j++) { var typeName = br.ReadString(); var type = Type.GetType(typeName, true); int behaviourID = br.ReadInt32(); bool isEnabled = br.ReadBoolean(); var behaviour = (Behaviour)Activator.CreateInstance(type); detail.CreateBehaviour(behaviour, behaviourID, isEnabled); } } int signalCount = br.ReadInt32(); for (int j = 0; j < signalCount; j++) { var signalDetailID = br.ReadInt32(); var signalBehaviourID = br.ReadInt32(); var signalName = br.ReadString(); var signal = this.GetDetail(signalDetailID).Behaviours[signalBehaviourID].Signals[signalName]; var slotCount = br.ReadInt32(); for (int k = 0; k < slotCount; k++) { var slotDetailID = br.ReadInt32(); var slotBehaviourID = br.ReadInt32(); var slotName = br.ReadString(); var slot = this.GetDetail(slotDetailID).Behaviours[slotBehaviourID].Slots[slotName]; signal.Connect(slot); } } } } }
public void RegisterDetail(DetailObject obj) { if (this.HasDetail(obj.ID)) throw new InvalidOperationException(); obj.Changed += Obj_Changed; obj.InteractionTriggered += Obj_InterationTriggered; this.details.Add(obj); if (obj.Shape != null) { var body = new RigidBody(obj.Shape); body.Position = obj.WorldPosition.Jitter(); body.Orientation = JMatrix.CreateFromQuaternion(obj.WorldRotation.Jitter()); body.IsStatic = true; body.Tag = obj; body.EnableDebugDraw = true; body.Material = this.blockMaterial; this.detailBodies.Add(obj.ID, body); this.AddBody(body); obj.PositionChanged += (s, e) => { body.Position = obj.WorldPosition.Jitter(); body.Orientation = JMatrix.CreateFromQuaternion(obj.WorldRotation.Jitter()); }; } this.OnDetailCreated(obj); }
public DetailEventArgs(DetailObject obj) { this.Detail = obj; }
private void PaintDetailUI(Graphics g, Size screen, DetailObject detail, Brush background, int selection) { if (this.player == null) return; if (detail.Interactions.Count == 0) return; var screenSpace = this.player.Camera.WorldToScreen(detail.WorldPosition, this.Aspect); if ((screenSpace.Z < 0.0f) || (screenSpace.Z > 1.0f)) return; int x = (int)(screen.Width * (0.5f + 0.5f * screenSpace.X)); int y = (int)(screen.Height * (0.5f - 0.5f * screenSpace.Y)); var state = g.Transform; g.TranslateTransform(x, y); var font = this.smallFont; RectangleF area = new RectangleF(); var interactions = detail.Interactions.ToArray(); for (int i = 0; i < interactions.Length; i++) { var size = g.MeasureString(interactions[i].Name, font); area.Width = Math.Max(size.Width, area.Width); area.Height += size.Height + 1; } g.FillRectangle(background, area); float pointer = 0.0f; for (int i = 0; i < interactions.Length; i++) { var text = interactions[i].Name; var size = g.MeasureString(text, font); if (i == selection) { var sel = new RectangleF(0, pointer, area.Width, size.Height); g.FillRectangle(Brushes.LightGreen, sel); } g.DrawString(text, font, Brushes.Black, 0, pointer); pointer += size.Height; } g.DrawRectangle(Pens.Black, area.X, area.Y, area.Width, area.Height); g.Transform = state; }
public DetailObject CreateDetail(string model, Vector3 position, DetailObject parent = null, Shape shape = null) { var obj = new DetailObject(parent, ++this.detailCounter, shape) { Model = model, Position = position, }; this.RegisterDetail(obj); return obj; }
private DetailObject CreateDetailInstance( Dictionary<DetailTemplate, DetailObject> mapping, Dictionary<BehaviourTemplate, Behaviour> behaviours, DetailTemplate template, DetailObject parent) { Vector3 pos = Vector3.Zero; if (template.Position != null) pos = template.GetPosition(); Shape shape = null; if(template.Shape != null) { shape = DetailHelper.CreateShape(template.Shape.GetSize()); } DetailObject root = this.CreateDetail(template.Model, pos, parent, shape); if (template.Rotation != null) root.Rotation = template.GetRotation(); if (template.Children != null) { foreach (var child in template.Children) { CreateDetailInstance(mapping, behaviours, child, root); } } mapping.Add(template, root); if (template.Behaviours != null) { foreach (var behav in template.Behaviours) { var type = Type.GetType(behav.Class); if (type.IsSubclassOf(typeof(Behaviour)) == false) throw new InvalidOperationException("Invalid behaviour type: " + behav.Class); Behaviour behaviour = root.CreateBehaviour(type, true); behaviours.Add(behav, behaviour); } } return root; }