private static void ApplyLanguagePrenetation(PresentationParamater parameter, LanguageInfo languageInfo, LanguageItem languageItem, Type itemType, PresentationSite presentationSite, PresentationData presentationData, List <Change> changes, string title) { object data = null; if (languageInfo.LanguageDatas.ContainsKey(languageItem.Id)) { data = languageInfo.LanguageDatas[languageItem.Id]; } Presentation presentation = parameter.FortInspector.GetResolver() .Resolve(new PresentationResolverParameter(itemType, data, presentationSite)); object languagePresentationData = null; if (presentationData.LanguagePresentationData.ContainsKey(languageInfo.Id)) { languagePresentationData = presentationData.LanguagePresentationData[languageInfo.Id]; } PresentationResult presentationResult = presentation.OnInspectorGui(new PresentationParamater(data, languagePresentationData, title, itemType, presentationSite, parameter.FortInspector)); changes.Add(presentationResult.Change); languageInfo.LanguageDatas[languageItem.Id] = presentationResult.Result; presentationData.LanguagePresentationData[languageInfo.Id] = presentationResult.PresentationData; }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { string[] valueDefenitions = (((string[])parameter.Instance) ?? new string[0]).ToArray(); PresentationResult presentationResult = base.OnInspectorGui(parameter); string[] newValueDefenitions = (string[])presentationResult.Result; if (!presentationResult.Change.IsDataChanged && presentationResult.Change.ChildrenChange.Any(change => change.IsDataChanged)) { Balance[] balances = TypeHelper.FindType(parameter.FortInspector.Targer, typeof(Balance)).Cast <Balance>().ToArray(); for (int i = 0; i < presentationResult.Change.ChildrenChange.Length; i++) { if (presentationResult.Change.ChildrenChange[i].IsDataChanged) { foreach (Balance balance in balances) { balance.SyncValueKey(valueDefenitions[i], newValueDefenitions[i]); } } } } return(presentationResult); }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { GUIStyle guiStyle = new GUIStyle(); Change change = new Change(); object presentationData = parameter.PresentationData; AchievementsPresentationData achievementPresentationData; if (presentationData != null && !((presentationData) is AchievementsPresentationData)) { presentationData = null; } if (presentationData != null) { achievementPresentationData = (AchievementsPresentationData)presentationData; _isFoldout = achievementPresentationData.IsFoldout; } else { achievementPresentationData = new AchievementsPresentationData { IsFoldout = _isFoldout }; } achievementPresentationData.IsFoldout = EditorGUILayout.Foldout(_isFoldout, "Achievements"); change.IsPresentationChanged |= _isFoldout != achievementPresentationData.IsFoldout; _isFoldout = achievementPresentationData.IsFoldout; AchievementInfo[] achievementInfos = (AchievementInfo[])parameter.Instance; if (achievementInfos == null) { achievementInfos = new AchievementInfo[0]; } EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); if (_isFoldout) { ConcretePresentation[] concretePresentations = _concretePresentations; _concretePresentations = new ConcretePresentation[achievementInfos.Length]; object[] innerPresentationData = achievementPresentationData.InnerPresentationData; achievementPresentationData.InnerPresentationData = new object[achievementInfos.Length]; for (int i = 0; i < achievementInfos.Length; i++) { if (i < innerPresentationData.Length) { achievementPresentationData.InnerPresentationData[i] = innerPresentationData[i]; } } for (int i = 0; i < _concretePresentations.Length; i++) { if (i < concretePresentations.Length) { _concretePresentations[i] = concretePresentations[i]; } if (_concretePresentations[i] == null) { _concretePresentations[i] = new ConcretePresentation(); } } change.ChildrenChange = new Change[achievementInfos.Length]; for (int i = 0; i < achievementInfos.Length; i++) { PresentationParamater concreteParamater = new PresentationParamater(achievementInfos[i], achievementPresentationData.InnerPresentationData[i], achievementInfos[i].GetType().Name, typeof(AchievementInfo), new PresentationSite { BaseSite = parameter.PresentationSite, Base = parameter.Instance, BasePresentation = this, SiteType = PresentationSiteType.None }, parameter.FortInspector); PresentationResult presentationResult = _concretePresentations[i].OnInspectorGui(concreteParamater); change.ChildrenChange[i] = presentationResult.Change; achievementPresentationData.InnerPresentationData[i] = presentationResult.PresentationData; achievementInfos[i] = (AchievementInfo)presentationResult.Result; } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); return(new PresentationResult { Change = change, PresentationData = achievementPresentationData, Result = achievementInfos }); }
private static Change ApplyOvveriededLanguageItem(PresentationParamater parameter, LanguageItem languageItem, Type itemType, PresentationSite presentationSite, PresentationData presentationData) { GUIStyle guiStyle = new GUIStyle(); Change change = new Change(); List <Change> changes = new List <Change>(); LanguageEditorInfo languageEditorInfo = EditorInfoResolver.Resolve <LanguageEditorInfo>(); LanguageInfo[] languageInfos = languageEditorInfo.Languages.Where(info => info != null).ToArray(); IInfoLanguageItem infoLanguageItem = (IInfoLanguageItem)languageItem; if (languageInfos.Length == 1) { if (!infoLanguageItem.UseOverridedValue) { change.IsDataChanged = true; //Remove Item From Languages foreach (LanguageInfo languageInfo in languageEditorInfo.Languages) { if (languageInfo.LanguageDatas.ContainsKey(languageItem.Id)) { languageInfo.LanguageDatas.Remove(languageItem.Id); } } } infoLanguageItem.UseOverridedValue = true; Presentation presentation = parameter.FortInspector.GetResolver() .Resolve(new PresentationResolverParameter(itemType, infoLanguageItem.GetOvverideValue(), presentationSite)); PresentationResult presentationResult = presentation.OnInspectorGui(new PresentationParamater(infoLanguageItem.GetOvverideValue(), presentationData.OvverideItemPresentationData, parameter.Title, itemType, presentationSite, parameter.FortInspector)); infoLanguageItem.SetOvverideValue(presentationResult.Result); presentationData.OvverideItemPresentationData = presentationResult.PresentationData; change.ChildrenChange = new[] { presentationResult.Change }; languageEditorInfo.SyncFortAndSave(false); } else { bool oldFoldout = presentationData.IsFoldout; presentationData.IsFoldout = EditorGUILayout.Foldout(presentationData.IsFoldout, parameter.Title); change.IsPresentationChanged = oldFoldout != presentationData.IsFoldout; if (presentationData.IsFoldout) { EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); bool oldUseOverridedValue = infoLanguageItem.UseOverridedValue; infoLanguageItem.UseOverridedValue = EditorGUILayout.Toggle("Ovveride", infoLanguageItem.UseOverridedValue); change.IsDataChanged |= oldUseOverridedValue != infoLanguageItem.UseOverridedValue; if (infoLanguageItem.UseOverridedValue) { Presentation presentation = parameter.FortInspector.GetResolver() .Resolve(new PresentationResolverParameter(itemType, infoLanguageItem.GetOvverideValue(), presentationSite)); PresentationResult presentationResult = presentation.OnInspectorGui(new PresentationParamater(infoLanguageItem.GetOvverideValue(), presentationData.OvverideItemPresentationData, parameter.Title, itemType, presentationSite, parameter.FortInspector)); infoLanguageItem.SetOvverideValue(presentationResult.Result); presentationData.OvverideItemPresentationData = presentationResult.PresentationData; change.ChildrenChange = new[] { presentationResult.Change }; languageEditorInfo.SyncFortAndSave(false); } else { infoLanguageItem.SetOvverideValue(itemType.GetDefault()); foreach (LanguageInfo languageInfo in languageInfos) { ApplyLanguagePrenetation(parameter, languageInfo, languageItem, itemType, presentationSite, presentationData, changes, languageInfo.Name); Change last = changes.Last(); if (last.IsAnyDataChanged()) { for (int i = 0; i < InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages.Length; i++) { if (InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages[i].Id == languageInfo.Id) { InfoResolver.Resolve <FortInfo>().Language.ActiveLanguages[i] = languageInfo; } } if (InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage != null && InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage.Id == languageInfo.Id) { InfoResolver.Resolve <FortInfo>().Language.DefaultLanguage = languageInfo; } } } if (changes.Any(change1 => change1.IsAnyDataChanged())) { languageEditorInfo.Save(); InfoResolver.Resolve <FortInfo>().Save(); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } change.ChildrenChange = changes.ToArray(); } return(change); }
public override PresentationResult OnInspectorGui(PresentationParamater parameter) { GUIStyle guiStyle = new GUIStyle(); EditorGUILayout.BeginVertical(guiStyle); Change change = new Change(); BalancePresentationData balancePresentationData = parameter.PresentationData as BalancePresentationData ?? new BalancePresentationData(); bool isFoldout = balancePresentationData.IsFoldout; balancePresentationData.IsFoldout = EditorGUILayout.Foldout(balancePresentationData.IsFoldout, parameter.Title); change.IsPresentationChanged = isFoldout != balancePresentationData.IsFoldout; Balance balance = (Balance)parameter.Instance; if (balance == null) { balance = new Balance(); } balance.SyncValues(); Dictionary <string, int> values = balance.Values; NumberPresentation[] numberPresentations = _numberPresentations; _numberPresentations = new NumberPresentation[values.Count]; KeyValuePair <string, int>[] pairs = values.ToArray(); if (balancePresentationData.IsFoldout) { change.ChildrenChange = new Change[_numberPresentations.Length]; for (int i = 0; i < _numberPresentations.Length; i++) { if (i < numberPresentations.Length) { _numberPresentations[i] = numberPresentations[i]; } PresentationParamater presentationParamater = new PresentationParamater(pairs[i].Value, null, pairs[i].Key, typeof(int), new PresentationSite { Base = parameter.Instance, BaseSite = parameter.PresentationSite, BasePresentation = this, SiteType = PresentationSiteType.None }, parameter.FortInspector); if (_numberPresentations[i] == null) { _numberPresentations[i] = new NumberPresentation(); } EditorGUILayout.BeginHorizontal(guiStyle); GUILayout.Space(FortInspector.ItemSpacing); EditorGUILayout.BeginVertical(guiStyle); PresentationResult presentationResult = _numberPresentations[i].OnInspectorGui(presentationParamater); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); change.ChildrenChange[i] = presentationResult.Change; values[pairs[i].Key] = (int)presentationResult.Result; } } EditorGUILayout.EndVertical(); return(new PresentationResult { Change = change, PresentationData = balancePresentationData, Result = balance }); }