BlueGit

timfa questward

Merge branch 'fix/trade-item-icons-flash'

timfa Tim Falken · pushed by timfa

Authored 2026-09-04 · 2 months ago

Hash
b1219b6913eb4357eec3734780dda10e2578b5b9
2 files changed +250 −62
client/src/play/trade.js +211 −62
@@ -44,6 +44,9 @@ export function initTrade ({
44 44 const qtyClose = document.getElementById("trade-qty-close");
45 45 const bagPanel = document.getElementById("bag-panel");
46 46
47 const ACCEPT_LOCK_MS = 3000;
48 const FLASH_MS = 700;
49
47 50 let open = false;
48 51 let partnerName = "";
49 52 let partnerEntityId = null;
@@ -56,6 +59,8 @@ export function initTrade ({
56 59 /** @type {Map<string, { dismiss: () => void }>} */
57 60 const inviteToasts = new Map();
58 61 let pendingQty = null;
62 let acceptUnlockAt = 0;
63 let acceptUnlockTimer = null;
59 64
60 65 function suppressWorldClick (event)
61 66 {
@@ -115,15 +120,164 @@ export function initTrade ({
115 120 theyAccepted = false;
116 121 yourOffer = [];
117 122 theirOffer = [];
123 acceptUnlockAt = 0;
124 if (acceptUnlockTimer != null)
125 {
126 window.clearTimeout(acceptUnlockTimer);
127 acceptUnlockTimer = null;
128 }
118 129 onTradeOpenChanged?.(false);
119 130 }
120 131
121 function renderOfferGrid (el, lines, { theirs = false } = {})
132 function offerLineKey (line)
133 {
134 return `${line.bagSlotIndex | 0}|${line.itemId | 0}|${line.quantity | 0}`;
135 }
136
137 function diffOfferLines (previous, next)
138 {
139 const prevBySlot = new Map((previous ?? []).map((line) => [line.bagSlotIndex | 0, line]));
140 const nextBySlot = new Map((next ?? []).map((line) => [line.bagSlotIndex | 0, line]));
141 /** @type {Set<string>} */
142 const addedKeys = new Set();
143 /** @type {Set<string>} */
144 const redKeys = new Set();
145 /** @type {any[]} */
146 const removedLines = [];
147 for (const [slot, line] of nextBySlot)
148 {
149 const old = prevBySlot.get(slot);
150 if (!old)
151 { addedKeys.add(offerLineKey(line)); }
152 else if (offerLineKey(old) !== offerLineKey(line))
153 {
154 if ((line.quantity | 0) > (old.quantity | 0))
155 { addedKeys.add(offerLineKey(line)); }
156 else
157 { redKeys.add(offerLineKey(line)); }
158 }
159 }
160 for (const [slot, line] of prevBySlot)
161 {
162 if (!nextBySlot.has(slot))
163 { removedLines.push(line); }
164 }
165 return {
166 addedKeys,
167 redKeys,
168 removedLines,
169 changed: addedKeys.size > 0 || redKeys.size > 0 || removedLines.length > 0
170 };
171 }
172
173 function acceptLocked ()
174 {
175 return Date.now() < acceptUnlockAt;
176 }
177
178 function syncAcceptButton ()
179 {
180 if (!acceptBtn)
181 { return; }
182 acceptBtn.textContent = youAccepted ? "Accepted" : "Accept";
183 acceptBtn.classList.toggle("active", !!youAccepted);
184 acceptBtn.disabled = acceptLocked();
185 }
186
187 function syncStatus ()
188 {
189 if (!statusEl)
190 { return; }
191 if (acceptLocked() && !youAccepted && !theyAccepted)
192 { statusEl.textContent = "Offers changed — wait a moment…"; }
193 else if (youAccepted && theyAccepted)
194 { statusEl.textContent = "Confirming…"; }
195 else if (theyAccepted)
196 { statusEl.textContent = `${partnerName} has accepted.`; }
197 else if (youAccepted)
198 { statusEl.textContent = "Waiting for them to accept…"; }
199 else
200 { statusEl.textContent = ""; }
201 }
202
203 function lockAccept (ms = ACCEPT_LOCK_MS)
204 {
205 acceptUnlockAt = Date.now() + ms;
206 if (acceptUnlockTimer != null)
207 { window.clearTimeout(acceptUnlockTimer); }
208 acceptUnlockTimer = window.setTimeout(() =>
209 {
210 acceptUnlockTimer = null;
211 syncAcceptButton();
212 syncStatus();
213 }, ms);
214 syncAcceptButton();
215 syncStatus();
216 }
217
218 function makeOfferSlot (line, { theirs = false, flash = null } = {})
219 {
220 const btn = document.createElement("button");
221 btn.type = "button";
222 btn.className = "item-slot";
223 if (flash === "add")
224 { btn.classList.add("trade-flash-add"); }
225 else if (flash === "remove")
226 { btn.classList.add("trade-flash-remove", "trade-flash-ghost"); }
227 else if (flash === "down")
228 { btn.classList.add("trade-flash-remove"); }
229 const stack = {
230 itemId: line.itemId,
231 quantity: line.quantity,
232 instance: line.instance ?? null,
233 origins: line.origins ?? undefined
234 };
235 const base = `${line.displayName ?? itemDisplayName(stack)}${
236 line.quantity > 1 ? ` ×${formatQuantity(line.quantity)}` : ""
237 }`;
238 const origin = itemOriginSummary(stack);
239 const desc = line.description || itemDescription(stack);
240 btn.title = [base, origin, desc].filter(Boolean).join("\n");
241 const img = document.createElement("img");
242 img.alt = line.displayName ?? itemDisplayName(stack);
243 img.draggable = false;
244 applyItemIcon(img, stack, itemAssetPathForStack(stack));
245 btn.append(img);
246 if (line.quantity > 1)
247 {
248 const qty = document.createElement("span");
249 qty.className = "qty";
250 qty.textContent = formatQuantity(line.quantity);
251 btn.append(qty);
252 }
253 if (flash === "remove")
254 {
255 btn.disabled = true;
256 window.setTimeout(() => btn.remove(), FLASH_MS);
257 return btn;
258 }
259 if (!theirs && !youAccepted)
260 {
261 btn.addEventListener("click", (event) =>
262 {
263 suppressWorldClick(event);
264 socket.send({
265 type: MessageType.tradeOfferRemove,
266 bagSlotIndex: line.bagSlotIndex
267 });
268 });
269 }
270 else
271 { btn.disabled = true; }
272 return btn;
273 }
274
275 function renderOfferGrid (el, lines, { theirs = false, addedKeys = null, redKeys = null, removedLines = null } = {})
122 276 {
123 277 if (!el)
124 278 { return; }
125 279 el.replaceChildren();
126 if (!lines.length)
280 if (!lines.length && !(removedLines?.length))
127 281 {
128 282 const empty = document.createElement("p");
129 283 empty.className = "hint";
@@ -133,47 +287,16 @@ export function initTrade ({
133 287 }
134 288 for (const line of lines)
135 289 {
136 const btn = document.createElement("button");
137 btn.type = "button";
138 btn.className = "item-slot";
139 const stack = {
140 itemId: line.itemId,
141 quantity: line.quantity,
142 instance: line.instance ?? null,
143 origins: line.origins ?? undefined
144 };
145 const base = `${line.displayName ?? itemDisplayName(stack)}${
146 line.quantity > 1 ? ` ×${formatQuantity(line.quantity)}` : ""
147 }`;
148 const origin = itemOriginSummary(stack);
149 const desc = line.description || itemDescription(stack);
150 btn.title = [base, origin, desc].filter(Boolean).join("\n");
151 applyItemIcon(btn, stack, {
152 resolveSpriteUrl,
153 resolveImage,
154 pathForStack: itemAssetPathForStack
155 });
156 if (line.quantity > 1)
157 {
158 const qty = document.createElement("span");
159 qty.className = "qty";
160 qty.textContent = formatQuantity(line.quantity);
161 btn.append(qty);
162 }
163 if (!theirs && !youAccepted)
164 {
165 btn.addEventListener("click", () =>
166 {
167 socket.send({
168 type: MessageType.tradeOfferRemove,
169 bagSlotIndex: line.bagSlotIndex
170 });
171 });
172 }
173 else
174 { btn.disabled = true; }
175 el.append(btn);
290 const key = offerLineKey(line);
291 let flash = null;
292 if (addedKeys?.has(key))
293 { flash = "add"; }
294 else if (redKeys?.has(key))
295 { flash = "down"; }
296 el.append(makeOfferSlot(line, { theirs, flash }));
176 297 }
298 for (const line of removedLines ?? [])
299 { el.append(makeOfferSlot(line, { theirs, flash: "remove" })); }
177 300 }
178 301
179 302 function render ()
@@ -184,32 +307,46 @@ export function initTrade ({
184 307 { partnerEl.textContent = partnerName ? `Trading with ${partnerName}` : "Trade"; }
185 308 renderOfferGrid(giveGrid, yourOffer, { theirs: false });
186 309 renderOfferGrid(receiveGrid, theirOffer, { theirs: true });
187 if (acceptBtn)
188 {
189 acceptBtn.textContent = youAccepted ? "Accepted" : "Accept";
190 acceptBtn.classList.toggle("active", !!youAccepted);
191 acceptBtn.disabled = false;
192 }
193 if (statusEl)
194 {
195 if (youAccepted && theyAccepted)
196 { statusEl.textContent = "Confirming…"; }
197 else if (theyAccepted)
198 { statusEl.textContent = `${partnerName} has accepted.`; }
199 else if (youAccepted)
200 { statusEl.textContent = "Waiting for them to accept…"; }
201 else
202 { statusEl.textContent = ""; }
203 }
310 syncAcceptButton();
311 syncStatus();
204 312 }
205 313
206 function applyState (message)
314 function applyState (message, { initial = false } = {})
207 315 {
316 const prevYours = yourOffer;
317 const prevTheirs = theirOffer;
208 318 youAccepted = !!message.youAccepted;
209 319 theyAccepted = !!message.theyAccepted;
210 320 yourOffer = message.yourOffer ?? [];
211 321 theirOffer = message.theirOffer ?? [];
212 render();
322
323 const yoursDiff = diffOfferLines(prevYours, yourOffer);
324 const theirsDiff = diffOfferLines(prevTheirs, theirOffer);
325 const offersChanged = !initial && (yoursDiff.changed || theirsDiff.changed);
326
327 if (!open)
328 { return; }
329 if (partnerEl)
330 { partnerEl.textContent = partnerName ? `Trading with ${partnerName}` : "Trade"; }
331 renderOfferGrid(giveGrid, yourOffer, {
332 theirs: false,
333 addedKeys: yoursDiff.addedKeys,
334 redKeys: yoursDiff.redKeys,
335 removedLines: initial ? [] : yoursDiff.removedLines
336 });
337 renderOfferGrid(receiveGrid, theirOffer, {
338 theirs: true,
339 addedKeys: theirsDiff.addedKeys,
340 redKeys: theirsDiff.redKeys,
341 removedLines: initial ? [] : theirsDiff.removedLines
342 });
343 if (offersChanged)
344 { lockAccept(); }
345 else
346 {
347 syncAcceptButton();
348 syncStatus();
349 }
213 350 onTradeOpenChanged?.(true);
214 351 }
215 352
@@ -218,6 +355,16 @@ export function initTrade ({
218 355 open = true;
219 356 partnerName = message.partnerName ?? "Player";
220 357 partnerEntityId = message.partnerEntityId | 0;
358 yourOffer = [];
359 theirOffer = [];
360 youAccepted = false;
361 theyAccepted = false;
362 acceptUnlockAt = 0;
363 if (acceptUnlockTimer != null)
364 {
365 window.clearTimeout(acceptUnlockTimer);
366 acceptUnlockTimer = null;
367 }
221 368 if (panel)
222 369 { panel.hidden = false; }
223 370 // Backdrop is visual-only (pointer-events: none) so the bag stays clickable.
@@ -225,7 +372,7 @@ export function initTrade ({
225 372 { backdrop.hidden = false; }
226 373 setBagRaised(true);
227 374 ensureBagOpen?.();
228 applyState(message);
375 applyState(message, { initial: true });
229 376 }
230 377
231 378 function sendTradeRequest (targetEntityId)
@@ -362,6 +509,8 @@ export function initTrade ({
362 509 acceptBtn?.addEventListener("click", (event) =>
363 510 {
364 511 suppressWorldClick(event);
512 if (acceptLocked())
513 { return; }
365 514 socket.send({ type: MessageType.tradeAccept });
366 515 });
367 516 cancelBtn?.addEventListener("click", (event) =>
@@ -44,6 +44,9 @@ export function initTrade ({
44 const qtyClose = document.getElementById("trade-qty-close");
44 const qtyClose = document.getElementById("trade-qty-close");
45 const bagPanel = document.getElementById("bag-panel");
45 const bagPanel = document.getElementById("bag-panel");
46
46
47 const ACCEPT_LOCK_MS = 3000;
48 const FLASH_MS = 700;
49
47 let open = false;
50 let open = false;
48 let partnerName = "";
51 let partnerName = "";
49 let partnerEntityId = null;
52 let partnerEntityId = null;
@@ -56,6 +59,8 @@ export function initTrade ({
56 /** @type {Map<string, { dismiss: () => void }>} */
59 /** @type {Map<string, { dismiss: () => void }>} */
57 const inviteToasts = new Map();
60 const inviteToasts = new Map();
58 let pendingQty = null;
61 let pendingQty = null;
62 let acceptUnlockAt = 0;
63 let acceptUnlockTimer = null;
59
64
60 function suppressWorldClick (event)
65 function suppressWorldClick (event)
61 {
66 {
@@ -115,15 +120,164 @@ export function initTrade ({
115 theyAccepted = false;
120 theyAccepted = false;
116 yourOffer = [];
121 yourOffer = [];
117 theirOffer = [];
122 theirOffer = [];
123 acceptUnlockAt = 0;
124 if (acceptUnlockTimer != null)
125 {
126 window.clearTimeout(acceptUnlockTimer);
127 acceptUnlockTimer = null;
128 }
118 onTradeOpenChanged?.(false);
129 onTradeOpenChanged?.(false);
119 }
130 }
120
131
121 function renderOfferGrid (el, lines, { theirs = false } = {})
132 function offerLineKey (line)
133 {
134 return `${line.bagSlotIndex | 0}|${line.itemId | 0}|${line.quantity | 0}`;
135 }
136
137 function diffOfferLines (previous, next)
138 {
139 const prevBySlot = new Map((previous ?? []).map((line) => [line.bagSlotIndex | 0, line]));
140 const nextBySlot = new Map((next ?? []).map((line) => [line.bagSlotIndex | 0, line]));
141 /** @type {Set<string>} */
142 const addedKeys = new Set();
143 /** @type {Set<string>} */
144 const redKeys = new Set();
145 /** @type {any[]} */
146 const removedLines = [];
147 for (const [slot, line] of nextBySlot)
148 {
149 const old = prevBySlot.get(slot);
150 if (!old)
151 { addedKeys.add(offerLineKey(line)); }
152 else if (offerLineKey(old) !== offerLineKey(line))
153 {
154 if ((line.quantity | 0) > (old.quantity | 0))
155 { addedKeys.add(offerLineKey(line)); }
156 else
157 { redKeys.add(offerLineKey(line)); }
158 }
159 }
160 for (const [slot, line] of prevBySlot)
161 {
162 if (!nextBySlot.has(slot))
163 { removedLines.push(line); }
164 }
165 return {
166 addedKeys,
167 redKeys,
168 removedLines,
169 changed: addedKeys.size > 0 || redKeys.size > 0 || removedLines.length > 0
170 };
171 }
172
173 function acceptLocked ()
174 {
175 return Date.now() < acceptUnlockAt;
176 }
177
178 function syncAcceptButton ()
179 {
180 if (!acceptBtn)
181 { return; }
182 acceptBtn.textContent = youAccepted ? "Accepted" : "Accept";
183 acceptBtn.classList.toggle("active", !!youAccepted);
184 acceptBtn.disabled = acceptLocked();
185 }
186
187 function syncStatus ()
188 {
189 if (!statusEl)
190 { return; }
191 if (acceptLocked() && !youAccepted && !theyAccepted)
192 { statusEl.textContent = "Offers changed — wait a moment…"; }
193 else if (youAccepted && theyAccepted)
194 { statusEl.textContent = "Confirming…"; }
195 else if (theyAccepted)
196 { statusEl.textContent = `${partnerName} has accepted.`; }
197 else if (youAccepted)
198 { statusEl.textContent = "Waiting for them to accept…"; }
199 else
200 { statusEl.textContent = ""; }
201 }
202
203 function lockAccept (ms = ACCEPT_LOCK_MS)
204 {
205 acceptUnlockAt = Date.now() + ms;
206 if (acceptUnlockTimer != null)
207 { window.clearTimeout(acceptUnlockTimer); }
208 acceptUnlockTimer = window.setTimeout(() =>
209 {
210 acceptUnlockTimer = null;
211 syncAcceptButton();
212 syncStatus();
213 }, ms);
214 syncAcceptButton();
215 syncStatus();
216 }
217
218 function makeOfferSlot (line, { theirs = false, flash = null } = {})
219 {
220 const btn = document.createElement("button");
221 btn.type = "button";
222 btn.className = "item-slot";
223 if (flash === "add")
224 { btn.classList.add("trade-flash-add"); }
225 else if (flash === "remove")
226 { btn.classList.add("trade-flash-remove", "trade-flash-ghost"); }
227 else if (flash === "down")
228 { btn.classList.add("trade-flash-remove"); }
229 const stack = {
230 itemId: line.itemId,
231 quantity: line.quantity,
232 instance: line.instance ?? null,
233 origins: line.origins ?? undefined
234 };
235 const base = `${line.displayName ?? itemDisplayName(stack)}${
236 line.quantity > 1 ? ` ×${formatQuantity(line.quantity)}` : ""
237 }`;
238 const origin = itemOriginSummary(stack);
239 const desc = line.description || itemDescription(stack);
240 btn.title = [base, origin, desc].filter(Boolean).join("\n");
241 const img = document.createElement("img");
242 img.alt = line.displayName ?? itemDisplayName(stack);
243 img.draggable = false;
244 applyItemIcon(img, stack, itemAssetPathForStack(stack));
245 btn.append(img);
246 if (line.quantity > 1)
247 {
248 const qty = document.createElement("span");
249 qty.className = "qty";
250 qty.textContent = formatQuantity(line.quantity);
251 btn.append(qty);
252 }
253 if (flash === "remove")
254 {
255 btn.disabled = true;
256 window.setTimeout(() => btn.remove(), FLASH_MS);
257 return btn;
258 }
259 if (!theirs && !youAccepted)
260 {
261 btn.addEventListener("click", (event) =>
262 {
263 suppressWorldClick(event);
264 socket.send({
265 type: MessageType.tradeOfferRemove,
266 bagSlotIndex: line.bagSlotIndex
267 });
268 });
269 }
270 else
271 { btn.disabled = true; }
272 return btn;
273 }
274
275 function renderOfferGrid (el, lines, { theirs = false, addedKeys = null, redKeys = null, removedLines = null } = {})
122 {
276 {
123 if (!el)
277 if (!el)
124 { return; }
278 { return; }
125 el.replaceChildren();
279 el.replaceChildren();
126 if (!lines.length)
280 if (!lines.length && !(removedLines?.length))
127 {
281 {
128 const empty = document.createElement("p");
282 const empty = document.createElement("p");
129 empty.className = "hint";
283 empty.className = "hint";
@@ -133,47 +287,16 @@ export function initTrade ({
133 }
287 }
134 for (const line of lines)
288 for (const line of lines)
135 {
289 {
136 const btn = document.createElement("button");
290 const key = offerLineKey(line);
137 btn.type = "button";
291 let flash = null;
138 btn.className = "item-slot";
292 if (addedKeys?.has(key))
139 const stack = {
293 { flash = "add"; }
140 itemId: line.itemId,
294 else if (redKeys?.has(key))
141 quantity: line.quantity,
295 { flash = "down"; }
142 instance: line.instance ?? null,
296 el.append(makeOfferSlot(line, { theirs, flash }));
143 origins: line.origins ?? undefined
144 };
145 const base = `${line.displayName ?? itemDisplayName(stack)}${
146 line.quantity > 1 ? ` ×${formatQuantity(line.quantity)}` : ""
147 }`;
148 const origin = itemOriginSummary(stack);
149 const desc = line.description || itemDescription(stack);
150 btn.title = [base, origin, desc].filter(Boolean).join("\n");
151 applyItemIcon(btn, stack, {
152 resolveSpriteUrl,
153 resolveImage,
154 pathForStack: itemAssetPathForStack
155 });
156 if (line.quantity > 1)
157 {
158 const qty = document.createElement("span");
159 qty.className = "qty";
160 qty.textContent = formatQuantity(line.quantity);
161 btn.append(qty);
162 }
163 if (!theirs && !youAccepted)
164 {
165 btn.addEventListener("click", () =>
166 {
167 socket.send({
168 type: MessageType.tradeOfferRemove,
169 bagSlotIndex: line.bagSlotIndex
170 });
171 });
172 }
173 else
174 { btn.disabled = true; }
175 el.append(btn);
176 }
297 }
298 for (const line of removedLines ?? [])
299 { el.append(makeOfferSlot(line, { theirs, flash: "remove" })); }
177 }
300 }
178
301
179 function render ()
302 function render ()
@@ -184,32 +307,46 @@ export function initTrade ({
184 { partnerEl.textContent = partnerName ? `Trading with ${partnerName}` : "Trade"; }
307 { partnerEl.textContent = partnerName ? `Trading with ${partnerName}` : "Trade"; }
185 renderOfferGrid(giveGrid, yourOffer, { theirs: false });
308 renderOfferGrid(giveGrid, yourOffer, { theirs: false });
186 renderOfferGrid(receiveGrid, theirOffer, { theirs: true });
309 renderOfferGrid(receiveGrid, theirOffer, { theirs: true });
187 if (acceptBtn)
310 syncAcceptButton();
188 {
311 syncStatus();
189 acceptBtn.textContent = youAccepted ? "Accepted" : "Accept";
190 acceptBtn.classList.toggle("active", !!youAccepted);
191 acceptBtn.disabled = false;
192 }
193 if (statusEl)
194 {
195 if (youAccepted && theyAccepted)
196 { statusEl.textContent = "Confirming…"; }
197 else if (theyAccepted)
198 { statusEl.textContent = `${partnerName} has accepted.`; }
199 else if (youAccepted)
200 { statusEl.textContent = "Waiting for them to accept…"; }
201 else
202 { statusEl.textContent = ""; }
203 }
204 }
312 }
205
313
206 function applyState (message)
314 function applyState (message, { initial = false } = {})
207 {
315 {
316 const prevYours = yourOffer;
317 const prevTheirs = theirOffer;
208 youAccepted = !!message.youAccepted;
318 youAccepted = !!message.youAccepted;
209 theyAccepted = !!message.theyAccepted;
319 theyAccepted = !!message.theyAccepted;
210 yourOffer = message.yourOffer ?? [];
320 yourOffer = message.yourOffer ?? [];
211 theirOffer = message.theirOffer ?? [];
321 theirOffer = message.theirOffer ?? [];
212 render();
322
323 const yoursDiff = diffOfferLines(prevYours, yourOffer);
324 const theirsDiff = diffOfferLines(prevTheirs, theirOffer);
325 const offersChanged = !initial && (yoursDiff.changed || theirsDiff.changed);
326
327 if (!open)
328 { return; }
329 if (partnerEl)
330 { partnerEl.textContent = partnerName ? `Trading with ${partnerName}` : "Trade"; }
331 renderOfferGrid(giveGrid, yourOffer, {
332 theirs: false,
333 addedKeys: yoursDiff.addedKeys,
334 redKeys: yoursDiff.redKeys,
335 removedLines: initial ? [] : yoursDiff.removedLines
336 });
337 renderOfferGrid(receiveGrid, theirOffer, {
338 theirs: true,
339 addedKeys: theirsDiff.addedKeys,
340 redKeys: theirsDiff.redKeys,
341 removedLines: initial ? [] : theirsDiff.removedLines
342 });
343 if (offersChanged)
344 { lockAccept(); }
345 else
346 {
347 syncAcceptButton();
348 syncStatus();
349 }
213 onTradeOpenChanged?.(true);
350 onTradeOpenChanged?.(true);
214 }
351 }
215
352
@@ -218,6 +355,16 @@ export function initTrade ({
218 open = true;
355 open = true;
219 partnerName = message.partnerName ?? "Player";
356 partnerName = message.partnerName ?? "Player";
220 partnerEntityId = message.partnerEntityId | 0;
357 partnerEntityId = message.partnerEntityId | 0;
358 yourOffer = [];
359 theirOffer = [];
360 youAccepted = false;
361 theyAccepted = false;
362 acceptUnlockAt = 0;
363 if (acceptUnlockTimer != null)
364 {
365 window.clearTimeout(acceptUnlockTimer);
366 acceptUnlockTimer = null;
367 }
221 if (panel)
368 if (panel)
222 { panel.hidden = false; }
369 { panel.hidden = false; }
223 // Backdrop is visual-only (pointer-events: none) so the bag stays clickable.
370 // Backdrop is visual-only (pointer-events: none) so the bag stays clickable.
@@ -225,7 +372,7 @@ export function initTrade ({
225 { backdrop.hidden = false; }
372 { backdrop.hidden = false; }
226 setBagRaised(true);
373 setBagRaised(true);
227 ensureBagOpen?.();
374 ensureBagOpen?.();
228 applyState(message);
375 applyState(message, { initial: true });
229 }
376 }
230
377
231 function sendTradeRequest (targetEntityId)
378 function sendTradeRequest (targetEntityId)
@@ -362,6 +509,8 @@ export function initTrade ({
362 acceptBtn?.addEventListener("click", (event) =>
509 acceptBtn?.addEventListener("click", (event) =>
363 {
510 {
364 suppressWorldClick(event);
511 suppressWorldClick(event);
512 if (acceptLocked())
513 { return; }
365 socket.send({ type: MessageType.tradeAccept });
514 socket.send({ type: MessageType.tradeAccept });
366 });
515 });
367 cancelBtn?.addEventListener("click", (event) =>
516 cancelBtn?.addEventListener("click", (event) =>
client/ui/play.css +39 −0
@@ -364,6 +364,45 @@ body {
364 364 border-color: #4a8a58;
365 365 }
366 366
367 #trade-accept:disabled {
368 opacity: 0.55;
369 cursor: not-allowed;
370 }
371
372 @keyframes trade-flash-add {
373 0%,
374 100% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; }
375 20%,
376 60% { box-shadow: inset 0 0 0 2px #4caf70; background-color: rgba(50, 140, 80, 0.35); }
377 }
378
379 @keyframes trade-flash-remove {
380 0%,
381 100% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; }
382 20%,
383 60% { box-shadow: inset 0 0 0 2px #d45a5a; background-color: rgba(160, 40, 40, 0.4); }
384 }
385
386 @keyframes trade-flash-remove-out {
387 0% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; opacity: 1; }
388 20%,
389 60% { box-shadow: inset 0 0 0 2px #d45a5a; background-color: rgba(160, 40, 40, 0.4); opacity: 1; }
390 100% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; opacity: 0; }
391 }
392
393 .item-slot.trade-flash-add {
394 animation: trade-flash-add 0.7s ease-in-out;
395 }
396
397 .item-slot.trade-flash-remove {
398 animation: trade-flash-remove 0.7s ease-in-out;
399 }
400
401 .item-slot.trade-flash-remove.trade-flash-ghost {
402 animation: trade-flash-remove-out 0.7s ease-in-out forwards;
403 pointer-events: none;
404 }
405
367 406 #trade-qty-backdrop {
368 407 z-index: 24;
369 408 pointer-events: auto;
@@ -364,6 +364,45 @@ body {
364 border-color: #4a8a58;
364 border-color: #4a8a58;
365}
365}
366
366
367#trade-accept:disabled {
368 opacity: 0.55;
369 cursor: not-allowed;
370}
371
372@keyframes trade-flash-add {
373 0%,
374 100% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; }
375 20%,
376 60% { box-shadow: inset 0 0 0 2px #4caf70; background-color: rgba(50, 140, 80, 0.35); }
377}
378
379@keyframes trade-flash-remove {
380 0%,
381 100% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; }
382 20%,
383 60% { box-shadow: inset 0 0 0 2px #d45a5a; background-color: rgba(160, 40, 40, 0.4); }
384}
385
386@keyframes trade-flash-remove-out {
387 0% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; opacity: 1; }
388 20%,
389 60% { box-shadow: inset 0 0 0 2px #d45a5a; background-color: rgba(160, 40, 40, 0.4); opacity: 1; }
390 100% { box-shadow: inset 0 0 0 2px transparent; background-color: transparent; opacity: 0; }
391}
392
393.item-slot.trade-flash-add {
394 animation: trade-flash-add 0.7s ease-in-out;
395}
396
397.item-slot.trade-flash-remove {
398 animation: trade-flash-remove 0.7s ease-in-out;
399}
400
401.item-slot.trade-flash-remove.trade-flash-ghost {
402 animation: trade-flash-remove-out 0.7s ease-in-out forwards;
403 pointer-events: none;
404}
405
367#trade-qty-backdrop {
406#trade-qty-backdrop {
368 z-index: 24;
407 z-index: 24;
369 pointer-events: auto;
408 pointer-events: auto;