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

🎮 Walkie-talkie label with forwardable commands info & clickable buttons #3063

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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/walkie_talkie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions source/main/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,30 @@ bool AppContext::SetUpRendering()
}
catch (Ogre::Exception&) {} // Logged by OGRE
}

}
catch (Ogre::Exception& e)
{
ErrorUtils::ShowError (_L("Startup error"), e.getFullDescription());
ErrorUtils::ShowError (_L("Startup error"), e.getDescription());
return false;
}

// Load renderer configuration
if (!m_ogre_root->restoreConfig())
try
{
const auto render_systems = App::GetAppContext()->GetOgreRoot()->getAvailableRenderers();
if (!render_systems.empty())
m_ogre_root->setRenderSystem(render_systems.front());
else
ErrorUtils::ShowError (_L("Startup error"), _L("No render system plugin available. Check your plugins.cfg"));
// Load renderer configuration
if (!m_ogre_root->restoreConfig())
{
const auto render_systems = App::GetAppContext()->GetOgreRoot()->getAvailableRenderers();
if (!render_systems.empty())
m_ogre_root->setRenderSystem(render_systems.front());
else
ErrorUtils::ShowError (_L("Startup error"), _L("No render system plugin available. Check your plugins.cfg"));
}
}
catch (Ogre::Exception& e)
{
ErrorUtils::ShowError (_L("Error restoring settings from 'ogre.cfg'"), e.getDescription());
return false;
}

const auto rs = m_ogre_root->getRenderSystemByName(App::app_rendersys_override->getStr());
Expand Down
1 change: 1 addition & 0 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ set(SOURCE_FILES
gui/panels/GUI_MultiplayerSelector.{h,cpp}
gui/panels/GUI_MultiplayerClientList.{h,cpp}
gui/panels/GUI_NodeBeamUtils.{h,cpp}
gui/panels/GUI_SceneLabels.{h,cpp}
gui/panels/GUI_SimActorStats.{h,cpp}
gui/panels/GUI_ScriptMonitor.{h,cpp}
gui/panels/GUI_SimPerfStats.{h,cpp}
Expand Down
27 changes: 25 additions & 2 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ void GameContext::UpdateSimInputEvents(float dt)
const Ogre::Vector3 position = App::GetGameContext()->GetPlayerCharacter()->getPosition();
ActorPtr nearest_actor = nullptr;
float min_squared_distance = std::numeric_limits<float>::max();
for (ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
for (const ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
{
float squared_distance = position.squaredDistance(actor->ar_nodes[0].AbsPosition);
if (squared_distance < min_squared_distance)
Expand All @@ -1093,15 +1093,38 @@ void GameContext::UpdateSimInputEvents(float dt)
nearest_actor->ar_import_commands &&
min_squared_distance < (nearest_actor->getMinCameraRadius()*nearest_actor->getMinCameraRadius()))
{
bool asleep = nearest_actor->ar_state == ActorState::LOCAL_SLEEPING;
// get commands
for (int i = 1; i <= MAX_COMMANDS; i++) // BEWARE: commandkeys are indexed 1-MAX_COMMANDS!
{
int eventID = EV_COMMANDS_01 + (i - 1);

nearest_actor->ar_command_key[i].playerInputValue = RoR::App::GetInputEngine()->getEventValue(eventID);
const float eventVal = RoR::App::GetInputEngine()->getEventValue(eventID);
if (asleep && (eventVal != nearest_actor->ar_command_key[i].playerInputValue))
{
// Wake up
nearest_actor->ar_state = ActorState::LOCAL_SIMULATED;
nearest_actor->ar_sleep_counter = 0.0f;
asleep = false;
}

nearest_actor->ar_command_key[i].playerInputValue = eventVal;
}
nearest_actor->ar_walkie_talkie = true;
App::GetGameContext()->GetPlayerCharacter()->cr_walkie_talkie = true;
}
else
{
if (nearest_actor)
nearest_actor->ar_walkie_talkie = false;
App::GetGameContext()->GetPlayerCharacter()->cr_walkie_talkie = false;
}
}
else
{
for (const ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
actor->ar_walkie_talkie = false;
}

// AI waypoint recording
if (App::GetGuiManager()->TopMenubar.ai_rec)
Expand Down
19 changes: 16 additions & 3 deletions source/main/gameplay/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Collisions.h"
#include "GameContext.h"
#include "GfxScene.h"
#include "GUIManager.h"
#include "InputEngine.h"
#include "MovableText.h"
#include "Network.h"
Expand Down Expand Up @@ -597,6 +598,7 @@ void RoR::GfxCharacter::BufferSimulationData()
xc_simbuf.simbuf_actor_coupling = xc_character->GetActorCoupling();
xc_simbuf.simbuf_anim_name = xc_character->GetAnimName();
xc_simbuf.simbuf_anim_time = xc_character->GetAnimTime();
xc_simbuf.simbuf_character_walkie_talkie = xc_character->cr_walkie_talkie;
}

void RoR::GfxCharacter::UpdateCharacterInScene()
Expand Down Expand Up @@ -686,11 +688,10 @@ void RoR::GfxCharacter::UpdateCharacterInScene()
as_cur->setTimePosition(xc_simbuf.simbuf_anim_time);
}

// Multiplayer label
#ifdef USE_SOCKETW
if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED && !xc_simbuf.simbuf_actor_coupling)
{
// From 'updateCharacterNetworkColor()'
// Update network color
const String materialName = "tracks/" + xc_instance_name;

MaterialPtr mat = MaterialManager::getSingleton().getByName(materialName);
Expand All @@ -702,15 +703,27 @@ void RoR::GfxCharacter::UpdateCharacterInScene()
state->setColourOperationEx(LBX_BLEND_CURRENT_ALPHA, LBS_MANUAL, LBS_CURRENT, color);
}

// Draw multiplayer label
if ((!xc_simbuf.simbuf_is_remote && !App::mp_hide_own_net_label->getBool()) ||
(xc_simbuf.simbuf_is_remote && !App::mp_hide_net_labels->getBool()))
{
float camDist = (xc_scenenode->getPosition() - App::GetCameraManager()->GetCameraNode()->getPosition()).length();
const float camDist = (xc_scenenode->getPosition() - App::GetCameraManager()->GetCameraNode()->getPosition()).length();
Ogre::Vector3 scene_pos = xc_scenenode->getPosition();
scene_pos.y += (1.9f + camDist / 100.0f);

App::GetGfxScene()->DrawNetLabel(scene_pos, camDist, xc_simbuf.simbuf_net_username, xc_simbuf.simbuf_color_number);
}
}
#endif // USE_SOCKETW

// Walkie talkie label (forwardcommands / importcommands)
if (xc_simbuf.simbuf_character_walkie_talkie)
{
const float camDist = (xc_scenenode->getPosition() - App::GetCameraManager()->GetCameraNode()->getPosition()).length();
Ogre::Vector3 scene_pos = xc_scenenode->getPosition();
scene_pos.y += (1.9f + camDist / 100.0f);

App::GetGuiManager()->SceneLabels.DrawInstance(scene_pos, camDist, nullptr);

}
}
3 changes: 3 additions & 0 deletions source/main/gameplay/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Character
void SetActorCoupling(bool enabled, ActorPtr actor);
GfxCharacter* SetupGfx();

bool cr_walkie_talkie = false;

private:

void ReportError(const char* detail);
Expand Down Expand Up @@ -108,6 +110,7 @@ struct GfxCharacter
ActorPtr simbuf_actor_coupling;
std::string simbuf_anim_name;
float simbuf_anim_time; // Intentionally left empty = forces initial update.
bool simbuf_character_walkie_talkie = false;
};

~GfxCharacter();
Expand Down
44 changes: 33 additions & 11 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

#include <Ogre.h>

#include <algorithm>

using namespace RoR;

RoR::GfxActor::GfxActor(ActorPtr actor, ActorSpawner* spawner, std::string ogre_resource_group,
Expand Down Expand Up @@ -1793,6 +1795,7 @@ void RoR::GfxActor::UpdateSimDataBuffer()

m_simbuf.simbuf_speedo_highest_kph = m_actor->ar_speedo_max_kph;
m_simbuf.simbuf_speedo_use_engine_max_rpm = m_actor->ar_gui_use_engine_max_rpm;
m_simbuf.simbuf_wakie_talkie = m_actor->ar_walkie_talkie;

// Linked Actors
m_linked_gfx_actors.clear();
Expand Down Expand Up @@ -1935,21 +1938,35 @@ void RoR::GfxActor::UpdateAeroEngines()

void RoR::GfxActor::UpdateNetLabels(float dt)
{
const bool is_remote =
m_simbuf.simbuf_actor_state == ActorState::NETWORKED_OK ||
m_simbuf.simbuf_actor_state == ActorState::NETWORKED_HIDDEN;
const bool is_remote =
m_simbuf.simbuf_actor_state == ActorState::NETWORKED_OK ||
m_simbuf.simbuf_actor_state == ActorState::NETWORKED_HIDDEN;

if (App::mp_hide_net_labels->getBool() || (!is_remote && App::mp_hide_own_net_label->getBool()) || App::mp_state->getEnum<MpState>() != MpState::CONNECTED)
{
return;
}
if (App::mp_hide_net_labels->getBool() || (!is_remote && App::mp_hide_own_net_label->getBool()) || App::mp_state->getEnum<MpState>() != MpState::CONNECTED)
{
return;
}

float vlen = m_simbuf.simbuf_pos.distance(App::GetCameraManager()->GetCameraNode()->getPosition());

float y_offset = (m_simbuf.simbuf_aabb.getMaximum().y - m_simbuf.simbuf_pos.y) + (vlen / 100.0);
Ogre::Vector3 scene_pos = m_simbuf.simbuf_pos + Ogre::Vector3::UNIT_Y * y_offset;

float vlen = m_simbuf.simbuf_pos.distance(App::GetCameraManager()->GetCameraNode()->getPosition());
App::GetGfxScene()->DrawNetLabel(scene_pos, vlen, m_simbuf.simbuf_net_username, m_simbuf.simbuf_net_colornum);

float y_offset = (m_simbuf.simbuf_aabb.getMaximum().y - m_simbuf.simbuf_pos.y) + (vlen / 100.0);
Ogre::Vector3 scene_pos = m_simbuf.simbuf_pos + Ogre::Vector3::UNIT_Y * y_offset;
}

void RoR::GfxActor::UpdateWalkieTalkieLabels(float dt)
{
if (!m_simbuf.simbuf_wakie_talkie)
return;

float vlen = m_simbuf.simbuf_pos.distance(App::GetCameraManager()->GetCameraNode()->getPosition());

App::GetGfxScene()->DrawNetLabel(scene_pos, vlen, m_simbuf.simbuf_net_username, m_simbuf.simbuf_net_colornum);
float y_offset = (m_simbuf.simbuf_aabb.getMaximum().y - m_simbuf.simbuf_pos.y) + (vlen / 100.0);
Ogre::Vector3 scene_pos = m_simbuf.simbuf_pos + Ogre::Vector3::UNIT_Y * y_offset;

App::GetGuiManager()->SceneLabels.DrawInstance(scene_pos, vlen, m_actor);

}

Expand Down Expand Up @@ -3206,3 +3223,8 @@ void RoR::GfxActor::RemoveBeam(int beam_index)
itor++;
}
}

int RoR::GfxActor::getNumBeacons() const
{
return std::count_if(m_props.begin(), m_props.end(), [](const Prop& p) { return p.pp_beacon_type != 0; });
}
2 changes: 2 additions & 0 deletions source/main/gfx/GfxActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class GfxActor
void UpdateCParticles();
void UpdateAeroEngines();
void UpdateNetLabels(float dt);
void UpdateWalkieTalkieLabels(float dt);
void UpdateFlares(float dt_sec, bool is_player);
void UpdateRenderdashRTT ();

Expand Down Expand Up @@ -149,6 +150,7 @@ class GfxActor
void CalcPropAnimation(const int flag_state, float& cstate, int& div, float timer,
const float lower_limit, const float upper_limit, const float option3);
std::vector<Prop>& getProps() { return m_props; }
int getNumBeacons() const;
bool hasCamera() { return m_videocameras.size() > 0; }

private:
Expand Down
25 changes: 3 additions & 22 deletions source/main/gfx/GfxScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ void GfxScene::UpdateScene(float dt_sec)
App::GetOverlayWrapper()->UpdatePressureOverlay(m_simbuf.simbuf_player_actor->GetGfxActor());
}

// HUD - network labels (always update)
// HUD - labels (always update)
for (GfxActor* gfx_actor: m_all_gfx_actors)
{
gfx_actor->UpdateNetLabels(m_simbuf.simbuf_sim_speed * dt_sec);
gfx_actor->UpdateWalkieTalkieLabels(m_simbuf.simbuf_sim_speed * dt_sec);
}

// Player avatars
Expand Down Expand Up @@ -340,26 +341,6 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string
{
#if USE_SOCKETW

// this ensures that the nickname is always in a readable size
float font_size = std::max(0.6, cam_dist / 40.0);
std::string caption;
if (cam_dist > 1000) // 1000 ... vlen
{
caption =
nick + " (" + TOSTRING((float)(ceil(cam_dist / 100) / 10.0) ) + " km)";
}
else if (cam_dist > 20) // 20 ... vlen ... 1000
{
caption =
nick + " (" + TOSTRING((int)cam_dist) + " m)";
}
else // 0 ... vlen ... 20
{
caption = nick;
}

// draw with DearIMGUI

ImVec2 screen_size = ImGui::GetIO().DisplaySize;
World2ScreenConverter world2screen(
App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y));
Expand All @@ -372,6 +353,7 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string
// Align position to whole pixels, to minimize jitter.
ImVec2 pos((int)pos_xyz.x+0.5, (int)pos_xyz.y+0.5);

std::string caption = FormatLabelWithDistance(nick, cam_dist);
ImVec2 text_size = ImGui::CalcTextSize(caption.c_str());
GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme();

Expand All @@ -396,4 +378,3 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string

#endif // USE_SOCKETW
}

1 change: 1 addition & 0 deletions source/main/gfx/SimBuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ struct ActorSB
// GUI
float simbuf_speedo_highest_kph = 0;
bool simbuf_speedo_use_engine_max_rpm = false;
bool simbuf_wakie_talkie = false;
};

struct GameContextSB
Expand Down
11 changes: 10 additions & 1 deletion source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ void GUIManager::ShutdownMyGUI()
}
}

void GUIManager::ApplyGuiCaptureKeyboard()
void GUIManager::ApplyQueuedGuiRequests()
{
m_gui_kb_capture_requested = m_gui_kb_capture_queued;
m_staticmenus_blocking_requested = m_staticmenus_blocking_queued;
};

bool GUIManager::AreStaticMenusAllowed() //!< i.e. top menubar / vehicle UI buttons
{
return (App::GetCameraManager()->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_FREE &&
!m_staticmenus_blocking_requested && // For ad-hoc windows like walkie-talkie label
!this->ConsoleWindow.IsHovered() &&
!this->GameControls.IsHovered() &&
!this->FrictionSettings.IsHovered() &&
Expand All @@ -129,6 +131,7 @@ void GUIManager::DrawSimulationGui(float dt)
if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
{
this->TopMenubar.Update();
this->SceneLabels.Update();

if (this->GameMainMenu.IsVisible())
{
Expand Down Expand Up @@ -317,6 +320,7 @@ void GUIManager::NewImGuiFrame(float dt)

// Reset state
m_gui_kb_capture_queued = false;
m_staticmenus_blocking_queued = false;
}

void GUIManager::SetupImGui()
Expand Down Expand Up @@ -450,6 +454,11 @@ void GUIManager::RequestGuiCaptureKeyboard(bool val)
m_gui_kb_capture_queued = m_gui_kb_capture_queued || val;
}

void GUIManager::RequestStaticMenusBlocking(bool val)
{
m_staticmenus_blocking_queued = m_staticmenus_blocking_queued || val;
}

void GUIManager::WakeUpGUI()
{
m_last_mousemove_time.reset();
Expand Down
Loading