Page 1 of 1

Help with zscript statusbar

PostPosted: Mon Oct 12, 2020 6:31 am
by ramon.dexter
Well, as I transfered most of my project's stuff into zscript, the only thing that was left behind is the statusbar. And as I was mostly successfull with the other zscript, I thought this one would be easy also. Woe me! I spent like a week trying to make it work, with completely zero success.
So, I'm asking if anyone woule be willing to translate my sbarinfo code into zscript? Or better, would anyone would be willing to teach me basics of the zscript hud making?

Here is my sbarinfo statusbar:
Code: Select allExpand view
height 0;
statusbar normal, forcescaled
{
   //screen frame
   DrawImage "HGframw", -54, 0;
   //light bar
   DrawBar "HGFHPB", "HGFHPBB", lampMagazine, horizontal, interpolate(2), 323, 5;
   //rads bar
   drawbar "MIN_RAD", "MIN_FIL", Radcount, horizontal, 270, 17, 2;   
   //weapon icon
   DrawImage weaponicon, 0, 1;
   //ammo icon
   usesammo //for reloading guns
   {         
      usessecondaryammo not
      {
         drawimage ammoicon1, 359, 159;
         drawnumber 3, INDEXFONT, gold, ammo1, 371, 136;
      }
      usessecondaryammo
      {
         drawimage ammoicon2, 359, 159;
         drawnumber 3, INDEXFONT, gold, ammo1, 371, 136;
         drawnumber 3, INDEXFONT, yellow, ammo2, 371, 147;
      }
   }
      
   //staff lvl2 fire mode indicator
   ininventory staffFire1token, 1
   {
      Drawimage "fire1t", -54, 0;
   }
   ininventory staffFire2token, 1
   {
      Drawimage "fire2t", -54, 0;
   }
      
   //armor icon
   DrawImage armoricon, -40, 4;
   //health
   DrawNumber 3, INDEXFONT, darkred, health, 337, 12;
   //armor
   DrawNumber 3, INDEXFONT, lightblue, armor, 357, 12;      
   //inv icon
   Alpha 0.35
   DrawImage "HGinv", -54, 0;      
   DrawSelectedInventory center, center, INDEXFONT, -23, 179, -8, 188, green;      
   //ammo 427, 147      
   //drawnumber 3, INDEXFONT, gold, ammo1, 372, 141;
   //usesammo //for reloading guns
   //{         
      //usessecondaryammo { drawnumber 3, INDEXFONT, yellow, ammo2, 372, 152; }         
   //}
   //grenade numbers
   InInventory GrenadeExplosive, 1 || GrenadeFire, 1
   {         
      InInventory GrenadeExplosive, 1 { Drawnumber 3, INDEXFONT, white, "GrenadeExplosive", 372, 105; }         
      InInventory GrenadeFire, 1 { Drawnumber 3, INDEXFONT, red, "GrenadeFire", 372, 116; }
   }
      
   //powerups
   InInventory nightEyeActiveToken, 1 { Drawimage "i_neye", -54, 0; }
   InInventory shieldPowerActiveToken, 1 { Drawimage "i_shield", -54, 0; }
   InInventory zmizikActiveToken, 1 { Drawimage "i_zmizik", -54, 0; }
   InInventory zscEnvironmentalSuitActiveToken, 1 { Drawimage "i_psuit", -54, 0; }
   InInventory regenModuleActiveToken, 1 { Drawimage "i_regen", -54, 0; }
   InInventory targeterActiveToken, 1 { Drawimage "i_trgt", -54, 0; }
   InInventory rebreatherActiveToken, 1 { Drawimage "i_rbr", -54, 0; }
   
}

//=INVENTORY OPEN=
//horizontal display, 7 positions
//start-------------------------------------------------------------------------
statusbar inventory
{
   Alpha 0.5
   DrawImage "HGINVB", -45, 0;
   DrawImage "HGINVF", -45, 0;
   DrawNumber 6, indexfont, gold, "credit", 155, 62;
   drawinventorybar strife, translucent, 5, INDEXFONT, 81, 23, 112, 45;
   
}

//keys popup
statusbar PopupKeys
{
   drawkeybar 26, vertical, reverserows, auto, -10, -80, 0, 13, 50;
}
//---end------------------------------------------------------------------------

//Strife Status popup
//------------------------------------------------------------------------------
CreatePopup status, 3, 10, SlideInBottom, 4;
statusbar PopupStatus, forcescaled
{
   //background
   Alpha 0.95
   DrawImage "HGPSTBK", 3, 10;   
   DrawImage "HGPSTAT", 3, 10;
   
   InInventory "dexpistol", 1 { DrawImage "P_DEPI", 3, 10; }
   InInventory "zscStrifeCrossbow", 1 { DrawImage "P_XBOW", 3, 10; }
   InInventory "dexAssaultRifle", 1 { DrawImage "P_DEAR", 3, 10; }
   InInventory "staffBlaster", 1 { DrawImage "P_ASTF", 3, 10; }
   InInventory "staffBlasterUpgr", 1 { DrawImage "P_USTF", 3, 10; }
   InInventory "BloodSawedoff", 1 { DrawImage "P_BLSW", 3, 10; }
   InInventory "SA24Riotgun", 1 { DrawImage "P_DEAS", 3, 10; }
   InInventory "SniperRifle", 1 { DrawImage "P_SNIP", 3, 10; }
   InInventory "zscFlameThrower", 1 { DrawImage "P_FLMR", 3, 10; }
   InInventory "RivetGun", 1 { DrawImage "P_RVPU", 3, 10; }
   InInventory "zscMauler", 1 { DrawImage "P_MAUL", 3, 10; }
   InInventory "GatLaser", 1 { DrawImage "P_GATS", 3, 10; }
   InInventory "zscStrifeGrenadeLauncher", 1 { DrawImage "P_GRND", 3, 10; }
   InInventory "napalmSpitter", 1 { DrawImage "P_WIMM", 3, 10; }
   
   //Accuracy stat
   DrawNumber 3, smallfont, yellow, Accuracy, alignment(right), 248, 37;
   //Stamina stat
   Drawnumber 3, smallfont, yellow, Stamina, alignment(right), 248, 56;   
   
   //clipofbullets
   DrawNumber 3, smallfont, yellow, Ammo(ammo57mm), alignment(right), 248, 73;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(ammo57mm), alignment(right), 281, 73;
   
   //shells
   DrawNumber 3, smallfont, yellow, Ammo(ammoShell), alignment(right), 248, 81;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(ammoShell), alignment(right), 281, 81;   
   
   //bolts
   DrawNumber 3, smallfont, yellow, Ammo(poisonBolts), alignment(right), 248, 98;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(poisonBolts), alignment(right), 281, 98;   
   DrawNumber 3, smallfont, yellow, Ammo(ElectricBolts), alignment(right), 248, 106;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(ElectricBolts), alignment(right), 281, 106;
   
   //rivets
   DrawNumber 3, smallfont, yellow, Ammo(Rivets), alignment(right), 248, 115;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(Rivets), alignment(right), 281, 115;
   
   //energypod
   DrawNumber 3, smallfont, yellow, Ammo(EnergyPod), alignment(right), 248, 123;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(EnergyPod), alignment(right), 281, 123;
   
   //grenades
   DrawNumber 3, smallfont, yellow, Ammo(HEGrenadeRounds), alignment(right), 248, 139;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(HEGrenadeRounds), alignment(right), 281, 139;
   
   DrawNumber 3, smallfont, yellow, Ammo(PhosphorusGrenadeRounds), alignment(right), 248, 147;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(PhosphorusGrenadeRounds), alignment(right), 281, 147;
   
   //napalm ammo
   DrawNumber 3, smallfont, yellow, Ammo(napalmAmmo), alignment(right), 248, 155;
   DrawNumber 3, smallfont, yellow, AmmoCapacity(napalmAmmo), alignment(right), 281, 155;
   
   //hand grenades
   DrawNumber 3, smallfont, yellow, "grenadeExplosive", alignment(right), 248, 172;   
   DrawNumber 3, smallfont, yellow, "grenadeFire", alignment(right), 248, 180;   
   
}
//------------------------------------------------------------------------------
//END OF HUD



Please, don't tell me to look on other projects code - that was the first thing I did and I was even more confused than when I started. Also, I tried to read the gzdoom.pk3 zscript regarding the UI statusbar stuff, and....not comprehend a thing. Sorry, but this scripting is way over me.

So, would somebody help me?

Re: Help with zscript statusbar

PostPosted: Mon Oct 12, 2020 9:15 am
by Player701
The question is - do you really need to convert this code to ZScript? Unless you want to extend your HUD with features not available via SBARINFO, it's probably best to leave it alone. As the saying goes - if it ain't broke, don't fix it.

However, if you still want to use ZScript to build your HUD, your best bet is to look at the Doom status bar code in gzdoom.pk3. Then look at the SBARINFO code that does the same thing, and compare them. Basically, this is what I started with when I was converting the HUD code in my project to ZScript with the intent to extend it further.

To start writing your HUD code, subclass BaseStatusBar and add the following line to the GameInfo block in your MAPINFO (replace MyHudClass with the name of your HUD class):

Code: Select allExpand view
StatusBarClass = "MyHudClass"

BaseStatusBar provides methods that you should use to draw various parts of your HUD. Note that if you're familiar with Screen.DrawText and co., the main difference is that the methods in BaseStatusBar already factor in the HUD scale for you. Unless you want to apply the HUD scale factors manually, you shouldn't use methods from the Screen struct to draw the HUD.

There seems to be some more information here on the wiki, but it doesn't look like much. If you need help with a specific issue (e.g. what a certain method does or what that data structrure is for), I could try to provide more detailed information.

Addendum: You may also want to take a look at this thread

Re: Help with zscript statusbar

PostPosted: Mon Oct 12, 2020 10:45 am
by ramon.dexter
Player701 wrote:As the saying goes - if it ain't broke, don't fix it.


That's my motto.
Yeah, the SBARINFO code works well for me. I just wanted to extend my HUD's possibilities, and also learn some new code. Your advice with doom statusbar zscript is OK. I actually coded a simple zscript HUD for another project, and it works well. But, this case is special, since I'm using things from strife statusbar. The statusbar has the popscreens, and this code is just too complicated for me.

Re: Help with zscript statusbar

PostPosted: Mon Oct 12, 2020 11:39 am
by Player701
Ah, the Strife popup screens. Never worked with them. Sorry about that. :(

Here's what I can say right now by looking at the code in strife_sbar.zs:

  • The code looks complicated mostly because it also handles the animations that happen when the screens are brought up and dismissed.
  • Classic Strife popups don't use the HUD scaling factors (I can see calls to Screen.DrawText and the like in there). Not sure if it's good or bad - that's how they were designed. But it doesn't mean that you have to do the same.
  • virtual void ShowPop (int popnum); - This gets called when the player presses a button to show one of the screens. Valid values for popnum appear to be: POP_Log, POP_Keys, POP_Status. Default implementation in BaseStatusBar responds only to POP_Log by toggling the value of the ShowLog field.
  • virtual bool MustDrawLog(int state); - This gets called when ShowLog is set to true and the engine attempts to draw a generic log screen (it has built-in functionality for doing that). If you plan to implement a custom log screen, you should probably override this method to return false.

Re: Help with zscript statusbar

PostPosted: Tue Oct 13, 2020 10:35 am
by ramon.dexter
Yeah, thanks for the help, I really appreciate it ;). Tried playing with strife statusbar and got something out.
I just took strife's statusbar code and commented most of it.
Looks like there is something hard-coded into gzdoom itself, becuase when I commented out most of the code, this happened:
Code: Select allExpand view
class soaStatusBar : BaseStatusBar
{
   InventoryBarState diparms;
   InventoryBarState diparms_argsbar;
   HUDFont mHUDFont;
   HUDFont mIndexFont;
   HUDFont mYelFont, mGrnFont, mBigFont;
   // Number of tics to move the popscreen up and down.
   const POP_TIME = (Thinker.TICRATE/8);

   // Popscreen height when fully extended
   const POP_HEIGHT = 104;

   // Number of tics to scroll keys left
   const KEY_TIME = (Thinker.TICRATE/3);

   enum eImg
   {
      imgINVCURS,
      imgCURSOR01,
      imgINVPOP,
      imgINVPOP2,
      imgINVPBAK,
      imgINVPBAK2,
      imgFONY0,
      imgFONY1,
      imgFONY2,
      imgFONY3,
      imgFONY4,
      imgFONY5,
      imgFONY6,
      imgFONY7,
      imgFONY8,
      imgFONY9,
      imgFONY_PERCENT,
      imgNEGATIVE,
   };
   
   TextureID Images[imgNEGATIVE + 1];
   int CursorImage;
   int CurrentPop, PendingPop, PopHeight, PopHeightChange;
   int KeyPopPos, KeyPopScroll;
   
   //HUDFont mYelFont, mGrnFont, mBigFont;

   override void Init()
   {
   
      Font fnt = "INDEXFONT";
      mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true);
      diparms = InventoryBarState.Create(mIndexFont);
      diparms_argsbar = InventoryBarState.CreateNoBox(mIndexFont, boxsize:(36, 30), innersize:(40, 30), arrowoffs:(0, 0));
      static const Name strifeLumpNames[] =
      {
         "INVCURS", "CURSOR01", "INVPOP", "INVPOP2",
         "INVPBAK", "INVPBAK2",
         "INVFONY0", "INVFONY1", "INVFONY2", "INVFONY3", "INVFONY4",
         "INVFONY5", "INVFONY6", "INVFONY7", "INVFONY8", "INVFONY9",
         "INVFONY%", ""

      };
      
      Super.Init();
      SetSize(32, 320, 200);
      Reset();
      
      //for(int i = 0; i <= imgNEGATIVE; i++)
      //{
         //Images[i] = TexMan.CheckForTexture(strifeLumpNames[i], TexMan.TYPE_MiscPatch);
      //}

      //CursorImage = Images[imgINVCURS].IsValid() ? imgINVCURS : imgCURSOR01;
      
      mYelFont = HUDFont.Create("Indexfont_Strife_Yellow", 7, Mono_CellLeft, 1, 1);
      mGrnFont = HUDFont.Create("Indexfont_Strife_Green", 7, Mono_CellLeft, 1, 1);
      mBigFont = HUDFont.Create("BigFont", 0, Mono_Off, 2, 2);
   }

   override void NewGame ()
   {
      Super.NewGame();
      Reset ();
   }

   override int GetProtrusion(double scaleratio) const
   {
      return 10;
   }

   override void Draw (int state, double TicFrac)
   {
      Super.Draw (state, TicFrac);

      if (state == HUD_StatusBar)
      {
         BeginStatusBar();
         DrawMainBar (TicFrac);
      }
      else
      {
         if (state == HUD_Fullscreen)
         {
            BeginHUD();
            DrawFullScreenStuff ();
         }

         // Draw pop screen (log, keys, and status)
         if (CurrentPop != POP_None && PopHeight < 0)
         {
            // This uses direct low level draw commands and would otherwise require calling
            // BeginStatusBar(true);
            DrawPopScreen (screen.GetHeight(), TicFrac);
         }
      }
   }

   override void ShowPop (int popnum)
   {
      Super.ShowPop(popnum);
      if (popnum == CurrentPop || (popnum == POP_LOG && MustDrawLog(0)))
      {
         if (popnum == POP_Keys)
         {
            Inventory item;

            KeyPopPos += 10;
            KeyPopScroll = 280;

            int i = 0;
            for (item = CPlayer.mo.Inv; item != NULL; item = item.Inv)
            {
               if (item is "Key")
               {
                  if (i == KeyPopPos)
                  {
                     return;
                  }
                  i++;
               }
            }
         }
         PendingPop = POP_None;
         // Do not scroll keys horizontally when dropping the popscreen
         KeyPopScroll = 0;
         KeyPopPos -= 10;
      }
      else
      {
         KeyPopPos = 0;
         PendingPop = popnum;
      }
   }

   override bool MustDrawLog(int state)
   {
      // Tell the base class to draw the log if the pop screen won't be displayed.
      return generic_ui || log_vgafont;
   }

   void Reset ()
   {
      CurrentPop = POP_None;
      PendingPop = POP_NoChange;
      PopHeight = 0;
      KeyPopPos = 0;
      KeyPopScroll = 0;
   }

   override void Tick ()
   {
      Super.Tick ();

      PopHeightChange = 0;
      if (PendingPop != POP_NoChange)
      {
         if (PopHeight < 0)
         {
            PopHeightChange = POP_HEIGHT / POP_TIME;
            PopHeight += POP_HEIGHT / POP_TIME;
         }
         else
         {
            CurrentPop = PendingPop;
            PendingPop = POP_NoChange;
         }
      }
      else
      {
         if (CurrentPop == POP_None)
         {
            PopHeight = 0;
         }
         else if (PopHeight > -POP_HEIGHT)
         {
            PopHeight -= POP_HEIGHT / POP_TIME;
            if (PopHeight < -POP_HEIGHT)
            {
               PopHeight = -POP_HEIGHT;
            }
            else
            {
               PopHeightChange = -POP_HEIGHT / POP_TIME;
            }
         }
         if (KeyPopScroll > 0)
         {
            KeyPopScroll -= 280 / KEY_TIME;
            if (KeyPopScroll < 0)
            {
               KeyPopScroll = 0;
            }
         }
      }
   }

   private void FillBar(double x, double y, double start, double stopp, Color color1, Color color2)
   {
   /*
      Fill(color1, x, y, (stopp-start)*2, 1);
      Fill(color2, x, y+1, (stopp-start)*2, 1);*/
   }
   
   protected void DrawHealthBar(int health, int x, int y)
   {
      /*
      Color green1 = Color(255, 180, 228, 128);   // light green
      Color green2 = Color(255, 128, 180, 80);   // dark green

      Color blue1 = Color(255, 196, 204, 252);   // light blue
      Color blue2 = Color(255, 148, 152, 200);   // dark blue

      Color gold1 = Color(255, 224, 188, 0);   // light gold
      Color gold2 = Color(255, 208, 128, 0);   // dark gold

      Color red1 = Color(255, 216, 44,  44);   // light red
      Color red2 = Color(255, 172, 28,  28);   // dark red
      
      if (health == 999)
      {
         FillBar (x, y, 0, 100, gold1, gold2);
      }
      else
      {
         if (health <= 100)
         {
            if (health <= 10)
            {
               FillBar (x, y, 0, health, red1, red2);
            }
            else if (health <= 20)
            {
               FillBar (x, y, 0, health, gold1, gold2);
            }
            else
            {
               FillBar (x, y, 0, health, green1, green2);
            }
            //FillBar (x, y, health, 100, 0, 0);
         }
         else
         {
            int stopp = 200 - health;
            FillBar (x, y, 0, stopp, green1, green2);
            FillBar (x, y, stopp, 100, blue1, blue2);
         }
      }*/
   }

   protected void DrawMainBar (double TicFrac)
   {
      DrawImage("HGframw", (-54, 0), DI_ITEM_OFFSETS);
      /*
      Inventory item;
      int i;

      // Pop screen (log, keys, and status)
      if (CurrentPop != POP_None && PopHeight < 0)
      {
         double tmp, h;
         [tmp, tmp, h] = StatusbarToRealCoords(0, 0, 8);
         DrawPopScreen (int(GetTopOfStatusBar() - h), TicFrac);
      }
       
       
      //DrawImage("INVBACK", (0, 168), DI_ITEM_OFFSETS);
      //DrawImage("INVTOP", (0, 160), DI_ITEM_OFFSETS);

      // Health
      DrawString(mGrnFont, FormatNumber(CPlayer.health, 3, 5), (79, 162), DI_TEXT_ALIGN_RIGHT);
      int points;
      if (CPlayer.cheats & CF_GODMODE)
      {
         points = 999;
      }
      else
      {
         points = min(CPlayer.health, 200);
      }
      //DrawHealthBar (points, 49, 172);
      //DrawHealthBar (points, 49, 175);

      // Armor
      item = CPlayer.mo.FindInventory('BasicArmor');
      if (item != NULL && item.Amount > 0)
      {
         DrawInventoryIcon(item, (2, 177), DI_ITEM_OFFSETS);
         DrawString(mYelFont, FormatNumber(item.Amount, 3, 5), (27, 191), DI_TEXT_ALIGN_RIGHT);
      }

      // Ammo
      Inventory ammo1 = GetCurrentAmmo ();
      if (ammo1 != NULL)
      {
         DrawString(mGrnFont, FormatNumber(ammo1.Amount, 3, 5), (311, 162), DI_TEXT_ALIGN_RIGHT);
         DrawInventoryIcon (ammo1, (290, 181), DI_ITEM_OFFSETS);
      }

      // Sigil
      /*item = CPlayer.mo.FindInventory('Sigil');
      if (item != NULL)
      {
         DrawInventoryIcon (item, (253, 175), DI_ITEM_OFFSETS);
      }*/
      /*
      // Inventory
      if (isInventoryBarVisible())
      {
         DrawImage("HGinvF", (21, 168), DI_ITEM_OFFSETS);
         DrawInventoryBar(diparms_argsbar, (35, 170), 7, DI_ITEM_LEFT_TOP);
      }
      /*CPlayer.inventorytics = 0;
      CPlayer.mo.InvFirst = ValidateInvFirst (6);
      i = 0;
      for (item = CPlayer.mo.InvFirst; item != NULL && i < 6; item = item.NextInv())
      {
         int flags = item.Amount <= 0? DI_ITEM_OFFSETS|DI_DIM : DI_ITEM_OFFSETS;
         if (item == CPlayer.mo.InvSel)
         {
            DrawTexture (Images[CursorImage], (42 + 35*i, 180), flags, 1. - itemflashFade);
         }
         DrawInventoryIcon (item, (48 + 35*i, 182), flags);
         DrawString(mYelFont, FormatNumber(item.Amount, 3, 5), (75 + 35*i, 191), DI_TEXT_ALIGN_RIGHT);
         i++;
      }*/
   }

   protected void DrawFullScreenStuff ()
   {
      /*
      // Draw health (use red color if health is below the run health threashold.)
      DrawString(mGrnFont, FormatNumber(CPlayer.health, 3), (4, -10), DI_TEXT_ALIGN_LEFT, (CPlayer.health < CPlayer.mo.RunHealth)? Font.CR_BRICK : Font.CR_UNTRANSLATED);
      DrawImage("I_MDKT", (14, -17));

      // Draw armor
      let armor = CPlayer.mo.FindInventory('BasicArmor');
      if (armor != NULL && armor.Amount != 0)
      {
         DrawString(mYelFont, FormatNumber(armor.Amount, 3), (35, -10));
         DrawInventoryIcon(armor, (45, -17));
      }

      // Draw ammo
      Inventory ammo1, ammo2;
      int ammocount1, ammocount2;

      [ammo1, ammo2, ammocount1, ammocount2] = GetCurrentAmmo ();
      if (ammo1 != NULL)
      {
         // Draw primary ammo in the bottom-right corner
         DrawString(mGrnFont, FormatNumber(ammo1.Amount, 3), (-23, -10));
         DrawInventoryIcon(ammo1, (-14, -17));
         if (ammo2 != NULL && ammo1!=ammo2)
         {
            // Draw secondary ammo just above the primary ammo
            DrawString(mGrnFont, FormatNumber(ammo1.Amount, 3), (-23, -48));
            DrawInventoryIcon(ammo1, (-14, -55));
         }
      }

      if (deathmatch)
      { // Draw frags (in DM)
         DrawString(mBigFont, FormatNumber(CPlayer.FragCount, 3), (4, 1));
      }

      // Draw inventory
      if (CPlayer.inventorytics == 0)
      {
         if (CPlayer.mo.InvSel != null)
         {
            if (itemflashFade > 0)
            {
               DrawTexture(Images[CursorImage], (-42, -15));
            }
            DrawString(mYelFont, FormatNumber(CPlayer.mo.InvSel.Amount, 3, 5), (-30, -10), DI_TEXT_ALIGN_RIGHT);
            DrawInventoryIcon(CPlayer.mo.InvSel, (-42, -17), DI_DIMDEPLETED);
         }
      }
      else
      {
         CPlayer.mo.InvFirst = ValidateInvFirst (6);
         int i = 0;
         Inventory item;
         Vector2 box = TexMan.GetScaledSize(Images[CursorImage]) - (4, 4);   // Fit oversized icons into the box.
         if (CPlayer.mo.InvFirst != NULL)
         {
            for (item = CPlayer.mo.InvFirst; item != NULL && i < 6; item = item.NextInv())
            {
               if (item == CPlayer.mo.InvSel)
               {
                  DrawTexture(Images[CursorImage], (-90+i*35, -3), DI_SCREEN_CENTER_BOTTOM, 0.75);
               }
               if (item.Icon.isValid())
               {
                  DrawInventoryIcon(item, (-90+i*35, -5), DI_SCREEN_CENTER_BOTTOM|DI_DIMDEPLETED, 0.75);
               }
               DrawString(mYelFont, FormatNumber(item.Amount, 3, 5), (-72 + i*35, -8), DI_TEXT_ALIGN_RIGHT|DI_SCREEN_CENTER_BOTTOM);
               ++i;
            }
         }
      }*/
   }

   protected void DrawPopScreen (int bottom, double TicFrac)
   {
   /*
      String buff;
      String label;
      int i;
      Inventory item;
      int xscale, yscale, left, top;
      //int bars = (CurrentPop == POP_Status) ? imgINVPOP : imgINVPOP2;
      //int back = (CurrentPop == POP_Status) ? imgINVPBAK : imgINVPBAK2;
      // Extrapolate the height of the popscreen for smoother movement
      int height = clamp (PopHeight + int(TicFrac * PopHeightChange), -POP_HEIGHT, 0);

      xscale = CleanXfac;
      yscale = CleanYfac;
      left = screen.GetWidth()/2 - 160*CleanXfac;
      top = bottom + height * yscale;

      screen.DrawTexture (Images[back], true, left, top, DTA_CleanNoMove, true, DTA_Alpha, 0.75);
      screen.DrawTexture (Images[bars], true, left, top, DTA_CleanNoMove, true);


      switch (CurrentPop)
      {
      case POP_Log:
      {
         // Draw the latest log message.
         screen.DrawText(SmallFont2, Font.CR_UNTRANSLATED, left + 210 * xscale, top + 8 * yscale, Level.TimeFormatted(),
            DTA_CleanNoMove, true);

         if (CPlayer.LogText.Length() > 0)
         {
            let text = Stringtable.Localize(CPlayer.LogText);
            BrokenLines lines = SmallFont2.BreakLines(text, 272);
            for (i = 0; i < lines.Count(); ++i)
            {
               screen.DrawText(SmallFont2, Font.CR_UNTRANSLATED, left + 24 * xscale, top + (18 + i * 12)*yscale,
                  lines.StringAt(i), DTA_CleanNoMove, true);
            }
         }
         break;
      }

      case POP_Keys:
         // List the keys the player has.
         int pos, endpos, leftcol;
         int clipleft, clipright;
         
         pos = KeyPopPos;
         endpos = pos + 10;
         leftcol = 20;
         clipleft = left + 17*xscale;
         clipright = left + (320-17)*xscale;
         if (KeyPopScroll > 0)
         {
            // Extrapolate the scroll position for smoother scrolling
            int scroll = MAX (0, KeyPopScroll - int(TicFrac * (280./KEY_TIME)));
            pos -= 10;
            leftcol = leftcol - 280 + scroll;
         }
         i = 0;
         for (item = CPlayer.mo.Inv; i < endpos && item != NULL; item = item.Inv)
         {
            if (!(item is "Key"))
               continue;
            
            if (i < pos)
            {
               i++;
               continue;
            }

            label = item.GetTag();

            int colnum = ((i-pos) / 5) & (KeyPopScroll > 0 ? 3 : 1);
            int rownum = (i % 5) * 18;

            screen.DrawTexture (item.Icon, true,
               left + (colnum * 140 + leftcol)*xscale,
               top + (6 + rownum)*yscale,
               DTA_CleanNoMove, true,
               DTA_ClipLeft, clipleft,
               DTA_ClipRight, clipright);
            screen.DrawText (SmallFont2, Font.CR_UNTRANSLATED,
               left + (colnum * 140 + leftcol + 17)*xscale,
               top + (11 + rownum)*yscale,
               label,
               DTA_CleanNoMove, true,
               DTA_ClipLeft, clipleft,
               DTA_ClipRight, clipright);
            i++;
         }
         break;

      case POP_Status:
         // Show miscellaneous status items.
         
         // Print stats
         DrINumber2 (CPlayer.mo.accuracy, left+268*xscale, top+28*yscale, 7*xscale, imgFONY0);
         DrINumber2 (CPlayer.mo.stamina, left+268*xscale, top+52*yscale, 7*xscale, imgFONY0);

         // How many keys does the player have?
         i = 0;
         for (item = CPlayer.mo.Inv; item != NULL; item = item.Inv)
         {
            if (item is "Key")
            {
               i++;
            }
         }
         DrINumber2 (i, left+268*xscale, top+76*yscale, 7*xscale, imgFONY0);

         // Does the player have a communicator?
         item = CPlayer.mo.FindInventory ("Communicator");
         if (item != NULL)
         {
            screen.DrawTexture (item.Icon, true,
               left + 280*xscale,
               top + 74*yscale,
               DTA_CleanNoMove, true);
         }

         // How much ammo does the player have?
         static const class<Ammo> AmmoList[] = {
            "ClipOfBullets",         
            "PoisonBolts",            
            "ElectricBolts",         
            "HEGrenadeRounds",         
            "PhosphorusGrenadeRounds",   
            "MiniMissiles",         
            "EnergyPod"};            
            
         static const int AmmoY[] = {19, 35, 43, 59, 67, 75, 83};
         
         for (i = 0; i < 7; ++i)
         {
            item = CPlayer.mo.FindInventory (AmmoList[i]);

            if (item == NULL)
            {
               DrINumber2 (0, left+206*xscale, top+AmmoY[i] * yscale, 7*xscale, imgFONY0);
               DrINumber2 (GetDefaultByType(AmmoList[i]).MaxAmount, left+239*xscale, top+AmmoY[i] * yscale, 7*xscale, imgFONY0);
            }
            else
            {
               DrINumber2 (item.Amount, left+206*xscale, top+AmmoY[i] * yscale, 7*xscale, imgFONY0);
               DrINumber2 (item.MaxAmount, left+239*xscale, top+AmmoY[i] * yscale, 7*xscale, imgFONY0);
            }
         }
               

         // What weapons does the player have?
         static const class<Weapon> WeaponList[] =
         {
            "StrifeCrossbow",
            "AssaultGun",
            "FlameThrower",
            "MiniMissileLauncher",
            "StrifeGrenadeLauncher",
            "Mauler"
         };
         static const int WeaponX[] = {23, 21, 57, 20, 55, 52};
         static const int WeaponY[] = {19, 41, 50, 64, 20, 75};

         for (i = 0; i < 6; ++i)
         {
            item = CPlayer.mo.FindInventory (WeaponList[i]);
            if (item != NULL)
            {
               screen.DrawTexture (item.Icon, true,
                  left + WeaponX[i] * xscale,
                  top + WeaponY[i] * yscale,
                  DTA_CleanNoMove, true,
                  DTA_LeftOffset, 0,
                  DTA_TopOffset, 0);
            }
         }
         break;
      }*/
   }

   void DrINumber2 (int val, int x, int y, int width, int imgBase) const
   {/*
      x -= width;

      if (val == 0)
      {
         screen.DrawTexture (Images[imgBase], true, x, y, DTA_CleanNoMove, true);
      }
      else
      {
         while (val != 0)
         {
            screen.DrawTexture (Images[imgBase+val%10], true, x, y, DTA_CleanNoMove, true);
            val /= 10;
            x -= width;
         }
      }*/
   }
}


[img]
https://lh3.googleusercontent.com/wdez6 ... 2Z5GAieObw
[/img]

Notice the black rectangle down. It is not part of my graphic. I haven't found definition of this anywhere in the code (tho I'm not 100% sure if I read the code correctly). What is causing this rectangle to draw? I have to note this not happens when using sbarinfo.

Re: Help with zscript statusbar

PostPosted: Tue Oct 13, 2020 10:48 am
by Player701
Your code sample wrote:
Code: Select allExpand view
override void Init()
{
    ...
    SetSize(32, 320, 200);
    ...
}

This sets the virtual dimensions of the status bar area: 32 is the height, and 320x200 is the total drawing area. When the HUD is in status bar mode (state == HUD_StatusBar), the bottom area of the screen is reserved for the status bar and scaled according to your HUD scale settings. The black rectangles appear because the status bar area doesn't cover the entire screen. And since you have commented everything out in DrawMainBar, the status bar itself doesn't get drawn, so there's nothing between them.

To solve this, you need to either remove the call to SetSize altogether (although this may cause glitches if you're using an old GZDoom version) or change the value of the first argument from 32 to 0.

Re: Help with zscript statusbar

PostPosted: Thu Oct 15, 2020 2:53 am
by ramon.dexter
Oh, is it really that simple? OK, maybe I'm starting to move somewhere. Many thanks buddy :wink: