49 if ((mMapMode == SurveyMapMode::BIG &&
53 mMapMode = SurveyMapMode::NONE;
61 if (mMapMode == SurveyMapMode::SMALL)
65 setMapZoomRelative(+ImGui::GetIO().DeltaTime);
69 setMapZoomRelative(-ImGui::GetIO().DeltaTime);
73 if (mWindowMouseHovered)
75 setMapZoomRelative(ImGui::GetIO().MouseWheel*0.5f);
81 ImVec2 view_size(0, 0);
82 ImVec2 view_padding(8, 8);
83 if (mMapMode == SurveyMapMode::BIG)
86 view_size.y = (rw->getWidth() * 0.55f) -
89 if (!terrn_size.isZeroLength())
91 view_size.x = (view_size.y / terrn_size.z) * terrn_size.x;
95 view_size.x = view_size.y;
98 else if (mMapMode == SurveyMapMode::SMALL)
100 view_size.y = rw->getWidth() * 0.2f;
101 view_size.x = view_size.y;
105 ImGuiWindowFlags flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
106 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(WINDOW_PADDING, WINDOW_PADDING));
107 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, WINDOW_ROUNDING);
108 ImGui::SetNextWindowSize(ImVec2((view_size.x + view_padding.x), (view_size.y + view_padding.y)));
112 if (mMapMode == SurveyMapMode::BIG)
115 ImGui::SetNextWindowPosCenter();
117 else if (mMapMode == SurveyMapMode::SMALL)
119 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0,0,0,0));
120 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0,0,0,0));
122 float x = ImGui::GetIO().DisplaySize.x -
124 ImGui::SetNextWindowPos(ImVec2(
x, 100.f));
126 ImGui::Begin(
"SurveyMap",
nullptr, flags);
129 ImVec2 tl_screen_pos = ImGui::GetCursorScreenPos();
130 Ogre::Vector2 smallmap_center;
131 Ogre::Vector2 smallmap_size;
132 Ogre::Vector2 view_origin;
133 Ogre::Vector2 texcoords_top_left(0,0);
134 Ogre::Vector2 texcoords_bottom_right(1,1);
135 if (mMapMode == SurveyMapMode::BIG)
137 view_origin = mMapCenterOffset;
139 else if (mMapMode == SurveyMapMode::SMALL)
142 smallmap_size = mTerrainSize * (1.0f - mMapZoom);
143 Ogre::Vector2 player_map_pos;
148 player_map_pos = (Vector2(actor_data.simbuf_pos.x, actor_data.simbuf_pos.z));
153 player_map_pos = (Vector2(scene_data.simbuf_character_pos.x, scene_data.simbuf_character_pos.z));
156 smallmap_center.x = Math::Clamp(player_map_pos.x - mMapCenterOffset.x, smallmap_size.x / 2, mTerrainSize.x - smallmap_size.x / 2);
157 smallmap_center.y = Math::Clamp(player_map_pos.y - mMapCenterOffset.y, smallmap_size.y / 2, mTerrainSize.y - smallmap_size.y / 2);
159 view_origin = ((smallmap_center + mMapCenterOffset) - smallmap_size / 2);
161 texcoords_top_left = (smallmap_center - (smallmap_size/2)) / mTerrainSize;
162 texcoords_bottom_right = (smallmap_center + (smallmap_size/2)) / mTerrainSize;
170 ImVec2 cw_dist = this->CalcWaypointMapPos(tl_screen_pos, view_size, view_origin, i);
171 if (abs(cw_dist.x) <= 5 && abs(cw_dist.y) <= 5)
178 ImGui::BeginChild(
"map", ImVec2(0.f, view_size.y),
false);
180 if (mMapMode == SurveyMapMode::BIG)
182 ImGui::Image(
reinterpret_cast<ImTextureID
>(mMapTexture->getHandle()), view_size);
184 else if (mMapMode == SurveyMapMode::SMALL)
186 ImDrawList* drawlist = ImGui::GetWindowDrawList();
188 ImVec2 p_min = ImGui::GetCursorScreenPos();
189 ImVec2 p_max = ImVec2(p_min.x + view_size.x, p_min.y + view_size.y);
190 ImVec2 p_offset = ImVec2(5.f, 5.f);
191 ImVec2 _min(p_min + p_offset);
192 ImVec2 _max(p_max + p_offset);
193 ImVec2 uv_min(texcoords_top_left.x, texcoords_top_left.y);
194 ImVec2 uv_max(texcoords_bottom_right.x, texcoords_bottom_right.y);
195 m_circle_center =_min + ((_max-_min)/2);
196 m_circle_radius = view_size.x/2 - p_offset.x;
199 drawlist->AddCircle(ImVec2(p_min.x + view_size.x/2, p_min.y + view_size.y/2), view_size.x/2 - 2*p_offset.x, ImGui::GetColorU32(theme.
semitransparent_window_bg), 96, 20);
202 drawlist->AddCircularImage(
reinterpret_cast<ImTextureID
>(mMapTexture->getHandle()), _min, _max, uv_min, uv_max, ImGui::GetColorU32(ImVec4(1,1,1,1)), m_circle_radius);
205 ImGui::InvisibleButton(
"circle", view_size);
208 if (ImGui::IsItemClicked(0) || ImGui::IsItemClicked(1))
210 ImVec2 mouse_view_offset = (ImGui::GetMousePos() - tl_screen_pos) / view_size;
211 Vector2 mouse_map_pos;
212 if (mMapMode == SurveyMapMode::BIG)
214 mouse_map_pos = view_origin + Vector2(mouse_view_offset.x, mouse_view_offset.y) * mTerrainSize;
216 else if (mMapMode == SurveyMapMode::SMALL)
218 mouse_map_pos = view_origin + (Vector2(mouse_view_offset.x, mouse_view_offset.y) * smallmap_size);
221 if (ImGui::IsItemClicked(1))
225 waypoint.
position = Ogre::Vector3(mouse_map_pos.x,
y, mouse_map_pos.y);
230 Ogre::Vector3* payload =
new Ogre::Vector3(mouse_map_pos.x, 0.f, mouse_map_pos.y);
234 else if (ImGui::IsItemClicked(2) && !w_adj)
238 else if (ImGui::IsItemHovered())
241 ImVec2 mouse_pos = ImGui::GetMousePos();
242 ImDrawList* drawlist = ImGui::GetWindowDrawList();
243 drawlist->AddCircleFilled(mouse_pos, 5, ImGui::GetColorU32(ImVec4(1,0,0,1)));
244 if (mMapMode == SurveyMapMode::SMALL)
246 const char* title =
"Teleport/Waypoint";
247 ImVec2 text_pos(mouse_pos.x - (ImGui::CalcTextSize(title).x/2), mouse_pos.y - 25);
248 drawlist->AddText(text_pos, ImGui::GetColorU32(ImGui::GetStyle().Colors[ImGuiCol_Text]), title);
257 ImVec2 cw_dist = this->DrawWaypoint(tl_screen_pos, view_size, view_origin, std::to_string(i), i);
259 if (abs(cw_dist.x) <= 5 && abs(cw_dist.y) <= 5)
261 if (ImGui::IsMouseClicked(0))
263 mMouseClicked =
true;
266 else if (ImGui::IsMouseReleased(0))
268 mMouseClicked =
false;
274 ImVec2 mouse_view_offset = (ImGui::GetMousePos() - tl_screen_pos) / view_size;
275 Vector2 mouse_map_pos;
276 if (mMapMode == SurveyMapMode::BIG)
278 mouse_map_pos = view_origin + Vector2(mouse_view_offset.x, mouse_view_offset.y) * mTerrainSize;
280 else if (mMapMode == SurveyMapMode::SMALL)
282 mouse_map_pos = view_origin + (Vector2(mouse_view_offset.x, mouse_view_offset.y) * smallmap_size);
288 else if (abs(cw_dist.x) <= 5 && abs(cw_dist.y) <= 5 && ImGui::IsItemClicked(2))
301 bool visible = !((e.type ==
"checkpoint" && e.id != id) || (e.type ==
"racestart" &&
id != -1 && e.id !=
id));
305 this->CacheMapIcon(e);
306 this->DrawMapIcon(e, tl_screen_pos, view_size, view_origin);
313 const char* type_str = this->getTypeByDriveable(gfx_actor->GetActor());
314 int truckstate = gfx_actor->GetActorState();
318 fileName <<
"icon_" << type_str <<
"_activated.dds";
320 fileName <<
"icon_" << type_str <<
"_networked.dds";
322 fileName <<
"icon_" << type_str <<
".dds";
324 auto& simbuf = gfx_actor->GetSimDataBuffer();
328 e.
pos = simbuf.simbuf_pos;
329 e.
rot_angle = Ogre::Radian(simbuf.simbuf_rotation);
335 e.
caption = simbuf.simbuf_net_username;
341 this->CacheMapIcon(e);
342 this->DrawMapIcon(e, tl_screen_pos, view_size, view_origin);
348 auto& simbuf = gfx_character->xc_simbuf;
349 if (!simbuf.simbuf_actor_coupling)
353 e.
pos = simbuf.simbuf_character_pos;
354 e.
rot_angle = simbuf.simbuf_character_rot;
355 e.
filename =
"icon_person_activated.dds";
358 if (simbuf.simbuf_is_remote)
360 e.
filename =
"icon_person_networked.dds";
361 e.
caption = simbuf.simbuf_net_username;
367 this->CacheMapIcon(e);
368 this->DrawMapIcon(e, tl_screen_pos, view_size, view_origin);
375 float orig_y = ImGui::GetCursorPosY();
382 ImGui::Image(
reinterpret_cast<ImTextureID
>(m_left_mouse_button->getHandle()), ImVec2(28, 24));
384 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().ItemSpacing.y);
386 const char* text =
"Teleport";
387 if (w_adj || mMouseClicked)
389 text =
"Drag to adjust this waypoint";
394 ImGui::SetCursorPosY(orig_y);
395 ImGui::Image(
reinterpret_cast<ImTextureID
>(m_right_mouse_button->getHandle()), ImVec2(28, 24));
397 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().ItemSpacing.y);
399 text =
"Set AI waypoint";
403 ImGui::SetCursorPosY(orig_y);
404 ImGui::Image(
reinterpret_cast<ImTextureID
>(m_middle_mouse_button->getHandle()), ImVec2(28, 24));
406 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().ItemSpacing.y);
408 text =
"Remove all AI waypoints";
409 if (w_adj || mMouseClicked)
411 text =
"Remove this waypoint";
416 ImGui::SetCursorPosY(orig_y);
417 ImGui::Image(
reinterpret_cast<ImTextureID
>(m_middle_mouse_scroll_button->getHandle()), ImVec2(28, 24));
419 ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().ItemSpacing.y);
421 text =
"Zoom mini map";
424 mWindowMouseHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
428 if (mMapMode == SurveyMapMode::BIG)
430 ImGui::PopStyleColor(1);
432 else if (mMapMode == SurveyMapMode::SMALL)
434 ImGui::PopStyleColor(2);
437 ImGui::PopStyleVar(2);
442 mMapCenterOffset = Ogre::Vector2::ZERO;
445 if (mMapTexture->getLoadingState() != Ogre::Resource::LoadingState::LOADSTATE_UNLOADED)
447 Ogre::TextureManager::getSingleton().unload(mMapTexture->getName(), mMapTexture->getGroup());
449 Ogre::TextureManager::getSingleton().remove(mMapTexture->getName(), mMapTexture->getGroup());
450 mMapTexture.setNull();
453 mMapMode = SurveyMapMode::NONE;
459 if (terrain_size.isZeroLength() || use_aab && (aab.getSize().length() < terrain_size.length()))
461 terrain_size = aab.getSize();
462 terrain_size.y = aab.getMaximum().y;
463 Vector3 offset = aab.getCenter() - terrain_size / 2;
464 mMapCenterOffset = Vector2(offset.x, offset.z);
467 mTerrainSize = Vector2(terrain_size.x, terrain_size.z);
468 Ogre::Vector2 mMapCenter = mTerrainSize / 2;
471 int fsaa = StringConverter::parseInt(ropts[
"FSAA"].currentValue, 0);
474 texCreatorStatic.
init(4096, fsaa);
475 texCreatorStatic.
update(mMapCenter + mMapCenterOffset, mTerrainSize);
483 zoom = Math::Clamp(zoom, 0.0f, std::max(0.0f, (mTerrainSize.x - 50.0f) / mTerrainSize.x));
485 if (mMapZoom == zoom)
493 setMapZoom(mMapZoom + 0.5f * delta * (1.0f - mMapZoom));
512 return this->getAIType(actor);
540 case SurveyMapMode::NONE: mMapLastMode = mMapMode = SurveyMapMode::SMALL;
break;
541 case SurveyMapMode::SMALL: mMapLastMode = mMapMode = SurveyMapMode::BIG;
break;
542 case SurveyMapMode::BIG: mMapMode = SurveyMapMode::NONE;
break;
549 mMapMode = (mMapMode == SurveyMapMode::NONE) ? mMapLastMode : SurveyMapMode::NONE;
554 Ogre::Vector2 terrn_size_adj = mTerrainSize;
555 if (mMapMode == SurveyMapMode::SMALL)
557 terrn_size_adj = mTerrainSize * (1.f - mMapZoom);
561 img_pos.x = view_pos.x + ((e.
pos.x - view_origin.x) / terrn_size_adj.x) * view_size.x;
562 img_pos.y = view_pos.y + ((e.
pos.z - view_origin.y) / terrn_size_adj.y) * view_size.y;
563 float img_dist = (img_pos.x - m_circle_center.x) * (img_pos.x - m_circle_center.x) + (img_pos.y - m_circle_center.y) * (img_pos.y - m_circle_center.y);
566 || (mMapMode == SurveyMapMode::SMALL && img_dist > (m_circle_radius * m_circle_radius)*0.8))
576 ImVec2 text_pos(img_pos.x - (ImGui::CalcTextSize(e.
caption.c_str()).x/2), img_pos.y + 5);
578 ImGui::GetWindowDrawList()->AddText(text_pos, ImColor(text_color), e.
caption.c_str());
582 ImVec2 dist = ImGui::GetMousePos() - img_pos;
583 if (!e.
caption.empty() && abs(dist.x) <= 5 && abs(dist.y) <= 5)
585 ImGui::BeginTooltip();
586 ImGui::Text(
"%s", e.
caption.c_str());
593 std::string
const& caption,
int idx)
595 Ogre::Vector2 terrn_size_adj = mTerrainSize;
596 if (mMapMode == SurveyMapMode::SMALL)
598 terrn_size_adj = mTerrainSize * (1.f - mMapZoom);
605 float wp_dist = (wp_pos.x - m_circle_center.x) * (wp_pos.x - m_circle_center.x) + (wp_pos.y - m_circle_center.y) * (wp_pos.y - m_circle_center.y);
607 if (mMapMode == SurveyMapMode::SMALL && wp_dist > (m_circle_radius * m_circle_radius)*0.8)
612 ImDrawList* drawlist = ImGui::GetWindowDrawList();
613 ImVec4 col = ImVec4(1,0,0,1);
614 ImVec2 dist = ImGui::GetMousePos() - wp_pos;
615 if (abs(dist.x) <= 5 && abs(dist.y) <= 5)
617 col = ImVec4(1,1,0,1);
619 ImGui::BeginTooltip();
620 ImGui::Text(
"%s %s",
"Waypoint", caption.c_str());
621 if (mMapMode == SurveyMapMode::BIG)
624 ImGui::TextDisabled(
"%s %s",
"Position: ", wpos.c_str());
629 if (mMapMode == SurveyMapMode::BIG || (mMapMode == SurveyMapMode::SMALL && wp_draw))
631 drawlist->AddCircleFilled(wp_pos, 5, ImGui::GetColorU32(ImVec4(col)));
640 float next_wp_dist = (next_wp_pos.x - m_circle_center.x) * (next_wp_pos.x - m_circle_center.x) + (next_wp_pos.y - m_circle_center.y) * (next_wp_pos.y - m_circle_center.y);
641 bool next_wp_draw =
true;
642 if (mMapMode == SurveyMapMode::SMALL && next_wp_dist > (m_circle_radius * m_circle_radius)*0.8)
644 next_wp_draw =
false;
647 if (mMapMode == SurveyMapMode::BIG || (mMapMode == SurveyMapMode::SMALL && wp_draw && next_wp_draw))
649 drawlist->AddLine(wp_pos, next_wp_pos, ImGui::GetColorU32(ImVec4(1,0,0,1)));
653 return ImGui::GetMousePos() - wp_pos;
658 Ogre::Vector2 terrn_size_adj = mTerrainSize;
659 if (mMapMode == SurveyMapMode::SMALL)
661 terrn_size_adj = mTerrainSize * (1.f - mMapZoom);
668 return ImGui::GetMousePos() - pos;
675 m_left_mouse_button =
FetchIcon(
"left-mouse-button.png");
676 m_middle_mouse_button =
FetchIcon(
"middle-mouse-button.png");
677 m_middle_mouse_scroll_button =
FetchIcon(
"middle-mouse-scroll-button.png");
678 m_right_mouse_button =
FetchIcon(
"right-mouse-button.png");
680 m_icons_cached =
true;
702 catch (Ogre::FileNotFoundException)
712 e.
cached_icon = Ogre::TextureManager::getSingleton().load(
716 catch (Ogre::FileNotFoundException)