From cdb72ce1589cf7e131ebe71f7e23923e70c4459b Mon Sep 17 00:00:00 2001 From: Big Bad Waffle Date: Wed, 1 Mar 2017 20:45:01 +0200 Subject: [PATCH] Fixes #25 --- src/client/js/input.js | 1 + .../ui/templates/inventory/inventory.js | 21 +++++++- src/client/ui/templates/messages/messages.js | 52 ++++++++++++++++--- src/server/components/social.js | 1 + 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/client/js/input.js b/src/client/js/input.js index b7d7e34f..e5b00f95 100644 --- a/src/client/js/input.js +++ b/src/client/js/input.js @@ -22,6 +22,7 @@ define([ '9': 'tab', '13': 'enter', '16': 'shift', + '17': 'ctrl', '27': 'esc', '37': 'left', '38': 'up', diff --git a/src/client/ui/templates/inventory/inventory.js b/src/client/ui/templates/inventory/inventory.js index 99f8b80f..f83bec0f 100644 --- a/src/client/ui/templates/inventory/inventory.js +++ b/src/client/ui/templates/inventory/inventory.js @@ -47,6 +47,7 @@ define([ items: [], shiftDown: false, + ctrlDown: false, dragItem: null, dragEl: null, @@ -127,7 +128,7 @@ define([ itemEl .data('item', item) - //.on('click', this.onClick.bind(this, itemEl, item)) + .on('click', this.onClick.bind(this, item)) .on('mousedown', this.onMouseDown.bind(this, itemEl, item, true)) .on('mouseup', this.onMouseDown.bind(this, null, null, false)) .on('mousemove', this.onHover.bind(this, itemEl, item)) @@ -150,6 +151,20 @@ define([ } }, + onClick: function(item) { + if (!this.ctrlDown) + return; + + client.request({ + cpn: 'social', + method: 'chat', + data: { + message: '{' + item.name + '}', + item: item + } + }); + }, + onMouseDown: function(el, item, down, e) { if (e.button != 0) return; @@ -467,6 +482,8 @@ define([ if (this.hoverItem) this.onHover(); } + else if (key == 'ctrl') + this.ctrlDown = true; }, onKeyUp: function(key) { if (key == 'shift') { @@ -474,6 +491,8 @@ define([ if (this.hoverItem) this.onHover(); } + else if (key == 'ctrl') + this.ctrlDown = false; } }; }); \ No newline at end of file diff --git a/src/client/ui/templates/messages/messages.js b/src/client/ui/templates/messages/messages.js index d6360594..caea15de 100644 --- a/src/client/ui/templates/messages/messages.js +++ b/src/client/ui/templates/messages/messages.js @@ -17,12 +17,12 @@ define([ messages: [], maxTtl: 500, + shiftDown: false, + hoverItem: null, + hoverFilter: false, postRender: function() { - //HACK: Write a global manager - //setInterval(this.fade.bind(this), 100); - this.onEvent('onGetMessages', this.onGetMessages.bind(this)); this.onEvent('onDoWhisper', this.onDoWhisper.bind(this)); @@ -53,9 +53,8 @@ define([ }, onKeyDown: function(key, state) { - if (key == 'enter') { + if (key == 'enter') this.toggle(true); - } }, onDoWhisper: function(charName) { @@ -75,7 +74,13 @@ define([ var container = this.find('.list'); messages.forEach(function(m) { - var el = $('
' + m.message + '
') + var message = m.message; + if (m.item) { + var source = message.split(':')[0] + ': '; + message = source + '' + message.replace(source, '') + ''; + } + + var el = $('
' + message + '
') .appendTo(container); if (m.type != null) @@ -83,6 +88,12 @@ define([ else el.addClass('info'); + if (m.item) { + el.find('span') + .on('mousemove', this.showItemTooltip.bind(this, el, m.item)) + .on('mouseleave', this.hideItemTooltip.bind(this)); + } + this.messages.push({ ttl: this.maxTtl, el: el @@ -92,6 +103,35 @@ define([ container.scrollTop(9999999); }, + hideItemTooltip: function() { + if (this.dragEl) { + this.hoverCell = null; + return; + } + + events.emit('onHideItemTooltip', this.hoverItem); + this.hoverItem = null; + }, + showItemTooltip: function(el, item, e) { + if (item) + this.hoverItem = item; + else + item = this.hoverItem; + + if (!item) + return; + + var ttPos = null; + if (el) { + ttPos = { + x: ~~(e.clientX + 32), + y: ~~(e.clientY) + }; + } + + events.emit('onShowItemTooltip', item, ttPos, null, true); + }, + update: function() { return; var maxTtl = this.maxTtl; diff --git a/src/server/components/social.js b/src/server/components/social.js index 70cfa89e..0b84ed3a 100644 --- a/src/server/components/social.js +++ b/src/server/components/social.js @@ -130,6 +130,7 @@ define([ messages: [{ class: msgStyle, message: prefix + charname + ': ' + msg.data.message, + item: msg.data.item, type: 'chat' }] }