Don't click here unless you want to be banned.

LSL Wiki : LibraryCBNotecardDisplayer

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
// Displays a notecard's contents onscreen.

// 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

vector LINE_COLOR = <0,1,0>; // Green


integer strStartsWith(string str, string prefix) {
    return llSubStringIndex(str, prefix) == 0;
}

string removePrefixFrom(string str, string prefix) {
    if (!strStartsWith(str, prefix)) return str;
    
    integer prefixLen = llStringLength(prefix);
    return llDeleteSubString(str, 0, prefixLen - 1);
}



string notecardName = "";
integer curLine = 0;
key curReq = NULL_KEY;

// It doesnt really matter what these values are.
// Just as long as they're not = to any formatting values.
//string FORMAT_COLOR             = "color";
//string FORMAT_PREFIX            = "pre";
//string FORMAT_SUFFIX            = "suf";
//string FORMAT_PARSE_LIST_INDEX  = "indx";

//list LINE_FORMATTING = [
//    FORMAT_COLOR, <0, 1, 0>
//];

// ========== 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_displayStatusMessage(string message) {
    callMethod(0, "displayStatusMessage", [message]);
}

//trigger_formatAndDisplay(integer line, string text, list formatting) {
//    callMethod("formatAndDisplay", [line, text, encodeList(formatting)]);
//}
trigger_setScreenWriter(string moduleName) {
    callMethod(0, "setScreenWriter", [moduleName]);
}
trigger_setMenuLineText(string moduleName, integer line, string text) {
    callMethod(0, "setMenuLineText", [moduleName, line, text]);
}

trigger_setMenuLineColor(string moduleName, integer line, vector color) {
    callMethod(0, "setMenuLineColor", [moduleName, line, color]);
}

trigger_cls(string moduleName) {
    callMethod(0, "cls", [moduleName]);
}

trigger_enableMenuLineButton(string moduleName, integer lineNumber) {
    callMethod(0, "enableMenuLineButton", [moduleName, lineNumber]);
}

trigger_disableMenuLineButton(string moduleName, integer lineNumber) {
    callMethod(0, "disableMenuLineButton", [moduleName, lineNumber]);
}

trigger_disableAllMenuLineButtons(string moduleName) {
    callMethod(0, "disableAllMenuLineButtons", [moduleName]);
}

trigger_pong(string moduleName) {
    callMethod(0, "pong", [moduleName]);
}

string this;
default {
    state_entry() {
        this = llGetScriptName();
        state main;
    }
}
state main {
    link_message(integer sender, integer num, string parameters, key methodName) {
        if (methodName == "displayNotecard") {
            list paramList = parseStringKeepNulls(parameters);
            // Method signature:
            // displayNotecard(string notecardName)
            notecardName = llList2String(paramList, 0);
            state readingNotecard;
        } else if (methodName == "ping") {
            list paramList = parseStringKeepNulls(parameters);
            // Method signature:
            // ping(string moduleName)
            string moduleName = llList2String(paramList, 0);
            if (moduleName == this)
                trigger_pong(this);
        }
    }
}

state readingNotecard {
    state_entry() {
        trigger_setScreenWriter(this);
        trigger_displayStatusMessage("Reading notecard...");
        trigger_disableAllMenuLineButtons(this);
        trigger_cls(this);
        curLine = 0;
        curReq = llGetNotecardLine(notecardName, curLine);
    }
    
    dataserver(key req, string data) {
        if (req == curReq) {
            curReq = NULL_KEY;
            if (data != EOF) {
                if (strStartsWith(data, "#")) {
                    data = removePrefixFrom(data, "#");
                    trigger_enableMenuLineButton(this, curLine);
                }
                
                trigger_setMenuLineText(this, curLine, data);
                trigger_setMenuLineColor(this, curLine, LINE_COLOR);
                curReq = llGetNotecardLine(notecardName, ++curLine);
            } else {
                trigger_displayStatusMessage("Reading notecard...Done.");
                state default;
            }
        }
    }
}


LibraryContentBrowser
There is no comment on this page. [Display comments/form]