Take over and improve default station building highlight
This commit is contained in:
@@ -460,7 +460,8 @@ public:
|
||||
this->SetWidgetDisabledState(WID_AP_LAYOUT_INCREASE, _selected_airport_layout + 1 >= as->num_table);
|
||||
|
||||
int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
|
||||
if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
//if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../industry.h"
|
||||
#include "../town.h"
|
||||
#include "../tilearea_type.h"
|
||||
#include "../tilehighlight_type.h"
|
||||
#include "../viewport_func.h"
|
||||
#include "../zoning.h"
|
||||
|
||||
@@ -19,6 +20,8 @@ enum FoundationPart {
|
||||
};
|
||||
extern void DrawSelectionSprite(SpriteID image, PaletteID pal, const TileInfo *ti, int z_offset, FoundationPart foundation_part); // viewport.cpp
|
||||
extern const Station *_viewport_highlight_station;
|
||||
extern TileHighlightData _thd;
|
||||
extern bool IsInsideSelectedRectangle(int x, int y);
|
||||
|
||||
namespace citymania {
|
||||
|
||||
@@ -31,6 +34,12 @@ struct TileZoning {
|
||||
|
||||
static TileZoning *_mz = nullptr;
|
||||
static IndustryType _industry_forbidden_tiles = INVALID_INDUSTRYTYPE;
|
||||
BuildingPossibility _station_possibility = BuildingPossibility::OK;
|
||||
// struct {
|
||||
// int w;
|
||||
// int h;
|
||||
// int catchment;
|
||||
// } _station_select;
|
||||
|
||||
const byte _tileh_to_sprite[32] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
|
||||
@@ -222,23 +231,40 @@ TileHighlight GetTileHighlight(const TileInfo *ti) {
|
||||
th.ground_pal = th.structure_pal = PALETTE_TINT_RED;
|
||||
}
|
||||
|
||||
if (_viewport_highlight_station != nullptr) {
|
||||
auto getter = [](TileIndex t) {
|
||||
if (IsTileType(t, MP_STATION) && GetStationIndex(t) == _viewport_highlight_station->index) return 2;
|
||||
if (_viewport_highlight_station->TileIsInCatchment(t)) return 1;
|
||||
return 0;
|
||||
};
|
||||
auto b = CalcTileBorders(ti->tile, getter);
|
||||
if(b.first != ZoningBorder::NONE) {
|
||||
th.border = b.first;
|
||||
bool draw_coverage = false;
|
||||
bool draw_selection = false;
|
||||
if ((_thd.drawstyle & HT_DRAG_MASK) == HT_RECT && _thd.outersize.x > 0) {
|
||||
// we have station selected
|
||||
draw_selection = true;
|
||||
draw_coverage = _settings_client.gui.station_show_coverage;
|
||||
}
|
||||
auto getter = [draw_selection, draw_coverage](TileIndex t) {
|
||||
auto x = TileX(t) * TILE_SIZE, y = TileY(t) * TILE_SIZE;
|
||||
if (draw_selection && IsInsideSelectedRectangle(x, y)) return 3;
|
||||
if (_viewport_highlight_station && IsTileType(t, MP_STATION) && GetStationIndex(t) == _viewport_highlight_station->index) return 2;
|
||||
if (_viewport_highlight_station && _viewport_highlight_station->TileIsInCatchment(t)) return 1;
|
||||
if (draw_coverage && IsInsideBS(x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
|
||||
IsInsideBS(y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) return 1;
|
||||
return 0;
|
||||
};
|
||||
auto b = CalcTileBorders(ti->tile, getter);
|
||||
if(b.first != ZoningBorder::NONE) {
|
||||
th.border = b.first;
|
||||
if (b.second == 3) {
|
||||
const SpriteID pal[] = {SPR_PALETTE_ZONING_RED, SPR_PALETTE_ZONING_YELLOW, SPR_PALETTE_ZONING_GREEN};
|
||||
th.border_color = pal[(int)_station_possibility];
|
||||
} else {
|
||||
const SpriteID pal[] = {PAL_NONE, SPR_PALETTE_ZONING_WHITE, SPR_PALETTE_ZONING_LIGHT_BLUE};
|
||||
th.border_color = pal[b.second];
|
||||
}
|
||||
auto z = getter(ti->tile);
|
||||
if (z) {
|
||||
const SpriteID pal[] = {PAL_NONE, PALETTE_TINT_WHITE, PALETTE_TINT_CYAN_DEEP};
|
||||
th.ground_pal = th.structure_pal = pal[z];
|
||||
}
|
||||
}
|
||||
auto z = getter(ti->tile);
|
||||
if (z == 3) {
|
||||
const SpriteID pal[] = {PALETTE_TINT_RED, PALETTE_TINT_YELLOW, PALETTE_TINT_GREEN};
|
||||
th.ground_pal = th.structure_pal = pal[(int)_station_possibility];
|
||||
} else if (z) {
|
||||
const SpriteID pal[] = {PAL_NONE, PALETTE_TINT_WHITE, PALETTE_TINT_CYAN_DEEP, PALETTE_TINT_GREEN_DEEP};
|
||||
th.ground_pal = th.structure_pal = pal[z];
|
||||
}
|
||||
|
||||
return th;
|
||||
@@ -376,4 +402,15 @@ void SetIndustryForbiddenTilesHighlight(IndustryType type) {
|
||||
_industry_forbidden_tiles = type;
|
||||
}
|
||||
|
||||
// void SetStationTileSelectSize(int w, int h, int catchment) {
|
||||
// _station_select.w = w;
|
||||
// _station_select.h = h;
|
||||
// _station_select.catchment = catchment;
|
||||
// }
|
||||
|
||||
void SetStationBiildingPossibility(BuildingPossibility possibility) {
|
||||
_station_possibility = possibility;
|
||||
};
|
||||
|
||||
|
||||
} // namespace citymania
|
||||
|
||||
@@ -26,6 +26,12 @@ enum ZoningBorder: uint8 {
|
||||
FULL = TOP_LEFT | TOP_RIGHT | BOTTOM_LEFT | BOTTOM_RIGHT,
|
||||
};
|
||||
|
||||
enum class BuildingPossibility {
|
||||
IMPOSSIBLE = 0,
|
||||
QUERY = 1,
|
||||
OK = 2,
|
||||
};
|
||||
|
||||
class TileHighlight {
|
||||
public:
|
||||
SpriteID ground_pal = PAL_NONE;
|
||||
@@ -46,9 +52,12 @@ DECLARE_ENUM_AS_BIT_SET(ZoningBorder);
|
||||
// };
|
||||
|
||||
|
||||
void SetStationBiildingPossibility(BuildingPossibility possibility);
|
||||
TileHighlight GetTileHighlight(const TileInfo *ti);
|
||||
void DrawTileSelection(const TileInfo *ti, const TileHighlight &th);
|
||||
|
||||
void SetStationTileSelectSize(int w, int h, int catchment);
|
||||
|
||||
void AllocateZoningMap(uint map_size);
|
||||
void InitializeZoningMap();
|
||||
|
||||
|
||||
@@ -419,11 +419,15 @@ public:
|
||||
|
||||
this->DrawWidgets();
|
||||
|
||||
SetTileSelectSize(1, 1);
|
||||
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
#if 0
|
||||
if (_settings_client.gui.station_show_coverage) {
|
||||
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
} else {
|
||||
SetTileSelectSize(1, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* strings such as 'Size' and 'Coverage Area' */
|
||||
int top = this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->pos_y + this->GetWidget<NWidgetBase>(BDSW_LT_OFF)->current_y + WD_PAR_VSEP_NORMAL;
|
||||
|
||||
@@ -1212,7 +1212,8 @@ public:
|
||||
|
||||
int rad = (_settings_game.station.modified_catchment) ? CA_TRAIN : CA_UNMODIFIED;
|
||||
|
||||
if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
//if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); // always let cm zoning know we're selecting station
|
||||
|
||||
for (uint bits = 0; bits < 7; bits++) {
|
||||
bool disable = bits >= _settings_game.station.station_spread;
|
||||
|
||||
@@ -83,4 +83,4 @@ const byte _openttd_revision_tagged = 1;
|
||||
const uint32 _openttd_newgrf_version = 1 << 28 | 10 << 24 | 0 << 20 | 0 << 19 | 28004;
|
||||
|
||||
|
||||
const char _citymania_version[] = "20200206-master-m0aab21535c 06.02.20";
|
||||
const char _citymania_version[] = "20200206-master-me7f1df5454 06.02.20";
|
||||
|
||||
@@ -1246,11 +1246,12 @@ struct BuildRoadStationWindow : public PickerWindowBase {
|
||||
this->DrawWidgets();
|
||||
|
||||
int rad = _settings_game.station.modified_catchment ? ((this->window_class == WC_BUS_STATION) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
|
||||
if (_settings_client.gui.station_show_coverage) {
|
||||
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
} else {
|
||||
SetTileSelectSize(1, 1);
|
||||
}
|
||||
SetTileSelectSize(1, 1);
|
||||
// if (_settings_client.gui.station_show_coverage) {
|
||||
SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
||||
// } else {
|
||||
// SetTileSelectSize(1, 1);
|
||||
// }
|
||||
|
||||
/* 'Accepts' and 'Supplies' texts. */
|
||||
StationCoverageType sct = (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "citymania/zoning.hpp"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
/**
|
||||
@@ -104,6 +106,7 @@ static void FindStationsAroundSelection()
|
||||
/* With distant join we don't know which station will be selected, so don't show any */
|
||||
if (_ctrl_pressed) {
|
||||
SetViewportCatchmentStation(nullptr, true);
|
||||
citymania::SetStationBiildingPossibility(citymania::BuildingPossibility::QUERY);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,6 +121,7 @@ static void FindStationsAroundSelection()
|
||||
TileArea ta(TileXY(max<int>(0, x - max_c), max<int>(0, y - max_c)), TileXY(min<int>(MapMaxX(), x + location.w + max_c), min<int>(MapMaxY(), y + location.h + max_c)));
|
||||
|
||||
Station *adjacent = nullptr;
|
||||
auto cmbp = citymania::BuildingPossibility::OK;
|
||||
|
||||
/* Direct loop instead of FindStationsAroundTiles as we are not interested in catchment area */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
@@ -127,12 +131,14 @@ static void FindStationsAroundSelection()
|
||||
if (adjacent != nullptr && st != adjacent) {
|
||||
/* Multiple nearby, distant join is required. */
|
||||
adjacent = nullptr;
|
||||
cmbp =(_ctrl_pressed ? citymania::BuildingPossibility::QUERY : citymania::BuildingPossibility::IMPOSSIBLE);
|
||||
break;
|
||||
}
|
||||
adjacent = st;
|
||||
}
|
||||
}
|
||||
SetViewportCatchmentStation(adjacent, true);
|
||||
citymania::SetStationBiildingPossibility(cmbp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2448,11 +2454,13 @@ struct SelectStationWindow : WindowPopup {
|
||||
{
|
||||
if (widget != WID_JS_PANEL || T::EXPECTED_FACIL == FACIL_WAYPOINT) {
|
||||
SetViewportCatchmentStation(nullptr, true);
|
||||
citymania::SetStationBiildingPossibility(citymania::BuildingPossibility::QUERY);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Show coverage area of station under cursor */
|
||||
uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP);
|
||||
citymania::SetStationBiildingPossibility(citymania::BuildingPossibility::OK);
|
||||
if (st_index == 0 || st_index > _stations_nearby_list.size()) {
|
||||
SetViewportCatchmentStation(nullptr, true);
|
||||
} else {
|
||||
|
||||
@@ -832,7 +832,7 @@ static bool IsInRangeInclusive(int begin, int end, int check)
|
||||
* @param y The y coordinate of the point to be checked.
|
||||
* @return True if the point is inside the rectangle, else false.
|
||||
*/
|
||||
static bool IsInsideSelectedRectangle(int x, int y)
|
||||
bool IsInsideSelectedRectangle(int x, int y)
|
||||
{
|
||||
if (!_thd.diagonal) {
|
||||
return IsInsideBS(x, _thd.pos.x, _thd.size.x) && IsInsideBS(y, _thd.pos.y, _thd.size.y);
|
||||
@@ -1126,6 +1126,11 @@ static void DrawTileSelection(const TileInfo *ti)
|
||||
TileHighlightType tht = GetTileHighlightType(ti->tile);
|
||||
DrawTileHighlightType(ti, tht);
|
||||
|
||||
if ((_thd.drawstyle & HT_DRAG_MASK) == HT_RECT && _thd.outersize.x > 0) {
|
||||
// station selector, handled by citymania highlight
|
||||
return;
|
||||
}
|
||||
|
||||
switch (_thd.drawstyle & HT_DRAG_MASK) {
|
||||
default: break; // No tile selection active?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user