客户端rsa,冗余清理,bug修复,安卓build问题
This commit is contained in:
@@ -6,6 +6,10 @@ using UnityEngine.EventSystems;
|
||||
|
||||
public class notebookController : MonoBehaviour
|
||||
{
|
||||
private const string NotebookCategoryPrefsKey = "notebook.selected_category";
|
||||
private const string NotebookFatherPrefsKey = "notebook.selected_father_id";
|
||||
private const string NotebookSonPrefsKey = "notebook.selected_son_id";
|
||||
|
||||
[Header("select father types")]
|
||||
public Toggle all_content_beforeAnything_toggle;
|
||||
public Toggle idols_toggle;
|
||||
@@ -53,20 +57,22 @@ public class notebookController : MonoBehaviour
|
||||
private void Start()
|
||||
{
|
||||
Initialize();
|
||||
RestoreNotebookSelectionOrDefault();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Initialize();
|
||||
RestoreNotebookSelectionOrDefault();
|
||||
PlayEnterAnim();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
StoreOwnershipLedger.EnsureInstance().InitializeIfNeeded();
|
||||
LoadAllData();
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
categoryToggles = new[]
|
||||
{
|
||||
all_content_beforeAnything_toggle,
|
||||
@@ -101,9 +107,6 @@ public class notebookController : MonoBehaviour
|
||||
quit_button.onClick.RemoveAllListeners();
|
||||
quit_button.onClick.AddListener(CloseSelf);
|
||||
}
|
||||
if (all_content_beforeAnything_toggle != null)
|
||||
all_content_beforeAnything_toggle.isOn = true;
|
||||
Refresh(notebook_faterType.notebook_fatherType.content);
|
||||
}
|
||||
|
||||
private void BindToggle(Toggle toggle, System.Action onSelected)
|
||||
@@ -176,24 +179,49 @@ public class notebookController : MonoBehaviour
|
||||
private void Refresh(notebook_faterType.notebook_fatherType? type)
|
||||
{
|
||||
if (fatherItem_prefab == null || svContent == null) return;
|
||||
notebook_faterType.notebook_fatherType effectiveType = type ?? LoadSavedCategory();
|
||||
SaveSelectedCategory(effectiveType);
|
||||
ClearContent();
|
||||
var fatherGroup = svContent.GetComponent<ToggleGroup>();
|
||||
if (fatherGroup == categoryToggleGroup) fatherGroup = null;
|
||||
Toggle firstFatherToggle = null;
|
||||
fatherItemPrefab firstFatherComp = null;
|
||||
notebook_faterType firstFatherData = null;
|
||||
Toggle restoredFatherToggle = null;
|
||||
fatherItemPrefab restoredFatherComp = null;
|
||||
notebook_faterType restoredFatherData = null;
|
||||
int savedFatherId = LoadSavedFatherId();
|
||||
for (int i = 0; i < cachedItems.Count; i++)
|
||||
{
|
||||
var so = cachedItems[i];
|
||||
if (so == null) continue;
|
||||
if (!so.isUnlocked) continue;
|
||||
if (type.HasValue && so.fatherType != type.Value) continue;
|
||||
if (so.fatherType != effectiveType) continue;
|
||||
var obj = Instantiate(fatherItem_prefab, svContent.transform);
|
||||
var comp = obj.GetComponent<fatherItemPrefab>();
|
||||
if (comp == null) continue;
|
||||
if (comp.father_name != null) comp.father_name.text = so.class_name;
|
||||
if (comp.father_img != null) comp.father_img.sprite = so.class_image;
|
||||
comp.SetFatherImage(so.class_image);
|
||||
if (comp.father_description != null) comp.father_description.text = so.class_description;
|
||||
SetupFatherItem(comp, so, fatherGroup);
|
||||
if (firstFatherToggle == null)
|
||||
{
|
||||
firstFatherToggle = ResolveFatherToggle(comp);
|
||||
firstFatherComp = comp;
|
||||
firstFatherData = so;
|
||||
}
|
||||
if (restoredFatherToggle == null && so.class_id == savedFatherId)
|
||||
{
|
||||
restoredFatherToggle = ResolveFatherToggle(comp);
|
||||
restoredFatherComp = comp;
|
||||
restoredFatherData = so;
|
||||
}
|
||||
}
|
||||
CacheFatherBasePositions();
|
||||
AutoSelectFather(
|
||||
restoredFatherToggle != null ? restoredFatherToggle : firstFatherToggle,
|
||||
restoredFatherComp != null ? restoredFatherComp : firstFatherComp,
|
||||
restoredFatherData != null ? restoredFatherData : firstFatherData);
|
||||
}
|
||||
|
||||
private void SetupFatherItem(fatherItemPrefab comp, notebook_faterType so, ToggleGroup fatherGroup)
|
||||
@@ -202,16 +230,16 @@ public class notebookController : MonoBehaviour
|
||||
ClearSonContainer(comp);
|
||||
if (comp.son_obj != null) comp.son_obj.SetActive(false);
|
||||
if (comp.son_prefab_toPut != null) comp.son_prefab_toPut.SetActive(false);
|
||||
Toggle toggle = null;
|
||||
if (comp.father_obj != null) toggle = comp.father_obj.GetComponent<Toggle>();
|
||||
if (toggle == null) toggle = comp.GetComponent<Toggle>();
|
||||
if (toggle == null) toggle = comp.GetComponentInChildren<Toggle>(true);
|
||||
if (toggle == null) toggle = comp.GetComponentInParent<Toggle>();
|
||||
Toggle toggle = ResolveFatherToggle(comp);
|
||||
if (toggle == null) return;
|
||||
if (fatherGroup != null) toggle.group = fatherGroup;
|
||||
toggle.onValueChanged.RemoveAllListeners();
|
||||
toggle.onValueChanged.AddListener(isOn =>
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
SaveSelectedFather(so.class_id);
|
||||
}
|
||||
ApplySonState(comp, so, isOn);
|
||||
});
|
||||
ApplySonState(comp, so, toggle.isOn);
|
||||
@@ -223,6 +251,7 @@ public class notebookController : MonoBehaviour
|
||||
int token = NextAnimToken(comp);
|
||||
if (isOn)
|
||||
{
|
||||
ClearSonDetails();
|
||||
EnsureSonsLoaded(comp, so);
|
||||
UpdateFatherSpacer(comp, so, true, token);
|
||||
FadeSonContainer(comp, true, token, null);
|
||||
@@ -234,6 +263,23 @@ public class notebookController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearSonDetails()
|
||||
{
|
||||
if (detailsImage != null)
|
||||
{
|
||||
detailsImage.sprite = null;
|
||||
detailsImage.enabled = false;
|
||||
}
|
||||
if (passage_title != null)
|
||||
{
|
||||
passage_title.text = string.Empty;
|
||||
}
|
||||
if (passage_text != null)
|
||||
{
|
||||
passage_text.text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureSonsLoaded(fatherItemPrefab comp, notebook_faterType so)
|
||||
{
|
||||
if (comp == null || so == null) return;
|
||||
@@ -245,6 +291,11 @@ public class notebookController : MonoBehaviour
|
||||
ToggleGroup sonGroup = null;
|
||||
if (comp.son_prefab_toPut != null) sonGroup = comp.son_prefab_toPut.GetComponent<ToggleGroup>();
|
||||
if (sonGroup == null && comp.son_obj != null) sonGroup = comp.son_obj.GetComponent<ToggleGroup>();
|
||||
Dictionary<Toggle, int> sonIdByToggle = new Dictionary<Toggle, int>();
|
||||
Dictionary<int, notebook_faterType.notebook_sonClass> sonById = new Dictionary<int, notebook_faterType.notebook_sonClass>();
|
||||
Toggle firstSonToggle = null;
|
||||
notebook_faterType.notebook_sonClass firstUnlockedSon = null;
|
||||
bool appliedSelectedSon = false;
|
||||
for (int i = 0; i < so.sonList.Count; i++)
|
||||
{
|
||||
var son = so.sonList[i];
|
||||
@@ -257,26 +308,92 @@ public class notebookController : MonoBehaviour
|
||||
if (sonToggle == null) sonToggle = obj.GetComponent<Toggle>();
|
||||
if (sonToggle == null) sonToggle = obj.GetComponentInChildren<Toggle>(true);
|
||||
if (sonGroup != null && sonToggle != null) sonToggle.group = sonGroup;
|
||||
if (firstSonToggle == null && sonToggle != null)
|
||||
{
|
||||
firstSonToggle = sonToggle;
|
||||
firstUnlockedSon = son;
|
||||
}
|
||||
if (sonToggle != null)
|
||||
{
|
||||
sonIdByToggle[sonToggle] = son.son_id;
|
||||
}
|
||||
if (!sonById.ContainsKey(son.son_id))
|
||||
{
|
||||
sonById.Add(son.son_id, son);
|
||||
}
|
||||
if (sonComp == null) continue;
|
||||
if (sonComp.sonName != null) sonComp.sonName.text = son.son_name;
|
||||
if (sonComp.sonDescription != null) sonComp.sonDescription.text = son.son_description;
|
||||
if (sonComp.sonImage != null) sonComp.sonImage.sprite = son.son_image;
|
||||
sonComp.SetSonImage(son.son_image);
|
||||
if (sonToggle != null)
|
||||
{
|
||||
sonToggle.onValueChanged.RemoveAllListeners();
|
||||
sonToggle.onValueChanged.AddListener(isOn =>
|
||||
{
|
||||
if (isOn) ApplySonDetails(son);
|
||||
if (isOn)
|
||||
{
|
||||
ApplySonDetails(so, son);
|
||||
}
|
||||
});
|
||||
if (sonToggle.isOn) ApplySonDetails(son);
|
||||
if (sonToggle.isOn)
|
||||
{
|
||||
ApplySonDetails(so, son);
|
||||
appliedSelectedSon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!appliedSelectedSon)
|
||||
{
|
||||
int savedSonId = LoadSavedSonId();
|
||||
Toggle restoredSonToggle = null;
|
||||
notebook_faterType.notebook_sonClass restoredSon = null;
|
||||
if (savedSonId > 0)
|
||||
{
|
||||
foreach (KeyValuePair<Toggle, int> pair in sonIdByToggle)
|
||||
{
|
||||
if (pair.Key == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pair.Value == savedSonId)
|
||||
{
|
||||
restoredSonToggle = pair.Key;
|
||||
sonById.TryGetValue(savedSonId, out restoredSon);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (restoredSonToggle != null && restoredSon != null)
|
||||
{
|
||||
SelectSon(restoredSonToggle, so, restoredSon);
|
||||
}
|
||||
else if (firstSonToggle != null && firstUnlockedSon != null)
|
||||
{
|
||||
SelectSon(firstSonToggle, so, firstUnlockedSon);
|
||||
}
|
||||
else if (firstUnlockedSon != null)
|
||||
{
|
||||
ApplySonDetails(so, firstUnlockedSon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySonDetails(notebook_faterType.notebook_sonClass son)
|
||||
private void ApplySonDetails(notebook_faterType father, notebook_faterType.notebook_sonClass son)
|
||||
{
|
||||
if (son == null) return;
|
||||
if (detailsImage != null) detailsImage.sprite = son.son_image;
|
||||
if (father != null)
|
||||
{
|
||||
SaveSelectedFather(father.class_id);
|
||||
}
|
||||
SaveSelectedSon(son.son_id);
|
||||
if (detailsImage != null)
|
||||
{
|
||||
detailsImage.sprite = son.son_detailsImage;
|
||||
detailsImage.enabled = son.son_detailsImage != null;
|
||||
}
|
||||
if (passage_title != null) passage_title.text = son.son_title;
|
||||
if (passage_text != null) passage_text.text = son.son_passage;
|
||||
}
|
||||
@@ -521,4 +638,189 @@ public class notebookController : MonoBehaviour
|
||||
fatherBaseAnchors.Clear();
|
||||
fatherSpacers.Clear();
|
||||
}
|
||||
|
||||
private Toggle ResolveFatherToggle(fatherItemPrefab comp)
|
||||
{
|
||||
if (comp == null) return null;
|
||||
Toggle toggle = null;
|
||||
if (comp.father_obj != null) toggle = comp.father_obj.GetComponent<Toggle>();
|
||||
if (toggle == null) toggle = comp.GetComponent<Toggle>();
|
||||
if (toggle == null) toggle = comp.GetComponentInChildren<Toggle>(true);
|
||||
if (toggle == null) toggle = comp.GetComponentInParent<Toggle>();
|
||||
return toggle;
|
||||
}
|
||||
|
||||
private void AutoSelectFather(Toggle targetFatherToggle, fatherItemPrefab targetFatherComp, notebook_faterType targetFatherData)
|
||||
{
|
||||
if (targetFatherToggle == null || targetFatherComp == null || targetFatherData == null)
|
||||
{
|
||||
ClearSonDetails();
|
||||
return;
|
||||
}
|
||||
|
||||
targetFatherToggle.SetIsOnWithoutNotify(true);
|
||||
SaveSelectedFather(targetFatherData.class_id);
|
||||
ApplySonState(targetFatherComp, targetFatherData, true);
|
||||
}
|
||||
|
||||
private void RestoreNotebookSelectionOrDefault()
|
||||
{
|
||||
notebook_faterType.notebook_fatherType savedCategory = ResolveInitialCategory();
|
||||
SaveSelectedCategory(savedCategory);
|
||||
Toggle targetToggle = GetCategoryToggle(savedCategory);
|
||||
if (targetToggle != null)
|
||||
{
|
||||
SetCategorySelectionWithoutNotify(savedCategory);
|
||||
Refresh(savedCategory);
|
||||
return;
|
||||
}
|
||||
|
||||
if (all_content_beforeAnything_toggle != null)
|
||||
{
|
||||
SetCategorySelectionWithoutNotify(notebook_faterType.notebook_fatherType.content);
|
||||
Refresh(notebook_faterType.notebook_fatherType.content);
|
||||
return;
|
||||
}
|
||||
|
||||
Refresh(notebook_faterType.notebook_fatherType.content);
|
||||
}
|
||||
|
||||
private notebook_faterType.notebook_fatherType ResolveInitialCategory()
|
||||
{
|
||||
notebook_faterType.notebook_fatherType savedCategory = LoadSavedCategory();
|
||||
if (HasVisibleFatherForCategory(savedCategory))
|
||||
{
|
||||
return savedCategory;
|
||||
}
|
||||
|
||||
return notebook_faterType.notebook_fatherType.content;
|
||||
}
|
||||
|
||||
private bool HasVisibleFatherForCategory(notebook_faterType.notebook_fatherType category)
|
||||
{
|
||||
for (int i = 0; i < cachedItems.Count; i++)
|
||||
{
|
||||
notebook_faterType item = cachedItems[i];
|
||||
if (item == null || !item.isUnlocked)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.fatherType == category)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Toggle GetCategoryToggle(notebook_faterType.notebook_fatherType category)
|
||||
{
|
||||
switch (category)
|
||||
{
|
||||
case notebook_faterType.notebook_fatherType.content:
|
||||
return all_content_beforeAnything_toggle;
|
||||
case notebook_faterType.notebook_fatherType.idols:
|
||||
return idols_toggle;
|
||||
case notebook_faterType.notebook_fatherType.enemies:
|
||||
return enemies_toggle;
|
||||
case notebook_faterType.notebook_fatherType.organizations:
|
||||
return organizations_toggle;
|
||||
case notebook_faterType.notebook_fatherType.areas:
|
||||
return areas_toggle;
|
||||
case notebook_faterType.notebook_fatherType.terminologies:
|
||||
return terminologies_toggle;
|
||||
case notebook_faterType.notebook_fatherType.Logs:
|
||||
return Logs_toggle;
|
||||
default:
|
||||
return all_content_beforeAnything_toggle;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCategorySelectionWithoutNotify(notebook_faterType.notebook_fatherType category)
|
||||
{
|
||||
if (categoryToggles == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < categoryToggles.Length; i++)
|
||||
{
|
||||
Toggle toggle = categoryToggles[i];
|
||||
if (toggle == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool shouldBeOn = toggle == GetCategoryToggle(category);
|
||||
toggle.SetIsOnWithoutNotify(shouldBeOn);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveSelectedCategory(notebook_faterType.notebook_fatherType category)
|
||||
{
|
||||
PlayerPrefs.SetInt(NotebookCategoryPrefsKey, (int)category);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
private notebook_faterType.notebook_fatherType LoadSavedCategory()
|
||||
{
|
||||
int defaultValue = (int)notebook_faterType.notebook_fatherType.content;
|
||||
int raw = PlayerPrefs.GetInt(NotebookCategoryPrefsKey, defaultValue);
|
||||
if (!System.Enum.IsDefined(typeof(notebook_faterType.notebook_fatherType), raw))
|
||||
{
|
||||
raw = defaultValue;
|
||||
}
|
||||
|
||||
notebook_faterType.notebook_fatherType category = (notebook_faterType.notebook_fatherType)raw;
|
||||
if (category == notebook_faterType.notebook_fatherType.none)
|
||||
{
|
||||
category = notebook_faterType.notebook_fatherType.content;
|
||||
}
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
private void SaveSelectedFather(int fatherId)
|
||||
{
|
||||
if (fatherId <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerPrefs.SetInt(NotebookFatherPrefsKey, fatherId);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
private int LoadSavedFatherId()
|
||||
{
|
||||
return PlayerPrefs.GetInt(NotebookFatherPrefsKey, -1);
|
||||
}
|
||||
|
||||
private void SaveSelectedSon(int sonId)
|
||||
{
|
||||
if (sonId <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerPrefs.SetInt(NotebookSonPrefsKey, sonId);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
private int LoadSavedSonId()
|
||||
{
|
||||
return PlayerPrefs.GetInt(NotebookSonPrefsKey, -1);
|
||||
}
|
||||
|
||||
private void SelectSon(Toggle toggle, notebook_faterType father, notebook_faterType.notebook_sonClass son)
|
||||
{
|
||||
if (toggle != null)
|
||||
{
|
||||
toggle.SetIsOnWithoutNotify(true);
|
||||
}
|
||||
|
||||
ApplySonDetails(father, son);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user