@@ -110,27 +110,27 @@ void mainMenu(universe &uni)
uni.update(0.1f);
uni.getUI()->clear();

std::array<int, 8> btncol = {20, 220, 255, 220, 20, 200, 255, 220};
std::array<int, 8> quitcol = {255, 25, 40, 220, 255, 5, 30, 220};
std::array<int, 8> blank = {0, 0, 0, 0, 0, 0, 0, 0};

ui::selection mainMenuSelection;
ui::button play ("PLAY GAME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 200.0f}, {200.0f, 80.0f});
ui::button tut ("PLAY TUTORIAL", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 50.0f}, {200.0f, 80.0f});
ui::button opt ("OPTIONS", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 100.0f}, {200.0f, 80.0f});
ui::button quit ("QUIT", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 250.0f}, {200.0f, 80.0f});
std::array<int, 4> btncol = {20, 200, 255, 220};
std::array<int, 4> quitcol = {255, 5, 30, 220};
std::array<int, 4> blank = {0, 0, 0, 0};

selection mainMenuSelection;
button play ("PLAY GAME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 200.0f}, {200.0f, 80.0f});
button tut ("PLAY TUTORIAL", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 50.0f}, {200.0f, 80.0f});
button opt ("OPTIONS", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 100.0f}, {200.0f, 80.0f});
button quit ("QUIT", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 250.0f}, {200.0f, 80.0f});
mainMenuSelection.add(play);
mainMenuSelection.add(tut);
mainMenuSelection.add(opt);
mainMenuSelection.add(quit);
uni.getUI()->add(mainMenuSelection);

ui::selection optionsHeader;
ui::button optionsHeaderBtn("OPTIONS (REQUIRE GAME RESTART)", blank, blank, {g_HALFWIN.m_x - 180.0f, g_HALFWIN.m_y - 150.0f}, {200.0f, 20.0f});
ui::button resolutionHeaderBtn("RESOLUTION", blank, blank, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 110.0f}, {200.0f, 20.0f});
ui::button graphicsHeaderBtn("QUALITY", blank, blank, {g_HALFWIN.m_x - 90.0f, g_HALFWIN.m_y + -5.0f}, {200.0f, 20.0f});
ui::button difficultyHeaderBtn("DIFFICULTY", blank, blank, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 100.0f}, {200.0f, 20.0f});
ui::button backToMainMenu("RETURN", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 240.0f}, {200.0f, 80.0f});
selection optionsHeader;
button optionsHeaderBtn("OPTIONS (REQUIRE GAME RESTART)", blank, blank, {g_HALFWIN.m_x - 180.0f, g_HALFWIN.m_y - 150.0f}, {200.0f, 20.0f});
button resolutionHeaderBtn("RESOLUTION", blank, blank, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 110.0f}, {200.0f, 20.0f});
button graphicsHeaderBtn("QUALITY", blank, blank, {g_HALFWIN.m_x - 90.0f, g_HALFWIN.m_y + -5.0f}, {200.0f, 20.0f});
button difficultyHeaderBtn("DIFFICULTY", blank, blank, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 100.0f}, {200.0f, 20.0f});
button backToMainMenu("RETURN", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 240.0f}, {200.0f, 80.0f});
optionsHeader.add(optionsHeaderBtn);
optionsHeader.add(resolutionHeaderBtn);
optionsHeader.add(graphicsHeaderBtn);
@@ -140,32 +140,32 @@ void mainMenu(universe &uni)
uni.getUI()->add(optionsHeader);

float w = 90.0f, h = 50.0f;
ui::selection resolutionOptions;
resolutionOptions.add(ui::button("1280 x 720", btncol, btncol, {g_HALFWIN.m_x - 355.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(ui::button("1280 x 1024", btncol, btncol, {g_HALFWIN.m_x - 255.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(ui::button("1366 x 768", btncol, btncol, {g_HALFWIN.m_x - 155.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(ui::button("1440 x 900", btncol, btncol, {g_HALFWIN.m_x - 55.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(ui::button("1600 x 900", btncol, btncol, {g_HALFWIN.m_x + 45.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(ui::button("1920 x 1080", btncol, btncol, {g_HALFWIN.m_x + 145.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(ui::button("1920 x 1200", btncol, btncol, {g_HALFWIN.m_x + 245.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
selection resolutionOptions;
resolutionOptions.add(button("1280 x 720", btncol, btncol, {g_HALFWIN.m_x - 355.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(button("1280 x 1024", btncol, btncol, {g_HALFWIN.m_x - 255.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(button("1366 x 768", btncol, btncol, {g_HALFWIN.m_x - 155.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(button("1440 x 900", btncol, btncol, {g_HALFWIN.m_x - 55.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(button("1600 x 900", btncol, btncol, {g_HALFWIN.m_x + 45.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(button("1920 x 1080", btncol, btncol, {g_HALFWIN.m_x + 145.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.add(button("1920 x 1200", btncol, btncol, {g_HALFWIN.m_x + 245.0f, g_HALFWIN.m_y - 80.0f}, {w, h}, 0.8f));
resolutionOptions.setVisible(false);
uni.getUI()->add(resolutionOptions);

ui::selection qualityOptions;
qualityOptions.add(ui::button("Potato", btncol, btncol, {g_HALFWIN.m_x - 155.0f, g_HALFWIN.m_y + 30.0f}, {w, h}, 0.8f));
qualityOptions.add(ui::button("Medium Rare", btncol, btncol, {g_HALFWIN.m_x - 55.0f, g_HALFWIN.m_y + 30.0f}, {w, h}, 0.8f));
qualityOptions.add(ui::button("Da Vinci", btncol, btncol, {g_HALFWIN.m_x + 45.0f, g_HALFWIN.m_y + 30.0f}, {w, h}, 0.8f));
selection qualityOptions;
qualityOptions.add(button("Potato", btncol, btncol, {g_HALFWIN.m_x - 155.0f, g_HALFWIN.m_y + 30.0f}, {w, h}, 0.8f));
qualityOptions.add(button("Medium Rare", btncol, btncol, {g_HALFWIN.m_x - 55.0f, g_HALFWIN.m_y + 30.0f}, {w, h}, 0.8f));
qualityOptions.add(button("Da Vinci", btncol, btncol, {g_HALFWIN.m_x + 45.0f, g_HALFWIN.m_y + 30.0f}, {w, h}, 0.8f));
qualityOptions.setVisible(false);
uni.getUI()->add(qualityOptions);

w = 140.0f;
h = 50.0f;
ui::selection difficultyOptions;
difficultyOptions.add(ui::button("Cadet", btncol, btncol, {g_HALFWIN.m_x - 370.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(ui::button("Cosmonaut", btncol, btncol, {g_HALFWIN.m_x - 220.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(ui::button("Captain", btncol, btncol, {g_HALFWIN.m_x - 70.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(ui::button("Commander", btncol, btncol, {g_HALFWIN.m_x + 80.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(ui::button("Computing for Animation 1", btncol, btncol, {g_HALFWIN.m_x + 230.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
selection difficultyOptions;
difficultyOptions.add(button("Cadet", btncol, btncol, {g_HALFWIN.m_x - 370.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(button("Cosmonaut", btncol, btncol, {g_HALFWIN.m_x - 220.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(button("Captain", btncol, btncol, {g_HALFWIN.m_x - 70.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(button("Commander", btncol, btncol, {g_HALFWIN.m_x + 80.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.add(button("Computing for Animation 1", btncol, btncol, {g_HALFWIN.m_x + 230.0f, g_HALFWIN.m_y + 130.0f}, {w, h}, 0.8f));
difficultyOptions.setVisible(false);
uni.getUI()->add(difficultyOptions);

@@ -232,7 +232,7 @@ void mainMenu(universe &uni)
case SDL_BUTTON_LEFT:
int mx = 0, my = 0;
SDL_GetMouseState(&mx, &my);
ui::selectionReturn mainMenuSelected = uni.getUI()->handleInput({static_cast<float>(mx), static_cast<float>(my)});
selectionReturn mainMenuSelected = uni.getUI()->handleInput({static_cast<float>(mx), static_cast<float>(my)});
std::cout << "CLICK : " << mainMenuSelected.m_sel_val << ", " << mainMenuSelected.m_button_val << std::endl;
if(mainMenuSelected.m_sel_val == 0)
{
@@ -450,7 +450,7 @@ void handleUserMouseDownInput(int btn, int * keymod, player *ply, universe *uni)
{
int x = 0, y = 0;
SDL_GetMouseState(&x,&y);
ui::selectionReturn ret = uni->getUI()->handleInput({static_cast<float>(x), static_cast<float>(y)});
selectionReturn ret = uni->getUI()->handleInput({static_cast<float>(x), static_cast<float>(y)});
if(ret.m_sel_val == 0)
{
playSnd(MENU_SELECT_SND);
@@ -543,7 +543,7 @@ void handleUserMouseUpInput(int btn, int keymod, player *ply, universe *uni)
int mx = 0, my = 0;
SDL_GetMouseState(&mx, &my);

ui::selectionReturn ret = uni->getUI()->handleInput({static_cast<float>(mx), static_cast<float>(my)});
selectionReturn ret = uni->getUI()->handleInput({static_cast<float>(mx), static_cast<float>(my)});
if(ret.m_sel_val > 0) uni->setMouseState(-1);

vec3 pos = {static_cast<float>(mx), static_cast<float>(my), 0.0f};
@@ -588,14 +588,14 @@ void handleUserScroll(int y, player * ply)
void handleUserKeyDownInput(int sym, player *ply, universe *uni, int * keymod)
{
//The menu to appear when the user presses escape.
ui::selection escMenuSelection;
std::array<int, 8> btncol = {20, 200, 255, 220, 20, 200, 255, 220};
std::array<int, 8> quitcol = {255, 5, 30, 220, 255, 5, 30, 220};
ui::button resume ("RESUME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 300.0f}, {200.0f, 80.0f});
ui::button sGame ("SAVE GAME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 200.0f}, {200.0f, 80.0f});
ui::button lGame ("LOAD GAME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 100.0f}, {200.0f, 80.0f});
ui::button mm ("MAIN MENU", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y}, {200.0f, 80.0f});
ui::button quit ("QUIT", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 100.0f}, {200.0f, 80.0f});
selection escMenuSelection;
std::array<int, 4> btncol = {20, 200, 255, 220};
std::array<int, 4> quitcol = {255, 5, 30, 220};
button resume ("RESUME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 300.0f}, {200.0f, 80.0f});
button sGame ("SAVE GAME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 200.0f}, {200.0f, 80.0f});
button lGame ("LOAD GAME", btncol, btncol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 100.0f}, {200.0f, 80.0f});
button mm ("MAIN MENU", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y}, {200.0f, 80.0f});
button quit ("QUIT", quitcol, quitcol, {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y + 100.0f}, {200.0f, 80.0f});

escMenuSelection.add(resume);
escMenuSelection.add(sGame);
@@ -916,7 +916,7 @@ void playTutorial(universe &uni)
{
uni.getRenderer()->drawText("THE RED BAR IS YOUR HEALTH, BLUE IS SHIELDS, AND GREEN IS ENERGY", "pix", {g_HALFWIN.m_x - 300.0f, g_HALFWIN.m_y - 200.0f}, false, 1.2f);
uni.getRenderer()->drawText("SHOOTING, MOVING AND RECHARGING SHIELDS ALL USE ENERGY, SO YOU HAVE TO BE CAREFUL", "pix", {g_HALFWIN.m_x - 200.0f, g_HALFWIN.m_y - 160.0f}, false, 1.0f);
uni.getRenderer()->drawText("USE THE BUTTONS ON THE RIGHT TO PRIORITISE CERTAIN SYSTEMS", "pix", {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 120.0f}, false, 1.0f);
uni.getRenderer()->drawText("USE THE buttonS ON THE RIGHT TO PRIORITISE CERTAIN SYSTEMS", "pix", {g_HALFWIN.m_x - 100.0f, g_HALFWIN.m_y - 120.0f}, false, 1.0f);
uni.getRenderer()->drawText("CTRL CLICK SET THE PRIORITY TO 'GUNS'", "pix", {g_HALFWIN.m_x, g_HALFWIN.m_y - 80.0f}, false, 1.2f);
}
else if(tutStage == STAGE_ASTEROID_1 and timer > 1.0f)
@@ -3,36 +3,46 @@ Type 0
SELECTION END

BUTTON START
Name LASERS I (4)
Pos 0.9r 0.35r
Name "LASERS I (4)"
Pos 0.9w 0.35h
Dim 128.0a 64.0a
Cost 4
TextCol 255 255 255 255
BackCol 250 200 200 255
BUTTON END

BUTTON START
Name SHIELDS I (4)
Pos 0.9r 0.35r
Name "SHIELDS I (4)"
Pos 0.9w 0.35h
Dim 128.0a 64.0a
Cost 4
TextCol 255 255 255 255
BackCol 250 200 200 255
BUTTON END

BUTTON START
Name GENERATORS I (4)
Pos 0.9r 0.35r
Name "GENERATORS I (4)"
Pos 0.9w 0.35h
Dim 128.0a 64.0a
Cost 4
TextCol 255 255 255 255
BackCol 250 200 200 255
BUTTON END

BUTTON START
Name THRUSTERS I (4)
Pos 0.9r 0.35r
Name "THRUSTERS I (4)"
Pos 0.9w 0.35h
Dim 128.0a 64.0a
Cost 4
TextCol 255 255 255 255
BackCol 250 200 200 255
BUTTON END

BUTTON START
Name MISSILE I (4)
Pos 0.9r 0.35r
Name "MISSILE I (4)"
Pos 0.9w 0.35h
Dim 128.0a 64.0a
Cost 4
TextCol 255 255 255 255
BackCol 250 200 200 255
BUTTON END
@@ -266,32 +266,103 @@ void setConfigValue(const std::string _entry, const int _val)
std::rename(( g_RESOURCE_LOC + "../" + "temp.txt").c_str(), ( g_RESOURCE_LOC + "../" + "config.txt").c_str());
}

ui::selection loadSelection(const std::string _path)
selection loadSelection(const std::string _path)
{
ui::selection menu;
selection menu;

std::ifstream data( g_RESOURCE_LOC + "../menus/" + _path );
std::string cur;
std::vector< std::string > allStrings;

bool done = false;
while(getline( data, cur ))
{
if(cur.length() > 0) allStrings.push_back(cur);
}
data.close();

while(!done)
for(auto i = allStrings.begin(); i != allStrings.end(); ++i)
{
ui::button temp;
//Process until we find a button start.
while(getline( data, cur ))
if(*i == "BUTTON START")
{
if(cur.length() == 0) continue;

std::vector<std::string> strings = split(cur, ' ');

if(strings.size() > 1 and strings[0] == "BUTTON" and strings[1] == "START")
button temp;
for(auto j = i; j != allStrings.end(); ++j)
{
if(*j == "BUTTON END")
{
menu.add(temp);
break;
}
std::vector<std::string> btnData = split(*j, ' ');

if(btnData[0] == "Name") temp.setLabel(btnData[1]);
else if(btnData[0] == "Pos") temp.setPos({convertMeasureF(btnData[1]), convertMeasureF(btnData[2])});
else if(btnData[0] == "Dim") temp.setDim({convertMeasureF(btnData[1]), convertMeasureF(btnData[2])});
else if(btnData[0] == "Cost") temp.setCost(std::stoi(btnData[1]));
else if(btnData[0] == "TextCol")
{
temp.setTCol({
stof(btnData[1], nullptr),
stof(btnData[2], nullptr),
stof(btnData[3], nullptr),
stof(btnData[4], nullptr)
});
}
else if(btnData[0] == "BackCol")
{
temp.setCol({
stof(btnData[1], nullptr),
stof(btnData[2], nullptr),
stof(btnData[3], nullptr),
stof(btnData[4], nullptr)
});
}
}
}
}
data.close();

return menu;
}

float convertMeasureF(std::string _str)
{
std::string toConvert = "";
for(int i = 0; i < _str.length() - 1; ++i) toConvert += _str[i];

switch(_str[ _str.length() - 1 ])
{
case 'a':
return std::stof(toConvert, nullptr);
break;
case 'w':
return std::stof(toConvert, nullptr) * g_WIN_WIDTH;
break;
case 'h':
return std::stof(toConvert, nullptr) * g_WIN_HEIGHT;
break;
default:
break;
}
return 0.0f;
}

int convertMeasureI(std::string _str)
{
std::string toConvert = "";
for(int i = 0; i < _str.length() - 1; ++i) toConvert += _str[i];

switch(_str[ _str.length() - 1 ])
{
case 'a':
return std::stoi(toConvert, nullptr);
break;
case 'w':
return std::stoi(toConvert, nullptr) * g_WIN_WIDTH;
break;
case 'h':
return std::stoi(toConvert, nullptr) * g_WIN_HEIGHT;
break;
default:
break;
}
return 0.0f;
}
@@ -666,7 +666,7 @@ GLuint renderer_ngl::createVAO(std::vector<ngl::Vec3> _verts, std::vector<ngl::V
return temp_vao;
}

void renderer_ngl::drawButton(const vec3 _p, const vec2 _d, const float _ang, std::array<float, 4> _col)
void renderer_ngl::drawbutton(const vec3 _p, const vec2 _d, const float _ang, std::array<float, 4> _col)
{
m_shader->use("debug");
m_shader->setRegisteredUniform("inColour", ngl::Vec4(_col[0], _col[1], _col[2], _col[3]));
@@ -939,27 +939,27 @@ void renderer_ngl::statusBars(player * _ply)
{
//health base
std::array<float, 4> col = {0.4f, 0.08f, 0.08f, 1.0f};
drawButton({128,40}, {256, 16}, 0.0f, col);
drawbutton({128,40}, {256, 16}, 0.0f, col);

//health
col = {0.9f, 0.2f, 0.2f, 1.0f};
drawButton({128,40}, {(_ply->getHealth() / _ply->getMaxHealth()) * 256, 16}, 0.0f, col);
drawbutton({128,40}, {(_ply->getHealth() / _ply->getMaxHealth()) * 256, 16}, 0.0f, col);

//shield base
col = {0.1f, 0.1f, 0.4f, 1.0f};
drawButton({128,56}, {256, 16}, 0.0f, col);
drawbutton({128,56}, {256, 16}, 0.0f, col);

//shield
col = {0.2f, 0.2f, 0.9f, 1.0f};
drawButton({128,56}, {(_ply->getShield() / _ply->getMaxShield()) * 256, 16}, 0.0f, col);
drawbutton({128,56}, {(_ply->getShield() / _ply->getMaxShield()) * 256, 16}, 0.0f, col);

//energy base
col = {0.08f, 0.4f, 0.08f, 1.0f};
drawButton({128,72}, {256, 16}, 0.0f, col);
drawbutton({128,72}, {256, 16}, 0.0f, col);

//energy
col = {0.2f, 0.9f, 0.2f, 1.0f};
drawButton({128,72}, {(_ply->getEnergy() / _ply->getMaxEnergy()) * 256, 16}, 0.0f, col);
drawbutton({128,72}, {(_ply->getEnergy() / _ply->getMaxEnergy()) * 256, 16}, 0.0f, col);
}

void renderer_ngl::drawWeaponStats(player *_ply)
@@ -3,12 +3,14 @@

#include "ui/button.hpp"

namespace ui
button::button()
{

}

button::button(const std::string _txt,
const std::array<int, 8> _b_col,
const std::array<int, 8> _t_col,
const std::array<int, 4> _b_col,
const std::array<int, 4> _t_col,
const vec2 _pos,
const vec2 _dim)
{
@@ -40,8 +42,8 @@ button::button(const std::string _txt,
}

button::button(const std::string _txt,
const std::array<int, 8> _b_col,
const std::array<int, 8> _t_col,
const std::array<int, 4> _b_col,
const std::array<int, 4> _t_col,
const vec2 _pos,
const vec2 _dim,
const float _smul)
@@ -75,8 +77,8 @@ button::button(const std::string _txt,

button::button(
const std::string _txt,
const std::array<int, 8> _label,
const std::array<int, 8> _pcol,
const std::array<int, 4> _label,
const std::array<int, 4> _pcol,
const vec2 _pos,
const vec2 _dim,
const int _pcost
@@ -145,5 +147,3 @@ void button::reset()
m_label = m_initLabel;
m_cost = m_initCost;
}

}
@@ -1,9 +1,6 @@
#include "util.hpp"
#include "ui/selection.hpp"

namespace ui
{

selection::selection()
{
m_visible = true;
@@ -59,5 +56,3 @@ void selection::update(int _s)
i.update(_s);
}
}

}
@@ -5,9 +5,6 @@

std::array< std::string, 10> g_ROMAN_NUMS = {"I","II","III","IV","V","VI","VII","IX","X","X"};

namespace ui
{

userInterface::userInterface()
{

@@ -19,7 +16,7 @@ selectionReturn userInterface::handleInput(vec2 _pos)
for(size_t i = 0; i < m_elements.size(); ++i)
{
if(!m_elements[i].isVisible()) continue;
for(size_t j = 0; j < m_elements[i].getButtons()->size(); ++j)
for(size_t j = 0; j < m_elements[i].getbuttons()->size(); ++j)
{
button * b = m_elements[i].getAt(j);
if(pointInRect(_pos, b->getPos(), b->getDim()))
@@ -41,5 +38,3 @@ void userInterface::update(int _s)
{
for(auto &i : m_elements) i.update(_s);
}

}
@@ -1,10 +1,10 @@
#include "universe.hpp"
#include "common.hpp"
#include "file.hpp"
#include "sfx.hpp"
#include "util.hpp"
#include "shapes.hpp"
#include "common.hpp"

#include "sim_time.hpp"
#include "universe.hpp"
#include "util.hpp"

bool emnityCheck(const aiTeam _a, const aiTeam _b);

@@ -882,7 +882,7 @@ void universe::drawUI()
for(auto i = m_ui.getElements()->begin(); i != m_ui.getElements()->end(); ++i)
{
if(!i->isVisible()) continue;
for(auto j = i->getButtons()->begin(); j != i->getButtons()->end(); ++j)
for(auto j = i->getbuttons()->begin(); j != i->getbuttons()->end(); ++j)
{
std::array<int, 8> col = j->getCol();
if(!j->isSelected())
@@ -1138,7 +1138,7 @@ void universe::drawUI()
for(auto i = m_ui.getElements()->begin(); i != m_ui.getElements()->end(); ++i)
{
if(!i->isVisible()) continue;
for(auto j = i->getButtons()->begin(); j != i->getButtons()->end(); ++j)
for(auto j = i->getbuttons()->begin(); j != i->getbuttons()->end(); ++j)
{
std::array<float, 4> col = j->getDrawCol();

@@ -1153,7 +1153,7 @@ void universe::drawUI()
m_drawer.drawRects(false);
m_drawer.clearVectors();

for(auto k = i->getButtons()->begin(); k != i->getButtons()->end(); ++k)
for(auto k = i->getbuttons()->begin(); k != i->getbuttons()->end(); ++k)
{
std::array<float, 4> col = k->getDrawCol();

@@ -2043,64 +2043,62 @@ void universe::addBuild(

void universe::initUI()
{
using ui::selection;
using ui::button;
//Initialise the two selection menus.
selection energy_menu;
selection upgrades_menu;
selection upgrades_menu = loadSelection("upgrades.txt");

//Add buttons to the energy menu.
std::array<int, 8> arr1 = {20,20,20,200,100,100,100,255};
std::array<int, 8> arr2 = {100,100,100,200,250,250,250,255};
std::array<int, 4> arr1 = {100,100,100,255};
std::array<int, 4> arr2 = {250,250,250,255};
button energy_menu_neutral("BALANCED",arr1,arr2,{g_WIN_WIDTH * 0.9f, g_WIN_HEIGHT * 0.35f},{128.0f,64.0f});
energy_menu_neutral.setDark(false);
energy_menu.add(energy_menu_neutral);

//Array 1 = bg colour
arr1 = {12,24,26,200,27,95,232,255};
arr2 = {45,67,188,200,119,156,238,255};
arr1 = {27,95,232,255};
arr2 = {119,156,238,255};
button energy_menu_shields("SHIELDS",arr1,arr2,{g_WIN_WIDTH * 0.9f, g_WIN_HEIGHT * 0.45f},{128.0f,64.0f});
energy_menu.add(energy_menu_shields);

arr1 = {14,35,20,200,36,204,52,255};
arr2 = {65,127,64,200,129,241,127,255};
arr1 = {36,204,52,255};
arr2 = {129,241,127,255};
button energy_menu_engines("ENGINES",arr1,arr2,{g_WIN_WIDTH * 0.9f, g_WIN_HEIGHT * 0.55f},{128.0f,64.0f});
energy_menu.add(energy_menu_engines);

arr1 = {35,23,23,200,232,31,31,255};
arr2 = {124,33,33,200,217,116,116,255};
arr1 = {232,31,31,255};
arr2 = {217,116,116,255};
button energy_menu_guns("GUNS",arr1,arr2,{g_WIN_WIDTH * 0.9f, g_WIN_HEIGHT * 0.65f},{128.0f,64.0f});
energy_menu.add(energy_menu_guns);

//Add buttons to the upgrades menu.
float w = 150.0f, h = 50.0f;
arr1 = {50,5,5,200,250,50,50,255};
arr2 = {100,50,50,200,250,200,200,255};
arr1 = {250,50,50,255};
arr2 = {250,200,200,255};
button upgrades_lasers("LASERS I (4)",arr1,arr2,{g_WIN_WIDTH * 0.0f, g_WIN_HEIGHT * 0.85f},{w,h},4);
upgrades_menu.add(upgrades_lasers);

arr1 = {5,5,50,200,50,50,250,255};
arr2 = {50,50,100,200,200,200,250,255};
arr1 = {50,50,250,255};
arr2 = {200,200,250,255};
button upgrades_shields("SHIELDS I (4)",arr1,arr2,{g_WIN_WIDTH * 0.15f, g_WIN_HEIGHT * 0.85f},{w,h},4);
upgrades_menu.add(upgrades_shields);

arr1 = {5,50,5,200,50,250,50,255};
arr2 = {50,100,50,200,200,250,200,255};
arr1 = {50,250,50,255};
arr2 = {200,250,200,255};
button upgrades_generators("GENERATORS I (4)",arr1,arr2,{g_WIN_WIDTH * 0.3f, g_WIN_HEIGHT * 0.85f},{w,h},4);
upgrades_menu.add(upgrades_generators);

arr1 = {5,25,25,200,50,50,250,255};
arr2 = {50,50,80,200,200,200,220,255};
arr1 = {50,50,250,255};
arr2 = {200,200,220,255};
button upgrades_thrusters("THRUSTERS I (4)",arr1,arr2,{g_WIN_WIDTH * 0.45f, g_WIN_HEIGHT * 0.85f},{w,h},4);
upgrades_menu.add(upgrades_thrusters);

arr1 = {60,40,0,200,220,200,50,255};
arr2 = {255,210,0,200,255,253,100,255};
arr1 = {220,200,50,255};
arr2 = {255,253,100,255};
button upgrades_m_missiles("MISSILE (4)",arr1,arr2,{g_WIN_WIDTH * 0.6f, g_WIN_HEIGHT * 0.85f},{w,h},4);
upgrades_menu.add(upgrades_m_missiles);

arr1 = {50,100,140,200,180,220,255,255};
arr2 = {100,210,255,200,180,220,255,255};
arr1 = {180,220,255,255};
arr2 = {180,220,255,255};
button upgrades_miner("MINER (16)",arr1,arr2,{g_WIN_WIDTH * 0.75f, g_WIN_HEIGHT * 0.85f},{w,h},16);
upgrades_menu.add(upgrades_miner);

@@ -2134,17 +2132,17 @@ bool universe::upgradeCallback(
//This function takes the selected button, looks at the cost vs the score, updates relevant values,
//then returns a bool representing whether the upgrade was successful or unsuccessful.

ui::button * selectedButton = &m_ui.getElements()->at(_sel).getButtons()->at(_btn);
button * selectedbutton = &m_ui.getElements()->at(_sel).getbuttons()->at(_btn);
int lvl = m_ply.getUpgrade( _btn );

selectedButton->set(false);
selectedbutton->set(false);

if(selectedButton->getCost() > m_score or m_ply.getUpgrade(_btn) > 9) return false;
if(selectedbutton->getCost() > m_score or m_ply.getUpgrade(_btn) > 9) return false;

if(lvl < 9)
{
addScore( -selectedButton->getCost() );
if(_btn < 4) selectedButton->setCost(selectedButton->getCost() * 2);
addScore( -selectedbutton->getCost() );
if(_btn < 4) selectedbutton->setCost(selectedbutton->getCost() * 2);
}

m_ply.upgrade(_btn);
@@ -2161,7 +2159,7 @@ void universe::upgradeSetLabels(
int _plvl
)
{
ui::button * selectedButton = &m_ui.getElements()->at(_sel).getButtons()->at(_btn);
button * selectedbutton = &m_ui.getElements()->at(_sel).getbuttons()->at(_btn);

std::string s1;
int lvl;
@@ -2190,15 +2188,15 @@ void universe::upgradeSetLabels(

if(lvl < 8)
{
selectedButton->setCost(pow(2.0, lvl + 1) * 2);
selectedbutton->setCost(pow(2.0, lvl + 1) * 2);
s1 += " (";
std::stringstream ss;
ss << selectedButton->getCost();
ss << selectedbutton->getCost();
s1 += ss.str();
s1 += ")";
}

selectedButton->updateText(s1);
selectedbutton->updateText(s1);

addScore(0);