// Maintains a virtual "window" onscreen that menu content is writeen to. // Most of its functionality has been deligated out to MenuColorScrolling, // MenuTextScrolling and MenuLineButtonScrolling for memory-related reasons. // 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 // ========== 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_setDisplayLineText(integer line, string text) { callMethod(0, "setDisplayLineText", [line, text]); } trigger_setDisplayLineColor(integer line, vector color) { callMethod(0, "setDisplayLineColor", [line, color]); } integer getScreenSizeRetVal; trigger_getScreenSize() { getScreenSizeRetVal = (integer) llFrand(172421); callMethod(getScreenSizeRetVal, "getScreenSize", []); } trigger_pong(string moduleName) { callMethod(0, "pong", [moduleName]); } integer END_LINE = 11; integer START_LINE = 0; integer menuWidth; string screenWriter; string this; default { state_entry() { this = llGetScriptName(); trigger_getScreenSize(); } link_message(integer sender, integer callId, string parameters, key methodName) { if (methodName == "getScreenSize_ret" && callId == getScreenSizeRetVal) { list paramList = parseStringKeepNulls(parameters); // Method signature: // getScreenSize_ret(integer width, integer height) integer width = (integer) llList2String(paramList, 0); integer height = (integer) llList2String(paramList, 1); menuWidth = width; state main; } } } state main { link_message(integer sender, integer callId, string parameters, key methodName) { //list paramList = parseStringKeepNulls(parameters); if (methodName == "cls") { list paramList = parseStringKeepNulls(parameters); // Method signature : // cls() string moduleName = llList2String(paramList, 0); if (moduleName != screenWriter) return; integer line; for (line = START_LINE; line <= END_LINE; line++) { trigger_setDisplayLineText(line, ""); } } else if (methodName == "getMenuTextAreaSize") { // Method signature: // <int, int> getSize() returnValue(methodName, callId, [menuWidth, END_LINE - START_LINE + 1]); } else if (methodName == "getMenuTextAreaPosition") { // Method signature: // <int, int> getMenuTextAreaPosition returnValue(methodName, callId, [START_LINE, END_LINE]); } else if (methodName == "setScreenWriter") { list paramList = parseStringKeepNulls(parameters); // Method signature: // setScreenWriter(string moduleName) string moduleName = llList2String(paramList, 0); screenWriter = moduleName; } else if (methodName == "ping") { list paramList = parseStringKeepNulls(parameters); // Method signature: // ping(string moduleName) string moduleName = llList2String(paramList, 0); if (moduleName == this) trigger_pong(this); } } }