125std::vector<CompassMark>
CompassMarks(
const std::vector<Figure>& figures,
126 int land, uint32_t target,
127 std::optional<Vector3> destination) {
128 const auto you = std::ranges::find_if(figures, &
Figure::you);
129 if (you == figures.end()) {
132 const Vector3 here = you->position;
133 std::vector<CompassMark> marks;
135 marks.push_back({.kind = kind,
137 .distance = std::hypot(to.x - here.x, to.z - here.z),
141 if (gate.land == land) {
146 for (
const Figure& figure : figures) {
147 if (figure.npc && figure.mark ==
'!') {
149 }
else if (figure.npc && figure.mark ==
'?') {
157 for (
const Figure& figure : figures) {
158 if (figure.monster && figure.id == target && target != 0 &&
159 figure.to != protocol::MOTION_DEAD) {
166void DrawCompass(
float heading,
const std::vector<CompassMark>& marks) {
168 ImDrawList* draw = ImGui::GetBackgroundDrawList();
170 const ImVec2 screen = ImGui::GetIO().DisplaySize;
171 const float width = std::min(
Ui(kWidth), screen.x * 0.6f);
172 const float height =
Ui(kHeight);
173 const ImVec2 min{(screen.x - width) / 2.0f,
Ui(kTop)};
174 const ImVec2 max{min.x + width, min.y + height};
175 const float middle = (min.x + max.x) / 2.0f;
176 const float half = width / 2.0f;
179 const float fade = width * 0.2f;
182 draw->AddRectFilledMultiColor(min, {min.x + fade, max.y}, clear, band, band,
184 draw->AddRectFilled({min.x + fade, min.y}, {max.x - fade, max.y}, band);
185 draw->AddRectFilledMultiColor({max.x - fade, min.y}, max, band, clear, clear,
187 DrawEdge(draw, min.x, max.x, min.y);
188 DrawEdge(draw, min.x, max.x, max.y - std::max(1.0f,
Ui(1.0f)));
192 for (
int degrees = 0; degrees < 360; degrees += 5) {
193 const std::optional<float> at =
194 CompassAt(heading,
static_cast<float>(degrees) * kPi / 180.0f, kSpan);
198 const float x = middle + *at * half;
199 const float alpha = EdgeFade(*at);
200 if (degrees % 45 == 0) {
201 const bool cardinal = degrees % 90 == 0;
205 DrawCentred(draw, fonts.
title, cardinal ?
Ui(22.0f) :
Ui(14.0f),
206 {x, (min.y + max.y) / 2.0f},
Faded(color, alpha),
207 Tr(
"compass", kPoints[degrees / 45]));
209 const float tall = degrees % 15 == 0 ?
Ui(9.0f) :
Ui(5.0f);
212 draw->AddLine({x, max.y -
Ui(3.0f) - tall}, {x, max.y -
Ui(3.0f)},
213 Faded(color, alpha), std::max(1.0f,
Ui(1.2f)));
219 float nearest_at =
kNear;
221 if (
const std::optional<float> at =
CompassAt(heading, mark.bearing, kSpan);
222 at && std::abs(*at) < nearest_at) {
224 nearest_at = std::abs(*at);
228 const std::optional<float> at =
CompassAt(heading, mark.bearing, kSpan);
238 : (std::remainder(mark.bearing - heading, 2.0f * kPi) < 0.0f ? -1.0f
240 const float x = middle + side * (half - (at ? 0.0f :
Ui(10.0f)));
241 const float alpha = at ? std::max(EdgeFade(*at), 0.0f) : 0.8f;
245 DrawMark(draw, mark, {x, (min.y + max.y) / 2.0f}, alpha);
248 const float tip = side < 0.0f ? min.x -
Ui(2.0f) : max.x +
Ui(2.0f);
249 const float back = tip - side *
Ui(7.0f);
250 const float y = (min.y + max.y) / 2.0f;
251 draw->AddTriangleFilled({tip, y}, {back, y -
Ui(5.0f)},
252 {back, y +
Ui(5.0f)},
Faded(mark.color, 0.8f));
253 }
else if (&mark == nearest) {
254 const std::string distance = absl::Substitute(
255 Tr(
"$0 m"),
static_cast<int>(std::lround(mark.distance)));
256 DrawCentred(draw, fonts.
bold,
Ui(13.0f), {x, max.y +
Ui(9.0f)},
263 draw->AddLine({middle, min.y +
Ui(2.0f)}, {middle, max.y -
Ui(2.0f)},
265 const float notch =
Ui(7.0f);
266 draw->AddTriangleFilled({middle - notch, min.y -
Ui(1.0f)},
267 {middle + notch, min.y -
Ui(1.0f)},