Mouse input added to Library tab.

This commit is contained in:
Mari the Deer 2022-02-14 20:09:24 +01:00
commit a545fc4d9c
5 changed files with 117 additions and 16 deletions

View file

@ -352,7 +352,7 @@ Class DemolitionistMenu : GenericMenu
{
if ( tabs[i].bHidden ) continue;
str = StringTable.Localize(tabs[i].title);
len = smallfont.StringWidth(str)+6;
len = smallfont.StringWidth(str)+10;
if ( (mpos.x >= xx) && (mpos.x < xx+len) )
{
if ( curtab == i ) break;
@ -518,7 +518,7 @@ Class DemolitionistMenu : GenericMenu
// draw top and bottom separators
DrawHSeparator(0,14,ws.x);
DrawHSeparator(0,ws.y-14,ws.x);
double xx = 3, yy = 1;
double xx = 5, yy = 1;
String str;
// draw tab listing
for ( int i=0; i<tabs.Size(); i++ )
@ -526,8 +526,8 @@ Class DemolitionistMenu : GenericMenu
if ( tabs[i].bHidden ) continue;
str = StringTable.Localize(tabs[i].title);
Screen.DrawText(smallfont,(curtab==i)?Font.CR_FIRE:Font.CR_DARKGRAY,origin.x+xx,origin.y+yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += smallfont.StringWidth(str)+6;
DrawVSeparator(xx-3,0,14);
xx += smallfont.StringWidth(str)+10;
DrawVSeparator(xx-5,0,14);
}
// draw money
xx = 637-smallfont.StringWidth(munstr);

View file

@ -94,7 +94,7 @@ Class DemolitionistMenuListItem ui
// checks if the mouse position is within bounds of the item
// (relative to item itself, not offset coords)
virtual bool CheckBounds( int x, int y )
virtual bool CheckBounds( double x, double y )
{
if ( x < xpos ) return false;
if ( y < ypos ) return false;
@ -346,7 +346,7 @@ Class DemolitionistMenuLoreItem : DemolitionistMenuListItem
{
String str = label;
if ( !ent.read ) str = "\cf‼\c-"..label;
Screen.DrawText(smallfont,bActive?Font.CR_FIRE:selected?Font.CR_WHITE:Font.CR_DARKGRAY,master.origin.x+pos.x,master.origin.y+pos.y,str,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true,DTA_ClipTop,cliptop,DTA_ClipBottom,clipbottom,DTA_ClipLeft,clipleft,DTA_ClipRight,clipright);
Screen.DrawText(smallfont,bActive?Font.CR_FIRE:Font.CR_WHITE,master.origin.x+pos.x,master.origin.y+pos.y,str,DTA_VirtualWidthF,master.ss.x,DTA_VirtualHeightF,master.ss.y,DTA_KeepRatio,true,DTA_ClipTop,cliptop,DTA_ClipBottom,clipbottom,DTA_ClipLeft,clipleft,DTA_ClipRight,clipright,DTA_ColorOverlay,selected?Color(0,0,0,0):Color(96,0,0,0));
}
}

View file

@ -10,7 +10,7 @@ Class DemolitionistLibraryTab : DemolitionistMenuTab
int loresz;
int ofs[4], maxofs[4];
double smofs[4];
bool drag;
bool drag[2];
int sel[4];
DemolitionistMenuLoreItem active;
SWWMLore clore;
@ -55,7 +55,6 @@ Class DemolitionistLibraryTab : DemolitionistMenuTab
lwidth = max(lwidth,smallfont.StringWidth("<‼ "..sname[i].." ‼>")+6);
lists[i] = new("DemolitionistMenuList");
lists[i].master = master;
lists[i].selected = 0;
}
loresz = lore.ent.Size();
for ( int i=0; i<loresz; i++ )
@ -68,9 +67,9 @@ Class DemolitionistLibraryTab : DemolitionistMenuTab
for ( int i=0; i<4; i++ )
{
qsort_lore(lists[i].items,0,lists[i].items.Size()-1);
maxofs[i] = max(0,lists[i].items.Size()*13-(master.ws.y-50));
maxofs[i] = max(0,lists[i].items.Size()*14-int(master.ws.y-50));
for ( int j=0; j<lists[i].items.Size(); j++ )
lists[i].items[j].ypos = j*13;
lists[i].items[j].ypos = j*14;
}
return Super.Init(master);
}
@ -116,10 +115,10 @@ Class DemolitionistLibraryTab : DemolitionistMenuTab
sel[i] = lists[i].selected = idx;
KBScroll();
}
maxofs[i] = max(0,lists[i].items.Size()*13-(master.ws.y-50));
maxofs[i] = max(0,lists[i].items.Size()*14-int(master.ws.y-50));
if ( ofs[i] > maxofs[i] ) smofs[i] = ofs[i] = maxofs[i];
for ( int j=0; j<lists[i].items.Size(); j++ )
lists[i].items[j].ypos = j*13;
lists[i].items[j].ypos = j*14;
}
loresz = lore.ent.Size();
// append the notification for new lore
@ -160,8 +159,8 @@ Class DemolitionistLibraryTab : DemolitionistMenuTab
void KBScroll()
{
if ( maxofs[section] <= 0 ) return;
int miny = (lists[section].selected+1)*13-(master.ws.y-50);
int maxy = lists[section].selected*13;
int miny = (lists[section].selected+1)*14-int(master.ws.y-50);
int maxy = lists[section].selected*14;
if ( ofs[section] < miny ) ofs[section] = clamp(miny,0,maxofs[section]);
else if ( ofs[section] > maxy ) ofs[section] = clamp(maxy,0,maxofs[section]);
}
@ -247,6 +246,108 @@ Class DemolitionistLibraryTab : DemolitionistMenuTab
break;
}
}
override void MouseInput( Vector2 pos, int btn )
{
// global events
switch ( btn )
{
case MB_DRAG:
if ( clore && ltext && drag[1] ) ltext.SetOffset(pos.y);
else if ( drag[0] ) SetOffset(pos.y);
break;
case MB_RELEASE:
drag[0] = drag[1] = false;
break;
}
// mouse on left side
if ( pos.x < (lwidth+((maxofs[section]>0)?8:0)) )
{
// see if we're clicking the scrollbar (if it exists)
if ( (btn == MB_LEFT) && (maxofs[section] > 0) && (pos.x >= lwidth) )
{
SetOffset(pos.y);
master.MenuSound("menu/demoscroll");
drag[0] = true;
return;
}
// mouse on the category sub-tab
if ( pos.y < 28 )
{
switch ( btn )
{
case MB_LEFT:
if ( pos.x < (lwidth/2) ) MenuInput(MK_LEFT);
else MenuInput(MK_RIGHT);
break;
case MB_WHEELUP:
MenuInput(MK_LEFT);
break;
case MB_WHEELDOWN:
MenuInput(MK_RIGHT);
break;
}
return;
}
switch ( btn )
{
case MB_LEFT:
// find which element we clicked
for ( int i=0; i<lists[section].items.Size(); i++ )
{
if ( !lists[section].items[i].CheckBounds(pos.x-3,(pos.y-32)+smofs[section]) )
continue;
sel[section] = lists[section].selected = i;
KBScroll();
if ( active && (lists[section].items[i] == active) )
MenuInput(MK_BACK);
else
{
if ( active ) active.bActive = false;
clore = null;
MenuInput(MK_ENTER);
}
break;
}
break;
case MB_WHEELUP:
if ( sel[section] > 0 )
{
lists[section].selected = --sel[section];
master.MenuSound("menu/demoscroll");
KBScroll();
}
break;
case MB_WHEELDOWN:
if ( sel[section] < lists[section].items.Size()-1 )
{
lists[section].selected = ++sel[section];
master.MenuSound("menu/demoscroll");
KBScroll();
}
break;
}
return;
}
if ( !clore || !ltext ) return;
switch ( btn )
{
case MB_LEFT:
// see if we're clicking the scrollbar (if it exists)
if ( ltext.scrollbar && (pos.x > (master.ws.x-8)) )
{
ltext.SetOffset(pos.y);
master.MenuSound("menu/demoscroll");
drag[1] = true;
}
break;
case MB_WHEELUP:
if ( ltext.Scroll(-8) ) master.MenuSound("menu/demoscroll");
break;
case MB_WHEELDOWN:
if ( ltext.Scroll(8) ) master.MenuSound("menu/demoscroll");
break;
}
}
override void Drawer()
{
double xx = 0;