diff --git a/src/Engine/CharEngine.js b/src/Engine/CharEngine.js index 3a44778..037e26b 100644 --- a/src/Engine/CharEngine.js +++ b/src/Engine/CharEngine.js @@ -131,6 +131,10 @@ define(function( require ) Network.setPing(function(){ Network.sendPacket(ping); }); + + Session.Playing = false; + //Session.hasCart = false; + UIManager.getComponent('WinLoading').remove(); diff --git a/src/Engine/LoginEngine.js b/src/Engine/LoginEngine.js index 9f9ebc0..f5d05f6 100644 --- a/src/Engine/LoginEngine.js +++ b/src/Engine/LoginEngine.js @@ -62,6 +62,7 @@ define(function( require ) */ var _loginID = ''; + var _rophservers = []; /** * Init Game diff --git a/src/Engine/MapEngine.js b/src/Engine/MapEngine.js index 8a73d1e..8965497 100644 --- a/src/Engine/MapEngine.js +++ b/src/Engine/MapEngine.js @@ -42,6 +42,9 @@ define(function( require ) var BasicInfo = require('UI/Components/BasicInfo/BasicInfo'); var WinStats = require('UI/Components/WinStats/WinStats'); var Inventory = require('UI/Components/Inventory/Inventory'); + var CartItems = require('UI/Components/CartItems/CartItems'); + var Vending = require('UI/Components/Vending/Vending'); + var ChangeCart = require('UI/Components/ChangeCart/ChangeCart'); var ShortCut = require('UI/Components/ShortCut/ShortCut'); var Equipment = require('UI/Components/Equipment/Equipment'); var StatusIcons = require('UI/Components/StatusIcons/StatusIcons'); @@ -109,14 +112,21 @@ define(function( require ) Session.Character.GID = fp.readLong(); } }); - + + var hbt = new PACKET.CZ.HBT(); + + var is_sec_hbt = Configs.get('sec_HBT', null); + // Ping var ping = new PACKET.CZ.REQUEST_TIME(); var startTick = Date.now(); Network.setPing(function(){ + if(is_sec_hbt)Network.sendPacket(hbt); ping.clientTime = Date.now() - startTick; Network.sendPacket(ping); }); + + Session.Playing = true; }, true); // Do not hook multiple time @@ -165,6 +175,9 @@ define(function( require ) MiniMap.prepare(); Escape.prepare(); Inventory.prepare(); + CartItems.prepare(); + Vending.prepare(); + ChangeCart.prepare(); Equipment.prepare(); ShortCut.prepare(); ChatRoomCreate.prepare(); @@ -199,6 +212,7 @@ define(function( require ) function onPong( pkt ) { //pkt.time + } @@ -288,6 +302,9 @@ define(function( require ) BasicInfo.append(); Escape.append(); Inventory.append(); + CartItems.append(); + Vending.append(); + ChangeCart.append(); Equipment.append(); StatusIcons.append(); ShortCut.append(); diff --git a/src/Engine/MapEngine/Entity.js b/src/Engine/MapEngine/Entity.js index 0cef6b0..2e72a6c 100644 --- a/src/Engine/MapEngine/Entity.js +++ b/src/Engine/MapEngine/Entity.js @@ -802,6 +802,7 @@ define(function( require ) // Show cart (in future) case StatusConst.ON_PUSH_CART: + //console.log("Entity on PushCart"); if (entity === Session.Entity) { Session.hasCart = pkt.state; } diff --git a/src/Engine/MapEngine/Item.js b/src/Engine/MapEngine/Item.js index a2b32c1..94b53e3 100644 --- a/src/Engine/MapEngine/Item.js +++ b/src/Engine/MapEngine/Item.js @@ -27,6 +27,7 @@ define(function( require ) var ItemObtain = require('UI/Components/ItemObtain/ItemObtain'); var ItemSelection = require('UI/Components/ItemSelection/ItemSelection'); var Inventory = require('UI/Components/Inventory/Inventory'); + var CartItems = require('UI/Components/CartItems/CartItems'); var Equipment = require('UI/Components/Equipment/Equipment'); @@ -338,7 +339,62 @@ define(function( require ) debugger; } + + /** + * Generic function to add items to cart + * + * @param {object} pkt - PACKET.ZC.CART_EQUIPMENT_ITEMLIST3 + */ + function onCartSetList( pkt ) + { + CartItems.setItems( pkt.itemInfo || pkt.ItemInfo ); + } + + /** + * Generic function to set cart info + * + * @param {object} pkt - PACKET.ZC.NOTIFY_CARTITEM_COUNTINFO + */ + function onCartSetInfo( pkt ) + { + CartItems.setCartInfo( pkt.curCount, pkt.maxCount, pkt.curWeight, pkt.maxWeight ); + } + + function onCartRemoveItem( pkt ) + { + CartItems.removeItem( pkt.index, pkt.count); + } + + CartItems.reqRemoveItem = function ReqRemoveItem( index, count ) + { + if (count <= 0) { + return; + } + + var pkt = new PACKET.CZ.MOVE_ITEM_FROM_CART_TO_BODY(); + pkt.index = index; + pkt.count = count; + Network.sendPacket( pkt ); + }; + + Inventory.reqMoveItemToCart = function reqMoveItemToCart( index, count ) + { + if (count <= 0) { + return; + } + var pkt = new PACKET.CZ.MOVE_ITEM_FROM_BODY_TO_CART(); + pkt.index = index; + pkt.count = count; + Network.sendPacket( pkt ); + }; + + + function onCartItemAdded( pkt ) + { + CartItems.addItem(pkt); + } + /** * Initialize @@ -358,6 +414,9 @@ define(function( require ) Network.hookPacket( PACKET.ZC.NORMAL_ITEMLIST2, onInventorySetList ); Network.hookPacket( PACKET.ZC.NORMAL_ITEMLIST3, onInventorySetList ); Network.hookPacket( PACKET.ZC.NORMAL_ITEMLIST4, onInventorySetList ); + Network.hookPacket( PACKET.ZC.CART_NORMAL_ITEMLIST3, onCartSetList ); + Network.hookPacket( PACKET.ZC.CART_EQUIPMENT_ITEMLIST3, onCartSetList ); + Network.hookPacket( PACKET.ZC.NOTIFY_CARTITEM_COUNTINFO, onCartSetInfo ); Network.hookPacket( PACKET.ZC.EQUIPMENT_ITEMLIST, onInventorySetList ); Network.hookPacket( PACKET.ZC.EQUIPMENT_ITEMLIST2, onInventorySetList ); Network.hookPacket( PACKET.ZC.EQUIPMENT_ITEMLIST3, onInventorySetList ); @@ -369,6 +428,7 @@ define(function( require ) Network.hookPacket( PACKET.ZC.REQ_WEAR_EQUIP_ACK2, onItemEquip ); Network.hookPacket( PACKET.ZC.ACK_WEAR_EQUIP_V5, onItemEquip ); Network.hookPacket( PACKET.ZC.DELETE_ITEM_FROM_BODY, onIventoryRemoveItem ); + Network.hookPacket( PACKET.ZC.DELETE_ITEM_FROM_CART, onCartRemoveItem ); Network.hookPacket( PACKET.ZC.USE_ITEM_ACK, onItemUseAnswer ); Network.hookPacket( PACKET.ZC.USE_ITEM_ACK2, onItemUseAnswer ); Network.hookPacket( PACKET.ZC.CONFIG_NOTIFY, onConfigEquip ); @@ -376,5 +436,7 @@ define(function( require ) Network.hookPacket( PACKET.ZC.ITEMCOMPOSITION_LIST, onItemCompositionList ); Network.hookPacket( PACKET.ZC.ACK_ITEMCOMPOSITION, onItemCompositionResult ); Network.hookPacket( PACKET.ZC.ACK_ITEMREFINING, onRefineResult); + Network.hookPacket( PACKET.ZC.ADD_ITEM_TO_CART, onCartItemAdded ); + Network.hookPacket( PACKET.ZC.ADD_ITEM_TO_CART2, onCartItemAdded ); }; }); \ No newline at end of file diff --git a/src/Engine/MapEngine/Main.js b/src/Engine/MapEngine/Main.js index f38b9c7..a301325 100644 --- a/src/Engine/MapEngine/Main.js +++ b/src/Engine/MapEngine/Main.js @@ -30,6 +30,7 @@ define(function( require ) var WinStats = require('UI/Components/WinStats/WinStats'); var Announce = require('UI/Components/Announce/Announce'); var Equipment = require('UI/Components/Equipment/Equipment'); + var ChangeCart = require('UI/Components/ChangeCart/ChangeCart'); var SkillList = require('UI/Components/SkillList/SkillList'); var PartyUI = require('UI/Components/PartyFriends/PartyFriends'); @@ -277,6 +278,7 @@ define(function( require ) case StatusProperty.CLEVEL: BasicInfo.update('blvl', amount); Equipment.onLevelUp(); + ChangeCart.onLevelUp(amount); break; case StatusProperty.SKPOINT: diff --git a/src/Engine/MapEngine/Skill.js b/src/Engine/MapEngine/Skill.js index 48cacd6..ebd7d31 100644 --- a/src/Engine/MapEngine/Skill.js +++ b/src/Engine/MapEngine/Skill.js @@ -32,6 +32,7 @@ define(function( require ) var ItemSelection = require('UI/Components/ItemSelection/ItemSelection'); var Inventory = require('UI/Components/Inventory/Inventory'); var NpcMenu = require('UI/Components/NpcMenu/NpcMenu'); + var getModule = require; /** @@ -447,11 +448,25 @@ define(function( require ) if (!count) { return; } - - pkt = new PACKET.CZ.USE_SKILL(); - pkt.SKID = id; - pkt.selectedLevel = level; - pkt.targetID = targetID || Session.Entity.GID; + + + if(id === SkillId.MC_CHANGECART) + { + if(Session.Entity.hasCart == true) + { + getModule('UI/Components/ChangeCart/ChangeCart').onChangeCartSkill(); + } + } + else if(id === SkillId.MC_VENDING) + { + getModule('UI/Components/Vending/Vending').onVendingSkill(); + return; + } + + pkt = new PACKET.CZ.USE_SKILL(); + pkt.SKID = id; + pkt.selectedLevel = level; + pkt.targetID = targetID || Session.Entity.GID; // In range if (count < 2 || target === entity) { diff --git a/src/Engine/MapEngine/Storage.js b/src/Engine/MapEngine/Storage.js index 215b2dc..34006e9 100644 --- a/src/Engine/MapEngine/Storage.js +++ b/src/Engine/MapEngine/Storage.js @@ -115,6 +115,19 @@ define(function( require ) pkt.count = count; Network.sendPacket( pkt ); }; + + + Storage.reqAddItemFromCart = function reqAddItemFromCart( index, count ) + { + if (count <= 0) { + return; + } + + var pkt = new PACKET.CZ.MOVE_ITEM_FROM_CART_TO_STORE(); + pkt.index = index; + pkt.count = count; + Network.sendPacket( pkt ); + }; /** @@ -132,6 +145,18 @@ define(function( require ) pkt.count = count; Network.sendPacket( pkt ); }; + + Storage.reqMoveItemToCart = function reqMoveItemToCart( index, count ) + { + if (count <= 0) { + return; + } + + var pkt = new PACKET.CZ.MOVE_ITEM_FROM_STORE_TO_CART(); + pkt.index = index; + pkt.count = count; + Network.sendPacket( pkt ); + }; /** diff --git a/src/Engine/MapEngine/Store.js b/src/Engine/MapEngine/Store.js index 7ae9a2b..7a9702f 100644 --- a/src/Engine/MapEngine/Store.js +++ b/src/Engine/MapEngine/Store.js @@ -16,13 +16,70 @@ define(function( require ) * Load dependencies */ var DB = require('DB/DBManager'); + var Session = require('Engine/SessionStorage'); var Network = require('Network/NetworkManager'); var PACKET = require('Network/PacketStructure'); var EntityManager = require('Renderer/EntityManager'); var NpcStore = require('UI/Components/NpcStore/NpcStore'); + var VendingShop = require('UI/Components/VendingShop/VendingShop'); var ChatBox = require('UI/Components/ChatBox/ChatBox'); + /** + * Received items list to buy from cash npc + * + * @param {object} pkt - PACKET.ZC.ZC_PC_CASH_POINT_ITEMLIST + */ + function onBuyCashList( pkt ) + { + NpcStore.append(); + NpcStore.setType(NpcStore.Type.CASH_SHOP); + NpcStore.setList(pkt.itemList); + + var entity = Session.Entity; + NpcStore.ui.find('.cashuser .buyer').text( entity ? entity.display.name : ''); + NpcStore.ui.find('.cashuser .cashpoints').text(pkt.KafraPoint); + + NpcStore.onSubmit = function(itemList) // add prompt confirmation first later... + { + var i, count; + var pkt; + + pkt = new PACKET.CZ.PC_BUY_CASH_POINT_ITEM(); + count = itemList.length; + pkt.kafrapts = 0; + + for (i = 0; i < count; ++i) + { + pkt.list.push({ + count: itemList[i].count, + ITID: itemList[i].ITID + }); + //pkt.kafrapts += (itemList[i].discountprice || itemList[i].price) * itemList[i].count; + } + + Network.sendPacket(pkt); + }; + } + + + /** + * Received items list to buy from cash npc + * + * @param {object} pkt - PACKET.ZC.ZC_PC_CASH_POINT_ITEMLIST + */ + function onBuyVendingList( pkt ) + { + VendingShop.append(); + VendingShop.setItems(pkt.itemList); + } + + function onDeleteVendingItem( pkt ) + { + VendingShop.removeItem(pkt.index,pkt.count); + } + + /** * Received items list to buy from npc * @@ -72,6 +129,28 @@ define(function( require ) default: ChatBox.addText( DB.getMessage(57), ChatBox.TYPE.ERROR); break; // deal failed } } + + /** + * Received purchased informations + * + * @param {object} pkt - PACKET_ZC_PC_CASH_POINT_UPDATE + */ + + function onBuyCashResult( pkt ) + { + NpcStore.remove(); + + switch (pkt.Error) { + case 0: ChatBox.addText( DB.getMessage(54), ChatBox.TYPE.BLUE); break; // success + case 1: ChatBox.addText( DB.getMessage(1227), ChatBox.TYPE.ERROR); break; // zeny + case 2: ChatBox.addText( DB.getMessage(1228), ChatBox.TYPE.ERROR); break; // overweight + case 4: ChatBox.addText( DB.getMessage(1229), ChatBox.TYPE.ERROR); break; // out of stock + case 5: ChatBox.addText( DB.getMessage(1230), ChatBox.TYPE.ERROR); break; // trade + case 6: ChatBox.addText( DB.getMessage(1254), ChatBox.TYPE.ERROR); break; + case 7: ChatBox.addText( DB.getMessage(1813), ChatBox.TYPE.ERROR); break; // no sale information + default: ChatBox.addText( DB.getMessage(1814), ChatBox.TYPE.ERROR); break; // deal failed + } + } /** @@ -174,6 +253,8 @@ define(function( require ) */ return function MainEngine() { + Network.hookPacket( PACKET.ZC.PC_CASH_POINT_ITEMLIST, onBuyCashList ); + Network.hookPacket( PACKET.ZC.PC_CASH_POINT_UPDATE, onBuyCashResult ); Network.hookPacket( PACKET.ZC.PC_PURCHASE_ITEMLIST, onBuyList ); Network.hookPacket( PACKET.ZC.PC_PURCHASE_RESULT, onBuyResult ); Network.hookPacket( PACKET.ZC.PC_SELL_ITEMLIST, onSellList ); @@ -181,5 +262,7 @@ define(function( require ) Network.hookPacket( PACKET.ZC.PC_PURCHASE_ITEMLIST_FROMMC, onVendingStoreList ); Network.hookPacket( PACKET.ZC.PC_PURCHASE_ITEMLIST_FROMMC2, onVendingStoreList ); Network.hookPacket( PACKET.ZC.PC_PURCHASE_RESULT_FROMMC, onBuyResult ); + Network.hookPacket( PACKET.ZC.PC_PURCHASE_MYITEMLIST, onBuyVendingList ); + Network.hookPacket( PACKET.ZC.DELETEITEM_FROM_MCSTORE, onDeleteVendingItem ); }; }); \ No newline at end of file diff --git a/src/Engine/SessionStorage.js b/src/Engine/SessionStorage.js index c7aa965..db1d538 100644 --- a/src/Engine/SessionStorage.js +++ b/src/Engine/SessionStorage.js @@ -40,6 +40,10 @@ define(function() hasGuild: false, guildRight: 0, - isGuildMaster: false + isGuildMaster: false, + + Playing: false, +// hasCart: false, +// CartNum: 0 }; }); \ No newline at end of file diff --git a/src/Network/PacketStructure.js b/src/Network/PacketStructure.js index 554381f..d27377f 100644 --- a/src/Network/PacketStructure.js +++ b/src/Network/PacketStructure.js @@ -30,6 +30,7 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK // * auto-generated * + // 0x64 PACKET.CA.LOGIN = function PACKET_CA_LOGIN() { this.Version = 0; @@ -184,6 +185,16 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK }; + // 0x844 + PACKET.CZ.HBT = function PACKET_CZ_HBT() {}; + PACKET.CZ.HBT.prototype.build = function() { + var pkt_len = 2; + var pkt_buf = new BinaryWriter(pkt_len); + pkt_buf.writeShort(0x0844); + return pkt_buf; + }; + + // 0x82 PACKET.CZ.REQUEST_QUIT = function PACKET_CZ_REQUEST_QUIT() {}; @@ -1937,7 +1948,7 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK for (i = 0, count = this.storeList.length; i < count; ++i) { pkt_buf.writeShort(this.storeList[i].index); pkt_buf.writeShort(this.storeList[i].count); - pkt_buf.writeLong(this.storeList[i].Price); + pkt_buf.writeLong(this.storeList[i].price); } return pkt_buf; @@ -2155,6 +2166,29 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK return pkt_buf; }; + /*// 0x01b2 + PACKET.CZ.REQ_OPEN_VENDING = function PACKET_CZ_REQ_REQ_OPEN_VENDING() { + this.shop_name = ''; + this.result = 0; + this.itemlist = []; + }; + PACKET.CZ.REQ_OPEN_VENDING.prototype.build = function() { + var i = 0; + var ver = this.getPacketVersion(); + var pkt_len = 2+2+80+1+itemlist.length*8; + var pkt_buf = new BinaryWriter(len); + pkt_buf.writeShort(ver[1]); + pkt_buf.writeShort(pkt_len); + pkt_buf.writeString(this.shop_name,80); + pkt_buf.writeChar(this.result); + for(i=0; i < this.itemlist.length; i += 1) + { + pkt_buf.writeShort(this.itemlist[i].index); + pkt_buf.writeShort(this.itemlist[i].amount); + pkt_buf.writeLong(this.itemlist[i].price); + } + return pkt_buf; + };*/ // 0x1df PACKET.CZ.REQ_ACCOUNTNAME = function PACKET_CZ_REQ_ACCOUNTNAME() { @@ -3172,43 +3206,31 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK // 0x288 + PACKET.CZ.PC_BUY_CASH_POINT_ITEM = function PACKET_CZ_PC_BUY_CASH_POINT_ITEM() { this.list = []; this.kafrapts = 0; }; PACKET.CZ.PC_BUY_CASH_POINT_ITEM.prototype.build = function() { var ver = this.getPacketVersion(); - var pkt = new BinaryWriter(ver[2]); - - pkt.writeShort(ver[1]); - - switch (ver[2]) { - case 6: - pkt.view.setUint16(ver[3], this.list[0].id, true); - pkt.view.setInt16(ver[4], this.list[0].count, true); - break; - - case 10: - pkt.view.setUint16(ver[3], this.list[0].id, true); - pkt.view.setInt16(ver[4], this.list[0].count, true); - pkt.view.setInt32(ver[5], this.kafrapts, true); - break; - - case -1: - pkt.writeShort(2 + 2 + 4 + 2 + this.list.length * 4); - pkt.view.setInt32(ver[3], this.kafrapts, true); - pkt.view.setInt16(ver[4], this.list.length, true); - var pos = ver[4] + 2; - var i, count = this.list.length; - - for (i = 0; i < count; ++i) { - pkt.view.setUint16(pos + 0, this.list[i].id, true); - pkt.view.setInt16(pos + 2, this.list[i].count, true); - pos += 4; - } - break; + + var len = 10 + this.list.length * 4; + var pkt = new BinaryWriter(len); + pkt.writeShort(ver[1]); // cmd + pkt.writeShort(len); + pkt.view.setInt32(ver[3], this.kafrapts, true); + pkt.view.setInt16(ver[4], this.list.length, true); + var pos = ver[4] + 2; + var i, count = this.list.length; + + for (i = 0; i < count; ++i) + { + pkt.view.setInt16(pos + 0, this.list[i].count , true); + pkt.view.setUint16(pos + 2, this.list[i].ITID , true); + pos += 4; } + return pkt; }; @@ -8289,7 +8311,8 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK // 0x287 PACKET.ZC.PC_CASH_POINT_ITEMLIST = function PACKET_ZC_PC_CASH_POINT_ITEMLIST(fp, end) { - this.CashPoint = fp.readULong(); + this.KafraPoint = fp.readULong(); + this.CashPoint = fp.readULong(); this.itemList = (function() { var i, count=(end-fp.tell())/11|0, out=new Array(count); for (i = 0; i < count; ++i) { @@ -8307,6 +8330,7 @@ define(['Utils/BinaryWriter', './PacketVerManager'], function(BinaryWriter, PACK // 0x289 PACKET.ZC.PC_CASH_POINT_UPDATE = function PACKET_ZC_PC_CASH_POINT_UPDATE(fp, end) { + this.KafraPoint = fp.readULong(); this.CashPoint = fp.readULong(); this.Error = fp.readShort(); }; diff --git a/src/Network/PacketVersions.js b/src/Network/PacketVersions.js index e935bfc..676a230 100644 --- a/src/Network/PacketVersions.js +++ b/src/Network/PacketVersions.js @@ -493,12 +493,13 @@ define( ['./PacketStructure'], function( PACKET ) //2010-08-03aRagexeRE 20100803: [ [PACKET.CZ.REMOVE_AID_SSO,0x0843,6,2], + //[PACKET.CZ.PC_BUY_CASH_POINT_ITEM,0x0288,-1,2,4,8,10], + [PACKET.CZ.PC_BUY_CASH_POINT_ITEM,0x0288,-1,4,8], ], //2010-11-24aRagexeRE 20101124: [ - [PACKET.CZ.PC_BUY_CASH_POINT_ITEM,0x0288,-1,4,8], [PACKET.CZ.ENTER,0x0436,19,2,6,10,14,18], [PACKET.CZ.REQUEST_MOVE,0x035f,5,2], [PACKET.CZ.REQUEST_TIME,0x0360,6,2], diff --git a/src/Preferences/BattleMode.js b/src/Preferences/BattleMode.js index b957190..d5f1cc3 100644 --- a/src/Preferences/BattleMode.js +++ b/src/Preferences/BattleMode.js @@ -32,6 +32,7 @@ define( ['Core/Preferences', 'Controls/KeyEventHandler'], function( Preferences, // UI defaultKey[ KEYS.C ] = { component:'ChatRoomCreate', cmd:'TOGGLE', alt:true }; defaultKey[ KEYS.E ] = { component:'Inventory', cmd:'TOGGLE', alt:true }; + defaultKey[ KEYS.W ] = { component:'CartItems', cmd:'TOGGLE', alt:true }; defaultKey[ KEYS.G ] = { component:'Guild', cmd:'TOGGLE', alt:true }; defaultKey[ KEYS.J ] = { component:'PetInformations', cmd:'TOGGLE', alt:true }; defaultKey[ KEYS.L ] = { component:'Emoticons', cmd:'TOGGLE', alt:true }; diff --git a/src/Renderer/Entity/Entity.js b/src/Renderer/Entity/Entity.js index 2af99ce..b51d4ff 100644 --- a/src/Renderer/Entity/Entity.js +++ b/src/Renderer/Entity/Entity.js @@ -134,6 +134,8 @@ define( function( require ) Entity.prototype.effectColor = null; Entity.prototype.isAdmin = false; + Entity.prototype.hasCart = false; + Entity.prototype.CartNum = 0; /** diff --git a/src/Renderer/Entity/EntityRender.js b/src/Renderer/Entity/EntityRender.js index 87242ad..7bbb499 100644 --- a/src/Renderer/Entity/EntityRender.js +++ b/src/Renderer/Entity/EntityRender.js @@ -18,12 +18,16 @@ define( function( require ) var glMatrix = require('Utils/gl-matrix'); var Camera = require('Renderer/Camera'); var Client = require('Core/Client'); + var StatusConst = require('DB/Status/StatusState'); var Renderer = require('Renderer/Renderer'); var SpriteRenderer = require('Renderer/SpriteRenderer'); var Ground = require('Renderer/Map/Ground'); var Altitude = require('Renderer/Map/Altitude'); + var Session = require('Engine/SessionStorage'); + var _last_body_dir = 0; + /** * Render an Entity * @@ -227,17 +231,41 @@ define( function( require ) SpriteRenderer.position[2] = Altitude.getCellHeight(this.position[0], this.position[1]); renderElement( this, this.files.shadow, 'shadow', _position, false ); + } - + SpriteRenderer.position.set(this.position); - + + // Shield is behind on some position, seems to be hardcoded by the client if (this.objecttype === Entity.TYPE_PC && this.shield && behind) { renderElement( this, this.files.shield, 'shield', _position, true ); } - - // Draw body, get head position - renderElement( this, this.files.body, 'body', _position, true ); + + + if(direction > 2 && direction < 6) + { + renderElement( this, this.files.body, 'body', _position, true ); + + if(Session.Playing == true && this.hasCart == true) + { + var cartidx = this.CartNum; + renderElement( this, this.files.cart_shadow, 'cartshadow', _position, false); + renderElement( this, this.files.cart[cartidx], 'cart', _position, false); + } + } + else + { + if(Session.Playing == true && this.hasCart == true) + { + var cartidx = this.CartNum; + renderElement( this, this.files.cart_shadow, 'cartshadow', _position, false); + renderElement( this, this.files.cart[cartidx], 'cart', _position, false); + } + renderElement( this, this.files.body, 'body', _position, true ); + } + + if (this.objecttype === Entity.TYPE_PC) { // Draw Head @@ -289,7 +317,8 @@ define( function( require ) return function renderElement( entity, files, type, position, is_main ) { // Nothing to render - if (!files.spr || !files.act) { + if (!files.spr || !files.act) + { return; } @@ -324,10 +353,57 @@ define( function( require ) _position[0] = 0; _position[1] = 0; - if (animation.pos.length && !is_main) { + if (animation.pos.length && !is_main) + { _position[0] = position[0] - animation.pos[0].x; _position[1] = position[1] - animation.pos[0].y; - } + } + + if(type === 'cart' || type === 'cartshadow') + { + var direction = (Camera.direction + entity.direction + 8) % 8; + + switch(direction) + { + case 0: + { + _position[0] = 0; + _position[1] = -30; + } + break; + case 1: + _position[0] = 30; + _position[1] = -10; + break; + case 2: + _position[0] = 40; + _position[1] = 0; + break; + case 3: + _position[0] = 30; + _position[1] = 10; + break; + case 4: + { + _position[0] = 0; + _position[1] = 20; + } + break; + case 5: + _position[0] = -30; + _position[1] = 10; + break; + case 6: + _position[0] = -40; + _position[1] = 0; + break; + case 7: + _position[0] = -30; + _position[1] = -10; + break; + } + } + // Render all frames for (var i=0, count=layers.length; i +
+
+ + CartItems +
+
+ + +
+
+
+
+
+ + + + + + + +
+
+
+
+
+
+
+ \ No newline at end of file diff --git a/src/UI/Components/CartItems/CartItems.js b/src/UI/Components/CartItems/CartItems.js new file mode 100644 index 0000000..7466c5a --- /dev/null +++ b/src/UI/Components/CartItems/CartItems.js @@ -0,0 +1,738 @@ +/** + * UI/Components/CartItems/CartItems.js + * + * Character CartItems Inventory + * + * This file is part of ROBrowser, Ragnarok Online in the Web Browser (http://www.robrowser.com/). + * + * @author Vincent Thibault + * In some cases the client will send packet twice.eg NORMAL_ITEMLIST4; fixit [skybook888] + * + */ +define(function(require) +{ + 'use strict'; + + + /** + * Dependencies + */ + var DB = require('DB/DBManager'); + var ItemType = require('DB/Items/ItemType'); + var jQuery = require('Utils/jquery'); + var Client = require('Core/Client'); + var Preferences = require('Core/Preferences'); + var Renderer = require('Renderer/Renderer'); + var Mouse = require('Controls/MouseEventHandler'); + var UIManager = require('UI/UIManager'); + var UIComponent = require('UI/UIComponent'); + var InputBox = require('UI/Components/InputBox/InputBox'); + var ItemInfo = require('UI/Components/ItemInfo/ItemInfo'); + var Session = require('Engine/SessionStorage'); + var htmlText = require('text!./CartItems.html'); + var cssText = require('text!./CartItems.css'); + var getModule = require; + + + /** + * Create Component + */ + var CartItems = new UIComponent( 'CartItems', htmlText, cssText ); + + + + /** + * Store inventory items + */ + CartItems.list = []; + + + /** + * @var {number} used to remember the window height + */ + var _realSize = 0; + + + /** + * @var {Preferences} structure + */ + var _preferences = Preferences.get('CartItems', { + x: 200, + y: 200, + width: 7, + height: 4, + show: false, + reduce: false + }, 1.0); + + + /** + * Initialize UI + */ + CartItems.init = function Init() + { + // Bind buttons + this.ui.find('.titlebar .base').mousedown(stopPropagation); + this.ui.find('.titlebar .mini').click(onToggleReduction); + this.ui.find('.footer .extend').mousedown(onResize); + this.ui.find('.titlebar .close').click(function(){ + CartItems.ui.hide(); + }); + + // on drop item + this.ui + .on('drop', onDrop) + .on('dragover', stopPropagation) + + // Items event + .find('.container .content') + .on('mousewheel DOMMouseScroll', onScroll) + .on('mouseover', '.item', onItemOver) + .on('mouseout', '.item', onItemOut) + .on('dragstart', '.item', onItemDragStart) + .on('dragend', '.item', onItemDragEnd) + .on('contextmenu', '.item', onItemInfo) + .on('dblclick', '.item', onItemUsed); + + this.draggable(this.ui.find('.titlebar')); + }; + + + /** + * Apply preferences once append to body + */ + CartItems.onAppend = function OnAppend() + { + if(Session.Entity.hasCart == false) + { + this.ui.hide(); + } + + // Apply preferences + if (!_preferences.show) { + this.ui.hide(); + } + + /*Client.loadFile( DB.INTERFACE_PATH + 'basic_interface/tab_itm_0'+ (_preferences.tab+1) +'.bmp', function(data){ + CartItems.ui.find('.tabs').css('backgroundImage', 'url("' + data + '")'); + });*/ + + this.resize( _preferences.width, _preferences.height ); + + this.ui.css({ + top: Math.min( Math.max( 0, _preferences.y), Renderer.height - this.ui.height()), + left: Math.min( Math.max( 0, _preferences.x), Renderer.width - this.ui.width()) + }); + + _realSize = _preferences.reduce ? 0 : this.ui.height(); + this.ui.find('.titlebar .mini').trigger('mousedown'); + }; + + + /** + * Remove Inventory from window (and so clean up items) + */ + CartItems.onRemove = function OnRemove() + { + this.ui.find('.container .content').empty(); + this.list.length = 0; + jQuery('.ItemInfo').remove(); + + // Save preferences + _preferences.show = this.ui.is(':visible'); + _preferences.reduce = !!_realSize; + _preferences.y = parseInt(this.ui.css('top'), 10); + _preferences.x = parseInt(this.ui.css('left'), 10); + _preferences.width = Math.floor( (this.ui.width() - (23 + 16 + 16 - 30)) / 32 ); + _preferences.height = Math.floor( (this.ui.height() - (31 + 19 - 30 )) / 32 ); + _preferences.save(); + }; + + + /** + * Process shortcut + * + * @param {object} key + */ + CartItems.onShortCut = function onShurtCut( key ) + { + console.log("CartItems.onShortCut : "+Session.Entity.hasCart); + + if(Session.Entity.hasCart == false) + { + return; + } + + switch (key.cmd) { + case 'TOGGLE': + this.ui.toggle(); + if (this.ui.is(':visible')) { + this.focus(); + } + else { + // Chrome bug + // when clicking double clicking an a weapon to equip + // the item disapear, if you don't move the mouse and + // triggered ALT+E then, the window disapear and you + // can't trigger the scene anymore + this.ui.trigger('mouseleave'); + } + break; + } + }; + + + /** + * Extend inventory window size + * + * @param {number} width + * @param {number} height + */ + CartItems.resize = function Resize( width, height ) + { + width = Math.min( Math.max(width, 6), 9); + height = Math.min( Math.max(height, 2), 6); + + this.ui.find('.container .content').css({ + width: width * 32 + 13, // 13 = scrollbar + height: height * 32 + }); + + this.ui.css({ + width: 16 + 16 + width * 32, + height: 31 + 19 + height * 32 + }); + }; + + + /** + * Get item object + * + * @param {number} id + * @returns {Item} + */ + CartItems.getItemById = function GetItemById( id ) + { + var i, count; + var list = CartItems.list; + + for (i = 0, count = list.length; i < count; ++i) { + if (list[i].ITID === id) { + return list[i]; + } + } + + return null; + }; + + + /** + * Search in a list for an item by its index + * + * @param {number} index + * @returns {Item} + */ + CartItems.getItemByIndex = function getItemByIndex( index ) + { + var i, count; + var list = CartItems.list; + + for (i = 0, count = list.length; i < count; ++i) { + if (list[i].index === index) { + return list[i]; + } + } + + return null; + }; + + + /** + * Add items to the list + * if the item index is exist you should clear it;[skybook888] + */ + CartItems.setItems = function SetItems(items) + { + var i, count; + + for (i = 0, count = items.length; i < count ; ++i) { + var object= this.getItemByIndex(items[i].index); + if(object){ + var item=this.removeItem(object.index,object.count); + } + if(this.addItemSub(items[i])){ + this.list.push(items[i]); + } + + + } + + }; + + + CartItems.setCartInfo = function SetCartInfo(curCount, maxCount, curWeight, maxWeight) + { + this.ui.find('.ncnt').text(curCount); + this.ui.find('.mcnt').text(maxCount); + this.ui.find('.nwt').text(curWeight); + this.ui.find('.mwt').text(maxWeight); + }; + + + /** + * Insert Item to inventory + * + * @param {object} Item + */ + CartItems.addItem = function AddItem( item ) + { + var object = this.getItemByIndex(item.index); + //console.log("add"); + + if (object) { + object.count += item.count; + this.ui.find('.item[data-index="'+ item.index +'"] .count').text( object.count ); + return; + } + + object = jQuery.extend({}, item); + if (this.addItemSub(object)) { + this.list.push(object); + } + }; + + + /** + * Add item to inventory + * + * @param {object} Item + */ + CartItems.addItemSub = function AddItemSub( item ) + { + // Equip item (if not arrow) + if (item.WearState && item.type !== ItemType.AMMO && item.type !== ItemType.CARD) { + //Equipment.equip(item); + return false; + } + + var it = DB.getItemInfo( item.ITID ); + var content = this.ui.find('.container .content'); + + content.append( + '
' + + '
' + + '
' + (item.count || 1) + '
' + + '
' + ); + + if (content.height() < content[0].scrollHeight) { + this.ui.find('.hide').hide(); + } + else { + this.ui.find('.hide').show(); + } + + Client.loadFile( DB.INTERFACE_PATH + 'item/' + ( item.IsIdentified ? it.identifiedResourceName : it.unidentifiedResourceName ) + '.bmp', function(data){ + content.find('.item[data-index="'+ item.index +'"] .icon').css('backgroundImage', 'url('+ data +')'); + }); + return true; + }; + + + /** + * Remove item from inventory + * + * @param {number} index in inventory + * @param {number} count + */ + CartItems.removeItem = function RemoveItem( index, count ) + { + var item = this.getItemByIndex(index); + + // Emulator failed to complete the operation + // do not remove item from inventory + if (!item || count <= 0) { + return null; + } + + + if (item.count) { + item.count -= count; + + if (item.count > 0) { + this.ui.find('.item[data-index="'+ item.index +'"] .count').text( item.count ); + return item; + } + } + + this.list.splice( this.list.indexOf(item), 1 ); + this.ui.find('.item[data-index="'+ item.index +'"]').remove(); + + var content = this.ui.find('.container .content'); + if (content.height() === content[0].scrollHeight) { + this.ui.find('.hide').show(); + } + + return item; + }; + + + /** + * Remove item from inventory + * + * @param {number} index in inventory + * @param {number} count + */ + CartItems.updateItem = function UpdateItem( index, count ) + { + var item = this.getItemByIndex(index); + + if (!item) { + return; + } + + item.count = count; + + // Update quantity + if (item.count > 0) { + this.ui.find('.item[data-index="'+ item.index +'"] .count').text( item.count ); + return; + } + + // no quantity, remove + this.list.splice( this.list.indexOf(item), 1 ); + this.ui.find('.item[data-index="'+ item.index +'"]').remove(); + + var content = this.ui.find('.container .content'); + if (content.height() === content[0].scrollHeight) { + this.ui.find('.hide').show(); + } + }; + + + + /** + * Stop event propagation + */ + function stopPropagation( event ) + { + event.stopImmediatePropagation(); + return false; + } + + + /** + * Extend inventory window size + */ + function onResize() + { + var ui = CartItems.ui; + var content = ui.find('.container .content'); + var hide = ui.find('.hide'); + var top = ui.position().top; + var left = ui.position().left; + var lastWidth = 0; + var lastHeight = 0; + var _Interval; + + function resizing() + { + var extraX = 23 + 16 + 16 - 30; + var extraY = 31 + 19 - 30; + + var w = Math.floor( (Mouse.screen.x - left - extraX) / 32 ); + var h = Math.floor( (Mouse.screen.y - top - extraY) / 32 ); + + // Maximum and minimum window size + w = Math.min( Math.max(w, 6), 9); + h = Math.min( Math.max(h, 2), 6); + + if (w === lastWidth && h === lastHeight) { + return; + } + + CartItems.resize( w, h ); + lastWidth = w; + lastHeight = h; + + //Show or hide scrollbar + if (content.height() === content[0].scrollHeight) { + hide.show(); + } + else { + hide.hide(); + } + } + + // Start resizing + _Interval = setInterval( resizing, 30); + + // Stop resizing on left click + jQuery(window).on('mouseup.resize', function(event){ + if (event.which === 1) { + clearInterval(_Interval); + jQuery(window).off('mouseup.resize'); + } + }); + } + + + + /** + * Hide/show inventory's content + */ + function onToggleReduction() + { + var ui = CartItems.ui; + + if (_realSize) { + ui.find('.panel').show(); + ui.height(_realSize); + _realSize = 0; + } + else { + _realSize = ui.height(); + ui.height(17); + ui.find('.panel').hide(); + } + } + + + /** + * Update tab, reset inventory content + */ + function requestFilter() + { + CartItems.ui.find('.container .content').empty(); + + var list = CartItems.list; + var i, count; + + for (i = 0, count = list.length; i < count; ++i) { + CartItems.addItemSub( list[i] ); + } + } + + + /** + * Drop an item from storage to inventory + * + * @param {event} + */ + function onDrop( event ) + { + var item, data; + event.stopImmediatePropagation(); + + try { + data = JSON.parse(event.originalEvent.dataTransfer.getData('Text')); + item = data.data; + } + catch(e) { + return false; + } + + // Just allow item from storage + if (data.type !== 'item' || (data.from !== 'Storage' && data.from !== 'Inventory')) { + return false; + } + + // Have to specify how much + if (item.count > 1) { + InputBox.append(); + InputBox.setType('number', false, item.count); + InputBox.onSubmitRequest = function OnSubmitRequest( count ) { + InputBox.remove(); + + switch(data.from) + { + case 'Storage': + getModule('UI/Components/Storage/Storage').reqMoveItemToCart( + item.index, + parseInt(count, 10 ) + ); + break; + + case 'Inventory': + getModule('UI/Components/Inventory/Inventory').reqMoveItemToCart( + item.index, + parseInt(count, 10 ) + ); + break; + + } + }; + return false; + } + + switch(data.from) + { + case 'Storage': + getModule('UI/Components/Storage/Storage').reqMoveItemToCart( item.index, 1 ); + break; + + case 'Inventory': + getModule('UI/Components/Inventory/Inventory').reqMoveItemToCart( item.index, 1 ); + break; + } + + return false; + } + + + /** + * Block the scroll to move 32px at each move + */ + function onScroll( event ) + { + var delta; + + if (event.originalEvent.wheelDelta) { + delta = event.originalEvent.wheelDelta / 120 ; + if (window.opera) { + delta = -delta; + } + } + else if (event.originalEvent.detail) { + delta = -event.originalEvent.detail; + } + + this.scrollTop = Math.floor(this.scrollTop/32) * 32 - (delta * 32); + event.stopImmediatePropagation(); + return false; + } + + + /** + * Show item name when mouse is over + */ + function onItemOver() + { + var idx = parseInt( this.getAttribute('data-index'), 10); + var item = CartItems.getItemByIndex(idx); + + if (!item) { + return; + } + + // Get back data + var pos = jQuery(this).position(); + var overlay = CartItems.ui.find('.overlay'); + + // Display box + overlay.show(); + overlay.css({top: pos.top, left:pos.left+35}); + overlay.text(DB.getItemName(item) + ' ' + (item.count || 1) + ' ea'); + + if (item.IsIdentified) { + overlay.removeClass('grey'); + } + else { + overlay.addClass('grey'); + } + } + + + /** + * Hide the item name + */ + function onItemOut() + { + CartItems.ui.find('.overlay').hide(); + } + + + /** + * Start dragging an item + */ + function onItemDragStart( event ) + { + var index = parseInt(this.getAttribute('data-index'), 10); + var item = CartItems.getItemByIndex(index); + + if (!item) { + return; + } + + // Set image to the drag drop element + var img = new Image(); + var url = this.firstChild.style.backgroundImage.match(/\(([^\)]+)/)[1]; + img.src = url.replace(/^\"/, '').replace(/\"$/, ''); + + event.originalEvent.dataTransfer.setDragImage( img, 12, 12 ); + event.originalEvent.dataTransfer.setData('Text', + JSON.stringify( window._OBJ_DRAG_ = { + type: 'item', + from: 'CartItems', + data: item + }) + ); + + onItemOut(); + } + + + /** + * Stop dragging an item + * + */ + function onItemDragEnd() + { + delete window._OBJ_DRAG_; + } + + + /** + * Get item info (open description window) + */ + function onItemInfo( event ) + { + event.stopImmediatePropagation(); + + var index = parseInt(this.getAttribute('data-index'), 10); + var item = CartItems.getItemByIndex(index); + + if (!item) { + return false; + } + + // Don't add the same UI twice, remove it + if (ItemInfo.uid === item.ITID) { + ItemInfo.remove(); + return false; + } + + // Add ui to window + ItemInfo.append(); + ItemInfo.uid = item.ITID; + ItemInfo.setItem(item); + + return false; + } + + + /** + * Ask to use an item + */ + function onItemUsed( event ) + { + var index = parseInt(this.getAttribute('data-index'), 10); + var item = CartItems.getItemByIndex(index); + + if (item) { + CartItems.useItem(item); + onItemOut(); + } + + event.stopImmediatePropagation(); + return false; + } + + + CartItems.reqRemoveItem = function reqRemoveItem(){}; + + /** + * Create component and export it + */ + return UIManager.addComponent(CartItems); +}); \ No newline at end of file diff --git a/src/UI/Components/ChangeCart/ChangeCart.css b/src/UI/Components/ChangeCart/ChangeCart.css new file mode 100644 index 0000000..ac2386e --- /dev/null +++ b/src/UI/Components/ChangeCart/ChangeCart.css @@ -0,0 +1,16 @@ +#changecart { position:absolute; width:400px; height:100px; font-size:12px; } +#changecart table { width:100%; height:100%; background-color:white; } +#changecart .titlebar { width:100%; height:17px; background-color:white; background-repeat:repeat-x; border-radius:3px 3px 0px 0px; } +#changecart .titlebar .base { width:11px; height:11px; border:none; background-color:transparent; background-repeat:no-repeat; vertical-align:middle; } +#changecart .titlebar .text { text-shadow:1px 1px white; vertical-align:-2px; white-space:nowrap; + /* chrome bug */ display: inline-block; width: 32px; height:13px; } +#changecart .titlebar .left { margin-left:3px; float:left; } +#changecart .titlebar .right { float:right; margin-right:3px;} +#changecart .titlebar .clear { clear:both; } +#changecart .titlebar .left { margin-left:3px; float:left; } +#changecart .cart { border:0; width:40px; height:53px; bottom:40px; background-color:transparent; } +#changecart .cart1 { border:0; width:40px; height:53px; bottom:40px; background-color:transparent; } +#changecart .cart2 { border:0; width:40px; height:53px; bottom:40px; background-color:transparent; } +#changecart .cart3 { border:0; width:40px; height:53px; bottom:40px; background-color:transparent; } +#changecart .cart4 { border:0; width:40px; height:53px; bottom:40px; background-color:transparent; } + diff --git a/src/UI/Components/ChangeCart/ChangeCart.html b/src/UI/Components/ChangeCart/ChangeCart.html new file mode 100644 index 0000000..37fc2cf --- /dev/null +++ b/src/UI/Components/ChangeCart/ChangeCart.html @@ -0,0 +1,32 @@ +
+
+
+ + ChangeCart +
+
+ + +
+
+
+ + + + + + + + +
+ + + + + + + + + +
+
diff --git a/src/UI/Components/ChangeCart/ChangeCart.js b/src/UI/Components/ChangeCart/ChangeCart.js new file mode 100644 index 0000000..9cfdb23 --- /dev/null +++ b/src/UI/Components/ChangeCart/ChangeCart.js @@ -0,0 +1,239 @@ +/** + * UI/Components/Equipment/Equipment.js + * + * Chararacter Equipment window + * + * This file is part of ROBrowser, Ragnarok Online in the Web Browser (http://www.robrowser.com/). + * + * @author Vincent Thibault + */ +define(function(require) +{ + 'use strict'; + + + /** + * Dependencies + */ + var DB = require('DB/DBManager'); + var Network = require('Network/NetworkManager'); + var PACKET = require('Network/PacketStructure'); + var jQuery = require('Utils/jquery'); + var Client = require('Core/Client'); + var Preferences = require('Core/Preferences'); + var Session = require('Engine/SessionStorage'); + var Renderer = require('Renderer/Renderer'); + var UIManager = require('UI/UIManager'); + var UIComponent = require('UI/UIComponent'); + var ChatBox = require('UI/Components/ChatBox/ChatBox'); + var ChatRoom = require('UI/Components/ChatRoom/ChatRoom'); + var htmlText = require('text!./ChangeCart.html'); + var cssText = require('text!./ChangeCart.css'); + + + /** + * Create Component + */ + var ChangeCart = new UIComponent( 'ChangeCart', htmlText, cssText ); + + + /** + * @var {Preference} window preferences + */ + var _preferences = Preferences.get('ChangeCart', { + show: false, + }, 1.0); + + + /** + * Initialize UI + */ + ChangeCart.init = function init() + { + var ui = this.ui; + + ui.css({ + top: (Renderer.height - 100) / 2.0, + left: (Renderer.width - 400) / 2.0 + }); + + + this.ui.find('.titlebar .close').click(function(){ ChangeCart.ui.hide(); }); + this.draggable(this.ui.find('.titlebar')); + + this.ui.find('.cart').click(onCart); + this.ui.find('.cart1').click(onCart1); + this.ui.find('.cart2').click(onCart2); + this.ui.find('.cart3').click(onCart3); + this.ui.find('.cart4').click(onCart4); + + this.ui.find('.cart').hide(); + this.ui.find('.cart1').hide(); + this.ui.find('.cart2').hide(); + this.ui.find('.cart3').hide(); + this.ui.find('.cart4').hide(); + + }; + + function onCart() + { + if(Session.Entity.hasCart == false/* || Session.Entity.CartNum == 1*/) + { + return + } + + var pkt = new PACKET.CZ.REQ_CHANGECART(); + pkt.num = 1; + Network.sendPacket(pkt); + } + + function onCart1() + { + if(Session.Entity.hasCart == false/* || Session.Entity.CartNum == 2*/) + { + return + } + var pkt = new PACKET.CZ.REQ_CHANGECART(); + pkt.num = 2; + Network.sendPacket(pkt); + } + + function onCart2() + { + if(Session.Entity.hasCart == false/* || Session.Entity.CartNum == 3*/) + { + return + } + var pkt = new PACKET.CZ.REQ_CHANGECART(); + pkt.num = 3; + Network.sendPacket(pkt); + } + + function onCart3() + { + if(Session.Entity.hasCart == false/* || Session.Entity.CartNum == 4*/) + { + return + } + var pkt = new PACKET.CZ.REQ_CHANGECART(); + pkt.num = 4; + Network.sendPacket(pkt); + } + + function onCart4() + { + if(Session.Entity.hasCart == false/* || Session.Entity.CartNum == 5*/) + { + return + } + var pkt = new PACKET.CZ.REQ_CHANGECART(); + pkt.num = 5; + Network.sendPacket(pkt); + } + + + /** + * Append to body + */ + ChangeCart.onAppend = function onAppend() + { + if (!_preferences.show) { + this.ui.hide(); + } + + this.ui.find('.cart').hide(); + this.ui.find('.cart1').hide(); + this.ui.find('.cart2').hide(); + this.ui.find('.cart3').hide(); + this.ui.find('.cart4').hide(); + + + if(Session.Character.level > 90) + { + this.ui.find('.cart4').show(); + } + + if(Session.Character.level > 80) + { + this.ui.find('.cart3').show(); + } + + if(Session.Character.level > 65) + { + this.ui.find('.cart2').show(); + } + + if(Session.Character.level > 40) + { + this.ui.find('.cart1').show(); + } + + this.ui.find('.cart').show(); + }; + + ChangeCart.onChangeCartSkill = function onChangeCartSkill() + { + if(Session.Entity.hasCart == false) + { + return; + } + + this.ui.show(); + + var msg = "Change Cart!!"; + + if (ChatRoom.isOpen) { + ChatRoom.message(msg); + return; + } + + ChatBox.addText( msg, ChatBox.TYPE.PUBLIC | ChatBox.TYPE.SELF ); + if (Session.Entity) { + Session.Entity.dialog.set( msg ); + } + }; + + + ChangeCart.onLevelUp = function onLevelUp(blvl) + { + if(Session.Entity.hasCart == false) + { + return; + } + + this.ui.find('.cart').hide(); + this.ui.find('.cart1').hide(); + this.ui.find('.cart2').hide(); + this.ui.find('.cart3').hide(); + this.ui.find('.cart4').hide(); + + if(blvl > 90) + { + this.ui.find('.cart4').show(); + } + + if(blvl > 80) + { + this.ui.find('.cart3').show(); + } + + if(blvl > 65) + { + this.ui.find('.cart2').show(); + } + + if(blvl > 40) + { + this.ui.find('.cart1').show(); + } + + this.ui.find('.cart').show(); + + }; + + + /** + * Create component and export it + */ + return UIManager.addComponent(ChangeCart); +}); \ No newline at end of file diff --git a/src/UI/Components/Equipment/Equipment.css b/src/UI/Components/Equipment/Equipment.css index c215ee8..4c09786 100644 --- a/src/UI/Components/Equipment/Equipment.css +++ b/src/UI/Components/Equipment/Equipment.css @@ -31,7 +31,8 @@ #Equipment .ammo { position:absolute; top:30px; } #Equipment .ammo .item { text-align:center; } #Equipment .ammo .item span { width:45px; } -#Equipment .removeOption { position:absolute; top:85px; left:12px; width:36px; height:36px; background-repeat:no-repeat; background-color:transparent; border:none; display:none; } +#Equipment .cartitems { position:absolute; top:65px; left:14px; width:36px; height:36px; background-repeat:no-repeat; background-color:transparent; border:none; display:none; } +#Equipment .removeOption { position:absolute; top:90px; left:12px; width:36px; height:36px; background-repeat:no-repeat; background-color:transparent; border:none; display:none; } #Equipment .footer { height:20px; border-bottom:1px solid #c0c0c0; } #Equipment .footer .left { float:left; text-align:left; margin-left:5px; margin-top:3px; } diff --git a/src/UI/Components/Equipment/Equipment.html b/src/UI/Components/Equipment/Equipment.html index 4d1437e..cc8426a 100644 --- a/src/UI/Components/Equipment/Equipment.html +++ b/src/UI/Components/Equipment/Equipment.html @@ -19,6 +19,7 @@
+
diff --git a/src/UI/Components/Equipment/Equipment.js b/src/UI/Components/Equipment/Equipment.js index f5b510e..8e9a020 100644 --- a/src/UI/Components/Equipment/Equipment.js +++ b/src/UI/Components/Equipment/Equipment.js @@ -18,6 +18,8 @@ define(function(require) var DB = require('DB/DBManager'); var StatusConst = require('DB/Status/StatusState'); var EquipLocation = require('DB/Items/EquipmentLocation'); + var Network = require('Network/NetworkManager'); + var PACKET = require('Network/PacketStructure'); var ItemType = require('DB/Items/ItemType'); var jQuery = require('Utils/jquery'); var Client = require('Core/Client'); @@ -29,6 +31,7 @@ define(function(require) var UIManager = require('UI/UIManager'); var UIComponent = require('UI/UIComponent'); var ItemInfo = require('UI/Components/ItemInfo/ItemInfo'); + var CartItems = require('UI/Components/CartItems/CartItems'); var WinStats = require('UI/Components/WinStats/WinStats'); var htmlText = require('text!./Equipment.html'); var cssText = require('text!./Equipment.css'); @@ -107,9 +110,12 @@ define(function(require) this.ui.find('.titlebar .mini').click(function(){ Equipment.ui.find('.panel').toggle(); }); this.ui.find('.titlebar .close').click(function(){ Equipment.ui.hide(); }); - this.ui.find('.removeOption').click(this.onRemoveOption); + this.ui.find('.removeOption').mousedown(onRemoveOption); this.ui.find('.view_status').mousedown(toggleStatus); this.ui.find('.show_equip').mousedown(toggleEquip); + + this.ui.find('.cartitems').click(onCartItems); + // drag, drop items this.ui.on('dragover', onDragOver); @@ -127,6 +133,23 @@ define(function(require) }; + function onCartItems() + { + if(Session.Entity.hasCart == false) + { + return; + } + CartItems.ui.toggle(); + } + + + function onRemoveOption() + { + var pkt = new PACKET.CZ.REQ_CARTOFF(); + Network.sendPacket(pkt); + } + + /** * Append to body */ @@ -374,14 +397,16 @@ define(function(require) var animation = character.animation; // If state change, we have to check if the new option is removable. - if (character.effectState !== _lastState || _hasCart !== Session.hasCart) { + if (character.effectState !== _lastState || _hasCart !== character.hasCart) { _lastState = character.effectState; - _hasCart = Session.hasCart; + _hasCart = character.hasCart; if (_lastState & OptionFlag || _hasCart) { + Equipment.ui.find('.cartitems').show(); Equipment.ui.find('.removeOption').show(); } else { + Equipment.ui.find('.cartitems').hide(); Equipment.ui.find('.removeOption').hide(); } } diff --git a/src/UI/Components/InputBox/InputBox.js b/src/UI/Components/InputBox/InputBox.js index 3fca9cf..4316cd5 100644 --- a/src/UI/Components/InputBox/InputBox.js +++ b/src/UI/Components/InputBox/InputBox.js @@ -132,6 +132,14 @@ define(function(require) this.ui.find('input').attr('type', 'text'); defaultVal = defaultVal || 0; break; + + case 'price': + this.ui.addClass('number'); + this.ui.find('.text').text( 'Input Price' ); + this.ui.find('input').attr('type', 'text'); + defaultVal = defaultVal || 0; + break; + case 'text': this.ui.removeClass('number'); @@ -139,6 +147,12 @@ define(function(require) this.ui.find('input').attr('type', 'text'); break; + case 'shopname': + this.ui.removeClass('number'); + this.ui.find('.text').text('Input your Shop Name'); + this.ui.find('input').attr('type', 'text'); + break; + case 'pass': this.ui.removeClass('number'); this.ui.find('.text').text(''); diff --git a/src/UI/Components/Inventory/Inventory.js b/src/UI/Components/Inventory/Inventory.js index fdc6142..ef7af8f 100755 --- a/src/UI/Components/Inventory/Inventory.js +++ b/src/UI/Components/Inventory/Inventory.js @@ -607,26 +607,52 @@ define(function(require) } // Just allow item from storage - if (data.type !== 'item' || data.from !== 'Storage') { + if (data.type !== 'item' || (data.from !== 'Storage' && data.from !== 'CartItems')) { return false; } // Have to specify how much - if (item.count > 1) { + if (item.count > 1) + { InputBox.append(); InputBox.setType('number', false, item.count); - InputBox.onSubmitRequest = function OnSubmitRequest( count ) { + + InputBox.onSubmitRequest = function OnSubmitRequest( count ) + { InputBox.remove(); - getModule('UI/Components/Storage/Storage').reqRemoveItem( - item.index, - parseInt(count, 10 ) - ); + + switch(data.from) + { + case 'Storage': + getModule('UI/Components/Storage/Storage').reqRemoveItem( + item.index, + parseInt(count, 10 ) + ); + break; + + case 'CartItems': + getModule('UI/Components/CartItems/CartItems').reqRemoveItem( + item.index, + parseInt(count, 10 ) + ); + break; + + } }; return false; } + + switch(data.from) + { + case 'Storage': + getModule('UI/Components/Storage/Storage').reqRemoveItem( item.index, 1 ); + break; + + case 'CartItems': + getModule('UI/Components/CartItems/CartItems').reqRemoveItem( item.index, 1 ); + break; + } - // Only one, don't have to specify - getModule('UI/Components/Storage/Storage').reqRemoveItem( item.index, 1 ); return false; } @@ -787,6 +813,7 @@ define(function(require) Inventory.onUseCard = function onUseCard(/* index */){}; Inventory.onEquipItem = function OnEquipItem(/* index, location */){}; Inventory.onUpdateItem = function OnUpdateItem(/* index, amount */){}; + Inventory.reqMoveItemToCart = function reqMoveItemToCart(){}; /** diff --git a/src/UI/Components/NpcStore/NpcStore.css b/src/UI/Components/NpcStore/NpcStore.css index 90a5e74..07768ea 100644 --- a/src/UI/Components/NpcStore/NpcStore.css +++ b/src/UI/Components/NpcStore/NpcStore.css @@ -18,7 +18,7 @@ #NpcStore .content .item .price { position:absolute; top:13px; right:16px; white-space:nowrap; text-align:right; } #NpcStore .content .item .unity { position:absolute; top:13px; right:2px; width:10px; } -#NpcStore .footer .total { padding-left:10px; padding-top:8px; } +#NpcStore .footer .total, #NpcStore .footer .totalP, #NpcStore .footer .cashuser { padding-left:10px; padding-top:8px; } #NpcStore .InputWindow, #NpcStore .OutputWindow { width:280px; position:absolute; z-index:50; } #NpcStore .btn.buy, #NpcStore .btn.sell { position:absolute; top:4px; right:62px; } #NpcStore .btn.cancel { position:absolute; top:4px; right:15px;} \ No newline at end of file diff --git a/src/UI/Components/NpcStore/NpcStore.html b/src/UI/Components/NpcStore/NpcStore.html index 3f2d104..226a277 100644 --- a/src/UI/Components/NpcStore/NpcStore.html +++ b/src/UI/Components/NpcStore/NpcStore.html @@ -1,42 +1,44 @@ -
- -
-
-
- Available Items for selling - Shop Items - - Merchant Shop - - -
-
-
-
-
- -
- -
-
-
- Selling Items - Buying Items -
-
-
-
-
- -
+
+ +
+
+
+ Available Items for selling + Shop Items + + Merchant Shop - + +
+
+
+
+
+ +
+ +
+
+
+ Selling Items + Buying Items +
+
+
+
+
+ +
\ No newline at end of file diff --git a/src/UI/Components/NpcStore/NpcStore.js b/src/UI/Components/NpcStore/NpcStore.js index 3605556..2d36ab7 100644 --- a/src/UI/Components/NpcStore/NpcStore.js +++ b/src/UI/Components/NpcStore/NpcStore.js @@ -45,7 +45,8 @@ define(function(require) NpcStore.Type = { BUY: 0, SELL: 1, - VENDING_STORE: 2 + VENDING_STORE: 2, + CASH_SHOP: 3 }; @@ -212,6 +213,7 @@ define(function(require) NpcStore.setType = function setType(type) { switch (type) { + case NpcStore.Type.CASH_SHOP: case NpcStore.Type.BUY: this.ui.find('.WinSell, .WinVendingStore').hide(); this.ui.find('.WinBuy').show(); @@ -243,7 +245,18 @@ define(function(require) var it, item, out, content; this.ui.find('.content').empty(); - this.ui.find('.total .result').text(0); + + if(_type == NpcStore.Type.CASH_SHOP) + { + this.ui.find('.total').hide(); + this.ui.find('.totalP .resultP').text(0); + } + else + { + this.ui.find('.cashuser').hide(); + this.ui.find('.totalP').hide(); + this.ui.find('.total .result').text(0); + } _input.length = 0; _output.length = 0; @@ -253,6 +266,7 @@ define(function(require) case NpcStore.Type.BUY: case NpcStore.Type.VENDING_STORE: + case NpcStore.Type.CASH_SHOP: for (i = 0, count = items.length; i < count; ++i) { if (!('index' in items[i])) { items[i].index = i; @@ -331,9 +345,12 @@ define(function(require) total += (_output[i].discountprice || _output[i].overchargeprice || _output[i].price) * _output[i].count; } } - - this.ui.find('.total .result').text(total); - + + if(_type == NpcStore.Type.CASH_SHOP) + this.ui.find('.totalP .resultP').text(total); + else + this.ui.find('.total .result').text(total); + return total; }; @@ -386,6 +403,7 @@ define(function(require) var it = DB.getItemInfo(item.ITID); var element = content.find('.item[data-index='+ item.index +']:first'); var price; + var m_unit; // 0 as amount ? remove it if (item.count === 0) { @@ -403,6 +421,11 @@ define(function(require) } price = prettyZeny(item.price, _type === NpcStore.Type.VENDING_STORE); + m_unit = 'Z'; + if(_type == NpcStore.Type.CASH_SHOP) + { + m_unit = 'P'; + } // Discount price if ('discountprice' in item && item.price !== item.discountprice) { @@ -419,7 +442,7 @@ define(function(require) '
' + (isFinite(item.count) ? item.count : '') + '
' + '
'+ jQuery.escape(DB.getItemName(item)) +'
' + '
'+ price +'
' + - '
Z
' + + '
'+ m_unit +'
' + '
' ); diff --git a/src/UI/Components/Storage/Storage.js b/src/UI/Components/Storage/Storage.js index 9ebf801..bfdca89 100644 --- a/src/UI/Components/Storage/Storage.js +++ b/src/UI/Components/Storage/Storage.js @@ -377,7 +377,7 @@ define(function(require) event.stopImmediatePropagation(); // Just support items for now ? - if (!data || data.type !== 'item' || data.from !== 'Inventory') { + if (!data || data.type !== 'item' || (data.from !== 'Inventory' && data.from !== 'CartItems')) { return false; } @@ -389,16 +389,35 @@ define(function(require) InputBox.setType('number', false, item.count); InputBox.onSubmitRequest = function OnSubmitRequest( count ) { InputBox.remove(); - Storage.reqAddItem( - item.index, - parseInt(count, 10 ) - ); + + if(data.from === 'CartItems') + { + Storage.reqAddItemFromCart( + item.index, + parseInt(count, 10 ) + ); + } + else + { + Storage.reqAddItem( + item.index, + parseInt(count, 10 ) + ); + } }; return false; } - Storage.reqAddItem( item.index, 1 ); + if(data.from === 'CartItems') + { + Storage.reqAddItemFromCart( item.index, 1 ); + } + else + { + Storage.reqAddItem( item.index, 1 ); + } + return false; } @@ -574,8 +593,9 @@ define(function(require) */ Storage.onClosePressed = function onClosedPressed(){}; Storage.reqAddItem = function reqAddItem(){}; + Storage.reqAddItemFromCart = function reqAddItemFromCart(){}; Storage.reqRemoveItem = function reqRemoveItem(){}; - + Storage.reqMoveItemToCart = function reqMoveItemToCart(){}; /** * Create component and export it diff --git a/src/UI/Components/Vending/Vending.css b/src/UI/Components/Vending/Vending.css new file mode 100644 index 0000000..a8124c5 --- /dev/null +++ b/src/UI/Components/Vending/Vending.css @@ -0,0 +1,29 @@ +#vending { position:relative; } +#vending .titlebar { width:100%; height:17px; background-color:white; background-repeat:repeat-x; border-radius:3px 3px 0px 0px; text-shadow:1px 1px white; } +#vending .titlebar .text { position:relative; top:2px; left:15px; white-space:nowrap;} +#vending .footer { width:100%; height:27px; background-repeat:repeat-x; background-color:transparent; position:relative; border-radius:0px 0px 3px 3px; position:relative;} +#vending .resize { position:absolute; right:1px; bottom:1px; width:13px; height:13px; border:none; background-repeat:no-repeat; background-color:transparent; } +#vending .btn { width:42px; height:20px; border:none; margin:0; background-color:transparent; background-repeat:no-repeat; } +#vending .selectall { vertical-align:2px; width:10px; height:10px; border:none; background-color:transparent; background-repeat:no-repeat; } +#vending .ask_quantity { padding-top:7px; padding-left:20px;} + +#vending .nstore { position:absolute; top:18px; float:left font-size:12px; border:none; padding-left:2px; outline:none;} +#vending input { position:absolute; left:85px; width:180px; border:none; background-color:#E9E9E9; padding-left:2px; outline:none;} +#vending input.shopname { top:18px; } + + +#vending .container { padding-left: 16px; border-right:1px solid #ccc; background:white; background-repeat:repeat-y; padding-right:2px; padding-top:5px; padding-bottom:5px; } +#vending .content { overflow-y:auto; width:100%; height:100%; min-height:65px; background-color:transparent; background-repeat:repeat-y; } +#vending .content .item { display:block; position:relative; height:28px; padding-top:4px; } +#vending .content .item.selected { background-color:#739cee; } + +#vending .content .item .icon { position:absolute; top:6px; left:4px; width:24px; height:24px; border:none; background-color:transparent; background-repeat:no-repeat; } +#vending .content .item .amount { position:absolute; white-space:nowrap; font-size:11px; top:18px; left:18px; text-align:left; text-shadow:-1px -1px white; } +#vending .content .item .name { position:absolute; top:13px; left:32px; width:115px; white-space:nowrap; } +#vending .content .item .price { position:absolute; top:13px; right:16px; white-space:nowrap; text-align:right; } +#vending .content .item .unity { position:absolute; top:13px; right:2px; width:10px; } + +#vending .footer .total, #vending .footer .totalP, #vending .footer .cashuser { padding-left:10px; padding-top:8px; } +#vending .InputWindow, #vending .OutputWindow { width:280px; position:absolute; z-index:50; } +#vending .btn.buy, #vending .btn.sell { position:absolute; top:4px; right:62px; } +#vending .btn.cancel { position:absolute; top:4px; right:15px;} \ No newline at end of file diff --git a/src/UI/Components/Vending/Vending.html b/src/UI/Components/Vending/Vending.html new file mode 100644 index 0000000..40d20f7 --- /dev/null +++ b/src/UI/Components/Vending/Vending.html @@ -0,0 +1,30 @@ +
+
+
+
+ Available Items for Vending +
+
+
+
+
+ +
+
+
+
+ Vending +
+
+
+
Shop Name:
+
+
+
+ +
+
\ No newline at end of file diff --git a/src/UI/Components/Vending/Vending.js b/src/UI/Components/Vending/Vending.js new file mode 100644 index 0000000..dfeaeea --- /dev/null +++ b/src/UI/Components/Vending/Vending.js @@ -0,0 +1,726 @@ +/** + * UI/Components/Vending/Vending.js + * + * Chararacter Basic information windows + * + * This file is part of ROBrowser, Ragnarok Online in the Web Browser (http://www.robrowser.com/). + * + * @author Vincent Thibault + */ +define(function(require) +{ + 'use strict'; + + + /** + * Dependencies + */ + var jQuery = require('Utils/jquery'); + var DB = require('DB/DBManager'); + var Network = require('Network/NetworkManager'); + var PACKET = require('Network/PacketStructure'); + var ItemType = require('DB/Items/ItemType'); + var Client = require('Core/Client'); + var Preferences = require('Core/Preferences'); + var Session = require('Engine/SessionStorage'); + var Mouse = require('Controls/MouseEventHandler'); + var KEYS = require('Controls/KeyEventHandler'); + var UIManager = require('UI/UIManager'); + var UIComponent = require('UI/UIComponent'); + var ItemInfo = require('UI/Components/ItemInfo/ItemInfo'); + var InputBox = require('UI/Components/InputBox/InputBox'); + var ChatBox = require('UI/Components/ChatBox/ChatBox'); + var CartItems = require('UI/Components/CartItems/CartItems'); + var htmlText = require('text!./Vending.html'); + var cssText = require('text!./Vending.css'); + + + /** + * Create NPC Menu component + */ + var Vending = new UIComponent( 'Vending', htmlText, cssText ); + + + + /** + * Freeze the mouse + */ + //Vending.mouseMode = UIComponent.MouseMode.FREEZE; + + + /** + * @var {Preferences} + */ + var _preferences = Preferences.get('Vending', { + inputWindow: { + x: 100, + y: 100, + height: 2 + }, + outputWindow: { + x: 100 + 280 + 10, + y: 100 + (7*32) - (2*32), + height: 5 + }, + select_all: false + }, 1.0); + + + /** + * @var {Array} item list + */ + var _input = []; + + + /** + * @var {Array} output list + */ + var _output = []; + + + /** + * @var {number} type (buy/sell) + */ + var _type; + + var _shopname = ''; + + + /** + * Initialize component + */ + Vending.init = function init() + { + var ui = this.ui; + var InputWindow = ui.find('.InputWindow'); + var OutputWindow = ui.find('.OutputWindow'); + + // Client do not send packet + //ui.find('.btn.cancel').click(this.remove.bind(this)); + ui.find('.btn.sell').click(function(){ + Vending.onSubmit(); + }); + this.ui.find('.btn.cancel').click(function(){ + Vending.onRemove(); + }); + + + // Items options + ui.find('.content') + .on('mousewheel DOMMouseScroll', onScroll) + .on('contextmenu', '.icon', onItemInfo) + .on('dblclick', '.item', onItemSelected) + .on('mousedown', '.item', onItemFocus) + .on('dragstart', '.item', onDragStart) + .on('dragend', '.item', function(){ + delete window._OBJ_DRAG_; + }); + + // Drop items + ui.find('.InputWindow, .OutputWindow') + .on('drop', onDrop) + .on('dragover', function(event) { + event.stopImmediatePropagation(); + return false; + }) + .on('mousedown', function(){ + Vending.focus(); + }); + + // Hacky drag drop + this.draggable.call({ui: InputWindow }, InputWindow.find('.titlebar')); + this.draggable.call({ui: OutputWindow }, OutputWindow.find('.titlebar')); + + }; + + + /** + * Player should not be able to move when the store is opened + */ + Vending.onAppend = function onAppend() + { + var InputWindow = this.ui.find('.InputWindow'); + var OutputWindow = this.ui.find('.OutputWindow'); + + InputWindow.css({ top: _preferences.inputWindow.y, left: _preferences.inputWindow.x }); + OutputWindow.css({ top: _preferences.outputWindow.y, left: _preferences.outputWindow.x }); + + resize( InputWindow.find('.content'), _preferences.inputWindow.height ); + resize( OutputWindow.find('.content'), _preferences.outputWindow.height ); + + // Seems like "EscapeWindow" is execute first, push it before. + //var events = jQuery._data( window, 'events').keydown; + //events.unshift( events.pop() ); + + this.ui.hide(); + }; + + /** + * Resize the content + * + * @param {jQueryElement} content + * @param {number} height + */ + function resize( content, height ) + { + height = Math.min( Math.max(height, 2), 9); + content.css('height', height * 32); + } + + + /** + * Released movement and save preferences + */ + Vending.onRemove = function onRemove() + { + + var InputWindow = this.ui.find('.InputWindow'); + var OutputWindow = this.ui.find('.OutputWindow'); + + _input.length = 0; + _output.length = 0; + + _preferences.inputWindow.x = parseInt( InputWindow.css('left'), 10); + _preferences.inputWindow.y = parseInt( InputWindow.css('top'), 10); + _preferences.inputWindow.height = InputWindow.find('.content').height() / 32 | 0; + + _preferences.outputWindow.x = parseInt( OutputWindow.css('left'), 10); + _preferences.outputWindow.y = parseInt( OutputWindow.css('top'), 10); + _preferences.outputWindow.height = OutputWindow.find('.content').height() / 32 | 0; + + _preferences.save(); + + this.ui.find('.content').empty(); + + this.ui.hide(); + }; + + + /** + * Key Listener + * + * Remove the UI when Escape key is pressed + */ + Vending.onKeyDown = function onKeyDown( event ) + { + if (event.which === KEYS.ESCAPE) { + this.remove(); + event.stopImmediatePropagation(); + return false; + } + + return true; + }; + + + + /** + * Add items to list + * + * @param {Array} item list + */ + Vending.setList = function setList( items ) + { + var i, count; + var it, item, out, content; + + this.ui.find('.content').empty(); + + _input.length = 0; + _output.length = 0; + + + content = this.ui.find('.InputWindow .content'); + + { + for (i = 0, count = items.length; i < count; ++i) { + + + if (!('index' in items[i])) { + items[i].index = i; + } + + + items[i].count = items[i].count || Infinity; + items[i].IsIdentified = true; + out = jQuery.extend({}, items[i]); + out.count = 0; + + addItem( content, items[i], true); + + _input[items[i].index] = items[i]; + _output[items[i].index] = out; + } + } + }; + + + + + /** + * Prettify zeny : 1000000 -> 1,000,000 + * + * @param {number} zeny + * @param {boolean} use color + * @return {string} + */ + function prettyZeny( val, useStyle ) + { + + var list = val.toString().split(''); + var i, count = list.length; + var str = ''; + + for (i = 0; i < count; i++) { + str = list[count-i-1] + (i && i%3 ===0 ? ',' : '') + str; + } + + if (useStyle) { + var style = [ + 'color:#000000; text-shadow:1px 0px #00ffff;', // 0 - 9 + 'color:#0000ff; text-shadow:1px 0px #ce00ce;', // 10 - 99 + 'color:#0000ff; text-shadow:1px 0px #00ffff;', // 100 - 999 + 'color:#ff0000; text-shadow:1px 0px #ffff00;', // 1,000 - 9,999 + 'color:#ff18ff;', // 10,000 - 99,999 + 'color:#0000ff;', // 100,000 - 999,999 + 'color:#000000; text-shadow:1px 0px #00ff00;', // 1,000,000 - 9,999,999 + 'color:#ff0000;', // 10,000,000 - 99,999,999 + 'color:#000000; text-shadow:1px 0px #cece63;', // 100,000,000 - 999,999,999 + 'color:#ff0000; text-shadow:1px 0px #ff007b;', // 1,000,000,000 - 9,999,999,999 + ]; + str = '' + str + ''; + } + + return str; + } + + + /** + * Add item to the list + * + * @param {jQuery} content element + * @param {Item} item info + */ + function addItem( content, item , isinput) + { + var it = DB.getItemInfo(item.ITID); + var element = content.find('.item[data-index='+ item.index +']:first'); + var price; + + // 0 as amount ? remove it + if (item.count === 0) { + if (element.length) { + element.remove(); + } + return; + } + + // Already here, update it + // Note: just the amount can be updated ? + if (element.length) { + element.find('.amount').text(isFinite(item.count) ? item.count : ''); + return; + } + + if(isinput==false)price = prettyZeny(item.price, false); + //price = item.price; + + // Create it + if(isinput == true) + { + content.append( + '
' + + '
' + + '
' + (isFinite(item.count) ? item.count : '') + '
' + + '
'+ jQuery.escape(DB.getItemName(item)) +'
' + + '
' + ); + } + else + { + content.append( + '
' + + '
' + + '
' + (isFinite(item.count) ? item.count : '') + '
' + + '
'+ jQuery.escape(DB.getItemName(item)) +'
' + + '
Price: '+ price +'
' + + '
' + ); + } + + + // Add the icon once loaded + Client.loadFile( DB.INTERFACE_PATH + 'item/' + (item.IsIdentified ? it.identifiedResourceName : it.unidentifiedResourceName) + '.bmp', function(data){ + content.find('.item[data-index="'+ item.index +'"] .icon').css('backgroundImage', 'url('+ data +')'); + }); + } + + + /** + * Transfer item from input to output (or the inverse) + * + * @param {jQueryElement} from content (input / output) + * @param {jQueryElement} to content (input / output) + * @param {boolean} is adding the content to the output element + * @param {number} item index + * @param {number} amount + */ + var transferItem = function transferItemQuantityClosure() + { + var tmpItem = { + ITID: 0, + count: 0, + price: 0, + index: 0 + }; + + return function transferItem(fromContent, toContent, isAdding, index, count) + { + // Add item to the list + if (isAdding) { + + _output[index].count = Math.min( _output[index].count + count, _input[index].count); + + // Update input ui item amount + tmpItem.ITID = _input[index].ITID; + tmpItem.count = _input[index].count - _output[index].count; + tmpItem.price = _input[index].price; + tmpItem.index = _input[index].index; + + addItem( fromContent, tmpItem, true); + addItem( toContent, _output[index], false); + } + + // Remove item + else { + count = Math.min(count, _output[index].count); + if (!count) { + return; + } + + _output[index].count -= count; + + // Update input ui item amount + tmpItem.ITID = _input[index].ITID; + tmpItem.count = _input[index].count + _output[index].count; + tmpItem.price = _input[index].price; + tmpItem.index = _input[index].index; + + addItem( fromContent, _output[index], false); + addItem( toContent, tmpItem, true); + } + + //Vending.calculateCost(); + }; + }(); + + + /** + * Request move item from box to another + * + * @param {number} item index + * @param {jQueryElement} from the content + * @param {jQueryElement} to the content + * @param {boolean} add the content to the output box ? + */ + function requestMoveItem( index, fromContent, toContent, isAdding) + { + var item, count, item_price; + var isStackable; + + item = isAdding ? _input[index] : _output[index]; + + isStackable = ( + item.type !== ItemType.WEAPON && + item.type !== ItemType.EQUIP && + item.type !== ItemType.PETEGG && + item.type !== ItemType.PETEQUIP + ); + + if (isAdding) { + count = isFinite(_input[index].count) ? _input[index].count : 1; + } + else { + count = _output[index].count; + } + + /*// Can't buy more than one same stackable item + if ((_type === Vending.Type.BUY || _type === Vending.Type.VENDING_STORE) && !isStackable && isAdding) { + if (toContent.find('.item[data-index="'+ item.index +'"]:first').length) { + return false; + } + }*/ + + // Just one item amount + if (item.count === 1 || !isStackable/* || (_type === Vending.Type.SELL && _preferences.select_all)*/) { + + if(isAdding) + { + // Have to specify an price + InputBox.append(); + InputBox.setType('price', false, item_price); + InputBox.onSubmitRequest = function(item_price) { + InputBox.remove(); + _output[index].price = item_price; + if(item_price > 0) + { + transferItem(fromContent, toContent, isAdding, index, isFinite(item.count) ? item.count : 1 ); + } + }; + } + else + { + transferItem(fromContent, toContent, isAdding, index, isFinite(item.count) ? item.count : 1 ); + } + return false; + } + + // Have to specify an amount + InputBox.append(); + InputBox.setType('number', false, count); + InputBox.onSubmitRequest = function(count) { + InputBox.remove(); + if (count > 0) { + + if(isAdding) + { + // Have to specify an price + InputBox.append(); + InputBox.setType('price', false, item_price); + InputBox.onSubmitRequest = function(item_price) { + InputBox.remove(); + _output[index].price = item_price; + if(item_price > 0) + { + transferItem(fromContent, toContent, isAdding, index, count); + } + }; + } + else + { + transferItem(fromContent, toContent, isAdding, index, count); + } + } + }; + } + + + /** + * Drop an input in the InputWindow or OutputWindow + * + * @param {jQueryEvent} event + */ + function onDrop( event ) + { + var data; + + event.stopImmediatePropagation(); + + try { + data = JSON.parse(event.originalEvent.dataTransfer.getData('Text')); + } + catch(e) { + return false; + } + + // Just allow item from store + if (data.type !== 'item' || data.from !== 'Vending' || data.container === this.className) { + return false; + } + + requestMoveItem( + data.index, + jQuery('.' + data.container + ' .content'), + jQuery(this).find('.content'), + this.className === 'OutputWindow' + ); + + return false; + } + + + /** + * Get informations about an item + */ + function onItemInfo(event) + { + var index = parseInt( this.parentNode.getAttribute('data-index'), 10); + var item = _input[index]; + + event.stopImmediatePropagation(); + + if (!item) { + return false; + } + + // Don't add the same UI twice, remove it + if (ItemInfo.uid === item.ITID) { + ItemInfo.remove(); + return false; + } + + // Add ui to window + ItemInfo.append(); + ItemInfo.uid = item.ITID; + ItemInfo.setItem(item); + return false; + } + + + /** + * Select an item, put it on the other box + */ + function onItemSelected() + { + var input, from, to; + + if (_type === Vending.Type.BUY || _type === Vending.Type.VENDING_STORE) { + return; + } + + input = Vending.ui.find('.InputWindow:first'); + + if (jQuery.contains(input.get(0), this)) { + from = input; + to = Vending.ui.find('.OutputWindow:first'); + } + else { + from = Vending.ui.find('.OutputWindow:first'); + to = input; + } + + requestMoveItem( + parseInt( this.getAttribute('data-index'), 10), + from.find('.content:first'), + to.find('.content:first'), + from === input + ); + } + + + /** + * Focus an item + */ + function onItemFocus() + { + Vending.ui.find('.item.selected').removeClass('selected'); + jQuery(this).addClass('selected'); + } + + + /** + * Update scroll by block (32px) + */ + function onScroll( event ) + { + var delta; + + if (event.originalEvent.wheelDelta) { + delta = event.originalEvent.wheelDelta / 120 ; + if (window.opera) { + delta = -delta; + } + } + else if (event.originalEvent.detail) { + delta = -event.originalEvent.detail; + } + + this.scrollTop = Math.floor(this.scrollTop/32) * 32 - (delta * 32); + return false; + } + + + /** + * Start dragging an item + */ + function onDragStart( event ) + { + var container, img, url; + var InputWindow, OutputWindow; + + InputWindow = Vending.ui.find('.InputWindow:first').get(0); + OutputWindow = Vending.ui.find('.OutputWindow:first').get(0); + + container = (jQuery.contains(InputWindow, this) ? InputWindow : OutputWindow).className; + img = new Image(); + url = this.firstChild.style.backgroundImage.match(/\(([^\)]+)/)[1].replace(/"/g, ''); + img.src = url; + + event.originalEvent.dataTransfer.setDragImage( img, 12, 12 ); + event.originalEvent.dataTransfer.setData('Text', + JSON.stringify( window._OBJ_DRAG_ = { + type: 'item', + from: 'Vending', + container: container, + index: this.getAttribute('data-index') + }) + ); + } + + Vending.onVendingSkill = function onVendingSkill() + { + //console.log("Vending.onVendingSkill"); + this.setList(CartItems.list); + this.ui.show(); + }; + + + Vending.onSubmit = function onSubmit() + { + + var output; + var i, count,shopname,ctr = 0; + + output = []; + count = _output.length; + + shopname = this.ui.find('.shopname').val(); + + for (i = 0; i < count; ++i) { + if (_output[i] && _output[i].count) { + output.push(_output[i]); + ctr++; + } + } + + if(ctr < 1) + { + this.onRemove(); + return; + } + + var pkt = new PACKET.CZ.REQ_OPENSTORE2(); + pkt.storeName = shopname; + pkt.result = 1; + pkt.storeList = output; + + if(!shopname) + { + InputBox.append(); + InputBox.setType('shopname', false, shopname); + InputBox.onSubmitRequest = function(shopname) { + InputBox.remove(); + pkt.storeName = shopname; + if(shopname) + { + this._shopname = shopname; + Network.sendPacket(pkt); + } + }; + } + else + { + this._shopname = shopname; + Network.sendPacket(pkt); + } + + this.onRemove(); + + }; + + + /** + * Create componentand export it + */ + return UIManager.addComponent(Vending); +}); \ No newline at end of file diff --git a/src/UI/Components/VendingShop/VendingShop.css b/src/UI/Components/VendingShop/VendingShop.css new file mode 100644 index 0000000..2d26737 --- /dev/null +++ b/src/UI/Components/VendingShop/VendingShop.css @@ -0,0 +1,24 @@ +#vendingshop { position:absolute; top:100px; left:100px; font-size:12px; } +#vendingshop table { border-spacing:0px; display:inline-block; } + +#vendingshop .titlebar { width:100%; height:17px; background-color:white; background-repeat:repeat-x; border-radius:3px 3px 0px 0px; } +#vendingshop .titlebar .base { width:11px; height:11px; border:none; background-color:transparent; background-repeat:no-repeat; vertical-align:middle; } +#vendingshop .titlebar .text { text-shadow:1px 1px white; vertical-align:-2px; white-space:nowrap; + /* chrome bug */ display: inline-block; width: 32px; height:13px; } +#vendingshop .titlebar .left { margin-left:3px; float:left; } +#vendingshop .titlebar .clear { clear:both; } + +#vendingshop .container { padding-left: 16px; border-right:1px solid #ccc; background:white; } +#vendingshop .ff_bugfix { position:relative; width: 100%; height: 100%; } +#vendingshop .hide { height:100%; width:16px; position:absolute; top:0px; right:0px; background-color:white;} +#vendingshop .content { overflow:auto; width:100%; height:100%; min-height:65px; background-color:transparent; background-repeat:repeat; } + +#vendingshop .content .item { display:block; width:24px; height:24px; margin:4px 4px 4px 4px; position:relative; float:left; } +#vendingshop .content .item .icon { width:24px; height:24px; border:none; background-color:transparent; background-repeat:no-repeat; } +#vendingshop .overlay { position:absolute; display:none; white-space:nowrap; z-index:900; height:13px; padding:5px; background:rgba(0,0,0,0.7); color:white; text-shadow:1px 1px black;} +#vendingshop .overlay.grey { color:#aaa; } +#vendingshop .content .item .amount { position:relative; font-size:11px; bottom:9px; right:0px; text-align:right; text-shadow:-1px -1px white; } + +#vendingshop .footer { width:100%; height:27px; background-repeat:repeat-x; background-color:transparent; position:relative; border-right:1px solid #ccc; } +#vendingshop .footer .right { float:right; margin-right:3px;} +#vendingshop .btn { width:42px; height:20px; border:none; margin:0; background-color:transparent; background-repeat:no-repeat; } diff --git a/src/UI/Components/VendingShop/VendingShop.html b/src/UI/Components/VendingShop/VendingShop.html new file mode 100644 index 0000000..63267cb --- /dev/null +++ b/src/UI/Components/VendingShop/VendingShop.html @@ -0,0 +1,28 @@ +
+
+
+ +
+
+
+
+
+ + + + + + + +
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/UI/Components/VendingShop/VendingShop.js b/src/UI/Components/VendingShop/VendingShop.js new file mode 100644 index 0000000..a7618ab --- /dev/null +++ b/src/UI/Components/VendingShop/VendingShop.js @@ -0,0 +1,577 @@ +/** + * UI/Components/VendingShop/VendingShop.js + * + * Character VendingShop Inventory + * + * This file is part of ROBrowser, Ragnarok Online in the Web Browser (http://www.robrowser.com/). + * + * @author Vincent Thibault + * In some cases the client will send packet twice.eg NORMAL_ITEMLIST4; fixit [skybook888] + * + */ +define(function(require) +{ + 'use strict'; + + + /** + * Dependencies + */ + var DB = require('DB/DBManager'); + var ItemType = require('DB/Items/ItemType'); + var jQuery = require('Utils/jquery'); + var Network = require('Network/NetworkManager'); + var PACKET = require('Network/PacketStructure'); + var Client = require('Core/Client'); + var Preferences = require('Core/Preferences'); + var Mouse = require('Controls/MouseEventHandler'); + var Renderer = require('Renderer/Renderer'); + var UIManager = require('UI/UIManager'); + var UIComponent = require('UI/UIComponent'); + var ItemInfo = require('UI/Components/ItemInfo/ItemInfo'); + var Session = require('Engine/SessionStorage'); + var Vending = require('UI/Components/Vending/Vending'); + var htmlText = require('text!./VendingShop.html'); + var cssText = require('text!./VendingShop.css'); + var getModule = require; + + + /** + * Create Component + */ + var VendingShop = new UIComponent( 'VendingShop', htmlText, cssText ); + + + + /** + * Store inventory items + */ + VendingShop.list = []; + + + /** + * @var {number} used to remember the window height + */ + var _realSize = 0; + + + var _vendcount = 0; + + + /** + * @var {Preferences} structure + */ + var _preferences = Preferences.get('VendingShop', { + x: 200, + y: 200, + width: 8, + height: 2, + reduce: false + }, 1.0); + + + /** + * Initialize UI + */ + VendingShop.init = function Init() + { + // Bind buttons + this.ui.find('.btn.close').click(function(){ + VendingShop.onSubmit(); + }); + // on drop item + this.ui + .on('drop', onDrop) + .on('dragover', stopPropagation) + + // Items event + .find('.container .content') + .on('mousewheel DOMMouseScroll', onScroll) + .on('mouseover', '.item', onItemOver) + .on('mouseout', '.item', onItemOut) + .on('dragstart', '.item', onItemDragStart) + .on('dragend', '.item', onItemDragEnd) + .on('contextmenu', '.item', onItemInfo) + .on('dblclick', '.item', onItemUsed); + + this.draggable(this.ui.find('.titlebar')); + }; + + + /** + * Apply preferences once append to body + */ + VendingShop.onAppend = function OnAppend() + { + this.resize( _preferences.width, _preferences.height ); + + this.ui.css({ + top: Math.min( Math.max( 0, _preferences.y), Renderer.height - this.ui.height()), + left: Math.min( Math.max( 0, _preferences.x), Renderer.width - this.ui.width()) + }); + + _realSize = _preferences.reduce ? 0 : this.ui.height(); + + this.ui.find('.text.shopname').text("My Shop : "+Vending._shopname); + }; + + + /** + * Remove Inventory from window (and so clean up items) + */ + VendingShop.onRemove = function OnRemove() + { + + this.ui.find('.container .content').empty(); + this.list.length = 0; + jQuery('.ItemInfo').remove(); + + // Save preferences + _preferences.reduce = !!_realSize; + _preferences.y = parseInt(this.ui.css('top'), 10); + _preferences.x = parseInt(this.ui.css('left'), 10); + _preferences.width = Math.floor( (this.ui.width() - (23 + 16 + 16 - 30)) / 32 ); + _preferences.height = Math.floor( (this.ui.height() - (31 + 19 - 30 )) / 32 ); + _preferences.save(); + + this.ui.hide(); + + }; + + + /** + * Extend inventory window size + * + * @param {number} width + * @param {number} height + */ + VendingShop.resize = function Resize( width, height ) + { + width = Math.min( Math.max(width, 6), 9); + height = Math.min( Math.max(height, 2), 6); + + this.ui.find('.container .content').css({ + width: width * 32 + 13, // 13 = scrollbar + height: height * 32 + }); + + this.ui.css({ + width: 16 + 16 + width * 32, + height: 31 + 19 + height * 32 + }); + }; + + + /** + * Get item object + * + * @param {number} id + * @returns {Item} + */ + VendingShop.getItemById = function GetItemById( id ) + { + var i, count; + var list = VendingShop.list; + + for (i = 0, count = list.length; i < count; ++i) { + if (list[i].ITID === id) { + return list[i]; + } + } + + return null; + }; + + + /** + * Search in a list for an item by its index + * + * @param {number} index + * @returns {Item} + */ + VendingShop.getItemByIndex = function getItemByIndex( index ) + { + var i, count; + var list = VendingShop.list; + + for (i = 0, count = list.length; i < count; ++i) { + if (list[i].index === index) { + return list[i]; + } + } + + return null; + }; + + + /** + * Add items to the list + * if the item index is exist you should clear it;[skybook888] + */ + VendingShop.setItems = function setItems(items) + { + var i, count; + + for (i = 0, count = items.length; i < count ; ++i) { + var object= this.getItemByIndex(items[i].index); + if(object){ + var item=this.removeItem(object.index,object.count); + } + if(this.addItemSub(items[i])){ + this.list.push(items[i]); + } + } + + this.ui.show(); + }; + + + /** + * Insert Item to inventory + * + * @param {object} Item + */ + VendingShop.addItem = function AddItem( item ) + { + var object = this.getItemByIndex(item.index); + //console.log("add"); + + if (object) { + object.count += item.count; + this.ui.find('.item[data-index="'+ item.index +'"] .count').text( object.count ); + return; + } + + object = jQuery.extend({}, item); + if (this.addItemSub(object)) { + this.list.push(object); + } + }; + + + /** + * Add item to inventory + * + * @param {object} Item + */ + VendingShop.addItemSub = function AddItemSub( item ) + { + // Equip item (if not arrow) + if (item.WearState && item.type !== ItemType.AMMO && item.type !== ItemType.CARD) { + //Equipment.equip(item); + return false; + } + + var it = DB.getItemInfo( item.ITID ); + var content = this.ui.find('.container .content'); + + content.append( + '
' + + '
' + + '
' + (item.count || 1) + '
' + + '
' + ); + + if (content.height() < content[0].scrollHeight) { + this.ui.find('.hide').hide(); + } + else { + this.ui.find('.hide').show(); + } + + Client.loadFile( DB.INTERFACE_PATH + 'item/' + ( item.IsIdentified ? it.identifiedResourceName : it.unidentifiedResourceName ) + '.bmp', function(data){ + content.find('.item[data-index="'+ item.index +'"] .icon').css('backgroundImage', 'url('+ data +')'); + }); + return true; + }; + + + /** + * Remove item from inventory + * + * @param {number} index in inventory + * @param {number} count + */ + VendingShop.removeItem = function RemoveItem( index, count ) + { + var i,ctr; + var item = this.getItemByIndex(index); + + // Emulator failed to complete the operation + // do not remove item from inventory + if (!item || count <= 0) { + return null; + } + + + if (item.count) { + item.count -= count; + + if (item.count > 0) { + this.ui.find('.item[data-index="'+ item.index +'"] .count').text( item.count ); + return item; + } + } + + this.list.splice( this.list.indexOf(item), 1 ); + this.ui.find('.item[data-index="'+ item.index +'"]').remove(); + + ctr = 0; + for(i=0; i < this.list.length; i++) + { + if(this.list[i].count > 0) + { + ctr++; + } + } + + if(ctr == 0) + { + this.onSubmit(); + } +/* + var content = this.ui.find('.container .content'); + if (content.height() === content[0].scrollHeight) { + this.ui.find('.hide').show(); + } +*/ + return item; + }; + + + /** + * Remove item from inventory + * + * @param {number} index in inventory + * @param {number} count + */ + VendingShop.updateItem = function UpdateItem( index, count ) + { + var item = this.getItemByIndex(index); + + if (!item) { + return; + } + + item.count = count; + + // Update quantity + if (item.count > 0) { + this.ui.find('.item[data-index="'+ item.index +'"] .count').text( item.count ); + return; + } + + // no quantity, remove + this.list.splice( this.list.indexOf(item), 1 ); + this.ui.find('.item[data-index="'+ item.index +'"]').remove(); + + var content = this.ui.find('.container .content'); + if (content.height() === content[0].scrollHeight) { + this.ui.find('.hide').show(); + } + }; + + + + /** + * Stop event propagation + */ + function stopPropagation( event ) + { + event.stopImmediatePropagation(); + return false; + } + + /** + * Hide/show inventory's content + */ + function onToggleReduction() + { + var ui = VendingShop.ui; + + if (_realSize) { + ui.find('.panel').show(); + ui.height(_realSize); + _realSize = 0; + } + else { + _realSize = ui.height(); + ui.height(17); + ui.find('.panel').hide(); + } + } + + + /** + * Update tab, reset inventory content + */ + function requestFilter() + { + VendingShop.ui.find('.container .content').empty(); + + var list = VendingShop.list; + var i, count; + + for (i = 0, count = list.length; i < count; ++i) { + VendingShop.addItemSub( list[i] ); + } + } + + + /** + * Drop an item from storage to inventory + * + * @param {event} + */ + function onDrop( event ) + { + event.stopImmediatePropagation(); + return false; + } + + + /** + * Block the scroll to move 32px at each move + */ + function onScroll( event ) + { + var delta; + + if (event.originalEvent.wheelDelta) { + delta = event.originalEvent.wheelDelta / 120 ; + if (window.opera) { + delta = -delta; + } + } + else if (event.originalEvent.detail) { + delta = -event.originalEvent.detail; + } + + this.scrollTop = Math.floor(this.scrollTop/32) * 32 - (delta * 32); + event.stopImmediatePropagation(); + return false; + } + + + /** + * Show item name when mouse is over + */ + function onItemOver() + { + var idx = parseInt( this.getAttribute('data-index'), 10); + var item = VendingShop.getItemByIndex(idx); + + if (!item) { + return; + } + + // Get back data + var pos = jQuery(this).position(); + var overlay = VendingShop.ui.find('.overlay'); + + // Display box + overlay.show(); + overlay.css({top: pos.top, left:pos.left+35}); + overlay.text(DB.getItemName(item) + ' ' + (item.count || 1) + ' ea'); + + if (item.IsIdentified) { + overlay.removeClass('grey'); + } + else { + overlay.addClass('grey'); + } + } + + + /** + * Hide the item name + */ + function onItemOut() + { + VendingShop.ui.find('.overlay').hide(); + } + + + /** + * Start dragging an item + */ + function onItemDragStart( event ) + { + return; + } + + + /** + * Stop dragging an item + * + */ + function onItemDragEnd() + { + delete window._OBJ_DRAG_; + } + + + /** + * Get item info (open description window) + */ + function onItemInfo( event ) + { + event.stopImmediatePropagation(); + + var index = parseInt(this.getAttribute('data-index'), 10); + var item = VendingShop.getItemByIndex(index); + + if (!item) { + return false; + } + + // Don't add the same UI twice, remove it + if (ItemInfo.uid === item.ITID) { + ItemInfo.remove(); + return false; + } + + // Add ui to window + ItemInfo.append(); + ItemInfo.uid = item.ITID; + ItemInfo.setItem(item); + + return false; + } + + + /** + * Ask to use an item + */ + function onItemUsed( event ) + { + var index = parseInt(this.getAttribute('data-index'), 10); + var item = VendingShop.getItemByIndex(index); + + if (item) { + VendingShop.useItem(item); + onItemOut(); + } + + event.stopImmediatePropagation(); + return false; + } + + /** + * Submit data to send items + */ + VendingShop.onSubmit = function onSubmit() + { + var pkt; + pkt = new PACKET.CZ.REQ_CLOSESTORE(); + Network.sendPacket(pkt); + this.onRemove(); + }; + + + + /** + * Create component and export it + */ + return UIManager.addComponent(VendingShop); +}); \ No newline at end of file diff --git a/src/UI/Components/WinLogin/WinLogin.css b/src/UI/Components/WinLogin/WinLogin.css index 6875393..fdeccad 100755 --- a/src/UI/Components/WinLogin/WinLogin.css +++ b/src/UI/Components/WinLogin/WinLogin.css @@ -5,4 +5,24 @@ #win_login .save { position:absolute; top:32px; right:10px; display:block; width:38px; height:10px; border:none; background-color:transparent; background-repeat:no-repeat; } #win_login .btn { position:absolute; border:0; width:42px; height:20px; bottom:4px; background-color:transparent; } #win_login .btn.connect { right:50px; } -#win_login .btn.exit { right:5px; } \ No newline at end of file +#win_login .btn.exit { right:5px; } +#win_login .btnfb { position:absolute; border:0; width:150px; height:20px; bottom:4px; } +#win_login .btnfb.facebook_button { + left:5px; + display: inline-block; + background: #627aac url(img/facebook_small.png) left no-repeat; + border-top: 1px solid #29447e; + border-right: 1px solid #29447e; + border-bottom: 1px solid #1a356e; + border-left: none; + height: 22px; + padding-right: 7px; + padding-left: 29px; + font-weight: bold; + font-size: 10px; + color: white; + text-decoration: none; + font-family: "lucida grande", tahoma, verdana, arial, sans-serif; + line-height: 22px; + cursor: pointer; +} diff --git a/src/UI/Components/WinLogin/WinLogin.html b/src/UI/Components/WinLogin/WinLogin.html index 4b1c42c..b03a41e 100755 --- a/src/UI/Components/WinLogin/WinLogin.html +++ b/src/UI/Components/WinLogin/WinLogin.html @@ -7,4 +7,6 @@ + + \ No newline at end of file diff --git a/src/UI/Components/WinLogin/WinLogin.js b/src/UI/Components/WinLogin/WinLogin.js index f40f754..538bb05 100644 --- a/src/UI/Components/WinLogin/WinLogin.js +++ b/src/UI/Components/WinLogin/WinLogin.js @@ -17,6 +17,7 @@ define(function(require) */ var DB = require('DB/DBManager'); var Client = require('Core/Client'); + var Configs = require('Core/Configs'); var Preferences = require('Core/Preferences'); var Renderer = require('Renderer/Renderer'); var KEYS = require('Controls/KeyEventHandler'); @@ -59,6 +60,7 @@ define(function(require) var _buttonSave; + /** * Initialize win_login UI - Inherit from UIComponent */ @@ -82,6 +84,7 @@ define(function(require) // Connect / Exit ui.find('.connect').click(connect); ui.find('.exit').click(exit); + ui.find('.facebook_button').click(fblogin); }; @@ -157,6 +160,12 @@ define(function(require) return false; } + function fblogin() + { + var fburl = Configs.get('fbloginurl'); + window.open(fburl,'_parent'); + } + /** * When the user click on Exit, or pressed "Escape"