Modding question – Creating custom UI screens

Discuss modding questions and implementation details.
Post Reply
User avatar
JIRKA_222
Posts: 9
Joined: Wed Apr 21, 2021 5:11 pm
Location: Czech Republic

Modding question – Creating custom UI screens

Post by JIRKA_222 »

I’ve been trying to make a mod, that would reimplement the bestiary from one of the demos (viewtopic.php?f=22&t=4550). I have almost zero experience in making Daggerfall mods. I’ve looked through the basic tutorials (such as this one: http://forums.dfworkshop.net/viewtopic.php?f=22&t=277) and had no issues. But I have problems in making the GUI itself. I’ve looked into the information found on this page (https://thelacus.github.io/daggerfall-u ... index.html) and tried to make sense of the gui script files (such as DaggerfallTeleportPopUp.cs)to try and figure out how UI scripting works and make my own custom ui screen, but didn't have much luck.
Does a more in-depth documentation (then the one found here https://thelacus.github.io/daggerfall-u ... index.html)/ tutorial for the UI system exist? Sorry if the answer is obvious and I'm wasting your time.

User avatar
Daniel87
Posts: 245
Joined: Thu Nov 28, 2019 6:25 pm

Re: Modding question – Creating custom UI screens

Post by Daniel87 »

Would it be possible for you to share your current code with us, so we can see your approach and maybe directly spot where the problem could be?

User avatar
JIRKA_222
Posts: 9
Joined: Wed Apr 21, 2021 5:11 pm
Location: Czech Republic

Re: Modding question – Creating custom UI screens

Post by JIRKA_222 »

I managed to solve the issue myself, but I have a couple questions. The UI screen in DFU is divided into a 320 x 200 grid (By that I mean, that for example set the coordinates of a lest say button from (0, 0) to (320, 200)), correct?
My second question is: can you change the font in a text label? So can I change the font of the highlighted "Title here" in image 1 to for example the fancy font of the text highlighted in picture 2?

Here is my code:

Code: Select all

using System;
using UnityEngine;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.UserInterface;
using DaggerfallWorkshop.Game.UserInterfaceWindows;
using DaggerfallWorkshop.Utility.AssetInjection;

namespace BestiaryMod
{
    class BestiaryUI : DaggerfallPopupWindow
    {
        Panel mainPanel;

        TextLabel titleLable;
        TextLabel descriptionLable1;
        TextLabel descriptionLable2;
        TextLabel descriptionLable3;
        TextLabel descriptionLable4;
        TextLabel descriptionLable5;


        public BestiaryUI(IUserInterfaceManager uiManager)
            : base(uiManager)
        {
            pauseWhileOpened = true;
            AllowCancel = false;
        }

        protected override void Setup()
        {
            base.Setup();
            ParentPanel.BackgroundColor = ScreenDimColor;

            mainPanel = DaggerfallUI.AddPanel(NativePanel, AutoSizeModes.None);
            mainPanel.Size = new Vector2(320, 200);
            mainPanel.HorizontalAlignment = HorizontalAlignment.Left;
            mainPanel.VerticalAlignment = VerticalAlignment.Top;


            titleLable = new TextLabel();
            titleLable.Position = new Vector2(16, 32);
            titleLable.Size = new Vector2(280, 16);
            titleLable.Name = "title_label";
            mainPanel.Components.Add(titleLable);

            descriptionLable1 = new TextLabel();
            descriptionLable1.Position = new Vector2(218, 72);
            descriptionLable1.Size = new Vector2(100, 16);
            descriptionLable1.Name = "title_label";
            mainPanel.Components.Add(descriptionLable1);

            descriptionLable2 = new TextLabel();
            descriptionLable2.Position = new Vector2(218, 88);
            descriptionLable2.Size = new Vector2(100, 16);
            descriptionLable2.Name = "title_label";
            mainPanel.Components.Add(descriptionLable2);

            descriptionLable3 = new TextLabel();
            descriptionLable3.Position = new Vector2(218, 104);
            descriptionLable3.Size = new Vector2(100, 16);
            descriptionLable3.Name = "title_label";
            mainPanel.Components.Add(descriptionLable3);

            descriptionLable4 = new TextLabel();
            descriptionLable4.Position = new Vector2(218, 120);
            descriptionLable4.Size = new Vector2(100, 16);
            descriptionLable4.Name = "title_label";
            mainPanel.Components.Add(descriptionLable4);


            titleLable.Text = "Title here";

            descriptionLable1.Text = "This is text label 1";
            descriptionLable2.Text = "And this is text label 2";
            descriptionLable3.Text = "This thing is text label 3";
            descriptionLable4.Text = "And this last one is text label 4";
        }

        public override void Update()
        {
            base.Update();

            if (Input.GetKeyUp(exitKey))
                CloseWindow();
        }
    }
}
Attachments
Image 1.png
Image 1.png (1.46 MiB) Viewed 77 times
Image 2.png
Image 2.png (249.73 KiB) Viewed 77 times
Last edited by JIRKA_222 on Sun Apr 25, 2021 9:54 am, edited 1 time in total.

User avatar
BadLuckBurt
Posts: 631
Joined: Sun Nov 05, 2017 8:30 pm

Re: Modding question – Creating custom UI screens

Post by BadLuckBurt »

If you have the font object, you should be able to assign a different font. The DaggerfallUI class has this static method that will return a TextLabel object:

Code: Select all

        public static TextLabel AddTextLabel(DaggerfallFont font, Vector2 position, string text, Panel panel = null, int glyphSpacing = 1)
        {
            TextLabel textLabel = new TextLabel();
            textLabel.AutoSize = AutoSizeModes.None;
            textLabel.Font = font;
            textLabel.Position = position;
            textLabel.Text = text;
            if (panel != null)
                panel.Components.Add(textLabel);

            return textLabel;
        }
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

User avatar
JIRKA_222
Posts: 9
Joined: Wed Apr 21, 2021 5:11 pm
Location: Czech Republic

Re: Modding question – Creating custom UI screens

Post by JIRKA_222 »

Thanks, got it to work.

Post Reply