supertux icon indicating copy to clipboard operation
supertux copied to clipboard

List object names within editor toolbox

Open Vankata453 opened this issue 3 years ago • 1 comments

Adds the ability for an object's name to be shown in the editor toolbox, when the mouse cursor hovers over it.

image

Potential issue: Currently, the toolbox gets an object's name by using a new temporary instance of it, via GameObjectFactory. That may not be a good solution, because creating an object just to get its name is not optimal (additional messages from the new object can also be seen in the log, because of that). [FIXED]

Vankata453 avatar Jun 16 '22 18:06 Vankata453

A potential solution to avoid having to create an object to get its name would be to refactor all GameObjects to add a static class function that would return the object's name and classname, and to have the virtual member (non-static) functions to fetch the names and classnames from their static counterparts. The GameObjectFactory class could then be refactored to allow calling the correct static function from the classes it holds, which could be used for this PR.

This is something I had planned doing for a certain fork.


In short:

...

class MyGameObject : public GameObject
{
public:
  static std::string classname() { return "mygameobject"; }
  static std::string name() { return "My GameObject"; }

...

  virtual std::string get_classname() const { return classname(); }
  virtual std::string get_name() const { return name(); }

...

};

...

(I don't remember how the currently existing functions are named, just make sure the static functions don't share names with the non-static ones)

As for the GameObjectFactory, I suppose there is a template somewhere; say the template is called T, you can invoke one of its static functions with T::name();.

Semphriss avatar Jun 17 '22 16:06 Semphriss