<commit_before>#include "Grapher.h"
#include <iostream>
#include <algorithm>
Grapher::Grapher() : fileManager("dialogue/")
{
	window.create(sf::VideoMode(1280, 720), "Scenario Grapher");

	// Loading the font
	font.loadFromFile("assets/fonts/Inconsolata.otf");

	nodeCount = 0;
	scale = 1.f;
	selectedNode = NULL;
	selectedInputBox = NULL;
	clickedNode = NULL;
	connEdit = NULL;
	flagEdit = NULL;
	movingView = false;
	showNodeNames = true;

	for (int i = 0; i < 2; ++i)
		connectingNodes[i] = NULL;

	imageManager.loadImage("assets/images/interface/buttons/flag.png", "flag");
	imageManager.loadImage("assets/images/interface/buttons/plus.png", "plus");

	ibox = InputBox(sf::Vector2f(window.getSize().x - 290,window.getSize().y - 50), sf::Vector2f(280,25), font);
	ibox.setActive(false);

	// Defining the UI colors
	colors["button"] = sf::Color(142, 196, 137);
	colors["background"] = sf::Color(31,31,31);
	colors["graphBG"] = sf::Color(43,43,43);
	colors["buttonHighlight"] = sf::Color(179,80,80);

	moduleName.setString("untitled");
	moduleName.setFont(font);
	moduleName.setCharacterSize(20);
	moduleName.setColor(sf::Color::White);

	sf::Vector2f bgSize(300, window.getSize().y);
	graphBG = sf::RectangleShape(bgSize);
	graphBG.setFillColor(colors["graphBG"]);
	graphBG.setPosition(window.getSize().x - 300,0);
	moduleName.setPosition(graphBG.getPosition());

	// Setting the view
	graphView.reset(sf::FloatRect(0,0,window.getSize().x, window.getSize().y));

	// Initilising the buttons
	buttons["m.name"] = new Button(sf::Vector2f(80,20), colors["button"],2);
	buttons["m.name"]->setPosition(sf::Vector2f(window.getSize().x - 100, 100));

	buttons["n.node"] = new Button(sf::Vector2f(80,20), colors["button"],2);
	buttons["n.node"]->setPosition(sf::Vector2f(window.getSize().x - 290, 100));

	//buttons["n.names"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	//buttons["n.names"]->setPosition(sf::Vector2f(window.getSize().x - 200, 100));
	buttons["n.ndoe"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["n.ndoe"]->setPosition(sf::Vector2f(window.getSize().x - 200, 100));

	buttons["exit"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["exit"]->setPosition(sf::Vector2f(window.getSize().x - 100, 50));

	buttons["load"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["load"]->setPosition(sf::Vector2f(window.getSize().x - 290, 50));

	buttons["save"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["save"]->setPosition(sf::Vector2f(window.getSize().x - 200, 50));

	// Setting the button text
	for(auto i : buttons)
		i.second->setText(i.first, font);

	connSpawn = sf::Vector2f(window.getSize().x - 290, 200);
}

Grapher::~Grapher()
{
	for(auto i : nodeViews)
	{
		delete i;
		i = NULL;
	}

	if (connEdit != NULL)
	{
		delete connEdit;
		connEdit = NULL;
	}

	if (flagEdit != NULL)
	{
		delete flagEdit;
		flagEdit = NULL;
	}
}

void Grapher::run()
{
	window.setFramerateLimit(60);
	inputManager.addBinding("tab_confirm", sf::Keyboard::Tab);

	// main loop
	while(!close)
	{
		update();
		render();
	}
}

void Grapher::update()
{
	sf::Event event;

	// Updating our key input
	inputManager.update(window);
	sf::Vector2f viewPos = window.mapPixelToCoords((sf::Vector2i)inputManager.getMousePosition(), graphView);

	if (inputManager.pressedOnce("cancel"))
	{
		if (selectedInputBox)
		{
			if (ibox.isSelected())
			{
				ibox.setActive(false);
				ibox.setSelected(false);
				ibox.clear();
			}
			else if (selectedNode)
			{
				// Reverting the edited textbox
				selectedInputBox->setString(selectedNode->getUnsavedInput());
			}

			selectedInputBox->setSelected(false);
			selectedInputBox = NULL;
		}


		if (connEdit != NULL)
		{
			if (connEdit->selectionExists())
				connEdit->cancelEdits();
			else
			{
				delete connEdit;
				connEdit = NULL;

				selectedNode = NULL;
			}
		}

		if (flagEdit != NULL)
		{
			delete flagEdit;
			flagEdit = NULL;
		}
	}

	// Tab switching 
	if (inputManager.pressedOnce("tab_confirm") &&
		selectedInputBox != NULL &&
		selectedNode != NULL)
	{
		selectedNode->updateNodeText();
		selectedInputBox->setSelected(false);
		selectedInputBox = selectedNode->getOtherInputBox(selectedInputBox);
		selectedInputBox->setSelected(true);
	}

	while(window.pollEvent(event))
	{
		switch(event.type)
		{
			case sf::Event::Closed:
			  exit(0);
			  break;

			case sf::Event::TextEntered:
				onTextEntered(event.text.unicode);
				break;

			case sf::Event::MouseWheelScrolled:
				if(flagEdit != NULL)
					flagEdit->checkScroll(event.mouseWheelScroll.delta);
				else
					onMouseScroll(event.mouseWheelScroll.delta);

				break;
			
			case sf::Event::MouseButtonReleased:
			{
			   if (event.mouseButton.button == sf::Mouse::Left)
				   onLeftRelease();
			   else if (event.mouseButton.button == sf::Mouse::Middle)
				   onMiddleRelease(viewPos);<commit_msg>fixed some indenation<commit_after>#include "Grapher.h"
#include <iostream>
#include <algorithm>
Grapher::Grapher() : fileManager("dialogue/")
{
	window.create(sf::VideoMode(1280, 720), "Scenario Grapher");

	// Loading the font
	font.loadFromFile("assets/fonts/Inconsolata.otf");

	nodeCount = 0;
	scale = 1.f;
	selectedNode = NULL;
	selectedInputBox = NULL;
	clickedNode = NULL;
	connEdit = NULL;
	flagEdit = NULL;
	movingView = false;
	showNodeNames = true;

	for (int i = 0; i < 2; ++i)
		connectingNodes[i] = NULL;

	imageManager.loadImage("assets/images/interface/buttons/flag.png", "flag");
	imageManager.loadImage("assets/images/interface/buttons/plus.png", "plus");

	ibox = InputBox(sf::Vector2f(window.getSize().x - 290,window.getSize().y - 50), sf::Vector2f(280,25), font);
	ibox.setActive(false);

	// Defining the UI colors
	colors["button"] = sf::Color(142, 196, 137);
	colors["background"] = sf::Color(31,31,31);
	colors["graphBG"] = sf::Color(43,43,43);
	colors["buttonHighlight"] = sf::Color(179,80,80);

	moduleName.setString("untitled");
	moduleName.setFont(font);
	moduleName.setCharacterSize(20);
	moduleName.setColor(sf::Color::White);

	sf::Vector2f bgSize(300, window.getSize().y);
	graphBG = sf::RectangleShape(bgSize);
	graphBG.setFillColor(colors["graphBG"]);
	graphBG.setPosition(window.getSize().x - 300,0);
	moduleName.setPosition(graphBG.getPosition());

	// Setting the view
	graphView.reset(sf::FloatRect(0,0,window.getSize().x, window.getSize().y));

	// Initilising the buttons
	buttons["m.name"] = new Button(sf::Vector2f(80,20), colors["button"],2);
	buttons["m.name"]->setPosition(sf::Vector2f(window.getSize().x - 100, 100));

	buttons["n.node"] = new Button(sf::Vector2f(80,20), colors["button"],2);
	buttons["n.node"]->setPosition(sf::Vector2f(window.getSize().x - 290, 100));

	//buttons["n.names"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	//buttons["n.names"]->setPosition(sf::Vector2f(window.getSize().x - 200, 100));
	buttons["n.ndoe"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["n.ndoe"]->setPosition(sf::Vector2f(window.getSize().x - 200, 100));

	buttons["exit"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["exit"]->setPosition(sf::Vector2f(window.getSize().x - 100, 50));

	buttons["load"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["load"]->setPosition(sf::Vector2f(window.getSize().x - 290, 50));

	buttons["save"] = new Button(sf::Vector2f(80, 20), colors["button"],2);
	buttons["save"]->setPosition(sf::Vector2f(window.getSize().x - 200, 50));

	// Setting the button text
	for(auto i : buttons)
		i.second->setText(i.first, font);

	connSpawn = sf::Vector2f(window.getSize().x - 290, 200);
}

Grapher::~Grapher()
{
	for(auto i : nodeViews)
	{
		delete i;
		i = NULL;
	}

	if (connEdit != NULL)
	{
		delete connEdit;
		connEdit = NULL;
	}

	if (flagEdit != NULL)
	{
		delete flagEdit;
		flagEdit = NULL;
	}
}

void Grapher::run()
{
	window.setFramerateLimit(60);
	inputManager.addBinding("tab_confirm", sf::Keyboard::Tab);

	// main loop
	while(!close)
	{
		update();
		render();
	}
}

void Grapher::update()
{
	sf::Event event;

	// Updating our key input
	inputManager.update(window);
	sf::Vector2f viewPos = window.mapPixelToCoords((sf::Vector2i)inputManager.getMousePosition(), graphView);

	if (inputManager.pressedOnce("cancel"))
	{
		if (selectedInputBox)
		{
			if (ibox.isSelected())
			{
				ibox.setActive(false);
				ibox.setSelected(false);
				ibox.clear();
			}
			else if (selectedNode)
			{
				// Reverting the edited textbox
				selectedInputBox->setString(selectedNode->getUnsavedInput());
			}

			selectedInputBox->setSelected(false);
			selectedInputBox = NULL;
		}


		if (connEdit != NULL)
		{
			if (connEdit->selectionExists())
				connEdit->cancelEdits();
			else
			{
				delete connEdit;
				connEdit = NULL;

				selectedNode = NULL;
			}
		}

		if (flagEdit != NULL)
		{
			delete flagEdit;
			flagEdit = NULL;
		}
	}

	// Tab switching 
	if (inputManager.pressedOnce("tab_confirm") &&
		selectedInputBox != NULL &&
		selectedNode != NULL)
	{
		selectedNode->updateNodeText();
		selectedInputBox->setSelected(false);
		selectedInputBox = selectedNode->getOtherInputBox(selectedInputBox);
		selectedInputBox->setSelected(true);
	}

	while(window.pollEvent(event))
	{
		switch(event.type)
		{
			case sf::Event::Closed:
			  exit(0);
			  break;

			case sf::Event::TextEntered:
				onTextEntered(event.text.unicode);
				break;

			case sf::Event::MouseWheelScrolled:
				if(flagEdit != NULL)
					flagEdit->checkScroll(event.mouseWheelScroll.delta);
				else
					onMouseScroll(event.mouseWheelScroll.delta);

				break;
			
			case sf::Event::MouseButtonReleased:
			{
				if (event.mouseButton.button == sf::Mouse::Left)
					onLeftRelease();
				else if (event.mouseButton.button == sf::Mouse::Middle)
					onMiddleRelease(viewPos);
{'fraction_non_alphanumeric': 0.18013055895552835, 'fraction_numerical': 0.03325173398612811, 'mean_word_length': 4.723876240513719, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509829', 'n_tokens_mistral': 4047, 'n_tokens_neox': 3484, 'n_words': 567}