void ProcessInfastructureState() { //Update if (data.Input.CheckKeyPressed(Keyboard.Key.L)) { string FileName; if (GetFileFromBrowser(out FileName)) { InfastructureHolder InfLoadHolder = new InfastructureHolder(); InfLoadHolder.parseFile(FileName); if (InfLoadHolder.isValid()) { Sprite env = new Sprite(InfLoadHolder.exportTextureResults()); env.Origin = new Vector2f(512, 512); env.Position = new Vector2f(512, 512); env.Rotation = -90; EnvironmentProduction.Draw(env); } } } //Check Transition //if (data.Input.CheckKeyPressed(Keyboard.Key.M)) // LeaveInfastructureState(); }
/// <summary> /// This paints the cursor onto the environment when the user modifies something. /// </summary> private void PaintCursor() { CircleShape CursorImage = new CircleShape(); //CursorImage.Origin = new Vector2f(CursorRadius * 1.1f, CursorRadius * 1.1f); CursorImage.Origin = new Vector2f(CursorRadius, CursorRadius); CursorImage.OutlineColor = Color.Black; CursorImage.OutlineThickness = 2f; CursorImage.Radius = CursorRadius; CursorImage.FillColor = new Color( (byte)(CursorColor.R * data.Settings.CursorPaintStep), (byte)(CursorColor.G * data.Settings.CursorPaintStep), (byte)(CursorColor.B * data.Settings.CursorPaintStep)); //CursorImage.Position = ((Vector2f)Mouse.GetPosition() - (Vector2f)data.Graphics.ProgramWindow.Position) * 4.0f; CursorImage.Position = new Vector2f((Mouse.GetPosition(data.Graphics.ProgramWindow).X - data.Settings.InformationResolution.X), Mouse.GetPosition(data.Graphics.ProgramWindow).Y); // new position for swapped windows if (CursorAdditive) { EnvironmentProduction.Draw(CursorImage, Additive); } else { EnvironmentProduction.Draw(CursorImage, Subtractive); } }
/// <summary> /// This gets the average color for the area around the cursor. It's used for the inspection. /// </summary> /// <returns>The average color</returns> private Color getAverageColor() { //Vector2f Position = ((Vector2f)Mouse.GetPosition() - (Vector2f)data.Graphics.ProgramWindow.Position) * 4.0f; Vector2f Position = new Vector2f((Mouse.GetPosition(data.Graphics.ProgramWindow).X - data.Settings.InformationResolution.X), Mouse.GetPosition(data.Graphics.ProgramWindow).Y); // new position for swapped windows EnvironmentProduction.Display(); Image icopy = EnvironmentProduction.Texture.CopyToImage(); float R = 0, B = 0, G = 0; int n = 0; for (int x = -(int)Math.Ceiling(CursorRadius); x < (int)Math.Ceiling(CursorRadius); x++) { if (x + Position.X < 0) { continue; } else if (x + Position.X > CursorProduction.Size.X) { continue; } for (int y = -(int)Math.Ceiling(CursorRadius); y < (int)Math.Ceiling(CursorRadius); y++) { if (y + Position.Y < 0) { continue; } else if (y + Position.Y > CursorProduction.Size.Y) { continue; } n++; Color pColor = icopy.GetPixel((uint)(x + Position.X), (uint)(y + Position.Y)); R += pColor.R; G += pColor.G; B += pColor.B; } } return(new Color((byte)(R / n), (byte)(G / n), (byte)(B / n))); }
/// <summary> /// This is the primary function for the input stage. /// It executes once per iteration and checks for events such as key or mouse clicks, and draws the cursor as appropriate. /// </summary> public override void Update() { // Hide Mouse Pointer while over simulation area bool hideMouseCursor = Mouse.GetPosition(Button.RenderWindow).X >= data.Settings.InformationResolution.X && Mouse.GetPosition(Button.RenderWindow).Y >= 0; Button.RenderWindow.SetMouseCursorVisible(!hideMouseCursor); CursorProduction.Clear(Color.Black); if (Mouse.IsButtonPressed(Mouse.Button.Left)) // handle regular button clicks { Button clickedButton = Button.GetButtonClicked(); if (clickedButton != null) { switch (clickedButton.Function) { case Button.ButtonFunctions.LoadMap: { string FileName; if (GetFileFromBrowser(out FileName)) { InfastructureHolder InfLoadHolder = new InfastructureHolder(); InfLoadHolder.parseFile(FileName); if (InfLoadHolder.isValid()) { Sprite env = new Sprite(InfLoadHolder.exportTextureResults()); env.Origin = new Vector2f(512, 512); env.Position = new Vector2f(512, 512); env.Rotation = -90; EnvironmentProduction.Draw(env); MapIsLoaded = true; // enable panels processInspectState = true; // begin processing inspect state foreach (Panel current in Panel.PanelList) { current.SetActive(true); } RadioButton.ReturnColorsToNormal(); RadioButton.GetRadioButtonByFunction(RadioButton.ButtonFunctions.Inspect).SelectRadioButton(); } } break; } case Button.ButtonFunctions.RunSim: { if (MapIsLoaded) { if (data.SpawnPositions.Count == 0) { if (SpawnWarning) { ErrorText.CurrentErrorText.ShowErrorText("At least one spawn must be set", 1f); // show spawn point error } } else { EnvironmentProduction.Display(); data.Environment = EnvironmentProduction.Texture.CopyToImage(); PerformStageTransition = true; return; } } break; } } } } if (Mouse.IsButtonPressed(Mouse.Button.Left) && MapIsLoaded) // handle radio button clicks { RadioButton ClickedButton = RadioButton.GetRadioButtonClicked(); if (ClickedButton != null) { Panel.GetPanelByMode(Panel.PanelModes.InspectMode).SetActive(false); processInspectState = false; ClickedButton.SelectRadioButton(); switch (ClickedButton.ButtonFunction) { case RadioButton.ButtonFunctions.Inspect: { Panel.GetPanelByMode(Panel.PanelModes.InspectMode).SetActive(true); processInspectState = true; EnterInspectState(); break; } case RadioButton.ButtonFunctions.PaintDamage: { EnterDamageState(); break; } case RadioButton.ButtonFunctions.PaintDifficulty: { EnterDifficultyState(); break; } case RadioButton.ButtonFunctions.PaintValue: { EnterValueState(); break; } } } } if (processInspectState) { ProcessInspectState(); } else if (MapIsLoaded) // Paint Mode { InteractCursor(); switch (CurrentInputState) { case InputStates.Damage: { ProcessDamageState(); break; } case InputStates.Difficulty: { ProcessDifficultyState(); break; } case InputStates.Value: { ProcessValueState(); break; } } } EnvironmentProduction.Display(); CursorProduction.Display(); Sprite EnvironmentSprite = new Sprite(EnvironmentProduction.Texture); Sprite CursorSprite = new Sprite(CursorProduction.Texture); data.Graphics.ProgramDisplayTexture.Draw(EnvironmentSprite, new RenderStates(BlendMode.Add)); data.Graphics.ProgramDisplayTexture.Draw(CursorSprite, new RenderStates(BlendMode.Add)); }