Skip to content

Commit f018f4c

Browse files
committed
DragDropDemo: updated to latest modules + 3.6.0 compatibility
1 parent 5e0688f commit f018f4c

File tree

12 files changed

+116
-60
lines changed

12 files changed

+116
-60
lines changed

demos/DragDropDemo/DragDrop.asc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ struct DragDropSettings
88

99
eKeyCode HookKey; // default hook key
1010
MouseButton HookMBtn; // default hook mouse button
11+
bool AutoTrackHookKey; // track hook key press and release
1112
int DragMinDistance; // minimal number of pixels to start drag
1213
int DragMinTime; // minimal time to start drag
13-
14-
bool AutoTrackHookKey; // track hook key press and release
1514
DragDropUnhookAction DefaultUnhookAction; // what to do by default when the hook key is up
1615
};
1716

@@ -267,26 +266,26 @@ static void DragDrop::HookKeyDown(int user_key, MouseButton mbut)
267266

268267
//===========================================================================
269268
//
270-
// DragDrop::SetDragObject()
269+
// DragDrop::DragKeyUp()
271270
//
272271
//===========================================================================
273-
static void DragDrop::HookObject(int user_mode, int obj_x, int obj_y, int tag, String stag)
272+
static void DragDrop::HookKeyUp()
274273
{
275-
if (DDState.IsWantingObject())
276-
DDState.SetDragObject(user_mode, obj_x, obj_y, tag, stag);
274+
if (DDState.IsDragging())
275+
DDState.StartDropping();
276+
else
277+
DDState.Reset();
277278
}
278279

279280
//===========================================================================
280281
//
281-
// DragDrop::DragKeyUp()
282+
// DragDrop::SetDragObject()
282283
//
283284
//===========================================================================
284-
static void DragDrop::HookKeyUp()
285+
static void DragDrop::HookObject(int user_mode, int obj_x, int obj_y, int tag, String stag)
285286
{
286-
if (DDState.IsDragging())
287-
DDState.StartDropping();
288-
else
289-
DDState.Reset();
287+
if (DDState.IsWantingObject())
288+
DDState.SetDragObject(user_mode, obj_x, obj_y, tag, stag);
290289
}
291290

292291
//===========================================================================

demos/DragDropDemo/DragDrop.ash

Lines changed: 6 additions & 7 deletions
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
@@ -60,13 +60,12 @@ struct DragDrop
6060
import static attribute eKeyCode DefaultHookKey;
6161
/// Get/set default hook mouse button
6262
import static attribute MouseButton DefaultHookMouseButton;
63+
/// Get/set if the module should automatically track hook key press and release
64+
import static attribute bool AutoTrackHookKey;
6365
/// Get/set minimal number of pixels the mouse should move before it is considered to be dragging
6466
import static attribute int DragMinDistance;
65-
/// Get/set minimal time (in milliseconds) the mouse should move before it is considered to be dragging
67+
/// Get/set minimal time (in milliseconds) the hook key should be pressed down before it is considered to be dragging
6668
import static attribute int DragMinTime;
67-
68-
/// Get/set if the module should automatically track hook key press and release
69-
import static attribute bool AutoTrackHookKey;
7069
/// Get/set the default action that should be done to dragged object when the hook key is released;
7170
/// this action may be overriden by user by explicitly calling Drop() or Revert()
7271
import static attribute DragDropUnhookAction DefaultUnhookAction;
@@ -140,10 +139,10 @@ struct DragDrop
140139

141140
/// Notify hook key push down; this does not have to be real keycode
142141
import static void HookKeyDown(int user_key = 0, MouseButton mbtn = 0);
143-
/// Assign a draggable object for the module when it expects to find one under the mouse cursor
144-
import static void HookObject(int user_mode, int obj_x, int obj_y, int tag = 0, String stag = 0);
145142
/// Notify hook key release
146143
import static void HookKeyUp();
144+
/// Assign a draggable object for the module when it expects to find one under the mouse cursor
145+
import static void HookObject(int user_mode, int obj_x, int obj_y, int tag = 0, String stag = 0);
147146

148147
/// Drop the object now
149148
import static void Drop();

demos/DragDropDemo/DragDropCommon.asc

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ struct DragDropSettings
88
bool PixelPerfect; // pixel-perfect hit mode for AGS objects
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
11-
int GhostTransparency; // transparency value of the overlay
12-
bool GhostAlpha; // keep alpha channel when creating translucent overlays
1311
GUI* GhostGUI; // GUI to use for dragged object representation
12+
int GhostZOrder; // ZOrder to use for ghost representation
13+
int GhostTransparency; // transparency value of the ghost representation
14+
bool GhostAlpha; // keep alpha channel when creating translucent overlays
1415
};
1516

1617
DragDropSettings DDSet;
@@ -53,9 +54,10 @@ void Reset(this DragDropSettings*)
5354
this.PixelPerfect = false;
5455
this.TestClickable = false;
5556
this.Move = eDDCmnMoveSelf;
57+
this.GhostGUI = null;
58+
this.GhostZOrder = 1000; // max GUI zorder in 3.2.1, according to the manual
5659
this.GhostTransparency = 33;
5760
this.GhostAlpha = true;
58-
this.GhostGUI = null;
5961
}
6062

6163
//===========================================================================
@@ -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

@@ -390,47 +402,62 @@ void set_DragMove(this DragDropCommon*, DragDropCommonMove value)
390402

391403
//===========================================================================
392404
//
393-
// DragDropCommon::GhostTransparency property
405+
// DragDropCommon::GhostGUI property
394406
//
395407
//===========================================================================
396-
int get_GhostTransparency(this DragDropCommon*)
408+
GUI* get_GhostGUI(this DragDropCommon*)
397409
{
398-
return DDSet.GhostTransparency;
410+
return DDSet.GhostGUI;
399411
}
400412

401-
void set_GhostTransparency(this DragDropCommon*, int value)
413+
void set_GhostGUI(this DragDropCommon*, GUI* value)
402414
{
403-
DDSet.GhostTransparency = value;
415+
DDSet.GhostGUI = value;
404416
}
405417

406418
//===========================================================================
407419
//
408-
// DragDropCommon::GhostAlpha property
420+
// DragDropCommon::GhostZOrder property
409421
//
410422
//===========================================================================
411-
bool get_GhostAlpha(this DragDropCommon*)
423+
int get_GhostZOrder(this DragDropCommon*)
412424
{
413-
return DDSet.GhostAlpha;
425+
return DDSet.GhostZOrder;
414426
}
415427

416-
void set_GhostAlpha(this DragDropCommon*, bool value)
428+
void set_GhostZOrder(this DragDropCommon*, int value)
417429
{
418-
DDSet.GhostAlpha = value;
430+
DDSet.GhostZOrder = value;
419431
}
420432

421433
//===========================================================================
422434
//
423-
// DragDropCommon::GhostGUI property
435+
// DragDropCommon::GhostTransparency property
424436
//
425437
//===========================================================================
426-
GUI* get_GhostGUI(this DragDropCommon*)
438+
int get_GhostTransparency(this DragDropCommon*)
427439
{
428-
return DDSet.GhostGUI;
440+
return DDSet.GhostTransparency;
429441
}
430442

431-
void set_GhostGUI(this DragDropCommon*, GUI* value)
443+
void set_GhostTransparency(this DragDropCommon*, int value)
432444
{
433-
DDSet.GhostGUI = value;
445+
DDSet.GhostTransparency = value;
446+
}
447+
448+
//===========================================================================
449+
//
450+
// DragDropCommon::GhostAlpha property
451+
//
452+
//===========================================================================
453+
bool get_GhostAlpha(this DragDropCommon*)
454+
{
455+
return DDSet.GhostAlpha;
456+
}
457+
458+
void set_GhostAlpha(this DragDropCommon*, bool value)
459+
{
460+
DDSet.GhostAlpha = value;
434461
}
435462

436463
//===========================================================================
@@ -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

demos/DragDropDemo/DragDropCommon.ash

Lines changed: 23 additions & 15 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

@@ -66,28 +69,31 @@ struct DragDropCommon
6669
// Functions and properties meant to configure the drag'n'drop behavior.
6770
//
6871
///////////////////////////////////////////////////////////////////////////
69-
72+
7073
/// Get/set whether particular drag'n'drop mode is enabled
7174
import static attribute bool ModeEnabled[];
7275
/// Disable drag'n'drop for all the modes
7376
import static void DisableAllModes();
74-
77+
7578
/// Get/set whether click on AGS object should be tested using pixel-perfect detection
7679
/// (alternatively only hit inside bounding rectangle is tested)
7780
import static attribute bool PixelPerfect;
7881
/// Get/set whether only Clickable AGS objects should be draggable
7982
import static attribute bool TestClickable;
80-
83+
8184
/// Get/set the way object's drag around is represented
8285
import static attribute DragDropCommonMove DragMove;
83-
/// Get/set transparency of a representation used when DragStyle is NOT eDragDropMoveSelf
84-
import static attribute int GhostTransparency;
85-
/// Get/set whether representation should keep sprite's alpha channel
86-
import static attribute bool GhostAlpha;
8786
/// Get/set the GUI used to represent dragged object
8887
import static attribute GUI* GhostGUI;
89-
90-
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;
91+
/// Get/set whether representation should keep sprite's alpha channel
92+
import static attribute bool GhostAlpha;
93+
/// Get/set transparency of a representation used when DragStyle is NOT eDragDropMoveSelf
94+
import static attribute int GhostTransparency;
95+
96+
9197
///////////////////////////////////////////////////////////////////////////
9298
//
9399
// State control
@@ -96,7 +102,7 @@ struct DragDropCommon
96102
// and control its state.
97103
//
98104
///////////////////////////////////////////////////////////////////////////
99-
105+
100106
/// Gets current dragged character
101107
readonly import static attribute Character* _Character;
102108
/// Gets current dragged GUI
@@ -111,9 +117,11 @@ 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;
116-
124+
117125
/// Start dragging a character under cursor
118126
import static bool TryHookCharacter();
119127
/// Start dragging a GUI under cursor

0 commit comments

Comments
 (0)