Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #library "HELPSCRN"
- #include "zcommon.acs"
- #define HSDBMAX 10240
- str HSDB_Category[HSDBMAX];
- str HSDB_Name[HSDBMAX];
- str HSDB_Actor[HSDBMAX];
- str HSDB_DescText[HSDBMAX];
- int HSDB_Count = 0;
- function void HSDBAdd(str category, str name, str actor, str desctext)
- {
- HSDB_Category[HSDB_Count] = category;
- HSDB_Name[HSDB_Count] = name;
- HSDB_Actor[HSDB_Count] = actor;
- HSDB_DescText[HSDB_Count] = desctext;
- HSDB_Count++;
- }
- function void HSDBInit(void)
- {
- // this adds database entries for helpscreen.
- // database entries have the following properties:
- // - category
- // - name
- // - display actor
- // - description text
- HSDBAdd("Monsters", "Zombie", "Zombieman", "This is what you would be if you happened to attend to a zombie apocalypse.");
- HSDBAdd("Monsters", "Zombie sergeant", "ShotgunGuy", "Not even being a skilled soldier would help you.");
- HSDBAdd("Monsters", "Chaingunner", "ChaingunGuy", "You want to hide from this one.");
- HSDBAdd("Monsters", "Imp", "DoomImp", "This monster is not so large.");
- HSDBAdd("Monsters", "Pinky", "Demon", "This monster is \cGBRUTAL\c*.");
- HSDBAdd("Monsters", "Lost soul", "LostSoul", "The little brother of AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.");
- HSDBAdd("Monsters", "Revenant", "Revenant", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!");
- HSDBAdd("Monsters", "Mancubus", "Fatso", "This monster is fatter than your mom.");
- HSDBAdd("Monsters", "Cacodemon", "Cacodemon", "This thing floats.\nSometimes this thing floats away.\nThe worst kind of floating.");
- HSDBAdd("Monsters", "Pain elemental", "PainElemental", "You don't want to know how this fits 20 horned human skulls in it's mouth.");
- HSDBAdd("Monsters", "Archvile", "Archvile", "This monster has a lot of frames.");
- HSDBAdd("Monsters", "Cyberdemon", "Cyberdemon", "After they cloned Dolly, they tried to clone a cow.\n\n...it didn't turn out good really.");
- HSDBAdd("Monsters", "Spider Mastermind", "SpiderMastermind", "This monster barely fits in the window.");
- HSDBAdd("Monsters", "* BFGBall", "BFGBall", "");
- HSDBAdd("Monsters", "* Barrel", "ExplosiveBarrel", "");
- HSDBAdd("Monsters", "* RedTorch", "RedTorch", "");
- HSDBAdd("Monsters", "* BlueTorch", "BlueTorch", "");
- HSDBAdd("Monsters", "* GreenTorch", "GreenTorch", "");
- HSDBAdd("Monsters", "* Fat shot", "FatShot", "");
- HSDBAdd("Weapons", "Super Shotgun", "SuperShotgun", "The weapon that you should always spawn at.");
- HSDBAdd("Weapons", "Chainsaw", "Chainsaw", "\cGYEA BRUTAL DOOM!!!");
- HSDBAdd("Artifacts", "Soulsphere", "SoulSphere", "Something you pick up if you want some action.");
- }
- function int Clamp(int what, int min, int max)
- {
- if (what < min) return min;
- if (what > max) return max;
- return what;
- }
- function int GetCVarFixed(str name)
- {
- str c = GetCVarString(name);
- // [-|+][123123123][.123123123]
- int part_integer = 0;
- int part_fractional = 0;
- // first, get the location of the dot
- int i;
- int dot = 0;
- for (i = 0; i < StrLen(c); i++)
- {
- if (GetChar(c, i) == '.')
- break;
- }
- dot = i;
- bool negative = false;
- for (i = 0; i < dot; i++)
- {
- if (i == 0 && (GetChar(c, i) == '-'))
- {
- negative = true;
- }
- else
- {
- int ch = GetChar(c, i);
- ch -= 0x30;
- int countOr = dot-i-1;
- for (int j = 0; j < countOr; j++)
- ch *= 10;
- part_integer += ch;
- }
- }
- for (i = dot+1; i < StrLen(c); i++)
- {
- ch = GetChar(c, i);
- ch -= 0x30;
- ch <<= 16;
- countOr = i-dot;
- for (j = 0; j < countOr; j++)
- ch /= 10;
- part_fractional += ch;
- }
- return ((part_integer & 0xFFFF) << 16) | (part_fractional & 0xFFFF);
- }
- script "HelpScreen" ENTER CLIENTSIDE
- {
- HSDBInit();
- // base coordinates are -32767.0, -32767.0 (yes not 32768)
- // camera at +64 y
- // model at 0,0
- // background at -1 y
- int bx = -32512.0;
- int by = 32512.0;
- int bz = 0;
- // spawn camera
- int camera = UniqueTID();
- SpawnForced("SecurityCamera", bx, by-128.0, bz, camera, 0.25>>8); // look up (north)
- SetCameraToTexture(camera, "HSCamTex", 90);
- // spawn background.
- int background = UniqueTID();
- SpawnForced("HelpScreenBackground", bx, by+32.0, bz-128.0, background, 0);
- // make TID for the thing to be viewed.
- int vtid = UniqueTID();
- //
- int hmsgId;
- int hmsgFlags = HUDMSG_PLAIN|HUDMSG_NOWRAP|HUDMSG_NOTWITHFULLMAP|HUDMSG_NOTWITHOVERLAYMAP;
- //
- str categoryCurrent = 0;
- //
- str itemLast = 0; // this is used to replace preview actor when it changes.
- str itemCurrent = 0; // this is class name, not name.
- int itemCurrentIndex = -1;
- int itemAngle = 0.25;
- // mouse and input
- int oldbuttons = 0;
- int mouseX = 320.0;
- int mouseY = 240.0;
- int mouseXi = 320;
- int mouseYi = 240;
- bool mouseWasDown = false;
- bool mouseDown = false;
- bool mouseClicked = false;
- // window state
- bool wWasActive = false;
- bool wActive = false;
- // these are local arrays.
- // they will break in ancient ZDoom versions.
- str lstCategories[1024];
- int cntCategories = 0;
- str lstItems[1024];
- int lstItemsIndices[1024];
- int cntItems = 0;
- while (true)
- {
- hmsgId = 0x06FFFFFFF;
- // buttons are needed even before mouse (to turn this window on and off)
- int buttons = GetPlayerInput(-1, INPUT_BUTTONS);
- mouseWasDown = mouseDown;
- mouseDown = !!(buttons & BT_ATTACK); // attack is typically mouse1
- mouseClicked = (mouseWasDown && !mouseDown);
- // activate/deactivate help screen.
- if (!(oldbuttons & BT_USER1) && (buttons & BT_USER1)) wActive = !wActive;
- oldbuttons = buttons;
- if (!wActive)
- {
- if (wWasActive)
- {
- SetPlayerProperty(0, 0, PROP_TOTALLYFROZEN);
- wWasActive = false;
- }
- Delay(1);
- continue;
- }
- // active = true
- if (!wWasActive)
- {
- SetPlayerProperty(0, 1, PROP_TOTALLYFROZEN);
- wWasActive = true;
- }
- // process mouse
- int deltaX = -GetPlayerInput(-1, INPUT_YAW);
- int deltaY = -GetPlayerInput(-1, INPUT_PITCH);
- int m_yaw = GetCVarFixed("m_yaw");
- int m_pitch = GetCVarFixed("m_pitch");
- //int mouse_sensitivity = GetCVarFixed("mouse_sensitivity"); // ok lets not touch this part
- deltaX = FixedDiv(deltaX, m_yaw);
- int aspectRatio = FixedDiv(480.0, 640.0);
- deltaY = FixedDiv(deltaY, m_pitch);
- deltaY = FixedDiv(deltaY, aspectRatio);
- if (!StrCmp(GetCVarString("invertmouse"), "true", 4))
- deltaY = -deltaY;
- //
- mouseX += deltaX*0.04;
- mouseY += deltaY*0.04;
- mouseX = Clamp(mouseX, 0, 640.0);
- mouseY = Clamp(mouseY, 0, 480.0);
- mouseXi = mouseX>>16;
- mouseYi = mouseY>>16;
- // process item lists (categories and items)
- // sadly we don't have separate list of categories, but its not like it's really needed.
- int i, j;
- bool categoryfound;
- if (!cntCategories)
- {
- for (i = 0; i < HSDB_Count; i++)
- {
- categoryfound = false;
- for (j = 0; j < cntCategories; j++)
- {
- if (lstCategories[j] == HSDB_Category[i])
- {
- categoryfound = true;
- break;
- }
- }
- if (!categoryfound)
- {
- lstCategories[cntCategories] = HSDB_Category[i];
- cntCategories++;
- }
- }
- }
- //
- cntItems = 0;
- for (i = 0; i < HSDB_Count; i++)
- {
- if (HSDB_Category[i] == categoryCurrent)
- {
- lstItems[cntItems] = HSDB_Name[i];
- lstItemsIndices[cntItems] = i;
- cntItems++;
- }
- }
- SetFont("HSBase");
- SetHudSize(640, 480, true);
- // draw background (the window)
- HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 0.1, 0.1, 0.029, 1.0);
- SetFont("HSCamTex");
- HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 309.1, 14.1, 0.029, 1.0);
- // draw categories and items.
- SetFont("SMALLFNT");
- int litemx = 0;
- int litemy = 0;
- int litemw = 0;
- int litemh = 0;
- int litemcolor = CR_GREEN;
- for (i = 0; i < cntCategories; i++)
- {
- // if mouse is hovered.
- litemx = 16; litemy = 16+12*i; litemw = 136; litemh = 9;
- if (mouseXi > litemx && mouseXi < litemx+litemw && mouseYi > litemy && mouseYi < litemy+litemh)
- {
- SetHudClipRect(litemx, litemy, litemw, litemh, 0);
- SetFont("HSBack");
- HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 0.1, 0.1, 0.029, 1.0);
- SetFont("SMALLFNT");
- SetHudClipRect(0, 0, 0, 0, 0);
- // also check if clicked
- if (mouseClicked)
- {
- categoryCurrent = lstCategories[i];
- itemCurrent = 0;
- itemCurrentIndex = -1;
- }
- }
- if (lstCategories[i] == categoryCurrent) litemcolor = CR_GOLD;
- else litemcolor = CR_GREEN;
- HudMessage(s:lstCategories[i]; hmsgFlags, hmsgId--, litemcolor, (litemx<<16)+1.1, (litemy<<16)+1.1, 0.029, 1.0);
- }
- //
- if (categoryCurrent != 0)
- {
- for (i = 0; i < cntItems; i++)
- {
- litemx = 163; litemy = 16+12*i; litemw = 136; litemh = 9;
- if (mouseXi > litemx && mouseXi < litemx+litemw && mouseYi > litemy && mouseYi < litemy+litemh)
- {
- SetHudClipRect(litemx, litemy, litemw, litemh, 0);
- SetFont("HSBack");
- HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, 0.1, 0.1, 0.029, 1.0);
- SetFont("SMALLFNT");
- SetHudClipRect(0, 0, 0, 0, 0);
- // also check if clicked
- if (mouseClicked)
- {
- itemCurrentIndex = lstItemsIndices[i];
- itemCurrent = HSDB_Actor[itemCurrentIndex];
- itemAngle = 0.75;
- }
- }
- if (lstItemsIndices[i] == itemCurrentIndex) litemcolor = CR_GOLD;
- else litemcolor = CR_GREEN;
- HudMessage(s:lstItems[i]; hmsgFlags, hmsgId--, litemcolor, (litemx<<16)+1.1, (litemy<<16)+1.1, 0.029, 1.0);
- }
- }
- // display current title.
- if (itemCurrentIndex >= 0)
- {
- SetFont("BIGFONT");
- HudMessage(s:HSDB_Name[itemCurrentIndex]; hmsgFlags, hmsgId--, CR_WHITE, 17.1, 260.1, 0.029, 1.0);
- SetFont("SMALLFNT");
- HudMessage(s:HSDB_DescText[itemCurrentIndex]; hmsgFlags, hmsgId--, CR_GREEN, 17.1, 276.1, 0.029, 1.0);
- }
- // set current entity.
- if (itemLast != itemCurrent) // ZDoom 2.7.x guarantees that operator== works for same strings
- {
- Thing_Remove(vtid); // whatever
- if (itemCurrent != 0)
- {
- SpawnForced(itemCurrent, bx, by-32.0, bz, vtid, itemAngle>>8);
- Thing_Deactivate(vtid);
- }
- itemLast = itemCurrent;
- }
- // adjust actor position and velocity.
- if (itemCurrent != 0)
- {
- int itemHeight = GetActorProperty(vtid, APROP_Height);
- SetActorPosition(vtid, bx, by-32.0, bz-itemHeight/2+8.0, false);
- SetActorVelocity(vtid, 0, 0, 0, false, false);
- SetActorAngle(vtid, itemAngle);
- itemAngle += 0.01;
- }
- // draw mouse cursor
- SetFont("HSMouse");
- HudMessage(s:"A"; hmsgFlags, hmsgId--, CR_UNTRANSLATED, (mouseX&0xFFFF0000)+0.1, (mouseY&0xFFFF0000)+0.1, 0.029, 1.0);
- Delay(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement