mirror of https://github.com/OpenTTD/OpenTTD
(svn r20145) -Codechange: keep original RMB->tooltip behaviour when hovering is disabled and there is no handled right click event for the widget, i.e. if a widget would handle the right click you won't see the tooltip anymore by right clicking; by enabling hovering you would get access to that tooltip again.
parent
fa3d9d04d3
commit
0e078670b7
|
@ -793,9 +793,9 @@ struct DepotWindow : Window {
|
||||||
DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
|
DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnRightClick(Point pt, int widget)
|
virtual bool OnRightClick(Point pt, int widget)
|
||||||
{
|
{
|
||||||
if (widget != DEPOT_WIDGET_MATRIX) return;
|
if (widget != DEPOT_WIDGET_MATRIX) return false;
|
||||||
|
|
||||||
GetDepotVehiclePtData gdvp = { NULL, NULL };
|
GetDepotVehiclePtData gdvp = { NULL, NULL };
|
||||||
const Vehicle *v = NULL;
|
const Vehicle *v = NULL;
|
||||||
|
@ -804,47 +804,49 @@ struct DepotWindow : Window {
|
||||||
|
|
||||||
if (this->type == VEH_TRAIN) v = gdvp.wagon;
|
if (this->type == VEH_TRAIN) v = gdvp.wagon;
|
||||||
|
|
||||||
if (v != NULL && mode == MODE_DRAG_VEHICLE) {
|
if (v == NULL || mode != MODE_DRAG_VEHICLE) return false;
|
||||||
CargoArray capacity, loaded;
|
|
||||||
|
|
||||||
/* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
|
CargoArray capacity, loaded;
|
||||||
bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed);
|
|
||||||
|
|
||||||
/* loop through vehicle chain and collect cargos */
|
/* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
|
||||||
uint num = 0;
|
bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed);
|
||||||
for (const Vehicle *w = v; w != NULL; w = w->Next()) {
|
|
||||||
if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
|
|
||||||
capacity[w->cargo_type] += w->cargo_cap;
|
|
||||||
loaded [w->cargo_type] += w->cargo.Count();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (w->type == VEH_TRAIN && !Train::From(w)->HasArticulatedPart()) {
|
/* loop through vehicle chain and collect cargos */
|
||||||
num++;
|
uint num = 0;
|
||||||
if (!whole_chain) break;
|
for (const Vehicle *w = v; w != NULL; w = w->Next()) {
|
||||||
}
|
if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
|
||||||
|
capacity[w->cargo_type] += w->cargo_cap;
|
||||||
|
loaded [w->cargo_type] += w->cargo.Count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build tooltipstring */
|
if (w->type == VEH_TRAIN && !Train::From(w)->HasArticulatedPart()) {
|
||||||
static char details[1024];
|
num++;
|
||||||
details[0] = '\0';
|
if (!whole_chain) break;
|
||||||
char *pos = details;
|
|
||||||
|
|
||||||
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
|
|
||||||
if (capacity[cargo_type] == 0) continue;
|
|
||||||
|
|
||||||
SetDParam(0, cargo_type); // {CARGO} #1
|
|
||||||
SetDParam(1, loaded[cargo_type]); // {CARGO} #2
|
|
||||||
SetDParam(2, cargo_type); // {SHORTCARGO} #1
|
|
||||||
SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
|
|
||||||
pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show tooltip window */
|
|
||||||
uint64 args[2];
|
|
||||||
args[0] = (whole_chain ? num : v->engine_type);
|
|
||||||
args[1] = (uint64)(size_t)details;
|
|
||||||
GuiShowTooltips(whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Build tooltipstring */
|
||||||
|
static char details[1024];
|
||||||
|
details[0] = '\0';
|
||||||
|
char *pos = details;
|
||||||
|
|
||||||
|
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
|
||||||
|
if (capacity[cargo_type] == 0) continue;
|
||||||
|
|
||||||
|
SetDParam(0, cargo_type); // {CARGO} #1
|
||||||
|
SetDParam(1, loaded[cargo_type]); // {CARGO} #2
|
||||||
|
SetDParam(2, cargo_type); // {SHORTCARGO} #1
|
||||||
|
SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
|
||||||
|
pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show tooltip window */
|
||||||
|
uint64 args[2];
|
||||||
|
args[0] = (whole_chain ? num : v->engine_type);
|
||||||
|
args[1] = (uint64)(size_t)details;
|
||||||
|
GuiShowTooltips(whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
virtual void OnPlaceObject(Point pt, TileIndex tile)
|
||||||
|
|
|
@ -1258,12 +1258,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnRightClick(Point pt, int widget)
|
virtual bool OnRightClick(Point pt, int widget)
|
||||||
{
|
{
|
||||||
if (widget == SM_WIDGET_MAP) {
|
if (widget != SM_WIDGET_MAP || _scrolling_viewport) return false;
|
||||||
if (_scrolling_viewport) return;
|
|
||||||
_scrolling_viewport = true;
|
_scrolling_viewport = true;
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnMouseWheel(int wheel)
|
virtual void OnMouseWheel(int wheel)
|
||||||
|
|
|
@ -383,12 +383,15 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
|
||||||
static void DispatchRightClickEvent(Window *w, int x, int y)
|
static void DispatchRightClickEvent(Window *w, int x, int y)
|
||||||
{
|
{
|
||||||
NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);
|
NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);
|
||||||
|
if (wid == NULL) return;
|
||||||
|
|
||||||
/* No widget to handle, or the window is not interested in it. */
|
/* No widget to handle, or the window is not interested in it. */
|
||||||
if (wid == NULL || wid->index < 0) return;
|
if (wid->index >= 0) {
|
||||||
|
Point pt = { x, y };
|
||||||
|
if (w->OnRightClick(pt, wid->index)) return;
|
||||||
|
}
|
||||||
|
|
||||||
Point pt = { x, y };
|
if (_settings_client.gui.hover_delay == 0 && wid->tool_tip != 0) GuiShowTooltips(wid->tool_tip, 0, NULL, TCC_RIGHT_CLICK);
|
||||||
w->OnRightClick(pt, wid->index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -654,8 +654,10 @@ public:
|
||||||
* A click with the right mouse button has been made on the window.
|
* A click with the right mouse button has been made on the window.
|
||||||
* @param pt the point inside the window that has been clicked.
|
* @param pt the point inside the window that has been clicked.
|
||||||
* @param widget the clicked widget.
|
* @param widget the clicked widget.
|
||||||
|
* @return true if the click was actually handled, i.e. do not show a
|
||||||
|
* tooltip if tooltip-on-right-click is enabled.
|
||||||
*/
|
*/
|
||||||
virtual void OnRightClick(Point pt, int widget) {}
|
virtual bool OnRightClick(Point pt, int widget) { return false; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mouse is hovering over a widget in the window, perform an action for it, like opening a custom tooltip.
|
* The mouse is hovering over a widget in the window, perform an action for it, like opening a custom tooltip.
|
||||||
|
|
Loading…
Reference in New Issue