Skip to content

Commit 5e0688f

Browse files
committed
DragDropCommon: updated to 3.6.0 features
* Allow customize representation's ZOrder; * Added DragDropCommon.GhostOverlay redonly property; * Overlays can have Transparency and ZOrder if it's AGS 3.6.0 or higher;
1 parent 1fcd096 commit 5e0688f

3 files changed

Lines changed: 56 additions & 11 deletions

File tree

scripts/ui/DragDrop/DragDrop.ash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#ifndef __MOUSE_DRAGDROP_MODULE__
2525
#define __MOUSE_DRAGDROP_MODULE__
2626

27-
#define MOUSE_DRAGDROP_VERSION_00_01_01_00
27+
#define MOUSE_DRAGDROP_VERSION_00_01_02_00
2828

2929
// Comment this line out to completely disable DragDrop during compilation
3030
#define ENABLE_MOUSE_DRAGDROP

scripts/ui/DragDrop/DragDropCommon.asc

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ struct DragDropSettings
99
bool TestClickable; // test Clickable property for AGS objects
1010
DragDropCommonMove Move; // whether object is dragged itself, or overlay with object's image on it
1111
GUI* GhostGUI; // GUI to use for dragged object representation
12-
int GhostTransparency; // transparency value of the overlay
12+
int GhostZOrder; // ZOrder to use for ghost representation
13+
int GhostTransparency; // transparency value of the ghost representation
1314
bool GhostAlpha; // keep alpha channel when creating translucent overlays
1415
};
1516

@@ -54,6 +55,7 @@ void Reset(this DragDropSettings*)
5455
this.TestClickable = false;
5556
this.Move = eDDCmnMoveSelf;
5657
this.GhostGUI = null;
58+
this.GhostZOrder = 1000; // max GUI zorder in 3.2.1, according to the manual
5759
this.GhostTransparency = 33;
5860
this.GhostAlpha = true;
5961
}
@@ -65,9 +67,11 @@ void Reset(this DragDropSettings*)
6567
//
6668
//===========================================================================
6769
int CreateRepresentation(this DragDropState*, DragDropCommonMove move, int x, int y, int offx, int offy,
68-
int slot, int trans, bool has_alpha)
70+
int slot, int trans, int zorder, bool has_alpha)
6971
{
7072
this.GhostGraphic = slot;
73+
#ifndef SCRIPT_API_v360
74+
// NOTE: pre-3.6.0 did not support Overlay.Transparency
7175
if (move != eDDCmnMoveGhostGUI &&
7276
trans != 100 && trans != 0)
7377
{
@@ -78,11 +82,16 @@ int CreateRepresentation(this DragDropState*, DragDropCommonMove move, int x, in
7882
this.GhostDspr = spr;
7983
slot = spr.Graphic;
8084
}
85+
#endif
8186
this.OverlayOffX = offx;
8287
this.OverlayOffY = offy;
8388
if (move == eDDCmnMoveGhostOverlay)
8489
{
8590
this.GhostOverlay = Overlay.CreateGraphical(x + offx, y + offy, slot, true);
91+
#ifdef SCRIPT_API_v360
92+
this.GhostOverlay.Transparency = trans;
93+
this.GhostOverlay.ZOrder = zorder;
94+
#endif
8695
}
8796
else
8897
{
@@ -93,7 +102,7 @@ int CreateRepresentation(this DragDropState*, DragDropCommonMove move, int x, in
93102
this.GhostGUI.Y = y + offy;
94103
this.GhostGUI.Width = Game.SpriteWidth[slot];
95104
this.GhostGUI.Height = Game.SpriteHeight[slot];
96-
this.GhostGUI.ZOrder = 1000; // max zorder, according to the manual
105+
this.GhostGUI.ZOrder = zorder;
97106
this.GhostGUI.Visible = true;
98107
}
99108
this.Move = move;
@@ -168,7 +177,7 @@ static bool DragDropCommon::TryHookCharacter()
168177
if (vf != null)
169178
sprite = vf.Graphic;
170179
DDState.CreateRepresentation(DDSet.Move, c.x, c.y, 0, -Game.SpriteHeight[sprite], sprite,
171-
DDSet.GhostTransparency, DDSet.GhostAlpha);
180+
DDSet.GhostTransparency, DDSet.GhostZOrder, DDSet.GhostAlpha);
172181
}
173182
return true;
174183
}
@@ -190,6 +199,7 @@ static bool DragDropCommon::TryHookGUI()
190199
return false;
191200
DDState._GUI = g;
192201
DragDrop.HookObject(eDragDropGUI, g.X, g.Y);
202+
// NOTE: GUIs may be only dragged on their own
193203
return true;
194204
}
195205

@@ -211,6 +221,7 @@ static bool DragDropCommon::TryHookGUIControl()
211221
return false;
212222
DDState._GUIControl = gc;
213223
DragDrop.HookObject(eDragDropGUIControl, gc.X, gc.Y);
224+
// NOTE: GUI Controls may be only dragged on their own
214225
return true;
215226
}
216227

@@ -247,7 +258,7 @@ static bool DragDropCommon::TryHookRoomObject()
247258
sprite = o.Graphic;
248259
}
249260
DDState.CreateRepresentation(DDSet.Move, o.X, o.Y, 0, -Game.SpriteHeight[sprite], sprite,
250-
DDSet.GhostTransparency, DDSet.GhostAlpha);
261+
DDSet.GhostTransparency, DDSet.GhostZOrder, DDSet.GhostAlpha);
251262
}
252263
return true;
253264
}
@@ -271,9 +282,10 @@ static bool DragDropCommon::TryHookInventoryItem()
271282
int i_x = DragDrop.DragStartX - (DragDrop.DragStartX - wnd.OwningGUI.X - wnd.X) % wnd.ItemWidth;
272283
int i_y = DragDrop.DragStartY - (DragDrop.DragStartY - wnd.OwningGUI.Y - wnd.Y) % wnd.ItemHeight;
273284
DragDrop.HookObject(eDragDropInvItem, i_x, i_y);
285+
// NOTE: Inventory Items may be only dragged using representation
274286
int sprite = i.Graphic;
275287
DDState.CreateRepresentation(DDSet.Move, i_x, i_y, 0, 0, sprite,
276-
DDSet.GhostTransparency, DDSet.GhostAlpha);
288+
DDSet.GhostTransparency, DDSet.GhostZOrder, DDSet.GhostAlpha);
277289
return true;
278290
}
279291

@@ -403,6 +415,21 @@ void set_GhostGUI(this DragDropCommon*, GUI* value)
403415
DDSet.GhostGUI = value;
404416
}
405417

418+
//===========================================================================
419+
//
420+
// DragDropCommon::GhostZOrder property
421+
//
422+
//===========================================================================
423+
int get_GhostZOrder(this DragDropCommon*)
424+
{
425+
return DDSet.GhostZOrder;
426+
}
427+
428+
void set_GhostZOrder(this DragDropCommon*, int value)
429+
{
430+
DDSet.GhostZOrder = value;
431+
}
432+
406433
//===========================================================================
407434
//
408435
// DragDropCommon::GhostTransparency property
@@ -571,6 +598,16 @@ int get_ObjectHeight(this DragDropCommon*)
571598
return 0;
572599
}
573600

601+
//===========================================================================
602+
//
603+
// DragDropCommon::GhostOverlay property
604+
//
605+
//===========================================================================
606+
Overlay* get_GhostOverlay(this DragDropCommon*)
607+
{
608+
return DDState.GhostOverlay;
609+
}
610+
574611
//===========================================================================
575612
//
576613
// DragDropCommon::UsedGhostGraphic property

scripts/ui/DragDrop/DragDropCommon.ash

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#error DragDropCommon requires DragDrop module
2929
#endif
3030

31-
#define MOUSE_DRAGDROPCOMMON_VERSION_00_01_01_00
31+
#define MOUSE_DRAGDROPCOMMON_VERSION_00_01_02_00
3232

3333
// Comment this line out to completely disable DragDropCommon during compilation
3434
#define ENABLE_MOUSE_DRAGDROPCOMMON
@@ -48,12 +48,15 @@ enum DragDropCommonMode
4848
// DragDropCommonMove enumeration determines the way hooked object is being dragged around
4949
enum DragDropCommonMove
5050
{
51-
// drag actual object itself (position updates real-time)
51+
// drag actual object itself (position updates real-time);
52+
// this works for everything except inventory items (because they do not have
53+
// actual position on screen on their own)
5254
eDDCmnMoveSelf,
5355
// drag overlay with object's image, while object stays in place until drag ends;
54-
// this currently works only for characters and room objects!
56+
// this works for everything except GUI and controls
5557
eDDCmnMoveGhostOverlay,
56-
// drag GUI with object's image; this is currently only way to drag inventory items
58+
// drag GUI with object's image;
59+
// this works for everything except GUI and controls
5760
eDDCmnMoveGhostGUI
5861
};
5962

@@ -82,6 +85,9 @@ struct DragDropCommon
8285
import static attribute DragDropCommonMove DragMove;
8386
/// Get/set the GUI used to represent dragged object
8487
import static attribute GUI* GhostGUI;
88+
/// Get/set the wanted z-order of a ghost representation (GUI or Overlay);
89+
/// please note that Overlays can have ZOrder only since AGS 3.6.0.
90+
import static attribute int GhostZOrder;
8591
/// Get/set whether representation should keep sprite's alpha channel
8692
import static attribute bool GhostAlpha;
8793
/// Get/set transparency of a representation used when DragStyle is NOT eDragDropMoveSelf
@@ -111,6 +117,8 @@ struct DragDropCommon
111117
readonly import static attribute int ObjectWidth;
112118
/// Gets current dragged object's or its representation height
113119
readonly import static attribute int ObjectHeight;
120+
/// Gets current Overlay representing the dragged object (only if drag style is eDDCmnMoveGhostOverlay)
121+
readonly import static attribute Overlay* GhostOverlay;
114122
/// Gets current dragged overlay's graphic (only if drag style is NOT eDragDropMoveSelf)
115123
readonly import static attribute int UsedGhostGraphic;
116124

0 commit comments

Comments
 (0)