Engine Components to Use:
DaggerfallConnect.Arena2
DaggerfallWorkshop.Game.UserInterface
First you need to create a text file token to store the text that will be displayed, like so. If you're going to have more than one text line within the message box, ensure to size the text tokens array for each line of text, including text formatting/line breaks, so there are enough tokens in the array for every text line, including line breaks.
Code: Select all
TextFile.Token[] tokens = "Text to display";
Code: Select all
DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, PreviousUIReference);
Code: Select all
messageBox.SetTextTokens(tokens, MacroContextProvider);
Code: Select all
messageBox.ClickAnywhereToClose = true;
messageBox.Show();
Here is my example for creating range and inertia values in the UI readout.
Code: Select all
protected void ShowInfoPopup(DaggerfallUnityItem item)
{
TextFile.Token[] tokens = ItemHelper.GetItemInfo(item, DaggerfallUnity.TextProvider);
//checks if an item has a usable range. If it does, resizes above text token array to add 2 blank tokens to it.
//Creates range string for itemdisplay ui, adds a formatting token to first blank token then adds text to second
//blank token.
if (item.rangeInFt != 0)
{
Array.Resize(ref tokens, tokens.Length + 4);
int addToken = tokens.Length;
string rangetxt = string.Format("Range: {0} feet", item.rangeInFt);
string speedtxt = string.Format("Intertia: {0} lb/ft", ItemHelper.getItemSpeed(item));
tokens[addToken - 1] = TextFile.CreateFormatToken(TextFile.Formatting.JustifyCenter);
tokens[addToken - 2] = TextFile.CreateTextToken(speedtxt);
tokens[addToken - 3] = TextFile.CreateFormatToken(TextFile.Formatting.JustifyCenter);
tokens[addToken - 4] = TextFile.CreateTextToken(rangetxt);
}
if (tokens != null && tokens.Length > 0)
{
DaggerfallMessageBox messageBox = new DaggerfallMessageBox(uiManager, this);
messageBox.SetTextTokens(tokens, item);
if (item.IsPotionRecipe)
{ // Setup the next message box with the potion recipe ingredients list.
DaggerfallMessageBox messageBoxRecipe = new DaggerfallMessageBox(uiManager, messageBox);
messageBoxRecipe.SetTextTokens(item.GetMacroDataSource().PotionRecipeIngredients(TextFile.Formatting.JustifyCenter));
messageBoxRecipe.ClickAnywhereToClose = true;
messageBox.AddNextMessageBox(messageBoxRecipe);
messageBox.Show();
}
else if (item.legacyMagic != null)
{ // Setup the next message box with the magic effect info.
DaggerfallMessageBox messageBoxMagic = new DaggerfallMessageBox(uiManager, messageBox);
messageBoxMagic.SetTextTokens(1016, item);
messageBoxMagic.ClickAnywhereToClose = true;
messageBox.AddNextMessageBox(messageBoxMagic);
messageBox.Show();
}
else if (item.ItemGroup == ItemGroups.Paintings)
{ // Setup the message box with the painting image generated by macro handlers
ImageData paintingImg = ImageReader.GetImageData(item.GetPaintingFilename(), item.GetPaintingFileIdx(), 0, true, true);
messageBox.ImagePanel.VerticalAlignment = VerticalAlignment.None;
messageBox.ImagePanel.Position = new Vector2(0, 5);
messageBox.ImagePanel.Size = new Vector2(paintingImg.width, paintingImg.height);
messageBox.ImagePanel.BackgroundTexture = paintingImg.texture;
messageBox.ClickAnywhereToClose = true;
messageBox.Show();
}
else
{
messageBox.ClickAnywhereToClose = true;
messageBox.Show();
}
}
}
You should be using either a boolean switch to trigger on and off the message when certain events trigger or a delta timer to set the time intervals for the message to appear or a combination of a timer and trigger switch to turn on the message and then repeat it at a set time interval; this is how the poison message works.
By using proper boolean switches, routine calls, coroutines, and timers, you can improve the efficiency and playability of all your mods and code.
Just always ask yourself, does this code executing do anything for the script/program in the coding execution flow. If not, you can probably get rid of it or recode it to free up a few more cycles/frames for the engine to use on more important things. Optimized code should only fire when the data/process is needed, and not on any other cpu cycle to ensure it doesn't affect further scripts and coding running in subsequent cpu cycles. Bethesda Engines have a long history of having issue with running extra script loads outside the programmed engine; Skyrim can only handle the modding it can because of the intense amount of work and millions of combined modding hours the whole community has put into rebuilding the game and engine from ground up to deal with Bethesda's cruddy development and coding practices and cycles.