Plans: Allow taking ownership of unowned plans
Except for unauthed network clients
This commit is contained in:
@@ -315,6 +315,7 @@ CommandProc CmdRemovePlanLine;
|
||||
CommandProc CmdChangePlanVisibility;
|
||||
CommandProc CmdChangePlanColour;
|
||||
CommandProc CmdRenamePlan;
|
||||
CommandProc CmdAcquireUnownedPlan;
|
||||
|
||||
CommandProc CmdDesyncCheck;
|
||||
|
||||
@@ -581,6 +582,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdChangePlanVisibility, 0, CMDT_OTHER_MANAGEMENT ), // CMD_CHANGE_PLAN_VISIBILITY
|
||||
DEF_CMD(CmdChangePlanColour, 0, CMDT_OTHER_MANAGEMENT ), // CMD_CHANGE_PLAN_COLOUR
|
||||
DEF_CMD(CmdRenamePlan, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_PLAN
|
||||
DEF_CMD(CmdAcquireUnownedPlan, CMD_SERVER_NS, CMDT_OTHER_MANAGEMENT ), // CMD_ACQUIRE_UNOWNED_PLAN
|
||||
|
||||
DEF_CMD(CmdDesyncCheck, CMD_SERVER, CMDT_SERVER_SETTING ), // CMD_DESYNC_CHECK
|
||||
};
|
||||
|
@@ -531,6 +531,7 @@ enum Commands {
|
||||
CMD_CHANGE_PLAN_VISIBILITY,
|
||||
CMD_CHANGE_PLAN_COLOUR,
|
||||
CMD_RENAME_PLAN,
|
||||
CMD_ACQUIRE_UNOWNED_PLAN,
|
||||
|
||||
CMD_DESYNC_CHECK, ///< Force desync checks to be run
|
||||
|
||||
|
@@ -1854,6 +1854,8 @@ 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_TAKE_OWNERSHIP :{BLACK}Take ownership
|
||||
STR_PLANS_TAKE_OWNERSHIP_TOOLTIP :{BLACK}Take ownership of the selected unowned item in the list
|
||||
STR_PLANS_LIST_ITEM_PLAN_PRIVATE :[Private]: {STRING3}
|
||||
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})
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "plans_func.h"
|
||||
#include "window_func.h"
|
||||
#include "company_func.h"
|
||||
#include "company_base.h"
|
||||
#include "string_func.h"
|
||||
#include "window_gui.h"
|
||||
#include "table/strings.h"
|
||||
@@ -247,3 +248,32 @@ CommandCost CmdRenamePlan(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire an unowned plan
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 ID of plan
|
||||
* @param p2 unused
|
||||
* @param text unused
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdAcquireUnownedPlan(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
|
||||
{
|
||||
Plan *p = Plan::GetIfValid(p1);
|
||||
if (p == nullptr) return CMD_ERROR;
|
||||
if (Company::IsValidID(p->owner)) return CMD_ERROR;
|
||||
if (!Company::IsValidID(_current_company)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
p->owner = _current_company;
|
||||
InvalidateWindowClassesData(WC_PLANS);
|
||||
if (p->visible) {
|
||||
for (PlanLine *line : p->lines) {
|
||||
if (line->visible) line->MarkDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
@@ -59,7 +59,10 @@ static constexpr 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(NWID_SELECTION, INVALID_COLOUR, WID_PLN_RENAME_SEL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_RENAME), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_NULL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_TAKE_OWNERSHIP), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_TAKE_OWNERSHIP, STR_PLANS_TAKE_OWNERSHIP_TOOLTIP),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
||||
EndContainer(),
|
||||
@@ -82,6 +85,7 @@ struct PlansWindow : Window {
|
||||
|
||||
Scrollbar *vscroll;
|
||||
NWidgetStacked *hide_all_sel;
|
||||
NWidgetStacked *rename_sel;
|
||||
std::vector<ListItem> list; ///< The translation table linking panel indices to their related PlanID.
|
||||
int selected; ///< What item is currently selected in the panel.
|
||||
uint vis_btn_left; ///< left offset of visibility button
|
||||
@@ -94,6 +98,8 @@ struct PlansWindow : Window {
|
||||
this->vscroll = this->GetScrollbar(WID_PLN_SCROLLBAR);
|
||||
this->hide_all_sel = this->GetWidget<NWidgetStacked>(WID_PLN_HIDE_ALL_SEL);
|
||||
this->hide_all_sel->SetDisplayedPlane(0);
|
||||
this->rename_sel = this->GetWidget<NWidgetStacked>(WID_PLN_RENAME_SEL);
|
||||
this->rename_sel->SetDisplayedPlane(0);
|
||||
this->FinishInitNested();
|
||||
|
||||
this->selected = INT_MAX;
|
||||
@@ -145,6 +151,13 @@ struct PlansWindow : Window {
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_PLN_TAKE_OWNERSHIP: {
|
||||
if (_current_plan != nullptr && !IsNonAdminNetworkClient()) {
|
||||
DoCommandP(0, this->list[this->selected].plan_id, 0, CMD_ACQUIRE_UNOWNED_PLAN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_PLN_SHOW_ALL: {
|
||||
for (Plan *p : Plan::Iterate()) {
|
||||
if (p->IsListable()) p->SetVisibility(true);
|
||||
@@ -255,11 +268,14 @@ struct PlansWindow : Window {
|
||||
this->SetWidgetDisabledState(WID_PLN_HIDE_ALL, this->vscroll->GetCount() == 0);
|
||||
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) {
|
||||
if (_current_plan != nullptr) {
|
||||
this->SetWidgetsDisabledState(_current_plan->owner != _local_company, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WID_PLN_COLOUR);
|
||||
this->GetWidget<NWidgetCore>(WID_PLN_VISIBILITY)->widget_data = _current_plan->visible_by_all ? STR_PLANS_VISIBILITY_PRIVATE : STR_PLANS_VISIBILITY_PUBLIC;
|
||||
this->SetWidgetDisabledState(WID_PLN_TAKE_OWNERSHIP, Company::IsValidID(_current_plan->owner) || IsNonAdminNetworkClient());
|
||||
this->rename_sel->SetDisplayedPlane(Company::IsValidID(_current_plan->owner) || !Company::IsValidID(_current_company) ? 0 : 1);
|
||||
} else {
|
||||
this->SetWidgetsDisabledState(true, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WID_PLN_COLOUR);
|
||||
this->SetWidgetsDisabledState(true, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WID_PLN_RENAME, WID_PLN_COLOUR, WID_PLN_TAKE_OWNERSHIP);
|
||||
this->rename_sel->SetDisplayedPlane(0);
|
||||
}
|
||||
this->DrawWidgets();
|
||||
}
|
||||
@@ -369,6 +385,10 @@ struct PlansWindow : Window {
|
||||
case WID_PLN_RENAME:
|
||||
*size = adddim(GetStringBoundingBox(STR_BUTTON_RENAME), padding);
|
||||
break;
|
||||
|
||||
case WID_PLN_TAKE_OWNERSHIP:
|
||||
*size = adddim(GetStringBoundingBox(STR_PLANS_TAKE_OWNERSHIP), padding);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,8 @@ enum PlansWidgets : WidgetID {
|
||||
WID_PLN_DELETE,
|
||||
WID_PLN_HIDE_ALL_SEL,
|
||||
WID_PLN_RENAME,
|
||||
WID_PLN_RENAME_SEL,
|
||||
WID_PLN_TAKE_OWNERSHIP,
|
||||
};
|
||||
|
||||
#endif /* WIDGETS_PLANS_WIDGET_H */
|
||||
|
Reference in New Issue
Block a user