Skip to content

Commit

Permalink
NUGHUD versioning, bump to version 2
Browse files Browse the repository at this point in the history
I determined that the offsets of some patches drawn by the NUGHUD should be ignored to improve support for mods which replace graphics used by it (e.g. ammo pickups).

Since that would break some existing HUDs, I decided to introduce a NUGHUD versioning system. The change described above will only take effect for HUDs of version 2 and greater.
  • Loading branch information
MrAlaux committed Oct 20, 2023
1 parent aaea5d0 commit 034efe9
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 57 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ None.

## Changes

None.
- **Bumped `NUGHUD` version to `2`** (see details in `docs/nughud.md`)

## Bug Fixes

- **Buggy caching of Status Bar bezel graphic** [thanks to @ceski-1]
None.
5 changes: 4 additions & 1 deletion docs/nughud.lmp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
; Default Nugget HUD distribution
; Default NUGHUD

; NUGHUD version
nughud_version 2

; - Widgets -

Expand Down
83 changes: 51 additions & 32 deletions docs/nughud.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,40 @@ names and values, optionally separated by blank or comment lines.

## NUGHUD widgets

**The Nugget HUD is composed of widgets**, whose behavior is determined by a set of properties.
**`NUGHUD` is composed of widgets**, whose behavior is determined by a set of properties.

The following properties are shared across all widgets:

- `_x`: **X position**, which can be any number between 0 and 320 (inclusive).
- `_y`: **Y position**, which can be any number between 0 and 200 (inclusive).
- `_x`: **X position**, which can be any number between `0` and `320` (inclusive).
- `_y`: **Y position**, which can be any number between `0` and `200` (inclusive).
- `_wide`: **Widescreen shift**, with the following possible values:
- -2 to shift the element left forcefully;
- -1 to shift the element left only when using the widescreen Nugget HUD;
- 0 to keep the element in place regardless of widescreen;
- 1 to shift the element right only when using the widescreen Nugget HUD;
- 2 to shift the element right forcefully.
- `-2` to shift the element left forcefully;
- `-1` to shift the element left only when in widescreen mode;
- ` 0` to keep the element in place regardless of widescreen mode;
- ` 1` to shift the element right only when in widescreen mode;
- ` 2` to shift the element right forcefully.

The following types of widgets support special behavior:

- **Disableables**: Can be disabled by setting `_x` to -1.
- **Disableables**: Can be disabled by setting `_x` to `-1`.
- **Alignables**: Can be aligned by means of the `_align` property, with the following possible values:
- -1 for left alignment;
- 0 for centered alignment;
- 1 for right alignment.
- `-1` for left alignment;
- ` 0` for centered alignment;
- ` 1` for right alignment.

The following widgets are available:

| Widget(s) | Disableable | Alignable | Description |
| :----------------: | :---------: | :-------: | :---------- |
| `nughud_ammo` | Yes | Yes | Ammo count for the currently-equipped weapon |
| `nughud_health` | Yes | Yes | Health count |
| `nughud_arms#` | Yes | No | Arms (weapon) number, where # is a number between 1 and 9 (inclusive) |
| `nughud_arms#` | Yes | No | Arms (weapon) number, where # is a number between `1` and `9` (inclusive) |
| `nughud_frags` | Yes | Yes | Frags count, only shown during Deathmatch games |
| `nughud_face` | Yes | No | Face (Mugshot) |
| `nughud_armor` | Yes | Yes | Armor count |
| `nughud_armoricon` | Yes | No | Armor icon, which changes depending on armor type (requires NHARMOR font - see below) |
| `nughud_key#` | Yes | No | Key display, where # is a number between 0 and 2 (in order: Blue Key; Yellow Key; Red Key) |
| `nughud_ammo#` | Yes | Yes | Ammo count for each type, where # is a number between 0 and 3 (in order: Bullets; Shells; Cells; Rockets) |
| `nughud_key#` | Yes | No | Key display, where # is a number between `0` and `2` (in order: Blue Key; Yellow Key; Red Key) |
| `nughud_ammo#` | Yes | Yes | Ammo count for each type, where # is a number between `0` and `3` (in order: Bullets; Shells; Cells; Rockets) |
| `nughud_maxammo#` | Yes | Yes | Same as the above, but for Max Ammo |
| `nughud_time` | No | Yes | Time display, only shown if enabled by the user |
| `nughud_sts` | No | Yes | Stats (Kills/Items/Secrets) display, only shown if enabled by the user |
Expand All @@ -63,15 +63,15 @@ The following widgets are available:
| `nughud_message` | No | Yes | Message display |
| `nughud_secret` | No | Yes | Secret Message display |

There are some additional boolean properties (value of 0 or 1) for some specific widgets:
There are some additional boolean properties (value of `0` or `1`) for some specific widgets:

- `nughud_face_bg`: Toggle the _Face_ background, whose position is linked to that of the _Face_ itself.
- `nughud_percents`: Toggle drawing of percentage signs for the Health and Armor counts.
- `nughud_time_sts`: Toggle relocation of the _Time_ widget to the position of the _Stats_ widget when the latter is inactive.
- `nughud_sts_ml`: Toggle three-lined _Stats_ widget.
- `nughud_coord_ml`: Toggle three-lined _Coordinates_ widget.

Lastly, the _Message_ widget supports an X position value of -1 to forcefully draw it at its original X position, where it'll be affected by the Centered Messages setting.
Lastly, the _Message_ widget supports an X position value of `-1` to forcefully draw it at its original X position, where it'll be affected by the Centered Messages setting.

#### Examples

Expand Down Expand Up @@ -106,39 +106,39 @@ The following fonts are available:
```
Tall Numbers, used for the Health, Armor, current-weapon Ammo and Frags counts:
NHTNUM# -- Number, where # is a number between 0 and 9 (inclusive)
NHTMINUS - Minus sign
NHTPRCNT - Percent sign
- NHTNUM# -- Number, where # is a number between 0 and 9 (inclusive)
- NHTMINUS - Minus sign
- NHTPRCNT - Percent sign
Current-weapon Ammo Numbers, used exclusively for the current-weapon Ammo count, taking precedence over the Tall Numbers:
NHRNUM# -- Number, where # is a number between 0 and 9 (inclusive)
NHRMINUS - Minus sign
- NHRNUM# -- Number, where # is a number between 0 and 9 (inclusive)
- NHRMINUS - Minus sign
Ammo Numbers, used for the Ammo and Max Ammo counts:
NHAMNUM# - Number, where # is a number between 0 and 9 (inclusive)
- NHAMNUM# - Number, where # is a number between 0 and 9 (inclusive)
Arms Numbers, used for the weapon numbers:
NHW0NUM# - Weapon unavailable, where # is a number between 1 and 9 (inclusive)
NHW1NUM# - Weapon available, where # is a number between 1 and 9 (inclusive)
- NHW0NUM# - Weapon unavailable, where # is a number between 1 and 9 (inclusive)
- NHW1NUM# - Weapon available, where # is a number between 1 and 9 (inclusive)
Keys:
NHKEYS# -- Key, where # is a number between 0 and 8 (inclusive)
- NHKEYS# -- Key, where # is a number between 0 and 8 (inclusive)
Berserk, drawn in place of the Ammo count when using the Berserk Fist:
NHBERSRK - Berserk graphic
- NHBERSRK - Berserk graphic
Armor graphics, used for the Armor icon widget:
NHARMOR# - Graphic, where # is either 0 (no armor), 1 (green armor) or 2 (blue armor)
- NHARMOR# - Graphic, where # is either 0 (no armor), 1 (green armor) or 2 (blue armor)
Infinity, drawn in place of the Ammo count when using weapons with no ammo type (e.g. Fist/Chainsaw):
NHINFNTY - Infinity graphic
- NHINFNTY - Infinity graphic
```

### Patches
Expand Down Expand Up @@ -173,12 +173,31 @@ nughud_patch2_name "STARMS"
### Miscellaneous

**There is an additional fixed-point property, `nughud_weapheight`, to increase the height at which weapon sprites are drawn**.
It can be any value between 0 and 200 (inclusive).
It can be any value between `0` and `200` (inclusive).

### Version

Some changes in the handling of the `NUGHUD` lump would result in old lumps not displaying correctly.
To work around this, starting with Nugget Doom 2.3.0, `NUGHUD` supports a version value which determines how certain details are handled.

Since `NUGHUD` was not originally conceived with a version system in place, HUDs made for Nugget Doom versions prior to 2.3.0 did not specify a version.
Due to this, if no version is specified by a HUD, it will be treated as a version 1 HUD to maintain compatibility.

If the version specified by the HUD is lesser than 1 or greater than the current version, it will be treated as a latest-version HUD to improve support of newer HUDs in older Nugget Doom releases.

The current `NUGHUD` version is `2`.
The version differences are listed below:

```
Version 2:
- Patches and Armor Icon graphics ignore the graphics' offsets
```

---

By default and compared to the original Crispy HUD, the Nugget HUD hides the face widget and shows Arms numbers 2-9 instead of 2-7.
By default and compared to the original Crispy HUD, `NUGHUD` hides the face widget and shows Arms numbers `2-9` instead of `2-7`.

**The default distribution for the Nugget HUD**, as defined in the executable, **is available in text format as `nughud.lmp`**, found in the `docs/` folder. Comments were added to it for clarity. Feel free to use it as a base to make new distributions.
**The default `NUGHUD`**, as defined in the executable, **is available in text format as `nughud.lmp`**, found in the `docs/` folder. Comments were added to it for clarity. Feel free to use it as a base to make new HUDs.

It is advised that you do not include values for variables that you do not wish to modify, as to avoid issues if the handling of any of them is altered in the future.
6 changes: 3 additions & 3 deletions src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "m_argv.h"
#include "m_misc.h"
#include "m_misc2.h" // [FG] M_StringDuplicate()
#include "m_nughud.h" // [Nugget]
#include "m_menu.h"
#include "m_swap.h"
#include "i_printf.h"
Expand All @@ -69,6 +68,7 @@
#include "i_endoom.h"
#include "d_quit.h"
#include "r_bmaps.h"
#include "m_nughud.h" // [Nugget]

#include "dsdhacked.h"

Expand Down Expand Up @@ -2552,10 +2552,10 @@ void D_DoomMain(void)

D_ProcessInWads("BRGHTMPS", R_ParseBrightmaps, false);

M_NughudLoadOptions(); // [Nugget]

I_PutChar(VB_INFO, '\n'); // killough 3/6/98: add a newline, by popular demand :)

M_NughudLoadOptions(); // [Nugget]

// Moved after WAD initialization because we are checking the COMPLVL lump
G_ReloadDefaults(false); // killough 3/4/98: set defaults just loaded.
// jff 3/24/98 this sets startskill if it was -1
Expand Down
46 changes: 35 additions & 11 deletions src/m_nughud.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
// Variant of m_misc.c specifically for declaration and loading of NUGHUD
// variables

#include "m_menu.h"
#include "w_wad.h"
#include "i_video.h"
#include "p_mobj.h"
#include <errno.h>

#include "hu_stuff.h"
#include "st_stuff.h"
#include "i_printf.h"
#include "i_video.h"
#include "m_menu.h"
#include "m_misc.h"
#include "m_nughud.h"
#include "p_mobj.h"
#include "st_stuff.h"
#include "w_wad.h"

#include "m_io.h"
#include <errno.h>

#define CURRENTVERSION 2

nughud_t nughud; // Behold!!!

Expand Down Expand Up @@ -60,6 +64,8 @@ nughud_t nughud; // Behold!!!
#define TOGGLE(n, m, v) { n, (config_t *)&(m), NULL, { v }, { 0, 1 }, number }

default_t nughud_defaults[] = {
{ "nughud_version", (config_t *)&nughud.version, NULL, { 1 }, { 1, CURRENTVERSION }, number },

WIDGET2( "nughud_ammo", nughud.ammo, ST_AMMOX, ST_AMMOY, -1, 1 ),
WIDGET2( "nughud_health", nughud.health, ST_HEALTHX, ST_HEALTHY, -1, 1 ),
WIDGET( "nughud_arms1", nughud.arms[0], -1, 0, 0 ),
Expand Down Expand Up @@ -193,17 +199,21 @@ static boolean M_NughudParseOption(const char *p, boolean wad)
if (sscanf(strparm, "%i", &parm) != 1) { return 1; } // Not A Number

//jff 3/4/98 range check numeric parameters
if ((dp->limit.min == UL || dp->limit.min <= parm)
&& (dp->limit.max == UL || dp->limit.max >= parm))
if (!strcmp(name, "nughud_version") // [Nugget] Unless it's the lump version
|| ( (dp->limit.min == UL || dp->limit.min <= parm)
&& (dp->limit.max == UL || dp->limit.max >= parm)))
{
if (wad) {
if (wad)
{
if (!dp->modified) { // First time it's modified by wad
dp->modified = 1; // Mark it as modified
dp->orig_default.i = dp->location->i; // Save original default
}

if (dp->current) // Change current value
{ dp->current->i = parm; }
}

dp->location->i = parm; // Change default
}
}
Expand All @@ -222,19 +232,33 @@ void M_NughudLoadOptions(void)
{
int size = W_LumpLength(lump), buflen = 0;
char *buf = NULL, *p, *options = p = W_CacheLumpNum(lump, PU_STATIC);

while (size > 0)
{
int len = 0;

while (len < size && p[len++] && p[len-1] != '\n');
if (len >= buflen)
{ buf = I_Realloc(buf, buflen = len+1); }

if (len >= buflen) { buf = I_Realloc(buf, buflen = len+1); }

strncpy(buf, p, len)[len] = 0;
p += len;
size -= len;

M_NughudParseOption(buf, true);
}

free(buf);
Z_ChangeTag(options, PU_CACHE);

if (!(1 <= nughud.version && nughud.version <= CURRENTVERSION))
{
I_Printf(VB_WARNING, "NUGHUD: Unsupported version '%i' detected.\n"
" Defaulting to latest version '%i'.\n",
nughud.version, CURRENTVERSION);

nughud.version = CURRENTVERSION;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/m_nughud.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef struct nughud_patch_s {
#define NUMNUGHUDPATCHES 8

typedef struct nughud_s {
int version;

nughud_alignable_t ammo;
nughud_alignable_t health;
nughud_widget_t arms[9];
Expand All @@ -69,6 +71,7 @@ typedef struct nughud_s {
nughud_alignable_t message;
nughud_alignable_t secret;
nughud_patch_t patches[NUMNUGHUDPATCHES];

boolean percents;
fixed_t weapheight;
} nughud_t;
Expand Down
34 changes: 26 additions & 8 deletions src/st_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,22 +898,40 @@ void ST_drawWidgets(void)

// [Nugget] Draw NUGHUD patches and Armor icon
if (st_crispyhud) {
patch_t *patch;
int x, y;

for (i = 0; i < NUMNUGHUDPATCHES; i++)
{
if (nughud_patchlump[i] >= 0) {
patch_t *const patch = W_CacheLumpNum(nughud_patchlump[i], PU_STATIC);
patch = W_CacheLumpNum(nughud_patchlump[i], PU_STATIC);

x = nughud.patches[i].x + NUGHUDWIDESHIFT(nughud.patches[i].wide)
- ((nughud.patches[i].align == 1) ? SHORT(patch->width) :
(nughud.patches[i].align == 0) ? SHORT(patch->width)/2 : 0);

y = nughud.patches[i].y;

if (nughud.version >= 2) {
x += SHORT(patch->leftoffset);
y += SHORT(patch->topoffset);
}

V_DrawPatch(nughud.patches[i].x + NUGHUDWIDESHIFT(nughud.patches[i].wide)
- ((nughud.patches[i].align == 1) ? SHORT(patch->width) :
(nughud.patches[i].align == 0) ? SHORT(patch->width)/2 : 0),
nughud.patches[i].y, FG, patch);
V_DrawPatch(x, y, FG, patch);
}
}

if (nughud.armoricon.x > -1 && nharmor[0]) {
V_DrawPatch(nughud.armoricon.x + NUGHUDWIDESHIFT(nughud.armoricon.wide),
nughud.armoricon.y, FG,
nharmor[BETWEEN(0, 2, plyr->armortype)]);
patch = nharmor[BETWEEN(0, 2, plyr->armortype)];
x = nughud.armoricon.x + NUGHUDWIDESHIFT(nughud.armoricon.wide);
y = nughud.armoricon.y;

if (nughud.version >= 2) {
x += SHORT(patch->leftoffset);
y += SHORT(patch->topoffset);
}

V_DrawPatch(x, y, FG, patch);
}
}

Expand Down

0 comments on commit 034efe9

Please sign in to comment.