The International Simutrans Forum

Development => Technical Documentation => Topic started by: hreintke on August 16, 2021, 09:47:35 PM

Title: Highlighting / marking trains
Post by: hreintke on August 16, 2021, 09:47:35 PM
Hi,

I am working on visualizing some statuses of the available cargo for factories.
I know how to highlight factories using the "obj->set_flag( obj_t::highlight );"

Looking now into the marking of running trains.
Think I can use something similar to the way the train blocks are shown (red tracks and unmarking when the train has passed).

Can you point me to the code that handles that ?
Title: Re: Highlighting / marking trains
Post by: prissi on August 17, 2021, 05:30:52 AM
This is usually handled by the display function, so there is no dedicated code to handle it. You would need to return a transparten image, if the obj is highlighted, override get_outline_image(); and get_outline_colour()
Title: Re: Highlighting / marking trains
Post by: hreintke on August 17, 2021, 07:24:41 AM
I understand that the actual highlight is done by the display function, but there is a higher level function that triggers that.

Like the gui_schedule_cc does for halts :


void highlight_schedule(bool marking)
{
marking &= env_t::visualize_schedule;
FOR(minivec_tpl<schedule_entry_t>, const& i, schedule->entries) {
if (grund_t* const gr = welt->lookup(i.pos)) {
for(  uint idx=0;  idx<gr->get_top();  idx++  ) {
obj_t *obj = gr->obj_bei(idx);
if(  marking  ) {
if(  !obj->is_moving()  ) {
obj->set_flag( obj_t::highlight );
}
}
else {
obj->clear_flag( obj_t::highlight );
}
}.
''''''



I am using similar code to highlight suppliers and consumers from factories.

Now looking for that "higher level function" for train block highlight.
Title: Re: Highlighting / marking trains
Post by: TurfIt on August 17, 2021, 07:38:10 AM
There is no higher level function.

schiene_t::show_reservations = true;

That's it. Any track reserved will be displayed red.
Title: Re: Highlighting / marking trains
Post by: Mariculous on August 17, 2021, 09:12:26 AM
What's wrong about using obj->set_flag( obj_t::highlight ) on tracks?
Doesn't it work?
Otherwise, overriding obj_t::get_outline_image() and obj_t::get_outline_colour() seems to be the way to go.

Edit: I am wondering why the highlight flag is not considered in get_outline_colour, but instead handled sperately in the display function. Seems a little confusing to me.
Title: Re: Highlighting / marking trains
Post by: hreintke on August 17, 2021, 11:28:59 AM
Thx for the replies.
Gives me a good starting point for my investigation.

@Freahk : I don't know it there is specific/other work done in display function but get_outline_colour() is used.


/**
* if a function return here a value with TRANSPARENT_FLAGS set
* then a transparent outline with the color form the lower 8 Bit is drawn
*/
FLAGGED_PIXVAL get_outline_colour() const OVERRIDE { return (show_reservations  &&  reserved.is_bound()) ? TRANSPARENT75_FLAG | OUTLINE_FLAG | color_idx_to_rgb(COL_RED) : 0;}

/*
* to show reservations if needed
*/
image_id get_outline_image() const OVERRIDE { return weg_t::get_image(); }



Edit : It is much easier than I anticipated.
I want to highlight convoys with specific content, I can just highlight the vehicles ("cnv->get_vehikel(i)->set_flag(obj_t::highlight);"