EditorTools.hx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package hrt.impl;
  2. #if editor
  3. class EditorIcon extends hrt.prefab.l3d.Billboard.BillboardObj {
  4. public var scaleWithParent = false;
  5. public var category : IconCategory;
  6. public function new(?tile : h3d.mat.Texture, ?parent : h3d.scene.Object, category: IconCategory) {
  7. super(tile, parent);
  8. ignoreCollide = false;
  9. this.category = category;
  10. }
  11. override function sync(ctx) {
  12. visible = EditorTools.isVisible(category);
  13. super.sync(ctx);
  14. }
  15. override function getLocalCollider():h3d.col.Collider {
  16. return new h3d.col.Sphere(0,0,0,billboardScale/2.0);
  17. }
  18. // Ingonre scale and rotation
  19. override function calcAbsPos() {
  20. absPos.identity();
  21. absPos.tx = x;
  22. absPos.ty = y;
  23. absPos.tx = z;
  24. if (parent != null) {
  25. absPos.tx += parent.absPos.tx;
  26. absPos.ty += parent.absPos.ty;
  27. absPos.tz += parent.absPos.tz;
  28. }
  29. if( invPos != null )
  30. invPos._44 = 0; // mark as invalid
  31. }
  32. }
  33. class Editor2DIcon extends h2d.ObjectFollower {
  34. public var category : IconCategory;
  35. public function new( obj, ?parent, texture, category: IconCategory) {
  36. super(obj, parent);
  37. horizontalAlign = Middle;
  38. followVisibility = true;
  39. var ico = new h2d.Bitmap(h2d.Tile.fromTexture(texture), this);
  40. this.category = category;
  41. }
  42. override function sync(ctx) {
  43. visible = EditorTools.isVisible(category);
  44. super.sync(ctx);
  45. }
  46. }
  47. enum IconCategory {
  48. Light;
  49. Trails;
  50. Audio;
  51. Misc;
  52. }
  53. class EditorTools {
  54. // Create a 3d Icon that will be displayed inside the scene as a 3d object, meaning that it can be
  55. // obscured by the other objects
  56. public static function create3DIcon(object:h3d.scene.Object, iconPath:String, scale:Float = 1.0, category: IconCategory) : EditorIcon {
  57. var ide = hide.Ide.inst;
  58. var tex = ide.getTexture(iconPath);
  59. var icon = new EditorIcon(tex, object, category);
  60. icon.texture = tex;
  61. icon.billboardScale = scale;
  62. return icon;
  63. }
  64. // Creates a 2d Icon that will be displayed in front of all the other icons
  65. public static function create2DIcon(object: h3d.scene.Object, s2d: h2d.Object, iconPath: String, category: IconCategory) : Editor2DIcon {
  66. var ide = hide.Ide.inst;
  67. return new Editor2DIcon(object, s2d, ide.getTexture(iconPath), category);
  68. }
  69. public static function setupIconCategories() {
  70. for (categoryName in haxe.EnumTools.getConstructors(IconCategory)) {
  71. var category = haxe.EnumTools.createByName(IconCategory, categoryName, []);
  72. var ide = hide.Ide.inst;
  73. if(!ide.show3DIconsCategory.exists(category)) {
  74. var value = js.Browser.window.localStorage.getItem(iconVisibilityKey(category));
  75. var shouldBeDisplayed = false;
  76. if (value == null || value == "true") {
  77. shouldBeDisplayed = true;
  78. }
  79. ide.show3DIconsCategory.set(category, shouldBeDisplayed);
  80. }
  81. }
  82. }
  83. public static function iconVisibilityKey(category: IconCategory) {
  84. return "3dIconVisibility/" + haxe.EnumTools.EnumValueTools.getName(category);
  85. }
  86. public static function isVisible(category: IconCategory) : Bool {
  87. return hide.Ide.inst.show3DIcons && hide.Ide.inst.show3DIconsCategory.get(category);
  88. }
  89. }
  90. #end