Skip to content

Commit 6657a9f

Browse files
authored
Merge pull request #2871 from ivan-mogilko/ags4--animatedoverlays
AGS 4: AnimatedOverlay
2 parents d95fd20 + 02da7e2 commit 6657a9f

File tree

13 files changed

+599
-67
lines changed

13 files changed

+599
-67
lines changed

Editor/AGS.Editor/Resources/agsdefns.sh

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,28 @@ enum StringSplitOptions {
669669
};
670670
#endif // SCRIPT_API_v400
671671
672+
#ifdef SCRIPT_API_v350
673+
enum GUIPopupStyle {
674+
eGUIPopupNormal = 0,
675+
eGUIPopupMouseYPos = 1,
676+
eGUIPopupModal = 2,
677+
eGUIPopupPersistent = 3
678+
};
679+
#endif // SCRIPT_API_v350
680+
681+
enum BlockingStyle {
682+
eBlock = 919,
683+
eNoBlock = 920
684+
};
685+
enum Direction {
686+
eForwards = 1062,
687+
eBackwards = 1063
688+
};
689+
enum WalkWhere {
690+
eAnywhere = 304,
691+
eWalkableAreas = 305
692+
};
693+
672694
internalstring autoptr builtin managed struct String {
673695
/// Creates a formatted string using the supplied parameters.
674696
import static String Format(__format const string format, ...); // $AUTOCOMPLETESTATICONLY$
@@ -1341,6 +1363,28 @@ builtin managed struct Overlay {
13411363
#endif // SCRIPT_API_v400_18
13421364
};
13431365

1366+
#ifdef SCRIPT_API_v400_22
1367+
builtin managed struct AnimatedOverlay extends Overlay
1368+
{
1369+
/// Creates a AnimatedOverlay object on the screen layer, optionally using a initial sprite
1370+
import static AnimatedOverlay* CreateAnimated(int x, int y, int slot = 0, bool pauseWithGame = true); // $AUTOCOMPLETESTATICONLY$
1371+
/// Creates a AnimatedOverlay object on the room layer, optionally using a initial sprite
1372+
import static AnimatedOverlay* CreateRoomAnimated(int x, int y, int slot = 0, bool pauseWithGame = true); // $AUTOCOMPLETESTATICONLY$
1373+
/// Animates the overlay using the specified view loop.
1374+
import void Animate(int view, int loop, int delay, RepeatStyle=eOnce, BlockingStyle=eNoBlock, Direction=eForwards, int frame=0, int volume=100);
1375+
/// Gets whether the overlay is currently animating.
1376+
import readonly attribute bool Animating;
1377+
/// Gets the current frame number during an animation.
1378+
import readonly attribute int Frame;
1379+
/// Gets the current loop number during an animation.
1380+
import readonly attribute int Loop;
1381+
/// Gets whether the overlay's animation is paused when the game is paused.
1382+
import readonly attribute bool PauseWithGame;
1383+
/// Gets the current view number during an animation.
1384+
import readonly attribute int View;
1385+
};
1386+
#endif // SCRIPT_API_v400_22
1387+
13441388
#ifdef SCRIPT_API_v400
13451389
enum ColorFormat
13461390
{
@@ -1517,28 +1561,6 @@ import int FindGUIID(const string); // $AUTOCOMPLETEIGNORE$
15171561
import void SkipCutscene();
15181562
#endif // SCRIPT_API_v3507
15191563

1520-
#ifdef SCRIPT_API_v350
1521-
enum GUIPopupStyle {
1522-
eGUIPopupNormal = 0,
1523-
eGUIPopupMouseYPos = 1,
1524-
eGUIPopupModal = 2,
1525-
eGUIPopupPersistent = 3
1526-
};
1527-
#endif // SCRIPT_API_v350
1528-
1529-
enum BlockingStyle {
1530-
eBlock = 919,
1531-
eNoBlock = 920
1532-
};
1533-
enum Direction {
1534-
eForwards = 1062,
1535-
eBackwards = 1063
1536-
};
1537-
enum WalkWhere {
1538-
eAnywhere = 304,
1539-
eWalkableAreas = 305
1540-
};
1541-
15421564
// forward-declare these so that they can be returned by GUIControl class
15431565
builtin managed struct GUI;
15441566
builtin managed struct Label;

Engine/ac/button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ void Button_Animate(GUIButton *butt, int view, int loop, int speed, int repeat,
8888
abtn.anim = ViewAnimateParams(static_cast<AnimFlowStyle>(repeat), static_cast<AnimFlowDirection>(direction), speed, volume);
8989
abtn.frame = SetFirstAnimFrame(view, loop, sframe, static_cast<AnimFlowDirection>(direction));
9090
abtn.wait = abtn.anim.Delay + views[abtn.view].loops[abtn.loop].frames[abtn.frame].speed;
91-
animbuts.push_back(abtn);
9291
// launch into the first frame, and play the first frame's sound
9392
ABut_CheckViewFrame(abtn);
93+
animbuts.push_back(std::move(abtn));
9494

9595
// Blocking animate
9696
if (blocking)

Engine/ac/dynobj/scriptoverlay.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@
2222

2323
using namespace AGS::Common;
2424

25+
const char *ScriptOverlay::GetType()
26+
{
27+
return "Overlay";
28+
}
29+
2530
int ScriptOverlay::Dispose(void* /*address*/, bool force)
2631
{
2732
// since the managed object is being deleted, remove the
2833
// reference so it doesn't try and dispose something else
2934
// with that handle later
30-
if (overlayId >= 0)
35+
if (_overlayID >= 0)
3136
{
32-
auto *over = get_overlay(overlayId);
37+
auto *over = get_overlay(_overlayID);
3338
if (over)
3439
{
3540
over->DetachScriptObject();
@@ -48,37 +53,45 @@ int ScriptOverlay::Dispose(void* /*address*/, bool force)
4853
return 1;
4954
}
5055

51-
const char *ScriptOverlay::GetType() {
52-
return "Overlay";
53-
}
54-
5556
size_t ScriptOverlay::CalcSerializeSize(const void* /*address*/)
5657
{
57-
return sizeof(int32_t) * 4;
58+
return sizeof(int32_t);
5859
}
5960

60-
void ScriptOverlay::Serialize(const void* /*address*/, Stream *out) {
61-
out->WriteInt32(overlayId);
62-
out->WriteInt32(0); // unused (was text window x padding)
63-
out->WriteInt32(0); // unused (was text window y padding)
64-
out->WriteInt32(0); // unused (was internal ref flag)
61+
void ScriptOverlay::Serialize(const void* /*address*/, Stream *out)
62+
{
63+
out->WriteInt32(_overlayID);
6564
}
6665

67-
void ScriptOverlay::Unserialize(int index, Stream *in, size_t /*data_sz*/) {
68-
overlayId = in->ReadInt32();
69-
in->ReadInt32(); // unused (was text window x padding)
70-
in->ReadInt32(); // unused (was text window y padding)
71-
in->ReadInt32(); // unused (was internal ref flag)
66+
void ScriptOverlay::Unserialize(int index, Stream *in, size_t /*data_sz*/)
67+
{
68+
_overlayID = in->ReadInt32();
69+
// NOTE: some older formats had 3 more int32 here, which we exclude now
7270
ccRegisterUnserializedObject(index, this, this);
7371
}
7472

75-
void ScriptOverlay::Remove()
73+
void ScriptOverlay::Remove()
7674
{
77-
if (overlayId < 0)
75+
if (_overlayID < 0)
7876
{
7977
debug_script_warn("Overlay.Remove: overlay is invalid, could have been removed earlier.");
8078
return;
8179
}
82-
remove_screen_overlay(overlayId);
83-
overlayId = -1;
80+
remove_screen_overlay(_overlayID);
81+
_overlayID = -1;
82+
}
83+
84+
const char *ScriptAnimatedOverlay::GetType()
85+
{
86+
return "AnimatedOverlay";
87+
}
88+
89+
int ScriptAnimatedOverlay::Dispose(void *address, bool force)
90+
{
91+
if (!force && _overlayID >= 0)
92+
{
93+
RemoveAnimatedOverlay(_overlayID);
94+
}
95+
96+
return ScriptOverlay::Dispose(address, force);
8497
}

Engine/ac/dynobj/scriptoverlay.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,35 @@
1616

1717
#include "ac/dynobj/cc_agsdynamicobject.h"
1818

19-
struct ScriptOverlay final : AGSCCDynamicObject
19+
struct ScriptOverlay : AGSCCDynamicObject
2020
{
2121
public:
22-
int overlayId = -1;
23-
24-
int Dispose(void *address, bool force) override;
22+
ScriptOverlay() = default;
23+
ScriptOverlay(int over_id) : _overlayID(over_id) {}
2524
const char *GetType() override;
25+
int Dispose(void *address, bool force) override;
2626
void Unserialize(int index, AGS::Common::Stream *in, size_t data_sz) override;
2727
void Remove();
28-
ScriptOverlay() = default;
28+
29+
int GetOverlayID() const { return _overlayID; }
30+
void Invalidate() { _overlayID = -1; }
2931

3032
protected:
3133
// Calculate and return required space for serialization, in bytes
3234
size_t CalcSerializeSize(const void *address) override;
3335
// Write object data into the provided stream
3436
void Serialize(const void *address, AGS::Common::Stream *out) override;
37+
38+
int _overlayID = -1;
39+
};
40+
41+
struct ScriptAnimatedOverlay final : ScriptOverlay
42+
{
43+
public:
44+
ScriptAnimatedOverlay() = default;
45+
ScriptAnimatedOverlay(int over_id) : ScriptOverlay(over_id) {}
46+
const char *GetType() override;
47+
int Dispose(void *address, bool force) override;
3548
};
3649

37-
#endif // __AC_SCRIPTOVERLAY_H
50+
#endif // __AC_SCRIPTOVERLAY_H

0 commit comments

Comments
 (0)