Advertisement
jewalky

Untitled

Mar 23rd, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.04 KB | None | 0 0
  1. // this is because the menu can be closed at any time, and we need to preserve this...
  2. class Doom3MenuData ui
  3. {
  4.     // doom logo
  5.     TextureID mDoomLogo;
  6.     TextureID mMouseCursor;
  7.     double mMouseX;
  8.     double mMouseY;
  9.     int mTicks;
  10.     TextureID mLineV;
  11.     TextureID mLineH;
  12.     //
  13.     TextureID mBorder1;
  14.     TextureID mBorder2;
  15.    
  16.     Array<int> mGridTime;
  17.     const GRID_RESX = 16;
  18.     const GRID_RESY = 16;
  19.     int mGridWidth;
  20.     int mGridHeight;
  21.    
  22.     private double GetGScale(double v)
  23.     {
  24.         double scale = 768.0 / Screen.GetHeight();
  25.         return v * scale;
  26.     }
  27.  
  28.     private void TickGrid()
  29.     {
  30.         int gridX = GetGScale(Screen.GetWidth()/GRID_RESX+1);
  31.         int gridY = GetGScale(Screen.GetHeight()/GRID_RESY+1);
  32.         if (gridX != mGridWidth || gridY != mGridHeight)
  33.         {
  34.             mGridTime.Resize(gridX+gridY);
  35.             mGridWidth = gridX;
  36.             mGridHeight = gridY;
  37.             for (int i = 0; i < mGridTime.Size(); i++)
  38.                 mGridTime[i] = 0;
  39.         }
  40.     }
  41.    
  42.     private void DrawDoomLogo()
  43.     {
  44.         int startTime = 35*3;
  45.  
  46.         double scale = 1.0;
  47.         if (mTicks < startTime)
  48.             scale = (double(mTicks)/startTime)/10 + 0.9;
  49.    
  50.         double sw = GetGScale(Screen.GetWidth());
  51.         double sh = GetGScale(Screen.GetHeight());
  52.         sw /= scale;
  53.         sh /= scale;
  54.    
  55.         //
  56.         double alpha = 0.7;
  57.         if (mTicks < startTime)
  58.             alpha = (double(mTicks)/startTime)*0.7;
  59.        
  60.         Screen.DrawTexture(mDoomLogo, false, sw/2, sh/2-64, DTA_Alpha, alpha, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
  61.     }
  62.    
  63.     private void DrawGrid()
  64.     {
  65.         int sw = GetGScale(Screen.GetWidth());
  66.         int sh = GetGScale(Screen.GetHeight());
  67.    
  68.         for (int y = 0; y < sh; y += GRID_RESY)
  69.         {
  70.             double lineAlpha = 0.05;
  71.             if ((y/GRID_RESY)%5 == 0)
  72.                 lineAlpha = 0.1;
  73.             int lineTime = mGridTime[mGridWidth+y/GRID_RESY];
  74.             if (mTicks-lineTime < 20)
  75.                 lineAlpha += (1.0-double(mTicks-lineTime)/20)/16;
  76.             for (int x = 0; x < sw; x += 320)
  77.                 Screen.DrawTexture(mLineH, false, x, y, DTA_Alpha, lineAlpha, DTA_FillColor, 0xAAE0FF, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
  78.         }
  79.        
  80.         for (int x = 0; x < sw; x += GRID_RESX)
  81.         {
  82.             double lineAlpha = 0.05;
  83.             if ((x/GRID_RESX)%5 == 0)
  84.                 lineAlpha = 0.1;
  85.             int lineTime = mGridTime[x/GRID_RESX];
  86.             if (mTicks-lineTime < 20)
  87.                 lineAlpha += (1.0-double(mTicks-lineTime)/20)/16;
  88.             for (int y = 0; y < sh; y += 320)
  89.                 Screen.DrawTexture(mLineV, false, x, y, DTA_Alpha, lineAlpha, DTA_FillColor, 0xAAE0FF, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
  90.         }
  91.     }
  92.  
  93.     private void OnMouseMove(int x, int y)
  94.     {
  95.         if (x != 0 || y != 0)
  96.         {
  97.             double mouseSpeed = 1.3;
  98.            
  99.             double offsX = x;
  100.             double offsY = -y;
  101.            
  102.             offsX /= 4;
  103.             offsX *= mouseSpeed;
  104.             offsY *= mouseSpeed;
  105.            
  106.             mMouseX += offsX;
  107.             mMouseY += offsY;
  108.            
  109.             mMouseX = clamp(mMouseX, 0, GetGScale(Screen.GetWidth())-1);
  110.             mMouseY = clamp(mMouseY, 0, GetGScale(Screen.GetHeight())-1);
  111.         }
  112.        
  113.         // grid
  114.         int gridX = mMouseX/GRID_RESX;
  115.         int gridY = mMouseY/GRID_RESY;
  116.         int inGridX = mMouseX-gridX*GRID_RESX;
  117.         int inGridY = mMouseY-gridY*GRID_RESY;
  118.         if (inGridX >= GRID_RESX/2)
  119.             gridX++;
  120.         if (inGridY >= GRID_RESY/2)
  121.             gridY++;
  122.         gridX = clamp(gridX, 0, mGridWidth-1);
  123.         gridY = clamp(gridY, 0, mGridHeight-1);
  124.         mGridTime[gridX] = mTicks;
  125.         mGridTime[mGridWidth+gridY] = mTicks;
  126.     }
  127.    
  128.     bool OnInputEvent(InputEvent ev)
  129.     {
  130.         if (ev.Type == InputEvent.Type_Mouse)
  131.         {
  132.             OnMouseMove(ev.MouseX, ev.MouseY);
  133.         }
  134.        
  135.         return true;
  136.     }
  137.    
  138.     bool OnUIEvent(UIEvent ev)
  139.     {
  140.         if (ev.Type == UiEvent.Type_MouseMove)
  141.         {
  142.             mMouseX = GetGScale(ev.MouseX);
  143.             mMouseY = GetGScale(ev.MouseY);
  144.             OnMouseMove(0, 0);
  145.         }
  146.         return true;
  147.     }
  148.    
  149.    
  150.     void Drawer()
  151.     {
  152.         // draw doom logo in the middle
  153.         int sw = GetGScale(Screen.GetWidth());
  154.         int sh = GetGScale(Screen.GetHeight());
  155.        
  156.         Screen.Dim(0x000000, 1.0, 0, 0, Screen.GetWidth(), Screen.GetHeight());
  157.        
  158.         DrawGrid();
  159.         DrawDoomLogo();
  160.            
  161.         // draw top border
  162.         Screen.DrawTexture(mBorder2, false, sw-55, 0, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
  163.         for (int x = 0; x < sw-55; x += 71)
  164.             Screen.DrawTexture(mBorder1, false, x, 0, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true, DTA_ClipRight, int(Screen.GetWidth()-55.0/GetGScale(1.0))+1);
  165.            
  166.         Screen.DrawTexture(mMouseCursor, false, mMouseX, mMouseY, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
  167.     }
  168.    
  169.  
  170.     void Init()
  171.     {
  172.         mDoomLogo = TexMan.CheckForTexture("graphics/doom.png", TexMan.Type_Any);
  173.         mMouseCursor = TexMan.CheckForTexture("graphics/D3Mouse.png", TexMan.Type_Any);
  174.         mLineV = TexMan.CheckForTexture("graphics/line-v.png", TexMan.Type_Any);
  175.         mLineH = TexMan.CheckForTexture("graphics/line-h.png", TexMan.Type_Any);
  176.         mBorder1 = TexMan.CheckForTexture("graphics/d3MenuTop1.png", TexMan.Type_Any);
  177.         mBorder2 = TexMan.CheckForTexture("graphics/d3MenuTop2.png", TexMan.Type_Any);
  178.        
  179.         mMouseX = GetGScale(Screen.GetWidth()/2);
  180.         mMouseY = GetGScale(Screen.GetHeight()/2);
  181.        
  182.         mTicks = 0;
  183.        
  184.         //
  185.         TickGrid();
  186.     }
  187.    
  188.     void Ticker()
  189.     {
  190.         mTicks++;
  191.        
  192.         // tick the grid.
  193.         TickGrid();
  194.     }
  195. }
  196.  
  197. class Doom3Menu : GenericMenu
  198. {
  199.     Doom3MenuData p;
  200.  
  201.     override bool OnUIEvent(UiEvent ev)
  202.     {
  203.         if (p) return p.OnUIEvent(ev);
  204.         return false;
  205.     }
  206.    
  207.     override bool OnInputEvent(InputEvent ev)
  208.     {
  209.         if (p) return p.OnInputEvent(ev);
  210.         return false;
  211.     }
  212.  
  213.     override void Drawer()
  214.     {
  215.         if (p) p.Drawer();
  216.     }
  217.  
  218.     override void Ticker()
  219.     {
  220.         if (p) p.Ticker();
  221.     }
  222. }
  223.  
  224. class Doom3MenuHandler : StaticEventHandler
  225. {
  226.     ui Doom3Menu D3Menu;
  227.     ui Doom3MenuData D3MenuData;
  228.     override void UiTick()
  229.     {
  230.         if (gamestate == GS_STARTUP || gamestate == GS_TITLELEVEL || gamestate == GS_DEMOSCREEN)
  231.         {
  232.             Menu m = Menu.GetCurrentMenu();
  233.             if (!Doom3Menu(m))
  234.             {
  235.                 //Menu.SetMenu('MainMenu');
  236.                 D3Menu = new('Doom3Menu');
  237.                 if (!D3MenuData)
  238.                 {
  239.                     D3MenuData = new('Doom3MenuData');
  240.                     D3MenuData.Init();
  241.                 }
  242.                 D3Menu.p = D3MenuData;
  243.                 D3Menu.Init(null);
  244.                 D3Menu.ActivateMenu();
  245.             }
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement