Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified resources/gui/widget/ProgressbarFill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/gui/gui2_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ GuiElement* GuiElement::setMargins(float left, float top, float right, float bot
return this;
}

GuiElement* GuiElement::setParent(GuiContainer* new_parent)
{
if (GuiContainer* old_owner = this->getOwner())
{
// Works only if both the old owner and new parent are valid.
if (new_parent && old_owner != new_parent)
{
// Remove from old owner's children list.
old_owner->children.remove(this);

// Add to new owner's children list.
new_parent->children.push_back(this);

// Update owner pointer.
this->owner = new_parent;
}
else if (!new_parent)
{
LOG(Debug, "GuiElement::setParent called, but new parent is invalid.");
}
}
else
LOG(Debug, "GuiElement::setParent called, but old owner is invalid.");

return this;
}

GuiElement* GuiElement::setPosition(float x, float y, sp::Alignment alignment)
{
layout.position.x = x;
Expand Down
3 changes: 3 additions & 0 deletions src/gui/gui2_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class GuiElement : public GuiContainer
GuiContainer* getTopLevelContainer();
const string& getID() { return id; }

// Change this element's owner/container safely (removes from old owner and adds to new owner)
GuiElement* setParent(GuiContainer* new_owner);

//Have this GuiElement destroyed, but at a safe point&time in the code. (handled by the container)
void destroy();

Expand Down
12 changes: 11 additions & 1 deletion src/gui/gui2_progressbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@ void GuiProgressbar::onDraw(sp::RenderTarget& renderer)
const auto& front = front_style->get(getState());

float f = (value - min_value) / (max_value - min_value);
sp::Rect fill_rect = rect;

if (drawBackground)
renderer.drawStretched(rect, back.texture, back.color);

sp::Rect fill_rect = rect;
if (rect.size.x >= rect.size.y)
{
if (drawBackground)
{
fill_rect.position.y += fill_rect.size.y * 0.125f;
fill_rect.size.y *= 0.75f;
}
fill_rect.size.x *= f;
if (max_value < min_value)
fill_rect.position.x = rect.position.x + rect.size.x - fill_rect.size.x;
renderer.drawStretchedHVClipped(rect, fill_rect, front.size, front.texture, color);
}
else
{
if (drawBackground)
{
fill_rect.position.x += fill_rect.size.x * 0.125f;
fill_rect.size.x *= 0.75f;
}
fill_rect.size.y *= f;
fill_rect.position.y = rect.position.y + rect.size.y - fill_rect.size.y;
renderer.drawStretchedHVClipped(rect, fill_rect, front.size, front.texture, color);
Expand Down
18 changes: 6 additions & 12 deletions src/gui/gui2_progressslider.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "gui2_progressslider.h"
#include "theme.h"


GuiProgressSlider::GuiProgressSlider(GuiContainer* owner, string id, float min_value, float max_value, float start_value, func_t func)
: GuiProgressbar(owner, id, min_value, max_value, start_value), callback(func)
{
Expand All @@ -20,19 +19,14 @@ void GuiProgressSlider::onMouseDrag(glm::vec2 position, sp::io::Pointer::ID id)
new_value = (position.x - rect.position.x) / (rect.size.x);
else
new_value = (position.y - rect.position.y) / (rect.size.y);

new_value = min_value + (max_value - min_value) * new_value;

if (min_value < max_value)
{
if (new_value < min_value)
new_value = min_value;
if (new_value > max_value)
new_value = max_value;
}else{
if (new_value > min_value)
new_value = min_value;
if (new_value < max_value)
new_value = max_value;
}
new_value = std::clamp(new_value, min_value, max_value);
else
new_value = std::clamp(new_value, max_value, min_value);

if (value != new_value)
{
value = new_value;
Expand Down
15 changes: 4 additions & 11 deletions src/gui/gui2_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,10 @@ void GuiBasicSlider::onMouseUp(glm::vec2 position, sp::io::Pointer::ID id)
GuiBasicSlider* GuiBasicSlider::setValue(float value)
{
if (min_value < max_value)
{
if (value < min_value)
value = min_value;
if (value > max_value)
value = max_value;
}else{
if (value > min_value)
value = min_value;
if (value < max_value)
value = max_value;
}
this->value = std::clamp(value, min_value, max_value);
else
this->value = std::clamp(value, max_value, min_value);

this->value = value;
return this;
}
Expand Down
530 changes: 418 additions & 112 deletions src/screens/extra/powerManagement.cpp

Large diffs are not rendered by default.

60 changes: 47 additions & 13 deletions src/screens/extra/powerManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,75 @@
#include "gui/gui2_overlay.h"
#include "components/shipsystem.h"

class GuiArrow;
class GuiCustomShipFunctions;
class GuiKeyValueDisplay;
class GuiLabel;
class GuiPanel;
class GuiSlider;
class GuiProgressbar;
class GuiKeyValueDisplay;
class GuiSlider;

class PowerManagementScreen : public GuiOverlay
{
private:
glm::vec2 view_size;
int active_system_count;
GuiElement* status_bar;
GuiKeyValueDisplay* energy_display;
GuiProgressbar* energy_capacity_gauge;
GuiArrow* energy_delta_arrow;
GuiKeyValueDisplay* coolant_display;
GuiProgressbar* coolant_distribution_gauge;
GuiElement* systems_grid;
GuiCustomShipFunctions* custom_functions;

float previous_energy_measurement;
float previous_energy_level;
float average_energy_delta;
ShipSystem::Type selected_system = ShipSystem::Type::None;
constexpr static int layout_margin = 20;
constexpr static float status_bar_height = 100.0f;
constexpr static float custom_functions_width = 250.0f;
constexpr static glm::u8vec3 coolant_color{32, 128, 128};
constexpr static glm::u8vec4 coolant_color_foreground{coolant_color, 128};
constexpr static glm::u8vec4 coolant_color_background{coolant_color, 255};
constexpr static glm::u8vec3 energy_color{192, 192, 32};
constexpr static glm::u8vec4 energy_color_background{energy_color, 255};
constexpr static float panel_width_with_coolant = 300.0f;
constexpr static float panel_width_without_coolant = 200.0f;

class SystemRow
glm::vec2 panel_size{panel_width_with_coolant, 380.0f};
float previous_energy_level = 0.0f;
float average_energy_delta = 0.0f;
float previous_energy_measurement = 0.0f;
ShipSystem::Type selected_system;

class SystemPanel
{
public:
GuiPanel* box;
SystemPanel()
: container(nullptr), system_label(nullptr), system_container_sliders(nullptr), power_control(nullptr), power_slider(nullptr), power_bar(nullptr), coolant_control(nullptr), coolant_slider(nullptr), coolant_bar(nullptr), heat_bar(nullptr)
{}
GuiPanel* container;
GuiKeyValueDisplay* system_label;
string icon_file;
GuiElement* system_container_sliders;
GuiLabel* power_label;
GuiElement* power_control;
GuiSlider* power_slider;
GuiSlider* coolant_slider;
GuiProgressbar* heat_bar;
GuiLabel* heat_label;
GuiProgressbar* power_bar;
GuiProgressbar* coolant_bar;
GuiLabel* coolant_label;
GuiElement* coolant_control;
GuiSlider* coolant_slider;
GuiProgressbar* coolant_bar;
GuiLabel* heat_label;
GuiArrow* heat_arrow;
GuiProgressbar* heat_bar;
};
SystemRow systems[ShipSystem::COUNT];
SystemPanel systems[ShipSystem::COUNT];
std::vector<GuiElement*> systems_rows;
bool set_power_active[ShipSystem::COUNT] = {false};
bool set_coolant_active[ShipSystem::COUNT] = {false};
public:
PowerManagementScreen(GuiContainer* owner);

void onDraw(sp::RenderTarget& target) override;
bool populateSystemPanel(int system_index, GuiElement* systems_row);
virtual void onUpdate() override;
};
Loading