# In-world hologram UI - In world inventory (Frontend) (Part 4)

> Learn how to create in-world hologram UI elements with Gameface in Unreal Engine.

> Documentation index: https://coherent-labs.com/llms.txt lists every page of this documentation as Markdown; the full text is in https://coherent-labs.com/llms-full.txt.

Source: https://coherent-labs.com/blog/uitutorials/hologram-ui/hologram-ui-part-4/

## In-world hologram UI - In world inventory (Frontend) (Part 4)

ui tutorials

1/9/2025

Kaloyan Geshev

1. Showcase Overview
2. Getting started - UI layout overview
3. Setting the wrappers
4. Creating the holographic background for menus
5. Weapon preview and stats menu
   1. Weapon preview
   2. Progress bar initialization
   3. Weapon stats
6. Inventory menu
7. Currencies menu
8. Showing menu controls hints
9. Setting up the data model
10. Active item selection
11. Focusing the items
12. Updating the progress bar value
13. Inventory items navigation
14. Enabling entry animations for the menus when the player opens the inventory
15. Closing the menu
16. Animations for the menu
17. Full source code

In the final tutorial of this series, we will design the UI for the inventory menu, allowing the player to interact with the items.

You can find the rest Hologram UI series here.

## Showcase Overview

This part will focus on creating the UI for the inventory.

We will achieve this by:

1. Using Gameface [data binding ](https://docs.coherent-labs.com/cpp-gameface/integration/ui_scripting/htmldatabinding/)to generate and render the inventory items.
2. Applying `CSS` transforms to create the screens from the image.
3. Utilizing the [progress bar ](https://coherentlabs.github.io/GameUIComponents/en/components/progress-bar/)Gameface component to display weapon stats.
4. Utilizing the [interaction manager ](https://coherentlabs.github.io/GameUIComponents/en/interaction-manager/introduction/)to allow the player to navigate through the items list using the keyboard.

## Getting started - UI layout overview

To create the inventory UI, we will divide the screens into three parts:

We will create a main wrapper element for all UI parts using display flex in a row direction. Inside this wrapper, we will have two elements that together occupy 100% of the wrapper’s width.

The first element will display the weapon stats and preview screen.

The second element will use display flex in a column direction and contain two children:

1. The first child will display the inventory items.

2) The second child will display the currencies.

## Setting the wrappers

The `HTML` representation of the above layout is as follows:

```html
<div class='menu'>
   <div class="menu-left">
      <div class="submenu-top"></div>
   </div>
   <div class="menu-right">
      <div class="submenu-top"></div>
      <div class="submenu-bottom"></div>
   </div>
</div>
```

The main wrapper element is `menu`. Inside it, we have `menu-left` and `menu-right` to split the screen into two parts as described. Inside them, we add `submenu-top` and `submenu-bottom` elements. Since the left menu only shows weapon stats, we omit `submenu-bottom`. The right menu’s `submenu-top` shows the inventory, and `submenu-bottom` shows the currencies.

The wrappers will have the following styles:

```css
.menu {
    background-color: rgb(0, 0, 0, 0);
    color: white;
    width: 100vw;
    height: 100vh;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
    opacity: 1;
}

.menu-left,
.menu-right {
    height: 100%;
    padding: 1rem;
}

.menu-left {
    margin-left: 1rem;
    flex: 1 1 30%;
    transform: rotateY(20deg) skewY(-3deg) translateY(-1rem);
    transform-origin: center left;
}

.menu-right {
    transform: translateX(-5rem);
    flex: 1 1 70%;
    perspective: 1000px;
}

.submenu-top {
    transform: scale(0.9) rotateY(-4deg);
    transform-origin: top right;
    height: 70%;
    position: relative;
}

.submenu-bottom {
    width: 97.5%;
    transform: scale(0.9) rotateY(-4deg) rotateX(10deg) skewY(0deg) skewX(-10deg) translateX(5%) translateY(-5%);
    transform-origin: center;
    height: 25%;
    position: relative;
}
```

As you can see, we also set the transformations for each screen. To achieve a 3D effect, we use the `perspective` CSS property on the `menu` wrapper. For the other elements, we use different transform properties to achieve the effect shown in the video or images.

To simplify the process, we used our [Inspector ](https://docs.coherent-labs.com/cpp-gameface/integration/optional_features/devtools/devtools_cpp/)to transform the wrappers, allowing temporary updates to the UI that are immediately visible in our standalone application called the `Player`. Once satisfied with the result, you can copy the CSS from the `Styles` tab and paste it into your CSS file.

**Note: Since the Gameface view in the game created in the [previous](https://coherent-labs.com/blog/uitutorials/hologram-ui/hologram-ui-part-3/#adding-in-world-view-inside-the-third-person-character-blueprint) tutorial also has transformations, it is advisable to check the final result directly in the game. You can open the inspector while the game is running and use the same approach to temporarily edit the elements as with the standalone application.**

## Creating the holographic background for menus

To achieve the holographic effect for the menu background, follow these steps:

- First, create a border as a PNG image for the element. Then, use the `border-image` CSS property to apply a nine-slice scaling technique, ensuring the border’s edges maintain their ratio when the wrapper element is scaled. We will use the following image:
- Next, add the noise animation created earlier in the series. To ensure it stays within the border image boundaries and acts as a background, use the `border-radius` CSS property.
- Finally, translate and scale the wrapper slightly to create an offset behind the menu wrapper, producing a depth effect.

For each submenu, add this element that is positioned absolutely to the menu. Here is an example in our HTML page:

```html
<div class='menu'>
   <div class="menu-left">
      <div class="submenu-top">
         <div class="border-bg border-bg-weapon-preview">
            <div class="overlay-lines border-radius-lines"></div>
         </div>
      </div>
   </div>
   <div class="menu-right">
      <div class="submenu-top">
         <div class="border-bg border-bg-inventory">
            <div class="overlay-lines border-radius-lines"></div>
         </div>
      </div>
      <div class="submenu-bottom">
         <div class="border-bg border-bg-currencies">
            <div class="overlay-lines border-radius-lines"></div>
         </div>
      </div>
   </div>
</div>
```

Each background is tagged with a specific class to apply different transition animations. For example, the weapon preview background is tagged with the `border-bg-weapon-preview` class.

The styles are defined as follows:

```css
.overlay,
.overlay-lines,
.overlay-radial {
    pointer-events: none;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
}

.overlay-lines {
    background-image: linear-gradient(rgba(0, 200, 228, 0.1) 0%, rgba(0, 200, 228, 0.1) 30%, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0) 100%);
    background-size: 100% 0.5rem;
    animation: overlay-anim 3s forwards linear infinite;
}

@keyframes overlay-anim {
    from {
        background-position: 0% 0%;
    }

    to {
        background-position: 0% -10%;
    }
}

.border-radius-lines {
    border-radius: 4rem;
}

.border-bg {
    position: absolute;
    width: 108%;
    height: 106%;
    border-image-source: url(./assets/border.png);
    border-image-slice: 60;
    border-image-width: 3.5rem;
    border-image-outset: 0;
    border-image-repeat: stretch;
    z-index: -1;
    transform: translateX(-2rem) scale(1);
    top: 1rem;
}
```

This will result in a similar effect:

## Weapon preview and stats menu

To create the weapon preview menu, we will design a separate submenu wrapper element that displays its children in a column layout.

Next, we will create two reusable elements within the submenu wrapper: one for the menu item title and one for the menu item container. This will help us define the layout based on images and videos.

### Weapon preview

We will use the following structure in our HTML file:

```html
<div class='menu'>
        <div class="menu-left">
            <div class="submenu-top">
                <div class="border-bg border-bg-weapon-preview">
                    <div class="overlay-lines border-radius-lines"></div>
                </div>
                <div class="submenu-wrapper weapon-preview-wrapper">
                    <div class="menu-item-title">Weapon preview</div>
                    <div class="menu-selected-item-preview">
                        <div
                            class="selected-item-image"
                            data-bind-style-background-image-url="{{activeState.selectedItem.image}}"
                        ></div>
                    </div>
```

We use the `menu-item-title` to display the text “Weapon preview” and the `menu-selected-item-preview` to show a preview image of the currently selected weapon. The `data-bind-style-background-image-url` attribute ensures that the image updates when the selected weapon changes. We will later set up all data models using mock models.

To match the submenu with the previously created background, we will set a border radius and overflow to hidden on the `submenu-wrapper`:

```css
.submenu-wrapper {
    border-radius: 4rem;
    overflow: hidden;
    height: 100%;
}
```

### Progress bar initialization

To use the progress bar in our UI, run `npm i coherent-gameface-progress-bar` inside the `Content/uiresources/HologramUI/` folder and then import its styles and JavaScript into the page.

```html
<head>
    <link rel="stylesheet" href="node_modules/coherent-gameface-progress-bar/coherent-gameface-components-theme.css">
    <link rel="stylesheet" href="node_modules/coherent-gameface-progress-bar/style.css">
    ...
</head>
<body>
   ...
   <script src="./node_modules/coherent-gameface-progress-bar/dist/progress-bar.production.min.js"></script>
</body>
```

### Weapon stats

For the weapon stats, we will add a `menu-item-title` with the text “Stats” and use the `menu-item-container` to display all the stats. Each stat will be wrapped in a` menu-item-stat` element, with `menu-item-stat-label` displaying the stat name and `menu-item-stat-value` showing the stat value using the gameface progress bar or simple text via the `data-bind-value` attribute.

Here is a snippet demonstrating how different stats are structured in the HTML page:

```html
<div class="submenu-wrapper weapon-preview-wrapper">
   ...
   <div class="menu-item-title">Stats</div>
   <div class="menu-item-container">
      <div class="menu-item-stats-wrapper">
            <div class="menu-item-stat">
               <div class="menu-item-stat-label">Name</div>
               <div
                  class="menu-item-stat-value"
                  data-bind-value="{{activeState.selectedItem.name}}"
               ></div>
            </div>
            ...
            <div class="menu-item-stat">
               <div class="menu-item-stat-label">Firepower</div>
               <div class="menu-item-stat-value">
                  <gameface-progress-bar
                        animation-duration="500"
                        data-bind-progress="{{activeState.selectedItem.firepower}}"
                  ></gameface-progress-bar>
                  <span
                        class="stat-text-value"
                        data-bind-value="{{activeState.selectedItem.firepower}}+'%'"
                  ></span>
               </div>
            </div>
            ...
      </div>
   </div>
</div>
```

We apply values from the active item in our model via data binding attributes, which we will set up later. To dynamically change the progress bar value, we will use the `data-bind-progress` custom attribute, which we will define later as well.

## Inventory menu

To build the inventory, we will reuse some elements from the weapon stats. We’ll create a new `submenu-top` inside the `menu-right` wrapper, adding the `border-bg` and `submenu-wrapper` elements.

For displaying all items, we’ll use a grid-like layout. Each item from our data model will be rendered using the `data-bind-for` attribute.

```html
<div class="menu-right">
   <div class="submenu-top">
         <div class="border-bg border-bg-inventory">
            <div class="overlay-lines border-radius-lines"></div>
         </div>
         <div class="submenu-wrapper inventory-wrapper">
            <div class="menu-item-title">Inventory (6)</div>
            <div class="menu-item-container">
               <div
                     class="player-item-wrapper"
                     data-bind-for="item:{{player.items}}"
               >
                     <div
                        class="player-item"
                        data-bind-mouseover="onItemFocused(event,this,{{item}})"
                        data-bind-focus="onItemFocused(event,this,{{item}})"
                     >
                        <div
                           data-bind-class-toggle="player-item-selected:{{item}}==={{activeState.selectedItem}}"
                           class="player-item-background"
                        ></div>
                        <div
                           data-bind-if="{{item}}==={{activeState.selectedItem}}"
                           class="overlay"
                        >
                           <div class="overlay-lines"></div>
                           <div class="overlay-radial"></div>
                        </div>
                        <div
                           class="player-item-image"
                           data-bind-style-background-image-url="{{item.image}}"
                        ></div>
                     </div>
               </div>
            </div>
         </div>
   </div>
```

Each `player-item` has `data-bind-mouseover` and `data-bind-focus` events. These events mark the item as active when the player hovers over or clicks on it. The `onItemFocused` function, defined later in our JavaScript file, handles these events.

The `player-item-selected` class styles the active item by changing its background. This class is toggled using the `data-bind-class-toggle` attribute.

When an item is active, an overlay is added to highlight it. The overlay is shown only when the item is active using the `data-bind-if` attribute.

The `player-item-image` element displays the item image, setting the background image using the `data-bind-style-background-image-url` attribute.

## Currencies menu

The currencies menu uses the same structure as the inventory menu. We’ll create a new `submenu-bottom` inside the `menu-right` wrapper, adding the `border-bg` and `submenu-wrapper` elements.

To dynamically show the active item’s price, we’ll use the `data-bind-value` attribute.

```html
<div class="submenu-bottom">
      <div class="border-bg border-bg-currencies">
         <div class="overlay-lines border-radius-lines"></div>
      </div>
      <div class="submenu-wrapper currencies-wrapper">
         <div class="menu-item-title">Currencies</div>
         <div class="menu-item-container">
            <div class="menu-item-stat">
                  <div class="menu-item-stat-label">
                     <div class="icon icon-money"></div>
                  </div>
                  <div
                     class="menu-item-stat-value currency"
                     data-bind-value="{{activeState.selectedItem.gold}}"
                  ></div>
            </div>
            <div class="menu-item-stat">
                  <div class="menu-item-stat-label">
                     <div class="icon icon-currency"></div>
                  </div>
                  <div class="menu-item-stat-value currency">155 230 500</div>
            </div>
         </div>
      </div>
</div>
```

## Showing menu controls hints

To guide the player on navigating through the items, we’ll add hints at the bottom of the screen, positioned after the currencies wrapper.

```html
<div class="submenu-bottom">
      <div class="border-bg border-bg-currencies">
         <div class="overlay-lines border-radius-lines"></div>
      </div>
      <div class="submenu-wrapper currencies-wrapper">
         <div class="menu-item-title">Currencies</div>
         <div class="menu-item-container">
            <div class="menu-item-stat">
                  <div class="menu-item-stat-label">
                     <div class="icon icon-money"></div>
                  </div>
                  <div
                     class="menu-item-stat-value currency"
                     data-bind-value="{{activeState.selectedItem.gold}}"
                  ></div>
            </div>
            <div class="menu-item-stat">
                  <div class="menu-item-stat-label">
                     <div class="icon icon-currency"></div>
                  </div>
                  <div class="menu-item-stat-value currency">155 230 500</div>
            </div>
         </div>
      </div>
      <div class="controls">
         <div class="arrow">
            <div class="arrow-icon up"></div>
            <div>Move up</div>
         </div>
         <div class="arrow">
            <div class="arrow-icon down"></div>
            <div>Move down</div>
         </div>
         <div class="arrow">
            <div class="arrow-icon left"></div>
            <div>Move left</div>
         </div>
         <div class="arrow">
            <div class="arrow-icon right"></div>
            <div>Move right</div>
         </div>
         <div class="arrow">
            <div class="arrow-icon p">P</div>
            <div>Close menu</div>
         </div>
      </div>
</div>
```

The arrow icon is an SVG that will be rotated using the `transform: rotate` CSS property based on the arrow direction.

```css
.arrow {
    width: 8rem;
    height: 5rem;
    display: flex;
    flex-direction: row;
    align-items: center;
}

.arrow-icon {
    background-image: url(./assets/arrow.svg);
    background-size: 100% 100%;
    width: 1.5rem;
    height: 1.5rem;
    margin-right: 0.5rem;
}

.arrow-icon.up {
    transform: rotate(-90deg);
}

.arrow-icon.down {
    transform: rotate(90deg);
}

.arrow-icon.left {
    transform: rotate(-180deg);
}

.arrow-icon.p {
    background-image: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5rem;
    color: rgba(0, 201, 228, 1);
}
```

## Setting up the data model

In this tutorial, we will mock our data directly in JavaScript for faster iteration. However, it is necessary to create all the models directly in the game and use the Gameface data binding to display them in the UI.

To set up the mock data model, first, we will import the `cohtml.js` library and the `player-inventory.js` file in our `player-inventory.html` file.

```html
<body>
   ...
   <script src="cohtml.js"></script>
   <script src="./js/player-inventory.js"></script>
</body>
```

After that, we can proceed with the data model setup:

```js
engine.whenReady.then(() => {
   const NO_ACHIEVEMENT_TITLE = "No achievements unlocked";
   const FIRST_GENERATION_DESCRIPTION = "First generation";

   const TYPE_LABEL_ENUM = {
      Shuko: "Shuko",
      Ucolos: "Ucolos",
      Arachod: "Arachod"
   };

   const QUALITY_LABEL_ENUM = {
      Poor: "Poor",
      Common: "Common",
      Rare: "Rare",
      Unique: "Unique"
   };

   const GUNS_DATA = [
      {
         name: "Pistol",
         description: FIRST_GENERATION_DESCRIPTION,
         gold: 1000123,
         image: "assets/weapon1.png",
         quality: QUALITY_LABEL_ENUM.Poor,
         type: TYPE_LABEL_ENUM.Ucolos,
         grade: 5,
         achievementTitle: NO_ACHIEVEMENT_TITLE,
         achievementValue: " ",
         dmgRating: 15,
         rof: 300,
         rounds: 24,
         firepower: "5",
         reload: "25",
         accuracy: "10",
         recoil: "8"
      },
      {
         name: "Rifle",
         description: FIRST_GENERATION_DESCRIPTION,
         gold: 2015017,
         image: "assets/weapon2.png",
         quality: QUALITY_LABEL_ENUM.Poor,
         type: TYPE_LABEL_ENUM.Shuko,
         grade: 25,
         achievementTitle: "Cold Marksman",
         achievementValue: "120% Critical Damage",
         dmgRating: 35,
         rof: 600,
         rounds: 90,
         firepower: "25",
         reload: "55",
         accuracy: "50",
         recoil: "60"
      },
      {
         name: "Blaster",
         description: FIRST_GENERATION_DESCRIPTION,
         gold: 199999,
         image: "assets/weapon3.png",
         quality: QUALITY_LABEL_ENUM.Poor,
         type: TYPE_LABEL_ENUM.Arachod,
         grade: 30,
         achievementTitle: NO_ACHIEVEMENT_TITLE,
         achievementValue: " ",
         dmgRating: 35,
         rof: 900,
         rounds: 60,
         firepower: "55",
         reload: "55",
         accuracy: "5",
         recoil: "60"
      },
      {
         name: "Knife",
         description: FIRST_GENERATION_DESCRIPTION,
         gold: 501010,
         image: "assets/weapon4.png",
         quality: QUALITY_LABEL_ENUM.Poor,
         type: TYPE_LABEL_ENUM.Shuko,
         grade: 15,
         achievementTitle: NO_ACHIEVEMENT_TITLE,
         achievementValue: " ",
         dmgRating: 25,
         rof: 0,
         rounds: 0,
         firepower: "0",
         reload: "0",
         accuracy: "0",
         recoil: "0"
      },
      {
         name: "RPG",
         description: FIRST_GENERATION_DESCRIPTION,
         gold: 3012343,
         image: "assets/weapon5.png",
         quality: QUALITY_LABEL_ENUM.Poor,
         type: TYPE_LABEL_ENUM.Ucolos,
         grade: 70,
         achievementTitle: NO_ACHIEVEMENT_TITLE,
         achievementValue: " ",
         dmgRating: 60,
         rof: 250,
         rounds: 5,
         firepower: "60",
         reload: "25",
         accuracy: "80",
         recoil: "30"
      },
      {
         name: "AWP",
         description: FIRST_GENERATION_DESCRIPTION,
         gold: 4300201,
         image: "assets/weapon6.png",
         quality: QUALITY_LABEL_ENUM.Poor,
         type: TYPE_LABEL_ENUM.Arachod,
         grade: 75,
         achievementTitle: NO_ACHIEVEMENT_TITLE,
         achievementValue: " ",
         dmgRating: 60,
         rof: 250,
         rounds: 35,
         firepower: "60",
         reload: "50",
         accuracy: "80",
         recoil: "80"
      },
   ];
   engine.createJSModel('player', {
      items: GUNS_DATA
   });

   engine.synchronizeModels();
});
```

## Active item selection

To retrieve the active item, we will use an [observable model ](https://docs.coherent-labs.com/cpp-gameface/integration/ui_scripting/htmldatabinding/#observable-models)that will hold the currently selected item. We will create a new model called `activeState` and set the `selectedItem` to the first item in the `player.items` array.

```js
engine.createJSModel('player', {
   items: GUNS_DATA
});

engine.createObservableModel("activeState");
activeState.selectedItem = player.items[0];

engine.synchronizeModels();
```

## Focusing the items

To focus the items, we will create a function called `onItemFocused` that will set the `activeState.selectedItem` to the item that is currently focused.

```js
function onItemFocused(event, element, item) {
    activeState.selectedItem = item;
    engine.synchronizeModels();
}
```

## Updating the progress bar value

To dynamically update the progress bar value, we will create a new [custom data binding attribute ](https://docs.coherent-labs.com/cpp-gameface/integration/ui_scripting/htmldatabinding/#custom-data-binding-attributes)called `data-bind-progress`.

```js
engine.whenReady.then(() => {
   class Progress {
      init(element, value) {
         element.targetValue = value;
      }

      update(element, value) {
         element.targetValue = value;
      }
   }

   engine.registerDataBinding('progress', Progress);
});
```

We will modify the progress bar value using the [targetValue ](https://coherentlabs.github.io/GameUIComponents/en/components/progress-bar/#target-value)property of the element whenever the model’s value changes.

## Inventory items navigation

To enable the player to navigate through the items, install the interaction manager library by running `npm i coherent-gameface-interaction-manager` inside the `Content/uiresources/HologramUI/` folder and then import it:

```html
<script src="./node_modules/coherent-gameface-interaction-manager/dist/interaction-manager.min.js"></script>
```

Once the library is imported, initialize spatial navigation and set the focusable elements to the items in the inventory.

```js
interactionManager.spatialNavigation.init(['.player-item']);
interactionManager.spatialNavigation.focusFirst();
```

We also focus the first item in the inventory so the player can start navigating through the items when the menu opens.

## Enabling entry animations for the menus when the player opens the inventory

When the player presses the `P` button in the game, it will trigger a JS event from the game to the UI as set in the previous tutorial. To handle this event and start the opening animations of our menu, we will subscribe to the `openMenu` engine event in the `player-inventory.js` file.

```js
engine.on('openMenu', () => {
   menu.classList.toggle('hide-screen', false);
});
```

When the event is triggered, we remove the `hide-screen` class from the `menu` element so the menu becomes visible and animations start.

## Closing the menu

As mentioned in the previous tutorial, closing the menu will be handled from the UI side. We will add a `keypress` event responsible for this operation. When the player presses the `P` button, we will close the menu by adding the `hide-screen` class and enabling the closing animations. Also, we will trigger an event to the engine indicating that the menu is closed.

```js
document.addEventListener('keypress', (event) => {
   if (event.key === 'p') {
      engine.trigger('closeMenu');
      menu.classList.toggle('hide-screen', true);
   }
});
```

## Animations for the menu

For the closing and opening animations of our menu, we will use transitions. We will change the `transform` property for each screen so they are opened or closed based on whether the `hide-screen` class is set on the `menu` element.

```css
.border-bg-weapon-preview {
    transition: transform 500ms;
}

.border-bg-inventory {
    transition: transform 300ms;
}

.border-bg-currencies {
    transition: transform 400ms;
}

.hide-screen .border-bg-weapon-preview {
    transform: translateX(-2rem) scale(0);
    transition: transform 500ms 300ms;
}

.hide-screen .border-bg-inventory {
    transform: translateX(-2rem) scale(0);
    transition: transform 300ms 500ms;
}

.hide-screen .border-bg-currencies {
    transform: translateX(-2rem)scale(0);
    transition: transform 400ms 400ms;
}

.weapon-preview-wrapper {
    transform-origin: top;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .weapon-preview-wrapper {
    transform: scaleY(0);
    transition: transform 500ms;
}

.inventory-wrapper {
    transform-origin: right;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .inventory-wrapper {
    transform: scaleX(0);
    transition: transform 300ms;
}

.currencies-wrapper {
    transform-origin: bottom;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .currencies-wrapper {
    transform: scaleY(0);
    transition: transform 400ms;
}

.controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    margin-top: 1.5rem;
    transform-origin: bottom;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .controls {
    transform: scaleY(0);
    transition: transform 400ms;
}
```

As you can see, we added a small delay between the animations so they do not all start at the same time. This will give a better visual effect when the menu is opened or closed.

## Full source code

```html
<!DOCTYPE html>
<html lang="en">

<head>
    <link
        rel="stylesheet"
        href="node_modules/coherent-gameface-progress-bar/coherent-gameface-components-theme.css"
    >
    <link
        rel="stylesheet"
        href="node_modules/coherent-gameface-progress-bar/style.css"
    >
    <link rel="stylesheet" href="player-inventory-styles.css">
</head>

<body>
    <div class='menu'>
        <div class="menu-left">
            <div class="submenu-top">
                <div class="border-bg border-bg-weapon-preview">
                    <div class="overlay-lines border-radius-lines"></div>
                </div>
                <div class="submenu-wrapper weapon-preview-wrapper">
                    <div class="menu-item-title">Weapon preview</div>
                    <div class="menu-selected-item-preview">
                        <div
                            class="selected-item-image"
                            data-bind-style-background-image-url="{{activeState.selectedItem.image}}"
                        ></div>
                    </div>
                    <div class="menu-item-title">Stats</div>
                    <div class="menu-item-container">
                        <div class="menu-item-stats-wrapper">
                            <div class="menu-item-stat">
                                <div class="menu-item-stat-label">Name</div>
                                <div
                                    class="menu-item-stat-value"
                                    data-bind-value="{{activeState.selectedItem.name}}"
                                ></div>
                            </div>
                            <div class="menu-item-stat">
                                <div class="menu-item-stat-label">Description</div>
                                <div
                                    class="menu-item-stat-value"
                                    data-bind-value="{{activeState.selectedItem.description}}"
                                ></div>
                            </div>
                            <div class="menu-item-stat">
                                <div class="menu-item-stat-label">Firepower</div>
                                <div class="menu-item-stat-value">
                                    <gameface-progress-bar
                                        animation-duration="500"
                                        data-bind-progress="{{activeState.selectedItem.firepower}}"
                                    ></gameface-progress-bar>
                                    <span
                                        class="stat-text-value"
                                        data-bind-value="{{activeState.selectedItem.firepower}}+'%'"
                                    ></span>
                                </div>
                            </div>
                            <div class="menu-item-stat">
                                <div class="menu-item-stat-label">Reload</div>
                                <div class="menu-item-stat-value">
                                    <gameface-progress-bar
                                        animation-duration="500"
                                        data-bind-progress="{{activeState.selectedItem.reload}}"
                                    ></gameface-progress-bar>
                                    <span
                                        class="stat-text-value"
                                        data-bind-value="{{activeState.selectedItem.reload}}+'%'"
                                    ></span>
                                </div>
                            </div>
                            <div class="menu-item-stat">
                                <div class="menu-item-stat-label">Accuracy</div>
                                <div class="menu-item-stat-value">
                                    <gameface-progress-bar
                                        animation-duration="500"
                                        data-bind-progress="{{activeState.selectedItem.accuracy}}"
                                    ></gameface-progress-bar>
                                    <span
                                        class="stat-text-value"
                                        data-bind-value="{{activeState.selectedItem.accuracy}}+'%'"
                                    ></span>
                                </div>
                            </div>
                            <div class="menu-item-stat">
                                <div class="menu-item-stat-label">Recoil</div>
                                <div class="menu-item-stat-value">
                                    <gameface-progress-bar
                                        animation-duration="500"
                                        data-bind-progress="{{activeState.selectedItem.recoil}}"
                                    ></gameface-progress-bar>
                                    <span
                                        class="stat-text-value"
                                        data-bind-value="{{activeState.selectedItem.recoil}}+'%'"
                                    ></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="menu-right">
            <div class="submenu-top">
                <div class="border-bg border-bg-inventory">
                    <div class="overlay-lines border-radius-lines"></div>
                </div>
                <div class="submenu-wrapper inventory-wrapper">
                    <div class="menu-item-title">Inventory (6)</div>
                    <div class="menu-item-container">
                        <div
                            class="player-item-wrapper"
                            data-bind-for="item:{{player.items}}"
                        >
                            <div
                                class="player-item"
                                data-bind-mouseover="onItemFocused(event,this,{{item}})"
                                data-bind-focus="onItemFocused(event,this,{{item}})"
                            >
                                <div
                                    data-bind-class-toggle="player-item-selected:{{item}}==={{activeState.selectedItem}}"
                                    class="player-item-background"
                                ></div>
                                <div
                                    data-bind-if="{{item}}==={{activeState.selectedItem}}"
                                    class="overlay"
                                >
                                    <div class="overlay-lines"></div>
                                    <div class="overlay-radial"></div>
                                </div>
                                <div
                                    class="player-item-image"
                                    data-bind-style-background-image-url="{{item.image}}"
                                ></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="submenu-bottom">
                <div class="border-bg border-bg-currencies">
                    <div class="overlay-lines border-radius-lines"></div>
                </div>
                <div class="submenu-wrapper currencies-wrapper">
                    <div class="menu-item-title">Currencies</div>
                    <div class="menu-item-container">
                        <div class="menu-item-stat">
                            <div class="menu-item-stat-label">
                                <div class="icon icon-money"></div>
                            </div>
                            <div
                                class="menu-item-stat-value currency"
                                data-bind-value="{{activeState.selectedItem.gold}}"
                            ></div>
                        </div>
                        <div class="menu-item-stat">
                            <div class="menu-item-stat-label">
                                <div class="icon icon-currency"></div>
                            </div>
                            <div class="menu-item-stat-value currency">155 230 500</div>
                        </div>
                    </div>
                </div>
                <div class="controls">
                    <div class="arrow">
                        <div class="arrow-icon up"></div>
                        <div>Move up</div>
                    </div>
                    <div class="arrow">
                        <div class="arrow-icon down"></div>
                        <div>Move down</div>
                    </div>
                    <div class="arrow">
                        <div class="arrow-icon left"></div>
                        <div>Move left</div>
                    </div>
                    <div class="arrow">
                        <div class="arrow-icon right"></div>
                        <div>Move right</div>
                    </div>
                    <div class="arrow">
                        <div class="arrow-icon p">P</div>
                        <div>Close menu</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../javascript/cohtml.js"></script>
    <script src="./node_modules/coherent-gameface-progress-bar/dist/progress-bar.production.min.js"></script>
    <script src="./node_modules/coherent-gameface-interaction-manager/dist/interaction-manager.min.js"></script>
    <script src="./js/player-inventory.js"></script>
</body>

</html>
```

```css
html {
    font-size: 1.5vh;
}

body {
    width: 100vw;
    height: 100vh;
    margin: 0;
}

.overlay,
.overlay-lines,
.overlay-radial {
    pointer-events: none;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999;
}

.overlay {
    mask-image: radial-gradient(circle, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.5327380952380952) 65%, rgba(255, 255, 255, 0) 100%);
    mask-size: 90% 90%;
    mask-position: center;
}

.overlay-lines {
    background-image: linear-gradient(rgba(0, 200, 228, 0.1) 0%, rgba(0, 200, 228, 0.1) 30%, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0) 100%);
    background-size: 100% 0.5rem;
    animation: overlay-anim 3s forwards linear infinite;
}

@keyframes overlay-anim {
    from {
        background-position: 0% 0%;
    }

    to {
        background-position: 0% -10%;
    }
}

.overlay-radial {
    background-image: radial-gradient(circle, rgba(0, 200, 228, 0.2) 0%, rgba(255, 255, 255, 0) 90%, rgba(255, 255, 255, 0) 100%);
    background-size: 200%;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    animation: overlay-radial-anim 3s forwards linear infinite;
    z-index: 998;
}

@keyframes overlay-radial-anim {
    0% {
        opacity: 0;
    }

    1% {
        opacity: 1;
    }

    5% {
        opacity: 0;
    }

    19% {
        opacity: 0;
    }

    20% {
        opacity: 1;
    }

    25% {
        opacity: 0;
    }

    59% {
        opacity: 0;
    }

    60% {
        opacity: 1;
    }

    65% {
        opacity: 0;
    }

    100% {
        opacity: 0;
    }
}

.menu {
    background-color: rgb(0, 0, 0, 0);
    color: white;
    width: 100vw;
    height: 100vh;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    display: flex;
    perspective: 1000px;
    opacity: 1;
}

.menu-left,
.menu-right {
    height: 100%;
    padding: 1rem;
}

.menu-left {
    margin-left: 1rem;
    flex: 1 1 30%;
    transform: rotateY(20deg) skewY(-3deg) translateY(-1rem);
    transform-origin: center left;
}

.menu-right {
    transform: translateX(-5rem);
    flex: 1 1 70%;
    perspective: 1000px;
}

.submenu-top {
    transform: scale(0.9) rotateY(-4deg);
    transform-origin: top right;
    height: 70%;
    position: relative;
}

.submenu-bottom {
    width: 97.5%;
    transform: scale(0.9) rotateY(-4deg) rotateX(10deg) skewY(0deg) skewX(-10deg) translateX(5%) translateY(-5%);
    transform-origin: center;
    height: 25%;
    position: relative;
}

.menu-item-title {
    background-color: rgba(0, 121, 137, 0.9);
    display: flex;
    font-size: 2rem;
    padding: 1rem 3rem 1rem 3rem;
}

.menu-item-container {
    background-color: rgba(0, 39, 44, 0.5);
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    flex: 1 0 auto;
    padding: 1rem 3rem 1rem 3rem;

}

.menu-selected-item-preview {
    background-color: rgba(0, 39, 44, 0.9);
    display: flex;
    align-content: center;
    justify-content: center;
    width: 100%;
    height: 30%;
    padding: 1rem 3rem 1rem 3rem;
}

.player-item-wrapper {
    z-index: 1001;
}

.player-item {
    margin: 1rem;
    position: relative;
    width: 14rem;
    height: 14rem;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2001;
}

.player-item-background {
    pointer-events: none;
    width: 100%;
    height: 100%;
    position: absolute;
    background-color: rgb(0, 59, 67);
    border: 0.2rem solid rgba(255, 255, 255, 0.133);
    transition: background-color 0.3s, border 0.3s;
    z-index: 1;
    border-radius: 1.5rem;

}

.player-item-selected {
    background-color: rgba(0, 83, 94, 0.9);
    border: 0.2rem solid rgba(255, 255, 255, 0.8);
}

.player-item-image {
    pointer-events: none;
    width: 60%;
    height: 60%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
}

.menu-bottom {
    transform: rotateX(-4deg);
}

.h-30 {
    height: 30%;
}

.h-60 {
    height: 60%;
}

.h-70 {
    height: 70%;
}


.selected-item-image {
    width: 90%;
    height: 90%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.menu-item-stats-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.menu-item-stat {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    padding: 1rem;
    font-size: 1.3rem;
}

.menu-item-stat-label {
    flex-basis: 8rem;
}

.menu-item-stat-value {
    height: 1.2rem;
    flex: 1 0 0;
    display: flex;
    flex-direction: row;
    align-items: center;
}

gameface-progress-bar {
    flex: 1 0 0;
}

.stat-text-value {
    width: 5%;
    margin-left: 1rem;
    display: flex;
    justify-content: center;
}

.icon {
    background-repeat: no-repeat;
    background-position: left center;
    background-size: contain;
    height: 3rem;
}

.icon-currency {
    background-image: url(./assets/iconCurrency.png);
}

.icon-money {
    background-image: url(./assets/money.png);
}

.currency {
    font-size: 1.6rem;
}

.border-bg {
    position: absolute;
    width: 108%;
    height: 106%;
    border-image-source: url(./assets/border.png);
    border-image-slice: 60;
    border-image-width: 3.5rem;
    border-image-outset: 0;
    border-image-repeat: stretch;
    z-index: -1;
    transform: translateX(-2rem) scale(1);
    top: 1rem;
}

.border-bg-weapon-preview {
    transition: transform 500ms;
}

.border-bg-inventory {
    transition: transform 300ms;
}

.border-bg-currencies {
    transition: transform 400ms;
}

.hide-screen .border-bg-weapon-preview {
    transform: translateX(-2rem) scale(0);
    transition: transform 500ms 300ms;
}

.hide-screen .border-bg-inventory {
    transform: translateX(-2rem) scale(0);
    transition: transform 300ms 500ms;
}

.hide-screen .border-bg-currencies {
    transform: translateX(-2rem)scale(0);
    transition: transform 400ms 400ms;
}

.border-radius-lines {
    border-radius: 4rem;
}

.submenu-wrapper {
    border-radius: 4rem;
    overflow: hidden;
    height: 100%;
}

.weapon-preview-wrapper {
    transform-origin: top;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .weapon-preview-wrapper {
    transform: scaleY(0);
    transition: transform 500ms;
}

.inventory-wrapper {
    transform-origin: right;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .inventory-wrapper {
    transform: scaleX(0);
    transition: transform 300ms;
}

.currencies-wrapper {
    transform-origin: bottom;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .currencies-wrapper {
    transform: scaleY(0);
    transition: transform 400ms;
}

.controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    margin-top: 1.5rem;
    transform-origin: bottom;
    transform: scale(1);
    transition: transform 500ms 500ms;
}

.hide-screen .controls {
    transform: scaleY(0);
    transition: transform 400ms;
}

.arrow {
    width: 8rem;
    height: 5rem;
    display: flex;
    flex-direction: row;
    align-items: center;
}

.arrow-icon {
    background-image: url(./assets/arrow.svg);
    background-size: 100% 100%;
    width: 1.5rem;
    height: 1.5rem;
    margin-right: 0.5rem;
}

.arrow-icon.up {
    transform: rotate(-90deg);
}

.arrow-icon.down {
    transform: rotate(90deg);
}

.arrow-icon.left {
    transform: rotate(-180deg);
}

.arrow-icon.p {
    background-image: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.5rem;
    color: rgba(0, 201, 228, 1);
}
```

```js
const menu = document.querySelector('.menu');

engine.whenReady.then(() => {
    class Progress {
        init(element, value) {
            element.targetValue = value;
        }

        update(element, value) {
            element.targetValue = value;
        }
    }
    engine.registerBindingAttribute('progress', Progress);
    engine.on('openMenu', () => {
        menu.classList.toggle('hide-screen', false);
    });

    document.addEventListener('keypress', (event) => {
        if (event.key === 'p') {
            engine.trigger('closeMenu');
            menu.classList.toggle('hide-screen', true);
        }
    });

    const NO_ACHIEVEMENT_TITLE = "No achievements unlocked";
    const FIRST_GENERATION_DESCRIPTION = "First generation";

    const TYPE_LABEL_ENUM = {
        Shuko: "Shuko",
        Ucolos: "Ucolos",
        Arachod: "Arachod"
    };

    const QUALITY_LABEL_ENUM = {
        Poor: "Poor",
        Common: "Common",
        Rare: "Rare",
        Unique: "Unique"
    };

    const GUNS_DATA = [
        {
            name: "Pistol",
            description: FIRST_GENERATION_DESCRIPTION,
            gold: 1000123,
            image: "assets/weapon1.png",
            quality: QUALITY_LABEL_ENUM.Poor,
            type: TYPE_LABEL_ENUM.Ucolos,
            grade: 5,
            achievementTitle: NO_ACHIEVEMENT_TITLE,
            achievementValue: " ",
            dmgRating: 15,
            rof: 300,
            rounds: 24,
            firepower: "5",
            reload: "25",
            accuracy: "10",
            recoil: "8"
        },
        {
            name: "Rifle",
            description: FIRST_GENERATION_DESCRIPTION,
            gold: 2015017,
            image: "assets/weapon2.png",
            quality: QUALITY_LABEL_ENUM.Poor,
            type: TYPE_LABEL_ENUM.Shuko,
            grade: 25,
            achievementTitle: "Cold Marksman",
            achievementValue: "120% Critical Damage",
            dmgRating: 35,
            rof: 600,
            rounds: 90,
            firepower: "25",
            reload: "55",
            accuracy: "50",
            recoil: "60"
        },
        {
            name: "Blaster",
            description: FIRST_GENERATION_DESCRIPTION,
            gold: 199999,
            image: "assets/weapon3.png",
            quality: QUALITY_LABEL_ENUM.Poor,
            type: TYPE_LABEL_ENUM.Arachod,
            grade: 30,
            achievementTitle: NO_ACHIEVEMENT_TITLE,
            achievementValue: " ",
            dmgRating: 35,
            rof: 900,
            rounds: 60,
            firepower: "55",
            reload: "55",
            accuracy: "5",
            recoil: "60"
        },
        {
            name: "Knife",
            description: FIRST_GENERATION_DESCRIPTION,
            gold: 501010,
            image: "assets/weapon4.png",
            quality: QUALITY_LABEL_ENUM.Poor,
            type: TYPE_LABEL_ENUM.Shuko,
            grade: 15,
            achievementTitle: NO_ACHIEVEMENT_TITLE,
            achievementValue: " ",
            dmgRating: 25,
            rof: 0,
            rounds: 0,
            firepower: "0",
            reload: "0",
            accuracy: "0",
            recoil: "0"
        },
        {
            name: "RPG",
            description: FIRST_GENERATION_DESCRIPTION,
            gold: 3012343,
            image: "assets/weapon5.png",
            quality: QUALITY_LABEL_ENUM.Poor,
            type: TYPE_LABEL_ENUM.Ucolos,
            grade: 70,
            achievementTitle: NO_ACHIEVEMENT_TITLE,
            achievementValue: " ",
            dmgRating: 60,
            rof: 250,
            rounds: 5,
            firepower: "60",
            reload: "25",
            accuracy: "80",
            recoil: "30"
        },
        {
            name: "AWP",
            description: FIRST_GENERATION_DESCRIPTION,
            gold: 4300201,
            image: "assets/weapon6.png",
            quality: QUALITY_LABEL_ENUM.Poor,
            type: TYPE_LABEL_ENUM.Arachod,
            grade: 75,
            achievementTitle: NO_ACHIEVEMENT_TITLE,
            achievementValue: " ",
            dmgRating: 60,
            rof: 250,
            rounds: 35,
            firepower: "60",
            reload: "50",
            accuracy: "80",
            recoil: "80"
        },
    ];
    engine.createJSModel('player', {
        items: GUNS_DATA
    });

    engine.createObservableModel("activeState");
    activeState.selectedItem = player.items[0];

    engine.synchronizeModels();

    interactionManager.spatialNavigation.init(['.player-item']);
    interactionManager.spatialNavigation.focusFirst();
});

function onItemFocused(event, element, item) {
    activeState.selectedItem = item;
    engine.synchronizeModels();
}
```

## On this page
