Using strings with parameters in dropdown?

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Using strings with parameters in dropdown?

Post by Yexo »

Is there any way to use a string that needs parameters, such as

Code: Select all

STR_GROUP_NAME                                                  :{GROUP}
in a dropdown list? If so, how to I give the parameter?

I've tried the following, but the games just crashes when I try this.

Code: Select all

Group *g; //Some valid pointer to a group
_data_dropdown[0] = STR_GROUP_NAME;
SetDParam(0,g->index);
_data_dropdown[1] = INVALID_STRING_ID;
ShowDropDownMenu(w, _data_dropdown, 0, REW_DATA, 0, 0);
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Using strings with parameters in dropdown?

Post by Rubidium »

No, it is impossible at the moment. (Or you have to rewrite the string handling subsystem)
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1791
Joined: 30 Mar 2005 09:43

Re: Using strings with parameters in dropdown?

Post by peter1138 »

Better to rewrite the drop down code...
He's like, some kind of OpenTTD developer.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Using strings with parameters in dropdown?

Post by DaleStan »

The comments for Patch's dropdown code say[0] that it's possible to pass it a collection of char* instead of a collection of (our version of) StringID.

This might be the best solution; pass the string through the string handler, and then pass that string pointer to the dropdown. The other solution depends on whether or not you still have the control character 82 XX XX, which, in TTD, inserts the string with id XX XX. If that exists, and if {GROUP} has a StringID, just modify the string on the fly.

[0] I don't think this has ever been tested.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Using strings with parameters in dropdown?

Post by Bilbo »

I asked somewhat similar question - http://tt-forums.net/viewtopic.php?f=33&t=35266

and basically, in OpenTTD you can't just stick bunch of char* into a drop down box.

I'll quote Rubidium from that thread:

[/quote]Partially... you can bind char *strings to stringIDs, but that is kinda tricky. What happens is that you get a StringID from some cyclic buffer, which means the StringID will eventually 'point' to a different string. With the 'wrong' windows open this is after the first redraw. Changing this behaviour means lots of changes and probably much memory leaks.
[/quote]

So you have some chance with using the temporary String ID's, but there are very few of them (I think about 8 or 16 or so) so for longer drop-downs you are out of luck.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: Using strings with parameters in dropdown?

Post by DaleStan »

Hence:
peter1138 wrote:Better to rewrite the drop down code...
StringIDs don't enter into the equation at all.

You allocate one big buffer, tell the string handler to write into that buffer, pass pointers into that buffer, and deallocate the buffer when the dropdown is dismissed. The dropdown handler never receives a StringID, and, in fact, never knows if the string in question ever had a StringID.

Unlike temporary StringIDs, pointers don't magically go invalid just because you opened a different window.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Using strings with parameters in dropdown?

Post by Yexo »

Well, I still wanted to do this so I created a little patch that makes it possible to give SetDParam arguments to the dropdownhandler. Usage example:

Code: Select all

static StringID _data_dropdown = {
STR_GROUP_NAME,
STR_01D3_SOUND_MUSIC,
STR_GROUP_NAME,
INVALID_STRING_ID
}; 
static uint64 _data_dropdown_arguments = {
SomeGroupID,
SomeOtherGroupID
};
static int _data_dropdown_num_arguments = {
1,
0,
1
};
The strings above are just random examples, but you can pass any number of arguments to any combination of strings.

Edit: FS #1649
Attachments
dropdownarguments.patch
patch against 11834
(2.55 KiB) Downloaded 46 times
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Using strings with parameters in dropdown?

Post by Bilbo »

Well, it seems in 11848 we have the new dropdown handler - so the solution "better to rewrite the dropdown code" was the best one :)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Using strings with parameters in dropdown?

Post by Yexo »

Bilbo wrote:Well, it seems in 11848 we have the new dropdown handler - so the solution "better to rewrite the dropdown code" was the best one :)
Yep, I noticed. The only drawback is now that I have to write my code using my custom handler again :(.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Ahrefs [Bot] and 28 guests