Button

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
Obsessively create a hierarchical menu from a directory listing:
+
// Use this script on a guiTexture object for regular push buttons
 +
// that behave properly like Mac OS X.
  
<c>
+
var normalMaterial : Material;
- (void)addItemsFromPath:(NSString*)path toMenu:(NSMenu*)menu
+
var hoverMaterial : Material;
 +
var pressedMaterial : Material;
 +
var messagee : GameObject;
 +
var message = "ButtonPress";
 +
 
 +
private var state = 0;
 +
 
 +
function OnMouseEnter()
 
{
 
{
NSArray *puzzles;
+
state++;
NSString *puzz;
+
if (state == 1)
NSMenuItem *item;
+
guiText.material = hoverMaterial;
BOOL dir;
+
}
int i;
+
 
+
function OnMouseDown()
puzzles = [[NSFileManager defaultManager] directoryContentsAtPath:[puzzlePath stringByAppendingString:path]];
+
{
for(i = 0; i < [puzzles count]; i++) {
+
state++;
puzz = [puzzles objectAtIndex:i];
+
if (state == 2)
if([[puzz substringFromIndex:[puzz length]-4] isEqualToString:@".tsu"]) {
+
guiText.material = pressedMaterial;
boardData = [NSString stringWithContentsOfFile:[puzzlePath stringByAppendingString:[path stringByAppendingString:puzz]]];
+
}
[self getBoardSize];
+
 
item = [[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ (%d, %d)", puzz, boardwidth, boardheight] action:@selector(loadLevelFromMenu:) keyEquivalent:@""] autorelease];
+
function OnMouseUp()
[item setTarget:self];
+
{
[item setRepresentedObject:[[path stringByAppendingString:@"/"] stringByAppendingString:puzz]];
+
if (state == 2)
[menu addItem:item];
+
{
}
+
state--;
else {
+
if (messagee)
[[NSFileManager defaultManager] fileExistsAtPath:[[puzzlePath stringByAppendingString:path] stringByAppendingString:puzz] isDirectory:&dir];
+
messagee.SendMessage(message, gameObject);
if(dir) {
+
NSMenu *submenu = [[NSMenu alloc] initWithTitle:@""];
+
item = [[[NSMenuItem alloc] initWithTitle:puzz action:NULL keyEquivalent:@""] autorelease];
+
[self addItemsFromPath:[[path stringByAppendingString:puzz] stringByAppendingString:@"/"] toMenu:submenu];
+
[item setSubmenu:submenu];
+
[menu addItem:item];
+
}
+
}
+
 
}
 
}
 +
else
 +
{
 +
state --;
 +
if (state < 0)
 +
state = 0;
 +
}
 +
guiText.material = normalMaterial;
 +
}
 +
 +
function OnMouseExit()
 +
{
 +
if (state > 0)
 +
state--;
 +
if (state == 0)
 +
guiText.material = normalMaterial;
 
}
 
}
</c>
 

Revision as of 01:44, 1 December 2005

// Use this script on a guiTexture object for regular push buttons // that behave properly like Mac OS X.

var normalMaterial : Material; var hoverMaterial : Material; var pressedMaterial : Material; var messagee : GameObject; var message = "ButtonPress";

private var state = 0;

function OnMouseEnter() { state++; if (state == 1) guiText.material = hoverMaterial; }

function OnMouseDown() { state++; if (state == 2) guiText.material = pressedMaterial; }

function OnMouseUp() { if (state == 2) { state--; if (messagee) messagee.SendMessage(message, gameObject); } else { state --; if (state < 0) state = 0; } guiText.material = normalMaterial; }

function OnMouseExit() { if (state > 0) state--; if (state == 0) guiText.material = normalMaterial; }

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox