So I've almost gotten the text width-constrained highlighting to work. It waits until you are actually over the text on the x-axis before highlighting, but there is a side-effect where, if you mouse above a line of text, parallel to its x-axis but not on its y-axis, it will still highlight it.
Here's the relevant part of the script, with my addition starting at the "&&" on line 8:
Code: ags
Any ideas?
Here's the complete code from the global script, if anyone would like to test it on their end:
Code: ags
Here's the relevant part of the script, with my addition starting at the "&&" on line 8:
int ypos = 0;
// Find the option that corresponds to where the mouse cursor is
for (int i = 1; i <= info.DialogToRender.OptionCount; i++)
{
if (info.DialogToRender.GetOptionState(i) == eOptionOn)
{
ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontFont0, info.Width - 10);
if ((mouse.y - info.Y) < ypos && (mouse.x < GetTextWidth(info.DialogToRender.GetOptionText(i), eFontFont0)))
{
info.ActiveOptionID = i;
return;
}
}
}
Any ideas?
Here's the complete code from the global script, if anyone would like to test it on their end:
int dlg_opt_acolor = 13;
int dlg_opt_ncolor = 4;
function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
// Create a 400x200 dialog options area at (50,100)
info.X = 50;
info.Y = 100;
info.Width = 400;
info.Height = 200;
// Enable alpha channel for the drawing surface
info.HasAlphaChannel = true;
}
function dialog_options_render(DialogOptionsRenderingInfo *info)
{
int ypos = 0;
for (int i = 1; i <= info.DialogToRender.OptionCount; i++)
{
if (info.DialogToRender.GetOptionState(i) == eOptionOn)
{
if (info.ActiveOptionID == i)
info.Surface.DrawingColor = dlg_opt_acolor;
else
info.Surface.DrawingColor = dlg_opt_ncolor;
info.Surface.DrawStringWrapped(5, ypos, info.Width - 10,
eFontFont0, eAlignLeft, info.DialogToRender.GetOptionText(i));
ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontFont0, info.Width - 10);
}
}
}
function dialog_options_repexec(DialogOptionsRenderingInfo *info)
{
info.ActiveOptionID = 0;
if (mouse.y < info.Y || mouse.y >= info.Y + info.Height ||
mouse.x < info.X || mouse.x >= info.X + info.Width)
{
return; // return if the mouse is outside UI bounds
}
int ypos = 0;
// Find the option that corresponds to where the mouse cursor is
for (int i = 1; i <= info.DialogToRender.OptionCount; i++)
{
if (info.DialogToRender.GetOptionState(i) == eOptionOn)
{
ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontFont0, info.Width - 10);
if ((mouse.y - info.Y) < ypos && (mouse.x < GetTextWidth(info.DialogToRender.GetOptionText(i), eFontFont0)))
{
info.ActiveOptionID = i;
return;
}
}
}
}
function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
if (button == eMouseLeft) {
if (info.ActiveOptionID > 0)
info.RunActiveOption();
}
}