Merge pull request 'Add base UI manger and dlg manager' (#57) from feature/hp_interact_npc into develop

Reviewed-on: https://git.brew.monster/Unity/perfect-world-unity/pulls/57
This commit is contained in:
tungdv
2025-11-18 07:15:54 +00:00
7 changed files with 718 additions and 330 deletions
@@ -0,0 +1,258 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace BrewMonster.UI
{
public class AUIManager
{
protected DialogScriptTableObject m_dialogResouce;
protected Canvas m_canvas;
protected Dictionary<int, string> m_StringTable = new Dictionary<int, string>();
protected Dictionary<int, string> m_auiDialog_stringTable = new Dictionary<int, string>();
public string GetStringFromTable(int idString)
{
if (m_StringTable.TryGetValue(idString, out var str))
return str;
return null;
}
public string GetStringFromAuiDialogTable(int idString)
{
if (m_auiDialog_stringTable.TryGetValue(idString, out var str))
return str;
return null;
}
public void SetDependency(DialogScriptTableObject resouce, Canvas canvas)
{
m_dialogResouce = resouce;
m_canvas = canvas;
}
public void Init()
{
ImportStringTable("ingame.stf");
ImportAuiDialogStringTable("msgbox.stf");
}
public string Translate(ushort[] str)
{
if (str == null || str.Length == 0)
return null;
string m_AWString = "";
string input = new string(str.Where(c => c != 0).Select(c => (char)c).ToArray());
m_AWString = input;
var result = new System.Text.StringBuilder();
int i = 0;
while (i < input.Length)
{
char c = input[i];
if (c != '\\')
{
result.Append(c);
i++;
continue;
}
i++;
if (i >= input.Length)
break;
char next = input[i];
switch (next)
{
case '\n':
i++;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int value = 0;
int count = 3;
while (i < input.Length && input[i] >= '0' && input[i] <= '7' && count > 0)
{
count--;
value = value * 8 + (input[i] - '0');
i++;
}
if (value <= 255)
result.Append((char)(value & 0xFF));
break;
}
case '"':
case '\'':
case '\\':
result.Append(next);
i++;
break;
case 'n':
result.Append('\n');
i++;
break;
case 'r':
result.Append('\r');
i++;
break;
case 't':
result.Append('\t');
i++;
break;
case 'v':
result.Append('\v');
i++;
break;
default:
i++;
break;
}
}
m_AWString = result.ToString();
return m_AWString;
}
public bool ImportStringTable(string pszFilename)
{
//AWScriptFile s = new AWScriptFile();
string szFilename = Path.Combine(Application.streamingAssetsPath, pszFilename);
foreach (var line in File.ReadLines(szFilename))
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split('\t', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
continue;
if (int.TryParse(parts[0], out int key))
{
string value = parts[1].Trim();
if (value.StartsWith("\"") && value.EndsWith("\""))
value = value.Substring(1, value.Length - 2);
m_StringTable[key] = value;
}
}
return true;
//bool bval = s.Open(szFilename);
//if (!bval) return false;
//while (!s.IsEnd())
//{
// bval = s.GetNextToken(true);
// if (!bval) break; // End of file.
// int idString = int.Parse(ByteToStringUtils.UshortArrayToUnicodeString(s.m_szToken));
// bval = s.GetNextToken(true);
// if (!bval) return false;
// string str = (Translate(s.m_szToken));
// m_StringTable[idString] = str;
//}
//s.Close();
//if (a_stricmp(GetStringFromTable(1), _AL("")) == 0) //1 默认字体
// m_StringTable[1] = _AL("方正细黑一简体");
//m_strDefaultFontName = GetStringFromTable(1);
//if (a_stricmp(GetStringFromTable(2), _AL("")) == 0) //2 默认字体大小
// m_StringTable[2] = _AL("10");
//m_nDefaultFontSize = a_atoi(GetStringFromTable(2));
//if (a_stricmp(GetStringFromTable(3), _AL("")) == 0) //3 符号 '\t' 相当于多少个 'W'的宽度
// m_StringTable[3] = _AL("30");
//_tab_char = a_atoi(GetStringFromTable(3));
//if (a_stricmp(GetStringFromTable(4), _AL("")) == 0) //4 m_FontImagePicture 字体大小
// m_StringTable[4] = m_StringTable[2];
//if (a_stricmp(GetStringFromTable(5), _AL("")) == 0) //5 MessageBox 字体大小
// m_StringTable[5] = m_StringTable[2];
//if (a_stricmp(GetStringFromTable(6), _AL("")) == 0) //6 MessageBox shadow
// m_StringTable[6] = _AL("0");
//if (a_stricmp(GetStringFromTable(7), _AL("")) == 0) //7 MessageBox outline
// m_StringTable[7] = _AL("0");
//if (a_stricmp(GetStringFromTable(8), _AL("")) == 0) //8 MessageBox outline color
// m_StringTable[8] = _AL("0");
//m_FontHint.szFontName = GetStringFromTable(1);
//m_FontHint.nFontSize = a_atoi(GetStringFromTable(2));
//m_FontImagePicture.szFontName = GetStringFromTable(1);
//m_FontImagePicture.nFontSize = a_atoi(GetStringFromTable(4));
//m_FontImagePicture.nOutline = 1;
//m_FontMessageBox.szFontName = GetStringFromTable(1);
//m_FontMessageBox.nFontSize = a_atoi(GetStringFromTable(5));
//m_FontMessageBox.nShadow = a_atoi(GetStringFromTable(6));
//m_FontMessageBox.nOutline = a_atoi(GetStringFromTable(7));
//return true;
}
public bool ImportAuiDialogStringTable(string pszFilename)
{
//bool bval;
//int idString;
//string str;
//AWScriptFile s = new AWScriptFile();
string szFilename = Path.Combine(Application.streamingAssetsPath, pszFilename);
//bval = s.Open(szFilename);
//if (!bval) return true; // Ignore error.
//while (!s.IsEnd())
//{
// bval = s.GetNextToken(true);
// if (!bval) break; // End of file.
// idString = int.Parse(ByteToStringUtils.UshortArrayToUnicodeString(s.m_szToken));
// bval = s.GetNextToken(true);
// if (!bval) return false;
// str = ByteToStringUtils.UshortArrayToUnicodeString(s.m_szToken);
// if(m_auiDialog_stringTable.TryGetValue(idString, out string value))
// {
// m_auiDialog_stringTable[idString] = str;
// }
// else
// {
// m_auiDialog_stringTable.Add(idString, str);
// }
//}
//s.Close();
foreach (var line in File.ReadLines(szFilename))
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split('\t', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
continue;
if (int.TryParse(parts[0], out int key))
{
string value = parts[1].Trim();
if (value.StartsWith("\"") && value.EndsWith("\""))
value = value.Substring(1, value.Length - 2);
m_auiDialog_stringTable[key] = value;
}
}
return true;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c2c1d56888edf9142b5d12309b832bba
@@ -0,0 +1,84 @@
using BrewMonster.Network;
using System.Collections.Generic;
using UnityEngine;
namespace BrewMonster.UI
{
public abstract class AUIDialog : MonoBehaviour
{
protected Dictionary<int, string> m_StringTable = new Dictionary<int, string>();
protected bool m_bShow = false;
protected string m_strDataName = "";
protected string m_strDataPtrName = "";
protected uint m_dwData;
protected object m_pvData;
protected AUIManager m_pAUIManager = null;
public virtual void Show(bool value)
{
gameObject.SetActive(value);
}
public void SetData(uint dwData, string strName)
{
m_strDataName = strName;
m_dwData = dwData;
}
public uint GetData()
{
return m_dwData;
}
public object GetDataPtr(string strName)
{
//if (0 != m_pvData && strName != m_strDataPtrName)
// AUI_ReportError(__LINE__, 1, "AUIDialog::GetDataPtr(), data name not match");
return m_pvData;
}
public bool IsShow()
{
return m_bShow;
}
public void SetDataPtr(object pvData, string strName)
{
m_strDataPtrName = strName;
m_pvData = pvData;
}
public CECGameUIMan GetGameUIMan()
{
return EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
}
public CECHostPlayer GetHostPlayer()
{
return EC_Game.GetGameRun().GetHostPlayer();
}
public string GetStringFromTable(int idString)
{
CECGameUIMan gameUIMan = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
string str = gameUIMan.GetStringFromAuiDialogTable(idString);
if (str == null)
{
return gameUIMan.GetStringFromTable(idString);
}
return str;
}
public AUIManager GetAUIManager()
{
return m_pAUIManager;
}
public void SetAUIManager(AUIManager pAUIManager)
{
m_pAUIManager = pAUIManager;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 923726bcb1a5625448a832da43198b7e
+363 -79
View File
@@ -8,16 +8,18 @@ using CSNetwork.GPDataType;
using ModelRenderer.Scripts.Common;
using ModelRenderer.Scripts.GameData;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static CSNetwork.Common.ExpTypes;
namespace BrewMonster.UI
{
public class DlgNPC : MonoBehaviour
public class DlgNPC : AUIDialog
{
[SerializeField] private TextMeshProUGUI m_pTxt_npc;
[SerializeField] private TextMeshProUGUI m_pTxt_Content;
@@ -26,11 +28,6 @@ namespace BrewMonster.UI
int m_iTracedTaskID;
int m_iTracedTaskNPCID;
CECTimeSafeChecker m_tracedTaskTimer;
bool m_bShow = false;
string m_strDataName = "";
string m_strDataPtrName = "";
uint m_dwData;
object m_pvData;
bool HasTracedTask()
{
@@ -128,23 +125,23 @@ namespace BrewMonster.UI
bool PopupTracedTaskDialog(NPC_ESSENCE pEssence)
{
PopupNPCDialog(pEssence);
//if (GetData() == NPC_DIALOG.NPC_DIALOG_ESSENCE)
//{
// for (int i = 0; i < m_pLst_Main.GetCount() - 1; ++i)
// {
// object pData = m_pLst_Main.GetItemDataPtr(i, 0, "");
// uint iService = m_pLst_Main.GetItemData(i, 0, "");
// DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
// EC_Game.GetElementDataMan().get_data_ptr(iService, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
// if (DataType == DATA_TYPE.DT_NPC_TASK_IN_SERVICE ||
// DataType == DATA_TYPE.DT_NPC_TASK_OUT_SERVICE ||
// DataType == DATA_TYPE.DT_NPC_TASK_MATTER_SERVICE)
// {
// SelectListItem(i);
// break;
// }
// }
//}
if (GetData() == NPC_DIALOG.NPC_DIALOG_ESSENCE)
{
for (int i = 0; i < m_pLst_Main.GetCount() - 1; ++i)
{
object pData = m_pLst_Main.GetItemDataPtr(i, 0, "");
uint iService = m_pLst_Main.GetItemData(i, 0, "");
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
EC_Game.GetElementDataMan().get_data_ptr(iService, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
if (DataType == DATA_TYPE.DT_NPC_TASK_IN_SERVICE ||
DataType == DATA_TYPE.DT_NPC_TASK_OUT_SERVICE ||
DataType == DATA_TYPE.DT_NPC_TASK_MATTER_SERVICE)
{
SelectListItem(i);
break;
}
}
}
//if (GetData() == NPC_DIALOG.NPC_DIALOG_TASK_LIST)
//{
// for (int i = 0; i < m_pLst_Main.GetCount() - 1; ++i)
@@ -199,30 +196,11 @@ namespace BrewMonster.UI
}
}
private string GetStringFromTable(int idString)
{
CECGameUIMan gameUIMan = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
string str = gameUIMan.GetStringFromAuiDialogTable(idString);
if(str == null)
{
return gameUIMan.GetStringFromTable(idString);
}
return str;
}
private void Show(bool value)
{
}
private CECGameUIMan GetGameUIMan()
public override void Show(bool value)
{
return EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
}
private CECHostPlayer GetHostPlayer()
{
return EC_ManMessageMono.Instance.EC_ManPlayer.GetHostPlayer();
base.Show(value);
}
void PopupNPCDialog(NPC_ESSENCE pEssence)
@@ -1323,35 +1301,6 @@ namespace BrewMonster.UI
//SetData(NPC_DIALOG_TASK_LIST);
}
void SetData(uint dwData, string strName)
{
m_strDataName = strName;
m_dwData = dwData;
}
uint GetData()
{
return m_dwData;
}
object GetDataPtr(string strName)
{
//if (0 != m_pvData && strName != m_strDataPtrName)
// AUI_ReportError(__LINE__, 1, "AUIDialog::GetDataPtr(), data name not match");
return m_pvData;
}
bool IsShow()
{
return m_bShow;
}
void SetDataPtr(object pvData, string strName)
{
m_strDataPtrName = strName;
m_pvData = pvData;
}
public void PopupNPCDialog(talk_proc pTalk)
{
if (pTalk.num_window == 0) return;
@@ -1379,6 +1328,341 @@ namespace BrewMonster.UI
if (!IsShow()) Show(true);
}
bool PopupCorrespondingServiceDialog(int idFunction, int iService, object pData)
{
//AUIDialog pShow1 = null, pShow2 = null;
//NPC_ESSENCE? pCurNPCEssence = GetGameUIMan().m_pCurNPCEssence;
//if (idFunction == (int)SERVICE_TYPE.NPC_SELL || idFunction == (int)SERVICE_TYPE.NPC_BUY)
//{
// Button pButton;
// pShow1 = m_pAUIManager.GetDialog("Win_Shop");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// GetHostPlayer().PrepareNPCService(iService);
// GetGameUIMan().m_pDlgShop.UpdateShop(1);
// if (pCurNPCEssence && pCurNPCEssence.id_repair_service)
// {
// pShow1.GetDlgItem("Btn_Repair").Show(true);
// pShow1.GetDlgItem("Btn_RepairAll").Show(true);
// }
// else
// {
// pShow1.GetDlgItem("Btn_Repair").Show(false);
// pShow1.GetDlgItem("Btn_RepairAll").Show(false);
// }
// pButton = (PAUISTILLIMAGEBUTTON)pShow2.GetDlgItem("Btn_NormalItem");
// pButton.SetPushed(true);
// pButton = (PAUISTILLIMAGEBUTTON)pShow2.GetDlgItem("Btn_QuestItem");
// pButton.SetPushed(false);
// GetGameUIMan().m_pDlgInventory.SetShowItem(CDlgInventory::INVENTORY_ITEM_NORMAL);
//}
//else if (idFunction == NPC_INSTALL)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_Enchase");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//}
//else if (idFunction == NPC_UNINSTALL)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_Disenchase");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//}
//else if (idFunction == NPC_HEAL)
//{
// GetGameSession().c2s_CmdNPCSevHeal();
// GetGameUIMan().EndNPCService();
//}
//else if (idFunction == NPC_TRANSMIT)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_WorldMapTravel");
// ((CDlgWorldMap*)pShow1).BuildTravelMap(DT_NPC_TRANSMIT_SERVICE, pData);
//}
//else if (idFunction == NPC_SKILL)
//{
// string strText = m_pLst_Main.GetText(m_pLst_Main.GetCurSel());
// string strHead = GetStringFromTable(249);
// string strComp = string(strHead + GetStringFromTable(7107));
// if (0 == a_stricmp(strText, strComp))
// {
// pShow1 = m_pAUIManager.GetDialog("Win_ELFLearn");
// ((CDlgELFLearn*)pShow1).SetNPCName(pCurNPCEssence.name);
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// GetHostPlayer().PrepareNPCService(iService);
// pShow1.SetData(DT_NPC_SKILL_SERVICE);
// }
// else
// {
// pShow1 = m_pAUIManager.GetDialog("Win_Teach");
// GetHostPlayer().PrepareNPCService(iService);
// pShow1.SetData(DT_NPC_SKILL_SERVICE);
// GetGameUIMan().UpdateTeach(0);
// }
//}
//else if (idFunction == NPC_MAKE)
//{
// NPC_MAKE_SERVICE* pMake = (NPC_MAKE_SERVICE*)pData;
// if (pMake.produce_type == 2)
// pShow1 = m_pAUIManager.GetDialog("Win_Produce1");
// else
// pShow1 = m_pAUIManager.GetDialog("Win_Produce");
// GetGameUIMan().m_pDlgProduce = (CDlgProduce*)pShow1;
// GetHostPlayer().PrepareNPCService(iService);
// pShow1.SetDataPtr(pMake, "ptr_NPC_MAKE_SERVICE");
// if (pMake.produce_type == 1 ||
// pMake.produce_type == 3 ||
// pMake.produce_type == 4 ||
// pMake.produce_type == 5)
// GetGameUIMan().m_pDlgProduce.ClearMaterial();
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// GetGameUIMan().m_pDlgProduce.UpdateProduce(1, 0);
//}
//else if (idFunction == NPC_DECOMPOSE)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_Split");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// pShow1.SetDataPtr(pData, "ptr_NPC_DECOMPOSE_SERVICE");
// PAUIPROGRESS pProgress;
// PAUIIMAGEPICTURE pImage;
// pImage = (PAUIIMAGEPICTURE)pShow1.GetDlgItem("Item_a");
// pImage.ClearCover();
// pImage.SetDataPtr(NULL);
// pImage = (PAUIIMAGEPICTURE)pShow1.GetDlgItem("Item_b");
// pImage.ClearCover();
// pImage.SetDataPtr(NULL);
// pProgress = (PAUIPROGRESS)pShow1.GetDlgItem("Prgs_1");
// pProgress.SetProgress(0);
// pShow1.GetDlgItem("Btn_Start").Enable(false);
// pShow1.GetDlgItem("Btn_Cancel").Enable(true);
// pShow1.GetDlgItem("Txt_no1").SetText(_AL(""));
// pShow1.GetDlgItem("Txt_no2").SetText(_AL(""));
// pShow1.GetDlgItem("Txt_Gold").SetText(_AL(""));
// pShow1.GetDlgItem("Txt_SkillName").SetText(_AL(""));
// pShow1.GetDlgItem("Txt_SkillLevel").SetText(_AL(""));
//}
//else if (idFunction == NPC_WAR_TOWERBUILD)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_WarTower");
//}
//else if (idFunction == NPC_RESETPROP)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_ResetProp");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//}
//else if (idFunction == NPC_PETNAME)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_PetRename");
// pShow2 = m_pAUIManager.GetDialog("Win_PetList");
//}
//else if (idFunction == NPC_PETLEARNSKILL)
//{
// CECPetCorral* pPetCorral = GetHostPlayer().GetPetCorral();
// CECPetData* pPet = pPetCorral.GetActivePet();
// if (!pPet)
// {
// GetGameUIMan().MessageBox("", GetStringFromTable(814), MB_OK, A3DCOLORRGB(255, 255, 255));
// GetGameUIMan().EndNPCService();
// }
// else
// {
// pShow1 = m_pAUIManager.GetDialog("Win_Teach");
// GetHostPlayer().PrepareNPCService(iService);
// pShow1.SetData(DT_NPC_PETLEARNSKILL_SERVICE);
// GetGameUIMan().UpdateTeach(0);
// }
//}
//else if (idFunction == NPC_PETFORGETSKILL)
//{
// CECPetCorral* pPetCorral = GetHostPlayer().GetPetCorral();
// CECPetData* pPet = pPetCorral.GetActivePet();
// if (!pPet)
// {
// GetGameUIMan().MessageBox("", GetStringFromTable(814), MB_OK, A3DCOLORRGB(255, 255, 255));
// GetGameUIMan().EndNPCService();
// }
// else
// pShow1 = m_pAUIManager.GetDialog("Win_PetRetrain");
//}
//else if (idFunction == NPC_EQUIPBIND)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_EquipBind");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// pShow1.SetData((DWORD)pData, "ptr_NPC_EQUIPBIND_SERVICE");
//}
//else if (idFunction == NPC_EQUIPDESTROY)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_EquipDestroy");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//}
//else if (idFunction == NPC_EQUIPUNDESTROY)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_EquipUndestroy");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//}
//else if (idFunction == NPC_IDENTIFY)
//{
// PAUIIMAGEPICTURE pImage;
// pShow1 = m_pAUIManager.GetDialog("Win_Identify");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// pShow1.SetDataPtr(pData, "ptr_NPC_IDENTIFY_SERVICE");
// pImage = (PAUIIMAGEPICTURE)pShow1.GetDlgItem("Item");
// pImage.ClearCover();
// pImage.SetDataPtr(NULL);
// pShow1.GetDlgItem("Txt").SetText(_AL(""));
// pShow1.GetDlgItem("Txt_Gold").SetText(_AL(""));
// pShow1.GetDlgItem("Btn_Confirm").Enable(false);
// pShow1.GetDlgItem("Btn_Cancel").Enable(true);
//}
//else if (idFunction == NPC_GIVE_TASK)
//{
// talk_proc::option* opt = (talk_proc::option*)pData;
// int idTask = opt.param;
// if (g_pGame.GetConfigs().IsMiniClient() && CECUIConfig::Instance().GetGameUI().IsTaskDisabledInMiniClient(idTask))
// {
// GetGameUIMan().MessageBox("", GetStringFromTable(10714), MB_OK, A3DCOLORRGBA(255, 255, 255, 160));
// }
// else
// {
// GetGameSession().c2s_CmdNPCSevAcceptTask(idTask, 0, 0);
// }
// GetGameUIMan().EndNPCService();
//}
//else if (idFunction == NPC_COMPLETE_TASK)
//{
// AWARD_DATA ad;
// talk_proc::option* opt = (talk_proc::option*)pData;
// CECTaskInterface* pTask = GetHostPlayer().GetTaskInterface();
// pTask.GetAwardCandidates(opt.param, &ad);
// if (ad.m_ulCandItems > 1)
// {
// pShow1 = m_pAUIManager.GetDialog("Win_Award");
// CDlgAward* pAward = dynamic_cast<CDlgAward*>(pShow1);
// if (pAward) pAward.UpdateAwardItem(opt.param, true);
// }
// else
// {
// GetGameSession().c2s_CmdNPCSevReturnTask(opt.param, 0);
// GetGameUIMan().EndNPCService();
// }
//}
//else if (idFunction == NPC_GIVE_TASK_MATTER)
//{
// talk_proc::option* opt = (talk_proc::option*)pData;
// GetGameSession().c2s_CmdNPCSevTaskMatter(opt.param);
// GetGameUIMan().EndNPCService();
//}
//else if (idFunction == NPC_STORAGE)
//{
// if (GetHostPlayer().TrashBoxHasPsw())
// {
// pShow1 = m_pAUIManager.GetDialog("Win_InputString");
// pShow1.GetDlgItem("DEFAULT_Txt_Input").SetText(_AL(""));
// }
// else
// g_pGame.GetGameSession().c2s_CmdNPCSevOpenTrash("");
//}
//else if (idFunction == NPC_STORAGE_PASSWORD)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_InputString3");
//}
//else if (idFunction == NPC_ACCOUNT_STORAGE)
//{
// if (CECCrossServer::Instance().IsOnSpecialServer())
// {
// GetGameUIMan().ShowErrorMsg(10130);
// GetGameUIMan().EndNPCService();
// }
// else g_pGame.GetGameSession().c2s_CmdNPCSevOpenAccountBox();
//}
//else if (idFunction == NPC_ENGRAVE)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_Engrave");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
//}
//else if (idFunction == NPC_RANDPROP)
//{
// pShow1 = m_pAUIManager.GetDialog("Win_RandProp");
// pShow2 = m_pAUIManager.GetDialog("Win_Inventory");
// GetHostPlayer().PrepareNPCService(iService);
// pShow1.SetDataPtr(pData, "ptr_NPC_RANDPROP_SERVICE");
//}
//else if (idFunction == TALK_RETURN)
//{
// OnCommand_back("back");
// return true; // To avoid to close NPC dialog.
//}
//else if (idFunction == TALK_EXIT)
//{
// GetGameUIMan().EndNPCService();
// int idCurFinishTask = GetGameUIMan().m_idCurFinishTask;
// if (GetData() == CDlgNPC::NPC_DIALOG_TASK_TALK && idCurFinishTask > 0)
// {
// GetHostPlayer().GetTaskInterface().OnUIDialogEnd(idCurFinishTask);
// GetGameUIMan().m_idCurFinishTask = -1;
// }
//}
//else if (idFunction == TALK_GIVEUP_TASK)
//{
// talk_proc::option* opt = (talk_proc::option*)pData;
// GetHostPlayer().GetTaskInterface().GiveUpTask(opt.param);
// GetGameUIMan().EndNPCService();
//}
//else
//{
// GetHostPlayer().GetPack(IVTRTYPE_PACK).UnfreezeAllItems();
// GetGameUIMan().EndNPCService();
//}
//if (pShow1)
//{
// DATA_TYPE DataType;
// elementdataman* pDataMan = g_pGame.GetElementDataMan();
// pDataMan.get_data_ptr(iService, ID_SPACE_ESSENCE, DataType);
// pShow1.Show(true);
// if (pShow2)
// {
// POINT ptPos = pShow1.GetPos();
// if (ptPos.x == 0 && ptPos.y == 0)
// {
// SIZE s1 = pShow1.GetSize();
// SIZE s2 = pShow2.GetSize();
// A3DVIEWPORTPARAM* p = m_pA3DEngine.GetActiveViewport().GetParam();
// int x, y = (p.Height - max(s1.cy, s2.cy)) / 2;
// x = (p.Width - s1.cx - s2.cx) / 2;
// // old : pShow1.SetPos(x, y);
// pShow1.SetPosEx(x, y);
// x += s1.cx;
// // old : pShow2.SetPos(x, y);
// pShow2.SetPosEx(x, y);
// }
// pShow2.Show(true);
// }
//}
Show(false);
return true;
}
void SelectListItem(int index)
{
m_pLst_Main.SetCurSel(index);
@@ -1446,15 +1730,15 @@ namespace BrewMonster.UI
};
//TO DO: fix later
// This show popup service NPC
//PopupCorrespondingServiceDialog(id,
// a_uiService[nIndex], m_pLst_Main.GetItemDataPtr(nCurSel));
PopupCorrespondingServiceDialog((int)id,
(int)a_uiService[nIndex1], m_pLst_Main.GetItemDataPtr(nCurSel, 0, ""));
}
else
{
//TO DO: fix later
// This show popup service NPC
//PopupCorrespondingServiceDialog(
// id, 0, m_pLst_Main.GetItemDataPtr(nCurSel));
PopupCorrespondingServiceDialog(
(int)id, 0, m_pLst_Main.GetItemDataPtr(nCurSel, 0, ""));
}
}
else // Window.
@@ -2427,7 +2711,7 @@ namespace BrewMonster.UI
}
}
int idFunction, id_dialog = 0;
int idFunction = 0, id_dialog = 0;
object pData = m_pLst_Main.GetItemDataPtr(nCurSel, 0, "");
EC_Game.GetElementDataMan().get_data_ptr((uint)iService, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
@@ -2611,7 +2895,7 @@ namespace BrewMonster.UI
else
{
object pData1 = m_pLst_Main.GetItemDataPtr(nCurSel, 0 ,"");
//PopupCorrespondingServiceDialog(idFunction, iService, pData1);
PopupCorrespondingServiceDialog(idFunction, iService, pData1);
}
}
}
@@ -10,14 +10,10 @@ using UnityEngine;
namespace BrewMonster.UI
{
public class CECGameUIMan
public class CECGameUIMan : AUIManager
{
DlgNPC m_pDlgNPC;
public NPC_ESSENCE? m_pCurNPCEssence;
private DialogScriptTableObject m_dialogResouce;
private Canvas m_canvas;
Dictionary<int, string> m_StringTable = new Dictionary<int, string>();
Dictionary<int, string> m_auiDialog_stringTable = new Dictionary<int, string>();
public static bool TALKPROC_IS_TERMINAL(uint id)
{
@@ -34,254 +30,13 @@ namespace BrewMonster.UI
return ((id) & 0x7FFFFFFF);
}
public string GetStringFromTable(int idString)
{
if (m_StringTable.TryGetValue(idString, out var str))
return str;
return null;
}
public string GetStringFromAuiDialogTable(int idString)
{
if (m_auiDialog_stringTable.TryGetValue(idString, out var str))
return str;
return null;
}
public void SetDependency(DialogScriptTableObject resouce, Canvas canvas)
{
m_dialogResouce = resouce;
m_canvas = canvas;
}
public void Init()
{
ImportStringTable("ingame.stf");
ImportAuiDialogStringTable("msgbox.stf");
}
public string Translate(ushort[] str)
{
if (str == null || str.Length == 0)
return null;
string m_AWString = "";
string input = new string(str.Where(c => c != 0).Select(c => (char)c).ToArray());
m_AWString = input;
var result = new System.Text.StringBuilder();
int i = 0;
while (i < input.Length)
{
char c = input[i];
if (c != '\\')
{
result.Append(c);
i++;
continue;
}
i++;
if (i >= input.Length)
break;
char next = input[i];
switch (next)
{
case '\n':
i++;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int value = 0;
int count = 3;
while (i < input.Length && input[i] >= '0' && input[i] <= '7' && count > 0)
{
count--;
value = value * 8 + (input[i] - '0');
i++;
}
if (value <= 255)
result.Append((char)(value & 0xFF));
break;
}
case '"':
case '\'':
case '\\':
result.Append(next);
i++;
break;
case 'n':
result.Append('\n');
i++;
break;
case 'r':
result.Append('\r');
i++;
break;
case 't':
result.Append('\t');
i++;
break;
case 'v':
result.Append('\v');
i++;
break;
default:
i++;
break;
}
}
m_AWString = result.ToString();
return m_AWString;
}
private bool ImportStringTable(string pszFilename)
{
//AWScriptFile s = new AWScriptFile();
string szFilename = Path.Combine(Application.streamingAssetsPath, pszFilename);
foreach (var line in File.ReadLines(szFilename))
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split('\t', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
continue;
if (int.TryParse(parts[0], out int key))
{
string value = parts[1].Trim();
if (value.StartsWith("\"") && value.EndsWith("\""))
value = value.Substring(1, value.Length - 2);
m_StringTable[key] = value;
}
}
return true;
//bool bval = s.Open(szFilename);
//if (!bval) return false;
//while (!s.IsEnd())
//{
// bval = s.GetNextToken(true);
// if (!bval) break; // End of file.
// int idString = int.Parse(ByteToStringUtils.UshortArrayToUnicodeString(s.m_szToken));
// bval = s.GetNextToken(true);
// if (!bval) return false;
// string str = (Translate(s.m_szToken));
// m_StringTable[idString] = str;
//}
//s.Close();
//if (a_stricmp(GetStringFromTable(1), _AL("")) == 0) //1 ĬÈÏ×ÖÌå
// m_StringTable[1] = _AL("·½ÕýϸºÚÒ»¼òÌå");
//m_strDefaultFontName = GetStringFromTable(1);
//if (a_stricmp(GetStringFromTable(2), _AL("")) == 0) //2 ĬÈÏ×ÖÌå´óС
// m_StringTable[2] = _AL("10");
//m_nDefaultFontSize = a_atoi(GetStringFromTable(2));
//if (a_stricmp(GetStringFromTable(3), _AL("")) == 0) //3 ·ûºÅ '\t' Ï൱ÓÚ¶àÉÙ¸ö 'W'µÄ¿í¶È
// m_StringTable[3] = _AL("30");
//_tab_char = a_atoi(GetStringFromTable(3));
//if (a_stricmp(GetStringFromTable(4), _AL("")) == 0) //4 m_FontImagePicture ×ÖÌå´óС
// m_StringTable[4] = m_StringTable[2];
//if (a_stricmp(GetStringFromTable(5), _AL("")) == 0) //5 MessageBox ×ÖÌå´óС
// m_StringTable[5] = m_StringTable[2];
//if (a_stricmp(GetStringFromTable(6), _AL("")) == 0) //6 MessageBox shadow
// m_StringTable[6] = _AL("0");
//if (a_stricmp(GetStringFromTable(7), _AL("")) == 0) //7 MessageBox outline
// m_StringTable[7] = _AL("0");
//if (a_stricmp(GetStringFromTable(8), _AL("")) == 0) //8 MessageBox outline color
// m_StringTable[8] = _AL("0");
//m_FontHint.szFontName = GetStringFromTable(1);
//m_FontHint.nFontSize = a_atoi(GetStringFromTable(2));
//m_FontImagePicture.szFontName = GetStringFromTable(1);
//m_FontImagePicture.nFontSize = a_atoi(GetStringFromTable(4));
//m_FontImagePicture.nOutline = 1;
//m_FontMessageBox.szFontName = GetStringFromTable(1);
//m_FontMessageBox.nFontSize = a_atoi(GetStringFromTable(5));
//m_FontMessageBox.nShadow = a_atoi(GetStringFromTable(6));
//m_FontMessageBox.nOutline = a_atoi(GetStringFromTable(7));
//return true;
}
public bool ImportAuiDialogStringTable(string pszFilename)
{
//bool bval;
//int idString;
//string str;
//AWScriptFile s = new AWScriptFile();
string szFilename = Path.Combine(Application.streamingAssetsPath, pszFilename);
//bval = s.Open(szFilename);
//if (!bval) return true; // Ignore error.
//while (!s.IsEnd())
//{
// bval = s.GetNextToken(true);
// if (!bval) break; // End of file.
// idString = int.Parse(ByteToStringUtils.UshortArrayToUnicodeString(s.m_szToken));
// bval = s.GetNextToken(true);
// if (!bval) return false;
// str = ByteToStringUtils.UshortArrayToUnicodeString(s.m_szToken);
// if(m_auiDialog_stringTable.TryGetValue(idString, out string value))
// {
// m_auiDialog_stringTable[idString] = str;
// }
// else
// {
// m_auiDialog_stringTable.Add(idString, str);
// }
//}
//s.Close();
foreach (var line in File.ReadLines(szFilename))
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split('\t', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
continue;
if (int.TryParse(parts[0], out int key))
{
string value = parts[1].Trim();
if (value.StartsWith("\"") && value.EndsWith("\""))
value = value.Substring(1, value.Length - 2);
m_auiDialog_stringTable[key] = value;
}
}
return true;
}
public void PopupNPCDialog(NPC_ESSENCE pEssence)
{
if(m_pDlgNPC == null)
{
GameObject ob = m_dialogResouce.GetPrefabDialog("DialogNPC");
m_pDlgNPC = GameObject.Instantiate(ob, m_canvas.transform).GetComponent<DlgNPC>();
m_pDlgNPC.SetAUIManager(this);
}
m_pDlgNPC.PopupDialog(pEssence);
}
@@ -292,6 +47,7 @@ namespace BrewMonster.UI
{
GameObject ob = m_dialogResouce.GetPrefabDialog("DialogNPC");
m_pDlgNPC = GameObject.Instantiate(ob, m_canvas.transform).GetComponent<DlgNPC>();
m_pDlgNPC.SetAUIManager(this);
}
m_pDlgNPC.PopupNPCDialog(pTalk);
}
+6 -4
View File
@@ -15,6 +15,7 @@ public class CECUIManager : MonoSingleton<CECUIManager>
[SerializeField] private int currentTargetNPCID;
CECGameUIMan gameUI;
AUIManager aUIManager;
[SerializeField] private DialogScriptTableObject dialogResouce;
[SerializeField] private Canvas canvasDlg;
protected override void Awake()
@@ -110,11 +111,12 @@ public class CECUIManager : MonoSingleton<CECUIManager>
public CECGameUIMan GetInGameUIMan()
{
if (gameUI == null)
if (aUIManager == null)
{
gameUI = new CECGameUIMan();
gameUI.SetDependency(dialogResouce, canvasDlg);
gameUI.Init();
aUIManager = new AUIManager();
aUIManager.SetDependency(dialogResouce, canvasDlg);
aUIManager.Init();
gameUI = aUIManager as CECGameUIMan;
}
return gameUI;
}