-
Notifications
You must be signed in to change notification settings - Fork 89
Small class to display warning and error prompts #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed05e68
Small class to display warning and error prompts
originalfoo 8f17abf
Added ...Format() methods
originalfoo 889cba6
_Should_ work anywhere now
originalfoo adcb115
Should work now
originalfoo 5024bd5
Does help if the class is added to the project
originalfoo 3ad3c5f
Updated call sites to use Prompt
originalfoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| namespace TrafficManager.UI.Helpers { | ||
| using ColossalFramework; | ||
| using ColossalFramework.UI; | ||
| using System; | ||
| using UnityEngine.SceneManagement; | ||
|
|
||
| /// <summary> | ||
| /// Use this class to display small but annoying dialog prompts to the user. | ||
| /// | ||
| /// TODO: At some point add more panels, such as: | ||
| /// * ConfirmPanel | ||
| /// * ExitConfirmPanel | ||
| /// * MessageBoxPanel | ||
| /// * TutorialPanel | ||
| /// * TutorialAdvisorPanel | ||
| /// </summary> | ||
| public class Prompt { | ||
|
|
||
| /// <summary> | ||
| /// Display a warning prompt in the centre of the screen. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="title">Dialog title.</param> | ||
| /// <param name="message">Dialog body text.</param> | ||
| public static void Warning(string title, string message) { | ||
| ExceptionPanel(title, message, false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Display a formatted warning prompt in the center of the screen. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="title">Dialog title.</param> | ||
| /// <param name="messageFormat">Dialog body text format.</param> | ||
| /// <param name="args">Values to put in the <paramref name="messageFormat"/>.</param> | ||
| public static void WarningFormat(string title, string messageFormat, params object[] args) { | ||
| ExceptionPanel(title, string.Format(messageFormat, args), false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Display an error prompt in the centre of the screen. | ||
| /// </summary> | ||
| /// <param name="title">Dialog title.</param> | ||
| /// <param name="message">Dialog body text.</param> | ||
| public static void Error(string title, string message) { | ||
| ExceptionPanel(title, message, true); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Display an formatted error prompt in the center of the screen. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="title">Dialog title.</param> | ||
| /// <param name="messageFormat">Dialog body text format.</param> | ||
| /// <param name="args">Values to put in the <paramref name="messageFormat"/>.</param> | ||
| public static void ErrorFormat(string title, string messageFormat, params object[] args) { | ||
| ExceptionPanel(title, string.Format(messageFormat, args), true); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Display an exception message in the center of the screen, optionally | ||
| /// styled as an error. | ||
| /// </summary> | ||
| /// | ||
| /// <param name="title">Dialog title.</param> | ||
| /// <param name="message">Dialog body text.</param> | ||
| /// <param name="isError">If <c>true</c>, the dialog is styled as an error.</param> | ||
| internal static void ExceptionPanel(string title, string message, bool isError) { | ||
| // if in-game, queue in main thread, otherwise display immediately | ||
| // note: I have no idea if this is good way to do it! | ||
| Action show = | ||
| if (SceneManager.GetActiveScene().name == "Game") { | ||
| Singleton<SimulationManager>.instance.m_ThreadingWrapper.QueueMainThread( | ||
| () => { | ||
| UIView.library | ||
| .ShowModal<ExceptionPanel>("ExceptionPanel") | ||
| .SetMessage(title, message, isError); | ||
| }); | ||
| } else { | ||
| UIView.library | ||
| .ShowModal<ExceptionPanel>("ExceptionPanel") | ||
| .SetMessage(title, message, isError); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.