Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added login UI #3175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 added resources/icons/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions source/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ CVar* mp_cyclethru_net_actors;

// New remote API
CVar* remote_query_url;
CVar* remote_login_token;
CVar* remote_refresh_token;
CVar* remote_user_auth_state;

// Diagnostic
CVar* diag_auto_spawner_report;
Expand Down Expand Up @@ -164,6 +167,7 @@ CVar* sys_user_dir;
CVar* sys_config_dir;
CVar* sys_cache_dir;
CVar* sys_thumbnails_dir;
CVar* sys_avatar_dir;
CVar* sys_logs_dir;
CVar* sys_resources_dir;
CVar* sys_profiler_dir;
Expand Down
26 changes: 26 additions & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define RGN_TEMP "Temp"
#define RGN_CACHE "Cache"
#define RGN_REPO "Repo"
#define RGN_AVATAR "Avatar"
#define RGN_CONFIG "Config"
#define RGN_CONTENT "Content"
#define RGN_SAVEGAMES "Savegames"
Expand Down Expand Up @@ -103,6 +104,19 @@ enum MsgType
MSG_NET_DISCONNECT_REQUESTED,
MSG_NET_USER_DISCONNECT,
MSG_NET_RECV_ERROR,
MSG_NET_USERAUTH_SUCCESS, //!< Payload = GUI::UserAuthToken* (owner)
MSG_NET_USERAUTH_FAILURE,
MSG_NET_USERAUTH_LOGOUT_REQUESTED,
MSG_NET_USERAUTH_RV_REQUESTED,
MSG_NET_USERAUTH_RV_FAILURE,
MSG_NET_USERAUTH_RV_SUCCESS,
MSG_NET_USERAUTH_TFA_REQUESTED,
MSG_NET_USERAUTH_TFA_FAILURE,
MSG_NET_USERAUTH_TFA_TRIGGERED,
MSG_NET_USERPROFILE_REQUESTED,
MSG_NET_USERPROFILE_FINISHED,
MSG_NET_USERPROFILE_AVATAR_REQUESTED,
MSG_NET_USERPROFILE_AVATAR_FINISHED,
MSG_NET_REFRESH_SERVERLIST_SUCCESS, //!< Payload = GUI::MpServerInfoVec* (owner)
MSG_NET_REFRESH_SERVERLIST_FAILURE, //!< Payload = RoR::CurlFailInfo* (owner)
MSG_NET_REFRESH_REPOLIST_SUCCESS, //!< Payload = GUI::ResourcesCollection* (owner)
Expand Down Expand Up @@ -173,6 +187,14 @@ enum class MpState
CONNECTED,
};

enum class UserAuthState
{
UNAUTHENTICATED, //!< A state where the user is not verified or failed to verify. Initial state.
EXPIRED, //!< Transient state to indicate we're no longer verified.
AUTHENTICATED,
INVALID, //!< We can't be verified, and we shouldn't retry.
};

enum class SimState
{
OFF,
Expand Down Expand Up @@ -364,6 +386,9 @@ extern CVar* mp_cyclethru_net_actors; //!< Include remote actors when cycling th

// New remote API
extern CVar* remote_query_url;
extern CVar* remote_login_token;
extern CVar* remote_refresh_token;
extern CVar* remote_user_auth_state;

// Diagnostic
extern CVar* diag_auto_spawner_report;
Expand Down Expand Up @@ -401,6 +426,7 @@ extern CVar* sys_user_dir;
extern CVar* sys_config_dir;
extern CVar* sys_cache_dir;
extern CVar* sys_thumbnails_dir;
extern CVar* sys_avatar_dir;
extern CVar* sys_logs_dir;
extern CVar* sys_resources_dir;
extern CVar* sys_profiler_dir;
Expand Down
1 change: 1 addition & 0 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ set(SOURCE_FILES
gui/panels/GUI_ConsoleWindow.{h,cpp}
gui/panels/GUI_DirectionArrow.{h,cpp}
gui/panels/GUI_LoadingWindow.{h,cpp}
gui/panels/GUI_LoginBox.{h,cpp}
gui/panels/GUI_FlexbodyDebug.{h,cpp}
gui/panels/GUI_FrictionSettings.{h,cpp}
gui/panels/GUI_TopMenubar.{h,cpp}
Expand Down
3 changes: 2 additions & 1 deletion source/main/ForwardDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This source file is part of Rigs of Rods
Copyright 2005-2012 Pierre-Michel Ricordel
Copyright 2007-2012 Thomas Fischer
Copyright 2013-2020 Petr Ohlidal
Copyright 2013-2024 Petr Ohlidal

For more information, see http://www.rigsofrods.org/

Expand Down Expand Up @@ -227,6 +227,7 @@ namespace RoR
class SurveyMap;
class TopMenubar;
class VehicleButtons;
class LoginBox;
}
} // namespace RoR

Expand Down
4 changes: 4 additions & 0 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,10 @@ void GameContext::UpdateGlobalInputEvents()
{
App::GetGuiManager()->RepositorySelector.SetVisible(false);
}
else if (App::GetGuiManager()->LoginBox.IsVisible())
{
App::GetGuiManager()->LoginBox.SetVisible(false);
}
else
{
this->PushMessage(Message(MSG_APP_SHUTDOWN_REQUESTED));
Expand Down
5 changes: 5 additions & 0 deletions source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ void GUIManager::DrawMainMenuGui()
{
this->RepositorySelector.Draw();
}

if (this->LoginBox.IsVisible())
{
this->LoginBox.Draw();
}
}

void GUIManager::ShowMessageBox(const char* title, const char* text, bool allow_close, const char* btn1_text, const char* btn2_text)
Expand Down
2 changes: 2 additions & 0 deletions source/main/gui/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "GUI_TopMenubar.h"
#include "GUI_VehicleDescription.h"
#include "GUI_VehicleButtons.h"
#include "GUI_LoginBox.h"

// Deps
#include <Bites/OgreWindowEventUtilities.h>
Expand Down Expand Up @@ -126,6 +127,7 @@ class GUIManager
GUI::DirectionArrow DirectionArrow;
GUI::VehicleButtons VehicleButtons;
GUI::FlexbodyDebug FlexbodyDebug;
GUI::LoginBox LoginBox;
Ogre::Overlay* MenuWallpaper = nullptr;

// GUI manipulation
Expand Down
60 changes: 60 additions & 0 deletions source/main/gui/panels/GUI_GameMainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using namespace GUI;
void GameMainMenu::Draw()
{
this->DrawMenuPanel();
this->DrawProfileBox();
if (App::app_state->getEnum<AppState>() == AppState::MAIN_MENU)
{
this->DrawVersionBox();
Expand Down Expand Up @@ -224,6 +225,65 @@ void GameMainMenu::DrawMenuPanel()
m_kb_enter_index = -1;
}

void GameMainMenu::DrawProfileBox()
{
ImVec2 image_size = ImVec2(50, 50);
ImVec2 button_size = ImVec2(60, 30);
ImVec2 display_size = ImGui::GetIO().DisplaySize;

const float window_height = 15.0f;
const float margin = display_size.y / 15.0f;

ImGui::SetNextWindowPos(ImVec2(margin, margin));
ImGui::PushStyleColor(ImGuiCol_WindowBg, WINDOW_BG_COLOR);
ImGuiWindowFlags flags =
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar;
if (ImGui::Begin(_LC("MainMenu", "Profile box"), nullptr, flags))
{

if (App::remote_user_auth_state->getEnum<UserAuthState>() == UserAuthState::AUTHENTICATED)
{
const auto& user = App::GetGuiManager()->LoginBox.GetUserProfile();

if (!user.avatar)
{
ImGui::Image(
reinterpret_cast<ImTextureID>(FetchIcon("blank.png")->getHandle()),
image_size);
}
else if (user.avatar)
{
ImGui::Image(
reinterpret_cast<ImTextureID>(user.avatar->getHandle()),
image_size);
}

ImGui::SameLine();
ImGui::Text("Hello, %s", user.username.c_str());
if (ImGui::Button("Log out", button_size)) {
App::GetGameContext()->PushMessage(Message(MSG_NET_USERAUTH_LOGOUT_REQUESTED));
}
}
else
{
ImGui::SameLine();
if (ImGui::Button("Log in", button_size)) {
App::GetGuiManager()->LoginBox.SetVisible(true);
this->SetVisible(false);
}

ImGui::SameLine();
if (ImGui::Button("Regster", button_size)) {
// TODO open as a link
}
}

ImGui::End();
}
ImGui::PopStyleColor(1);
}

void GameMainMenu::DrawVersionBox()
{
const float margin = ImGui::GetIO().DisplaySize.y / 30.f;
Expand Down
1 change: 1 addition & 0 deletions source/main/gui/panels/GUI_GameMainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class GameMainMenu
void DrawMenuPanel();
void DrawVersionBox();
void DrawNoticeBox();
void DrawProfileBox();
bool HighlightButton(const std::string &text, ImVec2 btn_size, int index) const;
void HandleInputEvents();
bool m_is_visible = false;
Expand Down
Loading