diff --git a/src/signs.cpp b/src/signs.cpp index c109a8a3e9..a1cb05c77c 100644 --- a/src/signs.cpp +++ b/src/signs.cpp @@ -51,7 +51,8 @@ void Sign::UpdateVirtCoord() if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index)); SetDParam(0, this->index); - this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_LVL_BASE, STR_WHITE_SIGN); + bool shown = HasBit(_display_opt, DO_SHOW_SIGNS) && !(this->IsCompetitorOwned() && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); + this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y - 6 * ZOOM_LVL_BASE, STR_WHITE_SIGN); if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index)); } diff --git a/src/signs_base.h b/src/signs_base.h index 6cc7dc6d80..3f77995dbd 100644 --- a/src/signs_base.h +++ b/src/signs_base.h @@ -14,6 +14,7 @@ #include "viewport_type.h" #include "core/pool_type.hpp" #include "company_type.h" +#include "company_func.h" typedef Pool SignPool; extern SignPool _sign_pool; @@ -29,6 +30,11 @@ struct Sign : SignPool::PoolItem<&_sign_pool> { Sign(Owner owner = INVALID_OWNER); ~Sign(); + bool IsCompetitorOwned() const + { + return _local_company != this->owner && this->owner != OWNER_DEITY; + } + void UpdateVirtCoord(); }; diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp index 35f04059e9..26725359f6 100644 --- a/src/signs_cmd.cpp +++ b/src/signs_cmd.cpp @@ -97,7 +97,9 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 } } else { // Delete sign if (flags & DC_EXEC) { - si->sign.MarkDirty(); + if (HasBit(_display_opt, DO_SHOW_SIGNS) && !(si->IsCompetitorOwned() && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) { + si->sign.MarkDirty(ZOOM_LVL_DRAW_SPR); + } if (_viewport_sign_kdtree_valid && si->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(si->index)); delete si; diff --git a/src/station.cpp b/src/station.cpp index 16381db73e..c5abf2d68d 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -64,7 +64,10 @@ BaseStation::~BaseStation() DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack()); DeleteWindowById(WC_DEPARTURES_BOARD, this->index); - this->sign.MarkDirty(); + if (HasBit(_display_opt, Station::IsExpected(this) ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES) && + !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) { + this->sign.MarkDirty(ZOOM_LVL_DRAW_SPR); + } } Station::Station(TileIndex tile) : diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 551ead4f3c..bf4a0c4196 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -417,7 +417,8 @@ void Station::UpdateVirtCoord() SetDParam(0, this->index); SetDParam(1, this->facilities); - this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION); + bool shown = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); + this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y, STR_VIEWPORT_STATION); if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index)); diff --git a/src/texteff.cpp b/src/texteff.cpp index 751f75c753..1e1267f127 100644 --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -32,7 +32,7 @@ struct TextEffect : public ViewportSign { /** Reset the text effect */ void Reset() { - this->MarkDirty(); + this->MarkDirty(ZOOM_LVL_OUT_8X); this->width_normal = 0; this->string_id = INVALID_STRING_ID; this->params_1 = _free_text_effect; @@ -64,7 +64,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, Text /* Make sure we only dirty the new area */ te.width_normal = 0; - te.UpdatePosition(center, y, msg); + te.UpdatePosition(ZOOM_LVL_OUT_8X, center, y, msg); return i; } @@ -78,7 +78,7 @@ void UpdateTextEffect(TextEffectID te_id, StringID msg) te->params_1 = GetDParam(0); te->params_2 = GetDParam(1); - te->UpdatePosition(te->center, te->top, msg); + te->UpdatePosition(ZOOM_LVL_OUT_8X, te->center, te->top, msg); } void RemoveTextEffect(TextEffectID te_id) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 6e5219c04e..0ee9699c1b 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -513,7 +513,7 @@ void Town::UpdateVirtCoord() SetDParam(0, this->index); SetDParam(1, this->cache.population); - this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE, this->Label(), STR_VIEWPORT_TOWN); + this->cache.sign.UpdatePosition(HasBit(_display_opt, DO_SHOW_TOWN_NAMES) ? ZOOM_LVL_OUT_128X : ZOOM_LVL_END, pt.x, pt.y - 24 * ZOOM_LVL_BASE, this->Label(), STR_VIEWPORT_TOWN); if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeTown(this->index)); diff --git a/src/viewport.cpp b/src/viewport.cpp index 88b421da73..f1080408c3 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1677,7 +1677,7 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi, bool towns_only) /* Don't draw if sign is owned by another company and competitor signs should be hidden. * Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt * companies can leave OWNER_NONE signs after them. */ - if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break; + if (!show_competitors && si->IsCompetitorOwned()) break; signs.push_back(si); break; @@ -1725,9 +1725,9 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi, bool towns_only) * @param str the string to show in the sign * @param str_small the string to show when zoomed out. STR_NULL means same as \a str */ -void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID str_small) +void ViewportSign::UpdatePosition(ZoomLevel maxzoom, int center, int top, StringID str, StringID str_small) { - if (this->width_normal != 0) this->MarkDirty(); + if (this->width_normal != 0) this->MarkDirty(maxzoom); this->top = top; @@ -1743,7 +1743,7 @@ void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID st } this->width_small = VPSM_LEFT + Align(GetStringBoundingBox(buffer, FS_SMALL).width, 2) + VPSM_RIGHT; - this->MarkDirty(); + this->MarkDirty(maxzoom); } /** @@ -1754,6 +1754,8 @@ void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID st */ void ViewportSign::MarkDirty(ZoomLevel maxzoom) const { + if (maxzoom == ZOOM_LVL_END) return; + Rect zoomlevels[ZOOM_LVL_COUNT]; for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) { diff --git a/src/viewport_type.h b/src/viewport_type.h index 80a0ad5a16..d31d5dd328 100644 --- a/src/viewport_type.h +++ b/src/viewport_type.h @@ -62,8 +62,8 @@ struct ViewportSign { uint16 width_normal; ///< The width when not zoomed out (normal font) uint16 width_small; ///< The width when zoomed out (small font) - void UpdatePosition(int center, int top, StringID str, StringID str_small = STR_NULL); - void MarkDirty(ZoomLevel maxzoom = ZOOM_LVL_MAX) const; + void UpdatePosition(ZoomLevel maxzoom, int center, int top, StringID str, StringID str_small = STR_NULL); + void MarkDirty(ZoomLevel maxzoom) const; }; /** Specialised ViewportSign that tracks whether it is valid for entering into a Kdtree */ @@ -74,10 +74,10 @@ struct TrackedViewportSign : ViewportSign { * Update the position of the viewport sign. * Note that this function hides the base class function. */ - void UpdatePosition(int center, int top, StringID str, StringID str_small = STR_NULL) + void UpdatePosition(ZoomLevel maxzoom, int center, int top, StringID str, StringID str_small = STR_NULL) { this->kdtree_valid = true; - this->ViewportSign::UpdatePosition(center, top, str, str_small); + this->ViewportSign::UpdatePosition(maxzoom, center, top, str, str_small); } diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 5dc33a92f8..f1e1e8ec84 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -42,7 +42,8 @@ void Waypoint::UpdateVirtCoord() if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index)); SetDParam(0, this->index); - this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT); + bool shown = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); + this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT); if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));