latest novapolis client for 1.5

--HG--
branch : novattd150
This commit is contained in:
Pavel Stupnikov
2015-03-16 03:20:50 +03:00
parent d201932121
commit e48d2d58e0
69 changed files with 3756 additions and 486 deletions

View File

@@ -33,6 +33,14 @@
#include "safeguards.h"
#include "house.h"
#include "town_map.h"
#include "station_base.h"
#include "viewport_func.h"
#include "industry.h"
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.
@@ -164,6 +172,7 @@ public:
td.airport_tile_name = STR_NULL;
td.rail_speed = 0;
td.road_speed = 0;
td.population = 0;
td.grf = NULL;
@@ -293,6 +302,13 @@ public:
line_nr++;
}
/* House pop */
if (td.population != 0) {
SetDParam(0, td.population);
GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_POP, lastof(this->landinfo_data[line_nr]));
line_nr++;
}
assert(line_nr < LAND_INFO_CENTERED_LINES);
/* Mark last line empty */
@@ -1208,3 +1224,229 @@ void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallback
new QueryWindow(&_query_desc, caption, message, parent, callback);
}
/** Window for displaying a tooltip. */
void GuiPrepareTooltipsExtra(Window *parent){
const Point p = GetTileBelowCursor();
const TileIndex tile = TileVirtXY(p.x, p.y);
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);
}
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.size.y + _cursor.offs.y + 5, scr_top, scr_bot);
if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.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)
{
static const uint LINE_HEIGHT = FONT_HEIGHT_NORMAL + 2;
size->width = 200;
size->height = LINE_HEIGHT + 4;
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 + 50, size->width);
}
break;
}
case MP_STATION: {
const Station *st = Station::GetIfValid((StationID)this->objIndex);
if(st == NULL) break;
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 + 50, size->width);
}
}
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
{
static const uint LINE_HEIGHT = FONT_HEIGHT_NORMAL + 2;
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 += LINE_HEIGHT;
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);
DrawString(left + 40, r.right - WD_FRAMERECT_RIGHT, y, STR_TTE_INDUSTRY);
y += LINE_HEIGHT;
}
break;
}
case MP_STATION: {
uint pars = 0;
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 += LINE_HEIGHT;
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);
DrawString(left + 40, r.right - WD_FRAMERECT_RIGHT, y, STR_TTE_STATION);
y += LINE_HEIGHT;
}
}
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_LEFT_CLICK: if (!_left_button_down) delete this; break;
case TCC_HOVER: if (!_mouse_hovering) delete this; break;
}
}
void DrawSpriteIcons(SpriteID sprite, int left, int top) const
{
for(int i = 0; i < 30; i += 10) {
DrawSprite(sprite, PAL_NONE, left + i, top);
}
}
};
void GuiShowTooltipsExtra(Window *parent, uint param, TooltipCloseCondition close_tooltip)
{
DeleteWindowById(WC_TOOLTIPS_EXTRA, 0);
new TooltipsExtraWindow(parent, param, close_tooltip);
}