The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Yona-TYT on May 28, 2024, 07:21:02 PM

Title: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on May 28, 2024, 07:21:02 PM


This function does not remove the tool icons, it only darkens them, creating a disabled tool visual effect, I would like to use this for the tutorial.

0001-ADD-new-function-is_tool_active-to-darken-tools-from.patch

Captura desde 2024-05-28 15-20-39.png

Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on May 29, 2024, 08:51:55 AM
It is not as easy as this since these tools will never change once created that way even if a tools becomes allowed later on. But I will think of something.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Roboron on May 30, 2024, 06:45:59 PM
Also, I'm not sure if the effect is strong enough to make it clear that the tool is unavailable. Can it be stronger?
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on May 30, 2024, 07:29:12 PM
Quote from: prissi on May 29, 2024, 08:51:55 AMIt is not as easy as this since these tools will never change once created that way even if a tools becomes allowed later on. But I will think of something.
I have tried to confirm that but all my builds fail when I use tools like rotate the map, I have tried a clean build but it seems to keep failing. (topic for another thread perhaps).


Quote from: Roboron on May 30, 2024, 06:45:59 PMAlso, I'm not sure if the effect is strong enough to make it clear that the tool is unavailable. Can it be stronger?
Yes I thought that too, so change "TRANSPARENT50_FLAG" to "TRANSPARENT25_FLAG" and now it looks like this:

Captura desde 2024-05-30 15-26-51.png

But there is an additional problem (maybe it has to do with what Prissi said), and that is that the level of luminosity (day and night mode) ends up affecting the darkened menus.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Andarix on May 30, 2024, 08:09:29 PM
Quote from: Yona-TYT on May 30, 2024, 07:29:12 PM...
But there is an additional problem (maybe it has to do with what Prissi said), and that is that the level of luminosity (day and night mode) ends up affecting the darkened menus.


The grey of the buttons is actually a special colour.

Menu gray (https://simutrans-germany.com/wiki/wiki/en_SpecialColors#Menu_gray)
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on May 30, 2024, 08:56:26 PM
Quote from: Andarix on May 30, 2024, 08:09:29 PMThe grey of the buttons is actually a special colour.

Menu gray (https://simutrans-germany.com/wiki/wiki/en_SpecialColors#Menu_gray)
Great, I wonder if there are any constants defined for them?.

Edit.
Oh no, but that's not the problem, rather it's the icons themselves that now become susceptible to day and night mode.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Isaac Eiland-Hall on May 30, 2024, 10:30:36 PM
Quote from: Yona-TYT on May 30, 2024, 07:29:12 PMBut there is an additional problem (maybe it has to do with what Prissi said), and that is that the level of luminosity (day and night mode) ends up affecting the darkened menus.

Clearly the solution is to only allow the tutorial to be used during the day. ;-)
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on May 30, 2024, 11:21:16 PM
Quote from: Isaac Eiland-Hall on May 30, 2024, 10:30:36 PMClearly the solution is to only allow the tutorial to be used during the day. ;-)
Hahahaha that's good!. ;D
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on June 08, 2024, 06:40:06 AM
I made this modification and it seems to work fine now.
if(tools[i].blend){
display_color_img(icon_img, draw_pos.x, draw_pos.y, player->get_player_nr(), false, tool_dirty);
display_img_blend( icon_img, draw_pos.x, draw_pos.y, TRANSPARENT75_FLAG|OUTLINE_FLAG|color_idx_to_rgb(COL_WHITE), false, tool_dirty );
//display_base_img_blend(icon_img, draw_pos.x, draw_pos.y, player->get_player_nr(), TRANSPARENT25_FLAG  | MN_GREY0, false, tool_dirty);
}

Captura desde 2024-06-08 02-37-19.png
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on June 24, 2024, 07:33:12 AM
I have implemented it, although slight differently. The function name is also "is_tool_enabled"
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on June 24, 2024, 12:42:26 PM
Quote from: prissi on June 24, 2024, 07:33:12 AMI have implemented it, although slight differently. The function name is also "is_tool_enabled"

Thank you very much! I am already integrating this into the tutorial. ;D

 I would also like to have the system type parameter, I think it is not very difficult to add. ;)
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on July 21, 2024, 09:54:15 PM
I apologize for bringing this thread back to life

There is a small bug when I try to disable extension building menus.

These do not hide until they are clicked for some reason.

Captura desde 2024-07-21 18-36-17.png


I used the following test script:test-tools2.zip



function is_tool_active(pl, tool_id, wt)
{
    if(wt == -1) return false

    return true
}
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on July 22, 2024, 08:23:25 AM
wt==-1 is never used in pak64, it is wt==0 for building the menu. Maybe check for wt<=0?

Since I have never tested script tools ever (I left this to Dwachs) I need some more instruction of how the test this error with the scenario file you provided.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on July 22, 2024, 12:23:57 PM
Quote from: prissi on July 22, 2024, 08:23:25 AMSince I have never tested script tools ever (I left this to Dwachs)
It's actually just a scenario, I just forgot to change the name.
script-test.zip

Quote from: prissi on July 22, 2024, 08:23:25 AMwt==-1 is never used in pak64, it is wt==0 for building the menu. Maybe check for wt<=0?
I need some more instruction of how the test this error with the scenario file you provided.
I changed it to this but the result is the same, the expected behavior is that these menus are hidden, but the effect is only seen when they are clicked.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on August 24, 2024, 08:51:58 PM
Quote from: prissi on July 22, 2024, 08:23:25 AMwt==-1 is never used in pak64, it is wt==0 for building the menu. Maybe check for wt<=0?

Since I have never tested script tools ever (I left this to Dwachs) I need some more instruction of how the test this error with the scenario file you provided.

I was able to track down the possible location where the fault is, there is a problem with the logic here.
hausbauer.cc line 311
    bool enable = welt->get_scenario()->is_tool_enabled(welt->get_active_player(), toolnr | GENERAL_TOOL, wt);

    const uint16 time = welt->get_timeline_year_month();
    DBG_DEBUG("hausbauer_t::fill_menu()","maximum %i",station_building.get_count());

    for(building_desc_t const* const desc :  station_building  ) {
//        DBG_DEBUG("hausbauer_t::fill_menu()", "try to add %s (%p)", desc->get_name(), desc);
        if(  desc->get_type()==btype  &&  desc->get_builder()  &&  (btype==building_desc_t::headquarters  ||  desc->get_extra()==(uint16)wt)  ) {
            if(  desc->is_available(time)  ) {
                desc->get_builder()->enabled = enable;
                tool_selector->add_tool_selector( desc->get_builder() );
            }
        }
    }


For example, if I try to condition so that only stations with wt = 0 appear then no stations appear:

for(building_desc_t const* const desc :  station_building  ) {
// DBG_DEBUG("hausbauer_t::fill_menu()", "try to add %s (%p)", desc->get_name(), desc);
if(  desc->get_type()==btype  &&  desc->get_builder()  &&  (btype==building_desc_t::headquarters  ||  desc->get_extra()==(uint16)wt)  ) {
if(  desc->is_available(time)  ) {
desc->get_builder()->enabled = enable;
if(wt == 0){
dbg->warning("Way Type","--------- Desc %x -- wt %d",desc->get_extra(), wt);
tool_selector->add_tool_selector( desc->get_builder() );
continue;
}
//tool_selector->add_tool_selector( desc->get_builder() );
}
}
}
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on August 24, 2024, 09:14:00 PM
The information on the waytype for a stop is in the extra_data field. But there is no station building with extra_data==0 only the Post office and some other extension buildings.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on August 24, 2024, 09:30:28 PM
Quote from: prissi on August 24, 2024, 09:14:00 PMThe information on the waytype for a stop is in the extra_data field. But there is no station building with extra_data==0 only the Post office and some other extension buildings.
Do you mean that these 8 extension buildings do not have the parameter "wt = 0"?.
Captura desde 2024-08-24 17-28-22.png

Is it possible that they can be added in the future?.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on August 25, 2024, 05:59:37 PM
Quote from: prissi on August 24, 2024, 09:14:00 PMThe information on the waytype for a stop is in the extra_data field. But there is no station building with extra_data==0 only the Post office and some other extension buildings.

The "generic_extension" buildings have the particularity that they do not depend on a waytype, therefore they can be used with any stop or station.
So they do not really have a real waytype restriction, or not?

With this I can solve the problem:

hausbauer.cc (https://github.com/simutrans/simutrans/blob/cd4419a0408e16a8e6fcebd54c40b508b4b5880c/src/simutrans/builder/hausbauer.cc#L311) (line 311)

bool enable = welt->get_scenario()->is_tool_enabled(welt->get_active_player(), toolnr | GENERAL_TOOL, btype == building_desc_t::generic_extension? invalid_wt : wt);


Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on August 25, 2024, 08:37:51 PM
The buildings in the screenshot have the waytype track, otherwise they would not appear in the track menu. See the file e.g. https://sourceforge.net/p/simutrans/code/HEAD/tree/pak64/player/mhz-station.dat?force=True
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on August 27, 2024, 06:55:54 AM
Quote from: prissi on August 25, 2024, 08:37:51 PMThe buildings in the screenshot have the waytype track, otherwise they would not appear in the track menu. See the file e.g. https://sourceforge.net/p/simutrans/code/HEAD/tree/pak64/player/mhz-station.dat?force=True
I already imagined that, my intention was to be able to differentiate between a normal station and an extension building. :(

I guess an additional parameter is needed to achieve this.
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on August 27, 2024, 08:05:16 AM
Their btype is generic_extension 35 not generic_station 34
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: Yona-TYT on August 27, 2024, 08:15:07 AM
Quote from: prissi on August 27, 2024, 08:05:16 AMTheir btype is generic_extension 35 not generic_station 34
I don't understand, are you saying that I made a mistake in the condition "btype == building_desc_t::generic_extension? invalid_wt : wt);"?
Title: Re: ADD new function is_tool_active to darken tools from script
Post by: prissi on August 27, 2024, 11:57:06 AM
I would say the ? operator is not needed as extensions have a waytype too. The do not have to, but they can.