| 1441 | } |
| 1442 | |
| 1443 | static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi) |
| 1444 | { |
| 1445 | Rect search_rect{ dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height }; |
| 1446 | search_rect = ExpandRectWithViewportSignMargins(search_rect, dpi->zoom); |
| 1447 | |
| 1448 | bool show_stations = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && _game_mode != GM_MENU; |
| 1449 | bool show_waypoints = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && _game_mode != GM_MENU; |
| 1450 | bool show_towns = HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _game_mode != GM_MENU; |
| 1451 | bool show_signs = HasBit(_display_opt, DO_SHOW_SIGNS) && !IsInvisibilitySet(TO_SIGNS); |
| 1452 | bool show_competitors = HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS); |
| 1453 | |
| 1454 | /* Collect all the items first and draw afterwards, to ensure layering */ |
| 1455 | std::vector<const BaseStation *> stations; |
| 1456 | std::vector<const Town *> towns; |
| 1457 | std::vector<const Sign *> signs; |
| 1458 | |
| 1459 | _viewport_sign_kdtree.FindContained(search_rect.left, search_rect.top, search_rect.right, search_rect.bottom, [&](const ViewportSignKdtreeItem & item) { |
| 1460 | switch (item.type) { |
| 1461 | case ViewportSignKdtreeItem::VKI_STATION: { |
| 1462 | if (!show_stations) break; |
| 1463 | const BaseStation *st = BaseStation::Get(std::get<StationID>(item.id)); |
| 1464 | |
| 1465 | /* If no facilities are present the station is a ghost station. */ |
| 1466 | StationFacilities facilities = st->facilities; |
| 1467 | if (facilities.None()) facilities = STATION_FACILITY_GHOST; |
| 1468 | |
| 1469 | if (!facilities.Any(_facility_display_opt)) break; |
| 1470 | |
| 1471 | /* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */ |
| 1472 | if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break; |
| 1473 | |
| 1474 | stations.push_back(st); |
| 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | case ViewportSignKdtreeItem::VKI_WAYPOINT: { |
| 1479 | if (!show_waypoints) break; |
| 1480 | const BaseStation *st = BaseStation::Get(std::get<StationID>(item.id)); |
| 1481 | |
| 1482 | /* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */ |
| 1483 | if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break; |
| 1484 | |
| 1485 | stations.push_back(st); |
| 1486 | break; |
| 1487 | } |
| 1488 | |
| 1489 | case ViewportSignKdtreeItem::VKI_TOWN: |
| 1490 | if (!show_towns) break; |
| 1491 | towns.push_back(Town::Get(std::get<TownID>(item.id))); |
| 1492 | break; |
| 1493 | |
| 1494 | case ViewportSignKdtreeItem::VKI_SIGN: { |
| 1495 | if (!show_signs) break; |
| 1496 | const Sign *si = Sign::Get(std::get<SignID>(item.id)); |
| 1497 | |
| 1498 | /* Don't draw if sign is owned by another company and competitor signs should be hidden. |
| 1499 | * Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt |
| 1500 | * companies can leave OWNER_NONE signs after them. */ |
no test coverage detected