Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for initial scene position #876

Closed
ghost opened this issue Jan 15, 2019 · 16 comments
Closed

Add setting for initial scene position #876

ghost opened this issue Jan 15, 2019 · 16 comments
Labels
⚙️ Addition required in GDevelop.js/GD Core (C++) Something must be added in GDevelop.js for this PR/bug fix 👌good first issue Good issue if you want to start contributing to GDevelop

Comments

@ghost
Copy link

ghost commented Jan 15, 2019

As per http://forum.compilgames.net/viewtopic.php?f=19&t=11147, I have a large scene and I've had to change the zoomFactor setting in game.json so as to see it better without manually zooming out every time I open the editor. However there's no way to change the position - currently its centred on the top-left corner and I have to drag to see the full scene.

It'd be nice if there were a setting for this in game.json or even better in the editor UI.

@zatsme
Copy link
Contributor

zatsme commented Jan 15, 2019

IMHO, Editor should open in the same state is was closed in, hopefully that's not too hard to achieve?

@blurymind
Copy link
Contributor

So lets get this clear- you need the game project file to be able to store the camera position +zoom and to restore it when you open the project :)

I could look it into this, if it doesn't require recompiling gdevelop.js

@zatsme
Copy link
Contributor

zatsme commented Jan 15, 2019

Yes, that's expected behavior from any program I believe. Same as grid settings, you expect the IDE to remember that too 😄

@blurymind
Copy link
Contributor

Yes I agree :)

@4ian
Copy link
Owner

4ian commented Jan 15, 2019

So both Layout (a scene) and ExternalLayout have a property called getAssociatedSettings, where they store a few options. These options are from this class: https://github.com/4ian/GDevelop/blob/master/Core/GDCore/IDE/Dialogs/LayoutEditorCanvas/LayoutEditorCanvasOptions.h#L41-L51

These options are read here (for the SceneEditor):

initialUiSettings={serializeToJSObject(layout.getAssociatedSettings())}

and here (for the ExternalLayoutEditor):

initialUiSettings={serializeToJSObject(
externalLayout.getAssociatedSettings()
)}

(serializeToJSObject take the C++ object and "transform" it to a JS object, that is passed to the editor. So it contains gridWidth, gridHeight, etc... See here for the C++ code)

So these settings are read... but they are never written :) This is why you can edit them in the game json file, but the IDE was never modified to store the changes.

To actually write them, you can do the reverse operation:
unserializeFromJSObject(layout.getAssociatedSettings(), uiSettings).

Explanation: layout.getAssociatedSettings() will return the "pointer" to the C++ object in memory. uiSettings is your JavaScript object (containing gridWidth, gridHeight, etc...).
Finally unserializeFromJSObject do the reverse operation than before: it take the JS object and "feed" the C++ object with it.

Finally, after doing this, when your game is saved, the settings will be saved (nothing to do here).

So now that I've shown how to save these settings, three things:

  • Decide when to store these settings. At every change? When the scene is closed? Every X seconds?
  • Implement the call to unserializeFromJSObject when you find a good place.
  • If you want to store more things than those which are currently supported by LayoutEditorCanvasOptions (like camera position), we'll need to add these members in LayoutEditorCanvasOptions.h, and write the lines to load/save them in LayoutEditorCanvasOptions.cpp and finally recompile GDevelop.js. But for now don't worry about this :)

@blurymind
Copy link
Contributor

blurymind commented Jan 17, 2019

@4ian I can look into this in the weekend if nobody else is doing it :) 👍
Thank you for taking the time to explain

@4ian
Copy link
Owner

4ian commented Jan 17, 2019

Sure, give it a try :)

@blurymind
Copy link
Contributor

@4ian I got it to save the grid and the zoom level so far 👍
However uiSettings doesnt contain the viewport camera coordinates

@4ian
Copy link
Owner

4ian commented Jan 19, 2019

Let's start without the viewport camera, I can add this later if we have something working for the rest

@blurymind
Copy link
Contributor

will do a pull later today :)

@zatsme
Copy link
Contributor

zatsme commented Jan 22, 2019

This will also cover..

#659

@blurymind
Copy link
Contributor

blurymind commented Jan 23, 2019

it covers grid and zoom for now, but will hopefully also cover navigation camera placement

@4ian 4ian added ⚙️ Addition required in GDevelop.js/GD Core (C++) Something must be added in GDevelop.js for this PR/bug fix 👌good first issue Good issue if you want to start contributing to GDevelop labels Feb 22, 2020
@jimil749
Copy link
Contributor

@4ian I would like to try on this. Does this require adding the viewport camera co-ordinates to the uiSettings to save the last camera position?

@4ian
Copy link
Owner

4ian commented Apr 13, 2020

Yes, though the changes need to define when do we save them and to do some changes in C++ to be able to persist them. See the steps I explained here: #876 (comment) :)

@jimil749
Copy link
Contributor

Thank you! Will take a look :)

@Silver-Streak
Copy link
Collaborator

This appears to have been solved through other pull requests than those mentioned above. Scene viewport settings (zoom/location/etc) are saved when saving a project in b117 and newer at least.

Closing this out, but feel free to reopen this if it's not resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ Addition required in GDevelop.js/GD Core (C++) Something must be added in GDevelop.js for this PR/bug fix 👌good first issue Good issue if you want to start contributing to GDevelop
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants