@@ -25,6 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525using UnityEngine . Events ;
2626using Il2CppInterop . Runtime . InteropTypes ;
2727using System . Linq . Expressions ;
28+ using System . Linq ;
29+ using System . Collections . Generic ;
2830
2931namespace ServerAdd
3032{
@@ -37,12 +39,11 @@ public static class RegionMenuOpenPatch
3739 private static GameObject isHttpsButton ;
3840 private static GameObject isDNSButton ;
3941 private static GameObject AddButton ;
40- private static GameObject ClearButton ;
42+ /* private static GameObject ClearButton; */
4143 private static GameObject ClearAllButton ;
42- private static Vector3 pos = new Vector3 ( 3f , 2f , - 100f ) ;
43- private static bool isOpen ;
44- private static ServerInfo [ ] ServerInfo ;
4544 private static IRegionInfo [ ] regions ;
45+ private static Vector3 pos = new Vector3 ( 3f , 2.5f , - 100f ) ;
46+ private static bool isOpen ;
4647 private static ServerManager serverManager = DestroyableSingleton < ServerManager > . Instance ;
4748 public static void Postfix ( RegionMenu __instance )
4849 {
@@ -165,7 +166,7 @@ void onEnterOrPortFieldChange()
165166
166167 isHttpsButton = UnityEngine . Object . Instantiate ( tf , __instance . transform ) ;
167168 isHttpsButton . name = "isHttpsButton" ;
168- isHttpsButton . transform . position = pos - new Vector3 ( 0f , 3f , 0f ) ;
169+ isHttpsButton . transform . position = pos - new Vector3 ( - 0.6f , 3f , 0f ) ;
169170
170171 var text = isHttpsButton . transform . GetChild ( 0 ) . GetComponent < TMPro . TMP_Text > ( ) ;
171172 PassiveButton isHttpsPassiveButton = isHttpsButton . GetComponent < PassiveButton > ( ) ;
@@ -191,7 +192,7 @@ void act()
191192
192193 isDNSButton = UnityEngine . Object . Instantiate ( tf , __instance . transform ) ;
193194 isDNSButton . name = "isDNSButton" ;
194- isDNSButton . transform . position = pos - new Vector3 ( 0f , 4f , 0f ) ;
195+ isDNSButton . transform . position = pos - new Vector3 ( 0.6f , 3f , 0f ) ;
195196
196197 var DNSButtontext = isDNSButton . transform . GetChild ( 0 ) . GetComponent < TMPro . TMP_Text > ( ) ;
197198 PassiveButton isDNSPassiveButton = isDNSButton . GetComponent < PassiveButton > ( ) ;
@@ -219,36 +220,150 @@ void DNSact()
219220 size . x *= 2.5f ;
220221 background . size = size ;
221222 popup . TextAreaTMP . fontSizeMin = 2 ;
222- popup . Show ( "Your version cannot connect to the server using DnsRegionInfo \n 你的版本不支持使用DNS方式连接 " ) ;
223+ popup . Show ( "你的版本不支持使用DNS方式连接 " ) ;
223224 }
224225 else { ServerAdd . isDNS . Value = ! ServerAdd . isDNS . Value ; }
225226 isDNSButton . UpdateButtonColor ( ServerAdd . isDNS . Value ) ;
226227 }
227228 }
228229
229- if ( isHttpsButton . transform . position != pos - new Vector3 ( 0f , 3f , 0f ) ) isHttpsButton . transform . position = pos - new Vector3 ( 0f , 3f , 0f ) ;
230+ if ( AddButton == null || AddButton . gameObject == null )
231+ {
232+ GameObject tf = GameObject . Find ( "NormalMenu/BackButton" ) ;
233+
234+ AddButton = UnityEngine . Object . Instantiate ( tf , __instance . transform ) ;
235+ AddButton . name = "AddButton" ;
236+ AddButton . transform . position = pos - new Vector3 ( - 0.6f , 4f , 0f ) ;
237+
238+ var AddButtontext = AddButton . transform . GetChild ( 0 ) . GetComponent < TMPro . TMP_Text > ( ) ;
239+ PassiveButton AddButtonPassiveButton = AddButton . GetComponent < PassiveButton > ( ) ;
240+ SpriteRenderer AddButtonButtonSprite = AddButton . GetComponent < SpriteRenderer > ( ) ;
241+ AddButtonPassiveButton . OnClick = new ( ) ;
242+ AddButtonPassiveButton . OnClick . AddListener ( ( UnityAction ) AddButtonVoid ) ;
243+ AddButtontext . SetText ( "添加" ) ;
244+ __instance . StartCoroutine ( Effects . Lerp ( 0.01f , new Action < float > ( ( p ) => AddButtontext . SetText ( "添加" ) ) ) ) ;
245+ AddButton . gameObject . SetActive ( isOpen ) ;
246+
247+ void AddButtonVoid ( )
248+ {
249+ AddRegionInfo ( ) ;
250+ UpdateRegionInfo ( ) ;
251+ }
252+ }
253+
254+ /* if (ClearButton == null || ClearButton.gameObject == null)
255+ {
256+ GameObject tf = GameObject.Find("NormalMenu/BackButton");
257+
258+ ClearButton = UnityEngine.Object.Instantiate(tf, __instance.transform);
259+ ClearButton.name = "ClearButton";
260+ ClearButton.transform.position = pos - new Vector3(0.5f, 4f, 0f);
261+
262+ var ClearButtontext = ClearButton.transform.GetChild(0).GetComponent<TMPro.TMP_Text>();
263+ PassiveButton ClearButtonPassiveButton = ClearButton.GetComponent<PassiveButton>();
264+ SpriteRenderer ClearButtonButtonSprite = ClearButton.GetComponent<SpriteRenderer>();
265+ ClearButtonPassiveButton.OnClick = new();
266+ ClearButtonPassiveButton.OnClick.AddListener((UnityAction)ClearButtonVoid);
267+ ClearButtontext.SetText("Clear");
268+ __instance.StartCoroutine(Effects.Lerp(0.01f, new Action<float>((p) => ClearButtontext.SetText("Clear"))));
269+ ClearButton.gameObject.SetActive(isOpen);
270+
271+ void ClearButtonVoid()
272+ {
273+ ClearRegionInfo();
274+ }
275+ } */
276+
277+ if ( ClearAllButton == null || ClearAllButton . gameObject == null )
278+ {
279+ GameObject tf = GameObject . Find ( "NormalMenu/BackButton" ) ;
280+
281+ ClearAllButton = UnityEngine . Object . Instantiate ( tf , __instance . transform ) ;
282+ ClearAllButton . name = "ClearAllButton" ;
283+ ClearAllButton . transform . position = pos - new Vector3 ( 0.6f , 4f , 0f ) ;
284+
285+ var ClearAllButtontext = ClearAllButton . transform . GetChild ( 0 ) . GetComponent < TMPro . TMP_Text > ( ) ;
286+ PassiveButton ClearAllButtonPassiveButton = ClearAllButton . GetComponent < PassiveButton > ( ) ;
287+ SpriteRenderer ClearAllButtonButtonSprite = ClearAllButton . GetComponent < SpriteRenderer > ( ) ;
288+ ClearAllButtonPassiveButton . OnClick = new ( ) ;
289+ ClearAllButtonPassiveButton . OnClick . AddListener ( ( UnityAction ) ClearAllButtonVoid ) ;
290+ ClearAllButtontext . SetText ( "清除所有" ) ;
291+ __instance . StartCoroutine ( Effects . Lerp ( 0.01f , new Action < float > ( ( p ) => ClearAllButtontext . SetText ( "清除所有" ) ) ) ) ;
292+ ClearAllButton . gameObject . SetActive ( isOpen ) ;
293+
294+ void ClearAllButtonVoid ( )
295+ {
296+ serverManager . SetRegion ( ServerAdd . defaultRegions [ 0 ] ) ;
297+ serverManager . AvailableRegions = ServerAdd . defaultRegions ;
298+ serverManager . SaveServers ( ) ;
299+ }
300+ }
301+
302+ if ( isHttpsButton . transform . position != pos - new Vector3 ( - 0.6f , 3f , 0f ) ) isHttpsButton . transform . position = pos - new Vector3 ( - 0.6f , 3f , 0f ) ;
303+
304+ if ( isDNSButton . transform . position != pos - new Vector3 ( 0.6f , 3f , 0f ) ) isDNSButton . transform . position = pos - new Vector3 ( 0.6f , 3f , 0f ) ;
305+
306+ if ( AddButton . transform . position != pos - new Vector3 ( - 0.6f , 4f , 0f ) ) AddButton . transform . position = pos - new Vector3 ( - 0.6f , 4f , 0f ) ;
307+
308+ /* if (ClearButton.transform.position != pos - new Vector3(0.5f, 4f, 0f)) ClearButton.transform.position = pos - new Vector3(0.5f, 4f, 0f); */
230309
231- if ( isDNSButton . transform . position != pos - new Vector3 ( 0f , 4f , 0f ) ) isDNSButton . transform . position = pos - new Vector3 ( 0f , 4f , 0f ) ;
310+ if ( ClearAllButton . transform . position != pos - new Vector3 ( 0.6f , 4f , 0f ) ) ClearAllButton . transform . position = pos - new Vector3 ( 0.6f , 4f , 0f ) ;
232311 }
233312
234313 // This is part of the Mini.RegionInstaller, Licensed under GPLv3
235314 // file="RegionInstallPlugin.cs" company="miniduikboot">
236315
237- public static void UpdateRegions ( )
238- {
239- string serverIp = ( ServerAdd . isDNS . Value ? "" : ( ServerAdd . isHttps . Value ? "https://" : "http://" ) ) + ServerAdd . Ip . Value ;
240- ServerInfo serverInfo = new ServerInfo ( ServerAdd . ServerName . Value , serverIp , ServerAdd . Port . Value , false ) ;
241- ServerInfo = new ServerInfo [ ] { serverInfo } ;
242- }
243316
244317 public static void UpdateRegionInfo ( )
245318 {
319+ IRegionInfo currentRegion = serverManager . CurrentRegion ;
246320 foreach ( IRegionInfo region in regions )
247321 {
248- serverManager . AddOrUpdateRegion ( region ) ;
322+ if ( region != null )
323+ {
324+ if ( currentRegion != null && region . Name . Equals ( currentRegion . Name , StringComparison . OrdinalIgnoreCase ) )
325+ currentRegion = region ;
326+ serverManager . AddOrUpdateRegion ( region ) ;
327+ }
328+ }
329+
330+ // AU remembers the previous region that was set, so we need to restore it
331+ if ( currentRegion != null )
332+ {
333+ serverManager . SetRegion ( currentRegion ) ;
249334 }
250335 }
251336
337+ public static void AddRegionInfo ( )
338+ {
339+ string serverIp = ( ServerAdd . isDNS . Value ? "" : ( ServerAdd . isHttps . Value ? "https://" : "http://" ) ) + ServerAdd . Ip . Value ;
340+ if ( ! ServerAdd . isDNS . Value )
341+ {
342+ ServerInfo serverInfo = new ServerInfo ( ServerAdd . ServerName . Value , serverIp , ServerAdd . Port . Value , false ) ;
343+ ServerInfo [ ] ServerInfo = new ServerInfo [ ] { serverInfo } ;
344+ regions = new IRegionInfo [ ] { new StaticHttpRegionInfo ( ServerAdd . ServerName . Value , StringNames . NoTranslation , serverIp , ServerInfo ) . CastFast < IRegionInfo > ( ) } ;
345+ }
346+ else
347+ {
348+ regions = new IRegionInfo [ ] { new DnsRegionInfo ( serverIp , ServerAdd . ServerName . Value , StringNames . NoTranslation , serverIp , ServerAdd . Port . Value , false ) . CastFast < IRegionInfo > ( ) } ;
349+ }
350+ }
351+
352+ /* public static void ClearRegionInfo()
353+ {
354+
355+ foreach (IRegionInfo r in serverManager.AvailableRegions.ToList())
356+ {
357+ if (ServerAdd.ServerName.Value.Equals(r.Name, StringComparison.OrdinalIgnoreCase))
358+ {
359+ List<IRegionInfo> newRegions = serverManager.AvailableRegions.ToList();
360+ newRegions.Remove(r);
361+ serverManager.AvailableRegions = newRegions.ToArray();
362+ serverManager.SetRegion(ServerAdd.defaultRegions[0]);
363+ }
364+ }
365+ } */
366+
252367 public static void UpdateButtonColor ( this GameObject objet , bool open )
253368 {
254369 var objectPassiveButton = objet . GetComponent < PassiveButton > ( ) ;
0 commit comments