static void GlobalEvents_onComponentSelected(Components.Component sender) { if (IsRunning) { scripts.CallFunction("OnComponentSelected", sender.ID); } }
internal static void getBluredTextureSelectedComponent(Components.Component c) { GraphicsEngine.isSelectedGlowPass = true; float pixel = 1f / (float)Main.WindowWidth * Settings.GameScale; var cr = new Vector2(); int rangeX = (int)cr.X; int rangeY = (int)cr.Y; Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.renderer.GraphicsDevice.Viewport.Width, Main.renderer.GraphicsDevice.Viewport.Height, 0, 0, 1); Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); blurX.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection); blurY.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection); #region PreStencil Main.renderer.GraphicsDevice.SetRenderTarget(c.selectionFBO); Main.renderer.GraphicsDevice.Clear(Color.Transparent); Main.renderer.Begin(); c.Graphics.Draw(Main.renderer); Main.renderer.End(); #endregion Main.renderer.GraphicsDevice.SetRenderTarget(null); }
static void GlobalEvents_onComponentPlacedByPlayer(Components.Component sender) { if (IsRunning) { scripts.CallFunction("OnComponentPlaced", sender.ID); } }
public Line(VertexPositionColorTexture cp1, VertexPositionColorTexture cp2, Components.Component cc1, Components.Component cc2) { p1 = cp1; p2 = cp2; c1 = cc1; c2 = cc2; }
public static void DrawSelectedBackground(Components.Component c) { if (c != null) { Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.renderer.GraphicsDevice.Viewport.Width, Main.renderer.GraphicsDevice.Viewport.Height, 0, 0, 1); selectedShader.Parameters["MatrixTransform"].SetValue(projection); selectedShader.Parameters["state"].SetValue((float)c.selectionShaderState / 20f); float[] p = new float[] { 1f / Main.renderer.GraphicsDevice.Viewport.Width, 1f / Main.renderer.GraphicsDevice.Viewport.Height }; selectedShader.Parameters["pixel1"].SetValue(p); selectedShader.Parameters["pixel2"].SetValue(new float[] { p[0] * 2, p[1] * 2 }); Main.renderer.End(); Main.renderer.BeginUnscaled(SpriteSortMode.Immediate, null, SamplerState.PointClamp, null, null, selectedShader); Main.renderer.Draw(c.selectionFBO, new Rectangle(0, 0, Main.WindowWidth, Main.WindowHeight), Color.White); Main.renderer.End(); Main.renderer.Begin(); c.Graphics.DrawBorder(Main.renderer); Main.renderer.End(); Main.renderer.Begin(); } else { //if (timeSelected > 0) // timeSelected--; } }
public RemovingComponentVisuals(Components.Component c) { var a = GraphicsEngine.Renderer; fbo = new RenderTarget2D(a.GraphicsDevice, Main.WindowWidth, Main.WindowHeight); g = c.Graphics; }
public void AddMonster(int x, int y, Core.DungeonMap m) { Core.Entity e = new Core.Entity(_entityID); Core.EntityReturner er; //int ind = r.Next(CreatNames.Count); int ind = Game.Random.Next(CreatNames.Count - 1); string creatureName = CreatNames[ind]; int entType = RogueSharp.DiceNotation.Dice.Roll("1d20"); if (entType <= 2) { er = Core.EntityFactory.CreateTroll(x, y, creatureName, m); } else if (entType > 2 && entType < 6) { er = Core.EntityFactory.CreateOrc(x, y, creatureName, m); } else if (entType >= 6 && entType < 12) { er = Core.EntityFactory.CreateKobold(x, y, creatureName, m); } else if (entType >= 12 && entType < 15) { er = Core.EntityFactory.CreateZombie(x, y, creatureName, m); } else { er = Core.EntityFactory.CreateRat(x, y, creatureName, m); } //add entity to entity dict Entities.Add(_entityID, er.ComponentList); EntityBitLookUp.Add(_entityID, er.LookUpBit); JustEntities.Add(_entityID, e); //add to PositionLookUp AddEntToPosition(x, y, e.UID); //try adding to schedule Components.Component ts = GetSingleComponentByID(_entityID, Core.ComponentTypes.Schedulable); if (ts != null) { Components.SchedulableComp sc = (Components.SchedulableComp)ts; int entTime = sc.Time; Game.ShedSystem.Add(e, entTime); } // inc entityID _entityID++; //add weapon to entity AddWeaponToEntity(e.UID); if (RogueSharp.DiceNotation.Dice.Roll("1d10") > 8) { AddPotionToEntity(e.UID); } }
public ArrowedLine(VertexPositionColorTexture cp1, VertexPositionColorTexture cp2, Components.Component cc1, Components.Component cc2) { p1 = cp1; p2 = cp2; c1 = cc1; c2 = cc2; arrowMatrix = Matrix.CreateRotationZ(-(float)Math.Atan2(c2.Graphics.Center.X - c1.Graphics.Center.X, c2.Graphics.Center.Y - c1.Graphics.Center.Y)); length = Math.Abs((c2.Graphics.Center - c1.Graphics.Center).Length()); }
public AABB(Vector2 a, Vector2 b, Components.Component p) { this.x1 = a.X; this.y1 = a.Y; this.x2 = b.X; this.y2 = b.Y; parent = p; SortCoords(); }
public AABB(float x1, float y1, float x2, float y2, Components.Component p) { this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; parent = p; SortCoords(); }
void GlobalEvents_onComponentSelected(Components.Component sender) { if (sender is Components.Properties.IUsesLight || sender is Components.Properties.ILightEmitting) { SelectedComponent = sender; } else { SelectedComponent = null; } }
void GlobalEvents_onComponentSelected(Components.Component sender) { if (sender is Components.Properties.IUsesMagnetism || sender is Components.Properties.IMagnetic) { SelectedComponent = sender; } else { SelectedComponent = null; } }
void bRemove_onClicked(object sender, InputEngine.MouseArgs e) { Sound.SoundPlayer.PlayButtonClick(); if (sender != null) { InputEngine.blockClick = true; } isVisible = false; Graphics.GUI.GUIEngine.RemoveHUDScene(this); SelectedComponent.OnButtonClickedRemove(); SelectedComponent = null; }
void GlobalEvents_onComponentRemovedByPlayer(Components.Component sender) { if (sender is Components.Joint) { return; } for (int i = 0; i < components.Count; i++) { if (components[i].objType == sender.GetType() && components[i].Avalable > -1) { components[i].Avalable++; } } }
public void SetTarget(Components.Component component, Coocoo3D.Core.Coocoo3DMain _appBody) { lightingComponent = (LightingComponent)component; appBody = _appBody; _cacheColor = lightingComponent.Color; if (lightingComponent.LightingType == LightingType.Directional) { radio1.IsChecked = true; } else if (lightingComponent.LightingType == LightingType.Point) { radio2.IsChecked = true; } }
public Components.Component GetSingleComponentByID(int eid, Core.ComponentTypes compType) { Components.Component returnComp = null; List <Components.Component> compList; if (Entities.TryGetValue(eid, out compList)) { if (compList != null) { returnComp = compList.FirstOrDefault(s => s.CompType == compType); } } return(returnComp); }
public void RegisterComponent(Components.Component comp) { CSComponent c = new CSComponent(); IO.Log.Write(" Adding " + comp.Graphics.GetCSToolTip() + " to ComponentSelector"); c.Texture = ResourceManager.Load <Texture2D>(comp.Graphics.GetIconName()); c.objType = comp.GetType(); c.instance = comp; c.componentGraphics = comp.Graphics; c.jointCoords0cw = comp.GetJointCoords(Components.Component.Rotation.cw0); c.jointCoords90cw = comp.GetJointCoords(Components.Component.Rotation.cw90); c.jointCoords180cw = comp.GetJointCoords(Components.Component.Rotation.cw180); c.jointCoords270cw = comp.GetJointCoords(Components.Component.Rotation.cw270); c.Name = comp.Graphics.GetCSToolTip(); c.IsDragDropPlacement = (comp is Components.Properties.IDragDropPlacable); /* * if (c.jointCoords0cw.Length % 2 == 1) * c.jointCoords0cw = new int[0]; * else * for (int i = 0; i < c.jointCoords0cw.Length; i++) * c.jointCoords0cw[i] = c.jointCoords0cw[i] - Math.Abs(c.jointCoords0cw[i] % 8); * * if (c.jointCoords90cw.Length % 2 == 1) * c.jointCoords90cw = new int[0]; * else * for (int i = 0; i < c.jointCoords90cw.Length; i++) * c.jointCoords90cw[i] = c.jointCoords90cw[i] - Math.Abs(c.jointCoords90cw[i] % 8); * * if (c.jointCoords180cw.Length % 2 == 1) * c.jointCoords180cw = new int[0]; * else * for (int i = 0; i < c.jointCoords180cw.Length; i++) * c.jointCoords180cw[i] = c.jointCoords180cw[i] - Math.Abs(c.jointCoords180cw[i] % 8); * * if (c.jointCoords270cw.Length % 2 == 1) * c.jointCoords270cw = new int[0]; * else * for (int i = 0; i < c.jointCoords270cw.Length; i++) * c.jointCoords270cw[i] = c.jointCoords270cw[i] - Math.Abs(c.jointCoords270cw[i] % 8);//*/ //comp.typeID = (short)components.Count; Components.ComponentsManager.TypeIDs.Add(comp.GetType(), (short)Components.ComponentsManager.TypeIDs.Count); components.Add(c); }
void GlobalEvents_onComponentPlacedByPlayer(Components.Component sender) { ScheduledReGen = true; }
void GlobalEvents_onComponentMoved(Components.Component sender) { ScheduledReGen = true; }
public OverlayToolTip(Components.Properties.IHasMapToolTip c, Components.Component filter) { isVisible = true; AssociatedComponent = c; this.filter = filter; }
public static void Update() { if (Main.curState.StartsWith("GAME") && !Graphics.GUI.GUIEngine.ContainsHUDScene(Graphics.GUI.GUIEngine.s_mainMenu)) { #region Simulation if (Settings.k_SimulationStart.IsMatched()) { Graphics.GUI.GUIEngine.s_runControl.strtClick(null, null); goto InputMatched; } if (Settings.k_SimulationStop.IsMatched()) { Graphics.GUI.GUIEngine.s_runControl.stpClick(null, null); goto InputMatched; } if (Settings.k_SimulationPause.IsMatched()) { Graphics.GUI.GUIEngine.s_runControl.psClick(null, null); goto InputMatched; } #endregion #region History if (Settings.k_Undo.IsMatched()) { Sound.SoundPlayer.PlayButtonClick(); Logics.ChangeHistory.Pop(); goto InputMatched; } #endregion #region Components if (Settings.k_ComponentRemove.IsMatched() || Settings.k_Eraser.IsMatched()) { bool wasRemoved = false; Components.Component container = null; int x = (int)(InputEngine.curMouse.X / Settings.GameScale - Settings.GameOffset.X); int y = (int)(InputEngine.curMouse.Y / Settings.GameScale - Settings.GameOffset.Y); for (int i = 0; i < Components.ComponentsManager.Components.Count; i++) { if (Components.ComponentsManager.Components[i].isIn(x, y) && Components.ComponentsManager.Components[i].Graphics.Visible) { if (Components.ComponentsManager.Components[i] is Components.Properties.IContainer) { container = Components.ComponentsManager.Components[i]; continue; } //if (Settings.GameState != Settings.GameStates.Stopped) //{ // MicroWorld.Graphics.OverlayManager.HighlightStop(); //} //else { wasRemoved = true; if (Components.ComponentsManager.Components[i] == MouseOverComponent) MouseOverComponent = null; Components.ComponentsManager.Components[i].OnButtonClickedRemove(); if (Settings.GameState != Settings.GameStates.Stopped) { CircuitManager.ReCreate(); } } break; } } if (wasRemoved && container != null) { InputEngine.blockClick = true; } if (!wasRemoved && container != null)// && Settings.GameState == Settings.GameStates.Stopped) { if (container == MouseOverComponent) MouseOverComponent = null; container.OnButtonClickedRemove(); if (Settings.GameState != Settings.GameStates.Stopped) { CircuitManager.ReCreate(); } } goto InputMatched; } #endregion #region Zoom if (Settings.k_ZoomIn.IsMatched()) { if (Settings.k_ZoomIn.WheelDelta != 0) { Settings.GameScale += (float)(InputEngine.curMouse.ScrollWheelValue - InputEngine.lastMouse.ScrollWheelValue) / 1200; } else { Settings.GameScale += 0.02f; } goto InputMatched; } if (Settings.k_ZoomOut.IsMatched()) { if (Settings.k_ZoomOut.WheelDelta != 0) { Settings.GameScale += (float)(InputEngine.curMouse.ScrollWheelValue - InputEngine.lastMouse.ScrollWheelValue) / 1200; } else { Settings.GameScale -= 0.02f; } goto InputMatched; } #endregion #region Grid if (Settings.k_ToggleGrid.IsMatched()) { Graphics.GUI.GridDraw.ShouldDrawGrid = !Graphics.GUI.GridDraw.ShouldDrawGrid; goto InputMatched; } #endregion #region ComponentRotation if (Settings.k_ComponentRotateCW.IsMatched()) { var old = GhostRotation; var a = Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponentGraphics.GetPossibleRotations(); if (a == null || a.Length == 0) { GhostRotation = Components.Component.Rotation.cw0; return; } int t = GhostRotation.GetHashCode() + 1; while (t >= a.Length) t -= a.Length; while (t < 0) t += a.Length; GhostRotation = a[t]; goto InputMatched; } if (Settings.k_ComponentRotateCCW.IsMatched()) { var old = GhostRotation; var a = Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponentGraphics.GetPossibleRotations(); if (a == null || a.Length == 0) { GhostRotation = Components.Component.Rotation.cw0; return; } int t = GhostRotation.GetHashCode() - 1; while (t >= a.Length) t -= a.Length; while (t < 0) t += a.Length; GhostRotation = a[t]; goto InputMatched; } #endregion goto PostInput; InputMatched: PostInput: ; } }
public static void onButtonDown(InputEngine.MouseArgs e) { //create placable area if (Graphics.GUI.Scene.PlacableAreasCreator.create) { int x1 = e.curState.X; int y1 = e.curState.Y; GridHelper.GridCoords(ref x1, ref y1); pendingWireP1 = new Vector2(x1, y1); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); isPlacableAreaPending = true; return; } //delete placable area if (Graphics.GUI.Scene.PlacableAreasCreator.delete) { if (PlacableAreasManager.Remove(e.curState.X, e.curState.Y) && !InputEngine.Shift) Graphics.GUI.Scene.PlacableAreasCreator.delete = false; } //Resize if (e.button == 0 && MouseOverComponent != null && MouseOverComponent is Components.Properties.IResizable) { int x1 = e.curState.X; int y1 = e.curState.Y; GridHelper.GridCoords(ref x1, ref y1); var a = (MouseOverComponent as Components.Properties.IResizable).CanResize(new Vector2(x1, y1)); if (a != Direction.None) { resizeLastPoint = new Vector2(InputEngine.curMouse.X, InputEngine.curMouse.Y); resizeType = a; resizeComponent = MouseOverComponent as Components.Properties.IResizable; (MouseOverComponent as Components.Properties.IResizable).OnResizeStart(a, new Vector2(x1, y1)); return; } } //Cancel resize if (e.button == 1 && resizeComponent != null) { resizeComponent.CancelResize(); resizeComponent = null; resizeType = Direction.None; return; } //DnD component if (e.button == 0 && Graphics.GUI.GUIEngine.ContainsHUDScene(Graphics.GUI.GUIEngine.s_subComponentButtons) && Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent.isIn(e.curState.X, e.curState.Y) && Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent.CanDragDrop() && Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent.IsMovable()) { if (Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent is Components.Joint) { if (!InputEngine.Control) { goto DnDPass; } } //if (Settings.GameState == Settings.GameStates.Stopped) { isDragDrop = true; canMove = true; DragDropComponent = Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent; DragDropStart = DragDropComponent.Graphics.Position; DnDStartOffset = new Vector2(e.curState.X, e.curState.Y) - DragDropStart; DragDropDelta = new Vector2(); } //else //{ // Graphics.OverlayManager.HighlightStop(); //} return; DnDPass: ; } //cancel DnD if (isDragDrop && e.button == 1) { isDragDrop = false; DragDropComponent = null; } if (isComponentDnD && e.button == 1) { isComponentDnD = false; DnDComponent = null; } //shift-placing wires if (e.button == 0 && InputEngine.Shift && Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent != null && Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent is Components.Joint) { int x1 = e.curState.X; int y1 = e.curState.Y; GridHelper.GridCoords(ref x1, ref y1); var a = HasJointAtCoord(x1, y1); if (a != null) { bool b = false; foreach (var wr in (Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent as Components.Joint).ConnectedWires) { if ((wr.J1.ID == Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent.ID && wr.J2.ID == a.ID) || (wr.J2.ID == Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent.ID && wr.J1.ID == a.ID)) { b = true; break; } } if (!b) { Components.Wire w = new Components.Wire(Graphics.GUI.GUIEngine.s_subComponentButtons.SelectedComponent as Components.Joint, a); w.Initialize(); Graphics.GUI.GUIEngine.s_componentSelector.DecreaseComponentAvilability("Wire"); Components.ComponentsManager.Add(w); w.OnPlaced(); IgnoreNextClick = true; if (Settings.GameState != Settings.GameStates.Stopped) { CircuitManager.ReCreate(); } return; } } } //placing wire if (Graphics.GUI.GUIEngine.s_componentSelector.GetComponent("Wire").Enabled && e.button == 0) { //if (Settings.GameState != Settings.GameStates.Stopped) //{ //Graphics.OverlayManager.HighlightStop(); // return; //} if (Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponent.Text == "Wire") { isLine = true; } else { goto PostWire; } int x1 = e.curState.X; int y1 = e.curState.Y; GridHelper.GridCoords(ref x1, ref y1); if (isLine) { pendingWirePath.Clear(); if (PlacableAreasManager.IsPlacable(x1, y1)) { if (HasJointAtCoord(x1, y1) == null && Components.ComponentsManager.VisibilityMap.GetAStarValue(x1, y1) == 0)//smth in the way return; //isLine = true; pendingWirePath.Clear(); pendingWireP1 = new Vector2(x1, y1); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); Components.Joint jj; Components.ComponentsManager.IgnoreAS1 = null; Components.ComponentsManager.IgnoreAS2 = null; if ((jj = HasJointAtCoord(x1, y1)) != null) { Components.ComponentsManager.IgnoreAS1 = jj; } } else { isLine = false; } } return; PostWire: ; //j1 = GetJointForCoord(e); } //canceling wire if (isLine && e.button == 1) { isLine = false; } //DnD-placing component if (Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponent.IsDragDropPlacement && !isLine && !isComponentDnD) { //if (Settings.GameState != Settings.GameStates.Stopped) //{ // Graphics.OverlayManager.HighlightStop(); // return; //} DnDComponent = Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponent.component.GetNewInstance() as Components.Properties.IDragDropPlacable; if (DnDComponent == null) return; int x1 = e.curState.X; int y1 = e.curState.Y; GridHelper.GridCoords(ref x1, ref y1); if (DnDComponent.CanStart(x1, y1)) { pendingWireP1 = new Vector2(x1, y1); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); isComponentDnD = true; } else { DnDComponent = null; isComponentDnD = false; } return; } //dragging wire from joint Components.Joint j; if (!InputEngine.Control && (j = HasJointAtCoord(e.curState.X, e.curState.Y)) != null && Graphics.GUI.GUIEngine.s_componentSelector.GetComponent("Wire").Enabled) { //if (Settings.GameState != Settings.GameStates.Stopped) //{ // Graphics.OverlayManager.HighlightStop(); // return; //} int x1 = e.curState.X; int y1 = e.curState.Y; GridHelper.GridCoords(ref x1, ref y1); if (PlacableAreasManager.IsPlacable(x1, y1)) { isLine = true; pendingWirePath.Clear(); pendingWireP1 = new Vector2(x1, y1); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); Components.ComponentsManager.IgnoreAS1 = null; Components.ComponentsManager.IgnoreAS2 = null; } return; } //DnD w/o selection if (e.button == 0) { LastLeftClick = new Vector2(e.curState.X, e.curState.Y); } else { LastLeftClick = null; } }
public void Add(Components.Component component) { components.Add(component); }
public override void Update() { if (!isActive) return; if (ScheduledReGen) { ScheduledReGen = false; ReGenAll(); } for (int i = 0; i < tooltips.Count; i++) { tooltips[i].Update(); } if (selectedComponent != null && !selectedComponent.GetComponentToolTip().isVisible) { SelectedComponent = null; } for (int i = 0; i < lines.Count; i++) { lines[i].Update(); } for (int i = 0; i < fadeOutLines.Count; i++) { fadeOutLines[i].Update(); if (fadeOutLines[i].IsDead) { fadeOutLines.RemoveAt(i); i--; } } #region Fades if (fadeState == FadeState.FadeIn) { opacity += 0.07f; if (opacity >= 1) { opacity = 1; fadeState = FadeState.None; } } if (fadeState == FadeState.FadeOut) { opacity -= 0.07f; if (opacity <= 0) { opacity = 0; fadeState = FadeState.None; isActive = false; LightAOE.Visible = false; } } LightAOE.FadeOpacity = opacity; #endregion var r = GraphicsEngine.Renderer; r.EnableFBO(fbo); r.GraphicsDevice.Clear(Color.Transparent); r.Begin(); DrawToFBO(r); r.End(); r.DisableFBO(); base.Update(); }
void GlobalEvents_onComponentSelected(Components.Component sender) { if (sender is Components.Properties.IUsesMagnetism|| sender is Components.Properties.IMagnetic) SelectedComponent = sender; else SelectedComponent = null; }
public override void Update() { if (!isActive) { return; } if (ScheduledReGen) { ScheduledReGen = false; ReGenAll(); } for (int i = 0; i < tooltips.Count; i++) { tooltips[i].Update(); } if (selectedComponent != null && !selectedComponent.GetComponentToolTip().isVisible) { SelectedComponent = null; } for (int i = 0; i < lines.Count; i++) { lines[i].Update(); } for (int i = 0; i < fadeOutLines.Count; i++) { fadeOutLines[i].Update(); if (fadeOutLines[i].IsDead) { fadeOutLines.RemoveAt(i); i--; } } #region Fades if (fadeState == FadeState.FadeIn) { opacity += 0.07f; if (opacity >= 1) { opacity = 1; fadeState = FadeState.None; } } if (fadeState == FadeState.FadeOut) { opacity -= 0.07f; if (opacity <= 0) { opacity = 0; fadeState = FadeState.None; isActive = false; LightAOE.Visible = false; } } LightAOE.FadeOpacity = opacity; #endregion var r = GraphicsEngine.Renderer; r.EnableFBO(fbo); r.GraphicsDevice.Clear(Color.Transparent); r.Begin(); DrawToFBO(r); r.End(); r.DisableFBO(); base.Update(); }
public override void Assign(Microsoft.Xna.Framework.Content.ContentManager cm, Components.Component comp, string binder) { var prop = comp.GetType().GetProperty(binder); var propType = prop.PropertyType; T[] arguments = new T[Count]; for (int i = 0; i < arguments.Length; i++) { arguments[i] = _data[i]; } var list = Activator.CreateInstance(propType, new object[] { arguments }); prop.SetValue(comp, list, null); }
public static void onButtonUp(InputEngine.MouseArgs e) { if (Graphics.GUI.Scene.PlacableAreasCreator.create) { Graphics.GUI.Scene.PlacableAreasCreator.create = false; int x2 = e.curState.X; int y2 = e.curState.Y; GridHelper.GridCoords(ref x2, ref y2); isPlacableAreaPending = false; PlacableAreasManager.Add(new Rectangle((int)pendingWireP1.X, (int)pendingWireP1.Y, (int)(x2 - pendingWireP1.X), (int)(y2 - pendingWireP1.Y))); return; } if (resizeComponent != null) { resizeComponent.OnResizeFinished(resizeType); resizeComponent = null; resizeType = Direction.None; return; } if (isDragDrop) { isDragDrop = false; DragDropComponent = null; return; } if (isLine) { int x2 = e.curState.X; int y2 = e.curState.Y; PlacableAreasManager.MakePlacable(ref x2, ref y2); GridHelper.GridCoords(ref x2, ref y2); if (pendingWireP1.X == x2 && pendingWireP1.Y == y2) { isLine = false; pendingWireP1 = new Vector2(); return; } Components.Joint tj1 = HasJointAtCoord((int)pendingWireP1.X, (int)pendingWireP1.Y), tj2 = HasJointAtCoordForWire(x2, y2); var a1 = Components.ComponentsManager.VisibilityMap.GetAStarValue((int)pendingWireP1.X + 2, (int)pendingWireP1.Y + 2); var a2 = tj2 == null ? Components.ComponentsManager.VisibilityMap.GetAStarValue((int)x2 + 2, (int)y2 + 2) : 0; if (tj2 == null) { tj2 = GetJointForCoordIfCan(x2, y2); if (tj2 == null) { isLine = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); return; } } if ((pendingWireP1.X != tj2.Graphics.Position.X || pendingWireP1.Y != tj2.Graphics.Position.Y) && !Components.Graphics.WireGraphics.CanFindPath(tj1, tj2, (int)pendingWireP1.X + 4, (int)pendingWireP1.Y + 4, (int)pendingWireP2.X + 4, (int)pendingWireP2.Y + 4)) { isLine = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); return; } if (pendingWireP1.X != tj2.Graphics.Position.X || pendingWireP1.Y != tj2.Graphics.Position.Y) { MicroWorld.Logics.ChangeHistory.Push(); Statistics.ElementsPlaced++; j1 = GetJointForCoord(pendingWireP1); Components.Joint j2 = GetJointForCoord((int)tj2.Graphics.Position.X, (int)tj2.Graphics.Position.Y); //w Components.Wire w = new Components.Wire(j1, j2); w.Initialize(); Graphics.GUI.GUIEngine.s_componentSelector.DecreaseComponentAvilability("Wire"); Components.ComponentsManager.Add(w); w.OnPlaced(); if (a1 == Components.VisibilityMap.WIRE) { var a = GetWiresForCoord((int)pendingWireP1.X, (int)pendingWireP1.Y); for (int i = 0; i < a.Count; i++) { if (a[i] != w && a[i].J1 != j1 && a[i].J2 != j1) SplitWire(a[i], j1); } } if (a2 == Components.VisibilityMap.WIRE) { var a = GetWiresForCoord((int)tj2.Graphics.Position.X, (int)tj2.Graphics.Position.Y); for (int i = 0; i < a.Count; i++) { if (a[i] != w && a[i].J1 != j2 && a[i].J2 != j2) SplitWire(a[i], j2); } } CircuitManager.ReCreate(); } isLine = false; return; } if (isComponentDnD) { int x2 = e.curState.X; int y2 = e.curState.Y; PlacableAreasManager.MakePlacable(ref x2, ref y2); GridHelper.GridCoords(ref x2, ref y2); if (pendingWireP1.X == x2 && pendingWireP1.Y == y2) { isComponentDnD = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); DnDComponent = null; return; } if (!DnDComponent.CanEnd((int)pendingWireP1.X, (int)pendingWireP1.Y, x2, y2)) { isComponentDnD = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); DnDComponent = null; return; } MicroWorld.Logics.ChangeHistory.Push(); DnDComponent.Place((int)pendingWireP1.X, (int)pendingWireP1.Y, x2, y2); MicroWorld.Graphics.GUI.GUIEngine.s_componentSelector.DecreaseComponentAvilability((DnDComponent as Components.Component).Graphics.GetCSToolTip()); CircuitManager.ReCreate(); isComponentDnD = false; pendingWireP1 = new Vector2(); pendingWireP2 = new Vector2(pendingWireP1.X, pendingWireP1.Y); DnDComponent = null; return; } if (e.button == 0 && InputEngine.LeftMouseButtonDownPos != null && MicroWorld.Graphics.GUI.GUIEngine.s_componentSelector.SelectedComponent.IsIn( (int)InputEngine.LeftMouseButtonDownPos.Value.X, (int)InputEngine.LeftMouseButtonDownPos.Value.Y)) { TryPlaceComponent(ref e); } }
public static void onMouseMove(InputEngine.MouseMoveArgs e) { //int x = e.curState.X, y = e.curState.Y; //Utilities.Tools.ScreenToGameCoords(ref x, ref y); if (LastLeftClick != null && InputEngine.curMouse.LeftButton == ButtonState.Pressed && DnDComponent == null) { if (MouseOverComponent == null || MouseOverComponent is Components.Joint || MouseOverComponent is Components.Wire || !MouseOverComponent.CanDragDrop() || !MouseOverComponent.IsMovable() || Graphics.GUI.GUIEngine.IsIn(InputEngine.curMouse.X, InputEngine.curMouse.Y)) { LastLeftClick = null; } else { if (DragDropComponent == null && LastLeftClick != null && (new Vector2(e.curState.X, e.curState.Y) - LastLeftClick).Value.Length() > Graphics.GUI.GridDraw.Step) { canMove = true; isDragDrop = true; DragDropComponent = MouseOverComponent; DragDropDelta = new Vector2(e.curState.X, e.curState.Y) - LastLeftClick.Value; DragDropDelta -= new Vector2(e.dx, e.dy); DragDropStart = DragDropComponent.Graphics.Position; DnDStartOffset = new Vector2(e.curState.X, e.curState.Y) - DragDropStart; } } } if (resizeComponent != null) { resizeComponent.Resize(resizeType, (float)(InputEngine.curMouse.X - resizeLastPoint.X) / Settings.GameScale, (float)(InputEngine.curMouse.Y - resizeLastPoint.Y) / Settings.GameScale); resizeLastPoint = new Vector2(InputEngine.curMouse.X, InputEngine.curMouse.Y); } MouseOverComponents = Components.ComponentsManager.GetVisibleComponents(e.curState.X, e.curState.Y); MouseOverComponent = Components.ComponentsManager.GetTopVisibleComponent(MouseOverComponents); if (isDragDrop) { //if (Settings.GameState != Settings.GameStates.Stopped) //{ // isDragDrop = false; // return; //} int tcx = (int)(e.curState.X - DnDStartOffset.X), tcy = (int)(e.curState.Y - DnDStartOffset.Y); GridHelper.GridCoords(ref tcx, ref tcy); DragDropDelta = new Vector2(tcx, tcy) - DragDropComponent.Graphics.Position; Vector2 t = new Vector2(DragDropDelta.X, DragDropDelta.Y); DragDropDelta -= t; if (t.X != 0 || t.Y != 0) { if (PlacableAreasManager.IsPlacable(DragDropComponent.Graphics.Position.X + t.X, DragDropComponent.Graphics.Position.Y + t.Y, DragDropComponent.Graphics.Size.X, DragDropComponent.Graphics.Size.Y) && (CanMove(DragDropComponent, DragDropComponent.Graphics.Position + t) || (DragDropComponent != null && DragDropComponent is Components.Joint && HasJointAtCoord((int)(DragDropComponent.Graphics.Position.X + t.X), (int)(DragDropComponent.Graphics.Position.Y + t.Y)) != null))) { canMove = true; DragDropComponent.OnMove((int)t.X, (int)t.Y); } else { canMove = false; } } return; } if (isLine) { int x = e.curState.X, y = e.curState.Y; GridHelper.GridCoords(ref x, ref y); Components.Joint j; if ((j = HasJointAtCoordForWire(x, y)) != null) { pendingWireP2 = new Vector2(j.Graphics.Position.X, j.Graphics.Position.Y); Components.ComponentsManager.IgnoreAS2 = j; } else { pendingWireP2 = new Vector2(x, y); Components.ComponentsManager.IgnoreAS2 = null; } if (Components.ComponentsManager.VisibilityMap.GetAStarValue((int)pendingWireP2.X, (int)pendingWireP2.Y) != 0) { if (pathThread != null) pathThread.Abort(); pathThread = new System.Threading.Thread(new System.Threading.ThreadStart(UpdatePendingWirePath)); pathThread.IsBackground = true; pathThread.Start(); } } }
void GlobalEvents_onComponentSelected(Components.Component sender) { if (sender is Components.Properties.IUsesLight || sender is Components.Properties.ILightEmitting) SelectedComponent = sender; else SelectedComponent = null; }
public void Remove(Components.Component component) { toBeRemoved.Add(component); }
void GlobalEvents_onComponentPlacedByPlayer(Components.Component sender) { button1_Click(null, null); }