public CircuitConnection(EditorCircuitActor circuitActor, EditorActor actor, Gate gate, string type) { _circuitActor = circuitActor; _actor = actor; _gate = gate; _type = type; }
public EditorCircuitActor(EditorLevel level, XElement data) : base(level, data) { _circuit = level.controller.editorController.circuitController.getCircuit(data.Attribute("circuit_uid").Value); _position = Loader.loadVector2(data.Attribute("position"), Vector2.Zero); _connections = new List <CircuitConnection>(); foreach (XElement connectionData in data.Elements("CircuitConnection")) { EditorActor actor = level.getActor(int.Parse(connectionData.Attribute("actor_id").Value)); Gate gate = _circuit.getGate(int.Parse(connectionData.Attribute("gate_id").Value)); string connectionType = connectionData.Attribute("type").Value; if (connectionType == "input") { GameEventType listenToEvent = (GameEventType)Loader.loadEnum(typeof(GameEventType), connectionData.Attribute("listen_to_event"), 0); _connections.Add(new CircuitInputConnection(this, actor, gate, listenToEvent)); } else if (connectionType == "output") { GameEventType onEnabledEvent = (GameEventType)Loader.loadEnum(typeof(GameEventType), connectionData.Attribute("on_enabled_event"), 0); GameEventType onDisabledEvent = (GameEventType)Loader.loadEnum(typeof(GameEventType), connectionData.Attribute("on_disabled_event"), 0); _connections.Add(new CircuitOutputConnection(this, actor, gate, onEnabledEvent, onDisabledEvent)); } } initializeGateControls(); }
// Contains actor public bool containsActor(EditorActor actor) { foreach (List <EditorActor> actors in _sortedActors.Values) { if (actors.Contains(actor)) { return(true); } } return(false); }
public override bool handleUnselectedClick(System.Windows.Forms.MouseButtons button) { if (button == System.Windows.Forms.MouseButtons.Left) { return(hitTest(_level.controller.worldMouse, (results) => { if (results.Count == 1 && results[0] is PointListNode) { _selectedPoints.Add(results[0] as PointListNode); select(); return true; } else if (results.Count == 2 && _actorA == null && _actorB == null) { foreach (IActorComponent component in results) { if (component is PointListNode) { _selectedPoints.Add(component as PointListNode); } } select(); return true; } else if (results.Count == 2 && _actorA != null && _actorB != null) { _nodeA.position = _actorA.collisionFilterConnectionPosition; _nodeB.position = _actorB.collisionFilterConnectionPosition; _actorA = null; _actorB = null; _selectedPoints.Add(_nodeA); _selectedPoints.Add(_nodeB); select(); } return false; })); } else if (button == System.Windows.Forms.MouseButtons.Right) { return(hitTest(_level.controller.worldMouse, (results) => { if (results.Count == 1) { _level.controller.openActorProperties(results[0]); return true; } return false; })); } return(false); }
public EditorRevoluteActor(EditorLevel level, XElement data) : base(level, data) { _position = Loader.loadVector2(data.Attribute("position"), Vector2.Zero); _actorA = data.Attribute("actor_a").Value == "-1" ? null : level.getActor(int.Parse(data.Attribute("actor_a").Value)); _actorB = data.Attribute("actor_b").Value == "-1" ? null : level.getActor(int.Parse(data.Attribute("actor_b").Value)); _lowerAngle = Loader.loadFloat(data.Attribute("lower_angle"), 0f); _upperAngle = Loader.loadFloat(data.Attribute("upper_angle"), 0f); _enableLimit = Loader.loadBool(data.Attribute("enable_limit"), false); _maxMotorTorque = Loader.loadFloat(data.Attribute("max_motor_torque"), 0f); _motorSpeed = Loader.loadFloat(data.Attribute("motor_speed"), 0f); _enableMotor = Loader.loadBool(data.Attribute("enable_motor"), false); initializeControls(); }
public override void handleSelectedClick(System.Windows.Forms.MouseButtons button) { if (_selectedA || _selectedB) { // Attempt to form a connection with another actor foreach (List <EditorActor> actors in _level.sortedActors.Values) { foreach (EditorActor actor in actors) { // Only connect with certain actor types if (actor.type == ActorType.Box || actor.type == ActorType.Circle || actor.type == ActorType.Terrain) { if (_selectedA && actor != _actorB) { // Form a connection (actorA) if (actor.hitTest(_controlA.position, (results) => { if (results.Count > 0 && results[0] is EditorActor) { _actorA = actor; return(true); } return(false); })) { break; } } else if (_selectedB && actor != _actorA) { // Form a connection (actorB) if (actor.hitTest(_controlB.position, (results) => { if (results.Count > 0 && results[0] is EditorActor) { _actorB = actor; return(true); } return(false); })) { break; } } } } } } deselect(); }
public EditorCollisionFilterActor(EditorLevel level, XElement data) : base(level, data) { _selectedPoints = new List <PointListNode>(); if (data.Attribute("actor_a").Value != "-1") { _actorA = level.getActor(int.Parse(data.Attribute("actor_a").Value)); } if (data.Attribute("actor_b").Value != "-1") { _actorB = level.getActor(int.Parse(data.Attribute("actor_b").Value)); } initializeControls(Vector2.Zero, Vector2.Zero); }
// Remove an actor public void removeActor(EditorActor actor, bool immediate = false) { if (immediate) { _sortedActors[actor.layerDepth].Remove(actor); if (_sortedActors[actor.layerDepth].Count == 0) { _sortedActors.Remove(actor.layerDepth); } } else { _actorsToRemove.Add(actor); } }
// Add an actor public void addActor(EditorActor actor, bool immediate = false) { if (immediate) { if (!_sortedActors.ContainsKey(actor.layerDepth)) { _sortedActors.Add(actor.layerDepth, new List <EditorActor>()); } _sortedActors[actor.layerDepth].Add(actor); } else { _actorsToAdd.Add(actor); } }
public EditorPrismaticActor(EditorLevel level, XElement data) : base(level, data) { int actorIdA = Loader.loadInt(data.Attribute("actor_a"), -1); int actorIdB = Loader.loadInt(data.Attribute("actor_b"), -1); _position = Loader.loadVector2(data.Attribute("position"), Vector2.Zero); _actorA = actorIdA == -1 ? null : level.getActor(actorIdA); _actorB = actorIdB == -1 ? null : level.getActor(actorIdB); Vector2 axis = Loader.loadVector2(data.Attribute("axis"), new Vector2(1, 0)); _angle = (float)Math.Atan2(axis.Y, axis.X); lowerLimit = Loader.loadFloat(data.Attribute("lower_limit"), 0f); upperLimit = Loader.loadFloat(data.Attribute("upper_limit"), 0f); _autoCalculateForce = Loader.loadBool(data.Attribute("auto_calculate_force"), false); _autoForceDifference = Loader.loadFloat(data.Attribute("auto_force_difference"), 0f); _motorSpeed = Loader.loadFloat(data.Attribute("motor_speed"), 0f); _motorEnabled = Loader.loadBool(data.Attribute("motor_enabled"), false); _maxMotorForce = Loader.loadFloat(data.Attribute("max_motor_force"), 0f); initializeControls(); }
public override void handleSelectedClick(System.Windows.Forms.MouseButtons button) { if (_selectedPoints.Count == 1) { // Perform an actor hit test and form a connection if successful foreach (List <EditorActor> actors in _level.sortedActors.Values) { foreach (EditorActor actor in actors) { if (actor.type == ActorType.Box || actor.type == ActorType.Circle || actor.type == ActorType.Terrain) { bool connectionFormed = actor.hitTest(_selectedPoints[0].position, (results) => { if (results.Count > 0) { if (_selectedPoints[0] == _nodeA) { _actorA = actor; } else if (_selectedPoints[0] == _nodeB) { _actorB = actor; } return(true); } return(false); }); if (connectionFormed) { deselect(); return; } } } } } deselect(); }
public override void handleSelectedClick(System.Windows.Forms.MouseButtons button) { if ((_selectedConnectionA || _selectedConnectionB) && !_moveActor) { foreach (List <EditorActor> actors in _level.sortedActors.Values) { foreach (EditorActor actor in actors) { if (actor.type == ActorType.Box || actor.type == ActorType.Circle || actor.type == ActorType.Terrain) { PointListNode connectionControl = _selectedConnectionA ? _connectionA : _connectionB; if (actor.hitTest(connectionControl.position, (results) => { if (results.Count > 0) { if (_selectedConnectionA) { _actorA = actor; } else { _actorB = actor; } return(true); } return(false); })) { break; } } } } } deselect(); }
public override void update() { Vector2 worldDelta = _level.controller.worldDeltaMouse; float angleIncrement = _level.controller.isKeyHeld(Keys.LeftShift) ? 0.00005f : 0.0005f; if (_actorA != null && !_level.containsActor(_actorA)) { _controlA.position = _actorA.revoluteConnectionPosition; _actorA = null; } if (_actorB != null && !_level.containsActor(_actorB)) { _controlB.position = _actorB.revoluteConnectionPosition; _actorB = null; } if (selected) { if (!_level.controller.isKeyHeld(Keys.LeftControl)) { if (_moveActor) { _position += worldDelta; } if (_selectedA) { _controlA.position += worldDelta; } if (_selectedB) { _controlB.position += worldDelta; } } if (_level.controller.isKeyHeld(Keys.A)) { lowerAngle += angleIncrement; } if (_level.controller.isKeyHeld(Keys.D)) { lowerAngle -= angleIncrement; } if (_level.controller.isKeyHeld(Keys.W)) { upperAngle -= angleIncrement; } if (_level.controller.isKeyHeld(Keys.S)) { upperAngle += angleIncrement; } if (_level.controller.isKeyPressed(Keys.Escape)) { deselect(); } else if (_level.controller.isKeyPressed(Keys.Delete)) { delete(); } } }
public CircuitOutputConnection(EditorCircuitActor circuitActor, EditorActor actor, Gate gate, GameEventType onEnabledEvent, GameEventType onDisabledEvent) : base(circuitActor, actor, gate, "output") { _onEnabledEvent = onEnabledEvent; _onDisabledEvent = onDisabledEvent; }
public override void update() { Vector2 worldDelta = _level.controller.worldDeltaMouse; float angleIncrement = _level.controller.isKeyHeld(Keys.LeftShift) ? 0.0001f : 0.0005f; float limitIncrement = _level.controller.isKeyHeld(Keys.LeftShift) ? 0.0001f : 0.0005f; // Update connections if (_actorA != null && !_level.containsActor(_actorA)) { _connectionA.position = _actorA.prismaticConnectionPosition; _actorA = null; } if (_actorB != null && !_level.containsActor(_actorB)) { _connectionB.position = _actorB.prismaticConnectionPosition; _actorB = null; } if (selected) { if (!_level.controller.isKeyHeld(Keys.LeftControl)) { if (_moveActor) { _position += worldDelta; } if (_selectedConnectionA) { _connectionA.position += worldDelta; } if (_selectedConnectionB) { _connectionB.position += worldDelta; } } if (_level.controller.isKeyHeld(Keys.Q)) { _angle -= angleIncrement; } if (_level.controller.isKeyHeld(Keys.E)) { _angle += angleIncrement; } if (_level.controller.isKeyHeld(Keys.W)) { upperLimit += limitIncrement; } if (_level.controller.isKeyHeld(Keys.S)) { upperLimit -= limitIncrement; } if (_level.controller.isKeyHeld(Keys.A)) { lowerLimit -= limitIncrement; } if (_level.controller.isKeyHeld(Keys.D)) { lowerLimit += limitIncrement; } if (_level.controller.isKeyPressed(Keys.Escape)) { deselect(); } else if (_level.controller.isKeyPressed(Keys.Delete)) { delete(); } } }
public CircuitInputConnection(EditorCircuitActor circuitActor, EditorActor actor, Gate gate, GameEventType listenToEvent) : base(circuitActor, actor, gate, "input") { _listenToEvent = listenToEvent; }