Advertisement
jewalky

Untitled

Jan 9th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.84 KB | None | 0 0
  1. #library "HELPSCRN"
  2. #include "zcommon.acs"
  3.  
  4. #define HSDBMAX 10240
  5. str HSDB_Category[HSDBMAX];
  6. str HSDB_Name[HSDBMAX];
  7. str HSDB_Actor[HSDBMAX];
  8. str HSDB_DescText[HSDBMAX];
  9. int HSDB_Count = 0;
  10.  
  11. function void HSDBAdd(str category, str name, str actor, str desctext)
  12. {
  13.     HSDB_Category[HSDB_Count] = category;
  14.     HSDB_Name[HSDB_Count] = name;
  15.     HSDB_Actor[HSDB_Count] = actor;
  16.     HSDB_DescText[HSDB_Count] = desctext;
  17.     HSDB_Count++;
  18. }
  19.  
  20. function void HSDBInit(void)
  21. {
  22.     // this adds database entries for helpscreen.
  23.     // database entries have the following properties:
  24.     //  - category
  25.     //  - name
  26.     //  - display actor
  27.     //  - description text
  28.     HSDBAdd("Monsters", "Zombie", "Zombieman", "This is what you would be if you happened to attend to a zombie apocalypse.");
  29.     HSDBAdd("Monsters", "Zombie sergeant", "ShotgunGuy", "Not even being a skilled soldier would help you.");
  30.     HSDBAdd("Monsters", "Chaingunner", "ChaingunGuy", "You want to hide from this one.");
  31.     HSDBAdd("Monsters", "Imp", "DoomImp", "This monster is not so large.");
  32.     HSDBAdd("Monsters", "Pinky", "Demon", "This monster is \cGBRUTAL\c*.");
  33.     HSDBAdd("Monsters", "Lost soul", "LostSoul", "The little brother of AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.");
  34.     HSDBAdd("Monsters", "Revenant", "Revenant", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!");
  35.     HSDBAdd("Monsters", "Mancubus", "Fatso", "This monster is fatter than your mom.");
  36.     HSDBAdd("Monsters", "Cacodemon", "Cacodemon", "This thing floats.\nSometimes this thing floats away.\nThe worst kind of floating.");
  37.     HSDBAdd("Monsters", "Pain elemental", "PainElemental", "You don't want to know how this fits 20 horned human skulls in it's mouth.");
  38.     HSDBAdd("Monsters", "Archvile", "Archvile", "This monster has a lot of frames.");
  39.     HSDBAdd("Monsters", "Cyberdemon", "Cyberdemon", "After they cloned Dolly, they tried to clone a cow.\n\n...it didn't turn out good really.");
  40.     HSDBAdd("Monsters", "Spider Mastermind", "SpiderMastermind", "This monster barely fits in the window.");
  41.     HSDBAdd("Monsters", "* BFGBall", "BFGBall", "");
  42.     HSDBAdd("Monsters", "* Barrel", "ExplosiveBarrel", "");
  43.     HSDBAdd("Monsters", "* RedTorch", "RedTorch", "");
  44.     HSDBAdd("Monsters", "* BlueTorch", "BlueTorch", "");
  45.     HSDBAdd("Monsters", "* GreenTorch", "GreenTorch", "");
  46.     HSDBAdd("Monsters", "* Fat shot", "FatShot", "");
  47.     HSDBAdd("Weapons", "Super Shotgun", "SuperShotgun", "The weapon that you should always spawn at.");
  48.     HSDBAdd("Weapons", "Chainsaw", "Chainsaw", "\cGYEA BRUTAL DOOM!!!");
  49.     HSDBAdd("Artifacts", "Soulsphere", "SoulSphere", "Something you pick up if you want some action.");
  50. }
  51.  
  52. function int Clamp(int what, int min, int max)
  53. {
  54.     if (what < min) return min;
  55.     if (what > max) return max;
  56.     return what;
  57. }
  58.  
  59. function int GetCVarFixed(str name)
  60. {
  61.     str c = GetCVarString(name);
  62.    
  63.     // [-|+][123123123][.123123123]
  64.    
  65.     int part_integer = 0;
  66.     int part_fractional = 0;
  67.    
  68.     // first, get the location of the dot
  69.     int i;
  70.     int dot = 0;
  71.     for (i = 0; i < StrLen(c); i++)
  72.     {
  73.         if (GetChar(c, i) == '.')
  74.             break;
  75.     }
  76.     dot = i;
  77.    
  78.     bool negative = false;
  79.    
  80.     for (i = 0; i < dot; i++)
  81.     {
  82.         if (i == 0 && (GetChar(c, i) == '-'))
  83.         {
  84.             negative = true;
  85.         }
  86.         else
  87.         {
  88.             int ch = GetChar(c, i);
  89.             ch -= 0x30;
  90.             int countOr = dot-i-1;
  91.             for (int j = 0; j < countOr; j++)
  92.                 ch *= 10;
  93.             part_integer += ch;
  94.         }
  95.     }
  96.    
  97.     for (i = dot+1; i < StrLen(c); i++)
  98.     {
  99.         ch = GetChar(c, i);
  100.         ch -= 0x30;
  101.         ch <<= 16;
  102.         countOr = i-dot;
  103.         for (j = 0; j < countOr; j++)
  104.             ch /= 10;
  105.         part_fractional += ch;
  106.     }
  107.    
  108.     return ((part_integer & 0xFFFF) << 16) | (part_fractional & 0xFFFF);
  109. }
  110.  
  111. script "HelpScreen" ENTER CLIENTSIDE
  112. {
  113.     HSDBInit();
  114.     // base coordinates are -32767.0, -32767.0 (yes not 32768)
  115.     // camera at +64 y
  116.     // model at 0,0
  117.     // background at -1 y
  118.     int bx = -32512.0;
  119.     int by = 32512.0;
  120.     int bz = 0;
  121.     // spawn camera
  122.     int camera = UniqueTID();
  123.     SpawnForced("SecurityCamera", bx, by-128.0, bz, camera, 0.25>>8); // look up (north)
  124.     SetCameraToTexture(camera, "HSCamTex", 90);
  125.     // spawn background.
  126.     int background = UniqueTID();
  127.     SpawnForced("HelpScreenBackground", bx, by+32.0, bz-128.0, background, 0);
  128.     // make TID for the thing to be viewed.
  129.     int vtid = UniqueTID();
  130.     //  
  131.     int hmsgId;
  132.     int hmsgFlags = HUDMSG_PLAIN|HUDMSG_NOWRAP|HUDMSG_NOTWITHFULLMAP|HUDMSG_NOTWITHOVERLAYMAP;
  133.     //
  134.     str categoryCurrent = 0;
  135.     //
  136.     str itemLast = 0; // this is used to replace preview actor when it changes.
  137.     str itemCurrent = 0; // this is class name, not name.
  138.     int itemCurrentIndex = -1;
  139.     int itemAngle = 0.25;
  140.     // mouse and input
  141.     int oldbuttons = 0;
  142.     int mouseX = 320.0;
  143.     int mouseY = 240.0;
  144.     int mouseXi = 320;
  145.     int mouseYi = 240;
  146.     bool mouseWasDown = false;
  147.     bool mouseDown = false;
  148.     bool mouseClicked = false;
  149.     // window state
  150.     bool wWasActive = false;
  151.     bool wActive = false;
  152.     // these are local arrays.
  153.     // they will break in ancient ZDoom versions.
  154.     str lstCategories[1024];
  155.     int cntCategories = 0;
  156.     str lstItems[1024];
  157.     int lstItemsIndices[1024];
  158.     int cntItems = 0;
  159.     while (true)
  160.     {
  161.         hmsgId = 0x06FFFFFFF;
  162.        
  163.         // buttons are needed even before mouse (to turn this window on and off)
  164.         int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
  165.         mouseWasDown = mouseDown;
  166.         mouseDown = !!(buttons & BT_ATTACK); // attack is typically mouse1
  167.         mouseClicked = (mouseWasDown && !mouseDown);
  168.        
  169.         // activate/deactivate help screen.
  170.         if (!(oldbuttons & BT_USER1) && (buttons & BT_USER1)) wActive = !wActive;
  171.         oldbuttons = buttons;
  172.    
  173.         if (!wActive)
  174.         {
  175.             if (wWasActive)
  176.             {
  177.                 SetPlayerProperty(0, 0, PROP_TOTALLYFROZEN);
  178.                 wWasActive = false;
  179.             }
  180.            
  181.             Delay(1);
  182.             continue;
  183.         }
  184.        
  185.         // active = true
  186.         if (!wWasActive)
  187.         {
  188.             SetPlayerProperty(0, 1, PROP_TOTALLYFROZEN);
  189.             wWasActive = true;
  190.         }
  191.            
  192.         // process mouse
  193.         int deltaX = -GetPlayerInput(-1, INPUT_YAW);
  194.         int deltaY = -GetPlayerInput(-1, INPUT_PITCH);
  195.         int m_yaw = GetCVarFixed("m_yaw");
  196.         int m_pitch = GetCVarFixed("m_pitch");
  197.         //int mouse_sensitivity = GetCVarFixed("mouse_sensitivity"); // ok lets not touch this part
  198.         deltaX = FixedDiv(deltaX, m_yaw);
  199.         int aspectRatio = FixedDiv(480.0, 640.0);
  200.         deltaY = FixedDiv(deltaY, m_pitch);
  201.         deltaY = FixedDiv(deltaY, aspectRatio);
  202.         if (!StrCmp(GetCVarString("invertmouse"), "true", 4))
  203.             deltaY = -deltaY;
  204.         //
  205.         mouseX += deltaX*0.04;
  206.         mouseY += deltaY*0.04;
  207.         mouseX = Clamp(mouseX, 0, 640.0);
  208.         mouseY = Clamp(mouseY, 0, 480.0);
  209.         mouseXi = mouseX>>16;
  210.         mouseYi = mouseY>>16;
  211.        
  212.         // process item lists (categories and items)
  213.         // sadly we don't have separate list of categories, but its not like it's really needed.
  214.         int i, j;
  215.         bool categoryfound;
  216.         if (!cntCategories)
  217.         {
  218.             for (i = 0; i < HSDB_Count; i++)
  219.             {
  220.                 categoryfound = false;
  221.                 for (j = 0; j < cntCategories; j++)
  222.                 {
  223.                     if (lstCategories[j] == HSDB_Category[i])
  224.                     {
  225.                         categoryfound = true;
  226.                         break;
  227.                     }
  228.                 }
  229.                
  230.                 if (!categoryfound)
  231.                 {
  232.                     lstCategories[cntCategories] = HSDB_Category[i];
  233.                     cntCategories++;
  234.                 }
  235.             }
  236.         }
  237.         //
  238.         cntItems = 0;
  239.         for (i = 0; i < HSDB_Count; i++)
  240.         {
  241.             if (HSDB_Category[i] == categoryCurrent)
  242.             {
  243.                 lstItems[cntItems] = HSDB_Name[i];
  244.                 lstItemsIndices[cntItems] = i;
  245.                 cntItems++;
  246.             }
  247.         }
  248.        
  249.         SetFont("HSBase");
  250.         SetHudSize(640, 480, true);
  251.        
  252.         // draw background (the window)
  253.         HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 0.1, 0.1, 0.029, 1.0);
  254.         SetFont("HSCamTex");
  255.         HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 309.1, 14.1, 0.029, 1.0);
  256.        
  257.         // draw categories and items.
  258.         SetFont("SMALLFNT");
  259.         int litemx = 0;
  260.         int litemy = 0;
  261.         int litemw = 0;
  262.         int litemh = 0;
  263.         int litemcolor = CR_GREEN;
  264.         for (i = 0; i < cntCategories; i++)
  265.         {
  266.             // if mouse is hovered.
  267.             litemx = 16; litemy = 16+12*i; litemw = 136; litemh = 9;
  268.             if (mouseXi > litemx && mouseXi < litemx+litemw && mouseYi > litemy && mouseYi < litemy+litemh)
  269.             {
  270.                 SetHudClipRect(litemx, litemy, litemw, litemh, 0);
  271.                 SetFont("HSBack");
  272.                 HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 0.1, 0.1, 0.029, 1.0);
  273.                 SetFont("SMALLFNT");
  274.                 SetHudClipRect(0, 0, 0, 0, 0);
  275.                 // also check if clicked
  276.                 if (mouseClicked)
  277.                 {
  278.                     categoryCurrent = lstCategories[i];
  279.                     itemCurrent = 0;
  280.                     itemCurrentIndex = -1;
  281.                 }
  282.             }
  283.            
  284.             if (lstCategories[i] == categoryCurrent) litemcolor = CR_GOLD;
  285.             else litemcolor = CR_GREEN;
  286.            
  287.             HudMessage(s:lstCategories[i]; hmsgFlags, hmsgId--, litemcolor, (litemx<<16)+1.1, (litemy<<16)+1.1, 0.029, 1.0);
  288.         }
  289.         //
  290.         if (categoryCurrent != 0)
  291.         {
  292.             for (i = 0; i < cntItems; i++)
  293.             {
  294.                 litemx = 163; litemy = 16+12*i; litemw = 136; litemh = 9;
  295.                 if (mouseXi > litemx && mouseXi < litemx+litemw && mouseYi > litemy && mouseYi < litemy+litemh)
  296.                 {
  297.                     SetHudClipRect(litemx, litemy, litemw, litemh, 0);
  298.                     SetFont("HSBack");
  299.                     HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 0.1, 0.1, 0.029, 1.0);
  300.                     SetFont("SMALLFNT");
  301.                     SetHudClipRect(0, 0, 0, 0, 0);
  302.                     // also check if clicked
  303.                     if (mouseClicked)
  304.                     {
  305.                         itemCurrentIndex = lstItemsIndices[i];
  306.                         itemCurrent = HSDB_Actor[itemCurrentIndex];
  307.                         itemAngle = 0.75;
  308.                     }
  309.                 }
  310.                
  311.                 if (lstItemsIndices[i] == itemCurrentIndex) litemcolor = CR_GOLD;
  312.                 else litemcolor = CR_GREEN;
  313.                
  314.                 HudMessage(s:lstItems[i]; hmsgFlags, hmsgId--, litemcolor, (litemx<<16)+1.1, (litemy<<16)+1.1, 0.029, 1.0);
  315.             }
  316.         }
  317.        
  318.         // display current title.
  319.         if (itemCurrentIndex >= 0)
  320.         {
  321.             SetFont("BIGFONT");
  322.             HudMessage(s:HSDB_Name[itemCurrentIndex]; hmsgFlags, hmsgId--, CR_WHITE, 17.1, 260.1, 0.029, 1.0);
  323.             SetFont("SMALLFNT");
  324.             HudMessage(s:HSDB_DescText[itemCurrentIndex]; hmsgFlags, hmsgId--, CR_GREEN, 17.1, 276.1, 0.029, 1.0);
  325.         }
  326.        
  327.         // set current entity.
  328.         if (itemLast != itemCurrent) // ZDoom 2.7.x guarantees that operator== works for same strings
  329.         {
  330.             Thing_Remove(vtid); // whatever
  331.             if (itemCurrent != 0)
  332.             {
  333.                 SpawnForced(itemCurrent, bx, by-32.0, bz, vtid, itemAngle>>8);
  334.                 Thing_Deactivate(vtid);
  335.             }
  336.             itemLast = itemCurrent;
  337.         }
  338.        
  339.         // adjust actor position and velocity.
  340.         if (itemCurrent != 0)
  341.         {
  342.             int itemHeight = GetActorProperty(vtid, APROP_Height);
  343.             SetActorPosition(vtid, bx, by-32.0, bz-itemHeight/2+8.0, false);
  344.             SetActorVelocity(vtid, 0, 0, 0, false, false);
  345.             SetActorAngle(vtid, itemAngle);
  346.             itemAngle += 0.01;
  347.         }
  348.        
  349.         // draw mouse cursor
  350.         SetFont("HSMouse");
  351.         HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, (mouseX&0xFFFF0000)+0.1, (mouseY&0xFFFF0000)+0.1, 0.029, 1.0);
  352.        
  353.         Delay(1);
  354.     }
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement