The International Simutrans Forum

 

Author Topic: cursor settings for scripted one click tools  (Read 556 times)

0 Members and 1 Guest are viewing this topic.

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
cursor settings for scripted one click tools
« on: December 08, 2020, 12:39:29 PM »
It must be convenient if you can set the cursor size other than 1x1 tile for a scripted one click tool. tool_t has three public variables related to the cursor size, which are "cursor_area", "cursor_centered", and "cursor_offset". I want to set values to these variables in a script.

To set these values from the script, I think there are two possible ways. The first one is setting these values directory from the script in init() function. The three variables are registered to script vm and the script can handle these as global variables. The second way is using interface function such as "get_cursor_area()" and so on.

I think the first approach is more appropriate since we need two or three interface functions to set these variables with interface functions. How do you think?

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4870
  • Languages: EN, DE, AT
Re: cursor settings for scripted one click tools
« Reply #1 on: December 08, 2020, 12:47:16 PM »
You could also read them from the tab-file. This seems to be simpler.

The two approaches you describe need double code for both single-tools and two-click tools. Since on the c++-side these are two different classes (and one is not the child of the other).

Also be careful with transfering coordinates between c++ and squirrel: if you use plain koord type then these are auto-rotated (scripts live in fixed map rotation) on rotated maps.

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: cursor settings for scripted one click tools
« Reply #2 on: December 08, 2020, 12:53:15 PM »
Writing cursor size in description.tab makes the cursor size static. Is there any situations where the cursor size needs dynamic? I think this does not need to be dynamic, and that approach makes things much simpler both for the simutrans code and the script code.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10642
  • Languages: De,EN,JP
Re: cursor settings for scripted one click tools
« Reply #3 on: December 08, 2020, 01:07:51 PM »
Cursors are by defualt now zoomable images, so fixed sizes should work.

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: cursor settings for scripted one click tools
« Reply #4 on: December 12, 2020, 08:25:38 AM »
I wrote a patch to make cursor area and offset configurable. This patch considers the map rotation.
The cursor area and offset is defined in description.tab like the example below.

Code: [Select]
cursor_area=3,4
cursor_offset=1,2

This settings is optional. The default area is (1, 1) and the default offset is (0,0).

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4870
  • Languages: EN, DE, AT
Re: cursor settings for scripted one click tools
« Reply #5 on: December 12, 2020, 09:32:37 AM »
Looks good. One comment: there is already a routine to read coordinates from text files in tabfile_t.

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: cursor settings for scripted one click tools
« Reply #6 on: December 17, 2020, 01:08:45 PM »
The routine to read coordinates was replaced with tabfileobj_t::get_koord().

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4870
  • Languages: EN, DE, AT
Re: cursor settings for scripted one click tools
« Reply #7 on: December 19, 2020, 10:23:19 AM »
thank you, in r9506