Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- redid mouse control for the conversation menu.
Since the page operates on different coordinate systems, the only working way to check the mouse is to store the real coordinates when drawing and check the mouse position against those.
  • Loading branch information
coelckers committed Jun 4, 2020
1 parent b441b64 commit 328d9c7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions wadsrc/static/zscript/ui/menu/conversationmenu.zs
Expand Up @@ -93,7 +93,7 @@ class ConversationMenu : Menu
int fontScale;
int refwidth;
int refheight;
double fontfactor;
Array<double> ypositions;

int SpeechWidth;
int ReplyWidth;
Expand Down Expand Up @@ -127,7 +127,6 @@ class ConversationMenu : Menu
displayWidth = CleanWidth;
displayHeight = CleanHeight;
fontScale = CleanXfac;
fontFactor = 1;
refwidth = 320;
refheight = 200;
ReplyWidth = 320-50-10;
Expand All @@ -140,7 +139,6 @@ class ConversationMenu : Menu
{
displayFont = NewSmallFont;
fontScale = (CleanXfac+1) / 2;
fontFactor = double(CleanXfac) / fontScale;
refwidth = 640;
refheight = 400;
ReplyWidth = 640-100-20;
Expand Down Expand Up @@ -365,18 +363,14 @@ class ConversationMenu : Menu

// convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture
x = ((x - (screen.GetWidth() / 2)) / fontScale) + refWidth/2;
y = ((y - (screen.GetHeight() / 2)) / fontScale) + refHeight/2;

int ypos = int(mYpos * FontFactor);

if (x >= 24 && x <= refWidth-24 && y >= ypos && y < ypos + fh * mResponseLines.Size())
if (x >= 24 && x <= refWidth-24)
{
sel = (y - ypos) / fh;
for(int i = 0; i < mResponses.Size(); i++)
for (int i = 0; i < ypositions.Size()-1; i++)
{
if (mResponses[i] > sel)
if (y > ypositions[i] && y <= ypositions[i+1])
{
sel = i-1;
sel = i;
break;
}
}
Expand Down Expand Up @@ -498,6 +492,7 @@ class ConversationMenu : Menu
int y = mYpos;

int response = 0;
ypositions.Clear();
for (int i = 0; i < mResponseLines.Size(); i++)
{
int width = displayFont.StringWidth(mResponseLines[i]);
Expand All @@ -506,6 +501,7 @@ class ConversationMenu : Menu
double sx = (x - 160.0) * CleanXfac + (screen.GetWidth() * 0.5);
double sy = (y - 100.0) * CleanYfac + (screen.GetHeight() * 0.5);

ypositions.Push(sy);

screen.DrawText(displayFont, Font.CR_GREEN, sx / fontScale, sy / fontScale, mResponseLines[i], DTA_KeepRatio, true, DTA_VirtualWidth, displayWidth, DTA_VirtualHeight, displayHeight);

Expand All @@ -530,6 +526,8 @@ class ConversationMenu : Menu
}
y += ReplyLineHeight;
}
double sy = (y - 100.0) * CleanYfac + (screen.GetHeight() * 0.5);
ypositions.Push(sy);
}

virtual void DrawGold()
Expand Down

0 comments on commit 328d9c7

Please sign in to comment.