Skip to content

Commit 68cd582

Browse files
committed
finish work on the tooltips
1 parent 8d903e7 commit 68cd582

1 file changed

Lines changed: 166 additions & 10 deletions

File tree

src/plugin.ts

Lines changed: 166 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ export default class MwRandomizer {
213213
this.analyzeLabel = "Filler";
214214

215215
let newOffY = 0;
216-
let flags = sc.multiworld.locationInfo[this.mwCheck.mwids[0]].flags;
216+
this.rawChest = sc.multiworld.locationInfo[this.mwCheck.mwids[0]];
217+
let flags = this.rawChest.flags;
217218
if (flags & (ap.ITEM_FLAGS.NEVER_EXCLUDE | ap.ITEM_FLAGS.TRAP)) {
218219
// USEFUL and TRAP items get a blue chest
219220
newOffY = 80;
@@ -248,15 +249,20 @@ export default class MwRandomizer {
248249
},
249250

250251
getQuickMenuSettings() {
251-
return {
252-
disabled: this.isOpen || (this.hideManager && this.hideManager.hidden),
253-
type: "Analyzable",
254-
color: this.analyzeColor ?? 0,
255-
text: this.mwCheck
256-
? `\\c[4]${this.mwCheck.name}\\c[0]\nType: \\c[3]${this.analyzeLabel}\\c[3]`
257-
: "\\c[1]Not in logic",
258-
259-
};
252+
let disabled = this.isOpen || (this.hideManager && this.hideManager.hidden);
253+
if (this.mwCheck) {
254+
return {
255+
type: "Chest",
256+
disabled: disabled,
257+
};
258+
} else {
259+
return {
260+
type: "Analyzable",
261+
disabled: disabled,
262+
color: this.analyzeColor ?? 0,
263+
text: "\\c[1]Not in logic",
264+
}
265+
}
260266
},
261267

262268
_reallyOpenUp() {
@@ -284,6 +290,156 @@ export default class MwRandomizer {
284290
},
285291
});
286292

293+
sc.QUICK_MENU_TYPES.Chest = sc.QuickMenuTypesBase.extend({
294+
init(type, settings, screen) {
295+
this.parent(type, settings, screen);
296+
this.setIconColor(settings.entity.analyzeColor);
297+
},
298+
});
299+
300+
sc.QUICK_INFO_BOXES.Chest = ig.BoxGui.extend({
301+
ninepatch: new ig.NinePatch("media/gui/menu.png", {
302+
width: 8,
303+
height: 8,
304+
left: 8,
305+
top: 8,
306+
right: 8,
307+
bottom: 8,
308+
offsets: { default: { x: 432, y: 304 }, flipped: { x: 456, y: 304 } },
309+
}),
310+
transitions: {
311+
HIDDEN: {
312+
state: { alpha: 0 },
313+
time: 0.2,
314+
timeFunction: KEY_SPLINES.LINEAR,
315+
},
316+
DEFAULT: { state: {}, time: 0.2, timeFunction: KEY_SPLINES.EASE },
317+
},
318+
319+
init() {
320+
this.parent(127, 100);
321+
this.areaGui = new sc.TextGui("", { font: sc.fontsystem.tinyFont });
322+
this.areaGui.setPos(12, 6);
323+
this.addChildGui(this.areaGui);
324+
this.locationGui = new sc.TextGui("", {
325+
font: sc.fontsystem.smallFont,
326+
maxWidth: 115,
327+
});
328+
this.locationGui.setPos(8, 19);
329+
this.addChildGui(this.locationGui);
330+
331+
this.line = new sc.LineGui(117);
332+
this.line.setPos(5, 16);
333+
this.addChildGui(this.line);
334+
335+
this.clearance = new sc.TextGui("", { font: sc.fontsystem.tinyFont });
336+
this.clearance.setPos(5, 13);
337+
this.clearance.setAlign(ig.GUI_ALIGN.X_RIGHT, ig.GUI_ALIGN.Y_TOP);
338+
this.addChildGui(this.clearance);
339+
340+
this.arrow = new sc.QuickItemArrow();
341+
this.addChildGui(this.arrow);
342+
343+
this.typeGui = new sc.TextGui("", { font: sc.fontsystem.tinyFont });
344+
this.typeGui.setPos(6, 6);
345+
this.typeGui.setAlign(ig.GUI_ALIGN.X_LEFT, ig.GUI_ALIGN.Y_BOTTOM);
346+
this.addChildGui(this.typeGui);
347+
},
348+
349+
show(tooltip) {
350+
let chest = tooltip.entity;
351+
if (!this.setData(chest)) {
352+
return;
353+
}
354+
this.alignToBase(tooltip.hook);
355+
this.doStateTransition("DEFAULT");
356+
this.active = true;
357+
},
358+
359+
hide() {
360+
this.doStateTransition("HIDDEN");
361+
this.active = false;
362+
},
363+
364+
setData(chest) {
365+
if (!chest.mwCheck) {
366+
return false;
367+
}
368+
369+
let [area, location] = chest.mwCheck.name.split(" - ");
370+
let level = null;
371+
const match = RegExp("(.+) \\((.+)\\)").exec(location);
372+
if (match) {
373+
location = match[1];
374+
level = match[2];
375+
}
376+
377+
this.areaGui.setText(`\\c[4]${area}\\c[0]`);
378+
this.locationGui.setText(location);
379+
if (level) {
380+
this.clearance.setText(`\\c[3]${level}\\c[0]`);
381+
this.line.hook.size.x = 114 - this.clearance.hook.size.x;
382+
} else {
383+
this.clearance.setText("");
384+
this.line.hook.size.x = 117;
385+
}
386+
387+
this.hook.size.y = 33 + this.locationGui.hook.size.y;
388+
389+
this.typeGui.setText(`Type: \\c[3]${chest.analyzeLabel}\\c[0]`);
390+
391+
return true;
392+
},
393+
394+
alignToBase: function (otherHook) {
395+
let hook = this.hook;
396+
let invisible = hook.currentState.alpha == 0;
397+
398+
let vec = Vec2.createC(0, 0);
399+
vec.x = otherHook.pos.x + Math.floor(otherHook.size.x / 2);
400+
vec.y = otherHook.pos.y + Math.floor(otherHook.size.y / 2);
401+
402+
let above = vec.y - 25;
403+
404+
vec.y = Math.max(10, Math.min(ig.system.height - this.hook.size.y - 10, above));
405+
406+
if (invisible) {
407+
hook.pos.y = vec.y;
408+
}
409+
410+
var arrowY = 17 + (above - vec.y);
411+
if (vec.x + 173 < ig.system.width) {
412+
this.currentTileOffset = "default";
413+
if (invisible) hook.pos.x = vec.x + 20 + 10;
414+
hook.doPosTranstition(vec.x + 20, vec.y, 0.2, KEY_SPLINES.EASE);
415+
this.arrow.setPosition(-10, Math.max(7, Math.min(hook.size.y - 15, arrowY)), false);
416+
} else {
417+
this.currentTileOffset = "flipped";
418+
if (invisible) hook.pos.x = vec.x - hook.size.x - 20 - 10 - 1;
419+
hook.doPosTranstition(
420+
vec.x - hook.size.x - 20 - 1,
421+
vec.y,
422+
0.2,
423+
KEY_SPLINES.EASE,
424+
);
425+
this.arrow.setPosition(
426+
hook.size.x + 1,
427+
Math.max(7, Math.min(hook.size.y - 15, arrowY)),
428+
true,
429+
);
430+
}
431+
432+
this.arrow.bottomAnchor = false;
433+
this.arrow.flipY = false;
434+
if (arrowY < 7) {
435+
this.arrow.bottomAnchor = true;
436+
this.arrow.flipY = true;
437+
} else if (arrowY > hook.size.y - 15) {
438+
this.arrow.bottomAnchor = true;
439+
}
440+
},
441+
});
442+
287443
ig.EVENT_STEP.SET_PLAYER_CORE.inject({
288444
start() {
289445
if (

0 commit comments

Comments
 (0)