News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

Unowned text label tool

Started by Yona-TYT, January 07, 2025, 01:05:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT



I would like a new tool exclusively for the public service, to create text labels using the unowned player, the result would be text labels that can be removed by any player and in theory should not interfere with their constructions.

This is intended for use in the tutorial and to stop using the public service text labels.

prissi

First: Why not use player labels in the tutorial?

Second: It looks like unowned players are supported. Just pass null for the player parameter or 15 for the player number if you build the command string by hand.

Yona-TYT

#2
Quote from: prissi on January 07, 2025, 02:38:50 AMSecond: It looks like unowned players are supported. Just pass null for the player parameter or 15 for the player number if you build the command string by hand.
unfortunately it doesn't work, it doesn't allow building with player 15/null using scripts.
https://github.com/simutrans/simutrans/blob/1128ad59ead6ac4adcefc50a051416d1107128f3/src/simutrans/script/api/api_command.cc#L82

Captura de pantalla -2025-01-06 23-32-49.png

I don't see much point in restricting this for scripts, as they can be very useful, additionally objects without owners such as rivers, moving objects, buildings, etc. should also be allowed.

prissi

There are several tools that should allow player==null I can remove that check, the later routines usually check for player==null too, it seems. I removed it in r11581. But expect crashes when trying to build unowned stops etc.

The additional request objects have no tool at all. Hence, there is no interface to build them.

Yona-TYT

Quote from: prissi on January 07, 2025, 04:09:31 AMBut expect crashes when trying to build unowned stops etc.
It is to be expected, but a warning in the documentation will be more than enough to prevent the yona-tyt from inventing too much.  ;)




There is a bug when trying to open the text label list.
Thread 1 "simutrans" received signal SIGSEGV, Segmentation fault.
0x00005555557b5cd2 in labellist_stats_t::labellist_stats_t(koord) ()
(gdb) where
#0  0x00005555557b5cd2 in labellist_stats_t::labellist_stats_t(koord) ()
#1  0x00005555557b124f in labellist_frame_t::fill_list() ()
#2  0x00005555557b22a3 in labellist_frame_t::labellist_frame_t() ()
#3  0x00005555559c5600 in dialog_list_label_t::init(player_t*) ()
#4  0x0000555555a3e5f9 in karte_t::local_set_tool(tool_t*, player_t*) ()
#5  0x00005555558258c7 in tool_selector_t::infowin_event(event_t const*) ()
#6  0x000055555581bdd6 in check_pos_win(event_t*, bool) ()
#7  0x00005555559a6190 in interaction_t::check_events() ()
#8  0x0000555555a4090d in karte_t::sync_step(unsigned int) ()
#9  0x00005555559a670d in interrupt_check(char const*) ()
#10 0x0000555555a522b6 in karte_t::interactive(unsigned int) ()
#11 0x00005555559af168 in simu_main(int, char**) ()
#12 0x00005555559b9149 in sysmain(int, char**) ()
#13 0x00007ffff7529248 in __libc_start_call_main (main=main@entry=0x555555641b30 <main>, argc=argc@entry=1, argv=argv@entry=0x7fffffffdc48)
    at ../sysdeps/nptl/libc_start_call_main.h:58
#14 0x00007ffff752930b in __libc_start_main_impl (main=0x555555641b30 <main>, argc=1, argv=0x7fffffffdc48, init=<optimized out>, fini=<optimized out>,
    rtld_fini=<optimized out>, stack_end=0x7fffffffdc38) at ../csu/libc-start.c:360
#15 0x0000555555641bfe in _start ()
(gdb)

Yona-TYT

#5
There is a curious bug with text labels, and that is that if you build a stop on them, then the halt name will be the same as the text of the label. It's not that serious, but if it's possible to fix it, it would be great. ;)

But in the case of these tags without owners, it would be good if when using the stop/station construction tool, these were removed to prevent the text from interfering with the station name.

prissi

The crash with labels should no longer occur in r11582 and the labels should be automatically removed in r11583.

Yona-TYT

#7
Quote from: prissi on January 07, 2025, 07:13:10 AMThe crash with labels should no longer occur in r11582 and the labels should be automatically removed in r11583.

There is an initialization problem on this line:
https://github.com/simutrans/simutrans/blob/e5b680628912828478421f3f5615260cfdf24c46/src/simutrans/tool/simtool.cc#L5004C1-L5004C20


This works for me:
https://github.com/Yona-TYT/simutrans/commit/3809ad58e239c09f259f4e163a64a320f3906e1a



Clicking on the label text from the label windows list causes a crash. It seems that trying to open the text label window causes the crash.
Thread 1 "simutrans" received signal SIGSEGV, Segmentation fault.
0x00005555556c5b70 in translator::translate(char const*) ()
(gdb) where
#0  0x00005555556c5b70 in translator::translate(char const*) ()
#1  0x00005555557b06ee in label_info_t::label_info_t(label_t*) ()
#2  0x00005555558582a6 in label_t::show_info() ()
#3  0x00005555557b51c8 in virtual thunk to labellist_stats_t::infowin_event(event_t const*) ()
#4  0x00005555556f3839 in gui_container_t::infowin_event(event_t const*) ()
#5  0x000055555570b37d in gui_scrollpane_t::infowin_event(event_t const*) ()
#6  0x00005555557090a8 in gui_scrolled_list_t::infowin_event(event_t const*) ()
#7  0x00005555556f3839 in gui_container_t::infowin_event(event_t const*) ()
#8  0x000055555578f4c8 in gui_frame_t::infowin_event(event_t const*) ()
#9  0x000055555581bdd6 in check_pos_win(event_t*, bool) ()
#10 0x00005555559a61a0 in interaction_t::check_events() ()
#11 0x0000555555a4093d in karte_t::sync_step(unsigned int) ()
#12 0x00005555559a671d in interrupt_check(char const*) ()
#13 0x0000555555a522e6 in karte_t::interactive(unsigned int) ()
#14 0x00005555559af178 in simu_main(int, char**) ()
#15 0x00005555559b9159 in sysmain(int, char**) ()
#16 0x00007ffff7529248 in __libc_start_call_main (main=main@entry=0x555555641b20 <main>, argc=argc@entry=1, argv=argv@entry=0x7fffffffdc48)
    at ../sysdeps/nptl/libc_start_call_main.h:58
#17 0x00007ffff752930b in __libc_start_main_impl (main=0x555555641b20 <main>, argc=1, argv=0x7fffffffdc48, init=<optimized out>, fini=<optimized out>,
    rtld_fini=<optimized out>, stack_end=0x7fffffffdc38) at ../csu/libc-start.c:360
#18 0x0000555555641bee in _start ()
(gdb)

prissi

Ups, submitted the wrong file. See 11584 and r11585

Yona-TYT

Quote from: prissi on January 07, 2025, 12:50:48 PMUps, submitted the wrong file. See 11584 and r11585
It seems to be working fine now.

Thanks a lot, this will be very useful, I will update the tutorial in a moment.

Yona-TYT

#10
When using label_x.set_text("text") you also get a message that it cannot be used with player null.

https://github.com/simutrans/simutrans/blob/c0bc32b377933e00db2e76d3b8cdcd512130d135/src/simutrans/script/api/api_command.cc#L82C1-L82C64

Captura de pantalla -2025-01-07 10-52-00.png


One limitation I have is that these text labels are not built on other players' objects, such as roads or rails. Is there a possibility that this can be done?.

In the opposite direction it is already possible (if you place the text label first and then the rails), so I think it should not be a problem. ;)

Captura de pantalla -2025-01-07 11-16-10.png

prissi

No, this is not possible to put them on other players stuff. The text color takes the ownership of the first thing on the tile.

I have disabled the player check for tool init as well.

Yona-TYT

Quote from: prissi on January 08, 2025, 03:05:46 AMNo, this is not possible to put them on other players stuff. The text color takes the ownership of the first thing on the tile.
I understand, I thought you could adopt the behavior as text labels from public services, which can be built on player property without overwriting anything.

If the public service can do it, why can't the unowned player?.

prissi

The text and the label are not connected. The label is just an object, while the text is part of an entirely different structure. Historically, only labels had text, but that has long gone.

This means that a text has no ownership. Its is just draw in the color of whatever is there first. If there is a way (which simutrans assumes is the first object) then it is drawn in the color of the way owner.

Maybe there is somewhere some logic to take ownership of roads below labels.

Yona-TYT

Quote from: prissi on January 10, 2025, 01:19:14 PMMaybe there is somewhere some logic to take ownership of roads below labels.

If you think it's not that complicated to implement then welcome :). Currently, ownerless text labels are very useful to me, but being able to place them on other players' roads or rails would be a great help.  8)