public virtual void Remove() { if (!isRemovable) { return; } RemoveComponentFromVisibilityMap(); ComponentsManager.Replace(this, new EmptyComponent(ID)); if (MicroWorld.Graphics.GUI.GUIEngine.ContainsHUDScene(ToolTip)) { MicroWorld.Components.ComponentsManager.closingProperties.Add(ToolTip); ToolTip.Close(); } if (MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons.isVisible && MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent == this) { MicroWorld.Graphics.GUI.GUIEngine.RemoveHUDScene(MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons); MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent = null; MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons.isVisible = false; } Statistics.ComponentsRemoved++; GlobalEvents.OnComponentRemoved(this); }
public override void PostLoad() { base.PostLoad(); ConnectedWires.Clear(); if (connectedWiresData != null && connectedWiresData != "") { var a = connectedWiresData.Split(';'); for (int i = 0; i < a.Length; i++) { ConnectedWires.Add(ComponentsManager.GetComponent(Convert.ToInt32(a[i])) as Wire); } } /* * ContainingComponents.Clear(); * if (containingComponentsData != null && containingComponentsData != "") * { * var a = containingComponentsData.Split(';'); * for (int i = 0; i < a.Length; i++) * { * ContainingComponents.Add(ComponentsManager.GetComponent(Convert.ToInt32(a[i])) as Wire); * } * }//*/ }
public void DrawGhost(MicroWorld.Graphics.Renderer renderer, int x1, int y1, int x2, int y2) { var c = ComponentsManager.GetComponent(x1, y1); if (c != null) { x1 = (int)(c.Graphics.Position.X + c.Graphics.GetSize().X / 2); y1 = (int)(c.Graphics.Position.Y + c.Graphics.GetSize().Y / 2); } else { return; } var c2 = ComponentsManager.GetComponent(x2, y2); if (c2 != null) { x2 = (int)(c2.Graphics.Position.X + c2.Graphics.GetSize().X / 2); y2 = (int)(c2.Graphics.Position.Y + c2.Graphics.GetSize().Y / 2); } if (c2 == null || c2 is Properties.IRotator || c2 is Properties.IRotatable) { (Graphics as Graphics.RotatableConnectorGraphics).DrawConnector(x1, y1, x2, y2, renderer, 0.6f); Components.Graphics.RotatableConnectorGraphics.DrawBorder(new Vector2(x1, y1), new Vector2(x2, y2), renderer); } }
public override void Start() { if (!ignoreNextPosSave) { origPos = Graphics.Position; components = ComponentsManager.GetComponents((int)Graphics.Position.X, (int)Graphics.Position.Y, (int)Graphics.Size.X, (int)Graphics.Size.Y); containsComponents = new Component[components.Count - 1]; PushedPositions.Clear(); for (int i = 0; i < components.Count; i++) { if (components[i] == this) { components.RemoveAt(i); i--; continue; } PushedPositions.Add(components[i].Graphics.PushPosition()); containsComponents[i] = components[i]; } } ignoreNextPosSave = false; ReDrawFBO = true; base.Start(); }
public override void PostLoad() { base.PostLoad(); ConnectedComponent1 = ComponentsManager.GetComponent(c1); ConnectedComponent2 = ComponentsManager.GetComponent(c2); }
public void UpdateComponentsList() { var a = ComponentsManager.GetComponents((int)Graphics.Position.X, (int)Graphics.Position.Y, (int)Graphics.Size.X, (int)Graphics.Size.Y); a.Remove(this); containsComponents = a.ToArray(); Component t; bool c; for (int i = 0; i < containsComponents.Length; i++) { c = false; for (int j = i + 1; j < containsComponents.Length; j++) { if (containsComponents[i].Graphics.Layer > containsComponents[j].Graphics.Layer) { c = true; t = containsComponents[i]; containsComponents[i] = containsComponents[j]; containsComponents[j] = t; } } if (!c) { break; } } }
private bool CanBeResizedTo(float x, float y, float w, float h) { var a = ComponentsManager.GetIntersectingComponents(x, y, 8, h); a.Remove(this); if (a.Count > 0) { return(false); } a = ComponentsManager.GetIntersectingComponents(x, y, w, 8); a.Remove(this); if (a.Count > 0) { return(false); } a = ComponentsManager.GetIntersectingComponents(x + w - 8, y, 8, h); a.Remove(this); if (a.Count > 0) { return(false); } a = ComponentsManager.GetIntersectingComponents(x, y + h - 8, w, 8); a.Remove(this); if (a.Count > 0) { return(false); } return(true); }
public override void AddComponentToManager() { //ComponentsManager.Remove(this); ID = ComponentsManager.GetFreeID(); //ComponentsManager.Add(this); base.AddComponentToManager(); }
public override void Remove() { ComponentsManager.Replace(this, new EmptyComponent(ID)); UnRegisterColliders(); collisions.Clear(); length = preCollisionLength; }
private void constructor() { ID = ComponentsManager.GetFreeID(); Logics = new Logics.JointLogics(); Graphics = new Graphics.JointGraphics(); Graphics.parent = this; Logics.parent = this; }
public override void PostLoad() { base.PostLoad(); if (con != Int32.MinValue && con != -1) { connectedComponent = ComponentsManager.GetComponent(com); connector = ComponentsManager.GetComponent(con) as RotatableConnector; } }
/// <summary> /// Check for things like shared Joints /// </summary> /// <returns></returns> public virtual bool IsMovable() { if (!IsRemovable) { return(false); } var a = getJoints(); Joint t; for (int i = 0; i < a.Length; i++) { t = ComponentsManager.GetComponent(a[i]) as Joint; if (t.ContainingComponents.Count > 1) { return(false); } } return(true); }
public override void PostLoad() { base.PostLoad(); Joints[0] = (Joint)Components.ComponentsManager.GetComponent(j0); Joints[1] = (Joint)Components.ComponentsManager.GetComponent(j1); W = (Wire)Components.ComponentsManager.GetComponent(w); Resistance = res; if (com != -1) { connectedComponent = ComponentsManager.GetComponent(com); connector = ComponentsManager.GetComponent(con) as RotatableConnector; } for (int i = 0; i < Joints.Length; i++) { Joints[i].ContainingComponents.Add(this); } }
public override void PostLoad() { base.PostLoad(); containsComponents = new Component[contains.Count]; components.Clear(); for (int i = 0; i < contains.Count; i++) { containsComponents[i] = ComponentsManager.GetComponent(contains[i]); components.Add(containsComponents[i]); if (origPos != null) { tppushed.Add(components[i].Graphics.PushPosition()); components[i].Graphics.PopPosition(PushedPositions[i]); } } contains.Clear(); RegisterColliders(); }
/// <summary> /// Function that is called EVERY update regardless of game state /// </summary> public virtual void NonGameUpdate() { Graphics.NonGameUpdate(); //selection shader if (MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons.isVisible && MicroWorld.Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent == this) { if (selectionShaderState < 20) { selectionShaderState++; } if (selectionShaderState == 1) { MicroWorld.Graphics.Effects.Effects.getBluredTextureSelectedComponent(this); } } else { if (selectionShaderState > 0) { selectionShaderState--; } } //TT if (ToolTip != null && ToolTip.isVisible && Settings.GameState != Settings.GameStates.Stopped) { int x = InputEngine.curMouse.X, y = InputEngine.curMouse.Y; Utilities.Tools.ScreenToGameCoords(ref x, ref y); var a = ComponentsManager.GetComponents(x, y); for (int i = 0; i < a.Count; i++) { if (a[i] is Properties.IRotatable) { ToolTip.isVisible = false; MicroWorld.Graphics.GUI.GUIEngine.RemoveHUDScene(ToolTip); } } } }
public override void PostLoad() { base.PostLoad(); J1 = (Joint)ComponentsManager.GetComponent(j1); J2 = (Joint)ComponentsManager.GetComponent(j2); if (dp != null) { var a = dp.Split(';'); var g = Graphics as Graphics.WireGraphics; g.DrawPath.Clear(); g.IgnoreNextPathFinder = true; for (int i = 0; i < a.Length; i += 2) { g.DrawPath.Add(new Vector2((float)Convert.ToDouble(a[i]), (float)Convert.ToDouble(a[i + 1]))); } } (Graphics as Graphics.WireGraphics).GenerateElectrons(); updateVoltageCurrent(); }
public Wire(int id1, int id2) { Component t = ComponentsManager.GetComponent(id1); if (t == null || !(t is Joint)) { J1 = new Joint(); } else { J1 = (Joint)t; } t = ComponentsManager.GetComponent(id2); if (t == null || !(t is Joint)) { J2 = new Joint(); } else { J2 = (Joint)t; } constructor(); }
private void constructor() { ID = ComponentsManager.GetFreeID(); Logics = new Logics.WireLogics(); Graphics = new Graphics.WireGraphics(); Graphics.parent = this; Logics.parent = this; if (J1 != null) { J1.ConnectedWires.Remove(this); J1.ConnectedWires.Add(this); J2.ConnectedWires.Remove(this); J2.ConnectedWires.Add(this); Statistics.WireLengthPlaced += Math.Sqrt(Math.Pow(J1.Graphics.Position.X - J2.Graphics.Position.X, 2) + Math.Pow(J1.Graphics.Position.Y - J2.Graphics.Position.Y, 2)); MicroWorld.Logics.CircuitManager.ScheduleReCreate(); } ToolTip = new GUI.WireProperties(); }
public override void AddComponentToManager() { ID = ComponentsManager.GetFreeID(); base.AddComponentToManager(); }
private bool CanBeResizedTo(float x, float y, float w, float h) { return(ComponentsManager.GetIntersectingComponents(x, y, w, h).Count <= 1); }
public void UpdateLasers() { for (int i = 0; i < 4; i++) { connectedDetectors[i] = null; lasers[i].Remove(); lasers[i].Length = 0; } if (!hasEnoughPowerSupply) { return; } int x = (int)Graphics.Center.X, y = (int)Graphics.Center.Y, r = (int)range; var a = ComponentsManager.GetComponents <MovementDetector>(x - r, y - r, 2 * r, 2 * r); for (int i = 0; i < a.Count; i++) { if (a[i] != this) { if (a[i].Graphics.Position.X == Graphics.Position.X) { if (a[i].Graphics.Position.Y < Graphics.Position.Y)//up { if (connectedDetectors[0] == null || connectedDetectors[0].Graphics.Position.Y < a[i].Graphics.Position.Y) { if (connectedDetectors[0] != null) { ComponentsManager.Remove(lasers[0]); } if (!a[i].HasEnoughPowerSupply) { continue; } if (a[i].Range < Graphics.Position.Y - a[i].Graphics.Position.Y) { continue; } connectedDetectors[0] = a[i]; lasers[0].Length = (int)(Graphics.Position.Y - a[i].Graphics.Position.Y); ComponentsManager.Add(lasers[0]); } } else//down { if (connectedDetectors[2] == null || connectedDetectors[2].Graphics.Position.Y > a[i].Graphics.Position.Y) { if (connectedDetectors[2] != null) { ComponentsManager.Remove(lasers[2]); } if (!a[i].HasEnoughPowerSupply) { continue; } if (a[i].Range < a[i].Graphics.Position.Y - Graphics.Position.Y) { continue; } connectedDetectors[2] = a[i]; lasers[2].Length = (int)(a[i].Graphics.Position.Y - Graphics.Position.Y); ComponentsManager.Add(lasers[2]); } } } if (a[i].Graphics.Position.Y == Graphics.Position.Y) { if (a[i].Graphics.Position.X < Graphics.Position.X)//left { if (connectedDetectors[1] == null || connectedDetectors[1].Graphics.Position.X < a[i].Graphics.Position.X) { if (connectedDetectors[1] != null) { ComponentsManager.Remove(lasers[1]); } if (!a[i].HasEnoughPowerSupply) { continue; } if (a[i].Range < Graphics.Position.X - a[i].Graphics.Position.X) { continue; } connectedDetectors[1] = a[i]; lasers[1].Length = (int)(Graphics.Position.X - a[i].Graphics.Position.X); ComponentsManager.Add(lasers[1]); } } else//right { if (connectedDetectors[3] == null || connectedDetectors[3].Graphics.Position.Y > a[i].Graphics.Position.Y) { if (connectedDetectors[3] != null) { ComponentsManager.Remove(lasers[3]); } if (!a[i].HasEnoughPowerSupply) { continue; } if (a[i].Range < a[i].Graphics.Position.X - Graphics.Position.X) { continue; } connectedDetectors[3] = a[i]; lasers[3].Length = (int)(a[i].Graphics.Position.X - Graphics.Position.X); ComponentsManager.Add(lasers[3]); } } } } } bool b = prevPowerSupply; prevPowerSupply = true; for (int i = 0; i < 4; i++) { if (connectedDetectors[i] != null) { lasers[i].RegisterColliders(); if (!b) { connectedDetectors[i].UpdateLasers(); } } } }
/// <summary> /// Add this component to a ComponentManager here /// </summary> public virtual void AddComponentToManager() { ComponentsManager.Add(this); }