Plans: Remove visibility/window code from CmdAddPlan, use callback
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
* Create a new plan.
|
* Create a new plan.
|
||||||
* @param tile unused
|
* @param tile unused
|
||||||
* @param flags type of operation
|
* @param flags type of operation
|
||||||
* @param p1 owner of the plan
|
* @param p1 unused
|
||||||
* @param p2 unused
|
* @param p2 unused
|
||||||
* @param text unused
|
* @param text unused
|
||||||
* @return the cost of this operation or an error
|
* @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)
|
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);
|
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) {
|
if (flags & DC_EXEC) {
|
||||||
_new_plan = new Plan(o);
|
_new_plan = new Plan(_current_company);
|
||||||
if (o == _local_company) {
|
|
||||||
_new_plan->SetVisibility(true);
|
|
||||||
Window *w = FindWindowById(WC_PLANS, 0);
|
|
||||||
if (w) w->InvalidateData(INVALID_PLAN, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return CommandCost();
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ struct PlansWindow : Window {
|
|||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_PLN_NEW:
|
case WID_PLN_NEW:
|
||||||
DoCommandP(0, _local_company, 0, CMD_ADD_PLAN, CcAddPlan);
|
DoCommandP(0, 0, 0, CMD_ADD_PLAN, CcAddPlan);
|
||||||
break;
|
break;
|
||||||
case WID_PLN_ADD_LINES:
|
case WID_PLN_ADD_LINES:
|
||||||
if (_current_plan) HandlePlacePushButton(this, widget, SPR_CURSOR_MOUSE, HT_POINT | HT_MAP);
|
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);
|
_current_plan->SetVisibility(true);
|
||||||
|
|
||||||
Window *w = FindWindowById(WC_PLANS, 0);
|
Window *w = FindWindowById(WC_PLANS, 0);
|
||||||
if (w) {
|
if (w != nullptr) {
|
||||||
w->InvalidateData(INVALID_PLAN, false);
|
w->InvalidateData(INVALID_PLAN, false);
|
||||||
((PlansWindow *) w)->SelectPlan(_current_plan->index);
|
((PlansWindow *) w)->SelectPlan(_current_plan->index);
|
||||||
if (!w->IsWidgetLowered(WID_PLN_ADD_LINES)) {
|
if (!w->IsWidgetLowered(WID_PLN_ADD_LINES)) {
|
||||||
|
Reference in New Issue
Block a user