登录和输入控件

This commit is contained in:
2025-08-20 23:57:22 +08:00
parent 818bf63d8d
commit 2f8251fe63
28 changed files with 346 additions and 70 deletions

View File

@@ -55,6 +55,7 @@ namespace NBC.Network.Interface
{
try
{
await Run(session, (T) message);
}
catch (Exception e)

View File

@@ -274,67 +274,6 @@ namespace NBC.Network.Interface
messageHandler.Handle(session, rpcId, protocolCode, message).Coroutine();
}
// 如果编译符号FANTASY_NET存在定义处理路由消息的方法
#if FANTASY_NET
/// <summary>
/// 处理路由消息,将消息分发给相应的路由消息处理器。
/// </summary>
/// <param name="session">会话对象</param>
/// <param name="type">消息类型</param>
/// <param name="entity">实体对象</param>
/// <param name="message">消息对象</param>
/// <param name="rpcId">RPC标识</param>
public async FTask RouteMessageHandler(Session session, Type type, Entity entity, object message, uint rpcId)
{
if (!_routeMessageHandlers.TryGetValue(type, out var routeMessageHandler))
{
Log.Warning($"Scene:{session.Scene.Id} Found Unhandled RouteMessage: {message.GetType()}");
if (message is IRouteRequest request)
{
FailRouteResponse(session, request.GetType(), InnerErrorCode.ErrEntityNotFound, rpcId);
}
return;
}
var runtimeId = entity.RuntimeId;
var sessionRuntimeId = session.RuntimeId;
if (entity is Scene)
{
// 如果是Scene的话、就不要加锁了、如果加锁很一不小心就可能会造成死锁
await routeMessageHandler.Handle(session, entity, rpcId, message);
return;
}
// 使用协程锁来确保多线程安全
using (await _receiveRouteMessageLock.Wait(runtimeId))
{
if (sessionRuntimeId != session.RuntimeId)
{
return;
}
if (runtimeId != entity.RuntimeId)
{
if (message is IRouteRequest request)
{
FailRouteResponse(session, request.GetType(), InnerErrorCode.ErrEntityNotFound, rpcId);
}
return;
}
await routeMessageHandler.Handle(session, entity, rpcId, message);
}
}
internal bool GetCustomRouteType(long protocolCode, out int routeType)
{
return _customRouteMap.TryGetValue(protocolCode, out routeType);
}
#endif
internal void FailRouteResponse(Session session, Type requestType, uint error, uint rpcId)
{
var response = CreateRouteResponse(requestType, error);

75
Assets/Scripts/Net/Net.cs Normal file
View File

@@ -0,0 +1,75 @@
using Assets.Scripts.Entity;
using Assets.Scripts.Hotfix;
using NBC;
using NBC.Network;
using NBC.Network.Interface;
namespace NBF
{
public class Net : EventDispatcher
{
public static Session Session { get; private set; }
public const int HeartbeatInterval = 5000;
#region
private static Net _inst;
public static Net Inst => _inst ??= new Net();
public Net()
{
}
#endregion
#region
public static Session CreateSession(string address)
{
var session = SessionHelper.CreateSession(App.Main, address, OnConnectComplete,
OnConnectFail,
OnConnectDisconnect);
Session = session;
return session;
}
private static void OnConnectComplete()
{
Log.Debug("连接成功");
Session.AddComponent<SessionHeartbeatComponent>().Start(HeartbeatInterval);
}
private static void OnConnectFail()
{
Log.Debug("连接失败");
// SetLoginState(false);
}
private static void OnConnectDisconnect()
{
Log.Debug("连接断开");
// SetLoginState(false);
}
#endregion
#region
public static FTask<IResponse> Call(IRequest request, long routeId = 0)
{
// var response = await Session.Call(request, routeId);
// response.DispatchMessage();
return Session.Call(request, routeId);;
}
public static void Send(IMessage message, uint rpcId = 0, long routeId = 0)
{
Session.Send(message, rpcId, routeId);
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1fe56eeffd614eaea7055d1c65f6859f
timeCreated: 1755701226

View File

@@ -0,0 +1,12 @@
using NBC.Network.Interface;
namespace NBF
{
public static class NetExtends
{
public static void DispatchMessage(this IResponse response)
{
Net.Inst.DispatchEventWith(response.OpCode().ToString(), response);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 25d56f7c87744a199e926365a516b85f
timeCreated: 1755702255

View File

@@ -132,9 +132,11 @@ namespace NBF
// UI.Inst.OpenUI<FishingShopPanel>();
LoadData();
CommonTopPanel.Show();
LoginPanel.Show();
// FishingPanel.Show();
PreviewPanel.Show();
Fishing.Inst.Go(1);
// PreviewPanel.Show();
// Fishing.Inst.Go(1);
// HomePanel.Show();
// ChatTestPanel.Show();

View File

@@ -12,6 +12,7 @@ namespace NBF
UIObjectFactory.SetPackageItemExtension(SelectPages.URL, typeof(SelectPages));
UIObjectFactory.SetPackageItemExtension(ModelTexture.URL, typeof(ModelTexture));
UIObjectFactory.SetPackageItemExtension(BottomMenu.URL, typeof(BottomMenu));
UIObjectFactory.SetPackageItemExtension(CommonInput.URL, typeof(CommonInput));
UIObjectFactory.SetPackageItemExtension(ClassifyList.URL, typeof(ClassifyList));
UIObjectFactory.SetPackageItemExtension(CommonMenu.URL, typeof(CommonMenu));
UIObjectFactory.SetPackageItemExtension(MarqueeTag.URL, typeof(MarqueeTag));

View File

@@ -0,0 +1,29 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
namespace NBF
{
public partial class CommonInput
{
public const string URL = "ui://6hgkvlau9zboma";
public Controller FocusState;
public GTextInput Input;
public GImage bottomBack;
public override void ConstructFromXML(XML xml)
{
base.ConstructFromXML(xml);
FocusState = GetController("FocusState");
Input = (GTextInput)GetChild("Input");
bottomBack = (GImage)GetChild("bottomBack");
OnInited();
UILanguage.TrySetComponentLanguage(this);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fb776407f4f25e64a8e803ba135bddef

View File

@@ -0,0 +1,47 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using UnityEngine;
using FairyGUI;
using NBC;
namespace NBF
{
public partial class CommonInput : GComponent
{
public EventListener onChanged => Input.onChanged;
public override string text
{
get => Input.text;
set => Input.text = value;
}
public string title
{
get => text;
set => text = value;
}
public string promptText
{
get => Input.promptText;
set => Input.promptText = value;
}
private void OnInited()
{
onFocusIn.Add(OnInputFocusIn);
onFocusOut.Add(OnInputFocusOut);
}
private void OnInputFocusIn()
{
FocusState.selectedIndex = 1;
}
private void OnInputFocusOut()
{
FocusState.selectedIndex = 0;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c7adc7972d1d401489dc796fb27d1eaa

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 12482424a8714a5fb52ce23312a0a0f6
timeCreated: 1755697902

View File

@@ -0,0 +1,54 @@
using Assets.Scripts.Entity;
using Assets.Scripts.Hotfix;
using NBC;
using NBC.Network;
namespace NBF
{
public static class LoginHelper
{
private static Session _session;
public static async FTask Login(string account)
{
_session = Net.CreateSession("127.0.0.1:20001");
var acc = account;
// 发送登录的请求给服务器
var response = (A2C_LoginResponse)await Net.Call(new C2A_LoginRequest()
{
Username = acc,
Password = acc,
LoginType = 1
});
if (response.ErrorCode != 0)
{
Log.Error($"登录发生错误{response.ErrorCode}");
return;
}
if (!App.Main.GetComponent<JWTParseComponent>().Parse(response.ToKen, out var payload))
{
return;
}
// 根据ToKen返回的Address登录到Gate服务器
_session = Net.CreateSession(payload.Address);
// 发送登录请求到Gate服务器
var loginResponse = (G2C_LoginResponse)await Net.Call(new C2G_LoginRequest()
{
ToKen = response.ToKen
});
if (loginResponse.ErrorCode != 0)
{
Log.Error($"登录发生错误{loginResponse.ErrorCode}");
return;
}
Log.Debug($"登录到Gate服务器成功ErrorCode:{loginResponse.ErrorCode}");
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 031ed023449844cdb9d6c4eb5d7fee90
timeCreated: 1755698636

View File

@@ -0,0 +1,32 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
using System.Collections.Generic;
namespace NBF
{
/// <summary> </summary>
public partial class LoginPanel
{
public GObject this[string aKey] => ContentPane.GetChild(aKey);
public override string UIPackName => "Main";
public override string UIResName => "LoginPanel";
[AutoFind(Name = "Back")]
public GLabel Back;
[AutoFind(Name = "InputAccount")]
public CommonInput InputAccount;
[AutoFind(Name = "BtnLogin")]
public GButton BtnLogin;
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
public static void Show(object param = null){ App.UI.OpenUI<LoginPanel>(param); }
public static void Hide(){ App.UI.HideUI<LoginPanel>(); }
public static void Del(){ App.UI.DestroyUI<LoginPanel>(); }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3b11ed3a4a10a3549a06d7845c9c4cfd

View File

@@ -0,0 +1,25 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using FairyGUI;
using UnityEngine;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class LoginPanel : UIPanel
{
protected override void OnInit()
{
this.AutoAddClick(OnClick);
}
private void OnClick(GComponent btn)
{
if (btn == BtnLogin)
{
LoginHelper.Login(InputAccount.text).Coroutine();
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b2d32e54ef5680541959b782ee8d0c7a

View File

@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<component size="221,66" extention="Button">
<controller name="button" pages="2,up,3,down,4,over,5,selectedOver" selected="0"/>
<component size="120,35" extention="Button">
<controller name="button" pages="2,up,3,down,6,over,7,selectedOver" selected="0"/>
<displayList>
<graph id="n6_isq9" name="n6" xy="0,0" size="221,66" type="rect" fillColor="#ffcccccc"/>
<text id="n7_isq9" name="title" xy="3,8" size="214,49" fontSize="36" align="center" vAlign="middle" text="1111111111">
<relation target="" sidePair="center-center"/>
<image id="n19_fcfg" name="n19" src="kryob" fileName="Images/Square.png" xy="0,0" size="120,35" alpha="0.2" color="#5c748b">
<gearLook controller="button" pages="6" values="0.1,0,0,0" default="0.2,0,0,0"/>
<gearColor controller="button" pages="3,6" values="#8bf3ff|#8bf3ff" default="#5c748b"/>
<relation target="" sidePair="width-width,height-height"/>
</image>
<text id="n21_9zbo" name="title" xy="0,0" size="120,35" font="ui://6hgkvlaugkm7w" fontSize="22" color="#d8fbff" align="center" vAlign="middle" autoSize="none" text="标题">
<relation target="" sidePair="width-width,height-height"/>
</text>
</displayList>
<Button downEffect="dark" downEffectValue=".8"/>
<Button/>
</component>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<component size="142,35">
<controller name="FocusState" pages="0,失去焦点,1,焦点" selected="0"/>
<displayList>
<image id="n34_9zbo" name="n34" src="r03ui6" fileName="Images/Panels/BasicPanel.png" xy="0,0" size="142,35" alpha="0.3" color="#5c748b">
<relation target="" sidePair="width-width,height-height"/>
</image>
<text id="n37_9zbo" name="Input" xy="2,1" size="138,34" alpha="0.7" fontSize="22" color="#ffffff" autoSize="none" text="" input="true">
<relation target="" sidePair="width-width,height-height"/>
</text>
<image id="n35_9zbo" name="bottomBack" src="kryob" fileName="Images/Square.png" xy="0,33" size="142,2" alpha="0.5" color="#5c748b">
<gearColor controller="FocusState" pages="0" values="#5c748b" default="#8bf3ff"/>
<relation target="" sidePair="width-width,center-center,bottom-bottom"/>
</image>
</displayList>
</component>

View File

@@ -4,7 +4,6 @@
<component id="ips61" name="MessageBox.xml" path="/Panel/" exported="true"/>
<component id="isq98" name="LoadingProgress.xml" path="/Com/Progress/" exported="true"/>
<component id="isq99" name="ProgressBar.xml" path="/Com/"/>
<component id="isq9a" name="BtnCommon.xml" path="/Com/Buttons/" exported="true"/>
<image id="kryob" name="Square.png" path="/Images/" exported="true" scale="9grid" scale9grid="1,1,1,0"/>
<component id="kryoc" name="GreenProgress.xml" path="/Com/Progress/" exported="true"/>
<component id="sqnkd" name="GMPanel.xml" path="/Panel/" exported="true"/>
@@ -221,6 +220,8 @@
<component id="5dtx19" name="SelectPageItem.xml" path="/Com/"/>
<component id="5dtx1a" name="SelectPages.xml" path="/Com/" exported="true"/>
<component id="5dtxm9" name="ModelTexture.xml" path="/Com/" exported="true"/>
<component id="9zboma" name="CommonInput.xml" path="/Com/Inputs/" exported="true"/>
<component id="9zbomb" name="BtnCommon.xml" path="/Com/Buttons/" exported="true"/>
</resources>
<publish name="" path="../Assets/Resources/Fgui/Common" packageCount="2" genCode="true"/>
</packageDescription>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<component size="1920,1080" designImage="ui://hxr7rc7pnmzbd" designImageAlpha="0">
<displayList>
<component id="n33_gii7" name="Back" src="8hy8la" fileName="Com/Back/Back1.xml" pkg="6hgkvlau" xy="0,0">
<relation target="" sidePair="width-width,height-height"/>
</component>
<component id="n36_9zbo" name="InputAccount" src="9zboma" fileName="Com/Inputs/CommonInput.xml" pkg="6hgkvlau" xy="817,480" size="285,35">
<relation target="" sidePair="center-center,middle-middle"/>
</component>
<component id="n39_9zbo" name="BtnLogin" src="9zbomb" fileName="Com/Buttons/BtnCommon.xml" pkg="6hgkvlau" xy="817,522" size="285,35">
<relation target="" sidePair="center-center,middle-middle"/>
<Button title="登录"/>
</component>
</displayList>
</component>

View File

@@ -48,6 +48,7 @@
<component id="5dtx1d" name="InputWaitingCom.xml" path="/" exported="true"/>
<component id="n5ne1e" name="ChatTestPanel.xml" path="/" exported="true"/>
<component id="n5ne1f" name="ChatItem.xml" path="/" exported="true"/>
<component id="9zbo1g" name="LoginPanel.xml" path="/" exported="true"/>
</resources>
<publish name="" path="../Assets/Resources/Fgui/Main" packageCount="2" genCode="true"/>
</packageDescription>

View File

@@ -0,0 +1 @@
{"url":"ui://6hgkvlau9zboma","name":"CommonInput","scriptType":"component","isCustomName":false,"customName":"","annotation":"","member":{}}

View File

@@ -0,0 +1 @@
{"url":"ui://hxr7rc7p9zbo1g","name":"LoginPanel","scriptType":"panel","isCustomName":false,"customName":"","annotation":"","member":{}}