Plans: Remove visibility/window code from CmdAddPlan, use callback

This commit is contained in:
Jonathan G Rennison 2024-02-26 21:24:59 +00:00
parent a20f862cd0
commit e5a34feaed
2 changed files with 4 additions and 12 deletions

View File

@ -22,7 +22,7 @@
* Create a new plan.
* @param tile unused
* @param flags type of operation
* @param p1 owner of the plan
* @param p1 unused
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
@ -30,16 +30,8 @@
CommandCost CmdAddPlan(TileIndex tile, DoCommandFlag flags, uint32_t p1, uint32_t p2, const char *text)
{
if (!Plan::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_PLANS);
Owner o = (Owner) p1;
CommandCost ret = CheckOwnership(o);
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
_new_plan = new Plan(o);
if (o == _local_company) {
_new_plan->SetVisibility(true);
Window *w = FindWindowById(WC_PLANS, 0);
if (w) w->InvalidateData(INVALID_PLAN, false);
}
_new_plan = new Plan(_current_company);
}
return CommandCost();
}

View File

@ -113,7 +113,7 @@ struct PlansWindow : Window {
{
switch (widget) {
case WID_PLN_NEW:
DoCommandP(0, _local_company, 0, CMD_ADD_PLAN, CcAddPlan);
DoCommandP(0, 0, 0, CMD_ADD_PLAN, CcAddPlan);
break;
case WID_PLN_ADD_LINES:
if (_current_plan) HandlePlacePushButton(this, widget, SPR_CURSOR_MOUSE, HT_POINT | HT_MAP);
@ -510,7 +510,7 @@ void CcAddPlan(const CommandCost &result, TileIndex tile, uint32_t p1, uint32_t
_current_plan->SetVisibility(true);
Window *w = FindWindowById(WC_PLANS, 0);
if (w) {
if (w != nullptr) {
w->InvalidateData(INVALID_PLAN, false);
((PlansWindow *) w)->SelectPlan(_current_plan->index);
if (!w->IsWidgetLowered(WID_PLN_ADD_LINES)) {