Skip to content
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

Small class to display warning and error prompts #774

Merged
merged 6 commits into from
Mar 5, 2020
Merged

Conversation

originalfoo
Copy link
Member

@originalfoo originalfoo commented Mar 3, 2020

Just a simple helper to display warning/error prompts in center of screen.

There's a few places where these things are used, most notably:

  • Warning that setting can only be changed in-game (mod options screen from main menu)
  • Warning about game version mismatch (in-game)
  • Warning about detour/patch issues (in-game)
  • Probably some user interactions in-game that haven't yet been moved to GuideManager?

Usage from call site:

using TrafficManager.UI.Helpers;

// ...

Prompt.Warning("title", "body text");

Prompt.Error("title", "body text");

TODO:

  • Currently the prompts are wrapped in Singleton<SimulationManager>.instance.m_ThreadingWrapper.QueueMainThread, so they will only work while in-game. From main menu, that stuff isn't required.
  • What's the best way to check whether I need to do the QueueMainThread stuff?
  • Also, should I be checking System.Threading.Thread.CurrentThread.Name != "Simulation" like in GuideWrapper.cs?

Answers on a postcard to usual address please :)

  • Add some ...Format() method overloads.
  • Find where the prompts are currently used in solution and make them use the Prompt helper

Following prompts have been updated:

  • Keybinds - shortcut already exists (both on key and mouse)
  • Mod options - when user changes game-only option from main menu
  • Threading extension - if an unexpected incompatibility is found
  • Main Tool - ShowError() renamed to ShowWarning() now uses Prompt.Warning(), affects:
    • Manual traffic light tool - if user clicks junction with TTL
    • Toggle traffic light tool - if user clicks junction with TTL
    • TTL tool - 4 separate warnings
    • Priority signs tool - if user clicks junction with TTL
  • Stuff in LoadingExtenion has not been altered as it will be replaced by PRs Lifecycle part 1 - IUserMod #773 and Updated compatibility checker #699.

Will probably only work while in-game, only tested from context of `LoadingExtension.OnLevelLoaded()`.
@originalfoo originalfoo added adjustments required An issue require some adjustments in code UI User interface updates code cleanup Refactor code, remove old code, improve maintainability labels Mar 3, 2020
@originalfoo originalfoo requested review from kianzarrin and a team March 3, 2020 14:33
@originalfoo originalfoo self-assigned this Mar 3, 2020
@kvakvs
Copy link
Collaborator

kvakvs commented Mar 3, 2020

Nice.
As the messages will be localized, maybe using localized string as a format can someday be useful.

@originalfoo originalfoo added the DO NOT MERGE YET Don't merge this PR, even if approved, until further notice label Mar 3, 2020
@originalfoo
Copy link
Member Author

Any ideas on how to determine whether to use QueueMainThread() or not?

@originalfoo originalfoo added this to the 11.2 milestone Mar 3, 2020
@krzychu124
Copy link
Member

Any ideas on how to determine whether to use QueueMainThread() or not?

I think you can use it even from main thread. Doesn't seem to break anything if you do. Here is the code (game internals):

public void QueueMainThread(Action action) {
	if (Dispatcher.currentSafe == ThreadHelper.dispatcher)
	{
		action();
	}
	else
	{
		ThreadHelper.dispatcher.Dispatch(action);
	}
}

@originalfoo
Copy link
Member Author

originalfoo commented Mar 3, 2020

@krzychu124 is the Singleton<SimulationManager>.instance always present? Even when cities.exe first loads (ie. not loaded a city yet)?

EDIT: I'll test to find out...

@krzychu124
Copy link
Member

krzychu124 commented Mar 3, 2020

@krzychu124 is the Singleton<SimulationManager>.instance always present? Even when cities.exe first loads (ie. not loaded a city yet)?

Yes, instance is almost always present. To be safe I suggest waiting until Starter.Awake() is completed. OnEnabled() is not the best place, but if you need it there you should create gameObject and start simple coroutine inside to wait for the next frame. I can post snipped if you need.
Plugins are loaded and enabled before SimulationManager ensure instance and register its managers that's why you need to delay your work.

@originalfoo
Copy link
Member Author

Just tested Prompt.Warning() in https://github.com/CitiesSkylinesMods/TMPE/blob/master/TLM/TLM/State/Options.cs#L167 but it didn't seem to work. Just trying some alternatives now.

I can test for UIView in same way we do before triggering mod checker maybe? I doubt we'd ever want to display prompts during intro screen stage of app load.

@originalfoo originalfoo removed DO NOT MERGE YET Don't merge this PR, even if approved, until further notice adjustments required An issue require some adjustments in code labels Mar 3, 2020
@originalfoo
Copy link
Member Author

ready for review

Copy link
Collaborator

@kvakvs kvakvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pleasure to read the code :)

Copy link
Member

@krzychu124 krzychu124 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look very good 👍

Copy link
Collaborator

@kianzarrin kianzarrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@originalfoo originalfoo merged commit 81e1206 into master Mar 5, 2020
@originalfoo originalfoo deleted the prompt-helper branch March 5, 2020 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Refactor code, remove old code, improve maintainability UI User interface updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants