Allow changing the colour of plans
This commit is contained in:
@@ -269,6 +269,7 @@ CommandProcEx CmdAddPlanLine;
|
||||
CommandProc CmdRemovePlan;
|
||||
CommandProc CmdRemovePlanLine;
|
||||
CommandProc CmdChangePlanVisibility;
|
||||
CommandProc CmdChangePlanColour;
|
||||
CommandProc CmdRenamePlan;
|
||||
|
||||
CommandProc CmdDesyncCheck;
|
||||
@@ -498,6 +499,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdRemovePlan, CMD_NO_TEST, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_PLAN
|
||||
DEF_CMD(CmdRemovePlanLine, CMD_NO_TEST, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_PLAN_LINE
|
||||
DEF_CMD(CmdChangePlanVisibility, CMD_NO_TEST, CMDT_OTHER_MANAGEMENT ), // CMD_CHANGE_PLAN_VISIBILITY
|
||||
DEF_CMD(CmdChangePlanColour, CMD_NO_TEST, CMDT_OTHER_MANAGEMENT ), // CMD_CHANGE_PLAN_COLOUR
|
||||
DEF_CMD(CmdRenamePlan, CMD_NO_TEST, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PLAN
|
||||
|
||||
DEF_CMD(CmdDesyncCheck, CMD_SERVER, CMDT_SERVER_SETTING ), // CMD_DESYNC_CHECK
|
||||
|
@@ -451,6 +451,7 @@ enum Commands {
|
||||
CMD_REMOVE_PLAN,
|
||||
CMD_REMOVE_PLAN_LINE,
|
||||
CMD_CHANGE_PLAN_VISIBILITY,
|
||||
CMD_CHANGE_PLAN_COLOUR,
|
||||
CMD_RENAME_PLAN,
|
||||
|
||||
CMD_DESYNC_CHECK, ///< Force desync checks to be run
|
||||
|
19
src/gfx.cpp
19
src/gfx.cpp
@@ -57,6 +57,25 @@ static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of ofte
|
||||
DrawPixelInfo *_cur_dpi;
|
||||
byte _colour_gradient[COLOUR_END][8];
|
||||
|
||||
byte _colour_value[COLOUR_END] = {
|
||||
133, // COLOUR_DARK_BLUE
|
||||
99, // COLOUR_PALE_GREEN,
|
||||
48, // COLOUR_PINK,
|
||||
68, // COLOUR_YELLOW,
|
||||
184, // COLOUR_RED,
|
||||
152, // COLOUR_LIGHT_BLUE,
|
||||
209, // COLOUR_GREEN,
|
||||
95, // COLOUR_DARK_GREEN,
|
||||
150, // COLOUR_BLUE,
|
||||
79, // COLOUR_CREAM,
|
||||
134, // COLOUR_MAUVE,
|
||||
174, // COLOUR_PURPLE,
|
||||
195, // COLOUR_ORANGE,
|
||||
116, // COLOUR_BROWN,
|
||||
6, // COLOUR_GREY,
|
||||
15, // COLOUR_WHITE,
|
||||
};
|
||||
|
||||
static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE);
|
||||
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE, ZoomLevel zoom = ZOOM_LVL_NORMAL);
|
||||
|
||||
|
@@ -211,6 +211,7 @@ TextColour GetContrastColour(uint8 background, uint8 threshold = 128);
|
||||
* 8 colours per gradient from darkest (0) to lightest (7)
|
||||
*/
|
||||
extern byte _colour_gradient[COLOUR_END][8];
|
||||
extern byte _colour_value[COLOUR_END];
|
||||
|
||||
extern bool _palette_remap_grf[];
|
||||
|
||||
|
@@ -5224,6 +5224,8 @@ STR_PLANS_SHOW_ALL_TOOLTIP :{BLACK}Set the
|
||||
STR_PLANS_VISIBILITY_PRIVATE :{BLACK}Make private
|
||||
STR_PLANS_VISIBILITY_PUBLIC :{BLACK}Make public
|
||||
STR_PLANS_VISIBILITY_TOOLTIP :{BLACK}Toggle the visibility of a plan (private is yellow, public is blue). A public plan will be displayed in the plan window of the other companies but only its owner can add lines to it.
|
||||
STR_PLANS_COLOUR :{BLACK}Colour
|
||||
STR_PLANS_COLOUR_TOOLTIP :{BLACK}Set the colour of a plan.
|
||||
STR_PLANS_DELETE :{BLACK}Delete
|
||||
STR_PLANS_DELETE_TOOLTIP :{BLACK}Delete the selected item in the list
|
||||
STR_PLANS_LIST_ITEM_PLAN :Plan #{NUM}: {NUM} line{P "" s} ({DATE_SHORT})
|
||||
|
@@ -103,7 +103,7 @@ struct PlanLine {
|
||||
this->visible = visible;
|
||||
}
|
||||
|
||||
void MarkDirty()
|
||||
void MarkDirty() const
|
||||
{
|
||||
const uint sz = (uint) this->tiles.size();
|
||||
for (uint i = 1; i < sz; i++) {
|
||||
@@ -167,6 +167,7 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> {
|
||||
bool show_lines;
|
||||
Date creation_date;
|
||||
std::string name;
|
||||
Colours colour;
|
||||
|
||||
Plan(Owner owner = INVALID_OWNER)
|
||||
{
|
||||
@@ -175,6 +176,7 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> {
|
||||
this->visible = false;
|
||||
this->visible_by_all = false;
|
||||
this->show_lines = false;
|
||||
this->colour = COLOUR_WHITE;
|
||||
this->temp_line = new PlanLine();
|
||||
}
|
||||
|
||||
@@ -261,6 +263,11 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> {
|
||||
return this->visible_by_all;
|
||||
}
|
||||
|
||||
void SetPlanColour(Colours colour)
|
||||
{
|
||||
if (_current_plan->owner == _local_company) DoCommandP(0, _current_plan->index, colour, CMD_CHANGE_PLAN_COLOUR);
|
||||
}
|
||||
|
||||
const std::string &GetName() const
|
||||
{
|
||||
return this->name;
|
||||
|
@@ -103,6 +103,34 @@ CommandCost CmdChangePlanVisibility(TileIndex tile, DoCommandFlag flags, uint32
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the colour of a plan.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 plan id
|
||||
* @param p2 colour
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdChangePlanColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
Plan *p = Plan::GetIfValid(p1);
|
||||
if (p == nullptr) return CMD_ERROR;
|
||||
if (p2 >= COLOUR_END) return CMD_ERROR;
|
||||
CommandCost ret = CheckOwnership(p->owner);
|
||||
if (ret.Failed()) return ret;
|
||||
if (flags & DC_EXEC) {
|
||||
p->colour = (Colours)p2;
|
||||
Window *w = FindWindowById(WC_PLANS, 0);
|
||||
if (w) w->InvalidateData(INVALID_PLAN, false);
|
||||
for (const PlanLine *line : p->lines) {
|
||||
if (line->visible) line->MarkDirty();
|
||||
}
|
||||
if (p->temp_line) p->temp_line->MarkDirty();
|
||||
}
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a plan.
|
||||
* @param tile unused
|
||||
|
@@ -50,6 +50,7 @@ static const NWidgetPart _nested_plans_widgets[] = {
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_NEW), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_NEW_PLAN, STR_NULL),
|
||||
NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_PLN_ADD_LINES), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_ADD_LINES, STR_PLANS_ADDING_LINES),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_PLN_VISIBILITY), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_VISIBILITY_PUBLIC, STR_PLANS_VISIBILITY_TOOLTIP),
|
||||
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_PLN_COLOUR), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_PLANS_COLOUR_TOOLTIP),
|
||||
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_PLN_HIDE_ALL_SEL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_HIDE_ALL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_HIDE_ALL, STR_PLANS_HIDE_ALL_TOOLTIP),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_SHOW_ALL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_SHOW_ALL, STR_PLANS_SHOW_ALL_TOOLTIP),
|
||||
@@ -62,7 +63,7 @@ static const NWidgetPart _nested_plans_widgets[] = {
|
||||
};
|
||||
|
||||
static WindowDesc _plans_desc(
|
||||
WDP_AUTO, "plans", 300, 100,
|
||||
WDP_AUTO, "plans", 350, 100,
|
||||
WC_PLANS, WC_NONE,
|
||||
WDF_CONSTRUCTION,
|
||||
_nested_plans_widgets, lengthof(_nested_plans_widgets)
|
||||
@@ -148,6 +149,25 @@ struct PlansWindow : Window {
|
||||
case WID_PLN_VISIBILITY:
|
||||
if (_current_plan) _current_plan->ToggleVisibilityByAll();
|
||||
break;
|
||||
case WID_PLN_COLOUR: {
|
||||
if (_current_plan) {
|
||||
DropDownList list;
|
||||
auto add_colour = [&](Colours colour) {
|
||||
list.emplace_back(new DropDownListStringItem(STR_COLOUR_DARK_BLUE + colour, colour, false));
|
||||
};
|
||||
add_colour(COLOUR_WHITE);
|
||||
add_colour(COLOUR_YELLOW);
|
||||
add_colour(COLOUR_LIGHT_BLUE);
|
||||
add_colour(COLOUR_BLUE);
|
||||
add_colour(COLOUR_GREEN);
|
||||
add_colour(COLOUR_PURPLE);
|
||||
add_colour(COLOUR_ORANGE);
|
||||
add_colour(COLOUR_BROWN);
|
||||
add_colour(COLOUR_PINK);
|
||||
ShowDropDownList(this, std::move(list), _current_plan->colour, widget);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WID_PLN_LIST: {
|
||||
int new_selected = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_PLN_LIST, WD_FRAMERECT_TOP);
|
||||
if (_ctrl_pressed) {
|
||||
@@ -198,6 +218,17 @@ struct PlansWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnDropdownSelect(int widget, int index) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_PLN_COLOUR:
|
||||
if (_current_plan && index < COLOUR_END) {
|
||||
_current_plan->SetPlanColour((Colours)index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnQueryTextFinished(char *str)
|
||||
{
|
||||
if (_current_plan == nullptr || str == nullptr) return;
|
||||
@@ -219,10 +250,10 @@ struct PlansWindow : Window {
|
||||
this->SetWidgetDisabledState(WID_PLN_SHOW_ALL, this->vscroll->GetCount() == 0);
|
||||
this->hide_all_sel->SetDisplayedPlane(this->vscroll->GetCount() != 0 && this->AllPlansHidden() ? 1 : 0);
|
||||
if (_current_plan) {
|
||||
this->SetWidgetsDisabledState(_current_plan->owner != _local_company, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WIDGET_LIST_END);
|
||||
this->SetWidgetsDisabledState(_current_plan->owner != _local_company, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WID_PLN_COLOUR, WIDGET_LIST_END);
|
||||
this->GetWidget<NWidgetCore>(WID_PLN_VISIBILITY)->widget_data = _current_plan->visible_by_all ? STR_PLANS_VISIBILITY_PRIVATE : STR_PLANS_VISIBILITY_PUBLIC;
|
||||
} else {
|
||||
this->SetWidgetsDisabledState(true, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WIDGET_LIST_END);
|
||||
this->SetWidgetsDisabledState(true, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WID_PLN_COLOUR, WIDGET_LIST_END);
|
||||
}
|
||||
this->DrawWidgets();
|
||||
}
|
||||
@@ -274,6 +305,15 @@ struct PlansWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
void SetStringParameters(int widget) const override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_PLN_COLOUR:
|
||||
SetDParam(0, _current_plan ? STR_COLOUR_DARK_BLUE + _current_plan->colour : STR_PLANS_COLOUR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnResize()
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_PLN_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
|
||||
|
@@ -87,7 +87,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
||||
{ XSLFI_TT_WAIT_IN_DEPOT, XSCF_NULL, 1, 1, "tt_wait_in_depot", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_AUTO_TIMETABLE, XSCF_NULL, 5, 5, "auto_timetables", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_VEHICLE_REPAIR_COST, XSCF_NULL, 2, 2, "vehicle_repair_cost", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_ENH_VIEWPORT_PLANS, XSCF_IGNORABLE_ALL, 3, 3, "enh_viewport_plans", nullptr, nullptr, "PLAN" },
|
||||
{ XSLFI_ENH_VIEWPORT_PLANS, XSCF_IGNORABLE_ALL, 4, 4, "enh_viewport_plans", nullptr, nullptr, "PLAN" },
|
||||
{ XSLFI_INFRA_SHARING, XSCF_NULL, 2, 2, "infra_sharing", nullptr, nullptr, "CPDP" },
|
||||
{ XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 2, 2, "variable_day_length", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 2, 2, "order_occupancy", nullptr, nullptr, nullptr },
|
||||
|
@@ -21,6 +21,7 @@ static const SaveLoad _plan_desc[] = {
|
||||
SLE_VAR(Plan, creation_date, SLE_INT32),
|
||||
SLE_CONDSSSTR_X(Plan, name, 0, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ENH_VIEWPORT_PLANS, 3)),
|
||||
SLE_CONDSSSTR_X(Plan, name, 0, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_JOKERPP, SL_JOKER_1_20)),
|
||||
SLE_CONDVAR_X(Plan, colour, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ENH_VIEWPORT_PLANS, 4)),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
|
@@ -2484,7 +2484,7 @@ void ViewportDrawPlans(const Viewport *vp)
|
||||
if (pl->focused) {
|
||||
GfxDrawLine(from_x, from_y, to_x, to_y, PC_RED, 1);
|
||||
} else {
|
||||
GfxDrawLine(from_x, from_y, to_x, to_y, PC_WHITE, 1);
|
||||
GfxDrawLine(from_x, from_y, to_x, to_y, _colour_value[p->colour], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2511,7 +2511,7 @@ void ViewportDrawPlans(const Viewport *vp)
|
||||
const int to_x = UnScaleByZoom(to_pt.x, vp->zoom);
|
||||
const int to_y = UnScaleByZoom(to_pt.y, vp->zoom);
|
||||
|
||||
GfxDrawLine(from_x, from_y, to_x, to_y, PC_WHITE, 3, 1);
|
||||
GfxDrawLine(from_x, from_y, to_x, to_y, _colour_value[_current_plan->colour], 3, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ enum PlansWidgets {
|
||||
WID_PLN_NEW,
|
||||
WID_PLN_ADD_LINES,
|
||||
WID_PLN_VISIBILITY,
|
||||
WID_PLN_COLOUR,
|
||||
WID_PLN_HIDE_ALL,
|
||||
WID_PLN_SHOW_ALL,
|
||||
WID_PLN_DELETE,
|
||||
|
Reference in New Issue
Block a user