Page 1 of 1

StoryPage Tile/Vehicle Buttons

Posted: 05 Jan 2021 22:04
by alc
Hi,
I am writing my first GS. It is usefull for seasonal industries productions like Fruit Plantations (at least with ECS that is what I use).
What the GS does is to look between October and June if there are vehicles that can transport fruits and/or Oil Seeds on station with full load/Full Load Any orders. If the station is empty, and the vehicle has above a percentage loaded, it is informing on the StaryPage what vehicles are in this condition. Up to here, is working,

I can't understand how the StoryPAge Buttons work. When I create a vehicle buttonn, in the parameters, I have to say the vehicle type, not the vehicle ID. Or for tile button, nothing refered to a tile is passed.
How does the event handler knows the vehicle_id in the GSEventStoryPageVehicleSelect.GetVehicleID()?

Is there any working example to have a look how it is implemented?

Instead of given the vehicle type, should be passed the vehicle ID? I try it but crushed the entire OTTD game.

static StoryPageButtonFormatting MakeTileButtonReference (StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor)

static StoryPageButtonFormatting MakeVehicleButtonReference (StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor, GSVehicle::VehicleType vehtype)

Thanks in advance, :bow:
Alberto

Re: StoryPage Tile/Vehicle Buttons

Posted: 06 Jan 2021 15:49
by jfs
What are you trying to do?
The Vehicle button is to let the player click on a vehicle, and you get a VehicleID in return (in the fired event) after the player has selected the vehicle.


This call creates a button to select a water vehicle (ship), the mouse cursor will show the "build station" icon:

Code: Select all

this._select_vehicle_button = GSStoryPage.NewElement(
    this._pageid,
    GSStoryPage.SPET_BUTTON_VEHICLE,
    GSStoryPage.MakeVehicleButtonReference(
        GSStoryPage.SPBC_GREEN,
        GSStoryPage.SPBF_NONE,
        GSStoryPage.SPBC_PICKSTATION,
        GSVehicle.VT_WATER
        ),
    "Find a vehicle");
When the player then clicks that button, and then clicks a vehicle, the game sends a GSEvent.ET_STORYPAGE_VEHICLE_SELECT event to your script.

You can then get the ID of the actual vehicle the player clicked by examining the event object.

Code: Select all

local vehicle_select_event = GSEventStoryPageVehicleSelect.Convert(event_object);
if (vehicle_select_event.GetElementID() == this._select_vehicle_button) {
    GSController.Print(false, "Player clicked vehicle, button=" + vehicle_select_event.GetElementID());
    GSController.Print(false, "Player clicked vehicle, vehicle name=" + GSVehicle.GetName(vehicle_select_event.GetVehicleID()));
}

Edit: Also, I'm very interested in seeing the code you had that caused the game to crash. That should not be possible, if you find any way of crashing the game (as in, OpenTTD closes completely) please report it.

Re: StoryPage Tile/Vehicle Buttons

Posted: 07 Jan 2021 18:36
by alc
Thanks, I make it work but that behavior is not what I am needing.
What I am trying to do?
On a StoryPage create a button for each vehicle that fullfil the conditions. That button was suppose to, by clicking, open the vehicle's window, to avoid needing to look at the different vehicles list. I don't see on GSWindows an open function so, as an alternative, after cliking, to position the viewport on that vehicle.

I will try to recreate the OTTD fail tomorrow or during the weekend.

Regards,
Alberto

Re: StoryPage Tile/Vehicle Buttons

Posted: 07 Jan 2021 19:57
by jfs
You can create a plain button that calls the GSViewport::ScrollClientTo() function to center the player on a vehicle. There isn't any way to open a vehicle window or to make the viewport follow a vehicle, but you can at least center the player's view on the vehicle's current tile.

Re: StoryPage Tile/Vehicle Buttons

Posted: 07 Feb 2021 21:20
by alc
I was able to recreate the conditions to make OTTD to crash.
I am using JGRPP 0.39.0
On GSStoryPage.MakeVehicleButtonReference instead of given the vehicle type, I gave the vehicle_ID.
Line 342 of main.nut
local reference = GSStoryPage.MakeVehicleButtonReference(GSStoryPage.SPBC_DARK_BLUE,
GSStoryPage.SPBF_NONE,
GSStoryPage.SPBC_SHIP_DEPOT,
Vehicle);
As I said, then I realize that the correct parameter was vehicle type.

zip file contains crash.dmp, .log, .png and my info.nut and main.nut.

Regards,
Alberto