Files
RedHotRoast-ios/Assets/Scripts/ModuleUI/FAQ/FAQUI.cs
T
2026-04-22 09:52:55 +08:00

240 lines
9.3 KiB
C#

using UnityEngine;
using FairyGUI;
using Newtonsoft.Json;
using System.Collections.Generic;
using FGUI.P06_Hall;
namespace FlowerPower
{
public class FAQUI : BaseUI
{
private FAQUICtrl ctrl;
private FAQModel model;
private FGUI.P06_Hall.com_faq ui;
public FAQUI(FAQUICtrl ctrl) : base(ctrl)
{
uiName = UIConst.FAQUI;
this.ctrl = ctrl;
}
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "P06_Hall";
uiInfo.assetName = "com_faq";
uiInfo.layerType = UILayerType.Popup;
uiInfo.isNeedOpenAnim = false;
uiInfo.isNeedCloseAnim = false;
uiInfo.isNeedUIMask = true;
}
#region
protected override void OnInit()
{
//model = ModuleManager.Instance.GetModel(ModelConst.FAQModel) as FAQModel;
}
protected override void OnClose()
{
}
protected override void OnBind()
{
ui = baseUI as FGUI.P06_Hall.com_faq;
}
protected override void OnOpenBefore(object args)
{
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<FAQRuleModel>().dataList));
Debug.Log(JsonConvert.SerializeObject(ConfigSystem.GetConfig<MessageBoardModel>().dataList));
if (GameHelper.isRDExchangeMode())
{
rule_list = ConfigSystem.GetConfig<FAQRuleModel_1>().dataList;
message_list = ConfigSystem.GetConfig<MessageBoardModel_1>().dataList;
}
else
{
rule_list = ConfigSystem.GetConfig<FAQRuleModel>().dataList;
message_list = ConfigSystem.GetConfig<MessageBoardModel>().dataList;
}
InitView();
}
private List<FAQRule> rule_list = ConfigSystem.GetConfig<FAQRuleModel>().dataList;
private List<MessageBoard> message_list = ConfigSystem.GetConfig<MessageBoardModel>().dataList;
protected override void OnOpen(object args)
{
}
protected override void OnHide()
{
}
protected override void OnDisplay(object args)
{
}
#endregion
#region
protected override void AddListener()
{
GameDispatcher.Instance.AddListener(GameMsg.faq_refresh, refreshList);
}
protected override void RemoveListener()
{
GameDispatcher.Instance.RemoveListener(GameMsg.faq_refresh, refreshList);
}
#endregion
void refreshList(object a)
{
com_msg com_msg = (com_msg)UIPackage.CreateObject("P06_Hall", "com_msg");
com_msg.text_msg.text = list_user_arr[list_user_arr.Count - 1] + ":" + list_content_arr[list_content_arr.Count - 1];
ui.list_msg.AddChild(com_msg);
ui.list_msg.scrollPane.ScrollDown(500, false);
}
//初始化页面逻辑
private void InitView()
{
ui.btn_close.SetClick(CtrlCloseUI);
for (int i = 0; i < rule_list.Count; i++)
{
com_question question = (com_question)UIPackage.CreateObject("P06_Hall", "com_question");
question.text_question.text = (i + 1) + "." + rule_list[i].Rule;
if (question.text_question.width > 730) {
question.text_question.autoSize = AutoSizeType.Shrink;
question.text_question.width = 730;
}
ui.list_faq.AddChild(question);
for (int j = 0; j < 4; j++)
{
if (j == 0)
{
if (!string.IsNullOrEmpty(rule_list[i].Information1))
{
com_answer anster = (com_answer)UIPackage.CreateObject("P06_Hall", "com_answer");
anster.text_answer.text = rule_list[i].Information1;
ui.list_faq.AddChild(anster);
}
}
else if (j == 1)
{
if (!string.IsNullOrEmpty(rule_list[i].Information2))
{
com_answer anster = (com_answer)UIPackage.CreateObject("P06_Hall", "com_answer");
anster.text_answer.text = rule_list[i].Information2;
ui.list_faq.AddChild(anster);
}
}
else if (j == 2)
{
if (!string.IsNullOrEmpty(rule_list[i].Information3))
{
com_answer anster = (com_answer)UIPackage.CreateObject("P06_Hall", "com_answer");
anster.text_answer.text = rule_list[i].Information3;
ui.list_faq.AddChild(anster);
}
}
else if (j == 3)
{
if (!string.IsNullOrEmpty(rule_list[i].Information4))
{
com_answer anster = (com_answer)UIPackage.CreateObject("P06_Hall", "com_answer");
anster.text_answer.text = rule_list[i].Information4;
ui.list_faq.AddChild(anster);
}
}
}
}
if (user_arr == null) //第一次显示
{
user_arr = message_list[0].user_name.Split(",");
int user_index = PlayerPrefs.GetInt("user_index", 0);
if (user_index + 10 >= user_arr.Length) user_index = 0;
content_arr = message_list[0].message.Split(",");
int faq_index = PlayerPrefs.GetInt("faq_index", 0);
if (faq_index + 10 >= content_arr.Length) faq_index = 0;
for (int i = user_index; i < user_index + 10; i++)
{
list_user_arr.Add(user_arr[i]);
}
for (int i = faq_index; i < faq_index + 10; i++)
{
list_content_arr.Add(content_arr[i]);
}
if (PlayerPrefs.GetInt("user_FAQindex", 0) < 10)
{
if (!string.IsNullOrEmpty(PlayerPrefs.GetString("user_FAQcontent", "")))
{
list_user_arr.Insert(10 - PlayerPrefs.GetInt("user_FAQindex", 0), PreferencesMgr.Instance.PlayerName);
list_content_arr.Insert(10 - PlayerPrefs.GetInt("user_FAQindex", 0), PlayerPrefs.GetString("user_FAQcontent", ""));
}
}
user_index += 10;
faq_index += 10;
PlayerPrefs.SetInt("user_index", user_index);
PlayerPrefs.SetInt("faq_index", faq_index);
}
for (int i = 0; i < list_user_arr.Count; i++)
{
com_msg com_msg = (com_msg)UIPackage.CreateObject("P06_Hall", "com_msg");
com_msg.text_msg.text = list_user_arr[i] + ":" + list_content_arr[i];
ui.list_msg.AddChild(com_msg);
}
ui.btn_send.SetClick(() =>
{
if (string.IsNullOrEmpty(ui.input_msg.text)) {
GameHelper.ShowTips("Please enter your message!");
return;
}
Debug.Log(ui.input_msg.text);
com_msg com_msg = (com_msg)UIPackage.CreateObject("P06_Hall", "com_msg");
com_msg.text_msg.text = PreferencesMgr.Instance.PlayerName + ":" + ui.input_msg.text;
list_user_arr.Add(PreferencesMgr.Instance.PlayerName);
list_content_arr.Add(ui.input_msg.text);
PlayerPrefs.SetInt("faq_time", (int)GameHelper.GetNowTime());
PlayerPrefs.SetInt("user_FAQindex", 0);
PlayerPrefs.SetString("user_FAQcontent", ui.input_msg.text);
ui.input_msg.text = "";
ui.input_msg.promptText = "[color=#999999][size=40]Can only send once every hour[/size][/color]";
ui.input_msg.touchable = false;
ui.btn_send.SetClick(() => { });
ui.list_msg.AddChild(com_msg);
ui.list_msg.scrollPane.ScrollDown(500, false);
ui.btn_send.grayed = true;
ui.input_bg.grayed = true;
});
ui.list_msg.scrollPane.ScrollDown(1000, false);
if (PlayerPrefs.GetInt("faq_time", 0) + 3600 > GameHelper.GetNowTime())
{
ui.input_msg.promptText = "[color=#999999][size=40]Can only send once every hour[/size][/color]";
ui.input_msg.touchable = false;
ui.btn_send.SetClick(() => { });
ui.btn_send.grayed = true;
ui.input_bg.grayed = true;
}
ui.btn_contactus.SetClick(() => { GameHelper.OpenEmail(); });
}
public static string[] user_arr;
public static string[] content_arr;
public static List<string> list_user_arr = new List<string>();
public static List<string> list_content_arr = new List<string>();
}
}