BoxProjects.hx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package arm.ui;
  2. import zui.Zui;
  3. import zui.Id;
  4. import arm.io.ImportArm;
  5. #if arm_touchui
  6. class BoxProjects {
  7. public static var htab = Id.handle();
  8. static var iconMap: Map<String, kha.Image> = null;
  9. @:access(zui.Zui)
  10. public static function show() {
  11. if (iconMap != null) {
  12. for (handle in iconMap.keys()) iron.data.Data.deleteImage(handle);
  13. iconMap = null;
  14. }
  15. UIBox.showCustom(function(ui: Zui) {
  16. if (ui.tab(htab, tr("Projects"), true)) {
  17. ui.beginSticky();
  18. if (ui.button(tr("New"))) {
  19. Project.projectNew();
  20. Viewport.scaleToBounds();
  21. UIBox.show = false;
  22. App.redrawUI();
  23. }
  24. ui.endSticky();
  25. ui.separator(3, false);
  26. var slotw = Std.int(300 * ui.SCALE());
  27. var num = Std.int(kha.System.windowWidth() / slotw);
  28. var recent_projects = Config.raw.recent_projects;
  29. for (row in 0...Std.int(Math.ceil(recent_projects.length / num))) {
  30. ui.row([for (i in 0...num) 1 / num]);
  31. for (j in 0...num) {
  32. var i = j + row * num;
  33. if (i >= recent_projects.length) {
  34. var imgw = Std.int(256 * ui.SCALE());
  35. @:privateAccess ui.endElement(imgw);
  36. continue;
  37. }
  38. var path = recent_projects[i];
  39. #if krom_ios
  40. var documentDirectory = Krom.saveDialog("", "");
  41. documentDirectory = documentDirectory.substr(0, documentDirectory.length - 8); // Strip /'untitled'
  42. path = documentDirectory + path;
  43. #end
  44. var iconPath = path.substr(0, path.length - 4) + "_icon.png";
  45. if (iconMap == null) iconMap = [];
  46. var icon = iconMap.get(iconPath);
  47. if (icon == null) {
  48. iron.data.Data.getImage(iconPath, function(image: kha.Image) {
  49. icon = image;
  50. iconMap.set(iconPath, icon);
  51. });
  52. }
  53. ui.fill(0, 0, 256, 256, ui.t.SEPARATOR_COL);
  54. if (icon != null) {
  55. var state = ui.image(icon);
  56. if (state == Released) {
  57. iron.App.notifyOnInit(function() {
  58. ImportArm.runProject(path);
  59. });
  60. UIBox.show = false;
  61. }
  62. if (ui.isHovered && ui.inputReleasedR) {
  63. UIMenu.draw(function(ui: Zui) {
  64. var name = path.substr(path.lastIndexOf("/") + 1);
  65. ui.text(name, Right, ui.t.HIGHLIGHT_COL);
  66. // if (ui.button(tr("Duplicate"), Left)) {}
  67. if (ui.button(tr("Delete"), Left)) {
  68. iron.App.notifyOnInit(function() {
  69. arm.sys.File.delete(path);
  70. arm.sys.File.delete(iconPath);
  71. recent_projects.splice(i, 1);
  72. });
  73. }
  74. }, 2);
  75. }
  76. }
  77. }
  78. ui._y += 32;
  79. }
  80. }
  81. }, 600, 400, null, false);
  82. #if arm_touchui
  83. @:privateAccess alignToFullScreen();
  84. #end
  85. }
  86. static function alignToFullScreen() {
  87. @:privateAccess UIBox.modalW = Std.int(kha.System.windowWidth() / App.uiBox.SCALE());
  88. @:privateAccess UIBox.modalH = Std.int(kha.System.windowHeight() / App.uiBox.SCALE());
  89. var appw = kha.System.windowWidth();
  90. var apph = kha.System.windowHeight();
  91. var mw = appw;
  92. var mh = apph;
  93. UIBox.hwnd.dragX = Std.int(-appw / 2 + mw / 2);
  94. UIBox.hwnd.dragY = Std.int(-apph / 2 + mh / 2);
  95. }
  96. }
  97. #end