Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this is because the menu can be closed at any time, and we need to preserve this...
- class Doom3MenuData ui
- {
- // doom logo
- TextureID mDoomLogo;
- TextureID mMouseCursor;
- double mMouseX;
- double mMouseY;
- int mTicks;
- TextureID mLineV;
- TextureID mLineH;
- //
- TextureID mBorder1;
- TextureID mBorder2;
- Array<int> mGridTime;
- const GRID_RESX = 16;
- const GRID_RESY = 16;
- int mGridWidth;
- int mGridHeight;
- private double GetGScale(double v)
- {
- double scale = 768.0 / Screen.GetHeight();
- return v * scale;
- }
- private void TickGrid()
- {
- int gridX = GetGScale(Screen.GetWidth()/GRID_RESX+1);
- int gridY = GetGScale(Screen.GetHeight()/GRID_RESY+1);
- if (gridX != mGridWidth || gridY != mGridHeight)
- {
- mGridTime.Resize(gridX+gridY);
- mGridWidth = gridX;
- mGridHeight = gridY;
- for (int i = 0; i < mGridTime.Size(); i++)
- mGridTime[i] = 0;
- }
- }
- private void DrawDoomLogo()
- {
- int startTime = 35*3;
- double scale = 1.0;
- if (mTicks < startTime)
- scale = (double(mTicks)/startTime)/10 + 0.9;
- double sw = GetGScale(Screen.GetWidth());
- double sh = GetGScale(Screen.GetHeight());
- sw /= scale;
- sh /= scale;
- //
- double alpha = 0.7;
- if (mTicks < startTime)
- alpha = (double(mTicks)/startTime)*0.7;
- Screen.DrawTexture(mDoomLogo, false, sw/2, sh/2-64, DTA_Alpha, alpha, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
- }
- private void DrawGrid()
- {
- int sw = GetGScale(Screen.GetWidth());
- int sh = GetGScale(Screen.GetHeight());
- for (int y = 0; y < sh; y += GRID_RESY)
- {
- double lineAlpha = 0.05;
- if ((y/GRID_RESY)%5 == 0)
- lineAlpha = 0.1;
- int lineTime = mGridTime[mGridWidth+y/GRID_RESY];
- if (mTicks-lineTime < 20)
- lineAlpha += (1.0-double(mTicks-lineTime)/20)/16;
- for (int x = 0; x < sw; x += 320)
- Screen.DrawTexture(mLineH, false, x, y, DTA_Alpha, lineAlpha, DTA_FillColor, 0xAAE0FF, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
- }
- for (int x = 0; x < sw; x += GRID_RESX)
- {
- double lineAlpha = 0.05;
- if ((x/GRID_RESX)%5 == 0)
- lineAlpha = 0.1;
- int lineTime = mGridTime[x/GRID_RESX];
- if (mTicks-lineTime < 20)
- lineAlpha += (1.0-double(mTicks-lineTime)/20)/16;
- for (int y = 0; y < sh; y += 320)
- Screen.DrawTexture(mLineV, false, x, y, DTA_Alpha, lineAlpha, DTA_FillColor, 0xAAE0FF, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
- }
- }
- private void OnMouseMove(int x, int y)
- {
- if (x != 0 || y != 0)
- {
- double mouseSpeed = 1.3;
- double offsX = x;
- double offsY = -y;
- offsX /= 4;
- offsX *= mouseSpeed;
- offsY *= mouseSpeed;
- mMouseX += offsX;
- mMouseY += offsY;
- mMouseX = clamp(mMouseX, 0, GetGScale(Screen.GetWidth())-1);
- mMouseY = clamp(mMouseY, 0, GetGScale(Screen.GetHeight())-1);
- }
- // grid
- int gridX = mMouseX/GRID_RESX;
- int gridY = mMouseY/GRID_RESY;
- int inGridX = mMouseX-gridX*GRID_RESX;
- int inGridY = mMouseY-gridY*GRID_RESY;
- if (inGridX >= GRID_RESX/2)
- gridX++;
- if (inGridY >= GRID_RESY/2)
- gridY++;
- gridX = clamp(gridX, 0, mGridWidth-1);
- gridY = clamp(gridY, 0, mGridHeight-1);
- mGridTime[gridX] = mTicks;
- mGridTime[mGridWidth+gridY] = mTicks;
- }
- bool OnInputEvent(InputEvent ev)
- {
- if (ev.Type == InputEvent.Type_Mouse)
- {
- OnMouseMove(ev.MouseX, ev.MouseY);
- }
- return true;
- }
- bool OnUIEvent(UIEvent ev)
- {
- if (ev.Type == UiEvent.Type_MouseMove)
- {
- mMouseX = GetGScale(ev.MouseX);
- mMouseY = GetGScale(ev.MouseY);
- OnMouseMove(0, 0);
- }
- return true;
- }
- void Drawer()
- {
- // draw doom logo in the middle
- int sw = GetGScale(Screen.GetWidth());
- int sh = GetGScale(Screen.GetHeight());
- Screen.Dim(0x000000, 1.0, 0, 0, Screen.GetWidth(), Screen.GetHeight());
- DrawGrid();
- DrawDoomLogo();
- // draw top border
- Screen.DrawTexture(mBorder2, false, sw-55, 0, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
- for (int x = 0; x < sw-55; x += 71)
- 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);
- Screen.DrawTexture(mMouseCursor, false, mMouseX, mMouseY, DTA_VirtualWidth, int(sw), DTA_VirtualHeight, int(sh), DTA_KeepRatio, true);
- }
- void Init()
- {
- mDoomLogo = TexMan.CheckForTexture("graphics/doom.png", TexMan.Type_Any);
- mMouseCursor = TexMan.CheckForTexture("graphics/D3Mouse.png", TexMan.Type_Any);
- mLineV = TexMan.CheckForTexture("graphics/line-v.png", TexMan.Type_Any);
- mLineH = TexMan.CheckForTexture("graphics/line-h.png", TexMan.Type_Any);
- mBorder1 = TexMan.CheckForTexture("graphics/d3MenuTop1.png", TexMan.Type_Any);
- mBorder2 = TexMan.CheckForTexture("graphics/d3MenuTop2.png", TexMan.Type_Any);
- mMouseX = GetGScale(Screen.GetWidth()/2);
- mMouseY = GetGScale(Screen.GetHeight()/2);
- mTicks = 0;
- //
- TickGrid();
- }
- void Ticker()
- {
- mTicks++;
- // tick the grid.
- TickGrid();
- }
- }
- class Doom3Menu : GenericMenu
- {
- Doom3MenuData p;
- override bool OnUIEvent(UiEvent ev)
- {
- if (p) return p.OnUIEvent(ev);
- return false;
- }
- override bool OnInputEvent(InputEvent ev)
- {
- if (p) return p.OnInputEvent(ev);
- return false;
- }
- override void Drawer()
- {
- if (p) p.Drawer();
- }
- override void Ticker()
- {
- if (p) p.Ticker();
- }
- }
- class Doom3MenuHandler : StaticEventHandler
- {
- ui Doom3Menu D3Menu;
- ui Doom3MenuData D3MenuData;
- override void UiTick()
- {
- if (gamestate == GS_STARTUP || gamestate == GS_TITLELEVEL || gamestate == GS_DEMOSCREEN)
- {
- Menu m = Menu.GetCurrentMenu();
- if (!Doom3Menu(m))
- {
- //Menu.SetMenu('MainMenu');
- D3Menu = new('Doom3Menu');
- if (!D3MenuData)
- {
- D3MenuData = new('Doom3MenuData');
- D3MenuData.Init();
- }
- D3Menu.p = D3MenuData;
- D3Menu.Init(null);
- D3Menu.ActivateMenu();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment