Skip to content

Commit

Permalink
Add open link function
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed Sep 1, 2024
1 parent 1871ef1 commit 56c89b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/states_screens/online/online_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "network/socket_address.hpp"
#include "network/stk_host.hpp"
#include "network/stk_peer.hpp"
#include "online/link_helper.hpp"
#include "online/profile_manager.hpp"
#include "online/request_manager.hpp"
#include "states_screens/online/networking_lobby.hpp"
Expand Down Expand Up @@ -154,14 +155,18 @@ void OnlineScreen::loadList()
NewsManager::get()->prioritizeNewsAfterID(NewsManager::NTYPE_MAINMENU, last_shown_id);

m_news_list->clear();
m_news_links.clear();

while (news_count--)
{
int id = NewsManager::get()->getNextNewsID(NewsManager::NTYPE_MAINMENU);
std::string id_str = StringUtils::toString(id);
core::stringw str = NewsManager::get()->getCurrentNewsMessage(NewsManager::NTYPE_MAINMENU);
std::string date = NewsManager::get()->getCurrentNewsDate(NewsManager::NTYPE_MAINMENU);
int icon = NewsManager::get()->isCurrentNewsImportant(NewsManager::NTYPE_MAINMENU) ?
m_icon_news_headline : m_icon_news;

m_news_links[id_str] = NewsManager::get()->getCurrentNewsLink(NewsManager::NTYPE_MAINMENU);

if (id > UserConfigParams::m_news_list_shown_id)
icon = m_icon_red_dot;
Expand All @@ -178,7 +183,7 @@ void OnlineScreen::loadList()
std::vector<GUIEngine::ListWidget::ListCell> row;
row.push_back(GUIEngine::ListWidget::ListCell(str.c_str(), icon, 4, false));
row.push_back(GUIEngine::ListWidget::ListCell(date.c_str(), -1, 1, true));
m_news_list->addItem(StringUtils::toString(id).c_str(), row);
m_news_list->addItem(id_str.c_str(), row);
}

UserConfigParams::m_news_list_shown_id = last_shown_id;
Expand Down Expand Up @@ -241,6 +246,15 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name,
StateManager::get()->escapePressed();
return;
}
else if (name == "news_list")
{
std::string id = m_news_list->getSelectionInternalName();

if (!m_news_links[id].empty())
{
Online::LinkHelper::openURL(m_news_links[id]);
}
}
else if (name == "enable-splitscreen")
{
CheckBoxWidget* splitscreen = dynamic_cast<CheckBoxWidget*>(widget);
Expand Down
2 changes: 2 additions & 0 deletions src/states_screens/online/online_screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class OnlineScreen : public GUIEngine::Screen,
irr::gui::STKModifiedSpriteBank
*m_icon_bank;

std::unordered_map<std::string, std::string> m_news_links;

OnlineScreen();

public:
Expand Down

0 comments on commit 56c89b9

Please sign in to comment.