diff --git a/src/gui/gui2_advancedscrolltext.cpp b/src/gui/gui2_advancedscrolltext.cpp index f8fbee95ad..71817df768 100644 --- a/src/gui/gui2_advancedscrolltext.cpp +++ b/src/gui/gui2_advancedscrolltext.cpp @@ -7,12 +7,13 @@ GuiAdvancedScrollText::GuiAdvancedScrollText(GuiContainer* owner, string id) scrollbar->setPosition(0, 0, sp::Alignment::TopRight)->setSize(50, GuiElement::GuiSizeMax); } -GuiAdvancedScrollText* GuiAdvancedScrollText::addEntry(string prefix, string text, glm::u8vec4 color) +GuiAdvancedScrollText* GuiAdvancedScrollText::addEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq) { entries.emplace_back(); entries.back().prefix = prefix; entries.back().text = text; entries.back().color = color; + entries.back().seq = seq; return this; } @@ -28,6 +29,13 @@ string GuiAdvancedScrollText::getEntryText(int index) const return entries[index].text; } +unsigned int GuiAdvancedScrollText::getEntrySeq(unsigned int index) const +{ + if (index >= getEntryCount()) + return 0; + return entries[index].seq; +} + GuiAdvancedScrollText* GuiAdvancedScrollText::removeEntry(int index) { if (index < 0 || index > int(getEntryCount())) diff --git a/src/gui/gui2_advancedscrolltext.h b/src/gui/gui2_advancedscrolltext.h index 58bf66c383..e3251f3e43 100644 --- a/src/gui/gui2_advancedscrolltext.h +++ b/src/gui/gui2_advancedscrolltext.h @@ -13,6 +13,7 @@ class GuiAdvancedScrollText : public GuiElement string prefix; string text; glm::u8vec4 color; + unsigned int seq; }; std::vector entries; @@ -25,11 +26,12 @@ class GuiAdvancedScrollText : public GuiElement GuiAdvancedScrollText* enableAutoScrollDown() { auto_scroll_down = true; return this; } GuiAdvancedScrollText* disableAutoScrollDown() { auto_scroll_down = false; return this; } - GuiAdvancedScrollText* addEntry(string prefix, string text, glm::u8vec4 color); + GuiAdvancedScrollText* addEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq); GuiAdvancedScrollText* setTextSize(float text_size) { this->text_size = text_size; return this; } unsigned int getEntryCount() const; string getEntryText(int index) const; + unsigned int getEntrySeq(unsigned int index) const; GuiAdvancedScrollText* removeEntry(int index); GuiAdvancedScrollText* clearEntries(); diff --git a/src/screenComponents/shipsLogControl.cpp b/src/screenComponents/shipsLogControl.cpp index 963d82b210..4e0dff9a1e 100644 --- a/src/screenComponents/shipsLogControl.cpp +++ b/src/screenComponents/shipsLogControl.cpp @@ -39,12 +39,12 @@ void ShipsLog::onDraw(sp::RenderTarget& renderer) log_text->removeEntry(0); } - if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntryText(0) != logs[0].text) + if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntrySeq(0) != logs[0].seq) { bool updated = false; for(unsigned int n=1; ngetEntryCount(); n++) { - if (log_text->getEntryText(n) == logs[0].text) + if (log_text->getEntrySeq(n) == logs[0].seq) { for(unsigned int m=0; mremoveEntry(0); @@ -59,7 +59,7 @@ void ShipsLog::onDraw(sp::RenderTarget& renderer) while(log_text->getEntryCount() < logs.size()) { int n = log_text->getEntryCount(); - log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color); + log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color, logs[n].seq); } }else{ log_text->setMargins(15, 12, 15, 0); @@ -85,7 +85,7 @@ void ShipsLog::onDraw(sp::RenderTarget& renderer) log_text->clearEntries(); } if (log_text->getEntryCount() == 0 && logs.size() > 0) - log_text->addEntry("LOG : ", logs.back().text, logs.back().color); + log_text->addEntry("LOG : ", logs.back().text, logs.back().color, logs.back().seq); // log_text->addEntry(logs.back().prefix, logs.back().text, logs.back().color); } } diff --git a/src/screens/extra/shipLogScreen.cpp b/src/screens/extra/shipLogScreen.cpp index 274002b9f2..909e272802 100644 --- a/src/screens/extra/shipLogScreen.cpp +++ b/src/screens/extra/shipLogScreen.cpp @@ -39,12 +39,12 @@ void ShipLogScreen::onDraw(sp::RenderTarget& renderer) log_text->removeEntry(0); } - if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntryText(0) != logs[0].text) + if (log_text->getEntryCount() > 0 && logs.size() > 0 && log_text->getEntrySeq(0) != logs[0].seq) { bool updated = false; for(unsigned int n=1; ngetEntryCount(); n++) { - if (log_text->getEntryText(n) == logs[0].text) + if (log_text->getEntrySeq(n) == logs[0].seq) { for(unsigned int m=0; mremoveEntry(0); @@ -59,7 +59,7 @@ void ShipLogScreen::onDraw(sp::RenderTarget& renderer) while(log_text->getEntryCount() < logs.size()) { int n = log_text->getEntryCount(); - log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color); + log_text->addEntry(logs[n].prefix, logs[n].text, logs[n].color, logs[n].seq); } } } diff --git a/src/spaceObjects/playerSpaceship.cpp b/src/spaceObjects/playerSpaceship.cpp index 4513ce148f..591d6b12b8 100644 --- a/src/spaceObjects/playerSpaceship.cpp +++ b/src/spaceObjects/playerSpaceship.cpp @@ -566,8 +566,8 @@ string alertLevelToLocaleString(EAlertLevel level) } // Configure ship's log packets. -static inline sp::io::DataBuffer& operator << (sp::io::DataBuffer& packet, const PlayerSpaceship::ShipLogEntry& e) { return packet << e.prefix << e.text << e.color.r << e.color.g << e.color.b << e.color.a << e.station; } -static inline sp::io::DataBuffer& operator >> (sp::io::DataBuffer& packet, PlayerSpaceship::ShipLogEntry& e) { packet >> e.prefix >> e.text >> e.color.r >> e.color.g >> e.color.b >> e.color.a >> e.station; return packet; } +static inline sp::io::DataBuffer& operator << (sp::io::DataBuffer& packet, const PlayerSpaceship::ShipLogEntry& e) { return packet << e.prefix << e.text << e.color.r << e.color.g << e.color.b << e.color.a << e.station << e.seq; } +static inline sp::io::DataBuffer& operator >> (sp::io::DataBuffer& packet, PlayerSpaceship::ShipLogEntry& e) { packet >> e.prefix >> e.text >> e.color.r >> e.color.g >> e.color.b >> e.color.a >> e.station; return packet >> e.seq; } REGISTER_MULTIPLAYER_CLASS(PlayerSpaceship, "PlayerSpaceship"); PlayerSpaceship::PlayerSpaceship() @@ -1435,7 +1435,7 @@ void PlayerSpaceship::addToSpecificShipLog(string message, glm::u8vec4 color, st if (ships_log_generic.size() > 100) ships_log_generic.erase(ships_log_generic.begin()); // Timestamp a log entry, color it, and add it to the end of the log. - ships_log_generic.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station); + ships_log_generic.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station, last_log_seq++); timer_log_generic = 6; } else if (station == "intern") @@ -1443,7 +1443,7 @@ void PlayerSpaceship::addToSpecificShipLog(string message, glm::u8vec4 color, st if (ships_log_intern.size() > 100) ships_log_intern.erase(ships_log_intern.begin()); // Timestamp a log entry, color it, and add it to the end of the log. - ships_log_intern.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station); + ships_log_intern.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station, last_log_seq++); timer_log_intern = 6; } else if (station == "docks") @@ -1451,7 +1451,7 @@ void PlayerSpaceship::addToSpecificShipLog(string message, glm::u8vec4 color, st if (ships_log_docks.size() > 100) ships_log_docks.erase(ships_log_docks.begin()); // Timestamp a log entry, color it, and add it to the end of the log. - ships_log_docks.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station); + ships_log_docks.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station, last_log_seq++); timer_log_docks = 6; } else if (station == "science") @@ -1459,7 +1459,7 @@ void PlayerSpaceship::addToSpecificShipLog(string message, glm::u8vec4 color, st if (ships_log_science.size() > 100) ships_log_science.erase(ships_log_science.begin()); // Timestamp a log entry, color it, and add it to the end of the log. - ships_log_science.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station); + ships_log_science.emplace_back(gameGlobalInfo->getMissionTime() + string(": "), message, color, station, last_log_seq++); timer_log_science = 6; } } diff --git a/src/spaceObjects/playerSpaceship.h b/src/spaceObjects/playerSpaceship.h index 90383b5983..f5d1bb5ede 100644 --- a/src/spaceObjects/playerSpaceship.h +++ b/src/spaceObjects/playerSpaceship.h @@ -81,8 +81,8 @@ class PlayerSpaceship : public SpaceShip string station; ShipLogEntry() {} - ShipLogEntry(string prefix, string text, glm::u8vec4 color, string station) - : prefix(prefix), text(text), color(color), station(station) {} + ShipLogEntry(string prefix, string text, glm::u8vec4 color, string station, unsigned int seq) + : prefix(prefix), text(text), color(color), station(station), seq(seq) {} bool operator!=(const ShipLogEntry& e) { return prefix != e.prefix || text != e.text || color != e.color || station != e.station; } }; @@ -140,6 +140,7 @@ class PlayerSpaceship : public SpaceShip float energy_shield_use_per_second = default_energy_shield_use_per_second; float energy_warp_per_second = default_energy_warp_per_second; + unsigned int last_log_seq = 0; public: ESystem auto_repairing_system; std::vector custom_functions;