Our MMORPG's interface gets a look of its own, in the game's colours, with two fonts and panels with their corners cut, drawn over Dear ImGui and raylib in C++. It scales with the screen's height, from 720p to 4K, and a size the player sets. The menu bar goes: Escape closes what's open and then opens the game's menu, with the settings in pages. Your frame shows your face, rendered each frame, a compass along the top shows the monster you picked, the quests and the gates, and the minimap is round, zooms and can turn with the camera. This is episode 63 of a series about building an MMORPG from scratch in C++, with the focus on the engineering around the game.
Topics: Graphics
The code
Each step on screen is a tag in the game's repository. The code at the end of the episode is ep063/end.
Transcript
Intro
0:00 Welcome back to the series, where in episode sixty-three, we're going to give the game's interface a look of its own, which is the first half of a new interface, from the compass along the top to the minimap. First, a quick look at what we'll have by the end.
0:15 By the end of the episode, the interface is in the game's colours, with the player's face in the top left and a round minimap in the top right. The monster we pick gets a frame at the top in the middle, and a skull on the compass, which turns with the camera, with the quests and the gates on it. And Escape opens the game's menu, over the world.
0:35 The project has a website, with a link to the code on GitHub, which is open source, and a page for each episode, with its chapters and the code at each of its steps.
Last time
0:45 A quick reminder of where we left off, first. Last time, a skill could dash the player across the ground on the server, leaving copies of them behind, and a blow could throw a monster up, hold it there and dash it down, for two seconds at most. With those, the sword got five new skills, from a spin through a group to one wide cut, with the camera going in close for a skill of our own.
Today
1:08 Here's how the interface looks in the game as it stands. It's ImGui's dark look, in its default blue and grey, with our frame and the quests in two corners, the minimap in a third, and the chat in the fourth, each a plain box. The bag and the character are ImGui's windows, with a blue title bar, and buttons for slots. Along the top is ImGui's menu bar, like a desktop program's, and the minimap and the map are squares of the land, north up. It works, and it's what ImGui gives us for free, but a screenshot of it looks like a tool, not a game.
1:42 Most other games draw their interface in a style of their own, so that a screenshot says which game it is. Ours is going to keep ImGui underneath, for its input, its layout and its text, and draw the look on top. So first, the game's own colours and two fonts, at a scale that follows the window's height, times a size the player picks. Then a panel of our own for each window, and a menu on Escape in place of the menu bar. After that, the HUD: our face in the top left, and the monster we pick at the top, a compass along the top, and a round minimap. All right, let's get going, with the colours.
Colours, fonts and a scale
2:21 This episode's code is a new minor version, so in the top CMake file, the project goes to zero point sixty-three. In the client's CMake file, a new file, theme, goes into the client's core library, and its test into the client's tests. And the assets target copies one more folder next to the client, fonts, as the client reads its fonts from files at run time, from beside it, like the music and the monsters.
2:46 The fonts go in a folder of the assets. We're going to set the titles in Cinzel's bold, whose carved capitals read as a fantasy game straight away. The rest goes in Alegreya Sans, a book face with a bit of calligraphy in it, which stays easy to read at small sizes, in a medium and a bold. Both come from Google Fonts, under the SIL Open Font License, which lets a game ship them, as long as the licence goes with them, so it's in the folder beside each.
3:15 The look gets a header file of its own, theme. It brings in ImGui, for its colour and font types, and string. The colours go in a namespace of their own, colors, so a name such as gold reads as colors gold at each use, and doesn't clash with the names a file has already. They're nanoMMO's own colours, the ones the videos and the website use. Night is the near black of a fire that's gone low, which the panels are made of. Each is inline constexpr, a constant the compiler knows, which a header can define without each file that includes it getting a copy of its own. An ImU32 is how ImGui's drawing takes a colour, red, green, blue and alpha in a single number, and IM_COL32 packs them. Coal is a little lighter, for the top of a panel. Wine is the darkest of the three reds, crimson is about twice as bright, and red is the brightest, for what's pressed. Ember is an orange red, and flame, a warm orange, is for a link. Gold is for what's prized, such as the titles we'll draw, which fade from a light gold at the top of their letters to a dark gold at their foot. Brass goes on the edges, the trim round each panel, gold gone dark with age. Paper is the cream of old paper, for words. Muted is paper gone grey, for words that matter less, and faint is greyer still. Shadow is a black that's about four fifths opaque, and the two reds are for the health bars to come, bright on top and dark at the foot. And good is a green, for a quest that's done. Faded gives back a colour with its alpha times a share, as most of what we draw fades in or sits over the world. Fonts holds the faces the interface is set in, and before they're loaded, as in tests, each is ImGui's own. They're pointers to fonts ImGui keeps: the text, the bold and the title. GetFonts hands them out, so the code that draws doesn't have to check for null. LoadFonts loads them from a folder, in ImGui's font loading, with Font Awesome's icons merged into the text face. FontFolder gives the path of that folder, beside the client. The text's size is eighteen, in points at a scale of one, up from the thirteen of ImGui's default font. InterfaceScale works out how much bigger than on a screen 1080 points high the interface is drawn, for a screen of the height, times the player's own size. A 4K screen gets twice the size, so the interface takes up as much of it as of a 1080p one, but a small screen stops at a size that can still be read. UiScale is the scale the theme was last applied at, which the sizes in our layouts get multiplied by. And Ui turns a size in points into one at that scale, for what we draw ourselves, with a twin for a pair of sizes, a width and a height. ApplyTheme sets ImGui's style in our colours, with its sizes and its text at a scale.
6:13 In theme, we bring in ImGui and raylib, which has the file functions we need, algorithm, for clamp, and string. In an unnamed namespace, so they stay in this file, go the fonts once they're loaded, and the scale the theme was last applied at, one to start with. ImGui's style keeps its colours as four floats, so Float4 turns one of our colours into that, and its twin sets the alpha too. AddFont loads one of our fonts, or gives back null when it isn't there, as a missing font is something to draw around, not crash on. So raylib's FileExists checks the path first, as ImGui treats a font file it can't open as an error. Pixel snap keeps each glyph on whole pixels across, which keeps small text sharp, and ImGui adds the font at the text's size. OrDefault hands back the font, or, without one, ImGui's own default, so a client without its fonts still has words. That's ImGui's built-in font, at the text's size, in its vector form, the one the client used before. Faded shifts the alpha out of the colour's top byte, multiplies it by the share, held between nothing and all of it, and masks it back in, leaving the red, green and blue alone. GetFonts returns the fonts we loaded, or, before then, a set of three that are all ImGui's current font, kept in a static, so the reference we hand back stays valid. LoadFonts adds the bold face first, then the title face, each through OrDefault, so a missing file falls back to ImGui's font. The text face goes last, as rlImGui, which joins ImGui to raylib, merges the Font Awesome icons we use in the menu into the last font added, and we want them in the text. Then the text face becomes ImGui's default, the one each window starts in. The folder is fonts, beside the client, wherever it's run from. InterfaceScale divides the screen's height by 1080, so a 1080p screen is a scale of one and a 4K one two. It doesn't go below three quarters, where the eighteen points of text come out at thirteen and a half, and anything smaller gets hard to read. The player's own size goes on top, held between a half and twice, and the result is held between a half and four. ApplyTheme starts from ImGui's default style, so that applying it twice doesn't scale twice, and sets the room inside windows and frames, between items, and round them, at a scale of one. These are a little roomier than ImGui's own, which are made for packing a tool's controls tight, where a game's windows have room to breathe. Windows get square corners, and frames, such as a text field or a slider, a little rounding, like popups, scrollbars, grabs and tabs. Frames and popups get a border, a line in brass, which gives a field its edge on a dark panel, where a dark field on a dark window would otherwise disappear. Titles and the text in a separator go in the middle. Then the colours, which ImGui keeps in an array, one for each part of a widget. Text is paper, and text that matters less, such as the music's credit, is muted. Windows are night, almost opaque, and a child window inside one is clear. Popups, such as a tooltip, are a shade lighter, borders are brass, and the shadow beside a border is clear. A frame is night too, a little more see-through, and as the mouse hovers over it, it glows redder, and redder still while it's active. A title bar is wine, crimson on the window that has focus, and a fainter wine when the window is collapsed. The menu bar along the top is coal. A scrollbar's track is clear, and its grab is wine, crimson under the mouse, and red while it's held. Check marks are gold, on a wine box once a checkbox is ticked, like the mute box. A slider's grab is dark gold, and turns bright while it's held. Buttons are wine, such as the sky's presets, crimson under the mouse, and red as they're pressed. Headers, such as a world in the login screen's list, are wine too, a lighter crimson under the mouse, and full crimson as they're clicked. Brass goes on separators, which turn dark gold under the mouse, and gold as they're dragged. A resize grip, the corner we pull to size a window, is a faint brass, going dark gold, then gold. The text cursor in a field we type into is gold. Tabs are a faded wine, crimson under the mouse and once selected, with a gold line over the selected one. In a window without focus, tabs are dimmed to a fainter wine, the selected one full wine, with a dark gold line. Plots, ImGui's line and bar charts, are gold, a line goes to flame under the mouse, and the bars are dark gold, going gold. A table's header row is wine, its outer borders brass, and the lines between its cells a fainter brass. Its rows are clear, and alternate rows get a touch of white, three percent, so a long list is easy to follow along. A link is flame, selected text sits on crimson, and the lines of a tree are brass. When we drag something over a place it can be dropped, the target gets a gold outline, over a faint wash of gold. The keyboard's cursor is gold, as is the highlight when we switch windows with control and tab, and behind it, the screen is dimmed to half black, and to sixty percent behind a modal window. Then ScaleAllSizes multiplies the paddings, spacings, roundings and border sizes by the scale. It rounds each size down, though, so under a scale of one, a border of one point would round to nothing, and the frames' border is raised back to a pixel at the least. Above it, we write why: scaling rounds sizes down, which takes a one-point border to nothing under a scale of one. The popups' and the separators' borders get that floor too. The text's base size is eighteen, and its main scale, which ImGui multiplies it by, is ours. Since version one point ninety-two, ImGui rasterises a font at the size it's drawn, as it's drawn, so text at twice the size is sharp, not a bitmap stretched. The style replaces ImGui's, and we keep the scale, for Ui. ApplyTheme is cheap, but it rebuilds the style from scratch, so the GUI calls it when the scale changes, not each frame. ImGui reads the font's size and scale as it starts the next frame, so the new size shows from the next frame on.
12:27 The client's Gui starts and ends ImGui's frames. Begin takes the player's own size now, one by default, and starts the frame at the scale for the screen's height times it. It keeps the scale it applied last, under private, starting at zero, so the first frame applies the theme. In gui, we bring in raylib, for the screen's height, and the theme. The callback that rlImGui calls to load fonts, as ImGui starts, used to add ImGui's default font at thirteen pixels. Now it loads ours, from the fonts folder. raylib already scales for a high DPI screen, so above the callback, we note that the fonts need no scaling for them, and that our own scale is for the screen's size, which in raylib is the window's. Begin works out the scale from raylib's screen height, in points, the units ImGui lays out in, so a Retina screen counts as half its pixels. And above it, we say so, as a scale worked out from pixels would come out twice as big on a Retina screen. The style is applied when the scale changes, as when the player picks a new size in the settings or drags the window bigger, not each frame. Then rlImGui begins the frame, as it did before. In window, the window it all runs in gets raylib's resizable flag, next to the high DPI one, so the player can drag it to any size. Above the flags, we write why: the interface follows the window's height, so any size works, from a small window on a laptop to the whole of a 4K monitor.
13:57 The player's own size goes into the settings file, which is in protobuf's text format. So in the settings' proto file, a new message, Interface, holds how the interface looks and is laid out, with the scale as an optional float, so a file without it keeps the default. And the settings get it as ui, field three. In the settings' header file, InterfaceSettings holds the scale, one by default, the size on top of the screen's, from half to twice. It gets a defaulted equals, like the sound's settings, so a test can compare it whole, and Settings keeps it in a new field, ui. In settings, loading reads the scale when the file has one. A player can edit the file by hand, so it's held between a half and twice, and a value that isn't a number keeps the default, as the volumes do. And saving the settings writes it into the file. In the menu's header file, the menu keeps the scale its slider's at, as a member. The interface would change size under the mouse while the slider's held, and the slider with it, so the new size takes effect once the slider's let go of, and the interface grows or shrinks in a single step. In menu, the settings window gets an interface section, first. While nothing's being dragged, or before the menu has a value of its own, the slider shows the settings' scale, in whole percent, so one and a quarter shows as a hundred and twenty-five. Size is a slider from seventy-five to a hundred and fifty, clamped like the sound's sliders, and as it's dragged, the percent becomes the menu's own value. ImGui says when an item that was edited is let go of, and that's when the settings take it. The client writes the settings file once a slider lets go, as it does for the sound. In the client's main, the frame's interface begins at the player's scale.
15:41 Now, let's pin down the scale with a quick test, in a new file, theme test. The first test asks InterfaceScale about a few screens, starting with the player's size at one. A screen 1080 high gets a scale of one, and above it, we write that at 1080 lines it's its own size, twice that at 4K, and the player's own scale goes on top. So 2160 lines gets twice, and a size of one and a quarter gives one and a quarter. A screen six hundred lines high would come out a little over a half, so on a small screen, it stops shrinking at three quarters, before it can't be read. And a scale of ten, past the settings file's ends, is held to twice. And the second test fades a colour: half of an alpha of two hundred is a hundred, with the red, green and blue left alone, and a share past all of it is held to all of it. In the settings' test, the settings kept between runs have a scale of one and a quarter, and a file that leaves the interface out gets its defaults.
16:40 Let's see what that does in the game. The login is in Alegreya Sans now, at three quarters of its size, as the window is 688 points high, and the frames, the chat and the menu bar take the game's colours, from ImGui's style. The bag and the character have our reds, with wine slots and cream words, but they're still ImGui's windows, with its title bar across the top, which is what we'll change next.
Panels of our own
17:05 Each window is going to be drawn as one of our panels, so the theme's header file gets the pieces a panel is drawn from. ImGui can't draw a window in a shape of our own, but it gives each window a draw list. A draw list is the list of triangles a window, or the whole screen, is drawn from, and we can add shapes and text to it ourselves. PathPanel traces a panel's shape on a draw list: a rectangle with its corners cut off. Cut corners read as a game's panel, where rounded ones read as a phone's, and they're cheap to draw, as a cut is a straight line. DrawPanel draws a whole panel in that shape: dark, with a red glow under its title, a brass trim with a thin light inside it, and a gem in each top corner. DrawDiamond draws one of those gems, filled in one colour and outlined in another. DrawDivider draws a line that fades in from its ends, with a diamond in its middle, which goes under a title. DrawShadowedText takes its arguments in the order ImGui's AddText does, and draws the text with a shadow under it, so it reads on any ground, such as words over the grass of the Meadows. DrawGradientText draws text that goes from one colour at its top to another at its bottom, which is how titles get their gold. DrawTitle takes a size and the text, and centres the title on a point, in Cinzel's carved capitals, in that gold. Each panel's title is drawn with it, so the windows all share one look. Shown takes a label, as ImGui's widgets are given them, and gives back the part of an ImGui label that's shown, as ImGui keeps an id after two hashes, so that two windows can show one title. BeginPanel takes a window's name, where to say it's been closed, ImGui's window flags, and an alpha, so that a panel can let more of the world show through behind it. Above it, we write that it begins a window drawn as one of our panels, with its title at the top, and a close button that sets open to false, if open isn't null. EndPanel always goes after it, even when BeginPanel returns false, as ImGui's End does. With a name of its own, it reads as BeginPanel's pair wherever a window is built. GameButton is a button in the panel's shape, dark red, or, for what a window's there for, such as taking a quest, in the colours of a fire. It can be disabled, for something the player can't do just yet. It returns whether it was clicked, so a window acts on a click where it draws the button. In theme, we bring in ImGui's internal header, for a function that shades a run of vertices, cfloat, for the largest float, and utility, for swap. In ApplyTheme, windows lose ImGui's border, as our panels draw their own borders, and child windows lose theirs too. PathPanel goes round the shape clockwise from the top left, two points for each corner, one on each side of its cut. They go on the draw list's path, a list of points that the draw list then fills or strokes in one go, which joins its corners cleanly. DrawDiamond works out its four tips from the centre: the top one above it, the right one to its right, the bottom one below and the left one to its left. AddQuadFilled fills the quad between them, and AddQuad outlines it, at least a pixel wide, so it doesn't vanish at small scales. DrawPanel cuts each corner ten points, at the scale. Its drop is three points to the right and four down, for the shadow, which goes first, a little below and to the right, so that it lifts off the world. The shadow is the panel's shape, moved by the drop, in black at under half the panel's alpha. We remember where the panel's vertices will start in the draw list, for a panel that's dark, a little lighter at the top, as if lit from above. Its shape is filled with night, the darkest of our colours, and ImGui's shade function colours its vertices from coal at the top to night at the bottom, keeping their alpha. A fill can't take a gradient, but its vertices can be shaded after it's made. The glow is forty-six points deep, or half the panel's height, if that's less. Under the title goes a rectangle, two points down and inset by six tenths of a corner's cut. Its top corners are wine at a little over half the alpha, and its bottom ones are clear, so it fades down into the panel. Round it goes the panel's shape once more, stroked in brass, a point and six tenths wide. Three and a half points inside it, with its corners cut three quarters as far, goes a thin light in a faint gold, at twelve percent of the alpha, which reads as a bevel. And in each top corner, where the corner's cut, goes a gem, a diamond four points to its tips, half a cut in from the top and the side. A loop draws one at each of the two centres, listed in braces, in ember inside gold. The divider's middle is half its width along, and the line is a point thick, or a pixel at least. The left half is a rectangle from clear at its left end to dark gold at the middle, as ImGui's multi-colour rectangle takes a colour for each corner, clockwise from the top left. The right half goes back from dark gold to clear. And they meet at a diamond, three and a half points to its tips, filled with night and edged in gold, so it reads as set into the line. Shadowed text works out an offset from its size, a sixteenth of it, and a pixel at least. The text goes first at that offset, in our shadow colour, a black at about four fifths, faded by the alpha in the text's colour, so the shadow fades out with the text. Then the text goes over it, in its own colour. Gradient text takes two colours and the text. Its shadow goes a fourteenth of the size down and to the right. We read the alpha out of the top colour, and draw the shadow in black, at eighty-five percent of that alpha. Then we remember where the text's vertices start, draw it in the top colour with the draw list's AddText, which adds two triangles for each letter. Then we shade it down to the other one. ImGui colours each of those vertices by where it lies between two points, which come next, straight down the line. The glyphs' boxes are taller than their capitals, so the gradient runs over the middle of the line, where the letters are, from a fifth of the size to eighty-five hundredths of it. A title is measured in the title font, without a limit on its width, which is what the largest float from cfloat is for. That way it can be centred, starting half its width to the left of the point, and it goes from gold light to dark gold. Shown cuts the label at its first two hashes, or keeps all of it when there are none. In an unnamed namespace, as nothing outside theme needs it, TitleHeight gives the thirty-four points a panel's title takes at its top, above what's in it. BeginPanel takes an alpha as well, and opens an ImGui window under its name, without an open flag, so ImGui adds no close button of its own. It adds four flags to the caller's: no title bar, no background, no collapsing and no scrollbar. Its background, title and close button are ours, drawn here, while ImGui still moves the window when it's dragged by its empty space, so we keep ImGui's window handling and change how it looks. We take its draw list, and its corners on the screen, from its position and size. The panel is drawn into the window's own draw list first, so it's under everything that goes in the window after it. A window clips what it draws to its own rectangle, so we push the whole screen as the clip rectangle while we draw it, which lets the shadow show past the window's edge, and pop it after. Then the title, nineteen points high, centred near the top, and the divider under it, which leaves eighteen points at each side. A window whose label is all id, after two hashes, has no title, and gets neither. With an open to set, a close button goes in the top right corner, twenty points square, as far in as the window's padding. Any further out, and a window that fits what's in it would grow to fit the button, a little more each frame, which is what we write above it. We save ImGui's cursor, where its next widget goes, and move it to that corner. It's an invisible button, and a click on it sets open to false. An invisible button has ImGui's clicks and hovering without drawing anything, so we keep ImGui's input and draw our own look. Its X is muted, and turns to an ember under the mouse, on a dark red circle as wide as the button. The X is two strokes, two points thick, one from the top left to the bottom right, and one from the bottom left to the top right. Then the cursor goes back where we saved it, so the window's content starts where it would have. If the panel has a title, the cursor moves down to ten points under the divider, unless it's further down already, as what's in the panel starts under its title. And EndPanel ends the window, as ImGui's End does. GameButton sets the shown part of its label in the title font, at seventeen points on a primary button and fifteen on the rest, and measures it, to fit its width to the label unless it's given a size. A width below zero takes the rest of the line, as ImGui's own widgets do, and a width of zero gets the label's width, plus eighteen points each side. A height of zero is forty-four points on a primary button, or thirty-four on the rest. It's an invisible button too, between BeginDisabled and EndDisabled, so a button that isn't enabled doesn't take a click, and isn't hovered or held. We take the corners of the button's rectangle from ImGui, and the window's draw list, and its corners are cut seven points, or three tenths of a short button's height. Its fill goes from a top colour to a bottom one: red to wine for the primary button, and a dark red to a darker one for the rest. Under the mouse, the primary goes to an ember and crimson, and the rest to a lighter red. While it's pressed, the two colours swap, so the button looks pushed in. A disabled button is drawn at under half its alpha, and a primary button under the mouse gets three rings round it, a glow like a fire's. Each ring is the button's shape grown by another two and a half points, filled in ember at eight percent, and where they overlap near the button, they add up to a soft edge. Then the button's own shape is filled with the top colour, and shaded to the bottom one, like the panel. Over its top half goes a rectangle, inside the cut corners, from white at a tenth of the alpha at its top to clear at the middle, a sheen along its top half. Round it goes an edge, gold under the mouse, or else dark gold on a primary button and brass on the rest, a little thicker on a primary. The label is centred in the button, and a point lower while it's pressed, so the words move with the button. We draw it in gradient gold, faded with the button, from gold light to dark gold, or to a brighter gold under the mouse, and GameButton returns whether it was clicked.
27:45 Now each window the player opens is drawn as a panel. The change in each is small, as BeginPanel takes what ImGui's Begin took, and most of the widgets inside it stay as they were. In the quest window, which a quest giver opens, we bring in the theme. Its width goes through Ui now, at four hundred points, so it grows with the rest of the interface, and a height of zero lets ImGui fit it to what's in it. It begins as a panel, with the NPC's name as its title, and the close button closing it. NoCollapse goes, as BeginPanel turns collapsing off for each panel, and ImGui's saving of a window's place and size goes off, as the client keeps none of it in a file. Each quest's name goes in the title font, at seventeen points, which ImGui scales with the rest, as PushFont takes a size before the scale. Take the quest is a primary button now, as taking it is what the window's there for, and so is Turn it in. A little spacing takes the place of the separator between quests, as the panel has room enough between them, and the window ends with EndPanel. In the talk window, which the storyteller opens, the theme's header takes the place of the icons' header, as its button loses its book icon. It begins as a panel, under the storyteller's name, and still can't be resized. Tell me a story is a primary GameButton now, and a width of minus one makes it fill the width, as it's the one button there. In the trainer's window, we bring in the theme, and its width goes through Ui, at three hundred and sixty points. It begins as a panel, under the trainer's name. Where its buttons start, two hundred points in, goes through Ui as well, so the buttons still line up past the skills' names at any scale, and Learn is a small primary button, ninety points by twenty-eight. In the bag, we bring in the theme. The bag's close button still hides it, as I does, and its size still fits its six columns of slots. Like the others, it saves no settings, and at its bottom, EndPanel takes the place of ImGui's End. Next, we bring in the theme for the character screen, and its starting size, seven hundred and twenty points by four hundred, goes. The screen is a panel now, sized to what's in it, as the preview and the slots beside it set its size. In the map, we bring in the theme, and the land's map is a panel, which can't be moved, with the land's name as its title, and its close button setting the map's flag to closed, as M does. The title ends in an id after three hashes, so ImGui sees one map window whichever land it shows. And in the menu, we bring in the theme, and BeginPanel opens the Settings window too, still sized to what's in it, and like the others, it saves no settings. Its sections stay as they were, one under the other, until the next step gives them pages, and it ends with EndPanel.
30:37 Here's what the panels look like in the game. The bag opens as a panel, with its corners cut, a brass trim, gems at the top, and its title in gold over a divider. The character opens beside it, with its preview still on a grey of its own for now. The map is a panel too, with the land's name at the top. The menu bar is still ImGui's, which is next.
A menu on Escape
30:59 The menu bar along the top is a desktop program's, and the top of the screen is where the compass goes, so the bar goes. Most other games have a menu that Escape opens, and buttons for their windows, so that's what we're going to write. First, in the theme's header file, DrawSlot draws a slot: a dark well in brass, lit round its edge by a colour. The caller picks that colour, such as gold while the mouse is over it, and a clear one leaves the edge unlit. The buttons are slots, with brass round them, in a function of their own that other slots can share. In theme, a slot has a shadow under it, a little down and to the right, in black at half its alpha. Its fill goes from near black at its top to a dark red at its bottom, darker at the top, as a well's shadow falls. Then comes its brass, and two and a half points inside it, a thin line in night, which gives the well its depth. If the edge colour isn't clear, it goes round the outside, a little over two points wide. And a glow of it comes up from the bottom of the well, at under a quarter of its alpha, fading out towards the top. In the menu's header file, the window's header goes, as quitting comes back to main as a choice. Above the class, we write what it is: the game's menu, which Escape opens when nothing else is open, and its settings. The menu can say whether it's open, Toggle opens or closes it, and the settings can be opened and closed on their own, for Escape. Choice is what the player can pick in the menu. It's an enum class, which keeps its names inside it and doesn't turn them into numbers without a cast. Build returns what the player picked, to log out or quit, if either, and as before, the settings window edits the player's settings and the atmosphere. The menu doesn't log out or quit on its own: it says which, and the client's main loop does it, where the connection and the window live. BuildButtons takes the three windows' flags by pointer, so a click can open or close each window right there. It draws the row of buttons in the bottom right, for the windows the keys open, with the keys in their tooltips, and one for the menu. Under private, the settings have pages, BuildSettings draws them, and the menu keeps whether it's open, whether the settings are, and their page. In menu, we bring in cfloat, for the largest float, and utility, for pairs. The keys go in a constant array of pairs of strings. A player can look up a key without leaving the game, and the list lives next to the menu, where it's easy to keep up to date as keys come and go. It starts with walking and running, goes on to the camera, the map, your character and your bag, and ends with the chat, and Escape. Over it, we write that these are the keys, and what each does. BarButton is a button for the row in the bottom right, square, with an icon. It's an invisible button, thirty-eight points across, so ImGui handles its clicks and tells us when the mouse is over it. Its corners come from the item ImGui has just laid out, and we draw it from those. It's a slot, lit with an ember's edge while its window is open, so you can see what's open at a glance, and gold under the mouse. Its icon is measured to sit in the middle, and drawn with a shadow under it. It's light gold while the button's lit or under the mouse, and paper otherwise. Under the mouse, its tooltip names it and its key. Each frame, Build starts with nothing as the player's choice, and shows the menu while it's open, and the settings while they are. On ImGui's background draw list goes a rectangle over the whole screen, in black at under half its alpha. So the world dims behind the menu, as that list is drawn before any window. The menu sits a little above the middle of the screen, three hundred points wide, in a panel that can't be moved or resized, and its close button closes it. Its buttons fill its width, each forty points high. Back to the game closes the menu, and it's the primary one, as it's what you'll want most. Settings closes the menu and opens the settings in its place, so they don't stack up. Log out closes the menu and returns its choice, and Quit returns its own. Then BuildSettings draws the settings while they're open, and Build returns the choice. The settings are a panel seven hundred points by four hundred and seventy, in the middle of the screen when they open. Their place is set as they appear, and not after, so they can be dragged about, but they can't be resized. The pages are a constant array of pairs, a page and its name with an icon. The interface gets columns, the sound a speaker, the graphics a screen, the sky a cloud and a sun, and the keys a keyboard. The pages go down the left, and the one picked goes on the right. The list is a child window, which is a region of a window with its own scrolling, a hundred and seventy points wide. Each page is a selectable, ImGui's widget for a row that can be picked. The page picked goes in a child window beside the list, with its widgets two hundred and sixty points wide. Each page is a case of a switch, so adding a page later is a value in the enum, a name in the array and a case here. The interface page starts with a separator with its name. Under it goes the size, from before, as it was: the settings' scale while nothing's dragged, then the slider, from seventy-five to a hundred and fifty percent, and once it's let go of, the settings take its value. Then a faded line says what the size is: on top of the size for your screen, which grows with it. The sound page has the volume, the music and the effects, each a slider in percent, and the mute, as before. Under them, after a little space, the music's credit goes in faded text: Background Music, by Pavel Bekirov, from Pixabay. The graphics page has its three checkboxes, for bloom, for cel shading and for anti-aliasing, as the old window had them. The sky page edits the atmosphere the land's drawn in: the sky's colour, the fog's near and far distances in metres, the sun's direction, and the colours of the sunlight and the ambient light. After a little space, the presets go in a row, each beside the one before. They're game buttons now, and so is going back to the land's own sky. These change the atmosphere as you play, and they aren't kept between runs, as the land's own look is what the game is meant to look like. The keys' page is a table, whose rows' backgrounds take turns, which makes a long list easy to read across. In each row, the key goes in the first column, in the bold and in gold, and what it does goes in the next one, in the text face. Once the table's ended, we pop the item width, and end the page's child window and the panel. The ImGui demo window goes with the menu bar. BuildButtons takes pointers to the booleans its buttons toggle, for the character, the bag and the map, so the row needs to know nothing else about them. The row sits in the bottom right corner, eighteen points from each edge. The row's padding is ten points, with six points between items. It has no title bar, can't be moved, has no background, fits its size to the buttons, and doesn't take the focus when it appears. Behind the buttons goes one of our panels, from the window's corners, at nine tenths of its alpha. The first is the character's, with a person's icon, and C in its tooltip. Next come the bag's, with a bag on it, and the map's, with a folded map, each with its key in its tooltip. The last is the menu's, with three bars, which opens the menu, as Escape would, so a player who doesn't know the key finds it there.
38:21 Escape is going to close whatever's on top, so it needs to know what's open. In the storyteller's window's header file, open says whether it's open, which is whether it has an NPC, and Close lets go of the NPC. The trainer's window gets the pair too, for the trainer it's showing, and so does the quest window, whose NPC is the quest giver we clicked on. In the bag's header file, its button opens and closes the bag now, along with I, and visible says whether the bag's open. In the client's main, Escape used to close the map, or let go of the monster picked. Now it closes what's on top, then lets go of the monster picked, and then opens the menu. It goes down a list, from the settings to the menu and the map, and does the first thing it can. Next come the storyteller's, the trainer's and the quest giver's windows, which it closes all at once, as closing one that isn't open does nothing. Then the bag, and after it the character's screen. With none of them open, it lets go of the monster picked, as most other games do, and with nothing picked either, it opens the menu. While you type in the chat, it does none of this, as ImGui gives Escape to the field. The buttons in the bottom right toggle the character, the bag and the map, through their flags. And the menu's choice goes through a switch: logging out drops the connection, which takes us back to the characters, and quitting closes the window. In the player's frame, the frames used to sit under the menu bar, a frame's height down, so they move up into its room, and so does the target's. And in the quest window, the quests you're on go up into the top right corner.
39:56 Let's try it in the game, at this step. The menu bar's gone, and the buttons sit in the bottom right. With nothing open and nothing picked, Escape opens the menu, over the world, dimmed. Settings opens on the interface page, and the keys' page lists what each key does. Back on the interface page, the size goes to a hundred and twenty-five percent, and once the slider's let go of, the text, the panels and their spacing grow by a quarter. The hotbar and the minimap keep their sizes for now, until we draw them ourselves. Escape closes the settings, as they're on top of everything else.
A face and a target
40:32 Most other games put the player's face in the top left, beside their health, so that's where ours goes, drawn from the game's own character. In the theme's header file, DrawBar takes the rectangle a bar goes in, the share of it that's full, two colours, the bar's own and a darker one for its foot, and its words, which can be null. It draws a bar that's full by the share, in its colour, in a dark trough with brass round it and its words in the middle. In theme, the share is held between nothing and all of it, as a share past one would draw the bar out of its trough. The trough is night, at nine tenths of its strength. The share that's full goes from the colour at its top to the darker one at its bottom, as a gradient over its four corners. Over that goes a second gradient, white at a quarter of its strength at the top, fading to nothing a little before halfway down. That's the glow along the top of what's filled, which makes the bar look rounded, like glass. Then comes a bright edge where it ends, a line of light gold at least a pixel wide, so the end reads at a glance. A brass rectangle goes round the whole trough. When there are words, they go in the middle, in the bold, with a shadow, at fifteen points, or less on a thinner bar, so they fit inside it. In the player frame's header file, we bring in Offscreen, the texture the character window's preview draws into, and the renderer. The function that drew the frame becomes a class, PlayerFrame, as the frame keeps a texture now. The portrait is 192 pixels square, twice what it's shown at on most screens, so it's sharp on the rest. Render draws your head and shoulders into it, before the frame, as you look now, and Draw draws the frame. Draw doesn't return where the frame ends any more, as nothing goes beside it. It keeps an offscreen target for the portrait, which is a texture raylib can draw into, and whether it's drawn one yet. The target's frame doesn't go beside ours any more, so it doesn't take a left edge. In the player frame, we bring in raylib, for the portrait's camera, cfloat, string formatting and the theme. The sizes go first, in points at a scale of one, which the interface's scale multiplies when they're drawn: the frame's margin, eighteen points from the corner of the screen. The portrait's radius is forty, and the plate beside it is three hundred by sixty-six. Then how far down from the top of the screen the target's frame goes, seventy points, which leaves room above it for the compass, coming up next. The portrait is taken from a metre and a quarter in front of the face, a little to one side and above it, looking at the face with a field of view of thirty degrees. A narrow field of view distorts a face less, as a portrait's lens would. Each frame is a window without decorations, moving, a background, keyboard navigation or saved settings, and clicking it doesn't bring it in front of the others. Share turns a value and its most into a share between nothing and all of it, and zero when there's no most. That keeps a division by zero out of the bars, for a most that hasn't come from the server yet. A ring of brass goes round a disc, with a shadow under it, which both frames use. Under it all, the shadow is a black disc at a little under half its strength, two points right of the ring and three below, as if the light came from the top left. Then the brass, four and a half points thick, a thin dark edge outside it, and a faint light just inside it, which together read as a raised rim. BeginFrame sets up the plate beside a portrait, from its middle out to the right, with a window over it for the mouse. That window keeps a click on the frame from reaching the world behind it. Without it, a click on your own health bar would land on the ground behind and let go of the monster you'd picked. Render takes you from the renderer's figures, and while you're not among them, as before the world's arrived, it leaves the portrait as it was. It makes a copy of you standing still at the middle, facing the camera, idle, so a fight or a walk doesn't swing you out of the picture. Its idle runs from the time the client started, so you breathe and look round in the portrait, as you do in the world. Then the renderer's preview draws you into the portrait, which is what the character window has drawn with since episode seventeen, and the frame knows it has a portrait now. Draw waits for your level to come from the server, as before, and returns nothing now. The portrait's radius is scaled to the screen, and its centre is a margin and a radius in from the corner, and the plate goes from there out to the right, so the portrait sits over its left end. The plate is as far above the portrait's centre as below it, so their middles line up. The window covers the portrait and the plate, and the panel is drawn first, at a little under full alpha, so the world shows faintly through it. A circle of coal goes under the portrait, which is all there is until the first one's rendered. The portrait goes in on it, as an image with its corners rounded by its radius, which ImGui draws as a circle. It's upside down, as OpenGL keeps a texture's rows bottom up, so the image's coordinates flip it, running from one at the top to zero at the bottom. The ring goes round it, over the picture's edge. Your level goes on a gem at the portrait's foot, where most other games put it, as the level is the number you check most after your health. The gem is one of the theme's diamonds, wine red with a gold edge, set at the lower right of the ring. The level is written in its middle, in the bold. It's measured first, so that it sits centred on the gem, and drawn with a shadow, so that it reads over the portrait, in a light gold. The name and the bars start twelve points right of the portrait and stop sixteen short of the plate's end. Along the top of the plate, in gold Cinzel, light at the top of its letters and darker at their foot, goes your name. Your health and its most are put into words first, for the middle of the bar. Its rectangle starts thirty points below the plate's top, at the bars' left edge, and runs to their right edge, sixteen points high. The bar is red, and full by your share of your health, as that's the number you watch during a fight. Under it, a thin gold bar, seven points high, shows how far you are into your level, from the experience the world message brings. It's too thin for words, so the cursor moves to its corner and an invisible button goes over it, the bar's size. That's an ImGui item that draws nothing, but it still knows when the mouse is over it. While it is, a tooltip under the mouse shows your experience and what the next level needs, as numbers. The old frame's lines go: its name in plain text, its level beside it, and two bars of ImGui's own. The target's frame finds the monster you picked, while there's one with a name, as before, and its old text and bar go too. It goes in the middle of the screen, seventy points down, with room above it along the top. The middle is where your eyes are during a fight, so the monster's health is a glance away from it, where a frame in a corner would be a look away. Its plate is two hundred and fifty points wide and twelve points less tall than ours, and the ring and the plate together are centred. BeginFrame covers them, a few points bigger to take in the ring's rim, so a click on it doesn't reach the world. The panel goes down first, then a disc of wine red in a ring, a little smaller than ours, as a monster matters less than you do. On it goes a skull, in the icons' font, as monsters have no portrait to show. The skull is twenty-two points high, measured so that it sits in the middle of the disc, and it has a shadow like our other words. The name and the level go between the ring, ten points clear of it, and sixteen points short of the plate's right end. That keeps the words off the ring's brass and out of the plate's cut corner. The monster's name goes in a pale red, a little lighter than the monsters' nameplates, fading into ember at its foot. Its level is written as the word Level and its number, in the bold, smaller than the name. It's measured first, so that it ends at that right edge, and it's in muted letters, as it matters less in a fight than the health under it. Its health is a red bar under them, fourteen points high, a little thinner than ours, with its health and its most in the middle, as numbers, like ours. In the renderer, a preview used to clear to a colour of its own, a dark blue grey. Now it clears to nothing, an alpha of zero, so the portrait shows our coal round your head. The colour behind it is a dark red, for the edges of the figure, which blend with it. In the client's main, the frame is a player frame now, which renders the portrait before the frame, with the character window's preview. It draws where the old frame did, with the target's frame after it. Rendering the portrait each frame costs a draw of one figure into a small texture, which is little next to drawing the world. In return, the face in the frame is the one in the world, in what you wear, and it changes when that does.
49:19 Here's how the frames look in the game at this step. Our face is in the top left, idle, as the renderer draws it each frame, in a ring with our level, beside the health and the experience. A skeleton we pick gets its frame at the top in the middle, and its health goes down as we fight it, with ours, as the server sends both.
A compass
49:40 A compass along the top, as most other games have now, shows which way you're looking, and which way the things you're after are, without opening the map. It gets a header file of its own, compass, with ImGui, and raylib, for the camera and positions in the world. Then optional and vector from the standard library, and the animator, for the figures. Heading is which way the camera looks, as a compass has it: in radians, clockwise from north. North is up the map, along minus z, as the map draws the land, so east, along plus x, is a quarter turn. Bearing is which way a place is from another, also clockwise from north. CompassAt says where a bearing goes across the compass while the camera looks along the heading. That's from minus one at the left end to one at the right, with the heading in the middle, or nothing, when it's further round than half the compass's span. A compass mark is something the compass shows the way to: its kind, its bearing, how far it is in metres, and its colour. The kinds are the monster you picked, a quest to take, a quest to turn in, a gate, and where you're walking to. Each draws in a look of its own, and the monster and the quests behave differently when they're behind you. CompassMarks makes them from the figures, the land, the monster we picked, and our destination. They're the monster you picked, the NPCs with a quest for you, the land's gates, each in the sky of the land it goes to, and where you're walking to. DrawCompass draws the compass along the top of the screen, the half of the world in front of the camera, with its points and its marks. The monster you picked and the quests stay at its ends while they're behind you, so that you know which way to turn. Then the header closes its namespace and its include guard. In compass, we bring in algorithm and array from the standard library, cfloat, for the largest float, cmath, for the trigonometry, and numbers, for pi. Then our own atmosphere, for each land's sky, the theme, for our colours and fonts, Font Awesome's icons, and the lands, for their gates. We keep pi as a float constant, from numbers. The compass spans pi, half the world, a quarter turn to each side of the way the camera looks, about twice what the camera sees. It's 620 points wide, at a scale of one, 36 high, and 14 from the top of the screen. Nearer the middle than twelve hundredths of each half, about eleven degrees, a mark says how far it is. The compass's eight points are an array of their letters, from north round to north west, one for each eighth of a turn. Things fade out towards the compass's ends, from three quarters of the way, so it has no hard edges. The fade is clamped between zero and one. DrawEdge takes the two ends and a height, and draws a line along the compass's edge, which fades out at its ends. It's a point thick at the interface's scale, and at least a pixel, in our brass. ImGui can fill a rectangle from a colour at each corner. So the left half goes from clear brass to solid in the middle, and the right half back to clear. Faded, from our theme, with a share of zero, makes the brass clear. DrawCentred writes a line of text centred on a point, as our letters and icons are. ImGui's calc text size measures it, and we write it with its shadow, half its width to the left and half its height up. A gate's mark is in the sky of the land it goes to. SkyOf reads that sky from the land's look, three floats from zero to one. A lambda turns each into a byte, clamped first, and the three bytes make an opaque ImGui colour. DrawMark draws a mark at a point, faded by an alpha, and switches on its kind. The monster you picked is a skull, sixteen points high, in our text face, which has Font Awesome's icons merged in. A quest to take, or one to turn in, is in Cinzel, our title face, at twenty-two points, as an exclamation mark or a question mark, like over the NPC. A gate is two rings, thirteen points across: a thicker black one first, which outlines it like the shadow under our text, then a thinner one in its sky's colour. And where you're walking to, the destination, is in the text face again, fifteen points high, as a location pin from the icons. A bearing is the arc tangent of how far east the place is over how far north, which atan2 works out the right way round in each of the four quarters. The heading is the bearing from the camera to what it's looking at, the player's chest. CompassAt takes the bearing less the heading, and remainder brings it to between minus and plus half a turn, going round from the heading the shorter way. Past half the span, it's off the compass, and nothing comes back, which the optional says without a magic number. Inside it, it's a share of the half, so the drawing can multiply it by half the compass's width. CompassMarks takes the figures, the land, the target and the destination. It finds you first, with ranges find if, which takes a pointer to the member you as its test. Without you, there's nothing to measure from, so the list is empty. A lambda, which captures by reference, adds a mark of a kind for a place to the list, with its bearing from you, and its distance across the ground, as height doesn't matter on a compass. The land's gates go on first, with a gate mark for each gate in this land, at its place on the map, in the sky of the land it goes to. Then the NPCs, by the mark over their names. One with an exclamation mark has a quest for you to take, and one with a question mark has one you've done, to turn in, both in gold. Then where you're walking to goes on, if you're walking somewhere, in light gold, a little paler than the quests. And last, so that it's drawn over the rest, the monster you picked goes on. It's the monster whose id is our target, as long as that isn't zero, which means none, and it mustn't be dead. It goes on in ember, and then the list of marks goes back to the caller. DrawCompass takes the heading and the marks, and draws on ImGui's background list, under the windows, so that one dragged over it covers it. It needs no window of its own, as it takes no clicks. It gets our fonts and the screen's size. It's no wider than six tenths of the screen, so a narrow window keeps room for the frames. It's centred across the screen, and its middle and half its width are what each place on it is measured from. A fifth of the width at each end is where it fades. It's a dark band, which fades out at its ends: night, at seven tenths of its alpha, so the sky shows through a little. Clear is that night at an alpha of zero. The ends blend in from clear to the band, and the middle is solid, which makes it read as a game's compass, not a box. Then DrawEdge puts the brass lines along its top and bottom. A loop goes round in steps of five degrees: the ticks go each five degrees, longer each fifteen, and the points each forty-five. CompassAt places each in radians, skipping those behind you. Its x is the middle plus its share of the half width. At each forty-five degrees goes a point, and the four cardinal ones, at each ninety, are in light gold, with north in ember and the ones between muted. They're in Cinzel, centred on the band's middle line, twenty-two points high for the cardinal ones and fourteen for the others, with their letters from the array of points. The ticks in between are five points high in our faint colour, or nine in dark gold at each fifteen degrees, which gives the eye a scale to read a bearing against. For the marks, we find the one nearest the middle first, if it's near, as two marks near the middle would write their distances over each other. A first loop finds where each mark is, in an if with an initialiser, so that where it is stays local to that if. It keeps the one with the smallest share from the middle, below the twelve hundredths it starts from. Then a second loop draws them in the order CompassMarks put them in, so the monster you picked, which came last, is on top. The monster you picked stays on the compass when it's behind you, and so do the quests to take and to turn in, as those are what you'd turn round for. A gate or a destination behind you is left off. Its side is where it is across the compass, or, for one behind you, minus one or one, by which way round is shorter. Behind you, it waits at the end it's nearer. Its x is the middle plus its side times half the width, ten points in for one that waits, at eight tenths of its alpha. A mark faded to nothing is skipped, and DrawMark draws the others on the band's middle line. For a mark behind you, we start with a tip, two points out past the band's end. An arrow out past the end shows the way to turn. Its back is seven points in, and it's ten points high, a triangle in the mark's colour. Otherwise, the one nearest the middle says how far it is, rounded to whole metres, under the band, in the bold. That answers the question you'd turn the camera to ask: how far is it to the thing I'm facing. After the marks, a faint gold line goes through the middle, at about a third of its alpha. A thin line down the middle and a notch at the top show where the camera looks, the heading each bearing is measured from. The notch is a gold triangle, fourteen points wide, which points down into the band from just above its top edge. In the client's CMake file, compass goes into the core library, and its test into the tests. In the client's main, we bring in the compass's header, and the compass draws after the nameplates and before the frames, so it's over the world and under the windows. It draws with the camera's heading, and the marks for the land we're in, the monster we picked, and where we're walking to, if we are. The marks are made afresh each frame, from the figures the animator gives us, so a monster on the move slides along the compass as it goes. In the player frame's header file, the target's frame is under the compass now, and in the player frame, it sits under the distance the compass shows as well.
59:37 Next, a quick test of the compass's maths, in compass test. A sign that goes the wrong way, or an angle off by a quarter turn, is easy to write and hard to see, as the compass would still slide and look like a compass. First, which way round they go: from the origin, the bearing of a place five metres up the map is zero, as north is up the map, along minus z, and east is along plus x. So a place along plus x is a quarter turn, one along plus z is half a turn, either way round, and one along minus x is minus a quarter. Then a camera, five metres up and ten back along plus z, with its target a metre off the ground at the origin. Raylib also wants its up vector, field of view and projection. From behind the player, south of them, it looks north, so its heading is zero, whatever its height, as height doesn't come into a bearing. Next, a heading of a quarter turn, which is east, and a span of half a turn, where east comes out at zero. Looking east, east is in the middle, north at the left end, at minus one, and south at the right, at one. Those two are the compass's ends, as its span reaches a quarter turn each side. And west comes back without a value, as west is behind, so off it. Then the shorter way round, from a heading a tenth short of two pi, to a bearing of a tenth, in radians. Looking a little west of north, a little east of north is just to the right, not most of a turn away. We assert that it's on the compass, at two tenths over a quarter turn, which is what remainder is for. And last, the marks, which we make from four figures. You're at the origin, the monster you picked is three metres east and four south, and another monster nobody picked is nine metres east and nine south. A quest giver stands eight metres due north, with an exclamation mark over it. We make the marks in land one, with seven, the picked monster's id, as the target, and nowhere to walk to. Then we count the targets and the quests among them. The target is at its five metres, three and four making five, and the quest, due north, is at a bearing of zero. There's one of each: the one picked, and not the other monster, which is the point of picking one, as it says which of them you're after.
1:01:53 Let's see the compass in the game, at this step. North's in the middle, as the camera starts behind us, looking north, with the gate to the Ashlands ahead and the healer's quest mark on it. The skeleton we pick goes on it as a skull, which stays on the compass wherever the skeleton is. As the camera turns, the points slide along, and the skull, once it's behind us, waits at the end it's nearer, with an arrow out past it.
A round minimap
1:02:19 The minimap is a square in the bottom right, and most other games have a round one in the top right, under the land's name, which is where ours goes. In the map's header file, we bring in array, for a list of zooms. A minimap turn says how the view's turned: north up, or with what's ahead of the camera up, as the player chooses. Some players read a map better one way and some the other, so it's theirs to pick. The minimap had one size, forty-five metres from you to its edge, and now it has three zooms, twenty-five, forty-five and eighty, close for a fight and far for finding your way. Drawing the minimap returns a bool now, and takes the camera's heading and the turn. Above it, we add that scrolling over it, or its buttons, zoom in and out, and that it returns true when its map button's clicked, for main to open the map. It says how far down the screen it reaches, for the quests under it, and keeps its zoom, with a setter that holds it to the zooms there are. The zoom starts at the middle one, forty-five metres, the size it had before. In map, we bring in cfloat, for the largest float, which ImGui's text measuring takes as a width without a limit, then numbers, Abseil's string joining, for the land's name, and the icons. From numbers, we take pi, as a float. The minimap's radius is a hundred points, inside a ring seven wide, eighteen points from the screen's corner. At three quarters of the size, on a small screen, that's a disc a hundred and fifty pixels across, which still shows the camps round you. Other players are a light blue now, as our arrow's gold, and the monsters and NPCs keep their red and gold. A view of the land gets a turn: the bearing that's up on the screen, zero for north. Way turns a way on the ground into a way on the screen, by the view's turn, without its scale. It's a rotation, with the cosine and sine of the turn, and it's what turns the way you're facing into your arrow. Then the view's call operator takes where a place is from the centre, at the scale, turns it with Way, and adds the origin, which is where the centre is on the screen. Dots and their outlines are sizes at the scale now, so they grow with the minimap. A glyph, such as a quest's mark, is drawn in Cinzel, centred on its point, with an outline from four offsets and a shadow, so it reads on grass, sand or sea. It's measured at its size, and its corner is half of that back from the point. The outline and the shadow are the glyph in dark, a pixel to each side and once down and to the right, and then the glyph goes on top, in its colour. OnDisc places a mark on a round map. Without a radius, as on the big map, a mark is where it is. Otherwise, we take its offset from the view's origin, and the distance, with hypot. Inside the radius, it's where it is too. Past the radius, a mark that isn't kept gets nullopt, and goes nowhere, and one that's kept goes on the rim, out from the origin at the radius, the way it is from the centre. So a mark on a round map of the radius round the origin is where it is, or, if it's past the rim and kept, on the rim, the way it is, or none. On a round map, the markers leave out what's past its rim, but for the monster you picked and the quests, which wait on the rim. So they take a radius, zero by default, for the big map, which has no rim. On the minimap, marks stop a little inside the rim, so they stay off the ring and stay whole. The gates go through OnDisc and aren't kept, so a gate past the rim is left out, and the compass shows the way to it instead. A gate is a ring in the colour of the land it goes to, with a dark ring under it, so it reads on the grass. An NPC with a quest is kept on the rim, and one that OnDisc leaves out is skipped. The quest's mark is drawn with DrawGlyph, in gold Cinzel, and an NPC without one is a gold dot. The monster you picked is kept too, so you can tell which way to go, as on the compass, and the others past the rim are skipped. A dead monster's dot goes, but its ring stays while it's picked. The ring is ember now, over a thicker dark one, so it shows on any ground, with a radius of five and a half points. Other players are light blue dots, and they aren't kept, and nor is where you're walking to. The cross for where you're walking to has arms of four points at the scale, where they were four pixels, and it's light gold, where it was white like the players. As at is an optional now, its x and y are reached through it, with an arrow. Each stroke goes from corner to corner, drawn three and a half points thick in the outline's dark, and then one and a half in its colour over it. Your arrow is drawn last, over everything, at your place on the map. Ahead is the way you face, put through the view's Way, so it turns with the view. Side is that way turned a quarter, by swapping its two parts and flipping one. A point of the arrow is so far along ahead and so far across it, along side, for x and for y, at the scale. The tip is nine points out in front, and the back corners six points back and six across, where they were eight and five pixels. A notch goes in its back, between them, two and a half points back from the middle. The arrow is two triangles either side of its middle, one in gold and one in dark gold, so it reads as lit from its left. And a dark outline goes round all four points, as a closed path, a point and a half wide. DrawDisc draws the map as a disc, for a view and a radius. ImGui can draw an image with its corners rounded into a circle, but the picture stays upright, and ours has to turn, so we draw the disc's triangles ourselves. The map's size is twice its half, and the view's centre, from the map's corner, over that size, is its texture coordinate, and then we push the map's texture. We reserve room in the draw list for a fan of seventy-two triangles, all from the centre, which is where you are on the map. That's seventy-three vertices, the centre and seventy-two on the rim, and three indices for each triangle. Each point on the rim is a way on the screen, at its angle round the circle. The way on the ground it shows is the view's turn the other way round. The vertex goes on the screen at the radius that way, and its texture coordinate is the place on the map that way, the zoom's distance from you. The map's texture is a pixel a metre, so a metre is one over the map's size in texture coordinates. Each triangle is the centre and two points on the rim, next to each other, the last one wrapping back to the first, and then the texture's popped. Above DrawDisc, we write what it draws: the texture, as a disc of the radius round a centre on the screen. It shows the land round a place, with the zoom's distance from it to the rim, turned as the view is. Seventy-two segments is enough for the rim to look smooth at a hundred points, and seventy-three vertices cost nothing next to the world. A ring button sits on the minimap's ring: it's round, with an icon. Its radius is eleven points, at the scale. ImGui's cursor goes to the corner of the square round it, where an invisible button takes the click, and tells us when the mouse is over it. We draw it in the window's draw list: a dark outline a point and a half wider, then a circle, wine, crimson under the mouse, with a brass edge, gold under the mouse. Its icon is from Font Awesome, merged into the text face, at twelve points, measured so it's centred, in paper, or light gold under the mouse. Setting the zoom clamps it between the first zoom and the last, so the buttons and the wheel can't take it past either end. Drawing the minimap needs the land's texture and you, and without them it's left out, and so is its bottom. Main draws it once we're in the world, after the land's built, so the check is a guard, say for a frame whose figures come without our own. The radius and the ring are points at the scale, and so is the banner, the name's plate, twenty-six points high. The window's size is the ring's width across, and the plate, the ring and the coordinates down. It's pinned to the top right by its own top right corner, eighteen points in, without padding. It makes a window without a background, which takes the mouse for its buttons. Its place isn't saved in ImGui's settings, as we set it each frame. And clicking it doesn't bring it in front of the other windows, so a window dragged over it stays on top. The disc's centre is under the name's plate. The window's bottom is kept, for the quests, which go under it, wherever the scale puts it. The land round you goes in a disc, with a shade inside its rim, at the zoom's metres from you to the rim. The view is centred on you, at a radius for the zoom, and its turn is the camera's heading when it turns with the camera, and zero for north up. The disc goes on a filled circle of night, with four rings of shade inside its rim, three points wide, darker towards it, so it looks sunk into the ring. Then the markers go on, given the minimap's radius, so they stay inside the rim. The ring is a thick circle in brass, drawn as a circle's outline at the ring's middle, as wide as the ring. It has an arc of light along its top left, as the land on the map is lit from there, and a thin dark line along each of its edges, inside and out. A notch goes on the ring at each quarter turn from north, turned with the view, so the notches go round as the camera does. Each one's bearing is its quarter turns, less the view's turn. At north, in place of a notch, goes a gem, a wine diamond with a gold edge, in the middle of the ring, ten points from its middle to its corners. On it goes its letter N, in the title face at thirteen points, centred, in light gold, which is how you tell which way north is while the minimap turns. The other quarters get a notch, a dark line two points wide across the ring, from its inside edge to its outside edge. The land's name goes on a small panel over the ring, in gold Cinzel. It's the land's name after The, such as the Meadows, and its size is fourteen points. The plate is as wide as the name needs, with sixteen points each side, and as tall as the banner. Its shape and trim are a panel's, drawn with DrawPanel, so the plate matches the windows. The name goes from light gold at its top to dark gold at its bottom, like the windows' titles. The place is your x and z, each rounded to a whole metre, and joined with a comma. Where you are, in metres east and south of the land's middle, goes under the ring, which is handy for telling someone where to meet. It's in the bold face, at thirteen points, measured so it's centred, and drawn with a shadow, four points under the ring, in the muted colour. A small lambda gives a place just outside the ring, at an angle in degrees, clockwise from its right. It turns the degrees to radians, and goes out by the cosine across and the sine down. Plus goes on the ring's lower left and zooms in, to the zoom before, and minus goes next to it and zooms out, to the one after, each held to the zooms there are. The map's button goes on its lower right, with a tooltip that names its key, M. Then ImGui's cursor goes to the top left of the square round the disc. And an invisible button over the disc catches the mouse wheel: up zooms in, and down zooms out. Each of these buttons, and the disc, are ImGui items in the minimap's window. So ImGui knows the mouse is over the interface there, and a click on the minimap doesn't pick a monster or walk you into the world behind it. That's the reason the minimap is a window at all, when the compass, which takes no clicks, isn't. The big map opens on M, or on the minimap's button, as a panel in the middle of the screen. It's a touch smaller than before, seventy-two hundredths of the screen's shorter side across. Its picture gets a brass edge, and its markers draw without a rim, as the whole land fits on it, so nothing's ever past its edge. A click on it still walks you to where you clicked, as before.
1:14:13 In the quest window's header file, drawing the tracker takes a top, where it starts, so it can go under the round map. The quests the player's on go on the right, from the top down, under the minimap, with how many they've killed for each. In the quest window, we bring in cfloat and string joining. The colour for a quest that's done goes, as the theme has a green, and the tracker's window goes too. Now it draws on ImGui's background draw list, under all the windows. The tracker is now words with shadows, without a window, lined up on the right, so they read on any ground and hide as little of it as they can. Its right edge is twenty-four points in, and it starts ten points under the top. A lambda draws a line of it, measured in its font and size, so it can end at the right edge, with a shadow, and moves down by its height and two points more. The tracker's title is Quests, in gold Cinzel, then each quest's name, in the bold, in a light gold. Under it goes how many you've killed of how many: in green, with a tick and done, once that's all of them, until it's turned in, and in paper until then. And a gap of six points goes under each quest. Whether the minimap turns goes into the settings, so the settings' proto file gets minimap turns, field two of the interface. In the settings' header file, it's a bool, false by default, so the minimap starts north up, like the map. In settings, loading reads it when the file has it, as older settings files don't, and saving writes it, after the scale. In the settings' test, the settings kept between runs turn it on. In the menu, the interface page gets a checkbox, turn the minimap with the camera. In the client's main, the minimap draws with the camera's heading, and turns with it if the settings say so, or keeps north up. When its map button's clicked, it toggles the map, as M does. And the tracker moves after it, to go under it.
1:16:07 Let's see the minimap in the game, at this step. It's in the top right, under the Meadows' name, with the quests under it. Minus takes it out to eighty metres round us, and plus brings it in to twenty-five. Its map button opens the land's map, which Escape closes. On the settings' interface page, the minimap can turn with the camera, and as the camera turns, the land turns under our arrow, with north's gem going round the ring.
Wrap-up
1:16:35 So, today, the interface got the game's colours and two fonts, at a scale that follows the screen's height and a size the player sets. Each window became a panel of our own, drawn under ImGui's widgets, and Escape took the menu bar's place, closing what's open and then opening the menu, with the settings in pages. Our frame got our face, drawn each frame by the renderer, and the target moved to the top, under a compass that shows the monster we picked, the quests and the gates. And the minimap went round, with three zooms, and can turn with the camera. All of it is ImGui underneath, which still does the input, the layout and the text.
Playing it
1:18:05 Let me know in the comments what you'd like to see next, and if you want to follow along with the series, subscribe to the channel. I hope you find this useful, and thanks for watching.