[Forum Game] Paste whatever's on your clipboard!
Welp, I guess this is what you end up with on your clipboard when doing janky coding.
I’ll just hide it in a summary so i don’t fill the entire page.
Edit: Oh god, the formatting made it even worse.
Summary
//#include
#include “Menu.h”
float bWidthStart = 0.33f;
float bLength = 0.33f;
float bHeight = 0.1f;
void Menu::Main(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
try {
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
tgui::Button::Ptr bFirst = tgui::Button::create();
tgui::Button::Ptr bSecond = tgui::Button::create();
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
bFirst = theme->load("Button");
bFirst->setSize(windowWidth*bLength, windowHeight*bHeight);
bSecond= theme->load("Button");
bSecond->setSize(windowWidth*bLength, windowHeight*bHeight);
// tgui::Button::Ptr bSecond = tgui::Button::copy(bFirst);
tgui::Button::Ptr bThird = tgui::Button::copy(bFirst);
tgui::Button::Ptr bFourth = tgui::Button::copy(bFirst);
bFirst->setPosition(windowWidth*bWidthStart, windowHeight*0.1f);
bSecond->setPosition(windowWidth*bWidthStart, windowHeight*0.3f);
bThird->setPosition(windowWidth*bWidthStart, windowHeight*0.5f);
bFourth->setPosition(windowWidth*bWidthStart, windowHeight*0.7f);
std::string spString = json.language["singleplayer"];
std::string mpString = json.language["multiplayer"];
std::string opString = json.language["options"];
std::string exString = json.language["exit"];
bFirst ->setText(sf::String::fromUtf8(spString.begin(), spString.end()));
bSecond ->setText(sf::String::fromUtf8(mpString.begin(), mpString.end()));
bThird ->setText(sf::String::fromUtf8(opString.begin(), opString.end()));
bFourth ->setText(sf::String::fromUtf8(exString.begin(), exString.end()));
bFirst->connect("clicked", [&]() {
lDebug("Button Singleplayer clicked"), sound.SoundClick(), state.NextState(
List_State::Singleplayer_Menu), state.updateInterface(gui, window, state, json, sound);
});
bSecond->connect("clicked", [&]() {
lDebug("Button Multiplayer clicked"), sound.SoundClick(), state.NextState(List_State::Multiplayer_Menu), state.updateInterface(
gui, window, state, json, sound);
});
bThird->connect("clicked", [&]() {
lDebug("Button Options clicked"), sound.SoundClick(), state.NextState(List_State::Option_Menu), state.updateInterface(gui,
window,
state, json, sound);
});
bFourth->connect("clicked", [&]() {
lDebug("Button Exit clicked"), sound.SoundClickBack(), state.NextState(List_State::Zero), state.updateInterface(gui, window, state, json, sound);
});
gui.add(bFirst);
gui.add(bSecond);
gui.add(bThird);
gui.add(bFourth);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}
void Menu::Option(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
try{
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
tgui::Button::Ptr bSettings, bMapEditor, bBack;
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
bSettings = theme->load("Button");
bSettings->setSize(windowWidth*bLength, windowHeight*bHeight);
bMapEditor = tgui::Button::copy(bSettings);
bBack = tgui::Button::copy(bSettings);
bSettings->setPosition(windowWidth*bWidthStart, windowHeight*0.1f);
bMapEditor->setPosition(windowWidth*bWidthStart, windowHeight*0.3f);
bBack->setPosition(windowWidth*bWidthStart, windowHeight*0.5f);
std::string setString = json.language["settings"];
std::string mapString = json.language["mapeditor"];
std::string backString = json.language["back"];
bSettings ->setText(sf::String::fromUtf8(setString.begin(), setString.end()));
bMapEditor ->setText(sf::String::fromUtf8(mapString.begin(), mapString.end()));
bBack ->setText(sf::String::fromUtf8(backString.begin(), backString.end()));
bSettings->connect("clicked", [&]() { lDebug("Button Settings clicked"), sound.SoundClick(), state.NextState(List_State::Settings), state.updateInterface(gui,window,state, json, sound); });
bMapEditor->connect("clicked", [&]() { lDebug("Button MapEditor clicked"), sound.SoundClick(), state.NextState(List_State::EditorSetup), state.updateInterface(gui,window,state, json, sound); });
bBack->connect("clicked", [&]() { lDebug("Button Back clicked"), sound.SoundClickBack(), state.NextState(List_State::Zero), state.updateInterface(gui,window,state, json, sound); });
gui.add(bSettings);
gui.add(bMapEditor);
gui.add(bBack);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}
void Menu::SingelPlayer(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
try{
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
tgui::Button::Ptr bFirst = tgui::Button::create();
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
bFirst = theme->load("Button");
bFirst ->setSize(windowWidth*bLength, windowHeight*bHeight);
tgui::Button::Ptr bSecond = tgui::Button::copy(bFirst);
tgui::Button::Ptr bThird = tgui::Button::copy(bFirst);
bFirst ->setPosition(windowWidth*bWidthStart, windowHeight*0.1f);
bSecond->setPosition(windowWidth*bWidthStart, windowHeight*0.3f);
bThird ->setPosition(windowWidth*bWidthStart, windowHeight*0.5f);
std::string gameString = json.language["game"];
std::string newString = json.language["new"];
std::string loadString = json.language["load"];
std::string backString = json.language["back"];
newString = newString + " " + gameString;
loadString = loadString + " " + gameString;
bFirst ->setText(sf::String::fromUtf8(newString.begin(), newString.end()));
bSecond ->setText(sf::String::fromUtf8(loadString.begin(), loadString.end()));
bThird ->setText(sf::String::fromUtf8(backString.begin(), backString.end()));
bFirst ->connect("clicked", [&]() { lDebug("Button New Game clicked"), sound.SoundClick(), state.NextState(List_State::New_Game), state.updateInterface(gui,window,state, json, sound); });
bSecond->connect("clicked", [&]() { lDebug("Button Load Game clicked"), sound.SoundClick(), state.NextState(List_State::Load_Game), state.updateInterface(gui,window,state, json, sound); });
bThird ->connect("clicked", [&]() { lDebug("Button Back clicked"), sound.SoundClickBack(), state.NextState(List_State::Zero), state.updateInterface(gui,window,state, json, sound); });
gui.add(bFirst);
gui.add(bSecond);
gui.add(bThird);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}
void Menu::MultiPlayer(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
try{
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
tgui::Button::Ptr bFirst = tgui::Button::create();
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
bFirst = theme->load("Button");
bFirst->setSize(windowWidth*bLength, windowHeight*bHeight);
tgui::Button::Ptr bSecond = tgui::Button::copy(bFirst);
tgui::Button::Ptr bThird = tgui::Button::copy(bFirst);
bFirst->setPosition(windowWidth*bWidthStart, windowHeight*0.1f);
bSecond->setPosition(windowWidth*bWidthStart, windowHeight*0.3f);
bThird->setPosition(windowWidth*bWidthStart, windowHeight*0.5f);
std::string gameString = json.language["game"];
std::string hostString = json.language["host"];
std::string joinString = json.language["join"];
std::string backString = json.language["back"];
hostString = hostString + " " + gameString;
joinString = joinString + " " + gameString;
bFirst ->setText(sf::String::fromUtf8(hostString.begin(), hostString.end()));
bSecond ->setText(sf::String::fromUtf8(joinString.begin(), joinString.end()));
bThird ->setText(sf::String::fromUtf8(backString.begin(), backString.end()));
bFirst->connect("clicked", [&]() { lDebug("Button Host Game clicked"), sound.SoundClick(), state.NextState(List_State::Host_Game), state.updateInterface(gui,window,state, json, sound); });
bSecond->connect("clicked", [&]() { lDebug("Button Join Game clicked"), sound.SoundClick(), state.NextState(List_State::Join_Game), state.updateInterface(gui,window,state, json, sound); });
bThird->connect("clicked", [&]() { lDebug("Button Back clicked"), sound.SoundClickBack(), state.NextState(List_State::Zero), state.updateInterface(gui,window,state, json, sound); });
gui.add(bFirst);
gui.add(bSecond);
gui.add(bThird);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}
void Menu::MenuSettings(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
SettingButtons sb;
try {
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
//Declaring Button Pointers
tgui::Button::Ptr bBack, bFullScreen, bResolution, bApply, bLanguage, bKeys, bRestore;
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
//Getting json strings
std::string backString = json.language["back"];
std::string applyString = json.language["apply"];
std::string volumString = json.language["volum"];
std::string languageString = json.language["language"];
std::string musicString = json.language["music"];
std::string soundString = json.language["sound"];
std::string keyString = json.language["keybinding"];
std::string restoreString = json.language["restore"];
musicString = musicString + " " + volumString;
soundString = soundString + " " + volumString;
///BUTTON: BACK
bBack = theme->load("Button");
bBack ->setSize(windowWidth*0.15f, windowHeight*0.07f);
bBack ->setPosition(windowWidth*0.01f, windowHeight*0.92f);
bBack ->setText(sf::String::fromUtf8(backString.begin(), backString.end()));
gui.add(bBack);
///BUTTON: RESOLUTION
bResolution = tgui::Button::copy(bBack);
bResolution ->setSize(windowWidth*0.3f, windowHeight*0.07f);
bResolution ->setPosition(windowWidth*0.5f, windowHeight*0.2f);
bResolution ->connect("clicked", [&]() {
lDebug("Button Resolution clicked"),
sound.SoundClick(),
sb.bResolution("bResolution",gui, json);
});
gui.add(bResolution, "bResolution");
///BUTTON: FULL SCREEN ON/OFF
bFullScreen = tgui::Button::copy(bBack);
bFullScreen ->setPosition(windowWidth*0.5f, windowHeight*0.3f);
bFullScreen ->connect("clicked", [&]() {
lDebug("Button FullScreen clicked"),
sound.SoundClick(),
sb.bFullScreen("bFullScreen",gui, json);
});
gui.add(bFullScreen, "bFullScreen");
///BUTTON: APPLY SETTINGS
bApply = tgui::Button::copy(bBack);
bApply ->setPosition(windowWidth*0.84f, windowHeight*0.92f);
bApply ->setText(sf::String::fromUtf8(applyString.begin(), applyString.end()));
bApply ->connect("clicked", [&]() {
lDebug("Button Apply clicked"),
sound.SoundClick(),
sb.applySettings(false, window, gui, json, sound),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bApply);
///BUTTON: CHANGE LANGUAGE
bLanguage = tgui::Button::copy(bBack);
bLanguage ->setPosition(windowWidth*0.1f, windowHeight*0.4f);
bLanguage ->setText(sf::String::fromUtf8(languageString.begin(), languageString.end())+"...");
bLanguage ->connect("clicked", [&]() {
lDebug("Button change language clicked"),
sound.SoundClick(),
json.getSettings(),
state.NextState(List_State::Language),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bLanguage);
///BUTTON: CHANGE KEY BINDINGS
bKeys = tgui::Button::copy(bBack);
bKeys ->setPosition(windowWidth*0.1f, windowHeight*0.55f);
bKeys ->setText(sf::String::fromUtf8(keyString.begin(), keyString.end())+"...");
bKeys ->connect("clicked", [&]() {
lDebug("Button change keybindings clicked"),
sound.SoundClick(),
json.getSettings(),
state.NextState(List_State::Keybinding),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bKeys);
///BUTTON: RESET SETTINGS
bRestore = tgui::Button::copy(bBack);
bRestore ->setPosition(windowWidth*0.68f, windowHeight*0.92f);
bRestore ->setText(sf::String::fromUtf8(restoreString.begin(), restoreString.end()));
bRestore ->connect("clicked", [&]() {
lDebug("Button Restore clicked"),
sound.SoundClick(),
sb.applySettings(true, window, gui, json, sound),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bRestore);
///SLIDER AND LABEL: MUSIC VOLUME
tgui::Slider::Ptr sliderMusic = theme->load("slider");
sliderMusic ->setPosition(windowWidth*0.1f, windowHeight*0.15f);
sliderMusic ->setSize(200, 18);
sliderMusic ->setMaximum(100);
sliderMusic ->setMinimum(0);
sliderMusic ->setValue(json.setting["music"]);
gui.add(sliderMusic, "music");
tgui::Label::Ptr label = theme->load("label");
label = theme->load("label");
label->setText(sf::String::fromUtf8(musicString.begin(), musicString.end()));
label->setPosition(windowWidth*0.1f, windowHeight*0.1f);
label->setTextSize(18);
gui.add(label);
///SLIDER AND LABEL: SOUND VOLUME
tgui::Slider::Ptr sliderSound = theme->load("slider");
sliderSound ->setPosition(windowWidth*0.1f, windowHeight*0.30f);
sliderSound ->setSize(200, 18);
sliderSound ->setMaximum(100);
sliderSound ->setMinimum(0);
sliderSound ->setValue(json.setting["sound"]);
gui.add(sliderSound, "sound");
label = theme->load("label");
label->setText(sf::String::fromUtf8(soundString.begin(), soundString.end()));
label->setPosition(windowWidth*0.1f, windowHeight*0.25f);
label->setTextSize(18);
gui.add(label);
bBack->connect("clicked", [&]() {
lDebug("Button back clicked"),
sound.SoundClickBack(),
json.getSettings(),
state.NextState(List_State::Zero),
state.updateInterface(gui, window, state, json, sound);
});
//Adding text to buttons
sb.getButtonText(bFullScreen, bResolution, json);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}
void Menu::LanguageSetting(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
SettingButtons sb;
try{
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
tgui::Button::Ptr bBack, bApply;
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
std::string backString = json.language["back"];
std::string applyString = json.language["apply"];
///BUTTON: BACK
bBack = theme->load("Button");
bBack ->setSize(windowWidth*0.15f, windowHeight*0.07f);
bBack ->setPosition(windowWidth*0.01f, windowHeight*0.92f);
bBack ->setText(sf::String::fromUtf8(backString.begin(), backString.end()));
gui.add(bBack);
///BUTTON: APPLY SETTINGS
bApply = tgui::Button::copy(bBack);
bApply ->setPosition(windowWidth*0.84f, windowHeight*0.92f);
bApply ->setText(sf::String::fromUtf8(applyString.begin(), applyString.end()));
bApply ->connect("clicked", [&]() {
lDebug("Button Apply clicked"),
sound.SoundClick(),
sb.applySelectedLanguage(json, gui),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bApply);
///LISTBOX: LANGUAGE LIST
tgui::ListBox::Ptr list;
list = theme->load("ListBox");
list->setSize(windowWidth*0.7f, windowHeight*0.8f);
list->setPosition(windowWidth*0.15f, windowHeight*0.1f);
list->addItem("English");
list->addItem("Norsk");
std::string selectedLanguage = json.setting["language"];
list->setSelectedItem(selectedLanguage);
list->setTextSize(20);
gui.add(list, "list");
std::string labelString = json.language["packet"];
tgui::Label::Ptr label;
label = theme->load("label");
label->setPosition(windowWidth*0.15f, windowHeight*0.02f);
label->setTextSize(30);
label->setText(sf::String::fromUtf8(labelString.begin(), labelString.end()));
gui.add(label);
bBack->connect("clicked", [&]() {
lDebug("Button back clicked"),
sound.SoundClickBack(),
state.NextState(List_State::Zero),
state.updateInterface(gui, window, state, json, sound);
});
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}
void Menu::KeybindingSettings(tgui::Gui &gui, sf::RenderWindow &window, StateMachine &state, Settings &json, Sound &sound) {
SettingButtons sb;
try{
tgui::Theme::Ptr theme = tgui::Theme::create("Texture/widgets/Black.txt");
gui.add(tgui::Picture::create("Texture/Texture/background.jpg"));
tgui::Button::Ptr bBack, bApply, bPause, bUp, bDown, bLeft, bRight;
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);
std::string backString = json.language["back"];
std::string applyString = json.language["apply"];
std::string pauseString = json.language["pause"];
std::string upString = json.language["up"];
std::string downString = json.language["down"];
std::string leftString = json.language["left"];
std::string rightString = json.language["right"];
///BUTTON: BACK
bBack = theme->load("Button");
bBack ->setSize(windowWidth*0.15f, windowHeight*0.07f);
bBack ->setPosition(windowWidth*0.01f, windowHeight*0.92f);
bBack ->setText(sf::String::fromUtf8(backString.begin(), backString.end()));
gui.add(bBack);
///BUTTON: APPLY SETTINGS
bApply = tgui::Button::copy(bBack);
bApply ->setPosition(windowWidth*0.84f, windowHeight*0.92f);
bApply ->setText(sf::String::fromUtf8(applyString.begin(), applyString.end()));
bApply ->connect("clicked", [&]() {
lDebug("Button Apply clicked"),
sound.SoundClick(),
sb.applySettings(false, window, gui, json, sound),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bApply);
bBack->connect("clicked", [&]() {
lDebug("Button Exit clicked"),
sound.SoundClickBack(),
state.NextState(List_State::Zero),
state.updateInterface(gui, window, state, json, sound);
});
///BUTTON: CHANGE PAUSE KEY
bPause = tgui::Button::copy(bBack);
bPause ->setPosition(windowWidth*0.1f, windowHeight*0.4f);
bPause ->setText(sf::String::fromUtf8(pauseString.begin(), pauseString.end())+"...");
bPause ->connect("clicked", [&]() {
lDebug("Button change pause key clicked"),
sound.SoundClick(),
json.getSettings(),
state.NextState(List_State::Language),
state.updateInterface(gui, window, state, json, sound);
});
gui.add(bPause);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
lFatal("TGUI could not be created");
}
}