aliens

Author Topic: Error in adding new button to .rul  (Read 5045 times)

Offline marcoblbr

  • Squaddie
  • *
  • Posts: 7
    • View Profile
Error in adding new button to .rul
« on: March 12, 2017, 10:07:35 pm »
Hi guys, how is it going?

Recently I posted here https://openxcom.org/forum/index.php/topic,5364.0.html about suggestions I wanted to see in Open X-Com and I'm trying to implement suggestion 1, which is a new way of loading and saving layouts based on the soldier's weight.

I know nothing about modding Open X-Com, but I am very inspired by this Merge Pull Request https://github.com/SupSuper/OpenXcom/commit/5e5281930b79a3b8edd1e04a9ba9a9600dea3284 from @myk002 that shows how the original load/save was put in the game, so I know what files I need to modify.

I need to add new buttons to the inventory, so in the file standard/xcom1/extraSprites.rul I added this:

Code: [Select]
   - type: InvWeightCopy
     width: 8
     height: 8
     singleImage: true
     files:
       0: Resources/UI/invweightcopy.png
   - type: InvWeightPaste
     width: 8
     height: 8
     singleImage: true
     files:
     0: Resources/UI/invweightpaste.png

But I'm having a compilation problem. This one:



No idea how to solve it. On the original merge pull request, I saw that "- type: InvCopy" is only on that file and has no other reference to it, besides the .cpp and .h files. Also, the metadata.yml on the same folder is very simple and has no references to InvCopy either, so no clue why that error is happening.

For reference, the original code what works is this one:

Code: [Select]
  - type: InvCopy
    width: 16
    height: 16
    singleImage: true
    files:
      0: Resources/UI/invcopy.png

I checked the image is not the problem because the compiler gives the same error even when I use one image that's already on the folder. The problem is the line "- type: InvWeightCopy"

I'm using a Mac and working on the project using XCode.

Any thoughts?

By the way, this is exactly what I want to achieve. More on that in the specific thread.


Thanks!
Marco




« Last Edit: March 12, 2017, 10:16:33 pm by marcoblbr »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9084
    • View Profile
Re: Error in adding new button to .rul
« Reply #1 on: March 12, 2017, 10:44:04 pm »
You are missing 2 spaces on the last line:

Code: [Select]
     files:
     0: Resources/UI/invweightpaste.png

The second line needs to be indented by two more spaces.

By the way, you can't add new buttons to inventory just by ruleset... you'll need to do code changes too.
Just to let you know.

Also, there is a feature for saving and loading multiple inventory templates already, up to 20 of them... even with names.
https://openxcom.org/forum/index.php/topic,4747.msg69139.html#msg69139
« Last Edit: March 12, 2017, 10:47:46 pm by Meridian »

Offline marcoblbr

  • Squaddie
  • *
  • Posts: 7
    • View Profile
Re: Error in adding new button to .rul
« Reply #2 on: March 13, 2017, 03:43:39 am »
You are missing 2 spaces on the last line:

Code: [Select]
     files:
     0: Resources/UI/invweightpaste.png

The second line needs to be indented by two more spaces.

By the way, you can't add new buttons to inventory just by ruleset... you'll need to do code changes too.
Just to let you know.

Also, there is a feature for saving and loading multiple inventory templates already, up to 20 of them... even with names.
https://openxcom.org/forum/index.php/topic,4747.msg69139.html#msg69139

I don't believe that was the problem! I fixed the empty spaces and now it is working! Thank you SO much!!

And yes, I definitely know I need to code. In fact, I'm already coding based on that merge pull request from mky002.

Meridian, I'm glad you touched on this point. I had read that thread already when I was thinking about this ideia for suggestion 1 and I tested this feature on OXCE+ and it is awesome. I wanted to ask you... At that time did you make a merge pull request to SupSuper or there is a separate branch for this feature on OXCE+? If so, do you have the link for that pull request or branch?

I wanted to understand more about how you do the saving on disk, the functions you call and files that you modify. I was able to compile OXCE+ on XCode and I already compared 2 save states and made a diff to understand exactly how you add this to the save files on OXCE+, but there are so many files to look at that I'm very lost at this moment! Without that spull request from mky002 I would have no clue on even how to start. If you have that specific code for this feature, it would help me a lot. And also, do you mind me being inspired by it to write this feature I'm proposing?

Thanks a lot!

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Error in adding new button to .rul
« Reply #3 on: March 13, 2017, 04:44:21 am »
Hi marcoblbr, OXCE+ is a completely separate repository from the nightly OXC maintained by SupSuper, Warboy, et al., specifically made by Meridian and based off of Yankes' OXCE.  You can use it directly to do anything (up to the version of the nightly pulled into OXCE) that OXC does, plus the new features added by Meridian and Yankes.  Their repositories (here for OXCE by Yankes and here for OXCE+ by Meridian) are good places to check for new features before you try implementing it from scratch yourself.  I'm not sure exactly how long ago, but the inventory templates are only a few months, less than a year at the very least, old, and pretty well documented in the commit history on Meridian's code if you want to look for them.

As for the saving to disk, that is all handled by the YAML C++ library used by OXC.  Look in the source code for the Savegame folder, and that contains most of the classes that are saved to disk as part of the YAML text file that constitutes an OXC save.  (I'd also suggest looking for a YAML tutorial, as things like indentation are very important to YAML as a markup language)  For example, you can see starting on this line how the position a certain item holds in an inventory is saved to the text file - most of the classes in the savegame folder have a save() method that writes variables to the text file.