summaryrefslogtreecommitdiffstats
path: root/SelectMark.c4d/Script.c
blob: 84080ce1567ba9a754bc3f041e8d1c0291b9bc3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#strict 2

local attachEffect;

global func CreateSelectMark() { return CreateObject(SELM, 0, 0, GetOwner()); }

func Padding(int forVal) { return (forVal < 3) * 2; }

func Initialize()
{
	Hide();
	SetAction("UpperLeft");
	Primary();
}

func MarkObject(object obj, int time, bool noShow)
{
	if(!noShow)
	{
		Show();
	}
	var id = GetID(obj);
	var w = GetObjWidth(obj);
	var h = GetObjHeight(obj);
	var x = GetX(obj) + GetDefOffset(id) + (GetDefWidth(id) - w) / 2;
	var y = GetY(obj) + GetDefOffset(id, 1) + (GetDefHeight(id) - h) / 2;
	var xOff = 0;
	var xPad = Padding(w);
	var yPad = Padding(h);
	if(x - xPad < 0)
	{
		x -= (xOff = -(w + 2 * xPad));
	}
	SetPosition(x - xPad, y - yPad);
	SetObjDrawTransform(1000, 0, xOff * 1000, 0, 1000, 0, this, 0);
	SetObjDrawTransform(1000, 0, (xOff + w + 2 * xPad) * 1000, 0, 1000, 0, this, 1);
	SetObjDrawTransform(1000, 0, xOff * 1000, 0, 1000, (h + 2 * yPad) * 1000, this, 2);
	SetObjDrawTransform(1000, 0, (xOff + w + 2 * xPad) * 1000, 0, 1000, (h + 2 * yPad) * 1000, this, 3);

	if(time != -1)
	{
		if(attachEffect && attachEffect[0] != obj)
		{
			RemoveEffect(0, attachEffect[0], attachEffect[1]);
		}
		if(!attachEffect)
		{
			AddEffect("SelectionMarkAttach", obj, 1, 1, this, 0, time);
		}
	}
	return this;
}

func Hide()
{
	SetVisibility(VIS_None, this);
}

func Show()
{
	SetVisibility(VIS_Owner, this);
}

func FxSelectionMarkAttachStart(object target, int effectNumber, int temp, int time)
{
	attachEffect = [target, effectNumber];
	EffectVar(0, target, effectNumber) = time;
}

func FxSelectionMarkAttachTimer(object target, int effectNumber, int effectTime)
{
	var time = EffectVar(0, target, effectNumber);
	if(time && effectTime > time)
	{
		return RemoveObject();
	}
	MarkObject(target, -1, true);
}

func FxSelectionMarkAttachStop(object target, int effectNumber)
{
	attachEffect = 0;
}

func Primary()
{
	SetGraphics();
	SetGraphics(0, this, GetID(), 1, GFXOV_MODE_Action, "UpperRight");
	SetGraphics(0, this, GetID(), 2, GFXOV_MODE_Action, "LowerLeft");
	SetGraphics(0, this, GetID(), 3, GFXOV_MODE_Action, "LowerRight");
	return this;
}

func Secondary()
{
	SetGraphics("2");
	SetGraphics("2", this, GetID(), 1, GFXOV_MODE_Action, "UpperRight");
	SetGraphics("2", this, GetID(), 2, GFXOV_MODE_Action, "LowerLeft");
	SetGraphics("2", this, GetID(), 3, GFXOV_MODE_Action, "LowerRight");
	return this;
}