Redscript
HomeGitHubDiscord
  • Home
  • Getting Started
    • Downloads
    • Setup for VSCode
    • Setup for JetBrains IDEs
    • How to start REDscripting
      • Step 1: Mod structure
      • Step 2: Finding the right class
  • Language
    • Intro
      • REDscript in 2 minutes
      • How to create a hook
        • Things to hook
    • Language Features
      • Intrinsics
      • Loops
      • Strings
      • Modules
      • Annotations
      • Conditional compilation
      • Configurable user hints
    • Built-in Types
    • Built-in Functions
      • Math
      • Random
      • Utilities
  • References and examples
    • Common Patterns
      • Safe downcasting
      • Class constructors
      • Hash maps
      • Heterogeneous array literals
      • Scriptable systems (singletons)
      • DelaySystem and DelayCallback
      • Generic callbacks
      • Persistence
    • Logging
    • UI Scripting
      • Logging Widget Trees
      • Popups
    • Vehicle system
    • Weapons
    • Codeware callbacks
      • Scriptables comparison
    • Libraries
    • Gameplay
      • Sleeping and Skipping Time
  • Help
    • Community
    • Troubleshooting
Powered by GitBook
On this page
  1. References and examples
  2. UI Scripting

Popups

Scriptable popups

PreviousLogging Widget TreesNextVehicle system

Last updated 1 month ago

Was this helpful?

CtrlK

Was this helpful?

The game has various built-in popup widgets that can be spawned easily.

  1. SimpleScreenMessage

```
    let warningMsg: SimpleScreenMessage;
    warningMsg.isShown = true;
    warningMsg.duration = 5.00;
    warningMsg.message = "Hello, this is a simple message";
    warningMsg.type = SimpleMessageType.Relic;
    /*
    enum SimpleMessageType {
        Undefined = 0,
        Negative = 1,
        Neutral = 2,
        Vehicle = 3,
        Apartment = 4,
        Relic = 5,
        Money = 6,
        Reveal = 7,
        Boss = 8,
        Twintone = 9,
        Police = 10,
      }
      */
    GameInstance.GetBlackboardSystem(this.GetGame()).Get(GetAllBlackboardDefs().UI_Notifications).SetVariant(GetAllBlackboardDefs().UI_Notifications.WarningMessage, ToVariant(warningMsg), true);
 
```

  1. GenericMessageNotification

Use this if you want a quick popup with a button

Example usage: https://github.com/psiberx/cp2077-equipment-ex/blob/master/scripts/UI/ConflictsPopup.reds'

Using Codeware

Codeware provides primitives for a lot of common UI components including pop ups.

Here's a simple pop up implemented using Codeware's InGamePopupwith custom text

Remember to add this import:

import Codeware.UI.*

```
public class MinimalPopup extends InGamePopup {
    protected let m_header: ref<InGamePopupHeader>;
    protected let m_footer: ref<InGamePopupFooter>;
    protected let m_content: ref<InGamePopupContent>;
    protected let m_text: wref<inkText>;
    protected let customText: String = "Default text";
    
    public static func Create() -> ref<MinimalPopup> {
        let self: ref<MinimalPopup> = new MinimalPopup();
        self.CreateInstance();
        return self;
    }

    protected cb func OnInitialize() {
        super.OnInitialize();
        this.m_text.SetText(this.customText);
    }
    
    protected cb func OnCreate() {
	super.OnCreate();
	this.m_container.SetSize(new Vector2(800.0, 600.0));
	this.m_header = InGamePopupHeader.Create();
	this.m_header.SetTitle("Minimal Popup");
	this.m_header.SetFluffRight("Text Example");
	this.m_header.Reparent(this);
	this.m_footer = InGamePopupFooter.Create();
	this.m_footer.SetFluffIcon(n"fluff_triangle2");
	this.m_footer.SetFluffText("Simple popup with updatable text");
	this.m_footer.Reparent(this);
	this.m_content = InGamePopupContent.Create();
	this.m_content.Reparent(this);

	let canvas = new inkCanvas();
	canvas.SetName(n"canvas");
	canvas.SetAnchor(inkEAnchor.Fill);
	canvas.Reparent(this.m_content.GetRootCompoundWidget());

	let text = new inkText();
	text.SetName(n"updatableText");
	text.SetFontFamily("base\\gameplay\\gui\\fonts\\raj\\raj.inkfontfamily");
	text.SetFontStyle(n"Medium");
	text.SetFontSize(30);
	text.SetHorizontalAlignment(textHorizontalAlignment.Center);
	text.SetVerticalAlignment(textVerticalAlignment.Center);
	text.SetAnchor(inkEAnchor.Centered);
	text.SetAnchorPoint(new Vector2(0.5, 0.5));
	text.SetMargin(new inkMargin(0.0, 0.0, 0.0, 0.0));
	text.SetWrapping(true, 700.0);
	text.SetFitToContent(true);
	text.SetStyle(r"base\\gameplay\\gui\\common\\main_colors.inkstyle");
	text.BindProperty(n"tintColor", n"MainColors.Blue");
        text.SetText("Default text");
        text.Reparent(canvas);
	this.m_text = text;
    }

    public func SetCustomText(text: String) -> Void {
        this.customText = text;
    }
} 
```

Which can then be used like this:

```
let controller = GameInstance.GetInkSystem().GetLayer(n"inkHUDLayer").GetGameController() as inkGameController;
let popup = MinimalPopup.Create();
popup.SetCustomText(text);
popup.Open(controller);
```

See Codeware Wiki and InkPlayground for more examples and details.