Skip to content

Commit

Permalink
hangar screen is now beautiful
Browse files Browse the repository at this point in the history
  • Loading branch information
Piglit committed Aug 7, 2023
1 parent a40241c commit 215ac91
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 106 deletions.
182 changes: 96 additions & 86 deletions src/screens/extra/hangar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <i18n.h>

HangarScreen::HangarScreen(GuiContainer* owner)
: GuiOverlay(owner, "HANGAR_SCREEN", colorConfig.background)
: GuiOverlay(owner, "HANGAR_SCREEN", colorConfig.background), creating_fighter(false)
{
// Render the background decorations.
auto background_crosses = new GuiOverlay(this, "BACKGROUND_CROSSES", glm::u8vec4{255,255,255,255});
Expand All @@ -18,13 +18,11 @@ HangarScreen::HangarScreen(GuiContainer* owner)
// Render the alert level color overlay.
(new AlertLevelOverlay(this));



// Draw a container with two columns.
auto container = new GuiElement(this, "");
container->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax)->setAttribute("layout", "horizontal");
auto left_col= new GuiElement(container, "");
left_col->setPosition(20, 100, sp::Alignment::TopLeft)->setSize(240, GuiElement::GuiSizeMax)->setAttribute("layout", "vertical");
left_col->setPosition(20, 100, sp::Alignment::TopLeft)->setSize(300, GuiElement::GuiSizeMax)->setMargins(0,0,0,20)->setAttribute("layout", "vertical");
auto right_col= new GuiElement(container, "");
right_col->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

Expand Down Expand Up @@ -64,25 +62,103 @@ HangarScreen::HangarScreen(GuiContainer* owner)
});
restocks_weapons_toggle->setSize(GuiElement::GuiSizeMax, 40);

// fighter selector
(new GuiLabel(left_col, "", tr("Ships in Hangar:"), 30))->setSize(GuiElement::GuiSizeMax, 50);
auto fighter_selection_panel = new GuiPanel(left_col, "FIGHTER_SELECTION_PANEL");
fighter_selection_panel->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
auto fighter_selection_content = new GuiElement(fighter_selection_panel, "");
fighter_selection_content->setMargins(10)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax)->setAttribute("layout", "vertical");
player_ship_list = new GuiListbox(fighter_selection_content, "FIGHTER_LIST", [this](int index, string value)
{
fighter_create_dialog->show();
select_fighter_label->hide();
});
player_ship_list->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Create Fighter Button
(new GuiButton(left_col, "CREATE_FIGHTER_BUTTON", tr("Create new fighter"), [this]() {
fighterCreateDialog->open();
}))->setPosition(0, 680, sp::Alignment::BottomLeft)->setSize(GuiElement::GuiSizeMax, 40);
fighterCreateDialog = new FighterCreateDialog(this, "FIGHTER_CREATE_DIALOG");

player_ship_list->setSelectionIndex(-1);
creating_fighter = true;
fighter_create_dialog->show();
select_fighter_label->hide();
}))->setSize(GuiElement::GuiSizeMax, 40);

// RIGHT PANEL
right_col->setMargins(47, 80, 40, 60);
auto right_panel = new GuiPanel(right_col, "FIGHTER_CREATION_PANEL");
right_panel->setPosition(0, 0, sp::Alignment::TopCenter)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
fighter_create_dialog = new GuiElement(right_panel, "");
fighter_create_dialog->setMargins(50)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax)->setAttribute("layout", "vertical");

// No fighter selected label
select_fighter_label = new GuiLabel(this, "FIGHTER_SELECT_LABEL", tr("Select or create a fighter"), 50);
select_fighter_label->setPosition(650, 300)->setSize(250, 60);

int left_col_width = 200;
// Callsign row
GuiElement* row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "CALLSIGN_LABEL", tr("Callsign: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(left_col_width, GuiElement::GuiSizeMax);
callsign = new GuiTextEntry(row, "CALLSIGN_ENTRY", "");
callsign->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// right column
// Password row
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "PASSWORD_LABEL", tr("Control Code: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(left_col_width, GuiElement::GuiSizeMax);
password = new GuiTextEntry(row, "PASSWORD_ENTRY", "");
password->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

(new GuiLabel(right_col, "", tr("Docked ships:"), 30))->setSize(GuiElement::GuiSizeMax, 50);
// Hull row
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "HULL_LABEL", tr("Hull: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(left_col_width, GuiElement::GuiSizeMax);
hull = new GuiSelector(row, "HULL_SELECTOR", [this](int index, string value)
{
P<ShipTemplate> ship_template = ShipTemplate::getTemplate(value);
playership_info->setText(ship_template->getDescription());
});
hull->setOptions({"MP52 Hornet", "ZX-Lindworm"})->setSelectionIndex(0); // TODO read from my ship witch template are available
hull->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// fighter selector
player_ship_list = new GuiSelector(right_col, "FIGHTER_SELECTOR", [this](int index, string value)
// Color row
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "COLOR_LABEL", tr("Color: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(left_col_width, GuiElement::GuiSizeMax);
color = new GuiSelector(row, "COLOR_SELECTOR", [this](int index, string value)
{
// TODO
// TODO change rendered model color
});
player_ship_list->setSize(GuiElement::GuiSizeMax, 50);
color->setOptions({"white", "yellow", "blue", "red", "green", "gray"})->setSelectionIndex(0);
color->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// info
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 400)->setAttribute("layout", "horizontal");
playership_info = new GuiScrollText(row, "PLAYERSHIP_INFO", tr("Ship info..."));
playership_info->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

P<ShipTemplate> ship_template = ShipTemplate::getTemplate(hull->getSelectionValue());
playership_info->setText(ship_template->getDescription());

// 3D TODO

// action row
row = new GuiElement(fighter_create_dialog, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiButton(row, "ABORT", tr("Cancel"), [this]() {
player_ship_list->setSelectionIndex(-1);
creating_fighter = false;
fighter_create_dialog->hide();
select_fighter_label->show();
}))->setSize(150,50);
(new GuiButton(row, "CREATE_SHIP_BUTTON", tr("Build Fighter"), [this]() {
// TODO
creating_fighter = false;
}))->setSize(150,50);

fighter_create_dialog->hide();
select_fighter_label->show();
}

void HangarScreen::onUpdate()
Expand All @@ -103,7 +179,12 @@ void HangarScreen::onUpdate()
index = player_ship_list->addEntry(ship_name, string(n));
}
}else{
if (player_ship_list->indexByValue(string(n)) != -1)
int index = player_ship_list->indexByValue(string(n));
if (index == player_ship_list->getSelectionIndex() && !creating_fighter){
fighter_create_dialog->hide();
select_fighter_label->show();
}
if (index != -1)
player_ship_list->removeEntry(player_ship_list->indexByValue(string(n)));
}
}
Expand All @@ -129,74 +210,3 @@ void HangarScreen::onDraw(sp::RenderTarget& renderer)

}

FighterCreateDialog::FighterCreateDialog(GuiContainer* parent, string id)
: GuiOverlay(parent, id, glm::u8vec4(0,0,0,64))
{
hide();

auto panel = new GuiPanel(this, "FIGHTER_CREATION_PANEL");
panel->setPosition(0, 350, sp::Alignment::TopCenter)->setSize(600, 600);

// Callsign row
GuiElement* row = new GuiElement(panel, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "CALLSIGN_LABEL", tr("Callsign: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(250, GuiElement::GuiSizeMax);
callsign = new GuiTextEntry(row, "CALLSIGN_ENTRY", "");
callsign->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Password row
row = new GuiElement(panel, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "PASSWORD_LABEL", tr("Control Code: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(250, GuiElement::GuiSizeMax);
password = new GuiTextEntry(row, "PASSWORD_ENTRY", "");
password->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Hull row
row = new GuiElement(panel, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "HULL_LABEL", tr("Hull: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(250, GuiElement::GuiSizeMax);
hull = new GuiSelector(row, "HULL_SELECTOR", [this](int index, string value)
{
P<ShipTemplate> ship_template = ShipTemplate::getTemplate(value);
playership_info->setText(ship_template->getDescription());
});
hull->setOptions({"MP52 Hornet", "ZX-Lindworm"})->setSelectionIndex(0); // TODO read from my ship witch template are available
hull->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Color row
row = new GuiElement(panel, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiLabel(row, "COLOR_LABEL", tr("Color: "), 30))->setAlignment(sp::Alignment::CenterRight)->setSize(250, GuiElement::GuiSizeMax);
color = new GuiSelector(row, "COLOR_SELECTOR", [this](int index, string value)
{
// TODO change rendered model color
});
color->setOptions({"white", "yellow", "blue", "red", "green", "gray"})->setSelectionIndex(0);
color->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// info
row = new GuiElement(panel, "");
row->setSize(GuiElement::GuiSizeMax, 400)->setAttribute("layout", "horizontal");
playership_info = new GuiScrollText(row, "PLAYERSHIP_INFO", tr("Ship info..."));
playership_info->setPosition(0, 10, sp::Alignment::TopCenter)->setSize(520, 400);

P<ShipTemplate> ship_template = ShipTemplate::getTemplate(hull->getSelectionValue());
playership_info->setText(ship_template->getDescription());

// 3D TODO

// action row
row = new GuiElement(panel, "");
row->setSize(GuiElement::GuiSizeMax, 50)->setAttribute("layout", "horizontal");
(new GuiButton(row, "ABORT", tr("Cancel"), [this]() {
// TODO
}))->setSize(100,50);
(new GuiButton(row, "CREATE_SHIP_BUTTON", tr("Build Fighter"), [this]() {
hide();
}))->setSize(100,50);

}

void FighterCreateDialog::open() {
show();
}
32 changes: 12 additions & 20 deletions src/screens/extra/hangar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#include "gui/gui2_textentry.h"
#include "gui/gui2_scrolltext.h"
#include "gui/gui2_keyvaluedisplay.h"
#include "gui/gui2_listbox.h"

class FighterCreateDialog;

class HangarScreen: public GuiOverlay//, public Updatable
class HangarScreen: public GuiOverlay
{
private:
GuiKeyValueDisplay* energy_display;
Expand All @@ -19,28 +18,21 @@ class HangarScreen: public GuiOverlay//, public Updatable
GuiToggleButton* repairs_docked_toggle;
GuiToggleButton* restocks_scan_probes_toggle;
GuiToggleButton* restocks_weapons_toggle;
GuiSelector* player_ship_list;
FighterCreateDialog* fighterCreateDialog;
public:
HangarScreen(GuiContainer* owner);

void onDraw(sp::RenderTarget& target) override;
virtual void onUpdate() override;
};

class FighterCreateDialog: public GuiOverlay
{
public:
FighterCreateDialog(GuiContainer* parent, string id);

void open();
private:

GuiListbox* player_ship_list;
GuiElement* fighter_create_dialog;
GuiLabel* select_fighter_label;
GuiTextEntry* callsign;
GuiTextEntry* password;
GuiSelector* hull;
GuiSelector* color;
GuiScrollText* playership_info;

bool creating_fighter;

public:
HangarScreen(GuiContainer* owner);

void onDraw(sp::RenderTarget& target) override;
virtual void onUpdate() override;
};
#endif//HANGAR_H

0 comments on commit 215ac91

Please sign in to comment.