| @@ -0,0 +1,9 @@ | |||
| 1 | + | Module | |
| 2 | + | name: game_shaders | |
| 3 | + | description: Load shaders | |
| 4 | + | author: otclientv8 | |
| 5 | + | website: http://otclient.ovh | |
| 6 | + | scripts: [ shaders ] | |
| 7 | + | sandboxed: true | |
| 8 | + | @onLoad: init() | |
| 9 | + | @onUnload: terminate() |
| @@ -0,0 +1,562 @@ | |||
| 1 | + | -- private variables | |
| 2 | + | local SHOP_EXTENTED_OPCODE = 201 | |
| 3 | + | ||
| 4 | + | shop = nil | |
| 5 | + | local otcv8shop = false | |
| 6 | + | local shopButton = nil | |
| 7 | + | local msgWindow = nil | |
| 8 | + | local browsingHistory = false | |
| 9 | + | ||
| 10 | + | -- for classic store | |
| 11 | + | local storeUrl = "" | |
| 12 | + | local coinsPacketSize = 0 | |
| 13 | + | ||
| 14 | + | local CATEGORIES = {} | |
| 15 | + | local HISTORY = {} | |
| 16 | + | local STATUS = {} | |
| 17 | + | local AD = {} | |
| 18 | + | ||
| 19 | + | local selectedOffer = {} | |
| 20 | + | ||
| 21 | + | local function sendAction(action, data) | |
| 22 | + | if not g_game.getFeature(GameExtendedOpcode) then | |
| 23 | + | return | |
| 24 | + | end | |
| 25 | + | ||
| 26 | + | local protocolGame = g_game.getProtocolGame() | |
| 27 | + | if data == nil then | |
| 28 | + | data = {} | |
| 29 | + | end | |
| 30 | + | if protocolGame then | |
| 31 | + | protocolGame:sendExtendedJSONOpcode(SHOP_EXTENTED_OPCODE, {action = action, data = data}) | |
| 32 | + | end | |
| 33 | + | end | |
| 34 | + | ||
| 35 | + | -- public functions | |
| 36 | + | function init() | |
| 37 | + | connect(g_game, { | |
| 38 | + | onGameStart = check, | |
| 39 | + | onGameEnd = hide, | |
| 40 | + | onStoreInit = onStoreInit, | |
| 41 | + | onStoreCategories = onStoreCategories, | |
| 42 | + | onStoreOffers = onStoreOffers, | |
| 43 | + | onStoreTransactionHistory = onStoreTransactionHistory, | |
| 44 | + | onStorePurchase = onStorePurchase, | |
| 45 | + | onStoreError = onStoreError, | |
| 46 | + | onCoinBalance = onCoinBalance | |
| 47 | + | }) | |
| 48 | + | ||
| 49 | + | ProtocolGame.registerExtendedJSONOpcode(SHOP_EXTENTED_OPCODE, onExtendedJSONOpcode) | |
| 50 | + | ||
| 51 | + | if g_game.isOnline() then | |
| 52 | + | check() | |
| 53 | + | end | |
| 54 | + | end | |
| 55 | + | ||
| 56 | + | function terminate() | |
| 57 | + | disconnect(g_game, { | |
| 58 | + | onGameStart = check, | |
| 59 | + | onGameEnd = hide, | |
| 60 | + | onStoreInit = onStoreInit, | |
| 61 | + | onStoreCategories = onStoreCategories, | |
| 62 | + | onStoreOffers = onStoreOffers, | |
| 63 | + | onStoreTransactionHistory = onStoreTransactionHistory, | |
| 64 | + | onStorePurchase = onStorePurchase, | |
| 65 | + | onStoreError = onStoreError, | |
| 66 | + | onCoinBalance = onCoinBalance | |
| 67 | + | }) | |
| 68 | + | ||
| 69 | + | ProtocolGame.unregisterExtendedJSONOpcode(SHOP_EXTENTED_OPCODE, onExtendedJSONOpcode) | |
| 70 | + | ||
| 71 | + | --if shopButton then | |
| 72 | + | -- shopButton:destroy() | |
| 73 | + | -- shopButton = nil | |
| 74 | + | --end | |
| 75 | + | if shop then | |
| 76 | + | disconnect(shop.categories, { onChildFocusChange = changeCategory }) | |
| 77 | + | shop:destroy() | |
| 78 | + | shop = nil | |
| 79 | + | end | |
| 80 | + | if msgWindow then | |
| 81 | + | msgWindow:destroy() | |
| 82 | + | end | |
| 83 | + | end | |
| 84 | + | ||
| 85 | + | function check() | |
| 86 | + | otcv8shop = false | |
| 87 | + | sendAction("init") | |
| 88 | + | end | |
| 89 | + | ||
| 90 | + | function hide() | |
| 91 | + | if not shop then | |
| 92 | + | return | |
| 93 | + | end | |
| 94 | + | shop:hide() | |
| 95 | + | end | |
| 96 | + | ||
| 97 | + | function show() | |
| 98 | + | if not shop then | |
| 99 | + | return | |
| 100 | + | end | |
| 101 | + | if g_game.getFeature(GameIngameStore) then | |
| 102 | + | g_game.openStore(0) | |
| 103 | + | end | |
| 104 | + | ||
| 105 | + | shop:show() | |
| 106 | + | shop:raise() | |
| 107 | + | shop:focus() | |
| 108 | + | end | |
| 109 | + | ||
| 110 | + | function toggle() | |
| 111 | + | if not shop then | |
| 112 | + | return | |
| 113 | + | end | |
| 114 | + | if shop:isVisible() then | |
| 115 | + | return hide() | |
| 116 | + | end | |
| 117 | + | show() | |
| 118 | + | check() | |
| 119 | + | end | |
| 120 | + | ||
| 121 | + | function createShop() | |
| 122 | + | if shop then return end | |
| 123 | + | shop = g_ui.displayUI('shop') | |
| 124 | + | shop:hide() | |
| 125 | + | --shopButton = modules.client_topmenu.addRightGameToggleButton('shopButton', tr('Shop'), '/images/topbuttons/shop', toggle, false, 8) | |
| 126 | + | connect(shop.categories, { onChildFocusChange = changeCategory }) | |
| 127 | + | end | |
| 128 | + | ||
| 129 | + | ||
| 130 | + | function onStoreInit(url, coins) | |
| 131 | + | if otcv8shop then return end | |
| 132 | + | storeUrl = url | |
| 133 | + | if storeUrl:len() > 0 then | |
| 134 | + | if storeUrl:sub(storeUrl:len(), storeUrl:len()) ~= "/" then | |
| 135 | + | storeUrl = storeUrl .. "/" | |
| 136 | + | end | |
| 137 | + | storeUrl = storeUrl .. "64/" | |
| 138 | + | if storeUrl:sub(1, 4):lower() ~= "http" then | |
| 139 | + | storeUrl = "http://" .. storeUrl | |
| 140 | + | end | |
| 141 | + | end | |
| 142 | + | coinsPacketSize = coins | |
| 143 | + | createShop() | |
| 144 | + | end | |
| 145 | + | ||
| 146 | + | function onStoreCategories(categories) | |
| 147 | + | if not shop or otcv8shop then return end | |
| 148 | + | local correctCategories = {} | |
| 149 | + | for i, category in ipairs(categories) do | |
| 150 | + | local image = "" | |
| 151 | + | if category.icon:len() > 0 then | |
| 152 | + | image = storeUrl .. category.icon | |
| 153 | + | end | |
| 154 | + | table.insert(correctCategories, { | |
| 155 | + | type = "image", | |
| 156 | + | image = image, | |
| 157 | + | name = category.name, | |
| 158 | + | offers = {} | |
| 159 | + | }) | |
| 160 | + | end | |
| 161 | + | processCategories(correctCategories) | |
| 162 | + | end | |
| 163 | + | ||
| 164 | + | function onStoreOffers(categoryName, offers) | |
| 165 | + | if not shop or otcv8shop then return end | |
| 166 | + | local updated = false | |
| 167 | + | ||
| 168 | + | for i, category in ipairs(CATEGORIES) do | |
| 169 | + | if category.name == categoryName then | |
| 170 | + | if #category.offers ~= #offers then | |
| 171 | + | updated = true | |
| 172 | + | end | |
| 173 | + | for i=1,#category.offers do | |
| 174 | + | if category.offers[i].title ~= offers[i].name or category.offers[i].id ~= offers[i].id or category.offers[i].cost ~= offers[i].price then | |
| 175 | + | updated = true | |
| 176 | + | end | |
| 177 | + | end | |
| 178 | + | if updated then | |
| 179 | + | for offer in pairs(category.offers) do | |
| 180 | + | category.offers[offer] = nil | |
| 181 | + | end | |
| 182 | + | for i, offer in ipairs(offers) do | |
| 183 | + | local image = "" | |
| 184 | + | if offer.icon:len() > 0 then | |
| 185 | + | image = storeUrl .. offer.icon | |
| 186 | + | end | |
| 187 | + | table.insert(category.offers, { | |
| 188 | + | id=offer.id, | |
| 189 | + | type="image", | |
| 190 | + | image=image, | |
| 191 | + | cost=offer.price, | |
| 192 | + | title=offer.name, | |
| 193 | + | description=offer.description | |
| 194 | + | }) | |
| 195 | + | end | |
| 196 | + | end | |
| 197 | + | end | |
| 198 | + | end | |
| 199 | + | if not updated then | |
| 200 | + | return | |
| 201 | + | end | |
| 202 | + | ||
| 203 | + | local activeCategory = shop.categories:getFocusedChild() | |
| 204 | + | changeCategory(activeCategory, activeCategory) | |
| 205 | + | end | |
| 206 | + | ||
| 207 | + | function onStoreTransactionHistory(currentPage, hasNextPage, offers) | |
| 208 | + | if not shop or otcv8shop then return end | |
| 209 | + | HISTORY = {} | |
| 210 | + | for i, offer in ipairs(offers) do | |
| 211 | + | table.insert(HISTORY, { | |
| 212 | + | id=offer.id, | |
| 213 | + | type="image", | |
| 214 | + | image=storeUrl .. offer.icon, | |
| 215 | + | cost=offer.price, | |
| 216 | + | title=offer.name, | |
| 217 | + | description=offer.description | |
| 218 | + | }) | |
| 219 | + | end | |
| 220 | + | ||
| 221 | + | if not browsingHistory then return end | |
| 222 | + | clearOffers() | |
| 223 | + | shop.categories:focusChild(nil) | |
| 224 | + | for i, transaction in ipairs(HISTORY) do | |
| 225 | + | addOffer(0, transaction) | |
| 226 | + | end | |
| 227 | + | end | |
| 228 | + | ||
| 229 | + | function onStorePurchase(message) | |
| 230 | + | if not shop or otcv8shop then return end | |
| 231 | + | processMessage({title="Successful shop purchase", msg=message}) | |
| 232 | + | end | |
| 233 | + | ||
| 234 | + | function onStoreError(errorType, message) | |
| 235 | + | if not shop or otcv8shop then return end | |
| 236 | + | processMessage({title="Shop error", msg=message}) | |
| 237 | + | end | |
| 238 | + | ||
| 239 | + | function onCoinBalance(coins, transferableCoins) | |
| 240 | + | if not shop or otcv8shop then return end | |
| 241 | + | shop.infoPanel.points:setText(tr("Points:") .. " " .. coins) | |
| 242 | + | shop.infoPanel.buy:hide() | |
| 243 | + | shop.infoPanel:setHeight(20) | |
| 244 | + | end | |
| 245 | + | ||
| 246 | + | function onExtendedJSONOpcode(protocol, code, json_data) | |
| 247 | + | createShop() | |
| 248 | + | ||
| 249 | + | local action = json_data['action'] | |
| 250 | + | local data = json_data['data'] | |
| 251 | + | local status = json_data['status'] | |
| 252 | + | if not action or not data then | |
| 253 | + | return false | |
| 254 | + | end | |
| 255 | + | ||
| 256 | + | otcv8shop = true | |
| 257 | + | if action == 'categories' then | |
| 258 | + | processCategories(data) | |
| 259 | + | elseif action == 'history' then | |
| 260 | + | processHistory(data) | |
| 261 | + | elseif action == 'message' then | |
| 262 | + | processMessage(data) | |
| 263 | + | end | |
| 264 | + | ||
| 265 | + | if status then | |
| 266 | + | processStatus(status) | |
| 267 | + | end | |
| 268 | + | end | |
| 269 | + | ||
| 270 | + | function clearOffers() | |
| 271 | + | while shop.offers:getChildCount() > 0 do | |
| 272 | + | local child = shop.offers:getLastChild() | |
| 273 | + | shop.offers:destroyChildren(child) | |
| 274 | + | end | |
| 275 | + | end | |
| 276 | + | ||
| 277 | + | function clearCategories() | |
| 278 | + | CATEGORIES = {} | |
| 279 | + | clearOffers() | |
| 280 | + | while shop.categories:getChildCount() > 0 do | |
| 281 | + | local child = shop.categories:getLastChild() | |
| 282 | + | shop.categories:destroyChildren(child) | |
| 283 | + | end | |
| 284 | + | end | |
| 285 | + | ||
| 286 | + | function clearHistory() | |
| 287 | + | HISTORY = {} | |
| 288 | + | if browsingHistory then | |
| 289 | + | clearOffers() | |
| 290 | + | end | |
| 291 | + | end | |
| 292 | + | ||
| 293 | + | function processCategories(data) | |
| 294 | + | if table.equal(CATEGORIES,data) then | |
| 295 | + | return | |
| 296 | + | end | |
| 297 | + | clearCategories() | |
| 298 | + | CATEGORIES = data | |
| 299 | + | for i, category in ipairs(data) do | |
| 300 | + | addCategory(category) | |
| 301 | + | end | |
| 302 | + | if not browsingHistory then | |
| 303 | + | local firstCategory = shop.categories:getChildByIndex(1) | |
| 304 | + | if firstCategory then | |
| 305 | + | firstCategory:focus() | |
| 306 | + | end | |
| 307 | + | end | |
| 308 | + | end | |
| 309 | + | ||
| 310 | + | function processHistory(data) | |
| 311 | + | if table.equal(HISTORY,data) then | |
| 312 | + | return | |
| 313 | + | end | |
| 314 | + | HISTORY = data | |
| 315 | + | if browsingHistory then | |
| 316 | + | showHistory(true) | |
| 317 | + | end | |
| 318 | + | end | |
| 319 | + | ||
| 320 | + | function processMessage(data) | |
| 321 | + | if msgWindow then | |
| 322 | + | msgWindow:destroy() | |
| 323 | + | end | |
| 324 | + | ||
| 325 | + | local title = tr(data["title"]) | |
| 326 | + | local msg = data["msg"] | |
| 327 | + | msgWindow = displayInfoBox(title, msg) | |
| 328 | + | msgWindow.onDestroy = function(widget) | |
| 329 | + | if widget == msgWindow then | |
| 330 | + | msgWindow = nil | |
| 331 | + | end | |
| 332 | + | end | |
| 333 | + | msgWindow:show() | |
| 334 | + | msgWindow:raise() | |
| 335 | + | msgWindow:focus() | |
| 336 | + | end | |
| 337 | + | ||
| 338 | + | function processStatus(data) | |
| 339 | + | if table.equal(STATUS,data) then | |
| 340 | + | return | |
| 341 | + | end | |
| 342 | + | STATUS = data | |
| 343 | + | ||
| 344 | + | if data['ad'] then | |
| 345 | + | processAd(data['ad']) | |
| 346 | + | end | |
| 347 | + | if data['points'] then | |
| 348 | + | shop.infoPanel.points:setText(tr("Points:") .. " " .. data['points']) | |
| 349 | + | end | |
| 350 | + | if data['buyUrl'] and data['buyUrl']:sub(1, 4):lower() == "http" then | |
| 351 | + | shop.infoPanel.buy:show() | |
| 352 | + | shop.infoPanel.buy.onMouseRelease = function() | |
| 353 | + | scheduleEvent(function() g_platform.openUrl(data['buyUrl']) end, 50) | |
| 354 | + | end | |
| 355 | + | else | |
| 356 | + | shop.infoPanel.buy:hide() | |
| 357 | + | shop.infoPanel:setHeight(20) | |
| 358 | + | end | |
| 359 | + | end | |
| 360 | + | ||
| 361 | + | function processAd(data) | |
| 362 | + | if table.equal(AD,data) then | |
| 363 | + | return | |
| 364 | + | end | |
| 365 | + | AD = data | |
| 366 | + | ||
| 367 | + | if data['image'] and data['image']:sub(1, 4):lower() == "http" then | |
| 368 | + | HTTP.downloadImage(data['image'], function(path, err) | |
| 369 | + | if err then g_logger.warning("HTTP error: " .. err .. " - " .. data['image']) return end | |
| 370 | + | shop.adPanel:setHeight(shop.infoPanel:getHeight()) | |
| 371 | + | shop.adPanel.ad:setText("") | |
| 372 | + | shop.adPanel.ad:setImageSource(path) | |
| 373 | + | shop.adPanel.ad:setImageFixedRatio(true) | |
| 374 | + | shop.adPanel.ad:setImageAutoResize(true) | |
| 375 | + | shop.adPanel.ad:setHeight(shop.infoPanel:getHeight()) | |
| 376 | + | end) | |
| 377 | + | elseif data['text'] and data['text']:len() > 0 then | |
| 378 | + | shop.adPanel:setHeight(shop.infoPanel:getHeight()) | |
| 379 | + | shop.adPanel.ad:setText(data['text']) | |
| 380 | + | shop.adPanel.ad:setHeight(shop.infoPanel:getHeight()) | |
| 381 | + | else | |
| 382 | + | shop.adPanel:setHeight(0) | |
| 383 | + | end | |
| 384 | + | if data['url'] and data['url']:sub(1, 4):lower() == "http" then | |
| 385 | + | shop.adPanel.ad.onMouseRelease = function() | |
| 386 | + | scheduleEvent(function() g_platform.openUrl(data['url']) end, 50) | |
| 387 | + | end | |
| 388 | + | else | |
| 389 | + | shop.adPanel.ad.onMouseRelease = nil | |
| 390 | + | end | |
| 391 | + | end | |
| 392 | + | ||
| 393 | + | function addCategory(data) | |
| 394 | + | local category | |
| 395 | + | if data["type"] == "item" then | |
| 396 | + | category = g_ui.createWidget('ShopCategoryItem', shop.categories) | |
| 397 | + | category.item:setItemId(data["item"]) | |
| 398 | + | category.item:setItemCount(data["count"]) | |
| 399 | + | category.item:setShowCount(false) | |
| 400 | + | elseif data["type"] == "outfit" then | |
| 401 | + | category = g_ui.createWidget('ShopCategoryCreature', shop.categories) | |
| 402 | + | category.creature:setOutfit(data["outfit"]) | |
| 403 | + | if data["outfit"]["rotating"] then | |
| 404 | + | category.creature:setAutoRotating(true) | |
| 405 | + | end | |
| 406 | + | elseif data["type"] == "image" then | |
| 407 | + | category = g_ui.createWidget('ShopCategoryImage', shop.categories) | |
| 408 | + | if data["image"] and data["image"]:sub(1, 4):lower() == "http" then | |
| 409 | + | HTTP.downloadImage(data['image'], function(path, err) | |
| 410 | + | if err then g_logger.warning("HTTP error: " .. err .. " - " .. data["image"]) return end | |
| 411 | + | category.image:setImageSource(path) | |
| 412 | + | end) | |
| 413 | + | else | |
| 414 | + | category.image:setImageSource(data["image"]) | |
| 415 | + | end | |
| 416 | + | else | |
| 417 | + | g_logger.error("Invalid shop category type: " .. tostring(data["type"])) | |
| 418 | + | return | |
| 419 | + | end | |
| 420 | + | category:setId("category_" .. shop.categories:getChildCount()) | |
| 421 | + | category.name:setText(data["name"]) | |
| 422 | + | end | |
| 423 | + | ||
| 424 | + | function showHistory(force) | |
| 425 | + | if browsingHistory and not force then | |
| 426 | + | return | |
| 427 | + | end | |
| 428 | + | ||
| 429 | + | if g_game.getFeature(GameIngameStore) and not otcv8shop then | |
| 430 | + | g_game.openTransactionHistory(100) | |
| 431 | + | end | |
| 432 | + | sendAction("history") | |
| 433 | + | ||
| 434 | + | browsingHistory = true | |
| 435 | + | clearOffers() | |
| 436 | + | shop.categories:focusChild(nil) | |
| 437 | + | for i, transaction in ipairs(HISTORY) do | |
| 438 | + | addOffer(0, transaction) | |
| 439 | + | end | |
| 440 | + | end | |
| 441 | + | ||
| 442 | + | function addOffer(category, data) | |
| 443 | + | local offer | |
| 444 | + | if data["type"] == "item" then | |
| 445 | + | offer = g_ui.createWidget('ShopOfferItem', shop.offers) | |
| 446 | + | offer.item:setItemId(data["item"]) | |
| 447 | + | offer.item:setItemCount(data["count"]) | |
| 448 | + | offer.item:setShowCount(false) | |
| 449 | + | elseif data["type"] == "outfit" then | |
| 450 | + | offer = g_ui.createWidget('ShopOfferCreature', shop.offers) | |
| 451 | + | offer.creature:setOutfit(data["outfit"]) | |
| 452 | + | if data["outfit"]["rotating"] then | |
| 453 | + | offer.creature:setAutoRotating(true) | |
| 454 | + | end | |
| 455 | + | elseif data["type"] == "image" then | |
| 456 | + | offer = g_ui.createWidget('ShopOfferImage', shop.offers) | |
| 457 | + | if data["image"] and data["image"]:sub(1, 4):lower() == "http" then | |
| 458 | + | HTTP.downloadImage(data['image'], function(path, err) | |
| 459 | + | if err then g_logger.warning("HTTP error: " .. err .. " - " .. data['image']) return end | |
| 460 | + | if not offer.image then return end | |
| 461 | + | offer.image:setImageSource(path) | |
| 462 | + | end) | |
| 463 | + | elseif data["image"] and data["image"]:len() > 1 then | |
| 464 | + | offer.image:setImageSource(data["image"]) | |
| 465 | + | end | |
| 466 | + | else | |
| 467 | + | g_logger.error("Invalid shop offer type: " .. tostring(data["type"])) | |
| 468 | + | return | |
| 469 | + | end | |
| 470 | + | offer:setId("offer_" .. category .. "_" .. shop.offers:getChildCount()) | |
| 471 | + | offer.title:setText(data["title"] .. " (" .. data["cost"] .. " points)") | |
| 472 | + | offer.description:setText(data["description"]) | |
| 473 | + | offer.offerId = data["id"] | |
| 474 | + | if category ~= 0 then | |
| 475 | + | offer.onDoubleClick = buyOffer | |
| 476 | + | offer.buyButton.onClick = function() buyOffer(offer) end | |
| 477 | + | else | |
| 478 | + | offer.buyButton:hide() | |
| 479 | + | end | |
| 480 | + | end | |
| 481 | + | ||
| 482 | + | ||
| 483 | + | function changeCategory(widget, newCategory) | |
| 484 | + | if not newCategory then | |
| 485 | + | return | |
| 486 | + | end | |
| 487 | + | ||
| 488 | + | if g_game.getFeature(GameIngameStore) and widget ~= newCategory and not otcv8shop then | |
| 489 | + | local serviceType = 0 | |
| 490 | + | if g_game.getFeature(GameTibia12Protocol) then | |
| 491 | + | serviceType = 2 | |
| 492 | + | end | |
| 493 | + | g_game.requestStoreOffers(newCategory.name:getText(), serviceType) | |
| 494 | + | end | |
| 495 | + | ||
| 496 | + | browsingHistory = false | |
| 497 | + | local id = tonumber(newCategory:getId():split("_")[2]) | |
| 498 | + | clearOffers() | |
| 499 | + | for i, offer in ipairs(CATEGORIES[id]["offers"]) do | |
| 500 | + | addOffer(id, offer) | |
| 501 | + | end | |
| 502 | + | end | |
| 503 | + | ||
| 504 | + | function buyOffer(widget) | |
| 505 | + | if not widget then | |
| 506 | + | return | |
| 507 | + | end | |
| 508 | + | local split = widget:getId():split("_") | |
| 509 | + | if #split ~= 3 then | |
| 510 | + | return | |
| 511 | + | end | |
| 512 | + | local category = tonumber(split[2]) | |
| 513 | + | local offer = tonumber(split[3]) | |
| 514 | + | local item = CATEGORIES[category]["offers"][offer] | |
| 515 | + | if not item then | |
| 516 | + | return | |
| 517 | + | end | |
| 518 | + | ||
| 519 | + | selectedOffer = {category=category, offer=offer, title=item.title, cost=item.cost, id=widget.offerId} | |
| 520 | + | ||
| 521 | + | scheduleEvent(function() | |
| 522 | + | if msgWindow then | |
| 523 | + | msgWindow:destroy() | |
| 524 | + | end | |
| 525 | + | ||
| 526 | + | local title = tr("Buying from shop") | |
| 527 | + | local msg = "Do you want to buy " .. item.title .. " for " .. item.cost .. " premium points?" | |
| 528 | + | msgWindow = displayGeneralBox(title, msg, { | |
| 529 | + | { text=tr('Yes'), callback=buyConfirmed }, | |
| 530 | + | { text=tr('No'), callback=buyCanceled }, | |
| 531 | + | anchor=AnchorHorizontalCenter}, buyConfirmed, buyCanceled) | |
| 532 | + | msgWindow:show() | |
| 533 | + | msgWindow:raise() | |
| 534 | + | msgWindow:focus() | |
| 535 | + | msgWindow:raise() | |
| 536 | + | end, 50) | |
| 537 | + | end | |
| 538 | + | ||
| 539 | + | function buyConfirmed() | |
| 540 | + | msgWindow:destroy() | |
| 541 | + | msgWindow = nil | |
| 542 | + | sendAction("buy", selectedOffer) | |
| 543 | + | if g_game.getFeature(GameIngameStore) and selectedOffer.id and not otcv8shop then | |
| 544 | + | local offerName = selectedOffer.title:lower() | |
| 545 | + | if string.find(offerName, "name") and string.find(offerName, "change") and modules.client_textedit then | |
| 546 | + | modules.client_textedit.singlelineEditor("", function(newName) | |
| 547 | + | if newName:len() == 0 then | |
| 548 | + | return | |
| 549 | + | end | |
| 550 | + | g_game.buyStoreOffer(selectedOffer.id, 1, newName) | |
| 551 | + | end) | |
| 552 | + | else | |
| 553 | + | g_game.buyStoreOffer(selectedOffer.id, 0, "") | |
| 554 | + | end | |
| 555 | + | end | |
| 556 | + | end | |
| 557 | + | ||
| 558 | + | function buyCanceled() | |
| 559 | + | msgWindow:destroy() | |
| 560 | + | msgWindow = nil | |
| 561 | + | selectedOffer = {} | |
| 562 | + | end |
| @@ -0,0 +1,10 @@ | |||
| 1 | + | Module | |
| 2 | + | name: game_shop | |
| 3 | + | description: Game shop | |
| 4 | + | author: otclient.ovh | |
| 5 | + | website: http://otclient.ovh | |
| 6 | + | sandboxed: true | |
| 7 | + | scripts: [ shop ] | |
| 8 | + | dependencies: [ client_topmenu ] | |
| 9 | + | @onLoad: init() | |
| 10 | + | @onUnload: terminate() |
| @@ -0,0 +1,236 @@ | |||
| 1 | + | ShopCategory < Panel | |
| 2 | + | height: 36 | |
| 3 | + | focusable: true | |
| 4 | + | background: alpha | |
| 5 | + | ||
| 6 | + | $focus: | |
| 7 | + | background: #99999999 | |
| 8 | + | ||
| 9 | + | Label | |
| 10 | + | id: name | |
| 11 | + | anchors.top: parent.top | |
| 12 | + | anchors.left: parent.left | |
| 13 | + | anchors.right: parent.right | |
| 14 | + | anchors.bottom: parent.bottom | |
| 15 | + | margin-left: 40 | |
| 16 | + | text-align: left | |
| 17 | + | color: white | |
| 18 | + | font: verdana-11px-rounded | |
| 19 | + | ||
| 20 | + | ShopCategoryItem < ShopCategory | |
| 21 | + | UIItem | |
| 22 | + | id: item | |
| 23 | + | anchors.top: parent.top | |
| 24 | + | anchors.left: parent.left | |
| 25 | + | anchors.bottom: parent.bottom | |
| 26 | + | margin-top: 2 | |
| 27 | + | margin-bottom: 2 | |
| 28 | + | margin-left: 2 | |
| 29 | + | virtual: true | |
| 30 | + | size: 32 32 | |
| 31 | + | ||
| 32 | + | ShopCategoryCreature < ShopCategory | |
| 33 | + | UICreature | |
| 34 | + | id: creature | |
| 35 | + | anchors.top: parent.top | |
| 36 | + | anchors.left: parent.left | |
| 37 | + | anchors.bottom: parent.bottom | |
| 38 | + | margin-top: 2 | |
| 39 | + | margin-bottom: 2 | |
| 40 | + | margin-left: 2 | |
| 41 | + | size: 32 32 | |
| 42 | + | ||
| 43 | + | ShopCategoryImage < ShopCategory | |
| 44 | + | Label | |
| 45 | + | id: image | |
| 46 | + | anchors.top: parent.top | |
| 47 | + | anchors.left: parent.left | |
| 48 | + | anchors.bottom: parent.bottom | |
| 49 | + | margin-top: 2 | |
| 50 | + | margin-bottom: 2 | |
| 51 | + | margin-left: 2 | |
| 52 | + | size: 32 32 | |
| 53 | + | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + | ShopOffer < Panel | |
| 57 | + | height: 56 | |
| 58 | + | background: alpha | |
| 59 | + | ||
| 60 | + | $focus: | |
| 61 | + | background: #99999999 | |
| 62 | + | ||
| 63 | + | Label | |
| 64 | + | id: title | |
| 65 | + | anchors.left: parent.left | |
| 66 | + | anchors.right: parent.right | |
| 67 | + | anchors.top: parent.top | |
| 68 | + | margin-top: 4 | |
| 69 | + | margin-left: 55 | |
| 70 | + | text-align: topleft | |
| 71 | + | color: white | |
| 72 | + | font: verdana-11px-rounded | |
| 73 | + | ||
| 74 | + | Label | |
| 75 | + | id: description | |
| 76 | + | anchors.top: prev.bottom | |
| 77 | + | anchors.left: parent.left | |
| 78 | + | anchors.right: parent.right | |
| 79 | + | anchors.bottom: parent.bottom | |
| 80 | + | margin-left: 55 | |
| 81 | + | margin-right: 55 | |
| 82 | + | text-align: topleft | |
| 83 | + | text-auto-resize: true | |
| 84 | + | text-wrap: true | |
| 85 | + | color: white | |
| 86 | + | font: verdana-11px-rounded | |
| 87 | + | ||
| 88 | + | Button | |
| 89 | + | id: buyButton | |
| 90 | + | text: BUY | |
| 91 | + | height: 25 | |
| 92 | + | anchors.verticalCenter: parent.verticalCenter | |
| 93 | + | anchors.left: prev.right | |
| 94 | + | anchors.right: parent.right | |
| 95 | + | margin-right: 15 | |
| 96 | + | text-align: center | |
| 97 | + | ||
| 98 | + | ShopOfferItem < ShopOffer | |
| 99 | + | UIItem | |
| 100 | + | id: item | |
| 101 | + | anchors.top: parent.top | |
| 102 | + | anchors.left: parent.left | |
| 103 | + | anchors.bottom: parent.bottom | |
| 104 | + | margin-top: 4 | |
| 105 | + | margin-bottom: 4 | |
| 106 | + | margin-left: 2 | |
| 107 | + | virtual: true | |
| 108 | + | size: 48 48 | |
| 109 | + | ||
| 110 | + | ShopOfferCreature < ShopOffer | |
| 111 | + | UICreature | |
| 112 | + | id: creature | |
| 113 | + | anchors.top: parent.top | |
| 114 | + | anchors.left: parent.left | |
| 115 | + | anchors.bottom: parent.bottom | |
| 116 | + | margin-top: 4 | |
| 117 | + | margin-bottom: 4 | |
| 118 | + | margin-left: 2 | |
| 119 | + | size: 48 48 | |
| 120 | + | ||
| 121 | + | ShopOfferImage < ShopOffer | |
| 122 | + | Label | |
| 123 | + | id: image | |
| 124 | + | anchors.top: parent.top | |
| 125 | + | anchors.left: parent.left | |
| 126 | + | anchors.bottom: parent.bottom | |
| 127 | + | margin-top: 4 | |
| 128 | + | margin-bottom: 4 | |
| 129 | + | margin-left: 2 | |
| 130 | + | size: 48 48 | |
| 131 | + | ||
| 132 | + | MainWindow | |
| 133 | + | id: shopWindow | |
| 134 | + | !text: tr('Shop') | |
| 135 | + | size: 750 500 | |
| 136 | + | @onEscape: modules.game_shop.hide() | |
| 137 | + | $mobile: | |
| 138 | + | size: 500 360 | |
| 139 | + | ||
| 140 | + | Panel | |
| 141 | + | id: infoPanel | |
| 142 | + | anchors.top: parent.top | |
| 143 | + | anchors.left: parent.left | |
| 144 | + | width: 230 | |
| 145 | + | height: 60 | |
| 146 | + | ||
| 147 | + | Label | |
| 148 | + | id: points | |
| 149 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 150 | + | anchors.top: parent.top | |
| 151 | + | margin-top: 10 | |
| 152 | + | text: - | |
| 153 | + | text-auto-resize: true | |
| 154 | + | ||
| 155 | + | Button | |
| 156 | + | id: buy | |
| 157 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 158 | + | width: 150 | |
| 159 | + | anchors.top: prev.bottom | |
| 160 | + | margin-top: 10 | |
| 161 | + | visible: false | |
| 162 | + | !text: tr("Buy points") | |
| 163 | + | ||
| 164 | + | Panel | |
| 165 | + | id: adPanel | |
| 166 | + | anchors.top: parent.top | |
| 167 | + | anchors.left: infoPanel.right | |
| 168 | + | anchors.right: parent.right | |
| 169 | + | margin-left: 10 | |
| 170 | + | height: 0 | |
| 171 | + | ||
| 172 | + | Label | |
| 173 | + | id: ad | |
| 174 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 175 | + | anchors.top: parent.top | |
| 176 | + | anchors.bottom: parent.bottom | |
| 177 | + | text-auto-resize: true | |
| 178 | + | text-wrap: true | |
| 179 | + | text-align: center | |
| 180 | + | font: sans-bold-16px | |
| 181 | + | ||
| 182 | + | TextList | |
| 183 | + | id: categories | |
| 184 | + | vertical-scrollbar: categoriesScrollBar | |
| 185 | + | anchors.top: infoPanel.bottom | |
| 186 | + | anchors.left: infoPanel.left | |
| 187 | + | anchors.right: infoPanel.right | |
| 188 | + | anchors.bottom: transactionHistory.top | |
| 189 | + | margin-top: 10 | |
| 190 | + | margin-bottom: 10 | |
| 191 | + | padding: 1 | |
| 192 | + | focusable: false | |
| 193 | + | ||
| 194 | + | VerticalScrollBar | |
| 195 | + | id: categoriesScrollBar | |
| 196 | + | anchors.top: categories.top | |
| 197 | + | anchors.bottom: categories.bottom | |
| 198 | + | anchors.right: categories.right | |
| 199 | + | step: 50 | |
| 200 | + | pixels-scroll: true | |
| 201 | + | ||
| 202 | + | TextList | |
| 203 | + | id: offers | |
| 204 | + | vertical-scrollbar: offersScrollBar | |
| 205 | + | anchors.top: adPanel.bottom | |
| 206 | + | anchors.left: adPanel.left | |
| 207 | + | anchors.right: adPanel.right | |
| 208 | + | anchors.bottom: transactionHistory.top | |
| 209 | + | margin-top: 10 | |
| 210 | + | margin-bottom: 10 | |
| 211 | + | padding: 1 | |
| 212 | + | focusable: false | |
| 213 | + | ||
| 214 | + | VerticalScrollBar | |
| 215 | + | id: offersScrollBar | |
| 216 | + | anchors.top: offers.top | |
| 217 | + | anchors.bottom: offers.bottom | |
| 218 | + | anchors.right: offers.right | |
| 219 | + | step: 50 | |
| 220 | + | pixels-scroll: true | |
| 221 | + | ||
| 222 | + | Button | |
| 223 | + | id: transactionHistory | |
| 224 | + | !text: tr('Transaction history') | |
| 225 | + | width: 128 | |
| 226 | + | anchors.left: parent.left | |
| 227 | + | anchors.bottom: parent.bottom | |
| 228 | + | @onClick: modules.game_shop.showHistory() | |
| 229 | + | ||
| 230 | + | Button | |
| 231 | + | id: buttonCancel | |
| 232 | + | !text: tr('Close') | |
| 233 | + | width: 64 | |
| 234 | + | anchors.right: parent.right | |
| 235 | + | anchors.bottom: parent.bottom | |
| 236 | + | @onClick: modules.game_shop.hide() |
| @@ -0,0 +1,442 @@ | |||
| 1 | + | skillsWindow = nil | |
| 2 | + | skillsButton = nil | |
| 3 | + | ||
| 4 | + | function init() | |
| 5 | + | connect(LocalPlayer, { | |
| 6 | + | onExperienceChange = onExperienceChange, | |
| 7 | + | onLevelChange = onLevelChange, | |
| 8 | + | onHealthChange = onHealthChange, | |
| 9 | + | onManaChange = onManaChange, | |
| 10 | + | onSoulChange = onSoulChange, | |
| 11 | + | onFreeCapacityChange = onFreeCapacityChange, | |
| 12 | + | onTotalCapacityChange = onTotalCapacityChange, | |
| 13 | + | onStaminaChange = onStaminaChange, | |
| 14 | + | onOfflineTrainingChange = onOfflineTrainingChange, | |
| 15 | + | onRegenerationChange = onRegenerationChange, | |
| 16 | + | onSpeedChange = onSpeedChange, | |
| 17 | + | onBaseSpeedChange = onBaseSpeedChange, | |
| 18 | + | onMagicLevelChange = onMagicLevelChange, | |
| 19 | + | onBaseMagicLevelChange = onBaseMagicLevelChange, | |
| 20 | + | onSkillChange = onSkillChange, | |
| 21 | + | onBaseSkillChange = onBaseSkillChange | |
| 22 | + | }) | |
| 23 | + | connect(g_game, { | |
| 24 | + | onGameStart = refresh, | |
| 25 | + | onGameEnd = offline | |
| 26 | + | }) | |
| 27 | + | ||
| 28 | + | skillsButton = modules.client_topmenu.addRightGameToggleButton('skillsButton', tr('Skills'), '/images/topbuttons/skills', toggle, false, 1) | |
| 29 | + | --skillsButton:setOn(true) | |
| 30 | + | skillsButton:hide() | |
| 31 | + | skillsWindow = g_ui.loadUI('skills', modules.game_interface.getRightPanel()) | |
| 32 | + | skillsWindow:hide() | |
| 33 | + | ||
| 34 | + | refresh() | |
| 35 | + | --skillsWindow:setup() | |
| 36 | + | end | |
| 37 | + | ||
| 38 | + | function terminate() | |
| 39 | + | disconnect(LocalPlayer, { | |
| 40 | + | onExperienceChange = onExperienceChange, | |
| 41 | + | onLevelChange = onLevelChange, | |
| 42 | + | onHealthChange = onHealthChange, | |
| 43 | + | onManaChange = onManaChange, | |
| 44 | + | onSoulChange = onSoulChange, | |
| 45 | + | onFreeCapacityChange = onFreeCapacityChange, | |
| 46 | + | onTotalCapacityChange = onTotalCapacityChange, | |
| 47 | + | onStaminaChange = onStaminaChange, | |
| 48 | + | onOfflineTrainingChange = onOfflineTrainingChange, | |
| 49 | + | onRegenerationChange = onRegenerationChange, | |
| 50 | + | onSpeedChange = onSpeedChange, | |
| 51 | + | onBaseSpeedChange = onBaseSpeedChange, | |
| 52 | + | onMagicLevelChange = onMagicLevelChange, | |
| 53 | + | onBaseMagicLevelChange = onBaseMagicLevelChange, | |
| 54 | + | onSkillChange = onSkillChange, | |
| 55 | + | onBaseSkillChange = onBaseSkillChange | |
| 56 | + | }) | |
| 57 | + | disconnect(g_game, { | |
| 58 | + | onGameStart = refresh, | |
| 59 | + | onGameEnd = offline | |
| 60 | + | }) | |
| 61 | + | ||
| 62 | + | skillsWindow:destroy() | |
| 63 | + | skillsButton:destroy() | |
| 64 | + | end | |
| 65 | + | ||
| 66 | + | function expForLevel(level) | |
| 67 | + | return math.floor((50*level*level*level)/3 - 100*level*level + (850*level)/3 - 200) | |
| 68 | + | end | |
| 69 | + | ||
| 70 | + | function expToAdvance(currentLevel, currentExp) | |
| 71 | + | return expForLevel(currentLevel+1) - currentExp | |
| 72 | + | end | |
| 73 | + | ||
| 74 | + | function resetSkillColor(id) | |
| 75 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 76 | + | local widget = skill:getChildById('value') | |
| 77 | + | widget:setColor('#bbbbbb') | |
| 78 | + | end | |
| 79 | + | ||
| 80 | + | function toggleSkill(id, state) | |
| 81 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 82 | + | skill:setVisible(state) | |
| 83 | + | end | |
| 84 | + | ||
| 85 | + | function setSkillBase(id, value, baseValue) | |
| 86 | + | if baseValue <= 0 or value < 0 then | |
| 87 | + | return | |
| 88 | + | end | |
| 89 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 90 | + | local widget = skill:getChildById('value') | |
| 91 | + | ||
| 92 | + | if value > baseValue then | |
| 93 | + | widget:setColor('#008b00') -- green | |
| 94 | + | skill:setTooltip(baseValue .. ' +' .. (value - baseValue)) | |
| 95 | + | elseif value < baseValue then | |
| 96 | + | widget:setColor('#b22222') -- red | |
| 97 | + | skill:setTooltip(baseValue .. ' ' .. (value - baseValue)) | |
| 98 | + | else | |
| 99 | + | widget:setColor('#bbbbbb') -- default | |
| 100 | + | skill:removeTooltip() | |
| 101 | + | end | |
| 102 | + | end | |
| 103 | + | ||
| 104 | + | function setSkillValue(id, value) | |
| 105 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 106 | + | local widget = skill:getChildById('value') | |
| 107 | + | widget:setText(value) | |
| 108 | + | end | |
| 109 | + | ||
| 110 | + | function setSkillColor(id, value) | |
| 111 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 112 | + | local widget = skill:getChildById('value') | |
| 113 | + | widget:setColor(value) | |
| 114 | + | end | |
| 115 | + | ||
| 116 | + | function setSkillTooltip(id, value) | |
| 117 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 118 | + | local widget = skill:getChildById('value') | |
| 119 | + | widget:setTooltip(value) | |
| 120 | + | end | |
| 121 | + | ||
| 122 | + | function setSkillPercent(id, percent, tooltip, color) | |
| 123 | + | local skill = skillsWindow:recursiveGetChildById(id) | |
| 124 | + | local widget = skill:getChildById('percent') | |
| 125 | + | if widget then | |
| 126 | + | widget:setPercent(math.floor(percent)) | |
| 127 | + | ||
| 128 | + | if tooltip then | |
| 129 | + | widget:setTooltip(tooltip) | |
| 130 | + | end | |
| 131 | + | ||
| 132 | + | if color then | |
| 133 | + | widget:setBackgroundColor(color) | |
| 134 | + | end | |
| 135 | + | end | |
| 136 | + | end | |
| 137 | + | ||
| 138 | + | function checkAlert(id, value, maxValue, threshold, greaterThan) | |
| 139 | + | if greaterThan == nil then greaterThan = false end | |
| 140 | + | local alert = false | |
| 141 | + | ||
| 142 | + | -- maxValue can be set to false to check value and threshold | |
| 143 | + | -- used for regeneration checking | |
| 144 | + | if type(maxValue) == 'boolean' then | |
| 145 | + | if maxValue then | |
| 146 | + | return | |
| 147 | + | end | |
| 148 | + | ||
| 149 | + | if greaterThan then | |
| 150 | + | if value > threshold then | |
| 151 | + | alert = true | |
| 152 | + | end | |
| 153 | + | else | |
| 154 | + | if value < threshold then | |
| 155 | + | alert = true | |
| 156 | + | end | |
| 157 | + | end | |
| 158 | + | elseif type(maxValue) == 'number' then | |
| 159 | + | if maxValue < 0 then | |
| 160 | + | return | |
| 161 | + | end | |
| 162 | + | ||
| 163 | + | local percent = math.floor((value / maxValue) * 100) | |
| 164 | + | if greaterThan then | |
| 165 | + | if percent > threshold then | |
| 166 | + | alert = true | |
| 167 | + | end | |
| 168 | + | else | |
| 169 | + | if percent < threshold then | |
| 170 | + | alert = true | |
| 171 | + | end | |
| 172 | + | end | |
| 173 | + | end | |
| 174 | + | ||
| 175 | + | if alert then | |
| 176 | + | setSkillColor(id, '#b22222') -- red | |
| 177 | + | else | |
| 178 | + | resetSkillColor(id) | |
| 179 | + | end | |
| 180 | + | end | |
| 181 | + | ||
| 182 | + | function update() | |
| 183 | + | local offlineTraining = skillsWindow:recursiveGetChildById('offlineTraining') | |
| 184 | + | if not g_game.getFeature(GameOfflineTrainingTime) then | |
| 185 | + | offlineTraining:hide() | |
| 186 | + | else | |
| 187 | + | offlineTraining:show() | |
| 188 | + | end | |
| 189 | + | ||
| 190 | + | local regenerationTime = skillsWindow:recursiveGetChildById('regenerationTime') | |
| 191 | + | if not g_game.getFeature(GamePlayerRegenerationTime) then | |
| 192 | + | regenerationTime:hide() | |
| 193 | + | else | |
| 194 | + | regenerationTime:show() | |
| 195 | + | end | |
| 196 | + | end | |
| 197 | + | ||
| 198 | + | function refresh() | |
| 199 | + | local player = g_game.getLocalPlayer() | |
| 200 | + | if not player then return end | |
| 201 | + | ||
| 202 | + | if expSpeedEvent then expSpeedEvent:cancel() end | |
| 203 | + | expSpeedEvent = cycleEvent(checkExpSpeed, 30*1000) | |
| 204 | + | ||
| 205 | + | onExperienceChange(player, player:getExperience()) | |
| 206 | + | onLevelChange(player, player:getLevel(), player:getLevelPercent()) | |
| 207 | + | onHealthChange(player, player:getHealth(), player:getMaxHealth()) | |
| 208 | + | onManaChange(player, player:getMana(), player:getMaxMana()) | |
| 209 | + | onSoulChange(player, player:getSoul()) | |
| 210 | + | onFreeCapacityChange(player, player:getFreeCapacity()) | |
| 211 | + | onStaminaChange(player, player:getStamina()) | |
| 212 | + | onMagicLevelChange(player, player:getMagicLevel(), player:getMagicLevelPercent()) | |
| 213 | + | onOfflineTrainingChange(player, player:getOfflineTrainingTime()) | |
| 214 | + | onRegenerationChange(player, player:getRegenerationTime()) | |
| 215 | + | onSpeedChange(player, player:getSpeed()) | |
| 216 | + | ||
| 217 | + | local hasAdditionalSkills = g_game.getFeature(GameAdditionalSkills) | |
| 218 | + | for i = Skill.Fist, Skill.ManaLeechAmount do | |
| 219 | + | onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i)) | |
| 220 | + | onBaseSkillChange(player, i, player:getSkillBaseLevel(i)) | |
| 221 | + | ||
| 222 | + | if i > Skill.Fishing then | |
| 223 | + | toggleSkill('skillId'..i, hasAdditionalSkills) | |
| 224 | + | end | |
| 225 | + | end | |
| 226 | + | ||
| 227 | + | update() | |
| 228 | + | ||
| 229 | + | local contentsPanel = skillsWindow:getChildById('contentsPanel') | |
| 230 | + | skillsWindow:setContentMinimumHeight(44) | |
| 231 | + | if hasAdditionalSkills then | |
| 232 | + | skillsWindow:setContentMaximumHeight(480) | |
| 233 | + | else | |
| 234 | + | skillsWindow:setContentMaximumHeight(390) | |
| 235 | + | end | |
| 236 | + | end | |
| 237 | + | ||
| 238 | + | function offline() | |
| 239 | + | if expSpeedEvent then expSpeedEvent:cancel() expSpeedEvent = nil end | |
| 240 | + | end | |
| 241 | + | ||
| 242 | + | function Meclose() | |
| 243 | + | skillsWindow:close() | |
| 244 | + | end | |
| 245 | + | function toggle() | |
| 246 | + | if skillsButton:isOn() then | |
| 247 | + | skillsWindow:close() | |
| 248 | + | skillsButton:setOn(false) | |
| 249 | + | else | |
| 250 | + | skillsWindow:open() | |
| 251 | + | skillsButton:setOn(true) | |
| 252 | + | end | |
| 253 | + | end | |
| 254 | + | ||
| 255 | + | function checkExpSpeed() | |
| 256 | + | local player = g_game.getLocalPlayer() | |
| 257 | + | if not player then return end | |
| 258 | + | ||
| 259 | + | local currentExp = player:getExperience() | |
| 260 | + | local currentTime = g_clock.seconds() | |
| 261 | + | if player.lastExps ~= nil then | |
| 262 | + | player.expSpeed = (currentExp - player.lastExps[1][1])/(currentTime - player.lastExps[1][2]) | |
| 263 | + | onLevelChange(player, player:getLevel(), player:getLevelPercent()) | |
| 264 | + | else | |
| 265 | + | player.lastExps = {} | |
| 266 | + | end | |
| 267 | + | table.insert(player.lastExps, {currentExp, currentTime}) | |
| 268 | + | if #player.lastExps > 30 then | |
| 269 | + | table.remove(player.lastExps, 1) | |
| 270 | + | end | |
| 271 | + | end | |
| 272 | + | ||
| 273 | + | function onMiniWindowClose() | |
| 274 | + | skillsButton:setOn(false) | |
| 275 | + | end | |
| 276 | + | ||
| 277 | + | function onSkillButtonClick(button) | |
| 278 | + | local percentBar = button:getChildById('percent') | |
| 279 | + | if percentBar then | |
| 280 | + | percentBar:setVisible(not percentBar:isVisible()) | |
| 281 | + | if percentBar:isVisible() then | |
| 282 | + | button:setHeight(21) | |
| 283 | + | else | |
| 284 | + | button:setHeight(21 - 6) | |
| 285 | + | end | |
| 286 | + | end | |
| 287 | + | end | |
| 288 | + | ||
| 289 | + | function onExperienceChange(localPlayer, value) | |
| 290 | + | local postFix = "" | |
| 291 | + | if value > 1e15 then | |
| 292 | + | postFix = "B" | |
| 293 | + | value = math.floor(value / 1e9) | |
| 294 | + | elseif value > 1e12 then | |
| 295 | + | postFix = "M" | |
| 296 | + | value = math.floor(value / 1e6) | |
| 297 | + | elseif value > 1e9 then | |
| 298 | + | postFix = "K" | |
| 299 | + | value = math.floor(value / 1e3) | |
| 300 | + | end | |
| 301 | + | setSkillValue('experience', comma_value(value) .. postFix) | |
| 302 | + | end | |
| 303 | + | ||
| 304 | + | function onLevelChange(localPlayer, value, percent) | |
| 305 | + | setSkillValue('level', value) | |
| 306 | + | local text = tr('You have %s percent to go', 100 - percent) .. '\n' .. | |
| 307 | + | tr('%s of experience left', expToAdvance(localPlayer:getLevel(), localPlayer:getExperience())) | |
| 308 | + | ||
| 309 | + | if localPlayer.expSpeed ~= nil then | |
| 310 | + | local expPerHour = math.floor(localPlayer.expSpeed * 3600) | |
| 311 | + | if expPerHour > 0 then | |
| 312 | + | local nextLevelExp = expForLevel(localPlayer:getLevel()+1) | |
| 313 | + | local hoursLeft = (nextLevelExp - localPlayer:getExperience()) / expPerHour | |
| 314 | + | local minutesLeft = math.floor((hoursLeft - math.floor(hoursLeft))*60) | |
| 315 | + | hoursLeft = math.floor(hoursLeft) | |
| 316 | + | text = text .. '\n' .. tr('%d of experience per hour', expPerHour) | |
| 317 | + | text = text .. '\n' .. tr('Next level in %d hours and %d minutes', hoursLeft, minutesLeft) | |
| 318 | + | end | |
| 319 | + | end | |
| 320 | + | ||
| 321 | + | setSkillPercent('level', percent, text) | |
| 322 | + | end | |
| 323 | + | ||
| 324 | + | function onHealthChange(localPlayer, health, maxHealth) | |
| 325 | + | setSkillValue('health', health) | |
| 326 | + | checkAlert('health', health, maxHealth, 30) | |
| 327 | + | end | |
| 328 | + | ||
| 329 | + | function onManaChange(localPlayer, mana, maxMana) | |
| 330 | + | setSkillValue('mana', mana) | |
| 331 | + | checkAlert('mana', mana, maxMana, 30) | |
| 332 | + | end | |
| 333 | + | ||
| 334 | + | function onSoulChange(localPlayer, soul) | |
| 335 | + | setSkillValue('soul', soul) | |
| 336 | + | end | |
| 337 | + | ||
| 338 | + | function onFreeCapacityChange(localPlayer, freeCapacity) | |
| 339 | + | setSkillValue('capacity', freeCapacity) | |
| 340 | + | checkAlert('capacity', freeCapacity, localPlayer:getTotalCapacity(), 20) | |
| 341 | + | end | |
| 342 | + | ||
| 343 | + | function onTotalCapacityChange(localPlayer, totalCapacity) | |
| 344 | + | checkAlert('capacity', localPlayer:getFreeCapacity(), totalCapacity, 20) | |
| 345 | + | end | |
| 346 | + | ||
| 347 | + | function onStaminaChange(localPlayer, stamina) | |
| 348 | + | local hours = math.floor(stamina / 60) | |
| 349 | + | local minutes = stamina % 60 | |
| 350 | + | if minutes < 10 then | |
| 351 | + | minutes = '0' .. minutes | |
| 352 | + | end | |
| 353 | + | local percent = math.floor(100 * stamina / (42 * 60)) -- max is 42 hours --TODO not in all client versions | |
| 354 | + | ||
| 355 | + | setSkillValue('stamina', hours .. ":" .. minutes) | |
| 356 | + | ||
| 357 | + | --TODO not all client versions have premium time | |
| 358 | + | if stamina > 2400 and g_game.getClientVersion() >= 1038 and localPlayer:isPremium() then | |
| 359 | + | local text = tr("You have %s hours and %s minutes left", hours, minutes) .. '\n' .. | |
| 360 | + | tr("Now you will gain 50%% more experience") | |
| 361 | + | setSkillPercent('stamina', percent, text, 'green') | |
| 362 | + | elseif stamina > 2400 and g_game.getClientVersion() >= 1038 and not localPlayer:isPremium() then | |
| 363 | + | local text = tr("You have %s hours and %s minutes left", hours, minutes) .. '\n' .. | |
| 364 | + | tr("You will not gain 50%% more experience because you aren't premium player, now you receive only 1x experience points") | |
| 365 | + | setSkillPercent('stamina', percent, text, '#89F013') | |
| 366 | + | elseif stamina > 2400 and g_game.getClientVersion() < 1038 then | |
| 367 | + | local text = tr("You have %s hours and %s minutes left", hours, minutes) .. '\n' .. | |
| 368 | + | tr("If you are premium player, you will gain 50%% more experience") | |
| 369 | + | setSkillPercent('stamina', percent, text, 'green') | |
| 370 | + | elseif stamina <= 2400 and stamina > 840 then | |
| 371 | + | setSkillPercent('stamina', percent, tr("You have %s hours and %s minutes left", hours, minutes), 'orange') | |
| 372 | + | elseif stamina <= 840 and stamina > 0 then | |
| 373 | + | local text = tr("You have %s hours and %s minutes left", hours, minutes) .. "\n" .. | |
| 374 | + | tr("You gain only 50%% experience and you don't may gain loot from monsters") | |
| 375 | + | setSkillPercent('stamina', percent, text, 'red') | |
| 376 | + | elseif stamina == 0 then | |
| 377 | + | local text = tr("You have %s hours and %s minutes left", hours, minutes) .. "\n" .. | |
| 378 | + | tr("You don't may receive experience and loot from monsters") | |
| 379 | + | setSkillPercent('stamina', percent, text, 'black') | |
| 380 | + | end | |
| 381 | + | end | |
| 382 | + | ||
| 383 | + | function onOfflineTrainingChange(localPlayer, offlineTrainingTime) | |
| 384 | + | if not g_game.getFeature(GameOfflineTrainingTime) then | |
| 385 | + | return | |
| 386 | + | end | |
| 387 | + | local hours = math.floor(offlineTrainingTime / 60) | |
| 388 | + | local minutes = offlineTrainingTime % 60 | |
| 389 | + | if minutes < 10 then | |
| 390 | + | minutes = '0' .. minutes | |
| 391 | + | end | |
| 392 | + | local percent = 100 * offlineTrainingTime / (12 * 60) -- max is 12 hours | |
| 393 | + | ||
| 394 | + | setSkillValue('offlineTraining', hours .. ":" .. minutes) | |
| 395 | + | setSkillPercent('offlineTraining', percent, tr('You have %s percent', percent)) | |
| 396 | + | end | |
| 397 | + | ||
| 398 | + | function onRegenerationChange(localPlayer, regenerationTime) | |
| 399 | + | if not g_game.getFeature(GamePlayerRegenerationTime) or regenerationTime < 0 then | |
| 400 | + | return | |
| 401 | + | end | |
| 402 | + | local minutes = math.floor(regenerationTime / 60) | |
| 403 | + | local seconds = regenerationTime % 60 | |
| 404 | + | if seconds < 10 then | |
| 405 | + | seconds = '0' .. seconds | |
| 406 | + | end | |
| 407 | + | ||
| 408 | + | setSkillValue('regenerationTime', minutes .. ":" .. seconds) | |
| 409 | + | checkAlert('regenerationTime', regenerationTime, false, 300) | |
| 410 | + | end | |
| 411 | + | ||
| 412 | + | function onSpeedChange(localPlayer, speed) | |
| 413 | + | setSkillValue('speed', speed) | |
| 414 | + | ||
| 415 | + | onBaseSpeedChange(localPlayer, localPlayer:getBaseSpeed()) | |
| 416 | + | end | |
| 417 | + | ||
| 418 | + | function onBaseSpeedChange(localPlayer, baseSpeed) | |
| 419 | + | setSkillBase('speed', localPlayer:getSpeed(), baseSpeed) | |
| 420 | + | end | |
| 421 | + | ||
| 422 | + | function onMagicLevelChange(localPlayer, magiclevel, percent) | |
| 423 | + | setSkillValue('magiclevel', magiclevel) | |
| 424 | + | setSkillPercent('magiclevel', percent, tr('You have %s percent to go', 100 - percent)) | |
| 425 | + | ||
| 426 | + | onBaseMagicLevelChange(localPlayer, localPlayer:getBaseMagicLevel()) | |
| 427 | + | end | |
| 428 | + | ||
| 429 | + | function onBaseMagicLevelChange(localPlayer, baseMagicLevel) | |
| 430 | + | setSkillBase('magiclevel', localPlayer:getMagicLevel(), baseMagicLevel) | |
| 431 | + | end | |
| 432 | + | ||
| 433 | + | function onSkillChange(localPlayer, id, level, percent) | |
| 434 | + | setSkillValue('skillId' .. id, level) | |
| 435 | + | setSkillPercent('skillId' .. id, percent, tr('You have %s percent to go', 100 - percent)) | |
| 436 | + | ||
| 437 | + | onBaseSkillChange(localPlayer, id, localPlayer:getSkillBaseLevel(id)) | |
| 438 | + | end | |
| 439 | + | ||
| 440 | + | function onBaseSkillChange(localPlayer, id, baseLevel) | |
| 441 | + | setSkillBase('skillId'..id, localPlayer:getSkillLevel(id), baseLevel) | |
| 442 | + | end |
| @@ -0,0 +1,11 @@ | |||
| 1 | + | Module | |
| 2 | + | name: game_skills | |
| 3 | + | description: Manage skills window | |
| 4 | + | author: baxnie, edubart | |
| 5 | + | website: https://github.com/edubart/otclient | |
| 6 | + | sandboxed: true | |
| 7 | + | scripts: [ skills ] | |
| 8 | + | @onLoad: init() | |
| 9 | + | @onUnload: terminate() | |
| 10 | + | dependencies: | |
| 11 | + | - game_interface |
| @@ -0,0 +1,212 @@ | |||
| 1 | + | SkillFirstWidget < UIWidget | |
| 2 | + | ||
| 3 | + | SkillButton < UIButton | |
| 4 | + | height: 21 | |
| 5 | + | margin-bottom: 2 | |
| 6 | + | &onClick: onSkillButtonClick | |
| 7 | + | ||
| 8 | + | SmallSkillButton < SkillButton | |
| 9 | + | height: 14 | |
| 10 | + | ||
| 11 | + | SkillNameLabel < GameLabel | |
| 12 | + | font: verdana-11px-monochrome | |
| 13 | + | anchors.left: parent.left | |
| 14 | + | anchors.top: parent.top | |
| 15 | + | anchors.bottom: parent.bottom | |
| 16 | + | ||
| 17 | + | SkillValueLabel < GameLabel | |
| 18 | + | id: value | |
| 19 | + | font: verdana-11px-monochrome | |
| 20 | + | text-align: topright | |
| 21 | + | anchors.right: parent.right | |
| 22 | + | anchors.top: parent.top | |
| 23 | + | anchors.bottom: parent.bottom | |
| 24 | + | anchors.left: prev.left | |
| 25 | + | ||
| 26 | + | SkillPercentPanel < ProgressBar | |
| 27 | + | id: percent | |
| 28 | + | background-color: green | |
| 29 | + | height: 5 | |
| 30 | + | margin-top: 15 | |
| 31 | + | anchors.left: parent.left | |
| 32 | + | anchors.right: parent.right | |
| 33 | + | anchors.top: parent.top | |
| 34 | + | phantom: false | |
| 35 | + | ||
| 36 | + | MiniWindow | |
| 37 | + | id: skillWindow | |
| 38 | + | !text: tr('Skills') | |
| 39 | + | height: 150 | |
| 40 | + | icon: /images/topbuttons/skills | |
| 41 | + | @onClose: modules.game_skills.onMiniWindowClose() | |
| 42 | + | &save: true | |
| 43 | + | &autoOpen: false | |
| 44 | + | ||
| 45 | + | MiniWindowContents | |
| 46 | + | padding-left: 5 | |
| 47 | + | padding-right: 5 | |
| 48 | + | layout: verticalBox | |
| 49 | + | ||
| 50 | + | SkillButton | |
| 51 | + | margin-top: 5 | |
| 52 | + | id: experience | |
| 53 | + | height: 15 | |
| 54 | + | SkillNameLabel | |
| 55 | + | !text: tr('Experience') | |
| 56 | + | SkillValueLabel | |
| 57 | + | ||
| 58 | + | SkillButton | |
| 59 | + | id: level | |
| 60 | + | SkillNameLabel | |
| 61 | + | !text: tr('Level') | |
| 62 | + | SkillValueLabel | |
| 63 | + | SkillPercentPanel | |
| 64 | + | background-color: red | |
| 65 | + | ||
| 66 | + | SkillButton | |
| 67 | + | id: health | |
| 68 | + | height: 15 | |
| 69 | + | SkillNameLabel | |
| 70 | + | !text: tr('Hit Points') | |
| 71 | + | SkillValueLabel | |
| 72 | + | ||
| 73 | + | SkillButton | |
| 74 | + | id: mana | |
| 75 | + | height: 15 | |
| 76 | + | SkillNameLabel | |
| 77 | + | !text: tr('Mana') | |
| 78 | + | SkillValueLabel | |
| 79 | + | ||
| 80 | + | SkillButton | |
| 81 | + | id: soul | |
| 82 | + | height: 15 | |
| 83 | + | SkillNameLabel | |
| 84 | + | !text: tr('Soul Points') | |
| 85 | + | SkillValueLabel | |
| 86 | + | ||
| 87 | + | SkillButton | |
| 88 | + | id: capacity | |
| 89 | + | height: 15 | |
| 90 | + | SkillNameLabel | |
| 91 | + | !text: tr('Capacity') | |
| 92 | + | SkillValueLabel | |
| 93 | + | ||
| 94 | + | SkillButton | |
| 95 | + | id: speed | |
| 96 | + | height: 15 | |
| 97 | + | SkillNameLabel | |
| 98 | + | !text: tr('Speed') | |
| 99 | + | SkillValueLabel | |
| 100 | + | ||
| 101 | + | SkillButton | |
| 102 | + | id: regenerationTime | |
| 103 | + | SkillNameLabel | |
| 104 | + | !text: tr('Regeneration Time') | |
| 105 | + | SkillValueLabel | |
| 106 | + | ||
| 107 | + | SkillButton | |
| 108 | + | id: stamina | |
| 109 | + | SkillNameLabel | |
| 110 | + | !text: tr('Stamina') | |
| 111 | + | SkillValueLabel | |
| 112 | + | SkillPercentPanel | |
| 113 | + | ||
| 114 | + | SkillButton | |
| 115 | + | id: offlineTraining | |
| 116 | + | SkillNameLabel | |
| 117 | + | !text: tr('Offline Training') | |
| 118 | + | SkillValueLabel | |
| 119 | + | SkillPercentPanel | |
| 120 | + | ||
| 121 | + | SkillButton | |
| 122 | + | id: magiclevel | |
| 123 | + | SkillNameLabel | |
| 124 | + | !text: tr('Magic Level') | |
| 125 | + | SkillValueLabel | |
| 126 | + | SkillPercentPanel | |
| 127 | + | background-color: red | |
| 128 | + | ||
| 129 | + | SkillButton | |
| 130 | + | id: skillId0 | |
| 131 | + | SkillNameLabel | |
| 132 | + | !text: tr('Fist Fighting') | |
| 133 | + | SkillValueLabel | |
| 134 | + | SkillPercentPanel | |
| 135 | + | ||
| 136 | + | SkillButton | |
| 137 | + | id: skillId1 | |
| 138 | + | SkillNameLabel | |
| 139 | + | !text: tr('Club Fighting') | |
| 140 | + | SkillValueLabel | |
| 141 | + | SkillPercentPanel | |
| 142 | + | ||
| 143 | + | SkillButton | |
| 144 | + | id: skillId2 | |
| 145 | + | SkillNameLabel | |
| 146 | + | !text: tr('Sword Fighting') | |
| 147 | + | SkillValueLabel | |
| 148 | + | SkillPercentPanel | |
| 149 | + | ||
| 150 | + | SkillButton | |
| 151 | + | id: skillId3 | |
| 152 | + | SkillNameLabel | |
| 153 | + | !text: tr('Axe Fighting') | |
| 154 | + | SkillValueLabel | |
| 155 | + | SkillPercentPanel | |
| 156 | + | ||
| 157 | + | SkillButton | |
| 158 | + | id: skillId4 | |
| 159 | + | SkillNameLabel | |
| 160 | + | !text: tr('Distance Fighting') | |
| 161 | + | SkillValueLabel | |
| 162 | + | SkillPercentPanel | |
| 163 | + | ||
| 164 | + | SkillButton | |
| 165 | + | id: skillId5 | |
| 166 | + | SkillNameLabel | |
| 167 | + | !text: tr('Shielding') | |
| 168 | + | SkillValueLabel | |
| 169 | + | SkillPercentPanel | |
| 170 | + | ||
| 171 | + | SkillButton | |
| 172 | + | id: skillId6 | |
| 173 | + | SkillNameLabel | |
| 174 | + | !text: tr('Fishing') | |
| 175 | + | SkillValueLabel | |
| 176 | + | SkillPercentPanel | |
| 177 | + | ||
| 178 | + | SmallSkillButton | |
| 179 | + | id: skillId7 | |
| 180 | + | SkillNameLabel | |
| 181 | + | !text: tr('Critical Hit Chance') | |
| 182 | + | SkillValueLabel | |
| 183 | + | ||
| 184 | + | SmallSkillButton | |
| 185 | + | id: skillId8 | |
| 186 | + | SkillNameLabel | |
| 187 | + | !text: tr('Critical Hit Damage') | |
| 188 | + | SkillValueLabel | |
| 189 | + | ||
| 190 | + | SmallSkillButton | |
| 191 | + | id: skillId9 | |
| 192 | + | SkillNameLabel | |
| 193 | + | !text: tr('Life Leech Chance') | |
| 194 | + | SkillValueLabel | |
| 195 | + | ||
| 196 | + | SmallSkillButton | |
| 197 | + | id: skillId10 | |
| 198 | + | SkillNameLabel | |
| 199 | + | !text: tr('Life Leech Amount') | |
| 200 | + | SkillValueLabel | |
| 201 | + | ||
| 202 | + | SmallSkillButton | |
| 203 | + | id: skillId11 | |
| 204 | + | SkillNameLabel | |
| 205 | + | !text: tr('Mana Leech Chance') | |
| 206 | + | SkillValueLabel | |
| 207 | + | ||
| 208 | + | SmallSkillButton | |
| 209 | + | id: skillId12 | |
| 210 | + | SkillNameLabel | |
| 211 | + | !text: tr('Mana Leech Amount') | |
| 212 | + | SkillValueLabel |
| @@ -0,0 +1,1040 @@ | |||
| 1 | + | local spellBarWindow = nil | |
| 2 | + | local clickedSlot = nil | |
| 3 | + | local newKey = nil | |
| 4 | + | local slotHotkey = nil | |
| 5 | + | local comboLabel = nil | |
| 6 | + | local spellCooldowns = {} -- Tabela de cooldowns. Estrutura: spellCooldowns["PlayerName"]["nomeSpell"] = endTime | |
| 7 | + | local comboPreview = nil | |
| 8 | + | ||
| 9 | + | local vocation = 0 | |
| 10 | + | local hotkeys = {} -- Tabela para armazenar os hotkeys salvos | |
| 11 | + | local lastUsedSpell = nil -- Armazena o último feitiço usado (para reverter cooldown se falhar) | |
| 12 | + | ||
| 13 | + | -- Variável para o cooldown global atual (será definido conforme a magia usada) | |
| 14 | + | local globalCooldownEnd = 0 | |
| 15 | + | ||
| 16 | + | -- Variável para bloquear movimento enquanto a hotkey é usada | |
| 17 | + | local movementBlocker = nil | |
| 18 | + | ||
| 19 | + | ---------------------------------------------------------------------- | |
| 20 | + | -- LAYOUT RESPONSIVO (posição, tamanho, quebra de linha) -- | |
| 21 | + | ---------------------------------------------------------------------- | |
| 22 | + | local SLOT_COUNT = 10 | |
| 23 | + | local SLOT_SIZE = 36 | |
| 24 | + | local SLOT_HEIGHT = 45 -- slot + hotkey number under it | |
| 25 | + | local SLOT_SPACING = 10 | |
| 26 | + | local ROW_SPACING = 6 | |
| 27 | + | local DEFAULT_BOTTOM = 90 | |
| 28 | + | ||
| 29 | + | -- Position relative to the bottom-center of the game screen (like CSS | |
| 30 | + | -- "position: fixed; bottom: Npx; left: 50%"), so it follows window resizes. | |
| 31 | + | local barOffset = { x = 0, bottom = DEFAULT_BOTTOM } | |
| 32 | + | local rootPanel = nil | |
| 33 | + | ||
| 34 | + | local function barWidth(columns) | |
| 35 | + | return columns * SLOT_SIZE + (columns - 1) * SLOT_SPACING | |
| 36 | + | end | |
| 37 | + | ||
| 38 | + | -- Client option "Show action bar" (client_options, id: actionBar) | |
| 39 | + | function isBarEnabled() | |
| 40 | + | return not modules.client_options or modules.client_options.getOption('actionBar') ~= false | |
| 41 | + | end | |
| 42 | + | ||
| 43 | + | function setBarEnabled(enabled) | |
| 44 | + | if not spellBarWindow then return end | |
| 45 | + | if enabled and g_game.isOnline() and spellBarWindow:getChildById('slot-1') then | |
| 46 | + | spellBarWindow:show() | |
| 47 | + | relayout() | |
| 48 | + | else | |
| 49 | + | spellBarWindow:hide() | |
| 50 | + | end | |
| 51 | + | end | |
| 52 | + | ||
| 53 | + | -- Re-anchors the bar to the bottom-center of the game screen, clamped so it | |
| 54 | + | -- never leaves the screen. | |
| 55 | + | function applyPosition() | |
| 56 | + | if not spellBarWindow then return end | |
| 57 | + | local parent = spellBarWindow:getParent() | |
| 58 | + | if not parent or parent:getWidth() <= 0 then return end | |
| 59 | + | ||
| 60 | + | local maxX = math.max(0, math.floor((parent:getWidth() - spellBarWindow:getWidth()) / 2)) | |
| 61 | + | local maxBottom = math.max(0, parent:getHeight() - spellBarWindow:getHeight()) | |
| 62 | + | local x = math.max(-maxX, math.min(maxX, barOffset.x)) | |
| 63 | + | local bottom = math.max(0, math.min(maxBottom, barOffset.bottom)) | |
| 64 | + | ||
| 65 | + | spellBarWindow:breakAnchors() | |
| 66 | + | spellBarWindow:addAnchor(AnchorBottom, 'parent', AnchorBottom) | |
| 67 | + | spellBarWindow:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter) | |
| 68 | + | spellBarWindow:setMarginBottom(bottom) | |
| 69 | + | spellBarWindow:setMarginLeft(math.max(0, x)) | |
| 70 | + | spellBarWindow:setMarginRight(math.max(0, -x)) | |
| 71 | + | end | |
| 72 | + | ||
| 73 | + | -- One row of 10 slots, or two rows of 5 when the game screen is too narrow. | |
| 74 | + | function relayout() | |
| 75 | + | if not spellBarWindow then return end | |
| 76 | + | local parent = spellBarWindow:getParent() | |
| 77 | + | if not parent or parent:getWidth() <= 0 then return end | |
| 78 | + | ||
| 79 | + | local columns = SLOT_COUNT | |
| 80 | + | if parent:getWidth() - 20 < barWidth(SLOT_COUNT) then | |
| 81 | + | columns = math.ceil(SLOT_COUNT / 2) | |
| 82 | + | end | |
| 83 | + | local rows = math.ceil(SLOT_COUNT / columns) | |
| 84 | + | spellBarWindow:setSize({ width = barWidth(columns), height = rows * SLOT_HEIGHT + (rows - 1) * ROW_SPACING }) | |
| 85 | + | ||
| 86 | + | for i = 1, SLOT_COUNT do | |
| 87 | + | local slot = spellBarWindow:getChildById('slot-' .. i) | |
| 88 | + | if slot then | |
| 89 | + | slot:setMarginLeft(((i - 1) % columns) * (SLOT_SIZE + SLOT_SPACING)) | |
| 90 | + | slot:setMarginTop(math.floor((i - 1) / columns) * (SLOT_HEIGHT + ROW_SPACING)) | |
| 91 | + | end | |
| 92 | + | end | |
| 93 | + | applyPosition() | |
| 94 | + | end | |
| 95 | + | ||
| 96 | + | function resetPosition() | |
| 97 | + | barOffset.x = 0 | |
| 98 | + | barOffset.bottom = DEFAULT_BOTTOM | |
| 99 | + | g_settings.set('spellBarOffsetX', barOffset.x) | |
| 100 | + | g_settings.set('spellBarOffsetBottom', barOffset.bottom) | |
| 101 | + | applyPosition() | |
| 102 | + | end | |
| 103 | + | ||
| 104 | + | -- After a drag, remember where the player put it (relative to bottom-center) | |
| 105 | + | -- and anchor it again, instead of leaving it at fixed pixels. | |
| 106 | + | local function onBarDragLeave(widget, droppedWidget, mousePos) | |
| 107 | + | local parent = widget:getParent() | |
| 108 | + | if not parent then return end | |
| 109 | + | barOffset.x = math.floor(widget:getX() + widget:getWidth() / 2 - (parent:getX() + parent:getWidth() / 2)) | |
| 110 | + | barOffset.bottom = math.floor(parent:getY() + parent:getHeight() - (widget:getY() + widget:getHeight())) | |
| 111 | + | g_settings.set('spellBarOffsetX', barOffset.x) | |
| 112 | + | g_settings.set('spellBarOffsetBottom', barOffset.bottom) | |
| 113 | + | applyPosition() | |
| 114 | + | end | |
| 115 | + | ||
| 116 | + | local function onBarMousePress(widget, mousePos, mouseButton) | |
| 117 | + | if mouseButton ~= MouseRightButton then return false end | |
| 118 | + | local menu = g_ui.createWidget('PopupMenu') | |
| 119 | + | menu:setGameMenu(true) | |
| 120 | + | menu:addOption(tr('Reset spell bar position'), resetPosition) | |
| 121 | + | menu:display(mousePos) | |
| 122 | + | return true | |
| 123 | + | end | |
| 124 | + | ||
| 125 | + | ---------------------------------------------------------------------- | |
| 126 | + | -- BLOQUEIO E LIBERAÇÃO DE MOVIMENTO -- | |
| 127 | + | ---------------------------------------------------------------------- | |
| 128 | + | function blockMovement() | |
| 129 | + | if not movementBlocker then | |
| 130 | + | -- Cria um widget invisível que captura o teclado e impede o movimento. | |
| 131 | + | -- Usamos o estilo "UIWidget", que é padrão. | |
| 132 | + | movementBlocker = g_ui.createWidget('UIWidget', modules.game_interface.getRootPanel()) | |
| 133 | + | if movementBlocker then | |
| 134 | + | movementBlocker:setSize({ width = 1, height = 1 }) | |
| 135 | + | movementBlocker:setOpacity(0) -- Torna o widget invisível | |
| 136 | + | movementBlocker:grabKeyboard() | |
| 137 | + | movementBlocker.onKeyDown = function(widget, keyCode, keyboardModifiers) | |
| 138 | + | local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers) | |
| 139 | + | if keyCombo == "Up" or keyCombo == "Down" or keyCombo == "Left" or keyCombo == "Right" or | |
| 140 | + | keyCombo:lower() == "w" or keyCombo:lower() == "a" or keyCombo:lower() == "s" or keyCombo:lower() == "d" then | |
| 141 | + | return true -- Bloqueia as teclas de movimento | |
| 142 | + | end | |
| 143 | + | return false | |
| 144 | + | end | |
| 145 | + | else | |
| 146 | + | print("Failed to create movementBlocker widget") | |
| 147 | + | end | |
| 148 | + | end | |
| 149 | + | end | |
| 150 | + | ||
| 151 | + | function unblockMovement() | |
| 152 | + | if movementBlocker then | |
| 153 | + | movementBlocker:destroy() | |
| 154 | + | movementBlocker = nil | |
| 155 | + | end | |
| 156 | + | end | |
| 157 | + | ||
| 158 | + | ---------------------------------------------------------------------- | |
| 159 | + | -- LISTA DE SPELLS -- | |
| 160 | + | ---------------------------------------------------------------------- | |
| 161 | + | local spelllist = { | |
| 162 | + | [1] = { -- Gon | |
| 163 | + | ["Punch"] = { | |
| 164 | + | name = '@#$0', | |
| 165 | + | exhaustion = 1, | |
| 166 | + | globalCooldown = 0.5, -- Cooldown global editável para esta magia | |
| 167 | + | icon = 'HXH/gon/1', | |
| 168 | + | level = 1, | |
| 169 | + | mana = 0, | |
| 170 | + | key = "F1", | |
| 171 | + | desc = "Gon da um soco rápido no inimigo.", | |
| 172 | + | movementBlockTime = 300 -- bloqueia movimento por 500ms | |
| 173 | + | }, | |
| 174 | + | ["Sequence Punch"] = { | |
| 175 | + | name = '@#$1', | |
| 176 | + | exhaustion = 2, | |
| 177 | + | globalCooldown = 0.8, | |
| 178 | + | icon = 'HXH/gon/10', | |
| 179 | + | level = 5, | |
| 180 | + | mana = 0, | |
| 181 | + | key = "F2", | |
| 182 | + | desc = "Gon atinge o alvo com uma sequencia de socos.", | |
| 183 | + | movementBlockTime = 500 | |
| 184 | + | }, | |
| 185 | + | ["Jajaken Gu"] = { | |
| 186 | + | name = '@#$2', | |
| 187 | + | exhaustion = 3, | |
| 188 | + | globalCooldown = 1, | |
| 189 | + | icon = 'HXH/gon/15', | |
| 190 | + | level = 15, | |
| 191 | + | mana = 0, | |
| 192 | + | key = "F3", | |
| 193 | + | desc = "Gon concentra aura em seu punho e desfere um soco de Nen.", | |
| 194 | + | movementBlockTime = 800 | |
| 195 | + | }, | |
| 196 | + | ["Dash"] = { | |
| 197 | + | name = '@#$3', | |
| 198 | + | exhaustion = 7, | |
| 199 | + | globalCooldown = 1, | |
| 200 | + | icon = 'HXH/gon/25', | |
| 201 | + | level = 20, | |
| 202 | + | mana = 0, | |
| 203 | + | key = "F4", | |
| 204 | + | desc = "Gon usa seu instinto selvagem para se esquivar.", | |
| 205 | + | movementBlockTime = 0 | |
| 206 | + | }, | |
| 207 | + | ["Ren"] = { | |
| 208 | + | name = '@#$4', | |
| 209 | + | exhaustion = 10, | |
| 210 | + | globalCooldown = 1, | |
| 211 | + | icon = 'HXH/gon/20', | |
| 212 | + | level = 25, | |
| 213 | + | mana = 0, | |
| 214 | + | key = "F5", | |
| 215 | + | desc = "Expande e intensifica a aura o máximo possível.", | |
| 216 | + | movementBlockTime = 300 | |
| 217 | + | }, | |
| 218 | + | ["Rock Smash"] = { | |
| 219 | + | name = '@#$5', | |
| 220 | + | exhaustion = 20, | |
| 221 | + | globalCooldown = 1.5, | |
| 222 | + | icon = 'HXH/gon/35', | |
| 223 | + | level = 35, | |
| 224 | + | mana = 0, | |
| 225 | + | key = "F6", | |
| 226 | + | desc = "Gon acumula uma grande quantidade de aura em seu punho e atinge o solo.", | |
| 227 | + | movementBlockTime = 1600 | |
| 228 | + | }, | |
| 229 | + | ["Jajaken Chi"] = { | |
| 230 | + | name = '@#$6', | |
| 231 | + | exhaustion = 10, | |
| 232 | + | globalCooldown = 0.7, | |
| 233 | + | icon = 'HXH/gon/50', | |
| 234 | + | level = 50, | |
| 235 | + | mana = 0, | |
| 236 | + | key = "F7", | |
| 237 | + | desc = "Gon transforma sua aura em uma lâmina de Nen.", | |
| 238 | + | movementBlockTime = 1200 | |
| 239 | + | }, | |
| 240 | + | ["Jajaken Pa"] = { | |
| 241 | + | name = '@#$7', | |
| 242 | + | exhaustion = 15, | |
| 243 | + | globalCooldown = 1.3, | |
| 244 | + | icon = 'HXH/gon/55', | |
| 245 | + | level = 55, | |
| 246 | + | mana = 0, | |
| 247 | + | key = "F8", | |
| 248 | + | desc = "Gon transforma sua aura em uma esfera de Nen e a dispara em direção ao alvo.", | |
| 249 | + | movementBlockTime = 2000 | |
| 250 | + | } | |
| 251 | + | }, | |
| 252 | + | ||
| 253 | + | [2] = { -- Killua | |
| 254 | + | ["Claws"] = { | |
| 255 | + | name = 'Claws', | |
| 256 | + | exhaustion = 1, | |
| 257 | + | globalCooldown = 1, | |
| 258 | + | icon = 'HXH/killua/1', | |
| 259 | + | level = 1, | |
| 260 | + | mana = 0, | |
| 261 | + | key = "F1", | |
| 262 | + | desc = "Killua ataca com suas mãos afiadas.", | |
| 263 | + | movementBlockTime = 300 | |
| 264 | + | }, | |
| 265 | + | ["Double Claws"] = { | |
| 266 | + | name = 'Double Claws', | |
| 267 | + | exhaustion = 5, | |
| 268 | + | globalCooldown = 1.2, | |
| 269 | + | icon = 'HXH/killua/10', | |
| 270 | + | level = 10, | |
| 271 | + | mana = 0, | |
| 272 | + | key = "F2", | |
| 273 | + | desc = "Killua se move rapidamente criando imagens residuais para confundir o inimigo.", | |
| 274 | + | movementBlockTime = 400 | |
| 275 | + | }, | |
| 276 | + | ["Critical Claws"] = { | |
| 277 | + | name = 'Critical Claws', | |
| 278 | + | exhaustion = 3, | |
| 279 | + | globalCooldown = 1.05, | |
| 280 | + | icon = 'HXH/killua/15', | |
| 281 | + | level = 15, | |
| 282 | + | mana = 0, | |
| 283 | + | key = "F3", | |
| 284 | + | desc = "Killua libera uma descarga elétrica concentrada em sua palma.", | |
| 285 | + | movementBlockTime = 300 | |
| 286 | + | }, | |
| 287 | + | ["dark steps"] = { | |
| 288 | + | name = 'dark steps', | |
| 289 | + | exhaustion = 5, | |
| 290 | + | globalCooldown = 2, | |
| 291 | + | icon = 'HXH/killua/20', | |
| 292 | + | level = 20, | |
| 293 | + | mana = 0, | |
| 294 | + | key = "F4", | |
| 295 | + | desc = "Killua dispara um raio elétrico em seus inimigos.", | |
| 296 | + | movementBlockTime = 700 | |
| 297 | + | }, | |
| 298 | + | ["Rhythm Echo"] = { | |
| 299 | + | name = 'Rhythm Echo', | |
| 300 | + | exhaustion = 15, | |
| 301 | + | globalCooldown = 1, | |
| 302 | + | icon = 'HXH/Killua/dash', | |
| 303 | + | level = 25, | |
| 304 | + | mana = 0, | |
| 305 | + | key = "F5", | |
| 306 | + | desc = "Killua atinge sua velocidade máxima com Nen elétrico.", | |
| 307 | + | movementBlockTime = 300 | |
| 308 | + | }, | |
| 309 | + | ["Kanden shi"] = { | |
| 310 | + | name = 'Kanden shi', | |
| 311 | + | exhaustion = 10, | |
| 312 | + | globalCooldown = 1, | |
| 313 | + | icon = 'HXH/Killua/40', | |
| 314 | + | level = 40, | |
| 315 | + | mana = 0, | |
| 316 | + | key = "F6", | |
| 317 | + | desc = "Killua atinge sua velocidade máxima com Nen elétrico.", | |
| 318 | + | movementBlockTime = 1250 | |
| 319 | + | } | |
| 320 | + | }, | |
| 321 | + | ||
| 322 | + | [3] = { -- Kurapika | |
| 323 | + | ["basic chain attack"] = { | |
| 324 | + | name = 'Basic Chain Attack', | |
| 325 | + | exhaustion = 2, | |
| 326 | + | globalCooldown = 1, | |
| 327 | + | icon = 'HXH/Kurapika_basic', | |
| 328 | + | level = 1, | |
| 329 | + | mana = 0, | |
| 330 | + | key = "Q", | |
| 331 | + | desc = "Kurapika ataca com sua corrente básica.", | |
| 332 | + | movementBlockTime = 300 | |
| 333 | + | }, | |
| 334 | + | ["chain jail"] = { | |
| 335 | + | name = 'Chain Jail', | |
| 336 | + | exhaustion = 10, | |
| 337 | + | globalCooldown = 1, | |
| 338 | + | icon = 'HXH/Kurapika1', | |
| 339 | + | level = 30, | |
| 340 | + | mana = 0, | |
| 341 | + | key = "1", | |
| 342 | + | desc = "Kurapika prende o alvo com correntes de Nen que restringem seu movimento.", | |
| 343 | + | movementBlockTime = 500 | |
| 344 | + | }, | |
| 345 | + | ["holy chain"] = { | |
| 346 | + | name = 'Holy Chain', | |
| 347 | + | exhaustion = 30, | |
| 348 | + | globalCooldown = 1, | |
| 349 | + | icon = 'HXH/Kurapika3', | |
| 350 | + | level = 50, | |
| 351 | + | mana = 0, | |
| 352 | + | key = "2", | |
| 353 | + | desc = "Correntes de cura restauram HP rapidamente.", | |
| 354 | + | movementBlockTime = 600 | |
| 355 | + | }, | |
| 356 | + | ["judgment chain"] = { | |
| 357 | + | name = 'Judgment Chain', | |
| 358 | + | exhaustion = 60, | |
| 359 | + | globalCooldown = 1, | |
| 360 | + | icon = 'HXH/Kurapika2', | |
| 361 | + | level = 70, | |
| 362 | + | mana = 0, | |
| 363 | + | key = "3", | |
| 364 | + | desc = "Uma corrente mortal que perfura o coração do inimigo e o condena.", | |
| 365 | + | movementBlockTime = 700 | |
| 366 | + | }, | |
| 367 | + | ["scarlet eyes mode"] = { | |
| 368 | + | name = 'Scarlet Eyes Mode', | |
| 369 | + | exhaustion = 90, | |
| 370 | + | globalCooldown = 1, | |
| 371 | + | icon = 'HXH/Kurapika4', | |
| 372 | + | level = 100, | |
| 373 | + | mana = 0, | |
| 374 | + | key = "4", | |
| 375 | + | desc = "Kurapika ativa seus olhos escarlates, aumentando drasticamente seu poder.", | |
| 376 | + | movementBlockTime = 800 | |
| 377 | + | } | |
| 378 | + | }, | |
| 379 | + | ||
| 380 | + | [4] = { -- Hisoka | |
| 381 | + | ["basic card throw"] = { | |
| 382 | + | name = 'Basic Card Throw', | |
| 383 | + | exhaustion = 2, | |
| 384 | + | globalCooldown = 1, | |
| 385 | + | icon = 'HXH/Hisoka_basic', | |
| 386 | + | level = 1, | |
| 387 | + | mana = 0, | |
| 388 | + | key = "Q", | |
| 389 | + | desc = "Hisoka arremessa uma carta de baralho afiada no inimigo.", | |
| 390 | + | movementBlockTime = 300 | |
| 391 | + | }, | |
| 392 | + | ["bungee gum trap"] = { | |
| 393 | + | name = 'Bungee Gum Trap', | |
| 394 | + | exhaustion = 10, | |
| 395 | + | globalCooldown = 1, | |
| 396 | + | icon = 'HXH/Hisoka1', | |
| 397 | + | level = 30, | |
| 398 | + | mana = 0, | |
| 399 | + | key = "1", | |
| 400 | + | desc = "Hisoka prende o inimigo com sua elasticidade especial.", | |
| 401 | + | movementBlockTime = 400 | |
| 402 | + | }, | |
| 403 | + | ["card barrage"] = { | |
| 404 | + | name = 'Card Barrage', | |
| 405 | + | exhaustion = 30, | |
| 406 | + | globalCooldown = 1, | |
| 407 | + | icon = 'HXH/Hisoka2', | |
| 408 | + | level = 50, | |
| 409 | + | mana = 0, | |
| 410 | + | key = "2", | |
| 411 | + | desc = "Hisoka lança várias cartas mortais simultaneamente.", | |
| 412 | + | movementBlockTime = 500 | |
| 413 | + | }, | |
| 414 | + | ["exploding trick"] = { | |
| 415 | + | name = 'Exploding Trick', | |
| 416 | + | exhaustion = 60, | |
| 417 | + | globalCooldown = 1, | |
| 418 | + | icon = 'HXH/Hisoka3', | |
| 419 | + | level = 75, | |
| 420 | + | mana = 0, | |
| 421 | + | key = "3", | |
| 422 | + | desc = "Hisoka engana o inimigo com uma ilusão antes de um golpe fatal.", | |
| 423 | + | movementBlockTime = 600 | |
| 424 | + | }, | |
| 425 | + | ["full power mode"] = { | |
| 426 | + | name = 'Full Power Mode', | |
| 427 | + | exhaustion = 90, | |
| 428 | + | globalCooldown = 1, | |
| 429 | + | icon = 'HXH/Hisoka4', | |
| 430 | + | level = 100, | |
| 431 | + | mana = 0, | |
| 432 | + | key = "4", | |
| 433 | + | desc = "Hisoka libera seu verdadeiro poder, aumentando sua força e velocidade por um tempo limitado.", | |
| 434 | + | movementBlockTime = 700 | |
| 435 | + | } | |
| 436 | + | } | |
| 437 | + | } | |
| 438 | + | ||
| 439 | + | -- Define a função global para buscar feitiços | |
| 440 | + | _G.getSpellByLowerName = function(voc, lowerName) | |
| 441 | + | for key, spell in pairs(spelllist[voc]) do | |
| 442 | + | if spell.name:lower() == lowerName then | |
| 443 | + | return spell | |
| 444 | + | end | |
| 445 | + | end | |
| 446 | + | return nil | |
| 447 | + | end | |
| 448 | + | ||
| 449 | + | ---------------------------------------------------------------------- | |
| 450 | + | -- SALVAR/CARREGAR HOTKEYS E COOLDOWNS -- | |
| 451 | + | ---------------------------------------------------------------------- | |
| 452 | + | function loadHotkeys() | |
| 453 | + | if g_settings then | |
| 454 | + | local data = g_settings.get("SpellbarHotkeys") | |
| 455 | + | if data and data ~= "" then | |
| 456 | + | local success, result = pcall(json.decode, data) | |
| 457 | + | if success and result then | |
| 458 | + | hotkeys = result | |
| 459 | + | end | |
| 460 | + | end | |
| 461 | + | end | |
| 462 | + | end | |
| 463 | + | ||
| 464 | + | function saveHotkeys() | |
| 465 | + | if g_settings then | |
| 466 | + | local encoded = json.encode(hotkeys) | |
| 467 | + | g_settings.set("SpellbarHotkeys", encoded) | |
| 468 | + | end | |
| 469 | + | end | |
| 470 | + | ||
| 471 | + | -- Retorna o nome do player para indexar cooldowns | |
| 472 | + | local function getPlayerNameForStorage() | |
| 473 | + | local player = g_game.getLocalPlayer() | |
| 474 | + | if not player then return nil end | |
| 475 | + | return player:getName() | |
| 476 | + | end | |
| 477 | + | ||
| 478 | + | -- Carrega cooldowns salvos em g_settings | |
| 479 | + | local function loadCooldowns() | |
| 480 | + | local data = g_settings.get("SpellCooldowns") | |
| 481 | + | if not data or data == "" then return end | |
| 482 | + | ||
| 483 | + | local success, result = pcall(json.decode, data) | |
| 484 | + | if not success or not result then return end | |
| 485 | + | ||
| 486 | + | local playerName = getPlayerNameForStorage() | |
| 487 | + | if not playerName or not result[playerName] then return end | |
| 488 | + | ||
| 489 | + | -- Cria a tabela do player se não existir | |
| 490 | + | if not spellCooldowns[playerName] then | |
| 491 | + | spellCooldowns[playerName] = {} | |
| 492 | + | end | |
| 493 | + | ||
| 494 | + | -- Reaplica o endTime = os.time() + timeLeft | |
| 495 | + | for spellName, timeLeft in pairs(result[playerName]) do | |
| 496 | + | spellCooldowns[playerName][spellName] = os.time() + timeLeft | |
| 497 | + | end | |
| 498 | + | end | |
| 499 | + | ||
| 500 | + | -- Salva cooldowns em g_settings | |
| 501 | + | local function saveCooldowns() | |
| 502 | + | local playerName = getPlayerNameForStorage() | |
| 503 | + | if not playerName then return end | |
| 504 | + | ||
| 505 | + | local data = {} | |
| 506 | + | -- Lê o que já existe no arquivo (para não sobrescrever outros chars) | |
| 507 | + | local oldData = g_settings.get("SpellCooldowns") | |
| 508 | + | local success, oldResult = pcall(json.decode, oldData or "") | |
| 509 | + | if success and oldResult then | |
| 510 | + | data = oldResult | |
| 511 | + | end | |
| 512 | + | ||
| 513 | + | -- Cria a tabela do player se não existir | |
| 514 | + | if not data[playerName] then | |
| 515 | + | data[playerName] = {} | |
| 516 | + | end | |
| 517 | + | ||
| 518 | + | -- Pega a tabela de cooldowns do player atual | |
| 519 | + | if spellCooldowns[playerName] then | |
| 520 | + | for spellName, endTime in pairs(spellCooldowns[playerName]) do | |
| 521 | + | local timeLeft = endTime - os.time() | |
| 522 | + | if timeLeft > 0 then | |
| 523 | + | data[playerName][spellName] = timeLeft | |
| 524 | + | else | |
| 525 | + | data[playerName][spellName] = nil | |
| 526 | + | end | |
| 527 | + | end | |
| 528 | + | end | |
| 529 | + | ||
| 530 | + | local encoded = json.encode(data) | |
| 531 | + | g_settings.set("SpellCooldowns", encoded) | |
| 532 | + | end | |
| 533 | + | ||
| 534 | + | ---------------------------------------------------------------------- | |
| 535 | + | -- INICIALIZAÇÃO -- | |
| 536 | + | ---------------------------------------------------------------------- | |
| 537 | + | function init() | |
| 538 | + | spellBarWindow = g_ui.loadUI('game_spellbar.otui', modules.game_interface.getRootPanel()) | |
| 539 | + | ||
| 540 | + | if not spellBarWindow then | |
| 541 | + | print("Erro: Falha ao carregar a SpellBar") | |
| 542 | + | return | |
| 543 | + | end | |
| 544 | + | ||
| 545 | + | spellBarWindow:setDraggable(true) | |
| 546 | + | spellBarWindow.onDragLeave = onBarDragLeave | |
| 547 | + | spellBarWindow.onMousePress = onBarMousePress | |
| 548 | + | ||
| 549 | + | barOffset.x = tonumber(g_settings.get('spellBarOffsetX')) or 0 | |
| 550 | + | barOffset.bottom = tonumber(g_settings.get('spellBarOffsetBottom')) or DEFAULT_BOTTOM | |
| 551 | + | ||
| 552 | + | -- follow the game screen size (window resize, side panels, fullscreen) | |
| 553 | + | rootPanel = modules.game_interface.getRootPanel() | |
| 554 | + | connect(rootPanel, { onGeometryChange = relayout }) | |
| 555 | + | ||
| 556 | + | loadHotkeys() | |
| 557 | + | ||
| 558 | + | connect(g_game, {onGameStart = onGameStart, onGameEnd = offline}) | |
| 559 | + | connect(LocalPlayer, {onLevelChange = onLevelChange, onManaChange = onManaChange}) | |
| 560 | + | connect(g_game, {onTextMessage = onTextMessage}) | |
| 561 | + | connect(g_game, 'onTalk', onTalk) | |
| 562 | + | ||
| 563 | + | ProtocolGame.registerExtendedOpcode(193, function(protocol, opcode, buffer) createSpellBar(buffer) end) | |
| 564 | + | end | |
| 565 | + | ||
| 566 | + | function terminate() | |
| 567 | + | disconnect(g_game, {onGameStart = onGameStart}) | |
| 568 | + | disconnect(g_game, {onGameEnd = offline}) | |
| 569 | + | disconnect(LocalPlayer, {onLevelChange = onLevelChange}) | |
| 570 | + | disconnect(LocalPlayer, {onManaChange = onManaChange}) | |
| 571 | + | disconnect(g_game, 'onTalk', onTalk) | |
| 572 | + | ||
| 573 | + | ProtocolGame.unregisterExtendedOpcode(193) | |
| 574 | + | if rootPanel then | |
| 575 | + | disconnect(rootPanel, { onGeometryChange = relayout }) | |
| 576 | + | rootPanel = nil | |
| 577 | + | end | |
| 578 | + | spellBarWindow:destroy() | |
| 579 | + | end | |
| 580 | + | ||
| 581 | + | ---------------------------------------------------------------------- | |
| 582 | + | -- CAPTURA MENSAGENS DE ERRO -- | |
| 583 | + | ---------------------------------------------------------------------- | |
| 584 | + | function onTextMessage(mode, text) | |
| 585 | + | local msgLower = text:lower() | |
| 586 | + | if msgLower:find("this action is not permitted in a protection zone") or | |
| 587 | + | msgLower:find("you can not cast that here") or | |
| 588 | + | msgLower:find("sorry, not possible") or | |
| 589 | + | msgLower:find("não pode usar isso aqui") or | |
| 590 | + | msgLower:find("you can only use it on creatures") then | |
| 591 | + | revertCooldown(lastUsedSpell) | |
| 592 | + | lastUsedSpell = nil | |
| 593 | + | end | |
| 594 | + | end | |
| 595 | + | ||
| 596 | + | function onTalk(name, level, mode, text, channelId, pos) | |
| 597 | + | local msgLower = text:lower() | |
| 598 | + | if msgLower:find("this action is not permitted in a protection zone") or | |
| 599 | + | msgLower:find("you can not cast that here") or | |
| 600 | + | msgLower:find("sorry, not possible") or | |
| 601 | + | msgLower:find("não pode usar isso aqui ou sem alvo") then | |
| 602 | + | revertCooldown(lastUsedSpell) | |
| 603 | + | lastUsedSpell = nil | |
| 604 | + | end | |
| 605 | + | end | |
| 606 | + | ||
| 607 | + | ---------------------------------------------------------------------- | |
| 608 | + | -- OFFLINE E CRIAÇÃO DA SPELLBAR -- | |
| 609 | + | ---------------------------------------------------------------------- | |
| 610 | + | function offline() | |
| 611 | + | -- Salva cooldowns antes de destruir a janela | |
| 612 | + | saveCooldowns() | |
| 613 | + | ||
| 614 | + | spellBarWindow:hide() | |
| 615 | + | for i = 1, 10 do | |
| 616 | + | local slot = spellBarWindow:recursiveGetChildById('slot-'..i) | |
| 617 | + | if slot ~= nil then | |
| 618 | + | slot:destroy() | |
| 619 | + | end | |
| 620 | + | end | |
| 621 | + | end | |
| 622 | + | ||
| 623 | + | function createSpellBar(buffer) | |
| 624 | + | vocation = tonumber(buffer) | |
| 625 | + | createSpellsIcons() | |
| 626 | + | relayout() | |
| 627 | + | if isBarEnabled() then | |
| 628 | + | spellBarWindow:show() | |
| 629 | + | end | |
| 630 | + | ||
| 631 | + | -- Ao criar a spellbar, carregamos os cooldowns | |
| 632 | + | loadCooldowns() | |
| 633 | + | onManaChange(g_game.getLocalPlayer(), g_game.getLocalPlayer():getMana(), g_game.getLocalPlayer():getMaxMana()) | |
| 634 | + | end | |
| 635 | + | ||
| 636 | + | function onGameStart() | |
| 637 | + | scheduleEvent(function() | |
| 638 | + | g_game.getProtocolGame():sendExtendedOpcode(193, 'refresh') | |
| 639 | + | -- Carrega cooldowns após o login | |
| 640 | + | loadCooldowns() | |
| 641 | + | end, 10) | |
| 642 | + | end | |
| 643 | + | ||
| 644 | + | ---------------------------------------------------------------------- | |
| 645 | + | -- FUNÇÕES DE REVERTER COOLDOWN E TRATAR ERROS -- | |
| 646 | + | ---------------------------------------------------------------------- | |
| 647 | + | function revertCooldown(spellName) | |
| 648 | + | if not spellName then return end | |
| 649 | + | local player = g_game.getLocalPlayer() | |
| 650 | + | if not player then return end | |
| 651 | + | ||
| 652 | + | local playerName = getPlayerNameForStorage() | |
| 653 | + | if not playerName then return end | |
| 654 | + | ||
| 655 | + | if spellCooldowns[playerName] and spellCooldowns[playerName][spellName] then | |
| 656 | + | spellCooldowns[playerName][spellName] = nil | |
| 657 | + | ||
| 658 | + | -- Reseta a barra de progresso | |
| 659 | + | local progress = spellBarWindow:recursiveGetChildById('progress-'..spellName) | |
| 660 | + | if progress then | |
| 661 | + | progress:setPercent(100) | |
| 662 | + | progress:setText('') | |
| 663 | + | end | |
| 664 | + | ||
| 665 | + | modules.game_textmessage.displayFailureMessage("não pode usar isso aqui ou sem alvo.") | |
| 666 | + | end | |
| 667 | + | end | |
| 668 | + | ||
| 669 | + | ---------------------------------------------------------------------- | |
| 670 | + | -- MUDANÇA DE LEVEL/MANA E SPELLS ICÔNICOS -- | |
| 671 | + | ---------------------------------------------------------------------- | |
| 672 | + | function onLevelChange(localPlayer, value, percent) | |
| 673 | + | if spelllist[vocation] then -- Verificar si spelllist[vocation] existe | |
| 674 | + | for _, list in pairs(spelllist[vocation]) do | |
| 675 | + | local spellWidget = spellBarWindow:recursiveGetChildById('spell-'..list.name:lower()) | |
| 676 | + | if spellWidget then | |
| 677 | + | local progress = spellBarWindow:recursiveGetChildById('progress-'..list.name:lower()) | |
| 678 | + | if localPlayer:getMana() >= list.mana then | |
| 679 | + | if progress:getText() == '' then | |
| 680 | + | if localPlayer:getLevel() < list.level then | |
| 681 | + | progress:setImageSource('img/lockedicon') | |
| 682 | + | progress:setPercent(0) | |
| 683 | + | else | |
| 684 | + | progress:setImageSource() | |
| 685 | + | progress:setPercent(100) | |
| 686 | + | end | |
| 687 | + | end | |
| 688 | + | end | |
| 689 | + | end | |
| 690 | + | end | |
| 691 | + | end | |
| 692 | + | end | |
| 693 | + | ||
| 694 | + | function onManaChange(localPlayer, mana, maxMana) | |
| 695 | + | if spelllist[vocation] then -- Verificar si spelllist[vocation] existe | |
| 696 | + | for _, list in pairs(spelllist[vocation]) do | |
| 697 | + | local spellWidget = spellBarWindow:recursiveGetChildById('spell-'..list.name:lower()) | |
| 698 | + | if not spellWidget then return end | |
| 699 | + | local progress = spellBarWindow:recursiveGetChildById('progress-'..list.name:lower()) | |
| 700 | + | if localPlayer:getLevel() >= list.level then | |
| 701 | + | if progress:getText() == '' then | |
| 702 | + | if localPlayer:getMana() < list.mana then | |
| 703 | + | progress:setPercent(0) | |
| 704 | + | else | |
| 705 | + | progress:setPercent(100) | |
| 706 | + | end | |
| 707 | + | end | |
| 708 | + | end | |
| 709 | + | end | |
| 710 | + | end | |
| 711 | + | end | |
| 712 | + | ||
| 713 | + | function createSpellsIcons() | |
| 714 | + | if not g_game.getLocalPlayer() then return end | |
| 715 | + | ||
| 716 | + | if not spelllist[vocation] or type(spelllist[vocation]) ~= "table" then | |
| 717 | + | return | |
| 718 | + | end | |
| 719 | + | ||
| 720 | + | local spells_icon = {} | |
| 721 | + | for _, list in pairs(spelllist[vocation]) do | |
| 722 | + | table.insert(spells_icon, { | |
| 723 | + | name = list.name, | |
| 724 | + | exhaustion = list.exhaustion, | |
| 725 | + | globalCooldown = list.globalCooldown, | |
| 726 | + | icon = list.icon, | |
| 727 | + | level = list.level, | |
| 728 | + | mana = list.mana, | |
| 729 | + | key = list.key, | |
| 730 | + | desc = list.desc | |
| 731 | + | }) | |
| 732 | + | end | |
| 733 | + | ||
| 734 | + | table.sort(spells_icon, function(a, b) return a.level < b.level end) | |
| 735 | + | ||
| 736 | + | -- the server can send the spell list again (refresh): don't stack a second set of slots | |
| 737 | + | for i = 1, SLOT_COUNT do | |
| 738 | + | local oldSlot = spellBarWindow:getChildById('slot-'..i) | |
| 739 | + | if oldSlot then | |
| 740 | + | oldSlot:destroy() | |
| 741 | + | end | |
| 742 | + | end | |
| 743 | + | ||
| 744 | + | -- positions are set by relayout() | |
| 745 | + | for i = 1, SLOT_COUNT do | |
| 746 | + | local slotSpell = g_ui.createWidget('SlotSpell', spellBarWindow) | |
| 747 | + | slotSpell:setId('slot-'..i) | |
| 748 | + | ||
| 749 | + | local spell = spells_icon[i] | |
| 750 | + | if spell then | |
| 751 | + | local icon = slotSpell:getChildById('spellButton') | |
| 752 | + | icon:setId('spell-'..spell.name:lower()) | |
| 753 | + | icon:setTooltip('\nEnergy: '..spell.mana..'\nExhaustion: '..spell.exhaustion..'\nDescription: '..spell.desc) | |
| 754 | + | icon.exhaustion = spell.exhaustion | |
| 755 | + | icon:setImageSource('img/vocations/'..spell.icon) | |
| 756 | + | icon.lvl = spell.level | |
| 757 | + | icon.mana = spell.mana | |
| 758 | + | icon.nowexausted = os.time() | |
| 759 | + | ||
| 760 | + | icon.onMousePress = function(widget, mousePos, mouseButton) | |
| 761 | + | if mouseButton == MouseLeftButton or mouseButton == MouseRightButton then | |
| 762 | + | useSpell(spell.name:lower()) | |
| 763 | + | end | |
| 764 | + | return true | |
| 765 | + | end | |
| 766 | + | ||
| 767 | + | local savedKey = hotkeys[spell.name:lower()] | |
| 768 | + | if savedKey then | |
| 769 | + | icon.key = g_keyboard.bindKeyPress(savedKey, function() useSpell(spell.name:lower()) end, modules.game_interface.getRootPanel()) | |
| 770 | + | icon.keypress = savedKey | |
| 771 | + | else | |
| 772 | + | icon.key = g_keyboard.bindKeyPress(spell.key, function() useSpell(spell.name:lower()) end, modules.game_interface.getRootPanel()) | |
| 773 | + | icon.keypress = spell.key | |
| 774 | + | end | |
| 775 | + | ||
| 776 | + | local progress = slotSpell:getChildById('spellProgress') | |
| 777 | + | progress:setId('progress-'..spell.name:lower()) | |
| 778 | + | progress:setText('') | |
| 779 | + | progress:setPercent(100) | |
| 780 | + | ||
| 781 | + | if g_game.getLocalPlayer():getLevel() < spell.level then | |
| 782 | + | progress:setImageSource('img/lockedicon') | |
| 783 | + | progress:setPercent(0) | |
| 784 | + | end | |
| 785 | + | if g_game.getLocalPlayer():getMana() < spell.mana then | |
| 786 | + | progress:setPercent(0) | |
| 787 | + | end | |
| 788 | + | end | |
| 789 | + | ||
| 790 | + | local label = slotSpell:getChildById('spellHotkey') | |
| 791 | + | label:setId('htk-'..i) | |
| 792 | + | label:setText(i < 10 and tostring(i) or "0") | |
| 793 | + | end | |
| 794 | + | end | |
| 795 | + | ||
| 796 | + | ---------------------------------------------------------------------- | |
| 797 | + | -- CHECAR ÁREA PROTEGIDA (OPCIONAL) -- | |
| 798 | + | ---------------------------------------------------------------------- | |
| 799 | + | function canCastSpell(spellData) | |
| 800 | + | local player = g_game.getLocalPlayer() | |
| 801 | + | if player and type(player.isInProtectedArea) == "function" then | |
| 802 | + | if player:isInProtectedArea() then | |
| 803 | + | return false | |
| 804 | + | end | |
| 805 | + | end | |
| 806 | + | return true | |
| 807 | + | end | |
| 808 | + | ||
| 809 | + | ---------------------------------------------------------------------- | |
| 810 | + | -- USO DE SPELL -- | |
| 811 | + | ---------------------------------------------------------------------- | |
| 812 | + | function useSpell(getspell) | |
| 813 | + | if not g_game.getLocalPlayer() then return end | |
| 814 | + | local now = os.time() | |
| 815 | + | if now < globalCooldownEnd then | |
| 816 | + | modules.game_textmessage.displayFailureMessage("Aguarde " .. (globalCooldownEnd - now) .. "s para usar outra magia.") | |
| 817 | + | return false | |
| 818 | + | end | |
| 819 | + | ||
| 820 | + | local spellWidget = spellBarWindow:recursiveGetChildById('spell-'..getspell) | |
| 821 | + | local progress = spellBarWindow:recursiveGetChildById('progress-'..getspell) | |
| 822 | + | if not spellWidget then return end | |
| 823 | + | if progress:getText() ~= '' then return end | |
| 824 | + | if progress:getPercent() < 100 then return end | |
| 825 | + | ||
| 826 | + | local spellData = getSpellByLowerName(vocation, getspell) | |
| 827 | + | if spellData then | |
| 828 | + | -- Define o tempo de bloqueio específico para este feitiço (em ms) ou usa 300ms como padrão | |
| 829 | + | local blockTime = spellData.movementBlockTime or 300 | |
| 830 | + | blockMovement() | |
| 831 | + | scheduleEvent(function() unblockMovement() end, blockTime) | |
| 832 | + | ||
| 833 | + | local playerName = getPlayerNameForStorage() | |
| 834 | + | if not playerName then return end | |
| 835 | + | ||
| 836 | + | if not spellCooldowns[playerName] then | |
| 837 | + | spellCooldowns[playerName] = {} | |
| 838 | + | end | |
| 839 | + | ||
| 840 | + | if spellCooldowns[playerName][getspell] then | |
| 841 | + | local remainingTime = spellCooldowns[playerName][getspell] - now | |
| 842 | + | if remainingTime > 0 then | |
| 843 | + | modules.game_textmessage.displayFailureMessage("Aguarde ["..remainingTime.."s] para usar esta magia novamente.") | |
| 844 | + | return false | |
| 845 | + | end | |
| 846 | + | end | |
| 847 | + | ||
| 848 | + | lastUsedSpell = getspell | |
| 849 | + | ||
| 850 | + | local individualCooldown = math.max(spellData.exhaustion, 1) | |
| 851 | + | spellCooldowns[playerName][getspell] = now + individualCooldown | |
| 852 | + | ||
| 853 | + | local gcool = spellData.globalCooldown or 1 | |
| 854 | + | globalCooldownEnd = now + gcool | |
| 855 | + | ||
| 856 | + | -- Verificar si spelllist[vocation] existe antes de iterarlo | |
| 857 | + | if spelllist[vocation] then | |
| 858 | + | for _, spell in pairs(spelllist[vocation]) do | |
| 859 | + | local lowerSpellName = spell.name:lower() | |
| 860 | + | if not spellCooldowns[playerName][lowerSpellName] or spellCooldowns[playerName][lowerSpellName] < globalCooldownEnd then | |
| 861 | + | spellCooldowns[playerName][lowerSpellName] = globalCooldownEnd | |
| 862 | + | end | |
| 863 | + | end | |
| 864 | + | end | |
| 865 | + | ||
| 866 | + | g_game.talk(spellData.name) | |
| 867 | + | startDownDelay(getspell) | |
| 868 | + | end | |
| 869 | + | end | |
| 870 | + | ||
| 871 | + | ---------------------------------------------------------------------- | |
| 872 | + | -- CONTAGEM REGRESSIVA -- | |
| 873 | + | ---------------------------------------------------------------------- | |
| 874 | + | function startDownDelay(getspell) | |
| 875 | + | local spellWidget = spellBarWindow:recursiveGetChildById('spell-'..getspell) | |
| 876 | + | local progress = spellBarWindow:recursiveGetChildById('progress-'..getspell) | |
| 877 | + | if not spellWidget then return end | |
| 878 | + | progress:setPercent(0) | |
| 879 | + | ||
| 880 | + | local spellData = getSpellByLowerName(vocation, getspell) | |
| 881 | + | if not spellData then return end | |
| 882 | + | ||
| 883 | + | local playerName = getPlayerNameForStorage() | |
| 884 | + | if not playerName then return end | |
| 885 | + | ||
| 886 | + | spellWidget.nowexausted = os.time() + spellData.exhaustion | |
| 887 | + | ||
| 888 | + | scheduleEvent(function() spellReload(getspell) end, 100) | |
| 889 | + | end | |
| 890 | + | ||
| 891 | + | function spellReload(getspell) | |
| 892 | + | local player = g_game.getLocalPlayer() | |
| 893 | + | if not player then return end | |
| 894 | + | ||
| 895 | + | local spellWidget = spellBarWindow:recursiveGetChildById('spell-'..getspell) | |
| 896 | + | local progress = spellBarWindow:recursiveGetChildById('progress-'..getspell) | |
| 897 | + | if not spellWidget then return end | |
| 898 | + | ||
| 899 | + | local spellData = getSpellByLowerName(vocation, getspell) | |
| 900 | + | if not spellData then return end | |
| 901 | + | ||
| 902 | + | local playerName = getPlayerNameForStorage() | |
| 903 | + | if not playerName then return end | |
| 904 | + | ||
| 905 | + | local exhausted = spellCooldowns[playerName][getspell] | |
| 906 | + | if not exhausted then | |
| 907 | + | progress:setPercent(100) | |
| 908 | + | progress:setText('') | |
| 909 | + | return | |
| 910 | + | end | |
| 911 | + | ||
| 912 | + | if player:getLevel() < spellData.level then | |
| 913 | + | progress:setImageSource('img/lockedicon') | |
| 914 | + | progress:setPercent(0) | |
| 915 | + | progress:setText('') | |
| 916 | + | return | |
| 917 | + | else | |
| 918 | + | local remainingTime = exhausted - os.time() | |
| 919 | + | if remainingTime <= 0 then | |
| 920 | + | progress:setPercent(100) | |
| 921 | + | progress:setText('') | |
| 922 | + | return | |
| 923 | + | end | |
| 924 | + | ||
| 925 | + | local perc = math.ceil((spellData.exhaustion - remainingTime) * 100 / spellData.exhaustion) | |
| 926 | + | progress:setPercent(perc) | |
| 927 | + | ||
| 928 | + | if remainingTime > 60 then | |
| 929 | + | local minutos = math.floor(remainingTime / 60) | |
| 930 | + | local segundos = remainingTime % 60 | |
| 931 | + | progress:setText(minutos .. 'm\n' .. segundos .. 's') | |
| 932 | + | else | |
| 933 | + | progress:setText(remainingTime .. 's') | |
| 934 | + | end | |
| 935 | + | end | |
| 936 | + | ||
| 937 | + | scheduleEvent(function() spellReload(getspell) end, 500) | |
| 938 | + | end | |
| 939 | + | ||
| 940 | + | ---------------------------------------------------------------------- | |
| 941 | + | -- MUDAR HOTKEY VIA POPUPMENU -- | |
| 942 | + | ---------------------------------------------------------------------- | |
| 943 | + | function createButtonKey(slot) | |
| 944 | + | local icon = spellBarWindow:recursiveGetChildById('spell-'..slot) | |
| 945 | + | local menu = g_ui.createWidget('PopupMenu') | |
| 946 | + | menu:setGameMenu(true) | |
| 947 | + | menu:addOption(tr('Set Hotkey to this slot'), function() buttonChangeKey() end) | |
| 948 | + | menu:display({x = icon:getPosition().x+5, y = icon:getPosition().y-20}) | |
| 949 | + | clickedSlot = icon | |
| 950 | + | end | |
| 951 | + | ||
| 952 | + | function buttonChangeKey() | |
| 953 | + | slotHotkey = g_ui.createWidget('SlotHotkey', rootWidget) | |
| 954 | + | slotHotkey:grabKeyboard() | |
| 955 | + | comboLabel = slotHotkey:getChildById('comboPreview') | |
| 956 | + | comboLabel.keyCombo = '' | |
| 957 | + | slotHotkey.onKeyDown = hotkeyCapture | |
| 958 | + | end | |
| 959 | + | ||
| 960 | + | function hotkeyCapture(slotHotkey, keyCode, keyboardModifiers) | |
| 961 | + | local keyCombo = determineKeyComboDesc(keyCode, keyboardModifiers) | |
| 962 | + | ||
| 963 | + | if keyCombo:match("^%d+$") then | |
| 964 | + | local num = tonumber(keyCombo) | |
| 965 | + | if num >= 1 and num <= 12 then | |
| 966 | + | keyCombo = "F" .. num | |
| 967 | + | else | |
| 968 | + | g_game.getLocalPlayer():sendCancelMessage("Hotkey inválido! Use apenas números de 1 a 12 ou teclas F1 até F12.") | |
| 969 | + | return true | |
| 970 | + | end | |
| 971 | + | end | |
| 972 | + | ||
| 973 | + | local fNum = keyCombo:match("^F(%d+)$") | |
| 974 | + | if not fNum then | |
| 975 | + | g_game.getLocalPlayer():sendCancelMessage("Hotkey inválido! Use apenas teclas F1 até F12.") | |
| 976 | + | return true | |
| 977 | + | end | |
| 978 | + | ||
| 979 | + | local num = tonumber(fNum) | |
| 980 | + | if not (num >= 1 and num <= 12) then | |
| 981 | + | g_game.getLocalPlayer():sendCancelMessage("Hotkey inválido! Use apenas teclas F1 até F12.") | |
| 982 | + | return true | |
| 983 | + | end | |
| 984 | + | ||
| 985 | + | comboPreview = slotHotkey:getChildById('comboPreview') | |
| 986 | + | comboPreview:setText(tr('Current hotkey to add: %s', keyCombo)) | |
| 987 | + | comboPreview.keyCombo = keyCombo | |
| 988 | + | comboPreview:resizeToText() | |
| 989 | + | slotHotkey:getChildById('addButton'):enable() | |
| 990 | + | newKey = keyCombo | |
| 991 | + | return true | |
| 992 | + | end | |
| 993 | + | ||
| 994 | + | function changeKey() | |
| 995 | + | if clickedSlot ~= nil then | |
| 996 | + | if newKey ~= 'none' then | |
| 997 | + | for _, list in pairs(spelllist[vocation]) do | |
| 998 | + | local spellWidget = spellBarWindow:recursiveGetChildById('spell-'..list.name:lower()) | |
| 999 | + | if spellWidget then | |
| 1000 | + | if spellWidget.keypress == newKey or spellWidget.keypress2 == newKey then | |
| 1001 | + | return true | |
| 1002 | + | end | |
| 1003 | + | end | |
| 1004 | + | end | |
| 1005 | + | ||
| 1006 | + | local id = string.explode(clickedSlot:getId(), '-') | |
| 1007 | + | local spellName = id[2] | |
| 1008 | + | local keypress = clickedSlot.keypress2 | |
| 1009 | + | if keypress ~= 'none' then | |
| 1010 | + | clickedSlot.key2 = g_keyboard.unbindKeyPress(keypress, nil, modules.game_interface.getRootPanel()) | |
| 1011 | + | end | |
| 1012 | + | clickedSlot.key2 = g_keyboard.bindKeyPress(newKey, function() useSpell(spellName) end, modules.game_interface.getRootPanel()) | |
| 1013 | + | clickedSlot.keypress2 = newKey | |
| 1014 | + | ||
| 1015 | + | hotkeys[spellName] = newKey | |
| 1016 | + | saveHotkeys() | |
| 1017 | + | ||
| 1018 | + | clickedSlot = nil | |
| 1019 | + | end | |
| 1020 | + | end | |
| 1021 | + | end | |
| 1022 | + | ||
| 1023 | + | function toggleLock() | |
| 1024 | + | if not spellBarWindow then return end | |
| 1025 | + | ||
| 1026 | + | isLocked = not isLocked -- Alterna o estado | |
| 1027 | + | ||
| 1028 | + | spellBarWindow:setDraggable(not isLocked) -- Ativa/desativa movimento | |
| 1029 | + | ||
| 1030 | + | local lockButton = spellBarWindow:recursiveGetChildById('lockButton') | |
| 1031 | + | if lockButton then | |
| 1032 | + | if isLocked then | |
| 1033 | + | lockButton:setText('??') -- ícone de destravado | |
| 1034 | + | lockButton:setTooltip(tr('Unlock Spell Bar')) | |
| 1035 | + | else | |
| 1036 | + | lockButton:setText('??') -- ícone de travado | |
| 1037 | + | lockButton:setTooltip(tr('Lock Spell Bar')) | |
| 1038 | + | end | |
| 1039 | + | end | |
| 1040 | + | end |
| @@ -0,0 +1,10 @@ | |||
| 1 | + | Module | |
| 2 | + | name: game_spellbar | |
| 3 | + | description: Displays spells in icons | |
| 4 | + | author: ALS | |
| 5 | + | website: none | |
| 6 | + | sandboxed: true | |
| 7 | + | autoload: true | |
| 8 | + | scripts: [ game_spellbar ] | |
| 9 | + | @onLoad: init() | |
| 10 | + | @onUnload: terminate() |
| @@ -0,0 +1,95 @@ | |||
| 1 | + | // Slots are positioned by relayout() in game_spellbar.lua (one row of 10, | |
| 2 | + | // or two rows of 5 when the game window is too narrow). | |
| 3 | + | SlotSpell < UIWidget | |
| 4 | + | anchors.top: parent.top | |
| 5 | + | anchors.left: parent.left | |
| 6 | + | size: 36 36 | |
| 7 | + | image-source: img/slot | |
| 8 | + | ||
| 9 | + | UIButton | |
| 10 | + | id: spellButton | |
| 11 | + | anchors.top: parent.top | |
| 12 | + | anchors.left: parent.left | |
| 13 | + | margin: 2 0 0 2 | |
| 14 | + | size: 32 32 | |
| 15 | + | focusable: false | |
| 16 | + | ||
| 17 | + | UIProgressRect | |
| 18 | + | id: spellProgress | |
| 19 | + | anchors.top: parent.top | |
| 20 | + | anchors.left: parent.left | |
| 21 | + | margin: 2 0 0 2 | |
| 22 | + | size: 32 32 | |
| 23 | + | phantom: true | |
| 24 | + | focusable: false | |
| 25 | + | font: verdana-11px-rounded | |
| 26 | + | percent: 100 | |
| 27 | + | color: white | |
| 28 | + | background: #000000AA | |
| 29 | + | ||
| 30 | + | UIWidget | |
| 31 | + | id: spellHotkey | |
| 32 | + | anchors.top: parent.top | |
| 33 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 34 | + | margin: 30 0 0 0 | |
| 35 | + | image-source: img/htknum | |
| 36 | + | ||
| 37 | + | SlotHotkey < MainWindow | |
| 38 | + | id: slotHotkey | |
| 39 | + | !text: tr('Change Hotkey') | |
| 40 | + | size: 360 150 | |
| 41 | + | @onEscape: self:destroy() | |
| 42 | + | ||
| 43 | + | Label | |
| 44 | + | !text: tr('Please, press the key you wish to change onto') | |
| 45 | + | anchors.left: parent.left | |
| 46 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 47 | + | anchors.top: parent.top | |
| 48 | + | text-auto-resize: true | |
| 49 | + | text-align: left | |
| 50 | + | ||
| 51 | + | Label | |
| 52 | + | id: comboPreview | |
| 53 | + | !text: tr('Current hotkey to change: %s', 'none') | |
| 54 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 55 | + | anchors.top: prev.bottom | |
| 56 | + | margin-top: 10 | |
| 57 | + | text-auto-resize: true | |
| 58 | + | ||
| 59 | + | HorizontalSeparator | |
| 60 | + | id: separator | |
| 61 | + | anchors.left: parent.left | |
| 62 | + | anchors.right: parent.right | |
| 63 | + | anchors.bottom: next.top | |
| 64 | + | margin-bottom: 10 | |
| 65 | + | ||
| 66 | + | Button | |
| 67 | + | id: addButton | |
| 68 | + | !text: tr('Change') | |
| 69 | + | width: 64 | |
| 70 | + | anchors.right: next.left | |
| 71 | + | anchors.bottom: parent.bottom | |
| 72 | + | margin-right: 10 | |
| 73 | + | @onClick: modules.game_spellbar.changeKey() self:getParent():destroy() | |
| 74 | + | ||
| 75 | + | Button | |
| 76 | + | id: cancelButton | |
| 77 | + | !text: tr('Close') | |
| 78 | + | width: 64 | |
| 79 | + | anchors.right: parent.right | |
| 80 | + | anchors.bottom: parent.bottom | |
| 81 | + | @onClick: self:getParent():destroy() | |
| 82 | + | ||
| 83 | + | // Size and position are set by relayout()/applyPosition() in game_spellbar.lua: | |
| 84 | + | // it stays anchored to the bottom-center of the game screen (plus the offset | |
| 85 | + | // the player dragged it to), so it follows window resizes. | |
| 86 | + | UIWindow | |
| 87 | + | id: spellBarWindow | |
| 88 | + | size: 450 45 | |
| 89 | + | anchors.bottom: parent.bottom | |
| 90 | + | anchors.horizontalCenter: parent.horizontalCenter | |
| 91 | + | margin-bottom: 90 | |
| 92 | + | draggable: true | |
| 93 | + | resizable: false | |
| 94 | + | focusable: false | |
| 95 | + | visible: false |