Refactor extra(land) tooltips and split into 3 settings in config
This commit is contained in:
241
src/misc_gui.cpp
241
src/misc_gui.cpp
@@ -38,12 +38,12 @@
|
||||
#include "viewport_func.h"
|
||||
#include "industry.h"
|
||||
|
||||
#include "citymania/cm_tooltips.hpp"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
extern const Station *_viewport_highlight_station; // CM
|
||||
|
||||
void GuiShowTooltipsExtra(Window *parent, uint param, TooltipCloseCondition close_tooltip);
|
||||
|
||||
/** Method to open the OSK. */
|
||||
enum OskActivation {
|
||||
OSKA_DISABLED, ///< The OSK shall not be activated at all.
|
||||
@@ -1340,237 +1340,10 @@ void GuiPrepareTooltipsExtra(Window *parent){
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_settings_client.gui.enable_extra_tooltips)
|
||||
return;
|
||||
|
||||
if (tile >= MapSize()) return;
|
||||
uint param = 0;
|
||||
switch (GetTileType(tile)) {
|
||||
/*case MP_HOUSE: {
|
||||
const HouseID house = GetHouseType(tile);
|
||||
param = ((house & 0xFFFF) << 16) | MP_HOUSE;
|
||||
break;
|
||||
}*/
|
||||
case MP_INDUSTRY: {
|
||||
const Industry *ind = Industry::GetByTile(tile);
|
||||
if(ind->produced_cargo[0] == CT_INVALID && ind->produced_cargo[1] == CT_INVALID) return;
|
||||
param = ((ind->index & 0xFFFF) << 16) | MP_INDUSTRY;
|
||||
break;
|
||||
}
|
||||
case MP_STATION: {
|
||||
if (IsRailWaypoint(tile) || HasTileWaterGround(tile)) break;
|
||||
const Station *st = Station::GetByTile(tile);
|
||||
param |= ((st->index & 0xFFFF) << 16) | MP_STATION;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if(param != 0) GuiShowTooltipsExtra(parent, param, TCC_HOVER);
|
||||
citymania::ShowLandTooltips(tile, parent);
|
||||
}
|
||||
|
||||
static const NWidgetPart _nested_tooltips_extra_widgets[] = {
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(64, 32), EndContainer(),
|
||||
};
|
||||
|
||||
static WindowDesc _tool_tips_extra_desc(
|
||||
WDP_MANUAL, NULL, 0, 0,
|
||||
WC_TOOLTIPS_EXTRA, WC_NONE,
|
||||
0,
|
||||
_nested_tooltips_extra_widgets, lengthof(_nested_tooltips_extra_widgets)
|
||||
);
|
||||
|
||||
struct TooltipsExtraWindow : public Window
|
||||
{
|
||||
TileType tiletype;
|
||||
uint16 objIndex;
|
||||
TooltipCloseCondition close_cond;
|
||||
|
||||
TooltipsExtraWindow(Window *parent, uint param, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_extra_desc)
|
||||
{
|
||||
this->parent = parent;
|
||||
this->tiletype = (TileType)(param & 0xFFFF);
|
||||
this->objIndex = (uint16)((param >> 16) & 0xFFFF);
|
||||
this->close_cond = close_tooltip;
|
||||
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;
|
||||
}
|
||||
|
||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||
{
|
||||
uint icon_size = ScaleGUITrad(10);
|
||||
uint line_height = max((uint)FONT_HEIGHT_NORMAL, icon_size) + 2;
|
||||
uint icons_width = icon_size * 3 + 20;
|
||||
size->width = 200;
|
||||
size->height = FONT_HEIGHT_NORMAL + 6;
|
||||
switch(this->tiletype) {
|
||||
/*case MP_HOUSE: {
|
||||
size->height += LINE_HEIGHT;
|
||||
SetDParam(0, 1000);
|
||||
size->width = GetStringBoundingBox(STR_TTE_HOUSE).width;
|
||||
break;
|
||||
}*/
|
||||
case MP_INDUSTRY: {
|
||||
const Industry *ind = Industry::GetIfValid((IndustryID)this->objIndex);
|
||||
if(ind == NULL) break;
|
||||
|
||||
for (CargoID i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
if (ind->produced_cargo[i] == CT_INVALID) continue;
|
||||
const CargoSpec *cs = CargoSpec::Get(ind->produced_cargo[i]);
|
||||
if(cs == NULL) continue;
|
||||
size->height += line_height;
|
||||
SetDParam(0, cs->name);
|
||||
SetDParam(1, cs->Index());
|
||||
SetDParam(2, ind->last_month_production[i]);
|
||||
SetDParam(3, ToPercent8(ind->last_month_pct_transported[i]));
|
||||
size->width = max(GetStringBoundingBox(STR_TTE_INDUSTRY).width + icons_width, size->width);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MP_STATION: {
|
||||
const Station *st = Station::GetIfValid((StationID)this->objIndex);
|
||||
if(st == NULL) break;
|
||||
|
||||
SetDParam(0, st->index);
|
||||
size->width = max(GetStringBoundingBox(STR_TTE_STATION_NAME).width, size->width);
|
||||
|
||||
for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
|
||||
const CargoSpec *cs = _sorted_cargo_specs[i];
|
||||
if(cs == NULL) continue;
|
||||
int cargoid = cs->Index();
|
||||
if (HasBit(st->goods[cargoid].status, GoodsEntry::GES_RATING)) {
|
||||
size->height += line_height;
|
||||
SetDParam(0, cs->name);
|
||||
SetDParam(1, cargoid);
|
||||
SetDParam(2, st->goods[cargoid].cargo.TotalCount());
|
||||
SetDParam(3, ToPercent8(st->goods[cargoid].rating));
|
||||
size->width = max(GetStringBoundingBox(STR_TTE_STATION).width + icons_width, size->width);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
size->width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
|
||||
size->height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||
}
|
||||
|
||||
virtual void DrawWidget(const Rect &r, int widget) const
|
||||
{
|
||||
uint icon_size = ScaleGUITrad(10);
|
||||
uint line_height = max((uint)FONT_HEIGHT_NORMAL, icon_size) + 2;
|
||||
uint icons_width = icon_size * 3 + 10;
|
||||
uint text_ofs = (line_height - FONT_HEIGHT_NORMAL) >> 1;
|
||||
uint icon_ofs = (line_height - icon_size) >> 1;
|
||||
|
||||
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_FRAMERECT_TOP + 4;
|
||||
int left = r.left + WD_FRAMERECT_LEFT + 4;
|
||||
|
||||
switch(this->tiletype) {
|
||||
/*case MP_HOUSE: {
|
||||
const HouseID house = (HouseID)this->objIndex;
|
||||
const HouseSpec *hs = HouseSpec::Get(house);
|
||||
if(hs == NULL) break;
|
||||
|
||||
SetDParam(0, hs->building_name);
|
||||
DrawString(left, r.right - WD_FRAMERECT_RIGHT, y, STR_TTE_HOUSE_NAME, TC_BLACK, SA_CENTER);
|
||||
y += LINE_HEIGHT;
|
||||
SetDParam(0, hs->population);
|
||||
DrawString(left, r.right - WD_FRAMERECT_RIGHT, y, STR_TTE_HOUSE);
|
||||
break;
|
||||
}*/
|
||||
case MP_INDUSTRY: {
|
||||
const Industry *ind = Industry::GetIfValid((IndustryID)this->objIndex);
|
||||
if(ind == NULL) break;
|
||||
|
||||
SetDParam(0, ind->index);
|
||||
DrawString(left, r.right - WD_FRAMERECT_RIGHT, y, STR_TTE_INDUSTRY_NAME, TC_BLACK, SA_CENTER);
|
||||
y += FONT_HEIGHT_NORMAL + 2;
|
||||
|
||||
for (CargoID i = 0; i < lengthof(ind->produced_cargo); i++) {
|
||||
if (ind->produced_cargo[i] == CT_INVALID) continue;
|
||||
const CargoSpec *cs = CargoSpec::Get(ind->produced_cargo[i]);
|
||||
if(cs == NULL) continue;
|
||||
SetDParam(0, cs->name);
|
||||
SetDParam(1, cs->Index());
|
||||
SetDParam(2, ind->last_month_production[i]);
|
||||
SetDParam(3, ToPercent8(ind->last_month_pct_transported[i]));
|
||||
|
||||
this->DrawSpriteIcons(cs->GetCargoIcon(), left, y + icon_ofs);
|
||||
DrawString(left + icons_width, r.right - WD_FRAMERECT_RIGHT, y + text_ofs, STR_TTE_INDUSTRY);
|
||||
y += line_height;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MP_STATION: {
|
||||
const Station *st = Station::GetIfValid((StationID)this->objIndex);
|
||||
if(st == NULL) break;
|
||||
|
||||
SetDParam(0, st->index);
|
||||
DrawString(left, r.right - WD_FRAMERECT_RIGHT, y, STR_TTE_STATION_NAME, TC_BLACK, SA_CENTER);
|
||||
y += FONT_HEIGHT_NORMAL + 2;
|
||||
|
||||
for (int i = 0; i < _sorted_standard_cargo_specs_size; i++) {
|
||||
const CargoSpec *cs = _sorted_cargo_specs[i];
|
||||
if(cs == NULL) continue;
|
||||
int cargoid = cs->Index();
|
||||
if (HasBit(st->goods[cargoid].status, GoodsEntry::GES_RATING)) {
|
||||
SetDParam(0, cs->name);
|
||||
SetDParam(1, cargoid);
|
||||
SetDParam(2, st->goods[cargoid].cargo.TotalCount());
|
||||
SetDParam(3, ToPercent8(st->goods[cargoid].rating));
|
||||
|
||||
this->DrawSpriteIcons(cs->GetCargoIcon(), left, y + icon_ofs);
|
||||
DrawString(left + icons_width, r.right - WD_FRAMERECT_RIGHT, y + text_ofs, STR_TTE_STATION);
|
||||
y += line_height;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
if (!_cursor.in_window) {
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSpriteIcons(SpriteID sprite, int left, int top) const
|
||||
{
|
||||
uint step = ScaleGUITrad(10);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
DrawSprite(sprite, PAL_NONE, left + i * step, top);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const NWidgetPart _nested_station_rating_tooltip_widgets[] = {
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(64, 32), EndContainer(),
|
||||
@@ -1580,7 +1353,7 @@ static WindowDesc _station_rating_tooltip_desc(
|
||||
WDP_MANUAL, NULL, 0, 0,
|
||||
WC_STATION_RATING_TOOLTIP, WC_NONE,
|
||||
0,
|
||||
_nested_tooltips_extra_widgets, lengthof(_nested_station_rating_tooltip_widgets)
|
||||
_nested_station_rating_tooltip_widgets, lengthof(_nested_station_rating_tooltip_widgets)
|
||||
);
|
||||
|
||||
static const int STATION_RATING_AGE[] = {0, 10, 20, 33};
|
||||
@@ -1807,12 +1580,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void GuiShowTooltipsExtra(Window *parent, uint param, TooltipCloseCondition close_tooltip)
|
||||
{
|
||||
DeleteWindowById(WC_TOOLTIPS_EXTRA, 0);
|
||||
new TooltipsExtraWindow(parent, param, close_tooltip);
|
||||
}
|
||||
|
||||
void GuiShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs) {
|
||||
DeleteWindowById(WC_STATION_RATING_TOOLTIP, 0);
|
||||
new StationRatingTooltipWindow(parent, st, cs);
|
||||
|
||||
Reference in New Issue
Block a user