aboutsummaryrefslogtreecommitdiff
path: root/Src/resources/skins/Big Bento/scripts/configtarget.m
blob: a1841046188eec97b9f35ca72a6e11ef179278fc (plain) (blame)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*---------------------------------------------------
-----------------------------------------------------
Filename:	configtarget.m
Version:	2.1

Type:		maki
Date:		04. Jan. 2007 - 22:46 
Edited by:	Martin Poehlmann aka Deimos
E-Mail:		martin@skinconsortium.com
Internet:	www.skinconsortium.com
		www.martin.deimos.de.vu

Note:		This script is based on configtarget.m
		from Winamp Modern
-----------------------------------------------------
---------------------------------------------------*/

#include <lib/std.mi>

// ------------------------------------------------------------------------------------
Global GuiObject target;
Global ComponentBucket buck;

Global GuiObject last, current;
// ------------------------------------------------------------------------------------
Function turnAllOffExcept(GuiObject except);
Function turnOn(GuiObject obj);
Function turnOff(GuiObject obj);

//Member int target.fff;

//function fff();
//Member button int fff();
// ------------------------------------------------------------------------------------


// ------------------------------------------------------------------------------------
// init
// ------------------------------------------------------------------------------------
System.onScriptLoaded()
{
	target = getScriptGroup().findObject("skin.config.target");
	buck = getScriptGroup().findObject("my.bucket");

	last = NULL;
	current = NULL;

	//debugInt(guiobject.fff);ffff

//	target.fff = 4;

	// turn off all
	GuiObject o = NULL;
	turnAllOffExcept(o);
}

// ------------------------------------------------------------------------------------
// save scroller position
// ------------------------------------------------------------------------------------
/*System.onScriptUnloading()
{
	if (buck)
	{
		setPrivateInt(getSkinName(), "", buck.getScroll());
	}
}*/

// ------------------------------------------------------------------------------------
// turn on last open
// ------------------------------------------------------------------------------------
buck.onStartup()
{
	//setScroll(getPrivateInt(getSkinName(), "settings_last_pos", 0));
	Group g = buck.enumChildren(getPrivateInt(getSkinName(), "settings_last_pos", 0));
	if (!g) g = buck.enumChildren(0);
	if (!g) return;
	ToggleButton btn = g.getObject("btn");
	if (btn) btn.leftClick();
}

// ------------------------------------------------------------------------------------
// this is called by the bucket button to switch to a new group
// ------------------------------------------------------------------------------------
target.onAction(String action, String param, int x, int y, int p1, int p2, GuiObject source)
{
	if (getToken(action,";",0) == "switchto")
	{
		String grp = getToken(action, ";", 1);
		String is_subpage = getToken(action, ";", 2);

		if (current != NULL)
		{
			last = current;
		}

		target.setXmlParam("groupid", grp);

		current = getScriptGroup().findObject(grp);

	//	setPrivateInt(getSkinName(), "settings_last_pos", stringToInteger(param));

		if (is_subpage!="subpage") turnAllOffExcept(source.getParent()); // getParent because the source is the button itself, the parent is the whole group item in the bucket
	}
}

// Hack to hide last item

last.onTargetReached ()
{
	if (getAlpha() == 0)
	{
		hide();
	}
}

// ------------------------------------------------------------------------------------
// turn off all buttons except for the parameter, also save last_page param based on param item
// ------------------------------------------------------------------------------------
turnAllOffExcept(GuiObject except)
{
	if (!buck) return;
	int i=0;
	// enumerate all inserted groups, turn them off if they're not our exception
	while (i<buck.getNumChildren())
	{
		GuiObject obj = buck.enumChildren(i);
		if (obj == except)
		{ // otherwise record last page
			setPrivateInt(getSkinName(), "settings_last_pos", i);
			i++;
			continue;
		}
		if (obj == NULL) { break; } // shoundnt happen
		turnOff(obj);
		i++;
	}
	// turn on the clicked item
	if (except) turnOn(except);
}

// ------------------------------------------------------------------------------------
turnOn(GuiObject obj)
{
	Group gobj = obj;

	// otherwise we just need this :
	ToggleButton tg = gobj.getObject("btn");
	tg.setActivated(1);
}

// ------------------------------------------------------------------------------------
turnOff(GuiObject obj)
{
	Group gobj = obj;

	// otherwise we just need this :
	ToggleButton tg = gobj.getObject("btn");
	tg.setActivated(0);
}