mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-22 19:54:06 +01:00
Feature: Signs, waypoint and station names may be moved (#14744)
This commit is contained in:
@@ -13,11 +13,14 @@
|
||||
#include "error.h"
|
||||
#include "gui.h"
|
||||
#include "gfx_layout.h"
|
||||
#include "tilehighlight_func.h"
|
||||
#include "command_func.h"
|
||||
#include "company_func.h"
|
||||
#include "town.h"
|
||||
#include "string_func.h"
|
||||
#include "company_base.h"
|
||||
#include "station_base.h"
|
||||
#include "waypoint_base.h"
|
||||
#include "texteff.hpp"
|
||||
#include "strings_func.h"
|
||||
#include "window_func.h"
|
||||
@@ -27,6 +30,8 @@
|
||||
#include "zoom_func.h"
|
||||
#include "viewport_func.h"
|
||||
#include "landscape_cmd.h"
|
||||
#include "station_cmd.h"
|
||||
#include "waypoint_cmd.h"
|
||||
#include "rev.h"
|
||||
#include "timer/timer.h"
|
||||
#include "timer/timer_window.h"
|
||||
@@ -899,6 +904,8 @@ struct QueryStringWindow : public Window
|
||||
QueryString editbox; ///< Editbox.
|
||||
QueryStringFlags flags{}; ///< Flags controlling behaviour of the window.
|
||||
|
||||
WidgetID last_user_action = INVALID_WIDGET; ///< Last started user action.
|
||||
|
||||
QueryStringWindow(std::string_view str, StringID caption, uint max_bytes, uint max_chars, WindowDesc &desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
|
||||
Window(desc), editbox(max_bytes, max_chars)
|
||||
{
|
||||
@@ -913,7 +920,9 @@ struct QueryStringWindow : public Window
|
||||
this->editbox.text.afilter = afilter;
|
||||
this->flags = flags;
|
||||
|
||||
this->InitNested(WN_QUERY_STRING);
|
||||
this->CreateNestedTree();
|
||||
this->GetWidget<NWidgetStacked>(WID_QS_MOVE_SEL)->SetDisplayedPlane((this->flags.Test(QueryStringFlag::EnableMove)) ? 0 : SZSP_NONE);
|
||||
this->FinishInitNested(WN_QUERY_STRING);
|
||||
|
||||
this->parent = parent;
|
||||
|
||||
@@ -961,16 +970,64 @@ struct QueryStringWindow : public Window
|
||||
case WID_QS_CANCEL:
|
||||
this->Close();
|
||||
break;
|
||||
|
||||
case WID_QS_MOVE:
|
||||
this->last_user_action = widget;
|
||||
|
||||
if (Station::IsExpected(Station::Get(this->parent->window_number))) {
|
||||
/* this is a station */
|
||||
SetViewportStationRect(Station::Get(this->parent->window_number), !this->IsWidgetLowered(WID_QS_MOVE));
|
||||
} else {
|
||||
/* this is a waypoint */
|
||||
SetViewportWaypointRect(Waypoint::Get(this->parent->window_number), !this->IsWidgetLowered(WID_QS_MOVE));
|
||||
}
|
||||
|
||||
HandlePlacePushButton(this, WID_QS_MOVE, SPR_CURSOR_SIGN, HT_RECT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
|
||||
{
|
||||
switch (this->last_user_action) {
|
||||
case WID_QS_MOVE: // Move name button
|
||||
if (Station::IsExpected(Station::Get(this->parent->window_number))) {
|
||||
/* this is a station */
|
||||
Command<CMD_MOVE_STATION_NAME>::Post(STR_ERROR_CAN_T_MOVE_STATION_NAME, CcMoveStationName, this->parent->window_number, tile);
|
||||
} else {
|
||||
/* this is a waypoint */
|
||||
Command<CMD_MOVE_WAYPOINT_NAME>::Post(STR_ERROR_CAN_T_MOVE_WAYPOINT_NAME, CcMoveWaypointName, this->parent->window_number, tile);
|
||||
}
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void OnPlaceObjectAbort() override
|
||||
{
|
||||
if (Station::IsExpected(Station::Get(this->parent->window_number))) {
|
||||
/* this is a station */
|
||||
SetViewportStationRect(Station::Get(this->parent->window_number), false);
|
||||
} else {
|
||||
/* this is a waypoint */
|
||||
SetViewportWaypointRect(Waypoint::Get(this->parent->window_number), false);
|
||||
}
|
||||
|
||||
this->RaiseButtons();
|
||||
}
|
||||
|
||||
void Close([[maybe_unused]] int data = 0) override
|
||||
{
|
||||
if (this->parent->window_class == WC_STATION_VIEW) SetViewportStationRect(Station::Get(this->parent->window_number), false);
|
||||
if (this->parent->window_class == WC_WAYPOINT_VIEW) SetViewportWaypointRect(Waypoint::Get(this->parent->window_number), false);
|
||||
|
||||
if (!this->editbox.handled && this->parent != nullptr) {
|
||||
Window *parent = this->parent;
|
||||
this->parent = nullptr; // so parent doesn't try to close us again
|
||||
parent->OnQueryTextFinished(std::nullopt);
|
||||
}
|
||||
|
||||
this->Window::Close();
|
||||
}
|
||||
};
|
||||
@@ -984,9 +1041,12 @@ static constexpr std::initializer_list<NWidgetPart> _nested_query_string_widgets
|
||||
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_DEFAULT),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_CANCEL),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_OK),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_DEFAULT),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_CANCEL),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_OK),
|
||||
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_QS_MOVE_SEL),
|
||||
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_MOVE), SetMinimalSize(65, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_MOVE),
|
||||
EndContainer(),
|
||||
EndContainer(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user