File: Script.c

package info (click to toggle)
openclonk 8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 169,520 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (75 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download | duplicates (7)
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
/*
	Progress-Bar element
	Author: Newton
	
	This object can show an unlimited amount of progress bars in different
	locations, sizes and colors. Using this basic funcionality, one could create
	floating health bars attached to clonks or include the bars as layers into
	(HUD) objects.
	This object is used by the crew selector.
*/

local offsx, offsy, layer, width, height;

protected func Construction()
{
	offsx = CreateArray();
	offsy = CreateArray();
	width = CreateArray();
	height = CreateArray();
	layer = CreateArray();
}

public func SetBarOffset(int x, int y, int num)
{
	offsx[num] = x;
	offsy[num] = y;
}

public func RemoveBarLayers(int la)
{
	// remove layers
	SetGraphics(nil,nil,la);
	SetGraphics(nil,nil,la+1);
}

public func SetBarLayers(int la, int num)
{
	RemoveBarLayers(la);

	// new layers
	layer[num] = la;
	SetGraphics("Empty",Library_Bars,layer[num],GFXOV_MODE_Base);
	SetGraphics("Bar",Library_Bars,layer[num]+1,GFXOV_MODE_Base);
}

public func SetBarDimensions(int wdt, int hgt, int num)
{
	width[num] = 1000 * wdt / Library_Bars->GetDefWidth();
	height[num] = 1000 * hgt / Library_Bars->GetDefHeight();
}

public func SetBarProgress(int promille, int num)
{
	// not existing
	if(GetLength(layer) <= num) return false;

	// width/height not set == 1000
	if(!width[num]) width[num] = 1000;
	if(!height[num]) height[num] = 1000;

	var w = Library_Bars->GetDefWidth()/2;
	
	// the bar does not start on the left side of the graphics... correct this
	var graphicscorrect = 100;
	
	var baroffset = offsx[num]*1000 - width[num]*w * (1000-promille)/(1000+graphicscorrect);

	SetObjDrawTransform(width[num],0,offsx[num]*1000, 0, height[num], offsy[num]*1000, layer[num]);
	SetObjDrawTransform((promille * width[num])/1000,0, baroffset, 0, height[num], offsy[num]*1000, layer[num]+1);

	return true;
}

// UI not saved.
func SaveScenarioObject() { return false; }