1015 lines
34 KiB
C#
1015 lines
34 KiB
C#
using asap.core;
|
|
using DG.Tweening;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
using cfg;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public class BuildingData
|
|
{
|
|
public float upgradeTime;
|
|
public int curStep;
|
|
public string CurrentPrefab;
|
|
|
|
public int areaStepCount;
|
|
public int turnOffTimeScale;
|
|
//public int rewardQCount;
|
|
/// <summary>
|
|
/// 以下是下一步的数据
|
|
/// </summary>
|
|
public bool isConstructionCost;
|
|
public int required;
|
|
public ulong NextUpgradeCost;
|
|
public List<int> benefitsLevel;
|
|
public string Icon;
|
|
public string Title_l10n_key;
|
|
public List<int> DisplaySwitch;
|
|
public int Rewards;
|
|
public int NextStep;
|
|
public int NextStepCount;
|
|
public int NextTimelineId;
|
|
public float NextStartTime;
|
|
public float NextDuration;
|
|
public string NextPrefab;
|
|
}
|
|
|
|
public class CampPanel : BasePanel
|
|
{
|
|
PlayerData _playerData;
|
|
CanvasGroup canvasGroup;
|
|
Animator animator;
|
|
public TextMeshProUGUI campName;
|
|
public TextMeshProUGUI areaInfo;
|
|
|
|
public TextMeshProUGUI text_progress;
|
|
string text_progress_string = "0/0";
|
|
public TextMeshProUGUI cost;
|
|
GameObject costRoot;
|
|
TMP_Text text_cost_buff;
|
|
TMP_Text text_old;
|
|
public RewardItemNew[] bg_reward; Image[] rewardBg;
|
|
public Image costIcon;
|
|
public Image currentWorkIcon;
|
|
GameObject barGo1;
|
|
GameObject barGo2;
|
|
GameObject barGo3;
|
|
Image bar1;
|
|
Image bar2;
|
|
Image bar3;
|
|
public Image currentBar;
|
|
CanvasGroup DownPanel;
|
|
UIButton upgradeButton;
|
|
GameObject btn_icon;
|
|
GameObject btn_fix;
|
|
Animator upButtonAni;
|
|
public UIDrag uiDrag;
|
|
public Button btn_close;
|
|
Button btn_right;
|
|
Animation camp_target;
|
|
|
|
public RectTransform areaIconParent;
|
|
public Image[] areaIcons;
|
|
public GameObject done1;
|
|
CampDataMM _campData;
|
|
CanvasGroup top_area_canvas;
|
|
float _upgradeTime;
|
|
bool _isUpgrading;
|
|
ulong _upgradeCost;
|
|
bool isStart = false;
|
|
bool isdrag = false;
|
|
bool fixIng = false;
|
|
private Coroutine dragWith;
|
|
GameObject particle;
|
|
GameObject kuang;
|
|
bool IsDowning = false;
|
|
bool IsDowning1 = false;
|
|
Coroutine startTimer;
|
|
|
|
TMP_Text text_name;
|
|
//TMP_Text text_map_name;
|
|
//TMP_Text text_comingsoon;
|
|
Button btn_go;
|
|
GameObject btn_p_text;
|
|
GameObject btn_text_confirm;
|
|
bool isCampPanel_fade = false;
|
|
System.IDisposable idis = null;
|
|
List<ItemData> levelItemDatas;
|
|
Tables _table;
|
|
float buildingSpeed = 1;
|
|
float maxSpeed = 1.5f;
|
|
int rewardLen = 0;
|
|
|
|
Queue<BuildingData> buildingDatas = new Queue<BuildingData>();
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
top_area_canvas = transform.Find("top_area").GetComponent<CanvasGroup>();
|
|
_table = GContext.container.Resolve<cfg.Tables>();
|
|
maxSpeed = 1 + _table.TbGlobalConfig.TimeScalePerStep * _table.TbGlobalConfig.AccMaxStep;
|
|
_playerData = GContext.container.Resolve<PlayerData>();
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
animator = GetComponent<Animator>();
|
|
particle = transform.Find("top_area/particle").gameObject;
|
|
campName = transform.Find("safearea/LeftPanel/stage/text_stage").GetComponent<TextMeshProUGUI>();
|
|
areaInfo = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/text_areaInfo").GetComponent<TextMeshProUGUI>();
|
|
text_progress = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bg_progress/text_progress").GetComponent<TextMeshProUGUI>();
|
|
costRoot = transform.Find("safearea/DownPanel/btn_construct/CostRoot").gameObject;
|
|
cost = transform.Find("safearea/DownPanel/btn_construct/CostRoot/text_cost").GetComponent<TextMeshProUGUI>();
|
|
text_cost_buff = transform.Find("safearea/DownPanel/btn_construct/CostRoot/text_cost_buff").GetComponent<TMP_Text>();
|
|
text_old = transform.Find("safearea/DownPanel/btn_construct/CostRoot/text_cost_buff/text_old").GetComponent<TMP_Text>();
|
|
bg_reward = transform.Find("safearea/MiddlePanel/camp_target/reward").GetComponentsInChildren<RewardItemNew>();
|
|
rewardBg = new Image[bg_reward.Length];
|
|
for (int i = 0; i < bg_reward.Length; i++)
|
|
{
|
|
rewardBg[i] = bg_reward[i].transform.Find("bg").GetComponent<Image>();
|
|
}
|
|
camp_target = transform.Find("safearea/MiddlePanel/camp_target").GetComponent<Animation>();
|
|
|
|
costIcon = transform.Find("safearea/DownPanel/btn_construct/CostRoot/text_cost/icon_cost").GetComponent<Image>();
|
|
|
|
barGo1 = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bar1").gameObject;
|
|
barGo2 = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bar2").gameObject;
|
|
barGo3 = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bar3").gameObject;
|
|
bar1 = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bar1/bar").GetComponent<Image>();
|
|
bar2 = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bar2/bar").GetComponent<Image>();
|
|
bar3 = transform.Find("safearea/MiddlePanel/camp_target/bg_bar/bar3/bar").GetComponent<Image>();
|
|
|
|
DownPanel = transform.Find("safearea/DownPanel").GetComponent<CanvasGroup>();
|
|
upgradeButton = transform.Find("safearea/DownPanel/btn_construct").GetComponent<UIButton>();
|
|
upButtonAni = transform.Find("safearea/DownPanel/btn_construct").GetComponent<Animator>();
|
|
btn_icon = transform.Find("safearea/DownPanel/btn_construct/icon").gameObject;
|
|
btn_fix = transform.Find("safearea/DownPanel/btn_construct/fix").gameObject;
|
|
uiDrag = transform.Find("safearea/Image").GetComponent<UIDrag>();
|
|
btn_close = transform.Find("safearea/DownPanel/btn_close").GetComponent<Button>();
|
|
btn_right = transform.Find("safearea/DownPanel/btn_right").GetComponent<Button>();
|
|
areaIconParent = transform.Find("safearea/LeftPanel/stage/Mask/layout").GetComponent<RectTransform>();
|
|
Transform la = transform.Find("safearea/LeftPanel/stage/Mask/layout");
|
|
areaIcons = new Image[4];
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
areaIcons[i] = la.GetChild(i).GetComponent<Image>();
|
|
}
|
|
done1 = areaIcons[1].transform.Find("done").gameObject;
|
|
kuang = transform.Find("safearea/DownPanel/btn_construct/kuang_glow").gameObject;
|
|
|
|
text_name = transform.Find("safearea/MiddlePanel/completed/text_name").GetComponent<TMP_Text>();
|
|
//text_map_name = transform.Find("safearea/DownPanel/reward/mask/text_map_name").GetComponent<TMP_Text>();
|
|
//text_comingsoon = transform.Find("safearea/DownPanel/reward/mask/text_comingsoon").GetComponent<TMP_Text>();
|
|
btn_go = transform.Find("safearea/DownPanel/reward/btn_go/btn_green").GetComponent<Button>();
|
|
btn_p_text = transform.Find("safearea/DownPanel/reward/btn_go/btn_green/Ani_Container/p_text").gameObject;
|
|
btn_text_confirm = transform.Find("safearea/DownPanel/reward/btn_go/btn_green/Ani_Container/text_confirm").gameObject;
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
GContext.container.RegisterInstance(this);
|
|
_campData = GContext.container.Resolve<CampDataMM>();
|
|
btn_icon.SetActive(!_campData.IsFix);
|
|
btn_fix.SetActive(_campData.IsFix);
|
|
upgradeButton.interactable = true;
|
|
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
|
|
}
|
|
public void SetAlpha()
|
|
{
|
|
canvasGroup.alpha = DeBugPanel.isShow ? 1 : 0;
|
|
if (!DeBugPanel.isShow)
|
|
{
|
|
OnUpgradClick();
|
|
}
|
|
}
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
uiDrag.OnBeginDragCall = () =>
|
|
{
|
|
if (_isUpgrading)
|
|
{
|
|
return;
|
|
}
|
|
#if UNITY_EDITOR
|
|
if (Input.GetMouseButton(0))
|
|
#else
|
|
if (Input.touchCount == 1)
|
|
#endif
|
|
{
|
|
GContext.Publish(new SwitchVirtualCameraEvent() { type = 1, isDrag = _campData.constructionArea?.TurnOffFreeLook != 1 });
|
|
}
|
|
OnDraging();
|
|
};
|
|
|
|
upgradeButton.onDown.AddListener(StartClick);
|
|
upgradeButton.onUp.AddListener(EndClick);
|
|
btn_close.onClick.AddListener(OnCloseClick);
|
|
btn_go.onClick.AddListener(OnGoto);
|
|
SetAlpha();
|
|
|
|
GContext.OnEvent<ChangeLanguageEvent>().Subscribe(OnChangeLanguage).AddTo(disposables);
|
|
GContext.OnEvent<GetUIAsyncEvent>().Subscribe(GetUIAsyncEvent).AddTo(disposables);
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnRewardPanelClose).AddTo(disposables);
|
|
|
|
GContext.OnEvent<RestartShowHomeUIEvent>().Subscribe(_ =>
|
|
{
|
|
canvasGroup.alpha = 1;
|
|
canvasGroup.blocksRaycasts = true;
|
|
}).AddTo(disposables);
|
|
|
|
GContext.OnEvent<HideHomePanelEvent>().Subscribe(_ =>
|
|
{
|
|
canvasGroup.alpha = 0;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}).AddTo(disposables);
|
|
|
|
GContext.OnEvent<ShowRewardPopupTop>().Subscribe(x =>
|
|
{
|
|
x.isHide = true;
|
|
}).AddTo(disposables);
|
|
|
|
transform.SetAsFirstSibling();
|
|
isStart = true;
|
|
BuildingData buildingData = new BuildingData();
|
|
buildingData.CurrentPrefab = _campData.CurrentPrefab;
|
|
UpdataData(buildingData);
|
|
UpdateAccount(buildingData);
|
|
UpdateDataInfo(buildingData);
|
|
isStart = false;
|
|
btn_right.onClick.AddListener(ToCampSkyscraper);
|
|
Input.multiTouchEnabled = true;
|
|
|
|
}
|
|
void GetUIAsyncEvent(GetUIAsyncEvent data)
|
|
{
|
|
if (!data.show)
|
|
{
|
|
return;
|
|
}
|
|
if (data.uIType != UITypes.RewardPopupPanel.Name
|
|
&& data.uIType != UITypes.VipPopupPanel.Name)
|
|
{
|
|
EndOutUpgrade();
|
|
}
|
|
}
|
|
void OnDraging()
|
|
{
|
|
isdrag = true;
|
|
EndOutUpgrade();
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
DOTween.Kill(currentBar);
|
|
Input.multiTouchEnabled = false;
|
|
}
|
|
|
|
void OnChangeLanguage(ChangeLanguageEvent changeLanguageEvent = null)
|
|
{
|
|
text_name.text = LocalizationMgr.GetText(_campData.Name);
|
|
campName.text = LocalizationMgr.GetText(_campData.Name);
|
|
var area = _campData.constructionArea;
|
|
if (area != null)
|
|
{
|
|
string AreaName = LocalizationMgr.GetText(area.Name_l10n_key) + LocalizationMgr.GetText(area.NameIndex_l10n_key);
|
|
areaInfo.text = AreaName;
|
|
}
|
|
text_progress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", text_progress_string);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 建造相关显示数据
|
|
/// </summary>
|
|
/// <param name="buildingData"></param>
|
|
void UpdataData(BuildingData buildingData)
|
|
{
|
|
var step_info = _campData.StepInfo;
|
|
buildingData.NextTimelineId = _campData.TimelineId;
|
|
buildingData.NextStartTime = _campData.StepInfo.StartTime;
|
|
buildingData.NextDuration = _campData.StepInfo.PlayTime;
|
|
buildingData.NextPrefab = _campData.CurrentPrefab;
|
|
_upgradeTime = step_info.PlayTime;
|
|
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<ConstructionCost>();
|
|
buildingData.isConstructionCost = buffTimeData != null;
|
|
if (_campData.IsFix)
|
|
{
|
|
buildingData.required = step_info.FixRequired;
|
|
}
|
|
else
|
|
{
|
|
buildingData.required = step_info.BuildRequired;
|
|
}
|
|
if (buildingData.isConstructionCost)
|
|
{
|
|
_upgradeCost = (ulong)(buildingData.required * (1 - buffTimeData.Param));
|
|
}
|
|
else
|
|
{
|
|
_upgradeCost = (ulong)buildingData.required;
|
|
}
|
|
buildingData.NextUpgradeCost = _upgradeCost;
|
|
buildingData.NextStep = _campData.AreaStep;
|
|
buildingData.NextStepCount = _campData.AreaStepCount;
|
|
|
|
UpdateButtonInfo(buildingData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 等级奖励相关显示数据
|
|
/// </summary>
|
|
/// <param name="buildingData"></param>
|
|
void UpdateAccount(BuildingData buildingData)
|
|
{
|
|
AccountMM account = GContext.container.Resolve<PlayerData>().nextAccountData;
|
|
buildingData.Icon = account.Icon;
|
|
buildingData.Title_l10n_key = account.Title_l10n_key;
|
|
buildingData.DisplaySwitch = account.DisplaySwitch;
|
|
buildingData.Rewards = account.Rewards;
|
|
buildingData.benefitsLevel = new List<int>
|
|
{
|
|
account.CashMag,
|
|
account.CashMagLimited,
|
|
account.EnergyLimit,
|
|
account.EnergyRecover,
|
|
account.EventFishCashMag,
|
|
account.EventFishDamage,
|
|
account.AquariumLimit,
|
|
account.AquariumCashMag,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新按钮显示
|
|
/// </summary>
|
|
/// <param name="buildingData"></param>
|
|
void UpdateButtonInfo(BuildingData buildingData)
|
|
{
|
|
costRoot.gameObject.SetActive(true);
|
|
text_cost_buff.gameObject.SetActive(buildingData.isConstructionCost);
|
|
cost.gameObject.SetActive(!buildingData.isConstructionCost);
|
|
|
|
if (buildingData.isConstructionCost)
|
|
{
|
|
text_cost_buff.text = ConvertTools.GetNumberString(buildingData.NextUpgradeCost);
|
|
text_old.text = ConvertTools.GetNumberString(buildingData.required);
|
|
}
|
|
else
|
|
{
|
|
cost.text = ConvertTools.GetNumberString(buildingData.required);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新建造步骤 等级奖励两部分
|
|
/// </summary>
|
|
/// <param name="buildingData"></param>
|
|
void UpdateDataInfo(BuildingData buildingData)
|
|
{
|
|
OnChangeLanguage();
|
|
IUIService uiService = GContext.container.Resolve<IUIService>();
|
|
|
|
rewardLen = 0;
|
|
if (!string.IsNullOrEmpty(buildingData.Icon))
|
|
{
|
|
uiService.SetImageSprite(rewardBg[rewardLen], "bg_shop_gift1");
|
|
bg_reward[rewardLen].SetData(buildingData.Icon, LocalizationMgr.GetText(buildingData.Title_l10n_key), LocalizationMgr.GetText("UI_PlayerGradePanel_1"));
|
|
rewardLen++;
|
|
}
|
|
var DisplaySwitch = buildingData.DisplaySwitch;
|
|
|
|
var levels = buildingData.benefitsLevel;
|
|
|
|
int id;
|
|
Item item;
|
|
for (int i = 0; i < DisplaySwitch.Count; i++)
|
|
{
|
|
if (rewardLen >= bg_reward.Length || i >= levels.Count)
|
|
{
|
|
break;
|
|
}
|
|
if (DisplaySwitch[i] > 0)
|
|
{
|
|
id = 12001 + i;
|
|
item = _table.TbItem.GetOrDefault(id);
|
|
uiService.SetImageSprite(rewardBg[rewardLen], "bg_grade_benefit");
|
|
bg_reward[rewardLen].SetData(item, levels[i], true);
|
|
rewardLen++;
|
|
}
|
|
}
|
|
if (buildingData.Rewards > 0)
|
|
{
|
|
levelItemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(buildingData.Rewards);
|
|
if (levelItemDatas != null)
|
|
{
|
|
for (int i = 0; i < levelItemDatas.Count; i++)
|
|
{
|
|
if (rewardLen >= bg_reward.Length)
|
|
{
|
|
break;
|
|
}
|
|
uiService.SetImageSprite(rewardBg[rewardLen], "bg_shop_gift1");
|
|
bg_reward[rewardLen].SetData(levelItemDatas[i], true, true);
|
|
rewardLen++;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
levelItemDatas = null;
|
|
}
|
|
for (int i = rewardLen; i < bg_reward.Length; i++)
|
|
{
|
|
bg_reward[i].gameObject.SetActive(false);
|
|
}
|
|
|
|
barGo1.SetActive(rewardLen >= 3);
|
|
barGo2.SetActive(rewardLen == 2);
|
|
barGo3.SetActive(rewardLen == 1);
|
|
currentBar = rewardLen >= 3 ? bar1 : rewardLen == 2 ? bar2 : bar3;
|
|
text_progress_string = $"{buildingData.NextStep}/{buildingData.NextStepCount}";
|
|
text_progress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", text_progress_string);
|
|
currentBar.fillAmount = (float)(buildingData.NextStep) / buildingData.NextStepCount;
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(costIcon, _table.GetItemIconName(1002), PanelName);
|
|
|
|
if (buildingData.NextStep >= buildingData.NextStepCount)
|
|
{
|
|
EndOutUpgrade();
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("open_new"))
|
|
{
|
|
e.AddContent("open_type", 2)
|
|
.AddContent("buliding_id", _campData.NextMapID);
|
|
|
|
}
|
|
#endif
|
|
bool isNext = _campData.NextMapID != -1;
|
|
if (isNext)
|
|
{
|
|
isNext = _table.TbConstruction.DataMap.ContainsKey(_campData.NextMapID);
|
|
}
|
|
btn_p_text.SetActive(isNext);
|
|
btn_text_confirm.SetActive(!isNext);
|
|
text_name.text = LocalizationMgr.GetText(_campData.Name);
|
|
|
|
OnLastBuilding();
|
|
}
|
|
btn_right.gameObject.SetActive(_campData.IsOpenSkyscraper);
|
|
}
|
|
void OnLastBuilding()
|
|
{
|
|
canvasGroup.blocksRaycasts = false;
|
|
if (isStart)
|
|
{
|
|
animator.Play("CampPanel_show2");
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
else
|
|
{
|
|
CurRewardQCount curRewardQCount = new CurRewardQCount();
|
|
GContext.Publish(curRewardQCount);
|
|
if (curRewardQCount.count > 0)
|
|
{
|
|
isCampPanel_fade = true;
|
|
}
|
|
else
|
|
{
|
|
CampPanel_show2();
|
|
}
|
|
}
|
|
}
|
|
async void CampPanel_show2()
|
|
{
|
|
//animator.Play("CampPanel_fade");
|
|
//await Awaiters.Seconds(0.5f);
|
|
//canvasGroup.blocksRaycasts = true;
|
|
GContext.Publish(new SwitchVirtualCameraEvent() { type = 11, isDrag = true });
|
|
await UIManager.Instance.ShowUI(UITypes.TravelMapCampPhotoPanel);
|
|
UIManager.Instance.DestroyUI(UITypes.CampPanel);
|
|
}
|
|
async void OnGoto()
|
|
{
|
|
canvasGroup.blocksRaycasts = false;
|
|
var mapData = _table.TbMapData.DataMap[_playerData.lastMapId];
|
|
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Load(mapData.EnvName);
|
|
if (isCanEnter)
|
|
{
|
|
EnterMap();
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, EnterMap, OnCloseClick);
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
}
|
|
void EnterMap()
|
|
{
|
|
canvasGroup.blocksRaycasts = false;
|
|
if (_campData.NextMapID != -1)
|
|
{
|
|
_campData.ChangeNextCampID();
|
|
GContext.Publish(new ConditionTypeEvent(ConditionType.MapUnlocked, _campData.Id));
|
|
}
|
|
_playerData.SetCurrentMapId(_playerData.lastMapId);
|
|
_campData.SaveChangeCamp();
|
|
OnCloseClick();
|
|
}
|
|
|
|
public void OnCloseClick()
|
|
{
|
|
if (IsDowning)
|
|
{
|
|
upgradeButton.Up();
|
|
EndOutUpgrade();
|
|
}
|
|
if (_isUpgrading) return;
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
}
|
|
void StartClick()
|
|
{
|
|
if (!IsDowning)
|
|
{
|
|
upButtonAni.Play("clicked", -1, 0);
|
|
if (GContext.container.Resolve<GuideDataCenter>().curDefine == null ||
|
|
GContext.container.Resolve<GuideDataCenter>().curDefine.fingerType == FingerType.None)
|
|
{
|
|
buildingSpeed = 1;
|
|
|
|
bool canAuto = OnClickUp();
|
|
if (canAuto && _playerData.lv > _table.TbGlobalConfig.AutoBuildUnlock)
|
|
{
|
|
if (!_isUpgrading)
|
|
{
|
|
return;
|
|
}
|
|
|
|
startTimer = StartCoroutine(StartTimer());
|
|
}
|
|
}
|
|
else if (_playerData.lv > _table.TbGlobalConfig.AutoBuildUnlock)
|
|
{
|
|
startTimer = StartCoroutine(StartTimer());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EndOutUpgrade();
|
|
}
|
|
}
|
|
void EndClick()
|
|
{
|
|
IsDowning1 = false;
|
|
if (!IsDowning)
|
|
{
|
|
StopCoroutineTimer();
|
|
if (DownPanel.blocksRaycasts)
|
|
upButtonAni.Play("Normal", -1, 0);
|
|
}
|
|
}
|
|
void StopCoroutineTimer()
|
|
{
|
|
IsDowning1 = false;
|
|
|
|
if (startTimer != null)
|
|
{
|
|
StopCoroutine(startTimer);
|
|
startTimer = null;
|
|
}
|
|
}
|
|
IEnumerator StartTimer()
|
|
{
|
|
kuang.SetActive(false);
|
|
|
|
StopCoroutineTimer();
|
|
IsDowning1 = true;
|
|
|
|
float HoldIntervalGeneral = _table.TbGlobalConfig.HoldIntervalGeneral;
|
|
|
|
yield return new WaitForSeconds(HoldIntervalGeneral);
|
|
buildingSpeed = 1;
|
|
StartOutUpgrade();
|
|
}
|
|
async void PlayFix()
|
|
{
|
|
fixIng = true;
|
|
_playerData.SetGold(_playerData.gold - _upgradeCost);
|
|
GContext.Publish(new ResAddEvent(1002));
|
|
OnUpgradeBuildingFix onUpgradeBuildingFix = new OnUpgradeBuildingFix();
|
|
GContext.Publish(onUpgradeBuildingFix);
|
|
bool fix = await onUpgradeBuildingFix.ts.Task;
|
|
if (fix)
|
|
{
|
|
isdrag = true;
|
|
}
|
|
btn_icon.SetActive(!_campData.IsFix);
|
|
btn_fix.SetActive(_campData.IsFix);
|
|
BuildingData buildingData = new BuildingData();
|
|
buildingData.CurrentPrefab = _campData.CurrentPrefab;
|
|
UpdataData(buildingData);
|
|
UpdateAccount(buildingData);
|
|
UpdateDataInfo(buildingData);
|
|
OnUpgradeComplete(buildingData);
|
|
fixIng = false;
|
|
}
|
|
public bool CheckIsCanUpgrading()
|
|
{
|
|
bool isCanUpgrading = true;
|
|
|
|
|
|
if (_playerData.gold < _upgradeCost)
|
|
{
|
|
GContext.Publish(new VibrationData(HapticTypes.Failure));
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("lack_resources"))
|
|
{
|
|
e.AddContent("item_id", 1002)
|
|
.AddContent("lv", GContext.container.Resolve<PlayerData>().lv);
|
|
}
|
|
#endif
|
|
if (GContext.container.Resolve<PlayerShopData>().IsShopOpen)
|
|
{
|
|
bool isGuide = GContext.container.Resolve<GuideDataCenter>().TriggerGuide(_table.TbGlobalConfig.FixedGuidance, "CampPanel", false);
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_CampPanel_8"));
|
|
}
|
|
else
|
|
{
|
|
GContext.container.Resolve<GuideDataCenter>().TriggerGuide(_table.TbGlobalConfig.FixedGuidance, "CampPanel");
|
|
}
|
|
isCanUpgrading = false;
|
|
}
|
|
return isCanUpgrading;
|
|
}
|
|
|
|
bool OnClickUp()
|
|
{
|
|
if (_campData.AreaIndex >= _campData.AreaList.Count)
|
|
{
|
|
//_campData.ChangeCampId(_campData.NextMapID);
|
|
GameDebug.Log("当前建造达最大等级");
|
|
return false;
|
|
}
|
|
|
|
if (!CheckIsCanUpgrading())
|
|
{
|
|
return false;
|
|
}
|
|
//修复
|
|
if (_campData.IsFix)
|
|
{
|
|
_isUpgrading = true;
|
|
_campData.SetIsFix(false);
|
|
PlayFix();
|
|
return false;
|
|
}
|
|
else if (!fixIng)
|
|
{
|
|
bool isMax = AddBuildingData();
|
|
OnUpgradClick();
|
|
if (isMax)
|
|
{
|
|
EndClick();
|
|
EndOutUpgrade();
|
|
DownPanel.blocksRaycasts = false;
|
|
upButtonAni.Play("Disabled", 0, 0);
|
|
costRoot.gameObject.SetActive(false);
|
|
}
|
|
return !isMax;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void OneBuildingData()
|
|
{
|
|
if (_campData.AreaIndex >= _campData.AreaList.Count)
|
|
{
|
|
//_campData.ChangeCampId(_campData.NextMapID);
|
|
GameDebug.Log("当前建造达最大等级");
|
|
return;
|
|
}
|
|
|
|
if (!CheckIsCanUpgrading())
|
|
{
|
|
upButtonAni.Play("Normal", -1, 0);
|
|
IsDowning = false;
|
|
return;
|
|
}
|
|
if (buildingDatas.Count == 0)
|
|
{
|
|
AddBuildingData();
|
|
}
|
|
}
|
|
|
|
bool AddBuildingData()
|
|
{
|
|
BuildingData buildingData = new BuildingData();
|
|
buildingData.upgradeTime = _upgradeTime;
|
|
buildingData.turnOffTimeScale = _campData.constructionArea?.TurnOffTimeScale ?? 0;
|
|
buildingData.curStep = _campData.AreaStep + 1;
|
|
buildingData.CurrentPrefab = _campData.CurrentPrefab;
|
|
buildingData.areaStepCount = _campData.AreaStepCount;
|
|
buildingDatas.Enqueue(buildingData);
|
|
|
|
_playerData.SetGold(_playerData.gold - _upgradeCost);
|
|
GContext.Publish(new ResAddEvent(1002));
|
|
//_playerData.SetLv(_playerData.lv + 1);
|
|
_campData.NextStep();
|
|
|
|
//CurRewardQCount curRewardQCount = new CurRewardQCount();
|
|
//GContext.Publish(curRewardQCount);
|
|
//buildingData.rewardQCount = DeBugPanel.isShow ? curRewardQCount.count : 0;
|
|
UpdataData(buildingData);
|
|
//UpdateAccount(buildingData);
|
|
//particle.SetActive(false);
|
|
//particle.SetActive(true);
|
|
return buildingData.NextStep == 0;
|
|
}
|
|
|
|
public void OnUpgradClick()
|
|
{
|
|
if (_isUpgrading)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (buildingDatas.Count > 0)
|
|
{
|
|
_isUpgrading = true;
|
|
top_area_canvas.blocksRaycasts = false;
|
|
BuildingData buildingData = buildingDatas.Dequeue();
|
|
|
|
StartCoroutine(Upgrad(buildingData));
|
|
if (isdrag)
|
|
{
|
|
GContext.Publish(new SwitchVirtualCameraEvent() { type = 0, isDrag = _campData.constructionArea?.TurnOffFreeLook != 1 });
|
|
isdrag = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EndOutUpgrade();
|
|
}
|
|
}
|
|
|
|
public IEnumerator Upgrad(BuildingData buildingData)
|
|
{
|
|
if (isdrag)
|
|
{
|
|
yield return Awaiters.Seconds(0.8f);
|
|
}
|
|
//升级
|
|
_playerData.SetLv(_playerData.lv + 1);
|
|
particle.SetActive(false);
|
|
particle.SetActive(true);
|
|
UpdateAccount(buildingData);
|
|
if (buildingData.turnOffTimeScale == 1)
|
|
{
|
|
buildingSpeed = 1;
|
|
}
|
|
GContext.Publish(new VibrationData(HapticTypes.MediumImpact));
|
|
var upgradeEvt = new OnUpgradeBuildingData(EBuildingType.UpgradeBuilding, false);
|
|
upgradeEvt.Speed = buildingSpeed;
|
|
upgradeEvt.NextPrefab = buildingData.NextPrefab;
|
|
upgradeEvt.CurrentPrefab = buildingData.CurrentPrefab;
|
|
GContext.Publish(upgradeEvt);
|
|
var fill_amount_target = (float)(buildingData.curStep) / buildingData.areaStepCount;
|
|
|
|
#if AGG
|
|
|
|
using (var e = GEvent.GameEvent("build_upgrade", gaSend: false))
|
|
{
|
|
e.AddContent("building_id", _campData.Id)
|
|
.AddContent("charge_count", GContext.container.Resolve<PlayerShopData>().GetBuyPaymentAmount())
|
|
.AddContent("is_auto", IsDowning)
|
|
.AddContent("hook_count", _playerData.GetEnergyRM());
|
|
|
|
if (_campData.IsUpdataArea && levelItemDatas != null)
|
|
{
|
|
for (int i = 0; i < levelItemDatas.Count; i++)
|
|
{
|
|
if (levelItemDatas[i].id == 1001)
|
|
{
|
|
e.AddContent("reward_hook", levelItemDatas[i].count);
|
|
}
|
|
else if (levelItemDatas[i].id == 1002)
|
|
{
|
|
e.AddContent("reward_cash", levelItemDatas[i].count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
currentBar.DOFillAmount(fill_amount_target, buildingData.upgradeTime / buildingSpeed);
|
|
|
|
while (!upgradeEvt.CanContinue)
|
|
{
|
|
yield return null;
|
|
}
|
|
text_progress_string = $"{buildingData.curStep}/{buildingData.areaStepCount}";
|
|
text_progress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", text_progress_string);
|
|
if (fill_amount_target > 0.999f)
|
|
{
|
|
camp_target.Play("camp_target");
|
|
//yield return Awaiters.Seconds(1f);
|
|
|
|
//if (levelItemDatas.Count > 1)
|
|
//{
|
|
// for (int i = 1; i < levelItemDatas.Count; i++)
|
|
// {
|
|
// rewardLen--;
|
|
// _ = bg_reward[rewardLen].ParticleAttractor();
|
|
// }
|
|
//}
|
|
//yield return bg_reward[rewardLen - 1].ParticleAttractor().AsIEnumerator();
|
|
}
|
|
OnUpgradeBuildingData upgradeBuildingData = new OnUpgradeBuildingData(EBuildingType.Next);
|
|
upgradeBuildingData.TimelineId = buildingData.NextTimelineId;
|
|
upgradeBuildingData.StartTime = buildingData.NextStartTime;
|
|
upgradeBuildingData.Duration = buildingData.NextDuration;
|
|
upgradeBuildingData.NextPrefab = buildingData.NextPrefab;
|
|
upgradeBuildingData.CurrentPrefab = buildingData.CurrentPrefab;
|
|
GContext.Publish(upgradeBuildingData);
|
|
if (buildingData.curStep == buildingData.areaStepCount)
|
|
{
|
|
_campData.ShowReward();
|
|
yield return Awaiters.Seconds(0.5f);
|
|
}
|
|
UpdateDataInfo(buildingData);
|
|
OnUpgradeComplete(buildingData);
|
|
}
|
|
|
|
|
|
void OnUpgradeComplete(BuildingData buildingData)
|
|
{
|
|
bool guide = GContext.container.Resolve<GuideDataCenter>().IsGuide("CampPanel");
|
|
_isUpgrading = false;
|
|
top_area_canvas.blocksRaycasts = true;
|
|
|
|
CurRewardQCount curRewardQCount = new CurRewardQCount();
|
|
GContext.Publish(curRewardQCount);
|
|
int rewardQCount = DeBugPanel.isShow ? curRewardQCount.count : 0;
|
|
if (rewardQCount > 0)
|
|
{
|
|
upgradeButton.Up();
|
|
return;
|
|
}
|
|
IsShowGuidance isShowGuidance = new IsShowGuidance();
|
|
GContext.Publish(isShowGuidance);
|
|
if (guide || isShowGuidance.isShow)
|
|
{
|
|
upgradeButton.Up();
|
|
EndOutUpgrade();
|
|
}
|
|
if (buildingDatas.Count > 0)
|
|
{
|
|
buildingSpeed += _table.TbGlobalConfig.TapTimeScale;
|
|
float max = 1 + _table.TbGlobalConfig.TapTimeScale * _table.TbGlobalConfig.TapScaleMaxStep;
|
|
if (buildingSpeed > max)
|
|
{
|
|
buildingSpeed = max;
|
|
}
|
|
OnUpgradClick();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
DownPanel.blocksRaycasts = true;
|
|
}
|
|
//如果upgradeButton处于长安状态继续升级
|
|
if (IsDowning || IsDowning1)
|
|
{
|
|
buildingSpeed += _table.TbGlobalConfig.TimeScalePerStep;
|
|
if (buildingSpeed > maxSpeed)
|
|
{
|
|
buildingSpeed = maxSpeed;
|
|
}
|
|
OneBuildingData();
|
|
OnUpgradClick();
|
|
}
|
|
else
|
|
{
|
|
upButtonAni.Play("Normal");
|
|
costRoot.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
async void OnRewardPanelClose(RewardPanelClose data)
|
|
{
|
|
DownPanel.blocksRaycasts = true;
|
|
costRoot.gameObject.SetActive(true);
|
|
await Awaiters.NextFrame;
|
|
bool isGuide = GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("CampPanel");
|
|
if (isGuide)
|
|
{
|
|
EndOutUpgrade();
|
|
return;
|
|
}
|
|
if (!string.IsNullOrEmpty(_campData.constructionArea.PhotoSwitch))
|
|
{
|
|
upgradeButton.Up();
|
|
EndOutUpgrade();
|
|
OnUpgradeBuildingData upgradeBuildingData = new OnUpgradeBuildingData(EBuildingType.CampPhoto);
|
|
GContext.Publish(upgradeBuildingData);
|
|
upButtonAni.Play("Normal");
|
|
return;
|
|
}
|
|
if (IsDowning)
|
|
{
|
|
OneBuildingData();
|
|
OnUpgradClick();
|
|
}
|
|
else
|
|
{
|
|
upButtonAni.Play("Normal");
|
|
}
|
|
if (isCampPanel_fade)
|
|
{
|
|
CampPanel_show2();
|
|
}
|
|
|
|
}
|
|
void StartOutUpgrade()
|
|
{
|
|
kuang.SetActive(true);
|
|
startTimer = null;
|
|
GContext.Publish(new VibrationData(HapticTypes.MediumImpact));
|
|
IsDowning = true;
|
|
|
|
upButtonAni.Play("Pressed", -1, 0);
|
|
|
|
if (GContext.container.Resolve<GuideDataCenter>().curDefine != null &&
|
|
GContext.container.Resolve<GuideDataCenter>().curDefine.fingerType != FingerType.None &&
|
|
GContext.container.Resolve<GuideDataCenter>().curDefine.panelName == "CampPanel")
|
|
{
|
|
OneBuildingData();
|
|
OnUpgradClick();
|
|
}
|
|
GContext.Publish(new GuideNextEvent());
|
|
}
|
|
void EndOutUpgrade()
|
|
{
|
|
if (!DownPanel.blocksRaycasts)
|
|
{
|
|
DownPanel.blocksRaycasts = true;
|
|
}
|
|
upButtonAni.Play("Normal", -1, 0);
|
|
StopCoroutineTimer();
|
|
IsDowning = false;
|
|
}
|
|
async void ToCampSkyscraper()
|
|
{
|
|
if (IsDowning)
|
|
{
|
|
upgradeButton.Up();
|
|
EndOutUpgrade();
|
|
}
|
|
if (_isUpgrading) return;
|
|
canvasGroup.blocksRaycasts = false;
|
|
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Load("InfiniteBuildingAct");
|
|
if (isCanEnter)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct"));
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct")));
|
|
//var panel = await UIManager.Instance.ShowUI(UITypes.FishingDownLoadPopupPanel);
|
|
//panel.GetComponent<FishingDownLoadPopupPanel>().SetBtn(null, () => GContext.Publish(new UnloadActToNextAct("InfiniteBuildingAct")));
|
|
}
|
|
canvasGroup.blocksRaycasts = true;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
GContext.container.Unregister<CampPanel>();
|
|
var userService = GContext.container.Resolve<IUserService>();
|
|
userService.SetPlayerLv(userService.UserId, _playerData.lv);
|
|
userService.UpdateProfileLv();
|
|
}
|
|
#if UNITY_EDITOR
|
|
private void Update()
|
|
{
|
|
if (Input.GetKey(KeyCode.X) && Input.GetKeyDown(KeyCode.Alpha1))
|
|
{
|
|
DeBugPanel.isShow = !DeBugPanel.isShow;
|
|
SetAlpha();
|
|
}
|
|
if (Input.GetKey(KeyCode.F))
|
|
{
|
|
if (!_isUpgrading)
|
|
{
|
|
_campData.SetIsFix(true);
|
|
btn_icon.SetActive(!_campData.IsFix);
|
|
btn_fix.SetActive(_campData.IsFix);
|
|
GContext.Publish(new OnUpgradeBuildingData(EBuildingType.OpenFix));
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|