Example #1
0
    /// <summary>
    /// The initialize function will setup all of the elements of the project. Namely SFML components.
    /// </summary>
    /// <param name="d">A reference to the primary data structure in the application.</param>
    public void Initialize(Data d)
    {
        data = d;

        ProgramDisplayTexture = new RenderTexture(data.Settings.SimulationResolution.X, data.Settings.SimulationResolution.Y);
        ProgramInfoTexture    = new RenderTexture(data.Settings.InformationResolution.X, data.Settings.InformationResolution.Y);
        ProgramWindow         = new RenderWindow(new VideoMode(data.Settings.ScreenResolution.X, data.Settings.ScreenResolution.Y), "Disaster Reactor - CS4330 Project", Styles.Close | Styles.Titlebar);

        Button.RenderWindow       = ProgramWindow;
        RadioButton.RenderWindow  = ProgramWindow;
        ToggleButton.RenderWindow = ProgramWindow;
        ProgramWindow.Closed     += onWindowClose;

        ProgramWindow.Clear(Color.White);
        ProgramWindow.Display();
        ProgramWindow.RequestFocus();

        RegularFont       = new Font("Anonymous_Pro.ttf");
        Button.ButtonFont = RegularFont;
        BoldFont          = new Font("Anonymous_Pro_B.ttf");

        HeaderText               = new Text("Initializing...", RegularFont);
        HeaderText.Color         = Color.Black;
        HeaderText.Font          = RegularFont;
        HeaderText.CharacterSize = data.Settings.InformationFontSize + 4;
        HeaderText.Position      = new Vector2f(5, 5);

        //INSPECT MODE HEADER TEXT
        ModesHeaderText               = new Text("Inspect Mode", RegularFont);
        ModesHeaderText.Color         = Color.Black;
        ModesHeaderText.CharacterSize = data.Settings.InformationFontSize + 10;

        //PAINT MODE HEADER TEXT
        InfoHeaderText               = new Text("Mode", RegularFont);
        InfoHeaderText.Color         = Color.Black;
        InfoHeaderText.CharacterSize = data.Settings.InformationFontSize + 10;
        InfoHeaderText.Origin        = new Vector2f(InfoHeaderText.GetLocalBounds().Width / 2f, InfoHeaderText.GetLocalBounds().Height / 2f);

        TextTemplate               = new Text("VOID", RegularFont);
        TextTemplate.Color         = Color.Black;
        TextTemplate.CharacterSize = data.Settings.InformationFontSize;

        //Creating Panels
        InspectModePanel = new Panel(new Vector2f(data.Settings.InformationResolution.X * 0.85f, data.Settings.InformationResolution.Y * 0.38f), new Vector2f(data.Settings.InformationResolution.X / 2f, data.Settings.InformationResolution.Y * 0.37f), Panel.PanelModes.InspectMode);
        PaintModePanel   = new Panel(new Vector2f(data.Settings.InformationResolution.X * 0.85f, data.Settings.InformationResolution.Y * 0.30f), new Vector2f(data.Settings.InformationResolution.X / 2f, data.Settings.InformationResolution.Y * 0.05f), Panel.PanelModes.PaintMode);

        //Creating Buttons
        LoadMapButton = new Button("loadmapimage.png", new Vector2f(data.Graphics.ProgramInfoTexture.Size.X / 5f, data.Graphics.ProgramInfoTexture.Size.Y * 0.95f), Button.ButtonFunctions.LoadMap);
        RunSimButton  = new Button("runsimimage.png", new Vector2f(4 * data.Graphics.ProgramInfoTexture.Size.X / 5f, data.Graphics.ProgramInfoTexture.Size.Y * 0.95f), Button.ButtonFunctions.RunSim);

        //Creating Radio Buttons
        InspectModeButton     = new RadioButton(new Vector2f(PaintModePanel.PanelShape.GetGlobalBounds().Width / 2f - 150, 160), RadioButton.ButtonFunctions.Inspect);
        PaintDamageButton     = new RadioButton(new Vector2f(PaintModePanel.PanelShape.GetGlobalBounds().Width / 2f - 150, 210), RadioButton.ButtonFunctions.PaintDamage);
        PaintDifficultyButton = new RadioButton(new Vector2f(PaintModePanel.PanelShape.GetGlobalBounds().Width / 2f - 150, 260), RadioButton.ButtonFunctions.PaintDifficulty);
        PaintValueButton      = new RadioButton(new Vector2f(PaintModePanel.PanelShape.GetGlobalBounds().Width / 2f - 150, 310), RadioButton.ButtonFunctions.PaintValue);


        //Creating Toggle Buttons
        ToggleAgentsButton = new ToggleButton(new Vector2f(80, 182), ToggleButton.ToggleOptions.ToggleAgents);
        ToggleAgentsButton.ChangeToggleStatus(true);
        ToggleEnvironmentButton = new ToggleButton(new Vector2f(80, 230), ToggleButton.ToggleOptions.ToggleEnvironment);
        ToggleEnvironmentButton.ChangeToggleStatus(true);
        ToggleSpawnsButton = new ToggleButton(new Vector2f(80, 278), ToggleButton.ToggleOptions.ToggleSpawns);
        ToggleSpawnsButton.ChangeToggleStatus(true);
        ToggleTrailsButton = new ToggleButton(new Vector2f(80, 326), ToggleButton.ToggleOptions.ToggleTrails);
        ToggleTrailsButton.ChangeToggleStatus(true);
    }
    public override void Update()
    {
        foreach (Agent a in data.Agents)
        {
            a.Update();
        }

        if (!mouseClickUsable) // ugly placement for custom mouse click delay
        {
            mouseClickDelay -= data.Time.deltaTime;
            if (mouseClickDelay <= 0)
            {
                mouseClickUsable = true;
                mouseClickDelay  = 0.25f;
            }
        }

        if (Mouse.IsButtonPressed(Mouse.Button.Left) && mouseClickUsable) // check for toggle or print button clicks
        {
            mouseClickUsable = false;
            ToggleButton ClickedToggleButton = ToggleButton.GetToggleButtonClicked();
            if (ClickedToggleButton != null)
            {
                ClickedToggleButton.ChangeToggleStatus(!ClickedToggleButton.IsToggled);
                switch (ClickedToggleButton.ToggleOption)
                {
                case ToggleButton.ToggleOptions.ToggleAgents:
                {
                    data.RenderAgents = ClickedToggleButton.IsToggled;
                    break;
                }

                case ToggleButton.ToggleOptions.ToggleEnvironment:
                {
                    renderEnv = ClickedToggleButton.IsToggled;
                    break;
                }

                case ToggleButton.ToggleOptions.ToggleSpawns:
                {
                    data.RenderSpawn = ClickedToggleButton.IsToggled;
                    break;
                }

                case ToggleButton.ToggleOptions.ToggleTrails:
                {
                    renderTra = ClickedToggleButton.IsToggled;
                    break;
                }
                }
            }
            else
            {
                Button ClickedButton = Button.GetButtonClicked();
                if (ClickedButton != null)
                {
                    if (ClickedButton.Function == Button.ButtonFunctions.PrintPDF)
                    {
                        string thePath;
                        FolderBrowserDialog FBD = new FolderBrowserDialog();
                        if (FBD.ShowDialog() == DialogResult.OK)
                        {
                            thePath = FBD.SelectedPath;
                        }
                        else
                        {
                            thePath = "NULL";
                        }
                        PrintResults(thePath);
                    }
                    else if (ClickedButton.Function == Button.ButtonFunctions.ExitSim)
                    {
                        data.Input.EscapeKeyPressed = true;
                    }
                }
            }
        }

        //if(data.Input.CheckKeyPressed(Keyboard.Key.A))
        //{
        //    data.RenderAgents = !data.RenderAgents;
        //}

        //if(data.Input.CheckKeyPressed(Keyboard.Key.S))
        //{
        //    data.RenderSpawn = !data.RenderSpawn;
        //}

        //if(data.Input.CheckKeyPressed(Keyboard.Key.E))
        //{
        //    renderEnv = !renderEnv;
        //}

        //if(data.Input.CheckKeyPressed(Keyboard.Key.T))
        //{
        //    renderTra = !renderTra;
        //}


        if (renderEnv)
        {
            data.Graphics.ProgramDisplayTexture.Draw(SEnv, new RenderStates(BlendMode.Add));
        }

        if (renderTra)
        {
            TTra.Update(data.Trails);

            data.Graphics.ProgramDisplayTexture.Draw(STra, new RenderStates(BlendMode.Add));
        }


        data.Graphics.ProgramDisplayTexture.Display();
    }