1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Threading . Tasks ;
4+ using UnityEngine ;
5+
6+ // ReSharper disable CheckNamespace
7+
8+ namespace GameLovers . UiService
9+ {
10+ /// <summary>
11+ /// This service provides an abstraction layer to interact with the game's <seealso cref="UiPresenter"/>
12+ /// The Ui Service is organized by layers. The higher the layer the more close is to the camera viewport
13+ /// </summary>
14+ public interface IUiService
15+ {
16+ /// <summary>
17+ /// Requests the <see cref="Canvas"/> of the given <paramref name="layer"/>
18+ /// </summary>
19+ Canvas GetLayer ( int layer ) ;
20+
21+ /// <summary>
22+ /// Adds the given UI <paramref name="config"/> to the service
23+ /// </summary>
24+ /// <exception cref="ArgumentException">
25+ /// Thrown if the service already contains the given <paramref name="config"/>
26+ /// </exception>
27+ void AddUiConfig ( UiConfig config ) ;
28+
29+ /// <summary>
30+ /// Adds the given <paramref name="uiPresenter"/> to the service and to be included inside the given <paramref name="layer"/>.
31+ /// If the given <paramref name="openAfter"/> is true, will open the <see cref="UiPresenter"/> after adding it to the service
32+ /// </summary>
33+ /// <exception cref="ArgumentException">
34+ /// Thrown if the service already contains the given <paramref name="uiPresenter"/>
35+ /// </exception>
36+ void AddUi < T > ( T uiPresenter , int layer , bool openAfter = false ) where T : UiPresenter ;
37+
38+ /// <summary>
39+ /// Removes and returns the UI of the given type <typeparamref name="T"/> without unloading it from the service
40+ /// </summary>
41+ /// <exception cref="KeyNotFoundException">
42+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given type <typeparamref name="T"/>
43+ /// </exception>
44+ T RemoveUi < T > ( ) where T : UiPresenter ;
45+
46+ /// <summary>
47+ /// Removes and returns the UI of the given <paramref name="type"/> without unloading it from the service
48+ /// </summary>
49+ /// <exception cref="KeyNotFoundException">
50+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <paramref name="type"/>
51+ /// </exception>
52+ UiPresenter RemoveUi ( Type type ) ;
53+
54+ /// <summary>
55+ /// Removes and returns the given <paramref name="uiPresenter"/> without unloading it from the service
56+ /// </summary>
57+ /// <exception cref="KeyNotFoundException">
58+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/>
59+ /// </exception>
60+ T RemoveUi < T > ( T uiPresenter ) where T : UiPresenter ;
61+
62+ /// <summary>
63+ /// Loads an UI asynchronously with the given <typeparamref name="T"/>.
64+ /// This method can be controlled in an async method and returns the UI loaded.
65+ /// If the given <paramref name="openAfter"/> is true, will open the <see cref="UiPresenter"/> after loading
66+ /// </summary>
67+ /// <exception cref="KeyNotFoundException">
68+ /// Thrown if the service does NOT contain a <see cref="UiConfig"/> of the given type <typeparamref name="T"/>.
69+ /// You need to call <seealso cref="AddUiConfig"/> or <seealso cref="AddUi{T}"/> or initialize the service first
70+ /// </exception>
71+ Task < T > LoadUiAsync < T > ( bool openAfter = false ) where T : UiPresenter ;
72+
73+ /// <summary>
74+ /// Loads an UI asynchronously with the given <paramref name="type"/>.
75+ /// This method can be controlled in an async method and returns the UI loaded.
76+ /// If the given <paramref name="openAfter"/> is true, will open the <see cref="UiPresenter"/> after loading
77+ /// </summary>
78+ /// <exception cref="KeyNotFoundException">
79+ /// Thrown if the service does NOT contain a <see cref="UiConfig"/> of the given <paramref name="type"/>
80+ /// You need to call <seealso cref="AddUiConfig"/> or <seealso cref="AddUi{T}"/> or initialize the service first
81+ /// </exception>
82+ Task < UiPresenter > LoadUiAsync ( Type type , bool openAfter = false ) ;
83+
84+ /// <summary>
85+ /// Unloads the UI of the given type <typeparamref name="T"/>
86+ /// </summary>
87+ /// <exception cref="KeyNotFoundException">
88+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given type <typeparamref name="T"/>
89+ /// </exception>
90+ void UnloadUi < T > ( ) where T : UiPresenter ;
91+
92+ /// <summary>
93+ /// Unloads the UI of the given <paramref name="type"/>
94+ /// </summary>
95+ /// <exception cref="KeyNotFoundException">
96+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <paramref name="type"/>
97+ /// </exception>
98+ void UnloadUi ( Type type ) ;
99+
100+ /// <summary>
101+ /// Unloads the UI of the given <paramref name="uiPresenter"/>
102+ /// </summary>
103+ /// <exception cref="KeyNotFoundException">
104+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <paramref name="type"/>
105+ /// </exception>
106+ void UnloadUi < T > ( T uiPresenter ) where T : UiPresenter ;
107+
108+ /// <summary>
109+ /// Checks if the service contains <seealso cref="UiPresenter"/> of the given <typeparamref name="T"/>
110+ /// </summary>
111+ bool HasUiPresenter < T > ( ) where T : UiPresenter ;
112+
113+ /// <summary>
114+ /// Checks if the service contains <seealso cref="UiPresenter"/> of the given <paramref name="type"/> is loaded or not
115+ /// </summary>
116+ bool HasUiPresenter ( Type type ) ;
117+
118+ /// <summary>
119+ /// Requests the UI of given type <typeparamref name="T"/>
120+ /// </summary>
121+ /// <exception cref="KeyNotFoundException">
122+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <typeparamref name="T"/>
123+ /// </exception>
124+ T GetUi < T > ( ) where T : UiPresenter ;
125+
126+ /// <summary>
127+ /// Requests the UI of given <paramref name="type"/>
128+ /// </summary>
129+ /// <exception cref="KeyNotFoundException">
130+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <paramref name="type"/>
131+ /// </exception>
132+ UiPresenter GetUi ( Type type ) ;
133+
134+ /// <summary>
135+ /// Requests the list all the visible UIs' <seealso cref="Type"/> on the screen
136+ /// </summary>
137+ List < Type > GetAllVisibleUi ( ) ;
138+
139+ /// <summary>
140+ /// Opens and returns the UI of given type <typeparamref name="T"/>
141+ /// </summary>
142+ /// <exception cref="KeyNotFoundException">
143+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <typeparamref name="T"/>
144+ /// </exception>
145+ T OpenUi < T > ( ) where T : UiPresenter ;
146+
147+ /// <summary>
148+ /// Opens and returns the UI of given <paramref name="type"/>
149+ /// </summary>
150+ /// <exception cref="KeyNotFoundException">
151+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <paramref name="type"/>
152+ /// </exception>
153+ UiPresenter OpenUi ( Type type ) ;
154+
155+ ///<inheritdoc cref="OpenUi{T}()"/>
156+ /// <remarks>
157+ /// It sets the given <paramref name="initialData"/> data BEFORE opening the UI
158+ /// </remarks>
159+ T OpenUi < T , TData > ( TData initialData )
160+ where T : class , IUiPresenterData
161+ where TData : struct ;
162+
163+ ///<inheritdoc cref="OpenUi(Type)"/>
164+ /// <exception cref="ArgumentException">
165+ /// Thrown if the the given <paramref name="type"/> is not of inhereting from <see cref="UiPresenterData{T}"/> class
166+ /// </exception>
167+ /// <remarks>
168+ /// It sets the given <paramref name="initialData"/> data BEFORE opening the UI
169+ /// </remarks>
170+ UiPresenter OpenUi < TData > ( Type type , TData initialData ) where TData : struct ;
171+
172+ /// <summary>
173+ /// Closes and returns the UI of given type <typeparamref name="T"/>
174+ /// </summary>
175+ /// <exception cref="KeyNotFoundException">
176+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given type <typeparamref name="T"/>
177+ /// </exception>
178+ T CloseUi < T > ( ) where T : UiPresenter ;
179+
180+ /// <summary>
181+ /// Closes and returns the UI of given <paramref name="type"/>
182+ /// </summary>
183+ /// <exception cref="KeyNotFoundException">
184+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given <paramref name="type"/>
185+ /// </exception>
186+ UiPresenter CloseUi ( Type type ) ;
187+
188+ /// <summary>
189+ /// Closes and returns the same given <paramref name="uiPresenter"/>
190+ /// </summary>
191+ /// <exception cref="KeyNotFoundException">
192+ /// Thrown if the service does NOT contain the given <paramref name="uiPresenter"/>
193+ /// </exception>
194+ T CloseUi < T > ( T uiPresenter ) where T : UiPresenter ;
195+
196+ /// <summary>
197+ /// Closes all the visible <seealso cref="UiPresenter"/>
198+ /// </summary>
199+ void CloseAllUi ( ) ;
200+
201+ /// <summary>
202+ /// Closes all the visible <seealso cref="UiPresenter"/> in the given <paramref name="layer"/>
203+ /// </summary>
204+ void CloseAllUi ( int layer ) ;
205+
206+ /// <summary>
207+ /// Closes all the visible <seealso cref="UiPresenter"/> in front or in the same layer of the given type <typeparamref name="T"/>
208+ /// It excludes any visible <seealso cref="UiPresenter"/> present in layers of the given <paramref name="excludeLayers"/>
209+ /// </summary>
210+ /// <exception cref="KeyNotFoundException">
211+ /// Thrown if the service does NOT contain an <see cref="UiPresenter"/> of the given type <typeparamref name="T"/>
212+ /// </exception>
213+ void CloseUiAndAllInFront < T > ( params int [ ] excludeLayers ) where T : UiPresenter ;
214+
215+ /// <summary>
216+ /// Adds the given <paramref name="uiSet"/> to the service
217+ /// </summary>
218+ /// <exception cref="ArgumentException">
219+ /// Thrown if the service already contains the given <paramref name="uiSet"/>
220+ /// </exception>
221+ void AddUiSet ( UiSetConfig uiSet ) ;
222+
223+ /// <summary>
224+ /// Removes and returns all the <see cref="UiPresenter"/> from given <paramref name="setId "/> that are still present in the service
225+ /// </summary>
226+ /// <exception cref="KeyNotFoundException">
227+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
228+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
229+ /// </exception>
230+ List < UiPresenter > RemoveUiPresentersFromSet ( int setId ) ;
231+
232+ /// <summary>
233+ /// Loads asynchronously all the <see cref="UiPresenter"/> from given <paramref name="setId "/> and have not yet been loaded.
234+ /// This method can be controlled in an async method and returns every UI when completes loaded.
235+ /// This method can be controlled in a foreach loop and it will return the UIs in a first-load-first-return scheme
236+ /// </summary>
237+ /// <exception cref="KeyNotFoundException">
238+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
239+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
240+ /// </exception>
241+ Task < Task < UiPresenter > > [ ] LoadUiSetAsync ( int setId ) ;
242+
243+ /// <summary>
244+ /// Unloads all the <see cref="UiPresenter"/> from given <paramref name="setId "/> that are still present in the service
245+ /// </summary>
246+ /// <exception cref="KeyNotFoundException">
247+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
248+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
249+ /// </exception>
250+ void UnloadUiSet ( int setId ) ;
251+
252+ /// <summary>
253+ /// Checks if the service contains or not the <seealso cref="UiSetConfig"/> of the given <paramref name="setId"/>
254+ /// </summary>
255+ bool HasUiSet ( int setId ) ;
256+
257+ /// <summary>
258+ /// Checks if the service containers all the <seealso cref="UiPresenter"/> belonging in the given <paramref name="setId"/>
259+ /// </summary>
260+ /// <exception cref="KeyNotFoundException">
261+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
262+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
263+ /// </exception>
264+ bool HasAllUiPresentersInSet ( int setId ) ;
265+
266+ /// <summary>
267+ /// Requests the <seealso cref="UiSetConfig"/> of given type <paramref name="setId"/>
268+ /// </summary>
269+ /// <exception cref="KeyNotFoundException">
270+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
271+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
272+ /// </exception>
273+ UiSetConfig GetUiSet ( int setId ) ;
274+
275+ /// <summary>
276+ /// Opens all the <seealso cref="UiPresenter"/> that are part of the given <paramref name="setId"/>
277+ /// If the given <paramref name="closeVisibleUi"/> is set to true, will close the currently open <seealso cref="UiPresenter"/>
278+ /// that are not part of the given <paramref name="setId"/>
279+ /// </summary>
280+ /// <exception cref="KeyNotFoundException">
281+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
282+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
283+ /// </exception>
284+ void OpenUiSet ( int setId , bool closeVisibleUi ) ;
285+
286+ /// <summary>
287+ /// Closes all the <seealso cref="UiPresenter"/> that are part of the given <paramref name="setId"/>
288+ /// </summary>
289+ /// <exception cref="KeyNotFoundException">
290+ /// Thrown if the service does NOT contain an <see cref="UiSetConfig"/> with the given <paramref name="setId"/>.
291+ /// You need to add it first by calling <seealso cref="AddUiSet"/>
292+ /// </exception>
293+ void CloseUiSet ( int setId ) ;
294+ }
295+ }
0 commit comments