Skip to content

Commit

Permalink
Allow changing opacity & flip XY from instance properties panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementPasteau committed Sep 10, 2024
1 parent 3508282 commit 17f9b26
Show file tree
Hide file tree
Showing 39 changed files with 718 additions and 144 deletions.
20 changes: 15 additions & 5 deletions Core/GDCore/Project/InitialInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ InitialInstance::InitialInstance()
rotationX(0),
rotationY(0),
zOrder(0),
opacity(255),
layer(""),
flippedX(false),
flippedY(false),
customSize(false),
customDepth(false),
width(0),
Expand Down Expand Up @@ -57,7 +60,10 @@ void InitialInstance::UnserializeFrom(const SerializerElement& element) {
SetHasCustomDepth(false);
}
SetZOrder(element.GetIntAttribute("zOrder", 0, "plan"));
SetOpacity(element.GetIntAttribute("opacity", 255));
SetLayer(element.GetStringAttribute("layer"));
SetFlippedX(element.GetBoolAttribute("flippedX", false));
SetFlippedY(element.GetBoolAttribute("flippedY", false));
SetLocked(element.GetBoolAttribute("locked", false));
SetSealed(element.GetBoolAttribute("sealed", false));
SetShouldKeepRatio(element.GetBoolAttribute("keepRatio", false));
Expand Down Expand Up @@ -113,6 +119,9 @@ void InitialInstance::SerializeTo(SerializerElement& element) const {
element.SetAttribute("y", GetY());
if (GetZ() != 0) element.SetAttribute("z", GetZ());
element.SetAttribute("zOrder", GetZOrder());
if (GetOpacity() != 255) element.SetAttribute("opacity", GetOpacity());
if (IsFlippedX()) element.SetAttribute("flippedX", IsFlippedX());
if (IsFlippedY()) element.SetAttribute("flippedY", IsFlippedY());
element.SetAttribute("layer", GetLayer());
element.SetAttribute("angle", GetAngle());
if (GetRotationX() != 0) element.SetAttribute("rotationX", GetRotationX());
Expand Down Expand Up @@ -155,8 +164,8 @@ InitialInstance& InitialInstance::ResetPersistentUuid() {

std::map<gd::String, gd::PropertyDescriptor>
InitialInstance::GetCustomProperties(
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer) {
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer) {
// Find an object
if (objectsContainer.HasObjectNamed(GetObjectName()))
return objectsContainer.GetObject(GetObjectName())
Expand All @@ -172,9 +181,10 @@ InitialInstance::GetCustomProperties(
}

bool InitialInstance::UpdateCustomProperty(
const gd::String &name, const gd::String &value,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer) {
const gd::String& name,
const gd::String& value,
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer) {
if (objectsContainer.HasObjectNamed(GetObjectName()))
return objectsContainer.GetObject(GetObjectName())
.GetConfiguration()
Expand Down
71 changes: 52 additions & 19 deletions Core/GDCore/Project/InitialInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GD_CORE_API InitialInstance {
* \brief Create an initial instance pointing to no object, at position (0,0).
*/
InitialInstance();
virtual ~InitialInstance(){};
virtual ~InitialInstance() {};

/**
* Must return a pointer to a copy of the object. A such method is needed to
Expand Down Expand Up @@ -123,6 +123,36 @@ class GD_CORE_API InitialInstance {
*/
void SetZOrder(int zOrder_) { zOrder = zOrder_; }

/**
* \brief Get Opacity.
*/
int GetOpacity() const { return opacity; }

/**
* \brief Set the opacity of the instance.
*/
void SetOpacity(int opacity_) { opacity = opacity_; }

/**
* \brief Return true if the instance is flipped on X axis.
*/
bool IsFlippedX() const { return flippedX; }

/**
* \brief Set whether the instance is flipped on X axis.
*/
void SetFlippedX(bool flippedX_) { flippedX = flippedX_; }

/**
* \brief Return true if the instance is flipped on Y axis.
*/
bool IsFlippedY() const { return flippedY; }

/**
* \brief Set whether the instance is flipped on Y axis.
*/
void SetFlippedY(bool flippedY_) { flippedY = flippedY_; }

/**
* \brief Get the layer the instance belongs to.
*/
Expand All @@ -134,8 +164,9 @@ class GD_CORE_API InitialInstance {
void SetLayer(const gd::String& layer_) { layer = layer_; }

/**
* \brief Return true if the instance has a width/height which is different from its
* object default width/height. This is independent from `HasCustomDepth`.
* \brief Return true if the instance has a width/height which is different
* from its object default width/height. This is independent from
* `HasCustomDepth`.
*
* \see gd::Object
*/
Expand All @@ -150,15 +181,13 @@ class GD_CORE_API InitialInstance {
bool HasCustomDepth() const { return customDepth; }

/**
* \brief Set whether the instance has a width/height which is different from its
* object default width/height or not.
* This is independent from `SetHasCustomDepth`.
* \brief Set whether the instance has a width/height which is different from
* its object default width/height or not. This is independent from
* `SetHasCustomDepth`.
*
* \see gd::Object
*/
void SetHasCustomSize(bool hasCustomSize_) {
customSize = hasCustomSize_;
}
void SetHasCustomSize(bool hasCustomSize_) { customSize = hasCustomSize_; }

/**
* \brief Set whether the instance has a depth which is different from its
Expand Down Expand Up @@ -264,18 +293,19 @@ class GD_CORE_API InitialInstance {
* \note Common properties ( name, position... ) do not need to be
* inserted in this map
*/
std::map<gd::String, gd::PropertyDescriptor>
GetCustomProperties(gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer);
std::map<gd::String, gd::PropertyDescriptor> GetCustomProperties(
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer);

/**
* \brief Update the property called \a name with the new \a value.
*
* \return false if the property could not be updated.
*/
bool UpdateCustomProperty(const gd::String &name, const gd::String &value,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer);
bool UpdateCustomProperty(const gd::String& name,
const gd::String& value,
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer);

/**
* \brief Get the value of a double property stored in the instance.
Expand Down Expand Up @@ -343,6 +373,9 @@ class GD_CORE_API InitialInstance {
double rotationX; ///< Instance angle on X axis (for a 3D object)
double rotationY; ///< Instance angle on Y axis (for a 3D object)
int zOrder; ///< Instance Z order (for a 2D object)
int opacity; ///< Instance opacity
bool flippedX; ///< True if the instance is flipped on X axis
bool flippedY; ///< True if the instance is flipped on Y axis
gd::String layer; ///< Instance layer
bool customSize; ///< True if object has a custom width and height
bool customDepth; ///< True if object has a custom depth
Expand All @@ -352,13 +385,13 @@ class GD_CORE_API InitialInstance {
gd::VariablesContainer initialVariables; ///< Instance specific variables
bool locked; ///< True if the instance is locked
bool sealed; ///< True if the instance is sealed
bool keepRatio; ///< True if the instance's dimensions
/// should keep the same ratio.
bool keepRatio; ///< True if the instance's dimensions
/// should keep the same ratio.
mutable gd::String persistentUuid; ///< A persistent random version 4 UUID,
/// useful for hot reloading.

static gd::String*
badStringPropertyValue; ///< Empty string returned by GetRawStringProperty
static gd::String* badStringPropertyValue; ///< Empty string returned by
///< GetRawStringProperty
};

} // namespace gd
12 changes: 10 additions & 2 deletions Extensions/3D/A_RuntimeObject3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace gdjs {
gdjs.Resizable,
gdjs.Scalable,
gdjs.Flippable,
gdjs.Base3DHandler {
gdjs.Base3DHandler
{
/**
* Position on the Z axis.
*/
Expand Down Expand Up @@ -164,8 +165,15 @@ namespace gdjs {
this.setWidth(initialInstanceData.width);
this.setHeight(initialInstanceData.height);
}
if (initialInstanceData.depth !== undefined)
if (initialInstanceData.depth !== undefined) {
this.setDepth(initialInstanceData.depth);
}
if (initialInstanceData.flippedX) {
this.flipX(initialInstanceData.flippedX);
}
if (initialInstanceData.flippedY) {
this.flipY(initialInstanceData.flippedY);
}
}

setX(x: float): void {
Expand Down
12 changes: 10 additions & 2 deletions Extensions/3D/CustomRuntimeObject3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace gdjs {
*/
export class CustomRuntimeObject3D
extends gdjs.CustomRuntimeObject
implements gdjs.Base3DHandler {
implements gdjs.Base3DHandler
{
/**
* Position on the Z axis.
*/
Expand Down Expand Up @@ -72,8 +73,15 @@ namespace gdjs {

extraInitializationFromInitialInstance(initialInstanceData: InstanceData) {
super.extraInitializationFromInitialInstance(initialInstanceData);
if (initialInstanceData.depth !== undefined)
if (initialInstanceData.depth !== undefined) {
this.setDepth(initialInstanceData.depth);
}
if (initialInstanceData.flippedX) {
this.flipX(initialInstanceData.flippedX);
}
if (initialInstanceData.flippedY) {
this.flipY(initialInstanceData.flippedY);
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion Extensions/BBText/bbtextruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace gdjs {
*/
export class BBTextRuntimeObject
extends gdjs.RuntimeObject
implements gdjs.OpacityHandler {
implements gdjs.OpacityHandler
{
_opacity: float;

_text: string;
Expand Down Expand Up @@ -192,6 +193,9 @@ namespace gdjs {
250
);
}
if (initialInstanceData.opacity !== undefined) {
this.setOpacity(initialInstanceData.opacity);
}
}

onDestroyed(): void {
Expand Down
6 changes: 5 additions & 1 deletion Extensions/BitmapText/bitmaptextruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ namespace gdjs {
*/
export class BitmapTextRuntimeObject
extends gdjs.RuntimeObject
implements gdjs.TextContainer, gdjs.OpacityHandler, gdjs.Scalable {
implements gdjs.TextContainer, gdjs.OpacityHandler, gdjs.Scalable
{
_opacity: float;
_text: string;
/** color in format [r, g, b], where each component is in the range [0, 255] */
Expand Down Expand Up @@ -203,6 +204,9 @@ namespace gdjs {
if (initialInstanceData.customSize) {
this.setWrappingWidth(initialInstanceData.width);
}
if (initialInstanceData.opacity !== undefined) {
this.setOpacity(initialInstanceData.opacity);
}
}

onDestroyed(): void {
Expand Down
6 changes: 5 additions & 1 deletion Extensions/PanelSpriteObject/panelspriteruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace gdjs {
*/
export class PanelSpriteRuntimeObject
extends gdjs.RuntimeObject
implements gdjs.Resizable, gdjs.OpacityHandler {
implements gdjs.Resizable, gdjs.OpacityHandler
{
_rBorder: integer;
_lBorder: integer;
_tBorder: integer;
Expand Down Expand Up @@ -172,6 +173,9 @@ namespace gdjs {
this.setWidth(initialInstanceData.width);
this.setHeight(initialInstanceData.height);
}
if (initialInstanceData.opacity !== undefined) {
this.setOpacity(initialInstanceData.opacity);
}
}

/**
Expand Down
12 changes: 11 additions & 1 deletion Extensions/Spine/spineruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace gdjs {
gdjs.Resizable,
gdjs.Scalable,
gdjs.Animatable,
gdjs.OpacityHandler {
gdjs.OpacityHandler
{
private _opacity: float = 255;
private _scaleX: number = 1;
private _scaleY: number = 1;
Expand Down Expand Up @@ -208,6 +209,15 @@ namespace gdjs {
this.setSize(initialInstanceData.width, initialInstanceData.height);
this.invalidateHitboxes();
}
if (initialInstanceData.opacity !== undefined) {
this.setOpacity(initialInstanceData.opacity);
}
if (initialInstanceData.flippedX) {
this.flipX(initialInstanceData.flippedX);
}
if (initialInstanceData.flippedY) {
this.flipY(initialInstanceData.flippedY);
}
}

getDrawableX(): number {
Expand Down
8 changes: 6 additions & 2 deletions Extensions/TextInput/textinputruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace gdjs {
'text area',
] as const;

type SupportedInputType = typeof supportedInputTypes[number];
type SupportedInputType = (typeof supportedInputTypes)[number];

const parseInputType = (potentialInputType: string): SupportedInputType => {
const lowercasedNewInputType = potentialInputType.toLowerCase();
Expand Down Expand Up @@ -72,7 +72,8 @@ namespace gdjs {
*/
export class TextInputRuntimeObject
extends gdjs.RuntimeObject
implements gdjs.TextContainer, gdjs.Resizable, gdjs.OpacityHandler {
implements gdjs.TextContainer, gdjs.Resizable, gdjs.OpacityHandler
{
private _string: string;
private _placeholder: string;
private opacity: float = 255;
Expand Down Expand Up @@ -254,6 +255,9 @@ namespace gdjs {
this.setWidth(initialInstanceData.width);
this.setHeight(initialInstanceData.height);
}
if (initialInstanceData.opacity !== undefined) {
this.setOpacity(initialInstanceData.opacity);
}
}

onScenePaused(runtimeScene: gdjs.RuntimeScene): void {
Expand Down
6 changes: 5 additions & 1 deletion Extensions/TextObject/textruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace gdjs {
*/
export class TextRuntimeObject
extends gdjs.RuntimeObject
implements gdjs.TextContainer, gdjs.OpacityHandler {
implements gdjs.TextContainer, gdjs.OpacityHandler
{
_characterSize: number;
_fontName: string;
_bold: boolean;
Expand Down Expand Up @@ -328,6 +329,9 @@ namespace gdjs {
} else {
this.setWrapping(false);
}
if (initialInstanceData.opacity !== undefined) {
this.setOpacity(initialInstanceData.opacity);
}
}

/**
Expand Down
Loading

0 comments on commit 17f9b26

Please sign in to comment.