1 /**
2 ShadedSimpleProgressBar
3 Shows progress.
4
5 additional data the bar takes through the "data" parameter:
6 color: color of the inside
7 back_color: color of the background
8 width: length of the bar in pixels
9 height: height of the bar in pixels
10
11 graphics_name: name of the filled graphics
12 back_graphics_name: name of the empty graphics
13
14 image: id to get the graphics from
15 */
16
17 #include GUI_SimpleProgressBar
18
19
20 local graphics_name, back_graphics_name, image;
21
Init(to,max,cur,timeout,offset,visibility,proplist data)22 func Init(to, max, cur, timeout, offset, visibility, proplist data)
23 {
24 inherited(to, max, cur, timeout, offset, visibility, data);
25
26 image = data.image ?? GUI_ShadedSimpleProgressBar;
27 graphics_name = data.graphics_name ?? "Bar";
28 back_graphics_name = data.back_graphics_name ?? "Empty";
29
30 SetGraphics(back_graphics_name, image, 0, GFXOV_MODE_Base, nil, GFX_BLIT_Custom);
31 SetGraphics(graphics_name, image, 1, GFXOV_MODE_Base, nil, GFX_BLIT_Custom);
32 SetBarColor(data.color, data.back_color);
33 Update();
34 }
35
SetBarColor(c,b)36 func SetBarColor(c, b)
37 {
38 color = c ?? RGB(255, 255, 255);
39 back_color = b ?? RGB(255, 255, 255);
40
41 SetClrModulation(color, 1);
42 SetClrModulation(back_color, 0);
43 }
44
Update()45 func Update()
46 {
47 var p = (current * 100) / Max(1, maximum);
48 var w = (width * 1000) / 110;
49 var l = (width * p * 10) / 110;
50 SetObjDrawTransform((width * 1000) / 110, 0, 0, 0, (height * 1000) / 19, 0, 0);
51 SetObjDrawTransform(l, 0, -(w-l) * 55, 0, (height * 1000) / 19, 100, 1);
52 }
53
54 /*
55 adds an energy bar above the object.
56 The energy bar uses either target.HitPoints & GetDamage() or target->GetMaxEnergy() & target->GetEnergy().
57 */
AddEnergyBar()58 global func AddEnergyBar()
59 {
60 var e = AddEffect("ShowEnergyBar", this, 1, 0, nil, nil);
61 if (e)
62 return e.bar;
63 }
64
FxShowEnergyBarStart(target,effect,temp)65 global func FxShowEnergyBarStart(target, effect, temp)
66 {
67 if (temp) return;
68 var attachpoint = { x = 0, y = target->GetDefOffset(1) - 5};
69 var current, max;
70 if (target->GetCategory() & C4D_Living)
71 {
72 max = target->~GetMaxEnergy();
73 current = target->GetEnergy();
74 }
75 else
76 {
77 max = target.HitPoints;
78 current = max - target->GetDamage();
79 }
80
81 if (current == nil || max == nil)
82 return -1;
83
84 effect.bar = target->CreateProgressBar(GUI_ShadedSimpleProgressBar, max, current, 0, target->GetOwner(), attachpoint, nil, { width = 28, height = 6, color = RGB(200, 1, 1) });
85 effect.bar->SetPlane(750);
86 // update once
87 effect.Interval = 1;
88
89 return 1;
90 }
91
FxShowEnergyBarTimer(target,effect,time)92 global func FxShowEnergyBarTimer(target, effect, time)
93 {
94 var value;
95 if (target->GetCategory() & C4D_Living) value = target->GetEnergy();
96 else value = target.HitPoints - target->GetDamage();
97
98 effect.bar->SetValue(value);
99 effect.Interval = 0;
100 return 1;
101 }
102
FxShowEnergyBarDamage(target,effect,dmg,cause)103 global func FxShowEnergyBarDamage(target, effect, dmg, cause)
104 {
105 effect.Interval = 1;
106 return dmg;
107 }
108
FxShowEnergyBarStop(target,effect,reason,temp)109 global func FxShowEnergyBarStop(target, effect, reason, temp)
110 {
111 if (temp) return;
112 if (effect.bar)
113 effect.bar->Close();
114 }