Update lua versions
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / appzone.lua
blob878ea0a7b3da1f67a2a7c68d157b47c4ff03f227
2 -- global
3 AppZone = {
4 id = "ui:interface:appzone",
5 homeuri = "?action=appzone_toolbar",
6 launchuri = "?action=launch_app",
7 addappuri = "?action=list_user_apps",
8 mode = "h_bar",
9 imagesize = 26
12 -- use client.cfg value when available
13 local uri = getClientCfg("AppZoneUrl")
14 if uri == nil or uri == '' then
15 uri = 'http://app.ryzom.com/'
16 end
18 AppZone.homeuri = uri .. AppZone.homeuri
19 AppZone.launchuri = uri .. AppZone.launchuri
20 AppZone.addappuri = uri .. AppZone.addappuri
22 function AppZone:getRoot()
23 return getUI(self.id)
24 end
26 function AppZone:onButtonHome()
27 local webig = getUI("ui:interface:webig")
28 webig:find("html").url = self.addappuri
29 webig.active = true
30 end
32 function AppZone:calculateSize(count, spacer, mode)
33 local w, h
34 if mode == "h_bar" then
35 -- icon=32, space=2+2
36 w = count * self.imagesize + spacer * 15
37 w = w + 55 + 10 + 20
38 h = self.imagesize + 2
39 elseif mode == "h_box" then
40 w = count * self.imagesize
41 w = w + 20
42 h = self.imagesize + 2
43 h = h * spacer
44 h = h + 15
45 elseif mode == "v_bar" then
46 -- icon=32, space=2+2
47 h = count * self.imagesize + spacer * 15
48 h = h + 20 + 20 + 12
49 w = self.imagesize + 2 + 18
50 else
51 h = count * self.imagesize
52 h = h + 20 + 25
53 w = self.imagesize + 2
54 w = w * spacer
55 w = w + 16
56 end
58 local ui = getUI("ui:interface")
59 if w > ui.w then
60 w = ui.w
61 end
62 if h > ui.h then
63 h = ui.h
64 end
66 return w, h
67 end
69 function AppZone:setElementCount(count,spacer,m)
70 self.mode = m
72 local root = self:getRoot()
73 local content = root:find("content")
74 local html = root:find("html")
76 local button_toggle = root:find("toggle_mode")
77 local button_reload = root:find("browse_reload")
78 local button_home = root:find("browse_home")
80 local w, h = self:calculateSize(count, spacer, self.mode)
81 root.h = h
82 root.w = w
83 content.w = w
84 content.h = h
86 -- set position of buttons
87 if self.mode == "h_bar" then
88 -- button_toggle.posref = "BL BL"
89 button_toggle.x = 2
90 button_toggle.y = 0
91 -- button_reload.posref = "TL BL"
92 html.x = 15
93 html.y = 0
94 button_reload.x = -25
95 button_reload.y = -25
96 -- button_home.posref = "BR BR"
97 button_home.x = 0
98 button_home.y = -3 + 5
99 elseif self.mode == "h_box" then
100 -- button_toggle.posref = "TL TL"
101 button_toggle.x = 2
102 button_toggle.y = h - 15
103 -- button_reload.posref = "TL BL"
104 html.x = 0
105 html.y = -20
106 button_reload.x = -25
107 button_reload.y = -4 - 20
108 -- button_home.posref = "BR BR"
109 button_home.x = 0
110 button_home.y = -3 + h - 18
111 elseif self.mode == "v_bar" then
112 -- button_toggle.posref = "TL TL"
113 button_toggle.x = 2
114 button_toggle.y = h - 15
115 -- button_reload.posref = "TL BL"
116 html.x = 0
117 html.y = -20
118 button_reload.x = 0
119 button_reload.y = -4
120 -- button_home.posref = "BR BR"
121 button_home.x = 4 - 7
122 button_home.y = -3
123 else
124 -- button_toggle.posref = "TL TL"
125 button_toggle.x = 2
126 button_toggle.y = h - 15
127 -- button_reload.posref = "TL BL"
128 html.x = 0
129 html.y = -20
130 button_reload.x = -25
131 button_reload.y = -4 - 20
132 -- button_home.posref = "BR BR"
133 button_home.x = 0 - w + 54 + 12
134 button_home.y = -3
138 function AppZone:setMode(m)
139 self.mode = m
141 self:reload()
144 function AppZone:setActive(s)
145 self:getRoot().active = s
148 function AppZone:launchApp(appid, appwin, appurl)
149 if not appwin then
150 if string.match(appid, "^[0-9]+$") then
151 appwin = "app" .. tostring(appid)
152 else
153 appwin = "webig"
157 if not appurl then
158 appurl = self.launchuri .. "&appid=" .. tostring(appid)
161 if WebBrowser then
162 WebBrowser:openWindow(appwin, appurl)
163 else
164 -- fallback if WebBrowser not present
165 local webig = getUI("ui:interface:webig")
166 webig:find("html").url = appurl;
167 webig.active = true
171 function AppZone:reload()
172 local url = self.homeuri
173 url = url .. "&mode=" .. tostring(self.mode)
175 local html = self:getRoot():find("html")
176 html.url = url
179 -- slash command: /appzone <cmd>
180 function AppZone:handle(cmd)
181 if cmd == 'show' then
182 self:setActive(true)
183 elseif cmd == 'hide' then
184 self:setActive(false)
185 elseif cmd == 'reload' then
186 self:reload()
187 elseif cmd == 'list' then
188 self:onButtonHome()
189 else
190 self:launchApp(cmd)
194 -- VERSION --
195 RYZOM_APPZONE_VERSION = 10469