// LogoutButtonView // Responsible for maintaining the appearence of the logout button // and fowarding/interpreting buttonPressed events for it. // Copyright (C) 2005-2006 Francisco V. Saldana // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // Francisco V. Saldana can be contacted using his email account // username: dressedinblue, at domain: gmail.com // and in Second Life by IMming Christopher Omega // Upon getting its buttonPressed method triggered, // this component first identifys what line corresponds with the button. // If a line does not correspond with the button, it doesnt do anything. // If it does, it triggeres a lineButtonPressed(integer lineNum) event. // Method calling: // ========== For method invocation ========== string randomStr(string chars, integer len) { integer numChars = llStringLength(chars); string ret; integer i; for (i = 0; i < len; i++) { integer randIndex = llFloor(llFrand(numChars)); ret += llGetSubString(chars, randIndex, randIndex); } return ret; } string SEPERATOR_CHARS = "`~!@#$%^&*()-_+[]{}\|'\";/?.>,<"; integer SEPERATOR_LEN = 3; string dumpList2String(list src) { // Generate a seperator not present in any of the // elements in the list. string chars = (string) src; // Squashes all elements together. string seperator; do { seperator = randomStr(SEPERATOR_CHARS, SEPERATOR_LEN); } while (llSubStringIndex(chars, seperator) != -1); return seperator + llDumpList2String(src, seperator); } list parseStringKeepNulls(string src) { // The seperator should be the first SEPERATOR_LEN // characters in the string. return llParseStringKeepNulls(llDeleteSubString(src, 0, SEPERATOR_LEN - 1), [llGetSubString(src, 0, SEPERATOR_LEN - 1)], []); } callMethod(integer callId, string methodName, list parameters) { llMessageLinked(LINK_THIS, callId, dumpList2String(parameters), methodName); } returnValue(string methodName, integer methodIdentifyer, list value) { llMessageLinked(LINK_THIS, methodIdentifyer, dumpList2String(value), methodName + "_ret"); } // ============================================= trigger_addButtonListener(string buttonNamePattern) { callMethod(0, "addButtonListener", [buttonNamePattern]); } trigger_removeButtonListener(string buttonNamePattern) { callMethod(0, "removeButtonListener", [buttonNamePattern]); } trigger_logoutButtonPressed() { callMethod(0, "logoutButtonPressed", []); } trigger_pong(string moduleName) { callMethod(0, "pong", [moduleName]); } // ============ llDetected* Related ============ integer DETECTED_KEY = 1002; integer DETECTED_LINK_NUMBER = 1003; integer DETECTED_NAME = 1004; integer DETECTED_POS = 1006; integer DETECTED_ROT = 1007; list getDetectedValue(list detectedData, integer detectedConstant) { integer index = llListFindList(detectedData, [(string) detectedConstant]); if (index != -1) { return llList2List(detectedData, index + 1, index + 1); } return []; } buttonInit() { trigger_addButtonListener(LOGOUT_BUTTON_NAME); } // Name of the logout button string LOGOUT_BUTTON_NAME = "logout"; // Color button changes to when its pressed. vector COLOR_PRESSED = <0.5, 0.5, 1>; // Color button changes to when its released, the button // stays this color after the press->release process. vector COLOR_RELEASED = <1, 1, 1>; string this; default { state_entry() { buttonInit(); this = llGetScriptName(); state running; } } state running { state_entry() { } link_message(integer sender, integer num, string parameters, key methodName) { if (methodName == "buttonPressed") { list paramList = parseStringKeepNulls(parameters); // Method signature: // buttonPressed(string buttonName, list detectedData) // Triggered when a registered button is pressed. string buttonName = llList2String(paramList, 0); list detectedData = parseStringKeepNulls(llList2String(paramList, 1)); // If the button released is a line button: if (buttonName == LOGOUT_BUTTON_NAME) { integer buttonLinkNum = (integer) ((string) getDetectedValue(detectedData, DETECTED_LINK_NUMBER)); trigger_logoutButtonPressed(); llSetLinkColor(buttonLinkNum, COLOR_PRESSED, ALL_SIDES); } } else if (methodName == "buttonReleased") { list paramList = parseStringKeepNulls(parameters); // Method signature: // buttonReleased(string buttonName, list detectedData) // Triggered when a registered button is released. string buttonName = llList2String(paramList, 0); list detectedData = parseStringKeepNulls(llList2String(paramList, 1)); if (buttonName == LOGOUT_BUTTON_NAME) { integer buttonLinkNum = (integer) ((string) getDetectedValue(detectedData, DETECTED_LINK_NUMBER)); llSetLinkColor(buttonLinkNum, COLOR_RELEASED, ALL_SIDES); } } else if (methodName == "reregisterButtons") { // Method signature: // reregisterButtons() buttonInit(); } else if (methodName == "ping") { list paramList = parseStringKeepNulls(parameters); // Method signature: // ping(string moduleName) string moduleName = llList2String(paramList, 0); if (moduleName == this) trigger_pong(this); } } }