View Single Post
Old 2nd January 2003, 21:33   #15
iPlayTheSpoons
Major Dude
 
iPlayTheSpoons's Avatar
 
Join Date: Aug 2001
Location: SJSU
Posts: 1,030
Send a message via AIM to iPlayTheSpoons
drawers drawers drawers

heyyyy, stickied...thats pretty cool. now, as requested:

these are one of the most used things that requires maki, but need to be customizable enough where a premade script just doesnt work the same. theyre also exceedingly easy to write. in this here ill show you how to setp up some basic drawers, and some other cool stuff you can do too.

lets start with a script i just wrote last night, but does something not most drawers dont:

code:

//----------------------------------------------------------------------
// eq.m
//
// controls drawer sliding and anything else i add later....
//
//----------------------------------------------------------------------

#include "../../../lib/std.mi"

Global Container MainContainer;
Global Layout NormalLayout;
Global Group Equalizer;
Global Button Toggle, presets;
Global Togglebutton power, auto;
Global Layer buttonback;
Global Int B;

System.onScriptLoaded() {
MainContainer = getContainer("main");
Layout NormalLayout = System.getContainer("main").getLayout("normal");

Equalizer = NormalLayout.getObject("equalizer");
Toggle = Equalizer.getobject("toggle");
presets = Equalizer.getobject("presets");
power = Equalizer.getobject("power");
auto = Equalizer.getobject("auto");
buttonback = Equalizer.getobject("buttons.back");

B = 0;

}

Toggle.onLeftClick() {
if (B == 0) {
B = 1;
Equalizer.setTargetX(265);
Equalizer.setTargetY(13);
Equalizer.setTargetSpeed(0.5);
Equalizer.gotoTarget();
}
else if (B == 1) {
B = 0;
presets.setTargetY(111);
presets.setTargetSpeed(0.5);
presets.gotoTarget();
power.setTargetY(111);
power.setTargetSpeed(0.5);
power.gotoTarget();
auto.setTargetY(111);
auto.setTargetSpeed(0.5);
auto.gotoTarget();
buttonback.setTargetY(90);
buttonback.setTargetSpeed(0.5);
buttonback.gotoTarget();
}
}

Equalizer.onTargetReached() {
if (B == 1) {
presets.setTargetY(136);
presets.setTargetSpeed(0.5);
presets.gotoTarget();
power.setTargetY(136);
power.setTargetSpeed(0.5);
power.gotoTarget();
auto.setTargetY(136);
auto.setTargetSpeed(0.5);
auto.gotoTarget();
buttonback.setTargetY(115);
buttonback.setTargetSpeed(0.5);
buttonback.gotoTarget();
}
}

buttonback.onTargetReached() {
if (B == 0) {
Equalizer.setTargetX(112);
Equalizer.setTargetY(13);
Equalizer.setTargetSpeed(0.5);
Equalizer.gotoTarget();
}
}



ok, you should all know what the first part of that mess means by now. ive decalred the global int B so i know if the drawer is in or out. i set B = 0; at first, so i know 0 means its closed. you can have your toggle button inside or outside of the drawer group...in this case its inside

code:

Toggle.onLeftClick() {
if (B == 0) {
B = 1;
Equalizer.setTargetX(265);
Equalizer.setTargetY(13);
Equalizer.setTargetSpeed(0.5);
Equalizer.gotoTarget();
}



thats the heart of a drawer right there. its pretty self explanitory. when the user clicks the toggle button (which i declared and defined earlier), heres what happens: if B == 0 then the drawer is closed. i set B = 1 so the drawer is now considered open. Equalizer.setTargetY(13); means that the Equalizer group's new Y position will be ay 13 (in pixels) and Equalizer.setTargetX(265); means its new X position will be at 265. Equalizer.setTargetSpeed(0.5); is how fast the drawer will get there, 0 being that fastest, and slower the higher the number. we finish it off with Equalizer.gotoTarget();, telling the drawer to move to the set position at the set speed. that will always follow the most recently set numbers, so its good to keep the clustered. also , if your only moving your Y position, you dont need to setTargetX().


code:

Equalizer.onTargetReached() {
if (B == 1) {
presets.setTargetY(136);
presets.setTargetSpeed(0.5);
presets.gotoTarget();
power.setTargetY(136);
power.setTargetSpeed(0.5);
power.gotoTarget();
auto.setTargetY(136);
auto.setTargetSpeed(0.5);
auto.gotoTarget();
buttonback.setTargetY(115);
buttonback.setTargetSpeed(0.5);
buttonback.gotoTarget();
}
}



now, this is not nescessary to a drawer at all, but it shows a command that can be fun to use. the onTargetReached() command bascically says 'when the group is done moving...do this.". in this case, i have it so when the drawer is finished opening, i have a whole bunch of different things sliding down, without the user having to click or do anything...and it knows to do that only when the drawer is done opeining (and not done closing, because it only happens when B == 1)

that pretty much all for making a drawer script. here are some other commands you can use assoctiated with drawers:

setTargetW(x) // this can have your objects width change to what you set (in pixels)

setTargetH(x) // this can have your objects height change to what you set (in pixels)

setTargetA(x) // this can have your objects alpha change to what you set. alpha is transperency, so you can have a drawer fade in or out as it moves. a value between 0 - 255.
iPlayTheSpoons is offline   Reply With Quote