Interface IViewManager
- Namespace
- BSGameLib.UI
- Assembly
- BSGameLib.UI.dll
Shows, replaces and removes the views on screen, and holds the UI's scale and button sound.
public interface IViewManager : IRunOnInitialization
- Inherited Members
Properties
ActiveView
The view on top: the last of Views. Null when nothing is showing.
View ActiveView { get; }
Property Value
HoverUnderPointer
This frame, the HoverKey of the innermost control under the pointer that has one, and
its view: in the front panel under it, or over no panel, the active view. Null when there is
none. What a game asks to say something about what the pointer rests on, as a tooltip.
ViewHover HoverUnderPointer { get; }
Property Value
PanelItemUnderPointer
This frame, the item of the repeater row the pointer is over in the front panel under it, or null: what a game asks to act on a row with a key rather than a button, such as putting it on a key.
object PanelItemUnderPointer { get; }
Property Value
Panels
The panels up, back first.
IReadOnlyList<View> Panels { get; }
Property Value
PanelsWantKeyboard
This frame, a panel's text box is being typed in: the keyboard is not the game's.
bool PanelsWantKeyboard { get; }
Property Value
PanelsWantMouse
This frame, the pointer is over a panel, or a press begun on one is still held: the mouse is not the game's.
bool PanelsWantMouse { get; }
Property Value
UIScale
How large the UI is built. The UI is laid out in the window's real pixels, so at 1 a menu is the same size on screen however large the window is; this makes it larger or smaller from there, by multiplying every size and font size a view declares rather than by stretching the picture. Clamped to 0.5-4. Setting it rebuilds what is on screen, and it may be set before the first view is.
float UIScale { get; set; }
Property Value
Views
Every view on screen, bottom first: whatever was set, then anything pushed over it. ActiveView is the last. Empty when nothing is showing.
IReadOnlyList<View> Views { get; }
Property Value
Methods
ClearView()
Disposes the active view and any dialogs under it, leaving nothing showing.
void ClearView()
ClosePanel(ViewModel)
Closes and disposes the panel showing viewModel, if one is.
void ClosePanel(ViewModel viewModel)
Parameters
viewModelViewModel
PopView()
Disposes the current view and reactivates whatever PushView<TViewModel>() suspended beneath it, if anything. A no-op if there's nothing to pop back to.
void PopView()
PrewarmView<TViewModel>()
Builds a view model's view and runs its LoadContent (font/texture loads) now, without activating it - ActiveView is untouched, ClearView()/SetView() elsewhere are unaffected. Returns the built view so the caller can also Update()+Draw() it (into a target that's never composited to screen) before disposing it - LoadContent alone is cheap; the real one-time cost is the first actual Draw() call (lazy GPU pipeline/shader setup for nine-patch and text rendering), and only drawing pays that. Call the whole sequence while something else already opaque is on screen (a splash, a loading screen) so the cost a later SetView<TViewModel>() call would otherwise pay - visibly, mid-transition - is already paid for by the time that call happens. Returns null if the view model didn't produce a view.
View PrewarmView<TViewModel>() where TViewModel : ViewModel, IViewModel
Returns
Type Parameters
TViewModel
PushView(ViewModel)
Builds the view of a view model that already exists and pushes it over what is active, as PushView<TViewModel>() does for one made by type.
void PushView(ViewModel viewModel)
Parameters
viewModelViewModel
PushView<TViewModel>()
Pushes a view as a dialog/overlay on top of whatever is currently active. The suspended view underneath keeps rendering (dimmed) but stops receiving Update()/input/ITickableViewModel.Tick() until PopView() brings it back. Use this instead of SetView<TViewModel>() for anything meant to return to what was open before it, rather than replace it outright.
void PushView<TViewModel>() where TViewModel : ViewModel, IViewModel
Type Parameters
TViewModel
ReloadActiveView()
Rebuilds what is currently on screen from its view files, in place. Every view in the stack is rebuilt - the active one and anything PushView<TViewModel>() suspended beneath it - keeping the order and which one is on top, and reusing the existing view model instances, so entered text and any other view-model state survive. A no-op when nothing is shown.
void ReloadActiveView()
Remarks
This exists because a view resolves every {Resource id} once, while it is being
built: there is no per-frame style pass, so changing
SetVariant(string) has no effect on anything already drawn. Pair
the two to switch theme without navigating away. Control state that lives on the
controls rather than the view model - which control had focus, a scroll position - is
not carried across, because the replacements are different control instances.
SetButtonClickSound(string)
Sets the sound played when a button is clicked. Null for no sound. It may be set before the first view is.
void SetButtonClickSound(string soundId)
Parameters
soundIdstring
SetView(View)
Makes view the active view. It replaces the previous view and any dialogs
pushed over it.
void SetView(View view)
Parameters
viewView
SetView(ViewModel)
Builds the view of a view model that already exists, and makes it the whole screen: for one made per window rather than registered by type, as a DataViewModel is.
void SetView(ViewModel viewModel)
Parameters
viewModelViewModel
SetViewModelFactoryProvider(IViewModelFactoryProvider)
Sets the provider the view-models are created with.
void SetViewModelFactoryProvider(IViewModelFactoryProvider provider)
Parameters
providerIViewModelFactoryProvider
SetView<TViewModel>()
Creates the view-model TViewModel and its view, and makes the view active. It replaces the
previous view and any dialogs pushed over it.
void SetView<TViewModel>() where TViewModel : ViewModel, IViewModel
Type Parameters
TViewModel
ShowPanel(ViewModel)
Shows viewModel's view as a panel: drawn over whatever is on screen --
the views, or a game screen that draws itself with no view up -- without suspending
anything. Several may be up at once; a click brings one to the front. It takes the mouse
only over its own controls and backgrounds, and the keyboard only while one of its text
boxes is being typed in, so the game under it goes on: ask PanelsWantMouse and
PanelsWantKeyboard before acting on input. Closed only by ClosePanel(ViewModel).
void ShowPanel(ViewModel viewModel)
Parameters
viewModelViewModel