/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com
Copyright (c) 2012 I-maginer
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
-----------------------------------------------------------------------------
*/
var iWidgetZIndex = 0;;
struct PlugChat = [
CHAT_instance : PInstance,
CHAT_netcomm : NetComm,
CHAT_bOnMaterial : I,
CHAT_Object : SO3_OBJECT,
CHAT_Material : SO3_MATERIAL,
CHAT_iTechnique : I,
CHAT_iPass : I,
CHAT_iTexture : I,
CHAT_win : SO3_WIDGET,
CHAT_iScaleMode : I,
CHAT_iPosX : I,
CHAT_iPosY : I,
CHAT_iWidth : I,
CHAT_iHeight : I,
CHAT_tPercent : [I I I I I I I I],
CHAT_tAlign : [I I],
CHAT_sPath : S,
CHAT_iZorder : I,
CHAT_bTransparency : I,
CHAT_iOpacity : I,
CHAT_bDraggable : I,
CHAT_bFocusOnInit : I,
CHAT_bTopOnFocus : I,
CHAT_bAllwaysOnTop : I,
CHAT_bState : I
]mkPlugChat;;
fun cbDestroy(inst, from, action, param, reply, constr)=
setPluginInstanceCbResizeView inst nil;
setPluginInstanceCbNetUserChangeLogin inst nil;
setPluginInstanceCbNetRoomChanged inst nil;
setPluginInstanceCbNetSConnected inst nil;
setPluginInstanceCbNetClosed inst nil;
setPluginInstanceCbNetNewUser inst nil;
setPluginInstanceCbNetDelUser inst nil;
V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) constr.CHAT_win;
SO3WidgetDestroy constr.CHAT_win;
set constr.CHAT_win = nil;
0;;
fun addChatText(constr, text)=
let strcatn "'"::(strreplace text "\n" "
")::"'"::nil -> text in
SO3WidgetCallFunction constr.CHAT_win "addMessage" (strtoutf8 text)::nil;
0;;
fun addChatPrivateText(constr, uid, text)=
let strcatn "'"::(strreplace text "\n" "
")::"'"::nil -> text in
SO3WidgetCallFunction constr.CHAT_win "addPrivateMessage" (itoa uid)::(strtoutf8 text)::nil;
0;;
fun cbLoginChanged(inst, netstr, userstr, newlogin, constr)=
let netUserGetLogin userstr -> login in
if (!strcmp login newlogin) then nil else
(
addChatText constr strcatn login::" >> "::newlogin::nil;
let strcatn "'"::(strreplace addSlashes newlogin "\n" "
")::"'"::nil -> newlogin in
SO3WidgetCallFunction constr.CHAT_win "changeLogin" (itoa netUserGetId userstr)::(strtoutf8 newlogin)::nil;
);
0;;
fun cbAddUser(inst, netstr, userstr, constr)=
if userstr == (netThisUser netstr) then nil else
let netUserGetLogin userstr -> login in
(
addChatText constr strcatn ">> "::login::" "::(loc "OS3DCHAT_0003")::nil;
let strcatn "'"::(strreplace addSlashes login "\n" "
")::"'"::nil -> login in
SO3WidgetCallFunction constr.CHAT_win "addUser" (itoa netUserGetId userstr)::(strtoutf8 login)::nil;
);
0;;
fun cbDelUser(inst, netstr, userstr, constr)=
let netUserGetLogin userstr -> login in
(
addChatText constr strcatn ">> "::login::" "::(loc "OS3DCHAT_0004")::nil;
SO3WidgetCallFunction constr.CHAT_win "delUser" (itoa netUserGetId userstr)::nil;
);
0;;
fun cbRoomChanged(inst, netstr, room, constr)=
addChatText constr strcatn ""::(loc "OS3DCHAT_0043")::" "::(netThisLogin netstr)::" "::(strcat (loc "OS3DCHAT_0005") " ")::room::"."::nil;
0;;
fun cbDisconnected(inst, netstr, constr)=
if(!constr.CHAT_bState) then nil else
addChatText constr strcatn "<<< "::(loc "OS3DCHAT_0007")::""::nil;
set constr.CHAT_bState = 0;
0;;
fun cbSConnected(inst, netstr, constr)=
set constr.CHAT_bState = 1;
addChatText constr strcatn "<<< "::(loc "OS3DCHAT_0008")::""::nil;
0;;
fun cbGetMessage(inst, from, action, param, reply, constr)=
if (param == nil) || (!strcmp (strtrim param) "") then nil else
addChatText constr param;
0;;
fun cbGetPrivateMessage(inst, from, action, param, reply, constr)=
let strfind " " param 0 -> pos in
let atoi substr param 0 pos -> uid in
let substr param pos + 1 ((strlen param) - pos) -> message in
(
addChatPrivateText constr uid message;
);
0;;
fun cbDisplayMessage(inst, from, action, param, reply, constr)=
addChatText constr strcatn ""::param::"
"::nil;
0;;
fun cbSendActionMessage(inst, from, action, param, reply, constr)=
let substr action ((strlen (getPluginInstanceName inst)) + 1) (strlen action) -> action in
let listQuote (strToList param) "'" -> paraml in
(
SO3WidgetCallFunction constr.CHAT_win action paraml;
);
0;;
fun cbSendMessage(widget, constr, message, args)=
set message = utf8tostr message;
if (!strcmp message "message") && (strcmp (hd args) "") && (args != nil) then
(
let utf8tostr (hd args) -> val in
if (!strcmp "/" (substr val 0 1)) then
(
SendPluginEvent constr.CHAT_instance "Command" (substr val 1 ((strlen val) - 1)) nil;
SendPluginEvent constr.CHAT_instance "Message" strcat "%login% << " (substr val 1 ((strlen val) - 1)) nil;
)
else
(
SendPluginEvent constr.CHAT_instance "Message" strcat "%login% > " val nil;
);
)
else if (!strcmp message "privateMessage") && (strcmp (hd tl args) "") && (args != nil) then
(
let hd args -> uid in
let utf8tostr (hd tl args) -> val in
let netGetUserById constr.CHAT_netcomm (atoi uid) -> duser in
if (!strcmp "/" (substr val 0 1)) then
(
SendPluginEvent constr.CHAT_instance "Command" (substr val 1 ((strlen val) - 1)) nil;
if (duser == nil) then nil else
(
addChatPrivateText constr (atoi uid) strcatn ""::(netThisLogin constr.CHAT_netcomm)::" << "::(substr val 1 ((strlen val) - 1))::nil;
SendPluginEvent constr.CHAT_instance "PrivateMessage" strcatn uid::" %login% << "::(substr val 1 ((strlen val) - 1))::nil nil;
0;
);
)
else
(
if (duser != nil) then
(
addChatPrivateText constr (atoi uid) strcatn ""::(netThisLogin constr.CHAT_netcomm)::" > "::val::nil;
SendPluginEvent constr.CHAT_instance "PrivateMessage" strcatn uid::" %login% > "::val::nil nil;
0;
)
else
(
addChatPrivateText constr (atoi uid) strcatn "<<< "::(loc "OS3DCHAT_0006")::""::nil;
0;
);
);
)
else nil;
SendPluginEvent constr.CHAT_instance message utf8tostr (listToString args) nil;
0;;
fun cbSendMessageStr(navigator, constr, message, args)=
"";;
fun cbPageLoaded(navigator, constr/*, fname, status*/)=
SendPluginEvent constr.CHAT_instance "Loaded" nil nil;
0;;
fun cbShow(inst, from, action, param, reply, constr)=
SO3WidgetSetVisibility constr.CHAT_win 1;
0;;
fun cbHide(inst, from, action, param, reply, constr)=
SO3WidgetSetVisibility constr.CHAT_win 0;
0;;
fun cbSetOpacity(inst, from, action, param, reply, constr)=
if param == nil then nil else
(
SO3WidgetSetOpacity constr.CHAT_win (atof param) *. 0.01;
set constr.CHAT_iOpacity = atoi param;
);
0;;
fun computePosSize(constr, vw, vh)=
let constr.CHAT_tPercent -> [px py pw ph xo yo wo ho] in
let constr.CHAT_tAlign -> [ax ay] in
let if pw then (ftoi (((itof constr.CHAT_iWidth) /. 100.0) *. (itof vw))) + wo else constr.CHAT_iWidth -> pw in
let if ph then (ftoi (((itof constr.CHAT_iHeight) /. 100.0) *. (itof vh))) + ho else constr.CHAT_iHeight -> ph in
let if px then (ftoi (((itof constr.CHAT_iPosX) /. 100.0) *. (itof vw))) + xo else constr.CHAT_iPosX -> px in
let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in
let if py then (ftoi (((itof constr.CHAT_iPosY) /. 100.0) *. (itof vh))) + yo else constr.CHAT_iPosY -> py in
let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in
[px py pw ph];;
fun cbSetPosition(inst, from, action, param, reply, constr)=
if constr.CHAT_bOnMaterial then nil else
if param == nil then nil else
let strextr param -> lp in
let (nth_list (hd lp) 0) -> p1 in
let (nth_list (hd lp) 1) -> p2 in
let if (!strcmp (substr p1 ((strlen p1) - 1) 1) "%") then 1 else 0 -> xpercent in
let if (!strcmp (substr p2 ((strlen p2) - 1) 1) "%") then 1 else 0 -> ypercent in
let if xpercent then substr p1 0 ((strlen p1) - 1) else p1 -> p1 in
let if ypercent then substr p2 0 ((strlen p2) - 1) else p2 -> p2 in
let if (atoi p1) == nil || (!strcmp p1 "_") then constr.CHAT_iPosX else (atoi p1) -> npx in
let if (atoi p2) == nil || (!strcmp p2 "_") then constr.CHAT_iPosY else (atoi p2) -> npy in
let constr.CHAT_tPercent -> [px py pw ph xo yo wo ho] in
(
mutate constr.CHAT_tPercent <- [(if (atoi p1) == nil || (!strcmp p1 "_") then px else xpercent) (if (atoi p2) == nil || (!strcmp p2 "_") then py else ypercent) _ _ _ _ _ _];
set constr.CHAT_iPosX = npx;
set constr.CHAT_iPosY = npy;
let V3DgetSessionView c3dXsession -> viewstr in
let (V3DgetDefaultViewport viewstr) -> viewportstr in
let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in
let computePosSize constr vw vh -> [px py pw ph] in
(
SO3WidgetSetPosition constr.CHAT_win px py;
SO3WidgetSetSize constr.CHAT_win pw ph;
);
);
0;;
fun cbSetSize(inst, from, action, param, reply, constr)=
if constr.CHAT_bOnMaterial then nil else
if param == nil then nil else
let strextr param -> lp in
let (nth_list (hd lp) 0) -> p1 in
let (nth_list (hd lp) 1) -> p2 in
let if (!strcmp (substr p1 ((strlen p1) - 1) 1) "%") then 1 else 0 -> xpercent in
let if (!strcmp (substr p2 ((strlen p2) - 1) 1) "%") then 1 else 0 -> ypercent in
let if xpercent then substr p1 0 ((strlen p1) - 1) else p1 -> p1 in
let if ypercent then substr p2 0 ((strlen p2) - 1) else p2 -> p2 in
let if (atoi p1) == nil || (!strcmp p1 "_") then constr.CHAT_iWidth else (atoi p1) -> npw in
let if (atoi p2) == nil || (!strcmp p2 "_") then constr.CHAT_iHeight else (atoi p2) -> nph in
let constr.CHAT_tPercent -> [px py pw ph xo yo wo ho] in
(
//addLogMessage itoa ypercent;
mutate constr.CHAT_tPercent <- [_ _ (if (atoi p1) == nil || (!strcmp p1 "_") then pw else xpercent) (if (atoi p2) == nil || (!strcmp p2 "_") then ph else ypercent) _ _ _ _];
set constr.CHAT_iWidth = npw;
set constr.CHAT_iHeight = nph;
let V3DgetSessionView c3dXsession -> viewstr in
let (V3DgetDefaultViewport viewstr) -> viewportstr in
let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in
let computePosSize constr vw vh -> [px py pw ph] in
(
SO3WidgetSetPosition constr.CHAT_win px py;
SO3WidgetSetSize constr.CHAT_win pw ph;
);
);
0;;
fun cbResizeCtrl(inst, viewstr, vw, vh, constr)=
if constr.CHAT_win == nil || constr.CHAT_bOnMaterial then nil else
let computePosSize constr vw vh -> [px py pw ph] in
(
SO3WidgetSetPosition constr.CHAT_win px py;
SO3WidgetSetSize constr.CHAT_win pw ph;
);
0;;
fun cbCreate(inst, from, action, param, reply, constr)=
let V3DgetSessionView c3dXsession -> viewstr in
let (V3DgetDefaultViewport viewstr) -> viewportstr in
if constr.CHAT_win != nil then nil else
(
V3DremoveWidgetControl viewportstr constr.CHAT_win;
SO3WidgetDestroy constr.CHAT_win;
if constr.CHAT_bOnMaterial then
(
set constr.CHAT_win = SO3WebNavigatorWidgetCreateOnMaterial (V3DgetSession c3dXsession) constr.CHAT_Material strcat (getPluginInstanceName inst) "_webNavigatorWidget" constr.CHAT_iWidth constr.CHAT_iHeight constr.CHAT_iTechnique constr.CHAT_iPass constr.CHAT_iTexture;
0;
)
else
(
let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in
let computePosSize constr vw vh -> [px py pw ph] in
(
set constr.CHAT_win = SO3WebNavigatorWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport strcat (getPluginInstanceName inst) "_webNavigatorWidget" px py pw ph constr.CHAT_iZorder;
);
SO3WidgetSetTopOnFocus constr.CHAT_win constr.CHAT_bTopOnFocus;
SO3WidgetSetForeground constr.CHAT_win constr.CHAT_bAllwaysOnTop;
//SO3WidgetSetDraggable constr.CHAT_win constr.CHAT_bDraggable;
);
V3DaddWidgetControl viewportstr constr.CHAT_win;
SO3WidgetSetTransparency constr.CHAT_win constr.CHAT_bTransparency;
SO3WidgetSetKeyboardEnable constr.CHAT_win 1;
SO3WidgetSetMouseEnable constr.CHAT_win 1;
if !constr.CHAT_bFocusOnInit then nil else
SO3WidgetSetFocus constr.CHAT_win;
SO3WidgetSetOpacity constr.CHAT_win (itof constr.CHAT_iOpacity) *. 0.01;
SO3WidgetOnScriptEventCb constr.CHAT_win @cbSendMessage constr;
//SO3WidgetOnScriptEventCb constr.CHAT_win @cbSendMessageStr constr;
SO3WidgetOnLoadEndEventCb constr.CHAT_win @cbPageLoaded constr;
SO3WidgetLoadFile constr.CHAT_win (_checkpack constr.CHAT_sPath);
setPluginInstanceCbNetUserChangeLogin inst mkfun5 @cbLoginChanged constr;
setPluginInstanceCbNetRoomChanged inst mkfun4 @cbRoomChanged constr;
setPluginInstanceCbNetSConnected inst mkfun3 @cbSConnected constr;
setPluginInstanceCbNetClosed inst mkfun3 @cbDisconnected constr;
setPluginInstanceCbNetNewUser inst mkfun4 @cbAddUser constr;
setPluginInstanceCbNetDelUser inst mkfun4 @cbDelUser constr;
if constr.CHAT_bOnMaterial then nil else
setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl constr;
);
0;;
fun deleteOb(inst, constr)=
cbDestroy inst nil nil nil nil constr;
0;;
fun newOb(inst)=
let atoi (getPluginInstanceParam inst "istexture") -> istexture in
let if istexture == nil then 0 else istexture -> istexture in
let (getPluginInstanceParam inst "object") -> objname in
let (getPluginInstanceParam inst "material") -> matname in
let atoi (getPluginInstanceParam inst "technique") -> technique in
let if technique == nil then 0 else technique -> technique in
let atoi (getPluginInstanceParam inst "pass") -> pass in
let if pass == nil then 0 else pass -> pass in
let atoi (getPluginInstanceParam inst "texture") -> texture in
let if texture == nil then 0 else texture -> texture in
let (getPluginInstanceParam inst "path") -> path in
let atoi (getPluginInstanceParam inst "scalemode") -> scalemode in
let if scalemode == nil then 0 else scalemode -> scalemode in
let atoi (getPluginInstanceParam inst "posx") -> posx in
let atoi (getPluginInstanceParam inst "posy") -> posy in
let atoi (getPluginInstanceParam inst "width") -> width in
let atoi (getPluginInstanceParam inst "height") -> height in
let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in
let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in
let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in
let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in
let atoi (getPluginInstanceParam inst "xoffset") -> xoffset in
let if xoffset == nil then 0 else xoffset -> xoffset in
let atoi (getPluginInstanceParam inst "yoffset") -> yoffset in
let if yoffset == nil then 0 else yoffset -> yoffset in
let atoi (getPluginInstanceParam inst "woffset") -> woffset in
let if woffset == nil then 0 else woffset -> woffset in
let atoi (getPluginInstanceParam inst "hoffset") -> hoffset in
let if hoffset == nil then 0 else hoffset -> hoffset in
let atoi (getPluginInstanceParam inst "xalign") -> xalign in
let atoi (getPluginInstanceParam inst "yalign") -> yalign in
let atoi (getPluginInstanceParam inst "transparency") -> transparency in
let atoi (getPluginInstanceParam inst "draggable") -> draggable in
let atoi (getPluginInstanceParam inst "focus") -> focus in
let atoi (getPluginInstanceParam inst "toponfocus") -> toponfocus in
let if toponfocus == nil then 1 else toponfocus -> toponfocus in
let atoi (getPluginInstanceParam inst "allwaysontop") -> allwaysontop in
let if allwaysontop == nil then 0 else allwaysontop -> allwaysontop in
let atoi (getPluginInstanceParam inst "opacity") -> opacity in
let atoi (getPluginInstanceParam inst "zorder") -> zorder in
let if ((zorder == nil) || (zorder == 0)) then set iWidgetZIndex = iWidgetZIndex + 1 else (if zorder > iWidgetZIndex then set iWidgetZIndex = zorder else zorder) -> zorder in
let atoi (getPluginInstanceParam inst "init") -> oninit in
let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in
let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in
let mkPlugChat [inst netcomOS3D istexture obj mat technique pass texture nil scalemode posx posy width height [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] path zorder transparency opacity draggable focus toponfocus allwaysontop 0] -> constr in
(
let getPluginInstanceUserActions inst -> laction in
let sizelist laction -> size in
let 0 -> i in
while i < size do
(
let nth_list laction i -> act in
PluginRegisterAction inst act mkfun6 @cbSendActionMessage constr;
set i = i + 1;
);
if !oninit then nil else
cbCreate inst nil nil nil nil constr;
PluginRegisterAction inst "Get message" mkfun6 @cbGetMessage constr;
PluginRegisterAction inst "Get private message" mkfun6 @cbGetPrivateMessage constr;
PluginRegisterAction inst "Display message" mkfun6 @cbDisplayMessage constr;
PluginRegisterAction inst "Show" mkfun6 @cbShow constr;
PluginRegisterAction inst "Hide" mkfun6 @cbHide constr;
PluginRegisterAction inst "Create" mkfun6 @cbCreate constr;
PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr;
PluginRegisterAction inst "Set opacity" mkfun6 @cbSetOpacity constr;
PluginRegisterAction inst "Set position" mkfun6 @cbSetPosition constr;
PluginRegisterAction inst "Set size" mkfun6 @cbSetSize constr;
setPluginInstanceCbDel inst mkfun2 @deleteOb constr;
);
0;;
fun IniPlug(file)=
PlugRegister @newOb nil;
setPluginEditor @dynamicedit;
0;;