[MIRROR] Fix tooltips not working on mobs (#8799)

Co-authored-by: Novacat <35587478+Novacat@users.noreply.github.com>
Co-authored-by: CHOMPStation2 <chompsation2@gmail.com>
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
CHOMPStation2
2024-08-22 13:49:13 -07:00
committed by GitHub
parent a86541a10a
commit 9952dc8d2b
2 changed files with 79 additions and 48 deletions

View File

@@ -37,6 +37,7 @@ Notes:
var/showing = 0
var/queueHide = 0
var/init = 0
var/atom/last_target
/datum/tooltip/New(client/C)
@@ -50,7 +51,15 @@ Notes:
/datum/tooltip/proc/show(atom/movable/thing, params = null, title = null, content = null, theme = "default", special = "none")
if (!thing || !params || (!title && !content) || !owner || !isnum(world.icon_size))
return 0
return FALSE
if (!isnull(last_target))
UnregisterSignal(last_target, COMSIG_PARENT_QDELETING)
RegisterSignal(thing, COMSIG_PARENT_QDELETING, PROC_REF(on_target_qdel))
last_target = thing
if (!init)
//Initialize some vars
init = 1
@@ -71,8 +80,6 @@ Notes:
title = replacetext(title, "\improper", "")
//Make our dumb param object
if(params[1] != "i") //Byond Bug: http://www.byond.com/forum/?post=2352648
params = "icon-x=16;icon-y=16;[params]" //Put in some placeholders
params = {"{ "cursor": "[params]", "screenLoc": "[thing.screen_loc]" }"}
//Send stuff to the tooltip
@@ -84,41 +91,48 @@ Notes:
if (queueHide)
hide()
return 1
return TRUE
/datum/tooltip/proc/hide()
queueHide = showing ? TRUE : FALSE
if (queueHide)
addtimer(CALLBACK(src, PROC_REF(do_hide)), 1)
addtimer(CALLBACK(src, PROC_REF(do_hide)), 0.1 SECONDS)
else
do_hide()
queueHide = showing ? TRUE : FALSE
return TRUE
/datum/tooltip/proc/on_target_qdel()
SIGNAL_HANDLER
INVOKE_ASYNC(src, PROC_REF(hide))
last_target = null
/datum/tooltip/proc/do_hide()
winshow(owner, control, FALSE)
/* TG SPECIFIC CODE */
/datum/tooltip/Destroy(force)
last_target = null
return ..()
//Open a tooltip for user, at a location based on params
//Theme is a CSS class in tooltip.html, by default this wrapper chooses a CSS class based on the user's UI_style (Midnight, Plasmafire, Retro, etc)
//Includes sanity.checks
/proc/openToolTip(mob/user = null, atom/movable/tip_src = null, params = null, title = "", content = "", theme = "")
if(istype(user))
if(user.client && user.client.tooltips)
if(!theme && user.client.prefs && user.client.prefs.tooltipstyle)
theme = lowertext(user.client.prefs.tooltipstyle)
if(!theme)
theme = "midnight"
user.client.tooltips.show(tip_src, params, title, content, theme)
if(!istype(user) || !user.client?.tooltips)
return
var/ui_style = user.client?.prefs?.tooltipstyle
if(!theme && ui_style)
theme = lowertext(ui_style)
if(!theme)
theme = "midnight"
user.client.tooltips.show(tip_src, params, title, content, theme)
//Arbitrarily close a user's tooltip
//Includes sanity checks.
/proc/closeToolTip(mob/user)
if(istype(user))
if(user.client && user.client.tooltips)
user.client.tooltips.hide()
if(!istype(user) || !user.client?.tooltips)
return
user.client.tooltips.hide()

View File

@@ -54,9 +54,6 @@
.cult .wrap {border-color: #292222;}
.cult .content {color: #FF0000; border-color: #4C4343; background-color: #3C3434;}
.clockcult .wrap {border-color: #170800;}
.clockcult .content {color: #B18B25; border-color: #000000; background-color: #5F380E;}
.pod .wrap {border-color: #052401;}
.pod .content {border-color: #326D29; background-color: #569F4B;}
@@ -80,12 +77,19 @@
.slimecore .wrap {border-color: #18640E;}
.slimecore .content {color: #6EA161; border-color: #11450B; background-color: #354E35;}
.operative .wrap {border-color: #1E0101;}
.operative .content {color: #FFFFFF; border-color: #750000; background-color: #350000;}
.operative .wrap {border-color: #13121b;}
.operative .content {color: #b01232; border-color: #13121b; background-color: #282831;}
/* ChompKeep Start */
.clockwork .wrap {border-color: #170800;}
.clockwork .content {color: #B18B25; border-color: #000000; background-color: #5F380E;}
/* ChompKeep End */
.trasen-knox .wrap {border-color: #998e81;}
.trasen-knox .content {color: #3ce375; border-color: #998e81; background-color: #1e1d21;}
.detective .wrap {border-color: #2c0F0c;}
.detective .wrap {color: #c7b08b; border-color: #2c0F0c; background-color: #221c1a;}
</style>
</head>
@@ -120,32 +124,45 @@
window.location = 'byond://winset?id='+tooltip.control+';anchor1=0,0;size=999x999';
//Get the real icon size according to the client view
//FYI, this bit is even more borrowed from goon, our widescreen broke tooltips so I took a look at how they do it
//To improve our code. Thanks gooncoders, very cool
var mapWidth = map['view-size'].x,
mapHeight = map['view-size'].y,
tilesShown = tooltip.client_view_w
realIconSize = mapWidth / tilesShown,
resizeRatio = realIconSize / tooltip.tileSize,
tilesShownX = tooltip.client_view_w
tilesShownY = tooltip.client_view_h
realIconSizeX = mapWidth / tilesShownX,
realIconSizeY = mapHeight / tilesShownY,
resizeRatioX = realIconSizeX / tooltip.tileSize,
resizeRatioY = realIconSizeY / tooltip.tileSize,
//Calculate letterboxing offsets
leftOffset = (map.size.x - mapWidth) / 2,
topOffset = (map.size.y - mapHeight) / 2;
//alert(realIconSize + ' | ' +tooltip.tileSize + ' | ' + resizeRatio); //DEBUG
//Parse out the tile and cursor locations from params (e.g. "icon-x=32;icon-y=29;screen-loc=3:10,15:29")
const parameters = new Object();
//Parse out the contents of params (e.g. "icon-x=32;icon-y=29;screen-loc=3:10,15:29")
//It is worth noting that params is not always ordered in the same way. We therefore need to write the code
//To load their values in independantly of their order
var paramsA = tooltip.params.cursor.split(';');
if (paramsA.length < 3) {return false;} //Sometimes screen-loc is never sent ahaha fuck you byond
for (var i = 0; i < paramsA.length; i++) {
var entry = paramsA[i];
var nameAndValue = entry.split("=");
parameters[nameAndValue[0]] = nameAndValue[1];
}
//Sometimes screen-loc is never sent ahaha fuck you byond
if (!parameters["icon-x"] || !parameters["icon-y"] || !parameters["screen-loc"]) {
return false;
}
//icon-x
var iconX = paramsA[0];
iconX = iconX.split('=');
iconX = parseInt(iconX[1]);
var iconX = parseInt(parameters["icon-x"]);
//icon-y
var iconY = paramsA[1];
iconY = iconY.split('=');
iconY = parseInt(iconY[1]);
var iconY = parseInt(parameters["icon-y"]);
//screen-loc
var screenLoc = paramsA[2];
screenLoc = screenLoc.split('=');
screenLoc = screenLoc[1].split(',');
var screenLoc = parameters["screen-loc"];
screenLoc = screenLoc.split(',');
if (screenLoc.length < 2) {return false;}
var left = screenLoc[0];
var top = screenLoc[1];
@@ -168,7 +185,7 @@
if ((iconX + westOffset) !== enteredX) { //Cursor entered on the offset tile
left = left + (westOffset < 0 ? 1 : -1);
}
leftOffset = leftOffset + (westOffset * resizeRatio);
leftOffset = leftOffset + (westOffset * resizeRatioX);
}
}
@@ -179,13 +196,13 @@
if (northOffset !== 0) {
if ((iconY + northOffset) === enteredY) { //Cursor entered on the original tile
top--;
topOffset = topOffset - ((tooltip.tileSize + northOffset) * resizeRatio);
topOffset = topOffset - ((tooltip.tileSize + northOffset) * resizeRatioY);
} else { //Cursor entered on the offset tile
if (northOffset < 0) { //Offset southwards
topOffset = topOffset - ((tooltip.tileSize + northOffset) * resizeRatio);
topOffset = topOffset - ((tooltip.tileSize + northOffset) * resizeRatioY);
} else { //Offset northwards
top--;
topOffset = topOffset - (northOffset * resizeRatio);
topOffset = topOffset - (northOffset * resizeRatioY);
}
}
}
@@ -198,12 +215,12 @@
}
//Clamp values
left = (left < 0 ? 0 : (left > tilesShown ? tilesShown : left));
top = (top < 0 ? 0 : (top > tilesShown ? tilesShown : top));
left = (left < 0 ? 0 : (left > tilesShownX ? tilesShownX : left));
top = (top < 0 ? 0 : (top > tilesShownY ? tilesShownY : top));
//Calculate where on the screen the popup should appear (below the hovered tile)
var posX = Math.round(((left - 1) * realIconSize) + leftOffset + tooltip.padding); //-1 to position at the left of the target tile
var posY = Math.round(((tilesShown - top + 1) * realIconSize) + topOffset + tooltip.padding); //+1 to position at the bottom of the target tile
var posX = Math.round(((left - 1) * realIconSizeX) + leftOffset + tooltip.padding); //-1 to position at the left of the target tile
var posY = Math.round(((tilesShownY - top + 1) * realIconSizeY) + topOffset + tooltip.padding); //+1 to position at the bottom of the target tile
//alert(mapWidth+' | '+mapHeight+' | '+tilesShown+' | '+realIconSize+' | '+leftOffset+' | '+topOffset+' | '+left+' | '+top+' | '+posX+' | '+posY); //DEBUG
@@ -226,7 +243,7 @@
docHeight = Math.floor($wrap.outerHeight() * pixelRatio);
if (posY + docHeight > map.size.y) { //Is the bottom edge below the window? Snap it up if so
posY = (posY - docHeight) - realIconSize - tooltip.padding;
posY = (posY - docHeight) - realIconSizeY - tooltip.padding;
}
//Actually size, move and show the tooltip box