ObjectCreateWindow.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using I2.Loc;
  5. using UnityEngine;
  6. using wf;
  7. public class ObjectCreateWindow : BaseMaidPhotoWindow
  8. {
  9. public static string folder_path
  10. {
  11. get
  12. {
  13. string text = PhotoWindowManager.path_photo_folder + "MyObject";
  14. if (!Directory.Exists(text))
  15. {
  16. Directory.CreateDirectory(text);
  17. }
  18. return text;
  19. }
  20. }
  21. public bool visibleTextureSelectWindow
  22. {
  23. get
  24. {
  25. return this.textureSelectSubtWindow.visible;
  26. }
  27. set
  28. {
  29. this.textureSelectSubtWindow.visible = value;
  30. }
  31. }
  32. public override void Awake()
  33. {
  34. base.Awake();
  35. EventDelegate.Add(this.selectTextureButton.onClick, new EventDelegate.Callback(this.OnClickSelectTextureButton));
  36. if (this.typeSelectPopupList != null)
  37. {
  38. EventDelegate.Add(this.typeSelectPopupList.onChange, delegate()
  39. {
  40. if (this.selectData == this.target_list_[0])
  41. {
  42. GameObject parent = GameObject.Find("CustomObjectPrev");
  43. GameObject gameObject3 = null;
  44. if (UIPopupList.current.value.IndexOf("プレーン") != -1 && this.selectData.customObject.type != BasePhotoCustomObject.Type.Plane)
  45. {
  46. gameObject3 = Utility.CreatePrefab(parent, "ScenePhotoMode/CustomObject/Plane", false);
  47. }
  48. else if (UIPopupList.current.value.IndexOf("スフィア") != -1 && this.selectData.customObject.type != BasePhotoCustomObject.Type.Sphere)
  49. {
  50. gameObject3 = Utility.CreatePrefab(parent, "ScenePhotoMode/CustomObject/Sphere", false);
  51. }
  52. if (gameObject3 != null)
  53. {
  54. int key = -1;
  55. foreach (KeyValuePair<int, BasePhotoCustomObject> keyValuePair in this.buttonDic)
  56. {
  57. if (keyValuePair.Value == this.selectData.customObject)
  58. {
  59. key = keyValuePair.Key;
  60. break;
  61. }
  62. }
  63. BasePhotoCustomObject component3 = gameObject3.GetComponent<BasePhotoCustomObject>();
  64. ObjectCreateWindow.Data value = new ObjectCreateWindow.Data(component3);
  65. this.target_list_[0] = value;
  66. this.buttonDic[key] = component3;
  67. UnityEngine.Object.DestroyImmediate(this.selectData.customObject.gameObject);
  68. this.selectData = null;
  69. this.selectData = value;
  70. this.UpdateObjectEditUI(this.selectData);
  71. }
  72. }
  73. });
  74. }
  75. this.editScaleSlider.ResetValue();
  76. this.editScaleSlider.onChangeValue.Add(delegate(float val)
  77. {
  78. if (this.selectData != null)
  79. {
  80. this.selectData.customObject.scale = val;
  81. }
  82. });
  83. this.texColorPalette.onChangeValue.Add(delegate(WindowPartsInputColorrPalette colorInputs, Color setColor)
  84. {
  85. if (this.selectData != null)
  86. {
  87. this.selectData.customObject.textureColor = setColor;
  88. }
  89. });
  90. EventDelegate.Add(this.planeBackDrawPopupList.onChange, delegate()
  91. {
  92. if (this.selectData != null && this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
  93. {
  94. PhotoCustomObjectPlane.BackRenderingType backRenderingType = PhotoCustomObjectPlane.BackRenderingType.Mirror;
  95. if (UIPopupList.current.value.IndexOf("反転") == 0)
  96. {
  97. backRenderingType = PhotoCustomObjectPlane.BackRenderingType.Flip;
  98. }
  99. else if (UIPopupList.current.value.IndexOf("透明") == 0)
  100. {
  101. backRenderingType = PhotoCustomObjectPlane.BackRenderingType.None;
  102. }
  103. (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType = backRenderingType;
  104. }
  105. });
  106. EventDelegate.Add(this.sphereBackDrawPopupList.onChange, delegate()
  107. {
  108. if (this.selectData != null && this.selectData.customObject.type == BasePhotoCustomObject.Type.Sphere)
  109. {
  110. PhotoCustomObjectSphere.RenderingType renderingType = PhotoCustomObjectSphere.RenderingType.TwoSides;
  111. if (UIPopupList.current.value.IndexOf("表面表示") == 0)
  112. {
  113. renderingType = PhotoCustomObjectSphere.RenderingType.Front;
  114. }
  115. else if (UIPopupList.current.value.IndexOf("裏面表示") == 0)
  116. {
  117. renderingType = PhotoCustomObjectSphere.RenderingType.Back;
  118. }
  119. (this.selectData.customObject as PhotoCustomObjectSphere).renderingType = renderingType;
  120. }
  121. });
  122. this.camera_move_support_ = base.gameObject.AddComponent<WfCameraMoveSupport>();
  123. this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.objectListGrid.transform);
  124. EventDelegate.Add(this.saveButton.onClick, new EventDelegate.Callback(this.OnClickSave));
  125. EventDelegate.Add(this.textureRestoreButton.onClick, new EventDelegate.Callback(this.OnClickTextureRestore));
  126. this.CheckPrevVisible.check = false;
  127. this.CheckPrevVisible.onClick.Add(delegate(WFCheckBox check_box)
  128. {
  129. if (this.selectData != null)
  130. {
  131. this.selectData.customObject.visible = check_box.check;
  132. }
  133. });
  134. this.textureSelectSubtWindow.GetButtonOnClickEventList(BasePhotoSubWindow.BtnType.End).Add(delegate
  135. {
  136. this.visibleTextureSelectWindow = false;
  137. });
  138. this.textureSelectSubtWindow.SetButtonEnabled(BasePhotoSubWindow.BtnType.End, true, false);
  139. GameObject gameObject = GameObject.Find("CustomObjectPrev");
  140. if (gameObject == null)
  141. {
  142. gameObject = new GameObject("CustomObjectPrev");
  143. }
  144. gameObject.transform.localPosition = new Vector3(0f, 1.5f, -0.8f);
  145. GameObject gameObject2 = Utility.CreatePrefab(gameObject, "ScenePhotoMode/CustomObject/Plane", false);
  146. BasePhotoCustomObject component = gameObject2.GetComponent<BasePhotoCustomObject>();
  147. this.target_list_.Add(new ObjectCreateWindow.Data(component));
  148. UIWFTabButton uiwftabButton = this.CreateTabButton(this.objectListGrid.gameObject, component, "新規オブジェクト");
  149. Localize componentInChildren = uiwftabButton.GetComponentInChildren<Localize>();
  150. if (componentInChildren != null)
  151. {
  152. componentInChildren.SetTerm("ScenePhotoMode/マイオブジェ/新規オブジェクト");
  153. }
  154. Action<string, List<string>> action = delegate(string path, List<string> result_list)
  155. {
  156. string[] files = Directory.GetFiles(path);
  157. for (int i = 0; i < files.Length; i++)
  158. {
  159. if (Path.GetExtension(files[i]) == ".poj")
  160. {
  161. result_list.Add(files[i]);
  162. }
  163. }
  164. };
  165. List<string> list = new List<string>();
  166. action(ObjectCreateWindow.folder_path, list);
  167. foreach (string text in list)
  168. {
  169. BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(gameObject, text);
  170. if (!(basePhotoCustomObject == null))
  171. {
  172. this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, text));
  173. this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, text);
  174. }
  175. }
  176. foreach (ObjectCreateWindow.Data data in this.target_list_)
  177. {
  178. data.customObject.visible = false;
  179. }
  180. UIWFTabPanel component2 = this.objectListGrid.GetComponent<UIWFTabPanel>();
  181. component2.UpdateChildren();
  182. component2.Select(this.objectListGrid.GetChild(0).gameObject.GetComponent<UIWFTabButton>());
  183. Utility.ResetNGUI(this.objectListGrid);
  184. Utility.ResetNGUI(this.scroll_view_);
  185. this.UpdateChildren();
  186. }
  187. public override void Start()
  188. {
  189. base.Start();
  190. this.visibleTextureSelectWindow = false;
  191. }
  192. private void OnDestroy()
  193. {
  194. }
  195. public void OnClickSelectTextureButton()
  196. {
  197. this.visibleTextureSelectWindow = !this.visibleTextureSelectWindow;
  198. }
  199. public void OnChangeSelectTexture(string pngPath)
  200. {
  201. this.textureExpTextObject.SetActive(false);
  202. if (!string.IsNullOrEmpty(this.selectData.fullPath) && this.selectData.backupPng == null)
  203. {
  204. byte[] imageBinarys = this.selectData.customObject.imageBinarys;
  205. this.selectData.backupPng = new byte[imageBinarys.Length];
  206. Array.Copy(imageBinarys, this.selectData.backupPng, imageBinarys.Length);
  207. this.textureRestoreButton.isEnabled = true;
  208. }
  209. this.selectData.customObject.SetTexture(pngPath);
  210. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  211. Sprite sprite2D = Sprite.Create(this.selectData.customObject.mainTexture, new Rect(0f, 0f, (float)this.selectData.customObject.mainTexture.width, (float)this.selectData.customObject.mainTexture.height), default(Vector2));
  212. componentInChildren.sprite2D = sprite2D;
  213. }
  214. private void UpdateObjectEditUI(ObjectCreateWindow.Data targetData)
  215. {
  216. if (targetData == null)
  217. {
  218. return;
  219. }
  220. if (this.typeSelectPopupList != null)
  221. {
  222. this.typeSelectPopupList.value = ((targetData.customObject.type != BasePhotoCustomObject.Type.Plane) ? "スフィア" : "プレーン");
  223. this.typeSelectPopupList.GetComponent<UIButton>().isEnabled = (targetData == this.target_list_[0]);
  224. }
  225. UILabel componentInChildren = this.saveButton.GetComponentInChildren<UILabel>();
  226. Localize component = componentInChildren.GetComponent<Localize>();
  227. if (!string.IsNullOrEmpty(targetData.fullPath))
  228. {
  229. componentInChildren.text = "更新";
  230. if (component != null)
  231. {
  232. component.SetTerm("ScenePhotoMode/マイオブジェ/更新");
  233. }
  234. this.textureExpTextObject.SetActive(false);
  235. }
  236. else
  237. {
  238. componentInChildren.text = "保存";
  239. if (component != null)
  240. {
  241. component.SetTerm("ScenePhotoMode/マイオブジェ/保存");
  242. }
  243. if (targetData.customObject.mainTexture != null)
  244. {
  245. this.textureExpTextObject.SetActive(false);
  246. }
  247. else
  248. {
  249. this.textureExpTextObject.SetActive(true);
  250. }
  251. }
  252. this.textureRestoreButton.gameObject.SetActive(!string.IsNullOrEmpty(targetData.fullPath));
  253. this.textureRestoreButton.isEnabled = (targetData.backupPng != null);
  254. foreach (ObjectCreateWindow.Data data in this.target_list_)
  255. {
  256. data.customObject.visible = (data == targetData && this.CheckPrevVisible.check);
  257. }
  258. BasePhotoCustomObject customObject = targetData.customObject;
  259. UI2DSprite componentInChildren2 = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  260. if (customObject.mainTexture != null)
  261. {
  262. Sprite sprite2D = Sprite.Create(customObject.mainTexture, new Rect(0f, 0f, (float)customObject.mainTexture.width, (float)customObject.mainTexture.height), default(Vector2));
  263. componentInChildren2.sprite2D = sprite2D;
  264. }
  265. else
  266. {
  267. componentInChildren2.sprite2D = null;
  268. }
  269. this.editScaleSlider.value = customObject.scale;
  270. this.texColorPalette.ColorPalette.SetColor(customObject.textureColor);
  271. this.texColorPalette.ColorPalette.UIUpdate();
  272. this.planeUIParent.SetActive(false);
  273. this.sphereUIParent.SetActive(false);
  274. if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
  275. {
  276. this.planeUIParent.SetActive(true);
  277. PhotoCustomObjectPlane.BackRenderingType backRenderingType = (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType;
  278. this.planeBackDrawPopupList.value = ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.Flip) ? ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.None) ? "鏡合わせ" : "透明") : "反転");
  279. }
  280. else if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Sphere)
  281. {
  282. this.sphereUIParent.SetActive(true);
  283. PhotoCustomObjectSphere.RenderingType renderingType = (this.selectData.customObject as PhotoCustomObjectSphere).renderingType;
  284. this.sphereBackDrawPopupList.value = ((renderingType != PhotoCustomObjectSphere.RenderingType.TwoSides) ? ((renderingType != PhotoCustomObjectSphere.RenderingType.Front) ? "裏面表示" : "表面表示") : "両面表示");
  285. }
  286. }
  287. public void OnSelectItem(BasePhotoCustomObject select)
  288. {
  289. foreach (ObjectCreateWindow.Data data in this.target_list_)
  290. {
  291. if (data.customObject == select)
  292. {
  293. this.selectData = data;
  294. this.UpdateObjectEditUI(this.selectData);
  295. break;
  296. }
  297. }
  298. }
  299. public void OnClickTextureRestore()
  300. {
  301. if (this.selectData == null || this.selectData.backupPng == null)
  302. {
  303. return;
  304. }
  305. this.selectData.customObject.SetTexture(this.selectData.backupPng);
  306. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  307. Sprite sprite2D = Sprite.Create(this.selectData.customObject.mainTexture, new Rect(0f, 0f, (float)this.selectData.customObject.mainTexture.width, (float)this.selectData.customObject.mainTexture.height), default(Vector2));
  308. componentInChildren.sprite2D = sprite2D;
  309. this.textureRestoreButton.isEnabled = false;
  310. this.selectData.backupPng = null;
  311. }
  312. public void OnClickSave()
  313. {
  314. if (this.selectData == null)
  315. {
  316. return;
  317. }
  318. if (this.selectData.customObject.mainTexture == null)
  319. {
  320. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/マイオブジェ/ダイアログ/テクスチャが未設定です", null, SystemDialog.TYPE.OK, null, null);
  321. return;
  322. }
  323. if (string.IsNullOrEmpty(this.selectData.fullPath))
  324. {
  325. this.savePanel.Open(this.selectData.customObject, delegate(string filePath)
  326. {
  327. GameObject parent = GameObject.Find("CustomObjectPrev");
  328. BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(parent, filePath);
  329. if (basePhotoCustomObject == null)
  330. {
  331. return;
  332. }
  333. this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, filePath));
  334. this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, filePath);
  335. this.objectListGrid.GetComponent<UIWFTabPanel>().UpdateChildren();
  336. Utility.ResetNGUI(this.objectListGrid);
  337. Utility.ResetNGUI(this.scroll_view_);
  338. this.UpdateChildren();
  339. ObjectManagerWindow objectManagerWindow2 = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  340. objectManagerWindow2.createBgObjectWindow.AddMyObject(filePath);
  341. });
  342. }
  343. else
  344. {
  345. if (File.Exists(this.selectData.fullPath))
  346. {
  347. File.Delete(this.selectData.fullPath);
  348. }
  349. try
  350. {
  351. File.WriteAllBytes(this.selectData.fullPath, this.selectData.customObject.Serialize());
  352. ObjectManagerWindow objectManagerWindow = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  353. objectManagerWindow.createBgObjectWindow.UpdateMyObject(this.selectData.fullPath);
  354. }
  355. catch
  356. {
  357. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/マイオブジェ/ダイアログ/オブジェクトの保存に失敗しました", null, SystemDialog.TYPE.OK, null, null);
  358. }
  359. }
  360. }
  361. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  362. {
  363. }
  364. public override void OnMaidRemoveEventPrev(Maid maid)
  365. {
  366. }
  367. public void OnClickCameraFocus()
  368. {
  369. if (this.select_trans_target_ == null || this.select_trans_target_.obj == null)
  370. {
  371. return;
  372. }
  373. Vector3 position = this.select_trans_target_.obj.transform.position;
  374. float distance = 4f;
  375. Vector2 aroundAngle = new Vector2(-180f, 4.7f);
  376. this.camera_move_support_.StartCameraPosition(position, distance, aroundAngle);
  377. }
  378. private BasePhotoCustomObject CreateLoadCustomObject(GameObject parent, string filePath)
  379. {
  380. BasePhotoCustomObject basePhotoCustomObject = BasePhotoCustomObject.InstantiateFromFile(parent, filePath);
  381. if (basePhotoCustomObject == null)
  382. {
  383. return null;
  384. }
  385. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
  386. basePhotoCustomObject.gameObject.name = fileNameWithoutExtension.GetHashCode().ToString();
  387. basePhotoCustomObject.visible = false;
  388. return basePhotoCustomObject;
  389. }
  390. private UIWFTabButton CreateTabButton(GameObject parent_obj, BasePhotoCustomObject target, string filePath)
  391. {
  392. GameObject gameObject = Utility.CreatePrefab(parent_obj, "ScenePhotoMode/WindowListItem", true);
  393. gameObject.name = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
  394. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  395. UIWFTabButton component = gameObject.GetComponent<UIWFTabButton>();
  396. this.buttonDic.Add(component.GetHashCode(), target);
  397. EventDelegate.Add(component.onSelect, delegate()
  398. {
  399. if (!UIWFSelectButton.current.isSelected)
  400. {
  401. return;
  402. }
  403. if (this.buttonDic.ContainsKey(UIWFSelectButton.current.GetHashCode()))
  404. {
  405. this.OnSelectItem(this.buttonDic[UIWFSelectButton.current.GetHashCode()]);
  406. }
  407. });
  408. return component;
  409. }
  410. public override void OnSerializeEvent()
  411. {
  412. }
  413. public override void OnDeserializeEvent()
  414. {
  415. }
  416. public override KeyValuePair<string, Dictionary<string, string>> Serialize()
  417. {
  418. KeyValuePair<string, Dictionary<string, string>> result = base.Serialize();
  419. Dictionary<string, string> value = result.Value;
  420. result = new KeyValuePair<string, Dictionary<string, string>>(result.Key, value);
  421. return result;
  422. }
  423. public override void Deserialize(Dictionary<string, Dictionary<string, string>> data)
  424. {
  425. base.Deserialize(data);
  426. string key = base.gameObject.name + "title";
  427. if (!data.ContainsKey(key))
  428. {
  429. return;
  430. }
  431. this.visibleTextureSelectWindow = false;
  432. }
  433. public PhotoModeObjectSave savePanel;
  434. public UIButton selectTextureButton;
  435. public GameObject textureExpTextObject;
  436. public UIButton textureRestoreButton;
  437. public TextureSelectSubWindow textureSelectSubtWindow;
  438. public UIGrid objectListGrid;
  439. public UIPopupList typeSelectPopupList;
  440. public WFCheckBox CheckPrevVisible;
  441. public UIButton saveButton;
  442. public PhotoSliderAndInput editScaleSlider;
  443. public WindowPartsInputColorrPalette texColorPalette;
  444. public GameObject planeUIParent;
  445. public UIPopupList planeBackDrawPopupList;
  446. public GameObject sphereUIParent;
  447. public UIPopupList sphereBackDrawPopupList;
  448. private Dictionary<int, BasePhotoCustomObject> buttonDic = new Dictionary<int, BasePhotoCustomObject>();
  449. private List<ObjectCreateWindow.Data> target_list_ = new List<ObjectCreateWindow.Data>();
  450. private ObjectCreateWindow.Data selectData;
  451. private bool change_bg_;
  452. private PhotoTransTargetObject select_trans_target_;
  453. private WfCameraMoveSupport camera_move_support_;
  454. private UIScrollView scroll_view_;
  455. private class Data
  456. {
  457. public Data(BasePhotoCustomObject obj)
  458. {
  459. this.customObject = obj;
  460. }
  461. public Data(BasePhotoCustomObject obj, string fullPath)
  462. {
  463. this.customObject = obj;
  464. this.fullPath = fullPath;
  465. }
  466. public BasePhotoCustomObject customObject;
  467. public byte[] backupPng;
  468. public string fullPath;
  469. }
  470. }