Skip to content

Commit

Permalink
add hangar screen WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Pithlit committed Aug 4, 2023
1 parent 96f2135 commit 66dd45d
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ set(MAIN_SOURCES
src/screens/extra/databaseScreen.cpp
src/screens/extra/commsScreen.cpp
src/screens/extra/shipLogScreen.cpp
src/screens/extra/hangar.cpp
src/screens/missionControlScreen.cpp
src/screens/gm/gameMasterScreen.cpp
src/screens/gm/objectCreationView.cpp
Expand Down Expand Up @@ -486,6 +487,7 @@ set(MAIN_SOURCES
src/screens/extra/databaseScreen.h
src/screens/extra/powerManagement.h
src/screens/extra/shipLogScreen.h
src/screens/extra/hangar.h
src/screens/gm/chatDialog.h
src/screens/gm/gameMasterScreen.h
src/screens/gm/globalMessageEntryView.h
Expand Down
7 changes: 7 additions & 0 deletions src/playerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "screens/extra/databaseScreen.h"
#include "screens/extra/commsScreen.h"
#include "screens/extra/shipLogScreen.h"
#include "screens/extra/hangar.h"

#include "screenComponents/mainScreenControls.h"
#include "screenComponents/selfDestructEntry.h"
Expand Down Expand Up @@ -219,6 +220,8 @@ void PlayerInfo::spawnUI(int monitor_index, RenderLayer* render_layer)
screen->addStationTab(new CommsScreen(container), commsOnly, getCrewPositionName(commsOnly), getCrewPositionIcon(commsOnly));
if (crew_position[shipLog] & (1 << monitor_index))
screen->addStationTab(new ShipLogScreen(container), shipLog, getCrewPositionName(shipLog), getCrewPositionIcon(shipLog));
if (crew_position[hangar] & (1 << monitor_index))
screen->addStationTab(new ShipLogScreen(container), hangar, getCrewPositionName(hangar), getCrewPositionIcon(hangar));

GuiSelfDestructEntry* sde = new GuiSelfDestructEntry(container, "SELF_DESTRUCT_ENTRY");
for(int n=0; n<max_crew_positions; n++)
Expand Down Expand Up @@ -265,6 +268,7 @@ string getCrewPositionName(ECrewPosition position)
case altRelay: return tr("station","Strategic Map");
case commsOnly: return tr("station","Comms");
case shipLog: return tr("station","Ship's Log");
case hangar: return tr("station","Hangar");
default: return "ErrUnk: " + string(position);
}
}
Expand All @@ -288,6 +292,7 @@ string getCrewPositionIcon(ECrewPosition position)
case altRelay: return "";
case commsOnly: return "";
case shipLog: return "";
case hangar: return "";
default: return "ErrUnk: " + string(position);
}
}
Expand Down Expand Up @@ -334,6 +339,8 @@ template<> void convert<ECrewPosition>::param(lua_State* L, int& idx, ECrewPosit
cp = commsOnly;
else if (str == "shiplog")
cp = shipLog;
else if (str == "hangar")
cp = hangar;
else
luaL_error(L, "Unknown value for crew position: %s", str.c_str());
}
1 change: 1 addition & 0 deletions src/playerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum ECrewPosition
altRelay,
commsOnly,
shipLog,
hangar,
max_crew_positions
};

Expand Down
155 changes: 155 additions & 0 deletions src/screens/extra/hangar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#include "hangar.h"
#include "gui/gui2_label.h"
#include "gui/gui2_panel.h"
#include "playerInfo.h"
#include "screenComponents/alertOverlay.h"
#include "shipTemplate.h"
#include "spaceObjects/playerSpaceship.h"
#include <i18n.h>

HangarScreen::HangarScreen(GuiContainer* owner)
: GuiOverlay(owner, "HANGAR_SCREEN", colorConfig.background)
{
// Render the background decorations.
auto background_crosses = new GuiOverlay(this, "BACKGROUND_CROSSES", glm::u8vec4{255,255,255,255});
background_crosses->setTextureTiled("gui/background/crosses.png");

// 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(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
auto right_col= new GuiElement(container, "");
right_col->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);

// Energy display.
energy_display = new GuiKeyValueDisplay(left_col, "ENERGY_DISPLAY", 0.45, tr("Energy"), "");
energy_display->setIcon("gui/icons/energy")->setTextSize(20)->setSize(240, 40);

// Reputation display.
info_reputation = new GuiKeyValueDisplay(left_col, "INFO_REPUTATION", 0.45f, tr("Reputation") + ":", "");

// Shares energy with docked bool
(new GuiLabel(left_col, "", tr("Docked ship services:"), 30))->setSize(GuiElement::GuiSizeMax, 50);
shares_energy_with_docked_toggle = new GuiToggleButton(left_col, "", tr("Share energy"), [this](bool value) {
my_spaceship->setSharesEnergyWithDocked(value);
});
shares_energy_with_docked_toggle->setSize(GuiElement::GuiSizeMax, 40);

// Repairs docked ships bool
repairs_docked_toggle = new GuiToggleButton(left_col, "", tr("Repair ships"), [this](bool value) {
my_spaceship->setRepairDocked(value);
});
repairs_docked_toggle->setSize(GuiElement::GuiSizeMax, 40);

// Restocks player scan probes bool
restocks_scan_probes_toggle = new GuiToggleButton(left_col, "", tr("Restock scan probes"), [this](bool value) {
my_spaceship->setRestocksScanProbes(value);
});
restocks_scan_probes_toggle->setSize(GuiElement::GuiSizeMax, 40);

// Restocks missiles selector
restocks_weapons_toggle= new GuiToggleButton(left_col, "", tr("Restock missiles"), [this](bool value) {
if (value)
my_spaceship->setRestocksMissilesDocked(R_Fighters);
else
my_spaceship->setRestocksMissilesDocked(R_None);
});
restocks_weapons_toggle->setSize(GuiElement::GuiSizeMax, 40);


}

void HangarScreen::onDraw(sp::RenderTarget& renderer)
{
GuiOverlay::onDraw(renderer);

// update stat displays
info_reputation->setValue(string(my_spaceship->getReputationPoints(), 0));
energy_display->setValue(string(int(nearbyint((my_spaceship->energy_level)))));
if (my_spaceship->energy_level < 100.0f)
energy_display->setColor(glm::u8vec4(255, 0, 0, 255));
else
energy_display->setColor(glm::u8vec4{255,255,255,255});

// update buttons
shares_energy_with_docked_toggle->setValue(my_spaceship->getSharesEnergyWithDocked());
repairs_docked_toggle->setValue(my_spaceship->getRepairDocked());
restocks_scan_probes_toggle->setValue(my_spaceship->getRestocksScanProbes());
restocks_weapons_toggle->setValue(my_spaceship->getRestocksMissilesDocked() == R_Fighters);

}

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]() {
// TODO
}))->setSize(100,50);

}

41 changes: 41 additions & 0 deletions src/screens/extra/hangar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef HANGAR_H
#define HANGAR_H

#include "gui/gui2_overlay.h"
#include "gui/gui2_togglebutton.h"
#include "gui/gui2_selector.h"
#include "gui/gui2_textentry.h"
#include "gui/gui2_scrolltext.h"
#include "gui/gui2_keyvaluedisplay.h"


class HangarScreen: public GuiOverlay
{
private:
GuiKeyValueDisplay* energy_display;
GuiKeyValueDisplay* info_reputation;
GuiToggleButton* shares_energy_with_docked_toggle;
GuiToggleButton* repairs_docked_toggle;
GuiToggleButton* restocks_scan_probes_toggle;
GuiToggleButton* restocks_weapons_toggle;
public:
HangarScreen(GuiContainer* owner);

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

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

// void open(string label, string preset_password, std::function<bool(string)> on_password_check, std::function<void()> on_ready, std::function<void()> on_cancel);
private:

GuiTextEntry* callsign;
GuiTextEntry* password;
GuiSelector* hull;
GuiSelector* color;
GuiScrollText* playership_info;
};
#endif//HANGAR_H

0 comments on commit 66dd45d

Please sign in to comment.