-- Action file
-- Creator : Lud2k.
-- Date : 19/04/2008
-- Permet d'accéder à l'objet associé à l'action
this = This()
-- Ecriture dans les logs (log.txt)
logs = Log()
-- Gestion des flux http (ne peut gérer qu'une requête a la fois -- une thread par requête)
http = Http()
-- Gestion des utilisateurs
user = User()
-- Popup affiché lorsque l'on clique sur l'objet
popup = Popup();
-- les informations sur l'image a afficher sur l'objet
small_img = ""
big_img = ""
adding = false
-- Fenêtre de visionnage de l'image
window_voir = Window([[
<?xml version="1.0" encoding="ISO-8859-1"?>
<fenetre x="50" y="50" w="590" h="430" align="center" atached="center" border="0" titre="Nouvelle Photo !">
<image x="0" y="18" w="590" h="430" trans="0.900000" border="1" abs="0" id="2" src="MAP/new_texture.bmp"/>
<bouton x="470" y="410" w="590" h="430" trans="0.500000" id="1" border="1">Fermer !</bouton>
</fenetre>
]])
-- Fenêtre de configuration du service
window_conf = Window([[
<?xml version="1.0" encoding="ISO-8859-1"?>
<fenetre popup="true" x="100" y="100" w="450" h="135" align="center" atached="center" border="0" titre="Configuration Photo">
<text x="12" y="35" w="0" h="0" trans="0.900000" id="0">Photo à utiliser (mini):</text>
<editbox x="12" y="45" w="400" h="60" trans="0.100000" id="1" passwd="0" max="100"></editbox>
<text x="12" y="75" w="0" h="0" trans="0.900000" id="0">Photo à utiliser (grande):</text>
<editbox x="12" y="85" w="400" h="100" trans="0.100000" id="2" passwd="0" max="100"></editbox>
<bouton x="390" y="115" w="450" h="135" trans="0.500000" id="3" border="1">Sauver</bouton>
<bouton x="330" y="115" w="390" h="135" trans="0.500000" id="4" border="1">Annuler</bouton>
</fenetre>
]])
-- Fonction appelé automatiquement par Alliun lors de l'ajout d'un service
function onAdd()
-- Lancement de la requête HTTP
url = "http://www.chat-3d.net/Service_Photo/add/"..user:getId().."/"..user:getPassKey()
http:call(url,"onAddFinish",true)
logs:add(url)
end
-- Fonction callback pour l'appel http asynchrone dans la fonction onAdd()
function onAddFinish(data)
xml = Xml()
xml:parse(data,"service")
etat = xml:getChildNodeByName("etat"):getValue()
if etat == "success" then
id = xml:getChildNodeByName("id"):getValue()
this:setId(id)
this:save()
else
this:delete()
end
end
-- Fonction appelé automatiquement par Alliun lors de la suppression d'un service
function onDelete()
-- Lancement de la requête HTTP
url = "http://www.chat-3d.net/Service_Photo/delete/"..this:getId().."/"..user:getId().."/"..user:getPassKey()
http:call(url,"onDeleteFinish",true)
logs:add(url)
end
-- Fonction callback pour l'appel http asynchrone dans la fonction onDelete()
function onDeleteFinish()
-- rien a faire, l'action est supprimé a la fin de la fonction
end
-- Fonction appelé automatiquement par Alliun lors du lancement du service
function onInit()
if this:getId() then
url = "http://www.chat-3d.net/Service_Photo/get/"..this:getId()
http:call(url,"onDonwloadFinish")
logs:add(url)
end
end
-- Fonction callback qui gère les données reçus.
function onDonwloadFinish(data)
-- Création d'un nouvelle objet XML et parsing des données reçus.
xml = Xml()
xml:parse(data,"service")
-- Vérification de l'état
etat = xml:getChildNodeByName("etat"):getValue()
if etat == "success" then
-- Récupération des informations
small_img = xml:getChildNodeByName("small"):getValue()
big_img = xml:getChildNodeByName("big"):getValue()
-- Modification de l'objet
objet = this:getObject()
if objet:nbPolygones() > 0 then
polygone = objet:getPolygone(0)
polygone:setImage(small_img)
polygone:setDefMapY()
end
else
small_img = ""
big_img = ""
end
-- Ecriture dans les logs
logs:add(small_img);
logs:add(big_img);
end
-- Fonction appelé automatiquement par Alliun lors de la réception d'un signal
function onSignal()
onInit()
end
-- Fonction appelé automatiquement par Alliun lorsque l'utilisateur fait un click droit
function onRightClick()
if popup:isEmpty() then
-- En fonction de l'utilisateur / depends on the user status
if user:isAdmin() then
popup:add("Configurer","onClickConfigurer");
end
popup:add("Voir l'image","onClickVoir");
end
popup:create();
end
-- Fonction callback appelé si l'utilisateur a cliqué sur "Configurer" dans la popup
function onClickConfigurer()
window_conf:create()
if small_img then window_conf:getItem(1):setText(small_img) end
if big_img then window_conf:getItem(2):setText(big_img) end
window_conf:getItem(3):setCallback("onClickSauve")
window_conf:getItem(4):setCallback("onClickAnnuler")
end
-- Fonction permettant d'encoder une chaine de caratère pour être transmise par HTTP GET
function url_encode(str)
if str then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
str = string.gsub (str, "%%2F", "|")
end
return str
end
-- Fonction callback appelé si l'utilisateur a cliqué sur "Sauver" dans la fenêtre de configuration
function onClickSauve()
-- Récupérer les données de la fenêtre
small_img = window_conf:getItem(1):getText()
big_img = window_conf:getItem(2):getText()
-- Encoder pour l'envoi
encoded_small = url_encode(small_img)
encoded_big = url_encode(big_img)
-- Appeler le service
url = "http://www.chat-3d.net/Service_Photo/update/"..this:getId().."/"..user:getId().."/"..user:getPassKey().."/"..encoded_small.."/"..encoded_big.."/"
http:call(url,"onSauveFinish",true)
logs:add(url)
-- Envoyer un signal au serveur Alliun pour indiquer que l'objet a été modifié
this:signal()
-- Détruire la fenêtre
window_conf:destroy();
end
-- Fonction callback appelé à la fin de la requête HTTP GET de sauvegarde
function onSauveFinish()
-- rien a faire..
end
-- Fonction callback appelé si l'utilisateur a cliqué sur "Annuler" dans la fenêtre de configuration
function onClickAnnuler()
-- Détruire la fenêtre
window_conf:destroy()
end
-- Fonction callback appelé si l'utilisateur a cliqué sur "Voir" dans le popup
function onClickVoir()
window_voir:create()
window_voir:getItem(1):setCallback("onClickClose")
window_voir:getItem(2):setImage(big_img)
end
-- Fonction callback appelé si l'utilisateur a cliqué sur "Fermer" dans la fenêtre de visionnage de la photo
function onClickClose()
window_voir:destroy()
end
-- Fonction appelé automatiquement par Alliun lorsque l'utilisateur fait un click gauche
function onLeftClick()
-- rien a faire
end
-- Fonction appelé automatiquement par Alliun lors de la destruction de l'objet
function onDeinit()
-- rien a faire
end
Web3D-fr
Groupe Facebook
- - - - - - - - - - -
Chat 3d
Monde virtuel
- - - - - - - - - - -
Votre site ici