GDevelop icon indicating copy to clipboard operation
GDevelop copied to clipboard

Add "text color" condition/expression for text objects

Open Elairyx7301 opened this issue 4 years ago • 8 comments

Description

Both main text objects / object types "Text" and "BBText" have actions to set the text color (or base color for BBText) but are missing getter expressions and conditions to check the current text instance color.

Solution suggested

Add a condition and expression each for regular text object, BBText and Bitmap Font that return the current text instance color. Therefore:

  • Color of text (text object)                  [condition] and [expression]
  • Color of text (BBText object)              [condition] and [expression]
  • Color of text (Bitmap Font object)     [condition] and [expression]     image

Maybe even have only one condition/expression and the engine then hands the instance to the method that needs that object type. Not needed because this would apply to other methods as well and should be put focus on separately in my opinion.

Quick sketch in case I explained it too poorly (simplified java syntax):

//main public method
public String color(Object object) {
  if (object is Text) { return color(Text object); }
  if (object is BBText) { return color(BBText object); }
  if (object is BitmapFont) { return color(BitmapFont object); }
  return ""; } //return error or empty string

//helper methods
private String color(Text object) { return object.textColor(); }
private String color(BBText object) { return object.bbtextColor(); }
private String color(BitmapFont object) { return object.bitmapColor(); }

Elairyx7301 avatar Nov 23 '21 20:11 Elairyx7301

I always support exposing more object/system parameters for objects as expressions. Hopefully we'll eventually have all objects/setting parameters exposed.

Silver-Streak avatar Nov 24 '21 07:11 Silver-Streak

I am new to opensource and contributions but I would love to try it out!

Shreyansh-Rai avatar Jan 07 '22 07:01 Shreyansh-Rai

It would also be helpful if you could tell me which file I would need to make these changes in (It's a pretty huge codebase and I am a little lost)

Thanks :)

Shreyansh-Rai avatar Jan 07 '22 07:01 Shreyansh-Rai

Thank you @Shreyansh-Rai! In lack of other comments, I can try my best to hint at a direction or files but without any guarantee that what I say is correct since I don't have any experience with the code nor GitHub, really. It seems like BBText and Bitmap Text are all based on the regular text object since I can only find actions and conditions being added for the regular Text object while the other two text object types include the .h file of the regular text object - if that make sense.

https://github.com/4ian/GDevelop/blob/d980400c2b2f1b553e7960393977183f7980669b/Extensions/TextObject/Extension.cpp

From what I can tell, you'd need to add something like this:

obj.AddCondition("Color",
      _("Color of text"),
      _("Get the color of the text object"),

      //...

      .SetFunctionName("GetColor")
      .SetIncludeFile("TextObject/TextObject.h");

That's a quick sketch, I think you get the idea. There are many other conditions and actions in that file that you can take a look at and compare with to get the right result (compare with the strings in the editor https://editor.gdevelop-app.com/, if needed or unsure)

That's about all guidance I can provide :)

Elairyx7301 avatar Jan 25 '22 18:01 Elairyx7301

If this issue is still open , I also want to contribute on this issue

harshsingh941 avatar Feb 08 '22 11:02 harshsingh941

Yes, it is still open and you are welcome to contribute to it :)

Elairyx7301 avatar Feb 08 '22 14:02 Elairyx7301

Since there haven't been any new notes (and since it hasn't been implemented in the latest version), I'll give it another go and block this thing for myself. I'll keep you updated.

Elairyx7301 avatar Dec 09 '25 13:12 Elairyx7301

Cool :) Note that we often don't provide a color condition because you can't really compare a color. I would be in favor of only doing a text expression (and if you really want to compare it, you can always use a For Each event + the condition to compare two texts).

4ian avatar Dec 09 '25 13:12 4ian