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 (128 lines) | stat: -rw-r--r-- 3,558 bytes parent folder | download | duplicates (5)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
	Default
	This is a simple stand-alone menu that can be used to present arbitrary items to the player.
	
	Internally, a list-style menu is used.
*/


local Name = "Default Menu";
local menu_id = nil;
local on_mouse_over_callback = nil;
local on_mouse_out_callback = nil;


func Construction()
{
	_inherited(...);
	this.topic = 
	{
		Bottom = "1.5em",
		BackgroundColor = RGB(50, 50, 50),
		Style = GUI_TextHCenter | GUI_TextVCenter,
		ID = 2,
		Target = this
		// Text = nil, <- will be set with SetTitle
	};
	this.container = 
	{
		Top = "3em",
		list_submenu = CreateObject(MenuStyle_List, nil, nil, NO_OWNER),
		description_submenu = 
		{
			ID = 5,
			Target = this,
			Left = "50%",
			textbox = {Top = "6em"},
			headline = {Top = "4.5em", Bottom = "5.5em", BackgroundColor = RGB(50, 50, 50), Style = GUI_TextVCenter | GUI_TextHCenter},
			icon = {Bottom = "4em"}
		}
	};
	this.Target = this;
	this.Visibility = VIS_Owner;
	this.BackgroundColor = RGB(1, 1, 1);
	this.Decoration = GUI_MenuDeco;
	this.container.list_submenu.Right = "50%";
	
	// Hook into MouseIn/Out of the list menu to be able to show a description.
	this.container.list_submenu->SetMouseOverCallback(this, "OnMouseOverListMenu");
	this.container.list_submenu->SetMouseOutCallback(this, "OnMouseOutListMenu");
}

/* Updates the description box on the right side on mouse-over. */
func UpdateDescription(id obj)
{
	if (!menu_id) return;
	
	var symbol = nil, text = nil, headline = nil;
	if (obj)
	{
		headline = obj->GetName();
		text = obj.Description;
		symbol = obj;
	}
	
	var update =
	{
		headline = {Text = headline},
		textbox = {Text = text},
		icon = {Symbol = symbol}
	};
	GuiUpdate(update, menu_id, 5, this);
}

/* Sets the headline of the menu. This can also be called after the menu had been opened. */
public func SetTitle(string text)
{
	this.topic.Text = text;
	
	if (menu_id) // already opened?
		GuiUpdateText(text, menu_id, 2, this);
}

/* Opens the menu as a stand-alone menu. Don't forget to call clonk->SetMenu(menu) first, if it's for a clonk. */
public func Open()
{
	menu_id = GuiOpen(this);
	return menu_id;
}

/* Closes the menu. */
public func Close()
{
	// The list-style submenu cares about removing its menu and executing potential callbacks.
	RemoveObject();
}

/* We need to have a wrapper around the MouseIn/Out callbacks, as we want to show a description. */
func SetMouseOverCallback(proplist target, callback)
{
	on_mouse_over_callback = [target, callback];
}

func SetMouseOutCallback(proplist target, callback)
{
	on_mouse_out_callback = [target, callback];
}

func OnMouseOverListMenu(parameter, int user_ID, int player)
{
	if (on_mouse_over_callback)
		on_mouse_over_callback[0]->Call(on_mouse_over_callback[1], parameter, user_ID, player);
	UpdateDescription(parameter);
}

func OnMouseOutListMenu(parameter, int user_ID, int player)
{
	if (on_mouse_out_callback)
		on_mouse_out_callback[0]->Call(on_mouse_out_callback[1], parameter, user_ID, player);
}

/* This mimics the interface of the list-style menu. */
public func SetPermanent(...) { return this.container.list_submenu->SetPermanent(...); }
public func SetFitChildren(...) { return this.container.list_submenu->SetFitChildren(...); }
public func SetCloseCallback(...) { return this.container.list_submenu->SetCloseCallback(...); }
public func AddItem(...) { return this.container.list_submenu->AddItem(...); }
public func UpdateItem(...) { return this.container.list_submenu->UpdateItem(...); }
public func RemoveItem(...) { return this.container.list_submenu->RemoveItem(...); }