GuiShipTweakSystems::GuiShipTweakSystems(GuiContainer* owner) : GuiTweakPage(owner) { GuiAutoLayout* left_col = new GuiAutoLayout(this, "LEFT_LAYOUT", GuiAutoLayout::LayoutVerticalTopToBottom); left_col->setPosition(20, 20, ATopLeft)->setSize(300, GuiElement::GuiSizeMax); GuiAutoLayout* right_col = new GuiAutoLayout(this, "RIGHT_LAYOUT", GuiAutoLayout::LayoutVerticalTopToBottom); right_col->setPosition(-20, 20, ATopRight)->setSize(300, GuiElement::GuiSizeMax); for(int n=0; n<SYS_COUNT; n++) { ESystem system = ESystem(n); (new GuiLabel(left_col, "", getSystemName(system) + " health", 20))->setSize(GuiElement::GuiSizeMax, 30); system_damage[n] = new GuiSlider(left_col, "", -1.0, 1.0, 0.0, [this, n](float value) { target->systems[n].health = value; }); system_damage[n]->setSize(GuiElement::GuiSizeMax, 30); system_damage[n]->addSnapValue(-1.0, 0.01); system_damage[n]->addSnapValue( 0.0, 0.01); system_damage[n]->addSnapValue( 1.0, 0.01); (new GuiLabel(right_col, "", getSystemName(system) + " heat", 20))->setSize(GuiElement::GuiSizeMax, 30); system_heat[n] = new GuiSlider(right_col, "", 0.0, 1.0, 0.0, [this, n](float value) { target->systems[n].heat_level = value; }); system_heat[n]->setSize(GuiElement::GuiSizeMax, 30); system_heat[n]->addSnapValue( 0.0, 0.01); system_heat[n]->addSnapValue( 1.0, 0.01); } }
void EngineeringScreen::onDraw(sf::RenderTarget& window) { if (my_spaceship) { energy_display->setValue(string(int(my_spaceship->energy_level)) + " (" + string(my_spaceship->getNetPowerUsage()) + ")"); if (my_spaceship->energy_level < 100) energy_display->setColor(sf::Color::Red); else energy_display->setColor(sf::Color::White); hull_display->setValue(string(int(100 * my_spaceship->hull_strength / my_spaceship->hull_max)) + "%"); if (my_spaceship->hull_strength < my_spaceship->hull_max / 4.0f) hull_display->setColor(sf::Color::Red); else hull_display->setColor(sf::Color::White); front_shield_display->setValue(string(my_spaceship->getShieldPercentage(0)) + "%"); rear_shield_display->setValue(string(my_spaceship->getShieldPercentage(1)) + "%"); for(int n=0; n<SYS_COUNT; n++) { SystemRow info = system_rows[n]; info.layout->setVisible(my_spaceship->hasSystem(ESystem(n))); float health = my_spaceship->systems[n].health; if (health < 0.0) info.damage_bar->setValue(-health)->setColor(sf::Color(128, 32, 32)); else info.damage_bar->setValue(health)->setColor(sf::Color(64, 128 * health, 64 * health)); info.damage_label->setText(string(int(health * 100)) + "%"); float heat = my_spaceship->systems[n].heat_level; info.heat_bar->setValue(heat)->setColor(sf::Color(128, 128 * (1.0 - heat), 0)); float heating_diff = my_spaceship->systems[n].getHeatingDelta(); if (heating_diff > 0) info.heat_arrow->setAngle(90); else info.heat_arrow->setAngle(-90); info.heat_arrow->setVisible(heat > 0); info.heat_arrow->setColor(sf::Color(255, 255, 255, std::min(255, int(255 * fabs(heating_diff))))); info.power_bar->setValue(my_spaceship->systems[n].power_level); info.coolant_bar->setValue(my_spaceship->systems[n].coolant_level); } if (selected_system != SYS_None) { ShipSystem& system = my_spaceship->systems[selected_system]; power_label->setText("Power: " + string(int(system.power_level * 100)) + "%/" + string(int(system.power_request * 100)) + "%"); coolant_label->setText("Coolant: " + string(int(system.coolant_level / PlayerSpaceship::max_coolant * 100)) + "%/" + string(int(system.coolant_request / PlayerSpaceship::max_coolant * 100)) + "%"); } } GuiOverlay::onDraw(window); }
PowerManagementScreen::PowerManagementScreen(GuiContainer* owner) : GuiOverlay(owner, "POWER_MANAGEMENT_SCREEN", colorConfig.background) { GuiAutoLayout* layout = new GuiAutoLayout(this, "", GuiAutoLayout::LayoutHorizontalLeftToRight); layout->setPosition(20, 50, ATopLeft)->setSize(GuiElement::GuiSizeMax, 400); for(int n=0; n<SYS_COUNT; n++) { if (n == 4) { //Start the 2nd row after 4 elements. layout = new GuiAutoLayout(this, "", GuiAutoLayout::LayoutHorizontalLeftToRight); layout->setPosition(20, 450, ATopLeft)->setSize(GuiElement::GuiSizeMax, 400); } GuiBox* box = new GuiBox(layout, ""); systems[n].box = box; box->setSize(290, 400); (new GuiLabel(box, "", getSystemName(ESystem(n)), 30))->addBackground()->setAlignment(ACenter)->setPosition(0, 0, ATopLeft)->setSize(290, 50); (new GuiLabel(box, "", "Power", 30))->setVertical()->setAlignment(ACenterLeft)->setPosition(20, 50, ATopLeft)->setSize(30, 340); (new GuiLabel(box, "", "Coolant", 30))->setVertical()->setAlignment(ACenterLeft)->setPosition(100, 50, ATopLeft)->setSize(30, 340); (new GuiLabel(box, "", "Heat", 30))->setVertical()->setAlignment(ACenterLeft)->setPosition(180, 50, ATopLeft)->setSize(30, 340); systems[n].power_slider = new GuiSlider(box, "", 3.0, 0.0, 1.0, [n](float value) { if (my_spaceship) my_spaceship->commandSetSystemPower(ESystem(n), value); }); systems[n].power_slider->addSnapValue(1.0, 0.1)->setPosition(50, 50, ATopLeft)->setSize(55, 340); systems[n].coolant_slider = new GuiSlider(box, "", 10.0, 0.0, 0.0, [n](float value) { if (my_spaceship) my_spaceship->commandSetSystemCoolant(ESystem(n), value); }); systems[n].coolant_slider->setPosition(130, 50, ATopLeft)->setSize(55, 340); systems[n].heat_bar = new GuiProgressbar(box, "", 0.0, 1.0, 0.0); systems[n].heat_bar->setPosition(210, 50, ATopLeft)->setSize(50, 340); } }
void PowerManagementScreen::onDraw(sf::RenderTarget& window) { GuiOverlay::onDraw(window); if (my_spaceship) { for(int n=0; n<SYS_COUNT; n++) { systems[n].box->setVisible(my_spaceship->hasSystem(ESystem(n))); systems[n].power_slider->setValue(my_spaceship->systems[n].power_level); systems[n].coolant_slider->setValue(my_spaceship->systems[n].coolant_level); float heat = my_spaceship->systems[n].heat_level; systems[n].heat_bar->setValue(heat)->setColor(sf::Color(128, 128 * (1.0 - heat), 0)); } } }
void EngineeringScreen::onDraw(sf::RenderTarget& window) { if (my_spaceship) { energy_display->setValue(string(int(my_spaceship->energy_level)) + " (" + string(my_spaceship->getNetPowerUsage()) + ")"); hull_display->setValue(string(int(100 * my_spaceship->hull_strength / my_spaceship->hull_max)) + "%"); shields_display->setValue(string(int(100 * my_spaceship->front_shield / my_spaceship->front_shield_max)) + "% " + string(int(100 * my_spaceship->rear_shield / my_spaceship->rear_shield_max)) + "%"); for(int n=0; n<SYS_COUNT; n++) { SystemRow info = system_rows[n]; info.layout->setVisible(my_spaceship->hasSystem(ESystem(n))); float health = my_spaceship->systems[n].health; if (health < 0.0) info.damage_bar->setValue(-health)->setColor(sf::Color(128, 32, 32)); else info.damage_bar->setValue(health)->setColor(sf::Color(64, 128 * health, 64 * health)); info.damage_label->setText(string(int(health * 100)) + "%"); float heat = my_spaceship->systems[n].heat_level; info.heat_bar->setValue(heat)->setColor(sf::Color(128, 128 * (1.0 - heat), 0)); float heating_diff = my_spaceship->systems[n].getHeatingDelta(); if (heating_diff > 0) info.heat_arrow->setAngle(90); else info.heat_arrow->setAngle(-90); info.heat_arrow->setVisible(heat > 0); info.heat_arrow->setColor(sf::Color(255, 255, 255, std::min(255, int(255 * fabs(heating_diff))))); info.power_bar->setValue(my_spaceship->systems[n].power_level); info.coolant_bar->setValue(my_spaceship->systems[n].coolant_level); } } GuiOverlay::onDraw(window); }
EngineeringScreen::EngineeringScreen(GuiContainer* owner) : GuiOverlay(owner, "ENGINEERING_SCREEN", sf::Color::Black), selected_system(SYS_Reactor) { energy_display = new GuiKeyValueDisplay(this, "ENERGY_DISPLAY", 0.45, "Energy", ""); energy_display->setTextSize(20)->setPosition(20, 100, ATopLeft)->setSize(240, 40); hull_display = new GuiKeyValueDisplay(this, "HULL_DISPLAY", 0.45, "Hull", ""); hull_display->setTextSize(20)->setPosition(20, 140, ATopLeft)->setSize(240, 40); shields_display = new GuiKeyValueDisplay(this, "SHIELDS_DISPLAY", 0.45, "Shields", ""); shields_display->setTextSize(20)->setPosition(20, 180, ATopLeft)->setSize(240, 40); (new GuiSelfDestructButton(this, "SELF_DESTRUCT"))->setPosition(20, 220, ATopLeft)->setSize(240, 100); GuiAutoLayout* system_row_layouts = new GuiAutoLayout(this, "SYSTEM_ROWS", GuiAutoLayout::LayoutVerticalBottomToTop); system_row_layouts->setPosition(20, -20, ABottomLeft); system_row_layouts->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); for(int n=0; n<SYS_COUNT; n++) { string id = "SYSTEM_ROW_" + getSystemName(ESystem(n)); SystemRow info; info.layout = new GuiAutoLayout(system_row_layouts, id, GuiAutoLayout::LayoutHorizontalLeftToRight); info.layout->setSize(GuiElement::GuiSizeMax, 50); info.button = new GuiToggleButton(info.layout, id + "_SELECT", getSystemName(ESystem(n)), [this, n](bool value){ for(int idx=0; idx<SYS_COUNT; idx++) { system_rows[idx].button->setValue(idx == n); } selected_system = ESystem(n); if (my_spaceship) { power_slider->setValue(my_spaceship->systems[n].power_level); coolant_slider->setValue(my_spaceship->systems[n].coolant_level); } }); info.button->setSize(300, GuiElement::GuiSizeMax); info.damage_bar = new GuiProgressbar(info.layout, id + "_DAMAGE", 0.0, 1.0, 0.0); info.damage_bar->setSize(100, GuiElement::GuiSizeMax); if (!gameGlobalInfo->use_system_damage) info.damage_bar->hide(); info.damage_label = new GuiLabel(info.damage_bar, id + "_DAMAGE_LABEL", "...", 20); info.damage_label->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); info.heat_bar = new GuiProgressbar(info.layout, id + "_HEAT", 0.0, 1.0, 0.0); info.heat_bar->setSize(50, GuiElement::GuiSizeMax); info.heat_arrow = new GuiArrow(info.heat_bar, id + "_HEAT_ARROW", 0); info.heat_arrow->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); info.power_bar = new GuiProgressbar(info.layout, id + "_POWER", 0.0, 3.0, 0.0); info.power_bar->setColor(sf::Color(192, 192, 0))->setSize(50, GuiElement::GuiSizeMax); info.coolant_bar = new GuiProgressbar(info.layout, id + "_COOLANT", 0.0, 10.0, 0.0); info.coolant_bar->setColor(sf::Color(0, 128, 128))->setSize(50, GuiElement::GuiSizeMax); info.layout->moveToBack(); system_rows.push_back(info); } GuiBox* box = new GuiBox(this, "POWER_COOLANT_BOX"); box->setPosition(110, -20, ABottomCenter)->setSize(270, 400); (new GuiLabel(box, "POWER_LABEL", "Power", 30))->setVertical()->setAlignment(ACenterLeft)->setPosition(20, 20, ATopLeft)->setSize(30, 360); (new GuiLabel(box, "COOLANT_LABEL", "Coolant", 30))->setVertical()->setAlignment(ACenterLeft)->setPosition(110, 20, ATopLeft)->setSize(30, 360); power_slider = new GuiSlider(box, "POWER_SLIDER", 3.0, 0.0, 1.0, [this](float value) { if (my_spaceship) my_spaceship->commandSetSystemPower(selected_system, value); }); power_slider->setSnapValue(1.0, 0.1)->setPosition(50, 20, ATopLeft)->setSize(60, 360); coolant_slider = new GuiSlider(box, "COOLANT_SLIDER", 10.0, 0.0, 0.0, [this](float value) { if (my_spaceship) my_spaceship->commandSetSystemCoolant(selected_system, value); }); coolant_slider->setPosition(140, 20, ATopLeft)->setSize(60, 360); (new GuiShieldFrequencySelect(this, "SHIELD_FREQ"))->setPosition(-20, -20, ABottomRight)->setSize(320, 400); (new GuiShipInternalView(system_row_layouts, "SHIP_INTERNAL_VIEW", 48.0f))->setShip(my_spaceship)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); }
void RepairCrew::update(float delta) { P<PlayerSpaceship> ship; if (game_server) ship = game_server->getObjectById(ship_id); else if (game_client) ship = game_client->getObjectById(ship_id); else { destroy(); return; } if (game_server && !ship) { destroy(); return; } if (!ship || !ship->ship_template) return; if (position.x < -0.5) { ship->ship_template->interiorSize(); int n=irandom(0, ship->ship_template->rooms.size() - 1); position = sf::Vector2f(ship->ship_template->rooms[n].position + sf::Vector2i(irandom(0, ship->ship_template->rooms[n].size.x - 1), irandom(0, ship->ship_template->rooms[n].size.y - 1))); target_position = sf::Vector2i(position); } action_delay -= delta; sf::Vector2i pos = sf::Vector2i(position + sf::Vector2f(0.5, 0.5)); switch(action) { case RC_Idle: { action_delay = 1.0 / move_speed; if (pos != target_position) { ERepairCrewDirection new_direction = pathFind(pos, target_position, ship->ship_template); if (new_direction != RC_None) { action = RC_Move; direction = new_direction; } } position = sf::Vector2f(pos); ESystem system = ship->ship_template->getSystemAtRoom(pos); if (system != SYS_None) { ship->systems[system].health += repair_per_second * delta; if (ship->systems[system].health > 1.0) ship->systems[system].health = 1.0; } if (ship->auto_repair_enabled && pos == target_position && (system == SYS_None || !ship->hasSystem(system) || ship->systems[system].health == 1.0)) { int n=irandom(0, SYS_COUNT - 1); if (ship->hasSystem(ESystem(n)) && ship->systems[n].health < 1.0) { for(unsigned int idx=0; idx<ship->ship_template->rooms.size(); idx++) { if (ship->ship_template->rooms[idx].system == ESystem(n)) { target_position = ship->ship_template->rooms[idx].position + sf::Vector2i(irandom(0, ship->ship_template->rooms[idx].size.x - 1), irandom(0, ship->ship_template->rooms[idx].size.y - 1)); } } } } } break; case RC_Move: switch(direction) { case RC_None: break; case RC_Left: position.x -= delta * move_speed; break; case RC_Right: position.x += delta * move_speed; break; case RC_Up: position.y -= delta * move_speed; break; case RC_Down: position.y += delta * move_speed; break; } if (action_delay < 0.0) action = RC_Idle; break; } }
EngineeringScreen::EngineeringScreen(GuiContainer* owner, ECrewPosition crew_position) : GuiOverlay(owner, "ENGINEERING_SCREEN", colorConfig.background), selected_system(SYS_None) { // Render the background decorations. background_crosses = new GuiOverlay(this, "BACKGROUND_CROSSES", sf::Color::White); background_crosses->setTextureTiled("gui/BackgroundCrosses"); // Render the alert level color overlay. (new AlertLevelOverlay(this)); energy_display = new GuiKeyValueDisplay(this, "ENERGY_DISPLAY", 0.45, "Energy", ""); energy_display->setIcon("gui/icons/energy")->setTextSize(20)->setPosition(20, 100, ATopLeft)->setSize(240, 40); hull_display = new GuiKeyValueDisplay(this, "HULL_DISPLAY", 0.45, "Hull", ""); hull_display->setIcon("gui/icons/hull")->setTextSize(20)->setPosition(20, 140, ATopLeft)->setSize(240, 40); front_shield_display = new GuiKeyValueDisplay(this, "SHIELDS_DISPLAY", 0.45, "Front", ""); front_shield_display->setIcon("gui/icons/shields-fore")->setTextSize(20)->setPosition(20, 180, ATopLeft)->setSize(240, 40); rear_shield_display = new GuiKeyValueDisplay(this, "SHIELDS_DISPLAY", 0.45, "Rear", ""); rear_shield_display->setIcon("gui/icons/shields-aft")->setTextSize(20)->setPosition(20, 220, ATopLeft)->setSize(240, 40); (new GuiSelfDestructButton(this, "SELF_DESTRUCT"))->setPosition(20, 260, ATopLeft)->setSize(240, 100); GuiElement* system_config_container = new GuiElement(this, ""); system_config_container->setPosition(0, -20, ABottomCenter)->setSize(750 + 300, GuiElement::GuiSizeMax); GuiAutoLayout* system_row_layouts = new GuiAutoLayout(system_config_container, "SYSTEM_ROWS", GuiAutoLayout::LayoutVerticalBottomToTop); system_row_layouts->setPosition(0, 0, ABottomLeft); system_row_layouts->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); for(int n=0; n<SYS_COUNT; n++) { string id = "SYSTEM_ROW_" + getSystemName(ESystem(n)); SystemRow info; info.layout = new GuiAutoLayout(system_row_layouts, id, GuiAutoLayout::LayoutHorizontalLeftToRight); info.layout->setSize(GuiElement::GuiSizeMax, 50); info.button = new GuiToggleButton(info.layout, id + "_SELECT", getSystemName(ESystem(n)), [this, n](bool value){ selectSystem(ESystem(n)); }); info.button->setSize(300, GuiElement::GuiSizeMax); info.damage_bar = new GuiProgressbar(info.layout, id + "_DAMAGE", 0.0, 1.0, 0.0); info.damage_bar->setSize(150, GuiElement::GuiSizeMax); if (!gameGlobalInfo->use_system_damage) info.damage_bar->hide(); info.damage_label = new GuiLabel(info.damage_bar, id + "_DAMAGE_LABEL", "...", 20); info.damage_label->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); info.heat_bar = new GuiProgressbar(info.layout, id + "_HEAT", 0.0, 1.0, 0.0); info.heat_bar->setSize(100, GuiElement::GuiSizeMax); info.heat_arrow = new GuiArrow(info.heat_bar, id + "_HEAT_ARROW", 0); info.heat_arrow->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); info.heat_icon = new GuiImage(info.heat_bar, "", "gui/icons/status_overheat"); info.heat_icon->setColor(colorConfig.overlay_overheating)->setPosition(0, 0, ACenter)->setSize(GuiElement::GuiSizeMatchHeight, GuiElement::GuiSizeMax); info.power_bar = new GuiProgressbar(info.layout, id + "_POWER", 0.0, 3.0, 0.0); info.power_bar->setColor(sf::Color(192, 192, 32, 128))->setSize(100, GuiElement::GuiSizeMax); info.coolant_bar = new GuiProgressbar(info.layout, id + "_COOLANT", 0.0, 10.0, 0.0); info.coolant_bar->setColor(sf::Color(32, 128, 128, 128))->setSize(100, GuiElement::GuiSizeMax); info.layout->moveToBack(); system_rows.push_back(info); } GuiAutoLayout* icon_layout = new GuiAutoLayout(system_row_layouts, "", GuiAutoLayout::LayoutHorizontalLeftToRight); icon_layout->setSize(GuiElement::GuiSizeMax, 48); (new GuiElement(icon_layout, "FILLER"))->setSize(300, GuiElement::GuiSizeMax); (new GuiImage(icon_layout, "SYSTEM_HEALTH_ICON", "gui/icons/system_health"))->setSize(150, GuiElement::GuiSizeMax); (new GuiImage(icon_layout, "HEAT_ICON", "gui/icons/status_overheat"))->setSize(100, GuiElement::GuiSizeMax); (new GuiImage(icon_layout, "POWER_ICON", "gui/icons/energy"))->setSize(100, GuiElement::GuiSizeMax); (new GuiImage(icon_layout, "COOLANT_ICON", "gui/icons/coolant"))->setSize(100, GuiElement::GuiSizeMax); system_rows[SYS_Reactor].button->setIcon("gui/icons/system_reactor"); system_rows[SYS_BeamWeapons].button->setIcon("gui/icons/system_beam"); system_rows[SYS_MissileSystem].button->setIcon("gui/icons/system_missile"); system_rows[SYS_Maneuver].button->setIcon("gui/icons/system_maneuver"); system_rows[SYS_Impulse].button->setIcon("gui/icons/system_impulse"); system_rows[SYS_Warp].button->setIcon("gui/icons/system_warpdrive"); system_rows[SYS_JumpDrive].button->setIcon("gui/icons/system_jumpdrive"); system_rows[SYS_FrontShield].button->setIcon("gui/icons/shields-fore"); system_rows[SYS_RearShield].button->setIcon("gui/icons/shields-aft"); system_effects_container = new GuiAutoLayout(system_config_container, "", GuiAutoLayout::LayoutVerticalBottomToTop); system_effects_container->setPosition(0, -400, ABottomRight)->setSize(270, 400); GuiPanel* box = new GuiPanel(system_config_container, "POWER_COOLANT_BOX"); box->setPosition(0, 0, ABottomRight)->setSize(270, 400); power_label = new GuiLabel(box, "POWER_LABEL", "Power", 30); power_label->setVertical()->setAlignment(ACenterLeft)->setPosition(20, 20, ATopLeft)->setSize(30, 360); coolant_label = new GuiLabel(box, "COOLANT_LABEL", "Coolant", 30); coolant_label->setVertical()->setAlignment(ACenterLeft)->setPosition(110, 20, ATopLeft)->setSize(30, 360); power_slider = new GuiSlider(box, "POWER_SLIDER", 3.0, 0.0, 1.0, [this](float value) { if (my_spaceship && selected_system != SYS_None) my_spaceship->commandSetSystemPowerRequest(selected_system, value); }); power_slider->setPosition(50, 20, ATopLeft)->setSize(60, 360); for(float snap_point = 0.0; snap_point <= 3.0; snap_point += 0.5) power_slider->addSnapValue(snap_point, snap_point == 1.0 ? 0.1 : 0.01); power_slider->disable(); coolant_slider = new GuiSlider(box, "COOLANT_SLIDER", 10.0, 0.0, 0.0, [this](float value) { if (my_spaceship && selected_system != SYS_None) my_spaceship->commandSetSystemCoolantRequest(selected_system, value); }); coolant_slider->setPosition(140, 20, ATopLeft)->setSize(60, 360); for(float snap_point = 0.0; snap_point <= 10.0; snap_point += 2.5) coolant_slider->addSnapValue(snap_point, 0.1); coolant_slider->disable(); (new GuiShipInternalView(system_row_layouts, "SHIP_INTERNAL_VIEW", 48.0f))->setShip(my_spaceship)->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); (new GuiCustomShipFunctions(this, crew_position, ""))->setPosition(-20, 120, ATopRight)->setSize(250, GuiElement::GuiSizeMax); previous_energy_level = 0.0; average_energy_delta = 0.0; previous_energy_measurement = 0.0; }
void EngineeringScreen::onDraw(sf::RenderTarget& window) { if (my_spaceship) { //Update the energy usage. if (previous_energy_measurement == 0.0) { previous_energy_level = my_spaceship->energy_level; previous_energy_measurement = engine->getElapsedTime(); }else{ if (previous_energy_measurement != engine->getElapsedTime()) { float delta_t = engine->getElapsedTime() - previous_energy_measurement; float delta_e = my_spaceship->energy_level - previous_energy_level; float delta_e_per_second = delta_e / delta_t; average_energy_delta = average_energy_delta * 0.99 + delta_e_per_second * 0.01; previous_energy_level = my_spaceship->energy_level; previous_energy_measurement = engine->getElapsedTime(); } } energy_display->setValue(string(int(my_spaceship->energy_level)) + " (" + string(int(average_energy_delta * 60.0f)) + "/m)"); if (my_spaceship->energy_level < 100) energy_display->setColor(sf::Color::Red); else energy_display->setColor(sf::Color::White); hull_display->setValue(string(int(100 * my_spaceship->hull_strength / my_spaceship->hull_max)) + "%"); if (my_spaceship->hull_strength < my_spaceship->hull_max / 4.0f) hull_display->setColor(sf::Color::Red); else hull_display->setColor(sf::Color::White); front_shield_display->setValue(string(my_spaceship->getShieldPercentage(0)) + "%"); rear_shield_display->setValue(string(my_spaceship->getShieldPercentage(1)) + "%"); for(int n=0; n<SYS_COUNT; n++) { SystemRow info = system_rows[n]; info.layout->setVisible(my_spaceship->hasSystem(ESystem(n))); float health = my_spaceship->systems[n].health; if (health < 0.0) info.damage_bar->setValue(-health)->setColor(sf::Color(128, 32, 32, 192)); else info.damage_bar->setValue(health)->setColor(sf::Color(64, 128 * health, 64 * health, 192)); info.damage_label->setText(string(int(health * 100)) + "%"); float heat = my_spaceship->systems[n].heat_level; info.heat_bar->setValue(heat)->setColor(sf::Color(128, 32 + 96 * (1.0 - heat), 32, 192)); float heating_diff = my_spaceship->systems[n].getHeatingDelta(); if (heating_diff > 0) info.heat_arrow->setAngle(90); else info.heat_arrow->setAngle(-90); info.heat_arrow->setVisible(heat > 0); info.heat_arrow->setColor(sf::Color(255, 255, 255, std::min(255, int(255 * fabs(heating_diff))))); if (heat > 0.9 && fmod(engine->getElapsedTime(), 0.5) < 0.25) info.heat_icon->show(); else info.heat_icon->hide(); info.power_bar->setValue(my_spaceship->systems[n].power_level); info.coolant_bar->setValue(my_spaceship->systems[n].coolant_level); } if (selected_system != SYS_None) { ShipSystem& system = my_spaceship->systems[selected_system]; power_label->setText("Power: " + string(int(system.power_level * 100)) + "%/" + string(int(system.power_request * 100)) + "%"); coolant_label->setText("Coolant: " + string(int(system.coolant_level / PlayerSpaceship::max_coolant * 100)) + "%/" + string(int(system.coolant_request / PlayerSpaceship::max_coolant * 100)) + "%"); coolant_slider->setEnable(!my_spaceship->auto_coolant_enabled); system_effects_index = 0; float effectiveness = my_spaceship->getSystemEffectiveness(selected_system); switch(selected_system) { case SYS_Reactor: if (effectiveness > 1.0f) effectiveness = (1.0f + effectiveness) / 2.0f; addSystemEffect("Energy production", string(effectiveness * -PlayerSpaceship::system_power_user_factor[SYS_Reactor] * 60.0, 1) + "/m"); break; case SYS_BeamWeapons: addSystemEffect("Firing rate", string(int(effectiveness * 100)) + "%"); // If the ship has a turret, also note that the rotation rate // is affected. for(int n = 0; n < max_beam_weapons; n++) { if (my_spaceship->beam_weapons[n].getTurretArc() > 0) { addSystemEffect("Turret rotation rate", string(int(effectiveness * 100)) + "%"); break; } } break; case SYS_MissileSystem: addSystemEffect("Reload rate", string(int(effectiveness * 100)) + "%"); break; case SYS_Maneuver: addSystemEffect("Turning speed", string(int(effectiveness * 100)) + "%"); if (my_spaceship->combat_maneuver_boost_speed > 0.0 || my_spaceship->combat_maneuver_strafe_speed) addSystemEffect("Combat recharge rate", string(int(((my_spaceship->getSystemEffectiveness(SYS_Maneuver) + my_spaceship->getSystemEffectiveness(SYS_Impulse)) / 2.0) * 100)) + "%"); break; case SYS_Impulse: addSystemEffect("Impulse speed", string(int(effectiveness * 100)) + "%"); if (my_spaceship->combat_maneuver_boost_speed > 0.0 || my_spaceship->combat_maneuver_strafe_speed) addSystemEffect("Combat recharge rate", string(int(((my_spaceship->getSystemEffectiveness(SYS_Maneuver) + my_spaceship->getSystemEffectiveness(SYS_Impulse)) / 2.0) * 100)) + "%"); break; case SYS_Warp: addSystemEffect("Warp drive speed", string(int(effectiveness * 100)) + "%"); break; case SYS_JumpDrive: addSystemEffect("Jump drive recharge rate", string(int(my_spaceship->getJumpDriveRechargeRate() * 100)) + "%"); addSystemEffect("Jump drive jump speed", string(int(effectiveness * 100)) + "%"); break; case SYS_FrontShield: if (gameGlobalInfo->use_beam_shield_frequencies) addSystemEffect("Calibration speed", string(int((my_spaceship->getSystemEffectiveness(SYS_FrontShield) + my_spaceship->getSystemEffectiveness(SYS_RearShield)) / 2.0 * 100)) + "%"); addSystemEffect("Charge rate", string(int(effectiveness * 100)) + "%"); { DamageInfo di; di.type = DT_Kinetic; float damage_negate = 1.0f - my_spaceship->getShieldDamageFactor(di, 0); if (damage_negate < 0.0) addSystemEffect("Extra damage", string(int(-damage_negate * 100)) + "%"); else addSystemEffect("Damage negate", string(int(damage_negate * 100)) + "%"); } break; case SYS_RearShield: if (gameGlobalInfo->use_beam_shield_frequencies) addSystemEffect("Calibration speed", string(int((my_spaceship->getSystemEffectiveness(SYS_FrontShield) + my_spaceship->getSystemEffectiveness(SYS_RearShield)) / 2.0 * 100)) + "%"); addSystemEffect("Charge rate", string(int(effectiveness * 100)) + "%"); { DamageInfo di; di.type = DT_Kinetic; float damage_negate = 1.0f - my_spaceship->getShieldDamageFactor(di, my_spaceship->shield_count); if (damage_negate < 0.0) addSystemEffect("Extra damage", string(int(-damage_negate * 100)) + "%"); else addSystemEffect("Damage negate", string(int(damage_negate * 100)) + "%"); } break; default: break; } for(unsigned int idx=system_effects_index; idx<system_effects.size(); idx++) system_effects[idx]->hide(); } } GuiOverlay::onDraw(window); }
ScienceScreen::ScienceScreen(GuiContainer* owner) : GuiOverlay(owner, "SCIENCE_SCREEN", colorConfig.background) { targets.setAllowWaypointSelection(); (new GuiOverlay(this, "", sf::Color::White))->setTextureCenter("gui/BackgroundGradient"); (new GuiOverlay(this, "", sf::Color::White))->setTextureTiled("gui/BackgroundCrosses"); radar_view = new GuiElement(this, "RADAR_VIEW"); radar_view->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); radar = new GuiRadarView(radar_view, "SCIENCE_RADAR", gameGlobalInfo->long_range_radar_range, &targets); radar->setPosition(20, 0, ACenterLeft)->setSize(GuiElement::GuiSizeMatchHeight, GuiElement::GuiSizeMax); radar->setRangeIndicatorStepSize(5000.0)->longRange()->enableWaypoints()->enableCallsigns()->enableHeadingIndicators()->setStyle(GuiRadarView::Circular)->setFogOfWarStyle(GuiRadarView::NebulaFogOfWar); radar->setCallbacks( [this](sf::Vector2f position) { if (!my_spaceship || my_spaceship->scanning_delay > 0.0) return; targets.setToClosestTo(position, 1000, TargetsContainer::Selectable); }, nullptr, nullptr ); raw_scanner_data_overlay = new RawScannerDataRadarOverlay(radar, "", gameGlobalInfo->long_range_radar_range); raw_scanner_data_overlay->setSize(GuiElement::GuiSizeMatchHeight, GuiElement::GuiSizeMax); GuiAutoLayout* sidebar = new GuiAutoLayout(radar_view, "SIDE_BAR", GuiAutoLayout::LayoutVerticalTopToBottom); sidebar->setPosition(-20, 50, ATopRight)->setSize(250, GuiElement::GuiSizeMax); (new GuiScanTargetButton(sidebar, "SCAN_BUTTON", &targets))->setSize(GuiElement::GuiSizeMax, 50); info_callsign = new GuiKeyValueDisplay(sidebar, "SCIENCE_CALLSIGN", 0.4, "Callsign", ""); info_callsign->setSize(GuiElement::GuiSizeMax, 30); info_distance = new GuiKeyValueDisplay(sidebar, "SCIENCE_DISTANCE", 0.4, "Distance", ""); info_distance->setSize(GuiElement::GuiSizeMax, 30); info_heading = new GuiKeyValueDisplay(sidebar, "SCIENCE_DISTANCE", 0.4, "Heading", ""); info_heading->setSize(GuiElement::GuiSizeMax, 30); info_relspeed = new GuiKeyValueDisplay(sidebar, "SCIENCE_REL_SPEED", 0.4, "Rel.Speed", ""); info_relspeed->setSize(GuiElement::GuiSizeMax, 30); info_faction = new GuiKeyValueDisplay(sidebar, "SCIENCE_FACTION", 0.4, "Faction", ""); info_faction->setSize(GuiElement::GuiSizeMax, 30); info_type = new GuiKeyValueDisplay(sidebar, "SCIENCE_TYPE", 0.4, "Type", ""); info_type->setSize(GuiElement::GuiSizeMax, 30); info_shields = new GuiKeyValueDisplay(sidebar, "SCIENCE_SHIELDS", 0.4, "Shields", ""); info_shields->setSize(GuiElement::GuiSizeMax, 30); info_shield_frequency = new GuiFrequencyCurve(sidebar, "SCIENCE_SHIELD_FREQUENCY", false, true); info_shield_frequency->setSize(GuiElement::GuiSizeMax, 100); info_beam_frequency = new GuiFrequencyCurve(sidebar, "SCIENCE_SHIELD_FREQUENCY", true, false); info_beam_frequency->setSize(GuiElement::GuiSizeMax, 100); probe_view_button = new GuiButton(radar_view, "LINK_TO_SCIENCE", "Probe View", [this](){ P<ScanProbe> probe; if (game_server) probe = game_server->getObjectById(my_spaceship->linked_object); else probe = game_client->getObjectById(my_spaceship->linked_object); if(probe && !my_spaceship->science_link) { sf::Vector2f probe_position = probe->getPosition(); my_spaceship->science_link = true; radar->setAutoCentering(false); radar->setViewPosition(probe_position); radar->setDistance(5000); radar->setFogOfWarStyle(GuiRadarView::NoFogOfWar); raw_scanner_data_overlay->hide(); probe_view_button->setText("Back to ship"); }else if(my_spaceship->science_link) { my_spaceship->science_link = false; radar->setAutoCentering(true); radar->setDistance(gameGlobalInfo->long_range_radar_range); raw_scanner_data_overlay->show(); probe_view_button->setText("Probe View"); radar->setFogOfWarStyle(GuiRadarView::NebulaFogOfWar); } }); probe_view_button->setPosition(-20, -70, ABottomRight)->setSize(250, 50)->disable(); (new GuiSelector(radar_view, "ZOOM_SELECT", [this](int index, string value) { float zoom_amount = 1 + 0.5 * index ; if(!my_spaceship->science_link) radar->setDistance(gameGlobalInfo->long_range_radar_range / zoom_amount); }))->setOptions({"Zoom: 1x", "Zoom: 1.5x", "Zoom: 2x", "Zoom: 2.5x", "Zoom: 3x"})->setSelectionIndex(0)->setPosition(-20, -20, ABottomRight)->setSize(250, 50); if (!gameGlobalInfo->use_beam_shield_frequencies) { info_shield_frequency->hide(); info_beam_frequency->hide(); } for(int n=0; n<SYS_COUNT; n++) { info_system[n] = new GuiKeyValueDisplay(sidebar, "SCIENCE_SYSTEM_" + string(n), 0.75, getSystemName(ESystem(n)), "-"); info_system[n]->setSize(GuiElement::GuiSizeMax, 30); info_system[n]->hide(); } info_description = new GuiScrollText(sidebar, "SCIENCE_DESC", ""); info_description->setTextSize(20)->hide()->setSize(GuiElement::GuiSizeMax, 400); database_view = new DatabaseViewComponent(this); database_view->hide()->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax); (new GuiListbox(this, "VIEW_SELECTION", [this](int index, string value) { radar_view->setVisible(index == 0); database_view->setVisible(index == 1); }))->setOptions({"Radar", "Database"})->setSelectionIndex(0)->setPosition(20, -20, ABottomLeft)->setSize(200, 100); new GuiScanningDialog(this, "SCANNING_DIALOG"); }