Update lua versions
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / webig.lua
blobd34fb372e929657a246e7d6838ef0cba87ab7f8c
2 -- create the webig namespace without reseting if already created in an other file.
3 if (webig==nil) then
4 webig= {}
5 end
7 if (webig.sheetLists==nil) then
8 webig.sheetLists = {}
9 end
11 if (webig.urls==nil) then
12 webig.urls = {}
13 end
15 function getUCtf8(text)
16 local uctext = ucstring()
17 if type(text) == "string" then
18 uctext:fromUtf8(text)
19 return uctext
20 end
21 return text
22 end
24 function game:openUrlOnWebig(url, noblink, close_if_open)
25 local winframe = getUI("ui:interface:open_url_window")
26 if close_if_open and winframe ~= nil and winframe.active == true then
27 winframe.active = false
28 else
29 WebBrowser:openWindow("open_url_window", url)
30 winframe = getUI("ui:interface:open_url_window")
31 winframe.opened=true
32 winframe.active=true
33 winframe.w = 830
34 winframe.h = 600
35 setTopWindow(winframe)
36 if noblink == nil then
37 winframe:blink(2)
38 end
39 end
40 end
43 function webig:addSheet(dst, sheet, quality, quantity, worned, user_color, rm_class_type, rm_faber_stat_type)
44 if quality == nil then quality=0 end
45 if quantity == nil then quantity=0 end
46 if worned == nil then worned=0 end
47 if user_color == nil then user_color=0 end
48 if rm_class_type == nil then rm_class_type=0 end
49 if rm_faber_stat_type == nil then rm_faber_stat_type=0 end
50 addDbProp(dst..":SHEET", sheet)
51 addDbProp(dst..":WORNED", worned)
52 addDbProp(dst..":QUALITY", quality)
53 addDbProp(dst..":QUANTITY", quantity)
54 addDbProp(dst..":USER_COLOR", user_color)
55 addDbProp(dst..":RM_CLASS_TYPE", rm_class_type)
56 addDbProp(dst..":RM_FABER_STAT_TYPE", rm_faber_stat_type)
57 addDbProp(dst..":CREATE_TIME", 0)
58 addDbProp(dst..":SERIAL", 0)
59 end
61 function webig:cleanSheets(db)
62 delDbProp(db)
63 end
65 function webig:addSheetList(name, ctrl, db, size)
66 webig.sheetLists[name] = {}
67 webig.sheetLists[name].ctrl = ctrl
68 webig.sheetLists[name].db = db
69 webig.sheetLists[name].selection = ""
70 webig.sheetLists[name].size = size
71 end
73 function webig:copyItems(src, dst)
74 addDbProp(dst..":SHEET", getDbProp(src..":SHEET"))
75 addDbProp(dst..":WORNED", getDbProp(src..":WORNED"))
76 addDbProp(dst..":QUALITY", getDbProp(src..":QUALITY"))
77 addDbProp(dst..":QUANTITY", getDbProp(src..":QUANTITY"))
78 addDbProp(dst..":USER_COLOR", getDbProp(src..":USER_COLOR"))
79 addDbProp(dst..":RM_CLASS_TYPE", getDbProp(src..":RM_CLASS_TYPE"))
80 addDbProp(dst..":RM_FABER_STAT_TYPE", getDbProp(src..":RM_FABER_STAT_TYPE"))
81 addDbProp(dst..":CREATE_TIME", 0)
82 addDbProp(dst..":SERIAL", 0)
83 end
85 function webig:swapItems(src, dst)
86 local sheet = getDbProp(dst..":SHEET")
87 local worned = getDbProp(dst..":WORNED")
88 local quality = getDbProp(dst..":QUALITY")
89 local quantity = getDbProp(dst..":QUANTITY")
90 local user_color = getDbProp(dst..":USER_COLOR")
91 local rm_class_type = getDbProp(dst..":RM_CLASS_TYPE")
92 local rm_faber_stat_type = getDbProp(dst..":RM_FABER_STAT_TYPE")
94 addDbProp(dst..":SHEET", getDbProp(src..":SHEET"))
95 addDbProp(dst..":WORNED", getDbProp(src..":WORNED"))
96 addDbProp(dst..":QUALITY", getDbProp(src..":QUALITY"))
97 addDbProp(dst..":QUANTITY", getDbProp(src..":QUANTITY"))
98 addDbProp(dst..":USER_COLOR", getDbProp(src..":USER_COLOR"))
99 addDbProp(dst..":RM_CLASS_TYPE", getDbProp(src..":RM_CLASS_TYPE"))
100 addDbProp(dst..":RM_FABER_STAT_TYPE", getDbProp(src..":RM_FABER_STAT_TYPE"))
101 addDbProp(dst..":CREATE_TIME", 0)
102 addDbProp(dst..":SERIAL", 0)
104 addDbProp(src..":SHEET", sheet)
105 addDbProp(src..":WORNED", worned)
106 addDbProp(src..":QUALITY", quality)
107 addDbProp(src..":QUANTITY", quantity)
108 addDbProp(src..":USER_COLOR", user_color)
109 addDbProp(src..":RM_CLASS_TYPE", rm_class_type)
110 addDbProp(src..":RM_FABER_STAT_TYPE", rm_faber_stat_type)
111 addDbProp(src..":CREATE_TIME", 0)
112 addDbProp(src..":SERIAL", 0)
115 function webig:deleteItem(src)
116 addDbProp(src..":SHEET", 0)
117 addDbProp(src..":WORNED", 0)
118 addDbProp(src..":QUALITY", 0)
119 addDbProp(src..":QUANTITY", 0)
120 addDbProp(src..":USER_COLOR", 0)
121 addDbProp(src..":RM_CLASS_TYPE", 0)
122 addDbProp(src..":RM_FABER_STAT_TYPE", 0)
123 addDbProp(src..":CREATE_TIME", 0)
124 addDbProp(src..":SERIAL", 0)
127 function webig:paramDbSheetSlot(sheet_list, ctrl)
128 local ctrlSheet = webig.sheetLists[sheet_list].ctrl:find("list:"..ctrl)
129 if ctrlSheet ~= nil then
130 ctrlSheet.left_click="lua"
131 ctrlSheet.left_click_params="webig:addOrRemoveDbSheet(\'"..sheet_list.."\', \'"..ctrl.."\')"
132 ctrlSheet.dragable=true
133 ctrlSheet.can_drop=true
134 ctrlSheet.on_drop="lua"
135 ctrlSheet.on_drop_params="webig:dropDbSheet(\'"..sheet_list.."\', \'"..ctrl.."\', \'%src\')"
136 ctrlSheet.on_can_drop="lua"
137 ctrlSheet.on_can_drop_params="webig:canDropDbSheet(\'"..sheet_list.."\', \'"..ctrl.."\', \'%src\')"
141 function webig:paramDbSheetSelect(sheet_list, ctrl, lua_function)
142 local ctrlSheet = webig.sheetLists[sheet_list].ctrl:find("list:"..ctrl)
143 if ctrlSheet ~= nil then
144 ctrlSheet.left_click="lua"
145 ctrlSheet.left_click_params=lua_function.."(\'"..sheet_list.."\', \'"..ctrl.."\')"
146 ctrlSheet.dragable=false
147 ctrlSheet.can_drop=false
151 function webig:canDropDbSheet(sheet_list, ctrl, src)
152 webig.sheetLists[sheet_list].ctrl:find("list:"..ctrl).can_drop=true
155 function webig:dropDbSheet(sheet_list, ctrl, src)
156 local db = webig.sheetLists[sheet_list].db
157 local sl_id = webig.sheetLists[sheet_list].ctrl.id
158 if (string.sub(src, 1, string.len(sl_id)) == sl_id) then -- copy from same list sheet
159 local pos=nil
160 for i=1, string.len(src) do
161 if string.sub(src, i, i) == ":" then
162 pos = i+1
165 id = string.sub(src, pos, string.len(src))
166 webig:swapItems(db..":"..id, db..":"..ctrl)
167 else
168 slot = getUI(src)
169 if slot ~= nil then
170 id = findReplaceAll(src, slot.parent.id..":", "")
171 webig:copyItems("LOCAL:INVENTORY:BAG:"..id, db..":"..ctrl)
177 function webig:addOrRemoveDbSheet(sheet_list, ctrl)
178 local db = webig.sheetLists[sheet_list].db
179 if getDbProp(db..":"..ctrl..":SHEET") == 0 then -- Add item
180 webig:AddDbSheet(sheet_list, ctrl)
181 else
182 webig:removeDbSheetQuantity(sheet_list, ctrl)
186 function webig:AddDbSheet(sheet_list, ctrl)
187 runAH(nil, "enter_modal", "group=ui:interface:webig_html_modal")
188 local whm = getUI("ui:interface:webig_html_modal")
189 whm.child_resize_h=false
190 whm.h = 44*webig.sheetLists[sheet_list].size
191 whm.w = 224
192 whm = getUI("ui:interface:webig_html_modal:html")
193 if whm ~= nil then
194 if string.sub(sheet_list, 1, 3) == "ark" then
195 whm:browse(webig.ark_modal_urls[sheet_list])
197 whm:refresh() -- url need be setted before
199 webig.sheetLists[sheet_list].selection = ctrl
202 function webig:removeDbSheetQuantity(sheet_list, ctrl)
203 local db = webig.sheetLists[sheet_list].db
204 webig:copyItems(db..":"..ctrl, "UI:DROP_DESTROY_ITEM:ITEM")
205 runAH(nil, "set_keyboard_focus", "select_all=true|target=ui:interface:webig_drop_destroy_item_quantity_modal:edit:eb")
206 getUI("ui:interface:webig_drop_destroy_item_quantity_modal:ok_cancel:ok").onclick_l="lua"
207 getUI("ui:interface:webig_drop_destroy_item_quantity_modal:ok_cancel:ok").params_l="webig:doRemoveDbSheetQuantity(\'"..sheet_list.."\', \'"..ctrl.."\')"
208 getUI("ui:interface:webig_drop_destroy_item_quantity_modal:edit:eb").on_enter="lua"
209 getUI("ui:interface:webig_drop_destroy_item_quantity_modal:edit:eb").on_enter_params="webig:doRemoveDbSheetQuantity(\'"..sheet_list.."\', \'"..ctrl.."\')"
210 runAH(nil, "enter_modal", "group=ui:interface:webig_drop_destroy_item_quantity_modal")
211 setDbProp("UI:DROP_DESTROY_ITEM:ITEM:QUANTITY", getDbProp(db..":"..ctrl..":QUANTITY"))
212 getUI("ui:interface:webig_drop_destroy_item_quantity_modal:edit:eb").input_string=tostring(getDbProp(db..":"..ctrl..":QUANTITY"))
215 function webig:doRemoveDbSheetQuantity(sheet_list, ctrl)
216 local db = webig.sheetLists[sheet_list].db
217 runAH(nil, "leave_modal", "group=ui:interface:webig_drop_destroy_item_quantity_modal")
218 local new_quantity = tonumber(getUI("ui:interface:webig_drop_destroy_item_quantity_modal:edit:eb").input_string)
219 local current_quantity = getDbProp(db..":"..ctrl..":QUANTITY")
220 if new_quantity >= current_quantity then
221 webig:deleteItem(db..":"..ctrl)
222 else
223 addDbProp(db..":"..ctrl..":QUANTITY", new_quantity)
227 function getUICallerRoot()
228 return getUI(getUICaller().id:match("(ui:interface:[^:]*):?"))
231 function webig:openUrl(url, ui)
232 if ui == nil then
233 getUI("ui:interface:web_transactions"):find("html"):browse(url)
234 else
235 getUI("ui:interface:"..ui):find("html"):browse(url)
239 function webig:openUrlInBg(url)
240 if webig.urls[url] ~= nil then
241 WebQueue:push(webig.urls[url])
242 else
243 WebQueue:push(url)
252 -- VERSION --
253 RYZOM_WEBIG_VERSION = 10469