Plans: Make it possible to give plans a name.

(cherry picked from commit d9b553f130a6eda36e2eea217785f829d3d8624e)
pull/73/head
keldorkatarn 6 years ago committed by Jonathan G Rennison
parent 2f2937356b
commit 98da7019d6

@ -203,6 +203,7 @@ CommandProc CmdAddPlanLine;
CommandProc CmdRemovePlan;
CommandProc CmdRemovePlanLine;
CommandProc CmdChangePlanVisibility;
CommandProc CmdRenamePlan;
#define DEF_CMD(proc, flags, type) {proc, #proc, (CommandFlags)flags, type}
@ -366,6 +367,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(CmdRenamePlan, CMD_NO_TEST, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PLAN
};
/*!

@ -334,6 +334,7 @@ enum Commands {
CMD_REMOVE_PLAN,
CMD_REMOVE_PLAN_LINE,
CMD_CHANGE_PLAN_VISIBILITY,
CMD_RENAME_PLAN,
CMD_END, ///< Must ALWAYS be on the end of this list!! (period)
};

@ -4105,8 +4105,10 @@ STR_PLANS_VISIBILITY_TOOLTIP :{BLACK}Toggle t
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})
STR_PLANS_LIST_ITEM_NAMED_PLAN :{RAW_STRING}: {NUM} line{P "" s} ({DATE_SHORT})
STR_PLANS_LIST_ITEM_LINE : -- Line #{NUM}: {NUM} segment{P "" s}
STR_PLANS_LIST_TOOLTIP :{BLACK}Double click any item in the list to (un)fold the related plan.{}Ctrl+Click to scroll to.
STR_PLANS_QUERY_RENAME_PLAN :{WHITE}Rename plan
# Vehicle loading indicators
STR_PERCENT_UP_SMALL :{TINY_FONT}{WHITE}{NUM}%{UP_ARROW}
@ -4534,6 +4536,7 @@ STR_ERROR_CAN_T_DELETE_SIGN :{WHITE}Can't de
STR_ERROR_TOO_MANY_PLANS :{WHITE}... too many plans
STR_ERROR_TOO_MANY_NODES :{WHITE}... too many nodes in plan line
STR_ERROR_NO_MORE_SPACE_FOR_LINES :{WHITE}No more space for lines
STR_ERROR_CAN_T_RENAME_PLAN :{WHITE}Can't rename plan...
# Translatable comment for OpenTTD's desktop shortcut
STR_DESKTOP_SHORTCUT_COMMENT :A simulation game based on Transport Tycoon Deluxe

@ -21,6 +21,7 @@
#include "date_func.h"
#include "viewport_func.h"
#include "core/endian_func.hpp"
#include <string>
#include <vector>
typedef Pool<Plan, PlanID, 16, 64000> PlanPool;
@ -164,6 +165,7 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> {
bool visible_by_all;
bool show_lines;
Date creation_date;
std::string name;
Plan(Owner owner = INVALID_OWNER)
{
@ -247,12 +249,22 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> {
return this->visible;
}
bool HasName() const
{
return !this->name.empty();
}
bool ToggleVisibilityByAll()
{
if (_current_plan->owner == _local_company) DoCommandP(0, _current_plan->index, !this->visible_by_all, CMD_CHANGE_PLAN_VISIBILITY);
return this->visible_by_all;
}
const std::string &GetName() const
{
return this->name;
}
TileIndex CalculateCentreTile() const
{
uint64 x = 0;

@ -15,6 +15,7 @@
#include "plans_func.h"
#include "window_func.h"
#include "company_func.h"
#include "string_func.h"
#include "window_gui.h"
#include "table/strings.h"
@ -157,3 +158,31 @@ CommandCost CmdRemovePlanLine(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
}
return CommandCost();
}
/**
* Give a custom name to your plan
* @param tile unused
* @param flags type of operation
* @param p1 ID of plan to name
* @param p2 unused
* @param text the new name
* @return the cost of this operation or an error
*/
CommandCost CmdRenamePlan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
if (text == NULL) return CMD_ERROR;
Plan *p = Plan::GetIfValid(p1);
if (p == NULL) return CMD_ERROR;
CommandCost ret = CheckOwnership(p->owner);
if (ret.Failed()) return ret;
if (Utf8StringLength(text) >= MAX_LENGTH_PLAN_NAME_CHARS) return CMD_ERROR;
if (flags & DC_EXEC) {
p->name = text;
InvalidateWindowClassesData(WC_PLANS);
}
return CommandCost();
}

@ -20,6 +20,7 @@
#include "window_func.h"
#include "viewport_func.h"
#include "gfx_func.h"
#include "textbuf_gui.h"
#include "tilehighlight_func.h"
#include "strings_func.h"
#include "core/pool_func.hpp"
@ -56,6 +57,7 @@ static const NWidgetPart _nested_plans_widgets[] = {
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),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_DELETE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_DELETE, STR_PLANS_DELETE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_RENAME), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_NULL),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(),
EndContainer(),
@ -126,6 +128,16 @@ struct PlansWindow : Window {
this->SetWidgetDirty(WID_PLN_LIST);
break;
}
case WID_PLN_RENAME: {
if (_current_plan) {
SetDParamStr(0, _current_plan->GetName().c_str());
ShowQueryString(STR_JUST_RAW_STRING, STR_PLANS_QUERY_RENAME_PLAN,
MAX_LENGTH_PLAN_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_LEN_IN_CHARS);
}
break;
}
case WID_PLN_SHOW_ALL: {
Plan *p;
FOR_ALL_PLANS(p) {
@ -187,6 +199,13 @@ struct PlansWindow : Window {
}
}
virtual void OnQueryTextFinished(char *str)
{
if (_current_plan == nullptr || str == nullptr) return;
DoCommandP(0, _current_plan->index, 0, CMD_RENAME_PLAN | CMD_MSG(STR_ERROR_CAN_T_RENAME_PLAN), NULL, str);
}
bool AllPlansHidden() const
{
Plan *p;
@ -202,10 +221,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, WIDGET_LIST_END);
this->SetWidgetsDisabledState(_current_plan->owner != _local_company, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, 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, WIDGET_LIST_END);
this->SetWidgetsDisabledState(true, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WIDGET_LIST_END);
}
this->DrawWidgets();
}
@ -235,10 +254,14 @@ struct PlansWindow : Window {
if (list[i].is_plan) {
DrawCompanyIcon(p->owner, icon_left, y + (this->resize.step_height - this->company_icon_spr_dim.height) / 2);
DrawBoolButton(btn_left, y + (this->resize.step_height - SETTING_BUTTON_HEIGHT) / 2, p->visible, true);
SetDParam(0, list[i].plan_id + 1);
if (p->HasName()) {
SetDParamStr(0, p->GetName().c_str());
} else {
SetDParam(0, list[i].plan_id + 1);
}
SetDParam(1, p->lines.size());
SetDParam(2, p->creation_date);
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, STR_PLANS_LIST_ITEM_PLAN, p->visible_by_all ? TC_LIGHT_BLUE : TC_YELLOW);
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, p->HasName() ? STR_PLANS_LIST_ITEM_NAMED_PLAN : STR_PLANS_LIST_ITEM_PLAN, p->visible_by_all ? TC_LIGHT_BLUE : TC_YELLOW);
} else {
PlanLine *pl = p->lines[list[i].line_id];
DrawBoolButton(btn_left, y + (this->resize.step_height - SETTING_BUTTON_HEIGHT) / 2, pl->visible, true);

@ -20,6 +20,8 @@ typedef uint16 PlanID;
struct PlanLine;
struct Plan;
static const uint MAX_LENGTH_PLAN_NAME_CHARS = 128; ///< The maximum length of a plan name in characters including '\0'
static const PlanID INVALID_PLAN = 0xFFFF; ///< Sentinel for an invalid plan.
#endif /* PLANS_TYPE_H */

@ -45,7 +45,7 @@ std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_ENH_VIEWPORT_PLANS, XSCF_IGNORABLE_ALL, 2, 2, "enh_viewport_plans", NULL, NULL, "PLAN" },
{ XSLFI_ENH_VIEWPORT_PLANS, XSCF_IGNORABLE_ALL, 3, 3, "enh_viewport_plans", NULL, NULL, "PLAN" },
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
};

@ -21,6 +21,7 @@ static const SaveLoad _plan_desc[] = {
SLE_VAR(Plan, visible, SLE_BOOL),
SLE_VAR(Plan, visible_by_all, SLE_BOOL),
SLE_VAR(Plan, creation_date, SLE_INT32),
SLE_CONDSTDSTR_X(Plan, name, 0, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ENH_VIEWPORT_PLANS, 3)),
SLE_END()
};

@ -24,6 +24,7 @@ enum PlansWidgets {
WID_PLN_SHOW_ALL,
WID_PLN_DELETE,
WID_PLN_HIDE_ALL_SEL,
WID_PLN_RENAME,
};
#endif /* WIDGETS_PLANS_WIDGET_H */

Loading…
Cancel
Save