Make station rating tooltips work with right click tooltip setting

This commit is contained in:
dP
2020-07-05 17:21:24 +03:00
parent a5674e2982
commit 5c4b5dad0e
5 changed files with 272 additions and 258 deletions

View File

@@ -2,15 +2,19 @@
#include "cm_tooltips.hpp"
#include "../company_base.h"
#include "../house.h"
#include "../industry.h"
#include "../newgrf_callbacks.h"
#include "../newgrf_cargo.h"
#include "../station_base.h"
#include "../station_map.h"
#include "../string_func.h"
#include "../strings_func.h"
#include "../tile_type.h"
#include "../town_map.h"
#include "../town.h"
#include "../window_func.h"
#include "../window_gui.h"
#include "../zoom_func.h"
#include "../safeguards.h"
@@ -204,13 +208,6 @@ struct LandTooltipsWindow : public Window
}
}
// virtual void OnMouseLoop()
// {
// if (!_cursor.in_window || !_mouse_hovering) {
// delete this;
// }
// }
void DrawSpriteIcons(SpriteID sprite, int left, int top) const
{
uint step = ScaleGUITrad(10);
@@ -225,6 +222,11 @@ void ShowLandTooltips(TileIndex tile, Window *parent) {
if (tile == last_tooltip_tile) return;
last_tooltip_tile = tile;
if (tile == INVALID_TILE) {
DeleteWindowById(CM_WC_LAND_TOOLTIPS, 0);
return;
}
uint param = 0;
switch (GetTileType(tile)) {
case MP_HOUSE: {
@@ -259,4 +261,253 @@ void ShowLandTooltips(TileIndex tile, Window *parent) {
new LandTooltipsWindow(parent, param);
}
static const NWidgetPart _nested_station_rating_tooltip_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY, 0), SetMinimalSize(64, 32), EndContainer(),
};
static WindowDesc _station_rating_tooltip_desc(
WDP_MANUAL, NULL, 0, 0,
WC_STATION_RATING_TOOLTIP, WC_NONE,
0,
_nested_station_rating_tooltip_widgets, lengthof(_nested_station_rating_tooltip_widgets)
);
static const int STATION_RATING_AGE[] = {0, 10, 20, 33};
static const int STATION_RATING_WAITTIME[] = {0, 25, 50, 95, 130};
static const int STATION_RATING_WAITUNITS[] = {-90, -35, 0, 10, 30, 40};
struct StationRatingTooltipWindow : public Window
{
TileType tiletype;
uint16 objIndex;
TooltipCloseCondition close_cond;
const Station *st;
const CargoSpec *cs;
bool newgrf_rating_used;
static const uint RATING_TOOLTIP_LINE_BUFF_SIZE = 512;
static const uint RATING_TOOLTIP_MAX_LINES = 8;
static const uint RATING_TOOLTIP_NEWGRF_INDENT = 20;
public:
char data[RATING_TOOLTIP_MAX_LINES + 1][RATING_TOOLTIP_LINE_BUFF_SIZE];
StationRatingTooltipWindow(Window *parent, const Station *st, const CargoSpec *cs, TooltipCloseCondition close_cond) : Window(&_station_rating_tooltip_desc)
{
this->parent = parent;
this->st = st;
this->cs = cs;
this->close_cond = close_cond;
this->InitNested();
CLRBITS(this->flags, WF_WHITE_BORDER);
}
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
{
int scr_top = GetMainViewTop() + 2;
int scr_bot = GetMainViewBottom() - 2;
Point pt;
pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
return pt;
}
int RoundRating(int rating) {
return RoundDivSU(rating * 101, 256);
}
void OnInit() override {
const GoodsEntry *ge = &this->st->goods[this->cs->Index()];
SetDParam(0, this->cs->name);
GetString(this->data[0], STR_STATION_RATING_TOOLTIP_RATING_DETAILS, lastof(this->data[0]));
if (!ge->HasRating()) {
this->data[1][0] = '\0';
return;
}
uint line_nr = 1;
int total_rating = 0;
if (HasBit(cs->callback_mask, CBM_CARGO_STATION_RATING_CALC)) {
uint last_speed = ge->HasVehicleEverTriedLoading() ? ge->last_speed : 0xFF;
uint32 var18 = min(ge->time_since_pickup, 0xFF) | (min(ge->max_waiting_cargo, 0xFFFF) << 8) | (min(last_speed, 0xFF) << 24);
uint32 var10 = (this->st->last_vehicle_type == VEH_INVALID) ? 0x0 : (this->st->last_vehicle_type + 0x10);
// TODO can desync
uint16 callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, this->cs);
int newgrf_rating = 0;
if (callback != CALLBACK_FAILED) {
newgrf_rating = GB(callback, 0, 14);
if (HasBit(callback, 14)) newgrf_rating -= 0x4000;
this->newgrf_rating_used = true;
total_rating += newgrf_rating;
newgrf_rating = this->RoundRating(newgrf_rating);
SetDParam(0, STR_STATION_RATING_TOOLTIP_NEWGRF_RATING_0 + (newgrf_rating <= 0 ? 0 : 1));
SetDParam(1, newgrf_rating);
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_RATING, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, min(last_speed, 0xFF));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_SPEED, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, min(ge->max_waiting_cargo, 0xFFFF));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_WAITUNITS, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, (min(ge->time_since_pickup, 0xFF) * 5 + 1) / 2);
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_WAITTIME, lastof(this->data[line_nr]));
line_nr++;
}
}
if (!this->newgrf_rating_used) {
byte waittime = ge->time_since_pickup;
if (this->st->last_vehicle_type == VEH_SHIP) waittime >>= 2;
int waittime_stage = 0;
(waittime > 21) ||
(waittime_stage = 1, waittime > 12) ||
(waittime_stage = 2, waittime > 6) ||
(waittime_stage = 3, waittime > 3) ||
(waittime_stage = 4, true);
total_rating += STATION_RATING_WAITTIME[waittime_stage];
SetDParam(0, STR_STATION_RATING_TOOLTIP_WAITTIME_0 + waittime_stage);
SetDParam(1, (ge->time_since_pickup * 5 + 1) / 2);
SetDParam(2, this->RoundRating(STATION_RATING_WAITTIME[waittime_stage]));
GetString(this->data[line_nr], this->st->last_vehicle_type == VEH_SHIP ? STR_STATION_RATING_TOOLTIP_WAITTIME_SHIP : STR_STATION_RATING_TOOLTIP_WAITTIME, lastof(this->data[line_nr]));
line_nr++;
uint waitunits = ge->max_waiting_cargo;
int waitunits_stage = 0;
(waitunits > 1500) ||
(waitunits_stage = 1, waitunits > 1000) ||
(waitunits_stage = 2, waitunits > 600) ||
(waitunits_stage = 3, waitunits > 300) ||
(waitunits_stage = 4, waitunits > 100) ||
(waitunits_stage = 5, true);
total_rating += STATION_RATING_WAITUNITS[waitunits_stage];
SetDParam(0, STR_STATION_RATING_TOOLTIP_WAITUNITS_0 + waitunits_stage);
SetDParam(1, ge->max_waiting_cargo);
SetDParam(2, this->RoundRating(STATION_RATING_WAITUNITS[waitunits_stage]));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_WAITUNITS, lastof(this->data[line_nr]));
line_nr++;
int b = ge->last_speed - 85;
int r_speed = b >= 0 ? b >> 2 : 0;
int r_speed_round = this->RoundRating(r_speed);
total_rating += r_speed;
if (ge->last_speed == 255) {
SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_MAX);
} else if (r_speed_round == 0) {
SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_ZERO);
} else {
SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_0 + r_speed / 11);
}
SetDParam(0, ge->last_speed == 255 ? STR_STATION_RATING_TOOLTIP_SPEED_MAX : STR_STATION_RATING_TOOLTIP_SPEED_0 + r_speed / 11);
SetDParam(1, ge->last_speed);
SetDParam(2, r_speed_round);
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_SPEED, lastof(this->data[line_nr]));
line_nr++;
}
int age_stage = (ge->last_age >= 3 ? 0 : 3 - ge->last_age);
total_rating += STATION_RATING_AGE[age_stage];
SetDParam(0, STR_STATION_RATING_TOOLTIP_AGE_0 + age_stage);
SetDParam(1, ge->last_age);
SetDParam(2, this->RoundRating(STATION_RATING_AGE[age_stage]));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_AGE, lastof(this->data[line_nr]));
line_nr++;
if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) {
SetDParam(0, STR_STATION_RATING_TOOLTIP_STATUE_YES);
total_rating += 26;
} else {
SetDParam(0, STR_STATION_RATING_TOOLTIP_STATUE_NO);
}
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_STATUE, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, ToPercent8(Clamp(total_rating, 0, 255)));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_TOTAL_RATING, lastof(this->data[line_nr]));
line_nr++;
this->data[line_nr][0] = '\0';
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
size->height = WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + 2;
for (uint i = 0; i <= RATING_TOOLTIP_MAX_LINES; i++) {
if (StrEmpty(this->data[i])) break;
uint width = GetStringBoundingBox(this->data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + 2;
if (this->newgrf_rating_used && i >= 2 && i <= 4)
width += RATING_TOOLTIP_NEWGRF_INDENT;
size->width = max(size->width, width);
size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
}
size->height -= WD_PAR_VSEP_NORMAL;
}
void DrawWidget(const Rect &r, int widget) const override
{
GfxDrawLine(r.left, r.top, r.right, r.top, PC_BLACK);
GfxDrawLine(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
GfxDrawLine(r.left, r.top, r.left, r.bottom, PC_BLACK);
GfxDrawLine(r.right, r.top, r.right, r.bottom, PC_BLACK);
int y = r.top + WD_FRAMETEXT_TOP + 1;
int left0 = r.left + WD_FRAMETEXT_LEFT + 1;
int right0 = r.right - WD_FRAMETEXT_RIGHT - 1;
DrawString(left0, right0, y, this->data[0], TC_LIGHT_BLUE, SA_CENTER);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
for (uint i = 1; i <= RATING_TOOLTIP_MAX_LINES; i++) {
if (StrEmpty(this->data[i])) break;
int left = left0, right = right0;
if (this->newgrf_rating_used && i >= 2 && i <= 4) {
if (_current_text_dir == TD_RTL) {
right -= RATING_TOOLTIP_NEWGRF_INDENT;
} else {
left += RATING_TOOLTIP_NEWGRF_INDENT;
}
}
DrawString(left, right, y, this->data[i], TC_BLACK);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
}
}
void OnMouseLoop() override
{
/* Always close tooltips when the cursor is not in our window. */
if (!_cursor.in_window) {
delete this;
return;
}
/* We can show tooltips while dragging tools. These are shown as long as
* we are dragging the tool. Normal tooltips work with hover or rmb. */
switch (this->close_cond) {
case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break;
case TCC_HOVER: if (!_mouse_hovering) delete this; break;
case TCC_NONE: break;
}
}
};
bool ShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs, TooltipCloseCondition close_cond) {
DeleteWindowById(WC_STATION_RATING_TOOLTIP, 0);
new StationRatingTooltipWindow(parent, st, cs, close_cond);
return true;
}
} // namespace citymania

View File

@@ -1,14 +1,18 @@
#ifndef CM_TOOLTIPS_HPP
#define CM_TOOLTIPS_HPP
#include "../cargotype.h"
#include "../station_type.h"
#include "../tile_type.h"
#include "../window_type.h"
#include "../window_gui.h"
class LandInfoWindow;
namespace citymania {
void ShowLandTooltips(TileIndex tile, Window *parent);
bool ShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs, TooltipCloseCondition close_cond);
} // namespace citymania

View File

@@ -436,6 +436,7 @@ public:
void ShowLandInfo(TileIndex tile, TileIndex end_tile)
{
DeleteWindowById(WC_LAND_INFO, 0);
if (tile == INVALID_TILE) return;
new LandInfoWindow(tile, end_tile);
}
@@ -1331,8 +1332,7 @@ void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallback
/** Window for displaying a tooltip. */
void GuiPrepareTooltipsExtra(Window *parent){
const Point p = GetTileBelowCursor();
if (p.x == -1) return;
const TileIndex tile = TileVirtXY(p.x, p.y);
TileIndex tile = (p.x == -1 ? INVALID_TILE : TileVirtXY(p.x, p.y));
if (_cursor.sprite_seq[0].sprite == SPR_CURSOR_QUERY) {
// Land info tool active
@@ -1340,247 +1340,6 @@ void GuiPrepareTooltipsExtra(Window *parent){
return;
}
if (tile >= MapSize()) return;
if (tile >= MapSize()) tile = INVALID_TILE;
citymania::ShowLandTooltips(tile, parent);
}
static const NWidgetPart _nested_station_rating_tooltip_widgets[] = {
NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(64, 32), EndContainer(),
};
static WindowDesc _station_rating_tooltip_desc(
WDP_MANUAL, NULL, 0, 0,
WC_STATION_RATING_TOOLTIP, WC_NONE,
0,
_nested_station_rating_tooltip_widgets, lengthof(_nested_station_rating_tooltip_widgets)
);
static const int STATION_RATING_AGE[] = {0, 10, 20, 33};
static const int STATION_RATING_WAITTIME[] = {0, 25, 50, 95, 130};
static const int STATION_RATING_WAITUNITS[] = {-90, -35, 0, 10, 30, 40};
struct StationRatingTooltipWindow : public Window
{
TileType tiletype;
uint16 objIndex;
TooltipCloseCondition close_cond;
const Station *st;
const CargoSpec *cs;
bool newgrf_rating_used;
static const uint RATING_TOOLTIP_LINE_BUFF_SIZE = 512;
static const uint RATING_TOOLTIP_MAX_LINES = 8;
static const uint RATING_TOOLTIP_NEWGRF_INDENT = 20;
public:
char data[RATING_TOOLTIP_MAX_LINES + 1][RATING_TOOLTIP_LINE_BUFF_SIZE];
StationRatingTooltipWindow(Window *parent, const Station *st, const CargoSpec *cs) : Window(&_station_rating_tooltip_desc)
{
this->parent = parent;
this->st = st;
this->cs = cs;
this->InitNested();
CLRBITS(this->flags, WF_WHITE_BORDER);
}
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
{
int scr_top = GetMainViewTop() + 2;
int scr_bot = GetMainViewBottom() - 2;
Point pt;
pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
return pt;
}
int RoundRating(int rating) {
// if (rating >= 0) {
// return rating * 101 +
// }
return RoundDivSU(rating * 101, 256);
}
virtual void OnInit() {
const GoodsEntry *ge = &this->st->goods[this->cs->Index()];
SetDParam(0, this->cs->name);
GetString(this->data[0], STR_STATION_RATING_TOOLTIP_RATING_DETAILS, lastof(this->data[0]));
if (!ge->HasRating()) {
this->data[1][0] = '\0';
return;
}
uint line_nr = 1;
int total_rating = 0;
if (HasBit(cs->callback_mask, CBM_CARGO_STATION_RATING_CALC)) {
uint last_speed = ge->HasVehicleEverTriedLoading() ? ge->last_speed : 0xFF;
uint32 var18 = min(ge->time_since_pickup, 0xFF) | (min(ge->max_waiting_cargo, 0xFFFF) << 8) | (min(last_speed, 0xFF) << 24);
uint32 var10 = (this->st->last_vehicle_type == VEH_INVALID) ? 0x0 : (this->st->last_vehicle_type + 0x10);
uint16 callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, this->cs);
int newgrf_rating = 0;
if (callback != CALLBACK_FAILED) {
newgrf_rating = GB(callback, 0, 14);
if (HasBit(callback, 14)) newgrf_rating -= 0x4000;
this->newgrf_rating_used = true;
total_rating += newgrf_rating;
newgrf_rating = this->RoundRating(newgrf_rating);
SetDParam(0, STR_STATION_RATING_TOOLTIP_NEWGRF_RATING_0 + (newgrf_rating <= 0 ? 0 : 1));
SetDParam(1, newgrf_rating);
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_RATING, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, min(last_speed, 0xFF));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_SPEED, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, min(ge->max_waiting_cargo, 0xFFFF));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_WAITUNITS, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, (min(ge->time_since_pickup, 0xFF) * 5 + 1) / 2);
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_WAITTIME, lastof(this->data[line_nr]));
line_nr++;
}
}
if (!this->newgrf_rating_used) {
byte waittime = ge->time_since_pickup;
if (this->st->last_vehicle_type == VEH_SHIP) waittime >>= 2;
int waittime_stage = 0;
(waittime > 21) ||
(waittime_stage = 1, waittime > 12) ||
(waittime_stage = 2, waittime > 6) ||
(waittime_stage = 3, waittime > 3) ||
(waittime_stage = 4, true);
total_rating += STATION_RATING_WAITTIME[waittime_stage];
SetDParam(0, STR_STATION_RATING_TOOLTIP_WAITTIME_0 + waittime_stage);
SetDParam(1, (ge->time_since_pickup * 5 + 1) / 2);
SetDParam(2, this->RoundRating(STATION_RATING_WAITTIME[waittime_stage]));
GetString(this->data[line_nr], this->st->last_vehicle_type == VEH_SHIP ? STR_STATION_RATING_TOOLTIP_WAITTIME_SHIP : STR_STATION_RATING_TOOLTIP_WAITTIME, lastof(this->data[line_nr]));
line_nr++;
uint waitunits = ge->max_waiting_cargo;
int waitunits_stage = 0;
(waitunits > 1500) ||
(waitunits_stage = 1, waitunits > 1000) ||
(waitunits_stage = 2, waitunits > 600) ||
(waitunits_stage = 3, waitunits > 300) ||
(waitunits_stage = 4, waitunits > 100) ||
(waitunits_stage = 5, true);
total_rating += STATION_RATING_WAITUNITS[waitunits_stage];
SetDParam(0, STR_STATION_RATING_TOOLTIP_WAITUNITS_0 + waitunits_stage);
SetDParam(1, ge->max_waiting_cargo);
SetDParam(2, this->RoundRating(STATION_RATING_WAITUNITS[waitunits_stage]));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_WAITUNITS, lastof(this->data[line_nr]));
line_nr++;
int b = ge->last_speed - 85;
int r_speed = b >= 0 ? b >> 2 : 0;
int r_speed_round = this->RoundRating(r_speed);
total_rating += r_speed;
if (ge->last_speed == 255) {
SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_MAX);
} else if (r_speed_round == 0) {
SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_ZERO);
} else {
SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_0 + r_speed / 11);
}
SetDParam(0, ge->last_speed == 255 ? STR_STATION_RATING_TOOLTIP_SPEED_MAX : STR_STATION_RATING_TOOLTIP_SPEED_0 + r_speed / 11);
SetDParam(1, ge->last_speed);
SetDParam(2, r_speed_round);
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_SPEED, lastof(this->data[line_nr]));
line_nr++;
}
int age_stage = (ge->last_age >= 3 ? 0 : 3 - ge->last_age);
total_rating += STATION_RATING_AGE[age_stage];
SetDParam(0, STR_STATION_RATING_TOOLTIP_AGE_0 + age_stage);
SetDParam(1, ge->last_age);
SetDParam(2, this->RoundRating(STATION_RATING_AGE[age_stage]));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_AGE, lastof(this->data[line_nr]));
line_nr++;
if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) {
SetDParam(0, STR_STATION_RATING_TOOLTIP_STATUE_YES);
total_rating += 26;
} else {
SetDParam(0, STR_STATION_RATING_TOOLTIP_STATUE_NO);
}
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_STATUE, lastof(this->data[line_nr]));
line_nr++;
SetDParam(0, ToPercent8(Clamp(total_rating, 0, 255)));
GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_TOTAL_RATING, lastof(this->data[line_nr]));
line_nr++;
this->data[line_nr][0] = '\0';
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
if (widget != WID_LI_BACKGROUND) return;
size->height = WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + 2;
for (uint i = 0; i <= RATING_TOOLTIP_MAX_LINES; i++) {
if (StrEmpty(this->data[i])) break;
uint width = GetStringBoundingBox(this->data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + 2;
if (this->newgrf_rating_used && i >= 2 && i <= 4)
width += RATING_TOOLTIP_NEWGRF_INDENT;
size->width = max(size->width, width);
size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
}
size->height -= WD_PAR_VSEP_NORMAL;
}
virtual void DrawWidget(const Rect &r, int widget) const
{
GfxDrawLine(r.left, r.top, r.right, r.top, PC_BLACK);
GfxDrawLine(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
GfxDrawLine(r.left, r.top, r.left, r.bottom, PC_BLACK);
GfxDrawLine(r.right, r.top, r.right, r.bottom, PC_BLACK);
int y = r.top + WD_FRAMETEXT_TOP + 1;
int left0 = r.left + WD_FRAMETEXT_LEFT + 1;
int right0 = r.right - WD_FRAMETEXT_RIGHT - 1;
DrawString(left0, right0, y, this->data[0], TC_LIGHT_BLUE, SA_CENTER);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
for (uint i = 1; i <= RATING_TOOLTIP_MAX_LINES; i++) {
if (StrEmpty(this->data[i])) break;
int left = left0, right = right0;
if (this->newgrf_rating_used && i >= 2 && i <= 4) {
if (_current_text_dir == TD_RTL) {
right -= RATING_TOOLTIP_NEWGRF_INDENT;
} else {
left += RATING_TOOLTIP_NEWGRF_INDENT;
}
}
DrawString(left, right, y, this->data[i], TC_BLACK);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
}
}
virtual void OnMouseLoop()
{
if (!_cursor.in_window || !_mouse_hovering) {
delete this;
}
}
};
void GuiShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs) {
DeleteWindowById(WC_STATION_RATING_TOOLTIP, 0);
new StationRatingTooltipWindow(parent, st, cs);
}

View File

@@ -40,6 +40,7 @@
#include <vector>
#include "citymania/station_ui.hpp"
#include "citymania/cm_tooltips.hpp"
#include "safeguards.h"
@@ -2117,14 +2118,14 @@ struct StationViewWindow : public Window {
this->vscroll->SetCapacityFromWidget(this, WID_SV_WAITING, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
}
virtual void OnHover(Point pt, int widget)
bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override
{
if (widget != WID_SV_ACCEPT_RATING_LIST ||
this->GetWidget<NWidgetCore>(WID_SV_ACCEPTS_RATINGS)->widget_data == STR_STATION_VIEW_RATINGS_BUTTON)
Window::OnHover(pt, widget);
return false;
int ofs_y = pt.y - this->ratings_list_y;
if (ofs_y < 0) return;
if (ofs_y < 0) return false;
const Station *st = Station::Get(this->window_number);
const CargoSpec *cs;
@@ -2133,10 +2134,10 @@ struct StationViewWindow : public Window {
if (!ge->HasRating()) continue;
ofs_y -= FONT_HEIGHT_NORMAL;
if (ofs_y < 0) {
GuiShowStationRatingTooltip(this, st, cs);
break;
return citymania::ShowStationRatingTooltip(this, st, cs, close_cond);
}
}
return false;
}
/**

View File

@@ -883,7 +883,6 @@ void RelocateAllWindows(int neww, int newh);
void GuiShowTooltips(Window *parent, StringID str, uint paramcount = 0, const uint64 params[] = nullptr, TooltipCloseCondition close_tooltip = TCC_HOVER);
void GuiPrepareTooltipsExtra(Window *parent);
void GuiShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs);
/* widget.cpp */
int GetWidgetFromPos(const Window *w, int x, int y);