Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing destination when stopped or waiting #7772

Open
Mysteron347 opened this issue Oct 16, 2019 · 11 comments · May be fixed by #8236
Open

Showing destination when stopped or waiting #7772

Mysteron347 opened this issue Oct 16, 2019 · 11 comments · May be fixed by #8236

Comments

@Mysteron347
Copy link

@Mysteron347 Mysteron347 commented Oct 16, 2019

I believe that it would be useful to replace the "destination"s Stopping, Stopped and Waiting... with the current-destination text when the mouse-pointer is moved over the current-status bar:

openttd2

@andythenorth
Copy link
Contributor

@andythenorth andythenorth commented Oct 22, 2019

I would find this useful. YMMV.

@aruscher
Copy link

@aruscher aruscher commented Feb 8, 2020

It seems like the OnHover-method in the veghicle_gui.cpp can only be executed by hovering over the vehicle in the viewport and not by hovering over any other widgets.

The problem is caused by the DispatchHoverEvent method in the window.cpp; In case a tooltip is defined the OnHover-method is not executed.

Possible fix: Remove the return statement from the tooltip handling;

static void DispatchHoverEvent(Window *w, int x, int y)
{
	NWidgetCore *wid = w->nested_root->GetWidgetFromPos(x, y);

	/* No widget to handle */
	if (wid == nullptr) return;

	Point pt = { x, y };

	/* Show the tooltip if there is any */
	if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) {
		GuiShowTooltips(w, wid->tool_tip);
        DEBUG(misc,1,"STOPED BY TOOLTIP: %d",wid->index);
        return;
	}

	/* Widget has no index, so the window is not interested in it. */
	if (wid->index < 0) return;

	DEBUG(misc,1,"DispatchHoverEvent: %d",wid->index);

	w->OnHover(pt, wid->index);
}
@junaidnaseer
Copy link

@junaidnaseer junaidnaseer commented Feb 15, 2020

So I tried commenting out the return statement and compiling the code again. Unforunately, nothing really changed.

image

I then activated "enable-debug" from "configure" and recompiled the project and stepped through the code. Being previously not familiar with the code, I stepped into the OnHover() function, which we can arrive at now, since the return statement in the tooltip handler is commented out, and it took me to the following empty virtual function.

	/**
	 * The mouse is hovering over a widget in the window, perform an action for it.
	 * @param pt     The point where the mouse is hovering.
	 * @param widget The widget where the mouse is hovering.
	 */
	virtual void OnHover(Point pt, int widget) {}
....

I grepped for "OnHover" in the OpenTTD project and found no additional references, calls, definitions, etc. I was hoping the debugger got it wrong and I would find a reimplementation of the OnHover function in some subclass. I didn't.

So, this might be a naive question on my part (I haven't delved into the code for more than a couple of days), but what is the purpose of an empty virtual function with no reimplementation in any other class.

@LordAro
Copy link
Member

@LordAro LordAro commented Feb 15, 2020

Because of the possibility of use! Or perhaps it was used in the past and has since been removed

@junaidnaseer
Copy link

@junaidnaseer junaidnaseer commented Feb 15, 2020

Ok. So if I understand it correctly, I can reimplement this OnHover function in "some class" in such a way, that upon hovering the mouse in the vehicle window on the widget showing "Stopped"/"Stopping",etc, it would show the destination. I am not sure, where exactly would be appropriate to place that function, but I look into it.

@LordAro
Copy link
Member

@LordAro LordAro commented Feb 15, 2020

Yes, just like the other On* functions

@aruscher
Copy link

@aruscher aruscher commented Feb 15, 2020

@junaidnaseer you can implement OnHover for each window (here the vehicle_window); There you have to switch-case base on the widget type (see OnClick Method). In my experiments i was not able to identify how to implement the proposed behavior without further reworking of the widgets.

@junaidnaseer
Copy link

@junaidnaseer junaidnaseer commented Feb 15, 2020

Ok, guys thanks for the tips. I am looking into the OnClick method in the vehicle_gui.cpp file and see how I can implement something ... as a first step anything that shows any change from the current behavior.

If that works, my second step would be to try to implement the above mentioned feature, if possible.

@aruscher
Copy link

@aruscher aruscher commented Feb 15, 2020

@junaidnaseer What do you mean with "anything that shows any change from the current behavior"? I would rather recommand to first get the changing of the text working, i.e., change the text in the START_STOP based OnHover and revert the changes after stop hovering. To build the right message-string for the bar should be done afterwards.

@junaidnaseer
Copy link

@junaidnaseer junaidnaseer commented Feb 15, 2020

By "anything that shows any change from the current behavior", I meant I would try to write a reimplementation of the OnHover function, in way that I can see some other text in the widget, where it is written "Stopped"/"Waiting ...".

Ok, so I reimplemented the OnHover function and I can see through the debugger that upon hovering over the widget containing the text "Stopped"/"Waiting", I do enter my OnHover function. I have hit a couple of roadblocks here.

  1. Where exactly does the output of the macro DEBUG() go to? Is it written in some log file? I don't see the output in the console. I didn't see any log file under /tmp either. I wanted to check the "vehstatus" but the debugger kept showing "value optimized out" while the log file, I could not find.
		DEBUG(misc, 6, "Vehicle state, %d", v->vehstatus);
  1. I was able to:
...
			SetDParam(0, v->current_order.GetDestination());
			SetDParam(1, v->GetDisplaySpeed());
			str = STR_VEHICLE_STATUS_HEADING_FOR_STATION_VEL;
...

But I am not sure where exactly to pass this str string further to update the widget text. In the DrawWidget function, I see a function DrawString. I am not sure, but maybe I have to use the DrawWidget or the DrawString function somehow.

@glx22
Copy link
Contributor

@glx22 glx22 commented Feb 15, 2020

Try DEBUG(misc, 0, ...) or increase debug level to >=6 else the message won't be shown.

abmyii added a commit to abmyii/OpenTTD that referenced this issue Jun 23, 2020
abmyii added a commit to abmyii/OpenTTD that referenced this issue Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants
You can’t perform that action at this time.