//-----------------------------------------------------------------------------
// volumebyframe.m
//
// Example of an Animated Volume bar using Frames
// (Improved, no longer requires HiddenVolume)
//
// written by FrisbeeMonkey
//-----------------------------------------------------------------------------
// USING THIS SCRIPT:
//*****************************************************************************
// 1. Define the following in your XML:
//
//
// Change the position(x,y) and size(w,h) of "VolumeAnim" to the specifics
// of your layer. (NOTE: w and h refer to just one frame, not the whole image)
// 2. Define your gradient map with your other elements using:
//
// If you need help creating a map file, check:
// http://www.stefanweb.com/wa3/tutorials.html#UsingMaps
// 3. Make sure your ticker is called "SongTicker" and is in the same group as
// "VolumeAnim". If you don't have a ticker, add one now.
// 4. Copy this script (and volumebyframe.maki) to your scripts folder.
// 5. If you don't have volumebyframe.maki, compile this script.
// 6. Add this line to the group that contains your layer and SongTicker
//
// 7. Refresh your skin(F5) and try it out.
//*****************************************************************************
// Never forget to include std.mi
#include
// Declare local functions for use in script
Function setVolumeAnim(int volValue);
Function updateVolume(int x, int y);
// Declare global variables for use in script
Global AnimatedLayer Volume;
Global Map VolumeMap;
Global Text SongTicker;
Global Timer SongTickerTimer;
Global Boolean VolumeChanging;
// When the script/skin is loaded, do this
System.onScriptLoaded() {
Group ScriptGrp = getScriptGroup();
// Get Volume Layer and SongTicker
Volume = ScriptGrp.findObject("VolumeAnim");
SongTicker = ScriptGrp.findObject("SongTicker");
// Initialize our timer
SongTickerTimer = new Timer;
SongTickerTimer.setDelay(750);
// Initialize Maps
VolumeMap = new Map;
VolumeMap.loadMap("player.map.Volume");
//Set Initial Volume Setting
setVolumeAnim(System.getVolume());
}
// Clears text area
SongTickerTimer.onTimer() {
SongTicker.setText("");
SongTickertimer.stop();
}
// Updates display and SongTicker on Volume changes
System.onVolumeChanged(int newVol) {
setVolumeAnim(newVol);
Songtickertimer.stop();
Songtickertimer.start();
int p = (newVol * 100) / 255;
Songticker.setAlternateText("Volume:" + System.integerToString(p) + "%)");
}
//sets the Animation to correct frame
setVolumeAnim(int Value) {
int f = (Value * (Volume.getLength()-1)) / 255;
if (Value > 0) {
Volume.gotoFrame(f+1);
}
if (Value == 255) {
Volume.gotoFrame(f);
}
if (Value == 0) {
Volume.gotoFrame(0);
}
}
// Handles Volume Mouse Events
Volume.onLeftButtonDown(int x, int y) {
VolumeChanging = 1;
updateVolume(x, y);
}
Volume.onLeftButtonUp(int x, int y) {
if (VolumeChanging) {
VolumeChanging = 0;
updateVolume(x, y);
}
}
Volume.onMouseMove(int x, int y) {
if (VolumeChanging) {
updateVolume(x, y);
}
}
// Updates Volume Image and System Position
updateVolume(int x, int y) {
int newValue = VolumeMap.getValue(x - Volume.getLeft(), y - Volume.getTop());
System.setVolume(newValue);
}
System.onScriptUnloading() {
delete SongTickerTimer;
delete VolumeMap;
}