Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 57.16 KB | None | 0 0
  1. package game.editor;
  2.  
  3. import cuttlefish.*;
  4. import cuttlefish.utils.Console;
  5. import cuttlefish.input.Mouse;
  6. import cuttlefish.input.Keyboard;
  7. import cuttlefish.components.CollisionSystem;
  8. import cuttlefish.components.CollisionBox;
  9. import cuttlefish.graphics.Atlas;
  10.  
  11. import kha.input.KeyCode;
  12. import cuttlefish.io.Files;
  13. import kha.Blob;
  14. import game.*;
  15. import game.battle.*;
  16. import game.dialogs.*;
  17. import game.editor.*;
  18. import game.entities.*;
  19. import cuttlefish.math.CMath;
  20.  
  21. import tween.Delta;
  22. import tween.easing.*;
  23. import tween.tweens.FloatTween;
  24.  
  25. import cuttlefish.ui.UI_Window;
  26. import cuttlefish.ui.UI_SelectItem;
  27.  
  28. typedef LevelsStruct = {
  29.     var levels: Array<String>;
  30. };
  31.  
  32. private class InputTextField {
  33.    
  34.     public var x: Float;
  35.     public var y: Float;
  36.  
  37.     var offset: Float = 0;
  38.  
  39.     public var content: String = "";
  40.     public var desc: String = "";
  41.     public var activated: Bool = false;
  42.  
  43.     var onEnter: String -> Void;
  44.  
  45.     public function new(x: Float, y: Float, d: String, fun: String->Void) {
  46.         this.x=x;
  47.         this.y=y;
  48.         onEnter = fun;
  49.         desc = d;
  50.     }
  51.  
  52.     public function update(): Void {
  53.        
  54.         // if(Mouse.checkPressed(Mouse.LEFT)){
  55.         //  var mx = Mouse.me.x;
  56.         //  var my = Mouse.me.y;
  57.  
  58.         //  if(mx >= x-offset && mx <= x+offset*2+Graphics.stringWidth(content)*Graphics.fontScale*2
  59.         //          && my >= y-offset && my <= y+offset*2+(Graphics.stringHeight(content)+Graphics.fontScale)*Graphics.fontScale*2){
  60.         //      activated = !activated;
  61.         //  }
  62.         // }
  63.  
  64.         if(activated){
  65.             var char = Keyboard.getKeyPressed();
  66.             if(char != ""){
  67.                 if(Atlas.get(0).exists(char)){
  68.                     content += char;
  69.                 }
  70.             }
  71.  
  72.             if(Keyboard.checkPressed(KeyCode.Backspace)){
  73.                 content = content.substring(0,content.length-1);
  74.             }
  75.  
  76.             if(Keyboard.checkPressed(KeyCode.Return)){
  77.                 if(onEnter != null){
  78.                     onEnter(content);
  79.                     activated = false;
  80.                 }
  81.             }
  82.         }
  83.  
  84.     }
  85.  
  86.     public function draw(): Void {
  87.         if(activated){
  88.             var lfs = Graphics.fontScale;
  89.             Graphics.fontScale = lfs*2;
  90.  
  91.             Graphics.setColor(Graphics.Black);
  92.             Graphics.drawRect(true
  93.                     ,x-offset -Graphics.stringWidth(content)*Graphics.fontScale/2
  94.                     ,y-offset -(Graphics.stringHeight(content)+Graphics.fontScale)*Graphics.fontScale/2
  95.                     , Graphics.stringWidth(content)*Graphics.fontScale + offset*2
  96.                     , (Graphics.stringHeight(content)+Graphics.fontScale)*Graphics.fontScale + offset*2);
  97.             Graphics.setColor(Graphics.White);
  98.             Graphics.drawString(content, x-Graphics.stringWidth(content)*Graphics.fontScale/2, y-(Graphics.stringHeight(content)+Graphics.fontScale)*Graphics.fontScale/2);
  99.  
  100.             Graphics.setColor(Graphics.Black);
  101.             Graphics.drawRect(true,
  102.                     x - Graphics.stringWidth(desc)*Graphics.fontScale/2,
  103.                     y-(Graphics.stringHeight(desc)+Graphics.fontScale)*Graphics.fontScale*2,
  104.                     Graphics.stringWidth(desc)*Graphics.fontScale,
  105.                     (Graphics.stringHeight(desc))*Graphics.fontScale);
  106.             Graphics.setColor(Graphics.White);
  107.             Graphics.drawString(desc, x - Graphics.stringWidth(desc)*Graphics.fontScale/2, y-(Graphics.stringHeight(desc)+Graphics.fontScale)*Graphics.fontScale*2);
  108.  
  109.             Graphics.fontScale = lfs;
  110.         }
  111.     }
  112.  
  113. }
  114.  
  115. private class IconButton {
  116.     var index: Int = 0;
  117.     var hovered: Bool = false;
  118.     var yoff: Float = 0;
  119.  
  120.     var editMode: EditMode;
  121.  
  122.     public function new(ind: Int, em: EditMode) {
  123.         index = ind;
  124.         editMode = em;
  125.     }
  126.  
  127.     public function activate(): Void {
  128.         switch(index){
  129.             case 0://save
  130.                 // input.activated = true;
  131.  
  132.                 var cw: EditInputWindow;
  133.                 cw = new EditInputWindow((1280)/2, (800)/2, function() {
  134.                     editMode.save_state(cw.value);
  135.                     editMode.current_file = cw.value;
  136.  
  137.                     Console.print('Level saved to ${cw.value}');
  138.  
  139.                     cw.delayDestroy();
  140.                 });
  141.  
  142.                 cw.manager = MainScene.testUI;
  143.                 cw.center();
  144.                 cw.setTitle("Save level:");
  145.                 MainScene.testUI.windows.push(cw);
  146.  
  147.             case 1://load
  148.                 // input.activated = true;
  149.                 var cw: EditListWindow;
  150.                 cw = new EditListWindow((1280)/2, (800)/2, function() {
  151.  
  152.                     LocationZone.id_destroying = true;
  153.                     editMode.load_state(cw.value);
  154.                     LocationZone.id_destroying = false;
  155.  
  156.                     Console.print('Loaded level from ${cw.value}');
  157.  
  158.                     cw.delayDestroy();
  159.                 });
  160.  
  161.                 cw.manager = MainScene.testUI;
  162.                 cw.center();
  163.                 cw.setTitle("Load level:");
  164.                 MainScene.testUI.windows.push(cw);
  165.  
  166.             case 2:
  167.                 // editMode.show_objects = !editMode.show_objects;
  168.         }
  169.     }
  170.     public function update(input: InputTextField): Void {
  171.         var mx = Mouse.me.realx;
  172.         var my = Mouse.me.realy;
  173.  
  174.         var h = kha.System.windowHeight(0);
  175.  
  176.         if(my > h-64 && mx > index*64 && mx < (index+1)*64){
  177.             hovered = true;
  178.         }else{
  179.             hovered = false;
  180.         }
  181.  
  182.         if(hovered){
  183.             if(Mouse.checkPressed(Mouse.LEFT)){
  184.                 activate();
  185.             }
  186.         }
  187.     }
  188.  
  189.     public function draw(spr: String): Void {
  190.         var atl = AtlasManager.getAtlas("ui");
  191.         var w = 72;//atl.getSpriteWidth(spr);
  192.         var h= atl.getSpriteHeight(spr);
  193.         if(!hovered){
  194.             Graphics.drawAtlasImage(atl,spr, Camera.getLeft() + index*w, Camera.getBottom()-h);
  195.         }else{
  196.             Graphics.drawAtlasImage(atl,spr, Camera.getLeft() + index*w, Camera.getBottom()-h-32);
  197.         }
  198.     }
  199. }
  200.  
  201. class EditMode extends Entity {
  202.  
  203.     var camera: Camera;
  204.     var console: Console;
  205.  
  206.     var camera_dragged: Bool = false;
  207.  
  208.     var start_x: Float;
  209.     var start_y: Float;
  210.  
  211.     var camera_start_x: Float;
  212.     var camera_start_y: Float;
  213.  
  214.     var collision_system: CollisionSystem;
  215.     var entity_dragging: Bool = false;
  216.     var entity_dragging_xo: Float = 0;
  217.     var entity_dragging_yo: Float = 0;
  218.     var snap_size: Float = 64;
  219.     public var snap_x: Float = 64;
  220.     public var snap_y: Float = 64;
  221.  
  222.     var icons: Array<String>;
  223.     var buttons: Array<IconButton>;
  224.     var inputs: Array<InputTextField>;
  225.     var test_string: String = "";
  226.  
  227.     public var current_file: String = "";
  228.     public static var levels: Array<String> = [];
  229.  
  230.     public var skipClick: Bool = false;
  231.  
  232.     public var selected_entity: Entity = null; //actually a reference to some entity
  233.  
  234.     public var enabled: Bool = false;
  235.  
  236.     public var edit_entities: Array<Entity>;
  237.  
  238.     public var show_objects: Bool = false;
  239.     public var objects_to_create: Array<String>;
  240.     public var objects_sprite: Array<String>;
  241.     public var holding_object: Int = -1;
  242.  
  243.     var deleted_entities: Array<Entity>;
  244.     var debug_info: Bool = false;
  245.  
  246.     public var actions: Array<String>;
  247.     var pickedFromX: Float = 0;
  248.     var pickedFromY: Float = 0;
  249.  
  250.     var draw_grid: Bool = false;
  251.  
  252.     public var current_zoom: Float = 100;
  253.  
  254.     public var groups: Array<String>;
  255.     public function getEntitiesByGroup(name: String): Array<Entity> {
  256.         var return_array: Array<Entity> = new Array<Entity>();
  257.         for(i in edit_entities){
  258.             if(cast(i.getComponent(Editable), Editable).group == name){
  259.                 return_array.push(i);
  260.             }
  261.         }
  262.         return return_array;
  263.     }
  264.  
  265.     public var levels_json: LevelsStruct;
  266.  
  267.     public function reload_levels(): Void {
  268.         levels = [];
  269.         kha.Assets.loadBlobFromPath("data/levels.json", function(a: kha.Blob){
  270.             levels_json = haxe.Json.parse(a.toString());
  271.             for(i in levels_json.levels) {
  272.                 levels.push(i + ".chl");   
  273.             }
  274.         });
  275.     }
  276.  
  277.     public function new() {
  278.         super("editor");
  279.         edit_entities = new Array<Entity>();
  280.         deleted_entities = new Array<Entity>();
  281.         actions = new Array<String>();
  282.         icons = ["save", "icon_load", "object"];
  283.         buttons = new Array<IconButton>();
  284.         buttons.push(new IconButton(0, this));
  285.         buttons.push(new IconButton(1, this));
  286.         // buttons.push(new IconButton(2, this));
  287.  
  288.         groups = new Array<String>();
  289.         groups.push('default');
  290.         groups.push('invisible');
  291.         groups.push('npcs');
  292.         groups.push('dialogs');
  293.         groups.push('lighting');
  294.  
  295.         reload_levels();
  296.  
  297.         inputs = new Array<InputTextField>();
  298.  
  299.         inputs.push(new InputTextField(0,256, "Save File:", function(filename: String){
  300.             //check for proper filename
  301.             // current_file = filename;
  302.             // save_state(filename);
  303.             // Console.print('Level saved to ${filename}');
  304.             // for(i in inputs){
  305.             //  i.content = filename;
  306.             // }
  307.             // current_file = filename;
  308.         }));
  309.         inputs.push(new InputTextField(0,256, "Load File:", function(filename: String){
  310.             //check for proper filename
  311.             // load_state(filename);
  312.             // Console.print('Loaded level from ${filename}');
  313.             // for(i in inputs){
  314.             //  i.content = filename;
  315.             // }
  316.         }));
  317.         inputs.push(new InputTextField(0,256, "", function(filename: String){
  318.             //kinda weird, fix it
  319.         }));
  320.         objects_to_create = new Array<String>();
  321.         objects_to_create.push("NPC");
  322.         objects_to_create.push("image");
  323.         objects_to_create.push("block");
  324.         objects_to_create.push("light");
  325.         objects_to_create.push("scast");
  326.         objects_to_create.push("location");
  327.         objects_to_create.push("dzone");
  328.         objects_to_create.push("sleep");
  329.         objects_to_create.push("egroup");
  330.         objects_to_create.push("ezone");
  331.         objects_to_create.push("computer");
  332.         objects_to_create.push("czone");
  333.         objects_to_create.push("inv_chest");
  334.         objects_to_create.push("scrzone");
  335.         objects_to_create.push("note");
  336.         objects_to_create.push("bugs");
  337.         objects_to_create.push("part_sys");
  338.         objects_to_create.push("eset_zone");
  339.         objects_to_create.push("darkjune");
  340.  
  341.         // objects_sprite = new Sprite(AtlasManager.getAtlas("ui"), ["NPC", "image", "icon_block", "location_zone", "icon_dialog", "sleep_zone", "NPC", "image", "image", "icon_cutscene"]);
  342.         objects_sprite = ["NPC", "image", "icon_block", "image", "icon_scast", "location_zone", "icon_dialog", "sleep_zone", "NPC", "icon_ezone", "image", "icon_cutscene", "icon_chest", "icon_scrzone", "icon_note", "NPC", "image", "image", "NPC"];
  343.     }
  344.  
  345.     private function insertLine(a: String, b: Dynamic, ?c: String = " "): String{
  346.         return a + Std.string(b) + c;
  347.     }
  348.  
  349.     //FIXME: please
  350.     //kinda a hack
  351.     public inline function resetIDs(): Void {
  352.         // return;
  353.  
  354.         // Entity.IDS = 100000;
  355.         // VisualObject.NID = 0;
  356.         // Block.NID = 0;
  357.         // Light.NID = 0;
  358.         // Enemy.NID = 0;
  359.         // SleepZone.NID = 0;
  360.         // NPC_Entity.NID = 1000;//?????????????
  361.         // ShadowCast.NID = 0;
  362.         // ScriptZone.NID = 0;
  363.         // EnemyGroup.NID = 0;
  364.         // ComputerZone.NID = 0;
  365.         // CutsceneZone.NID = 0;
  366.         // LocationZone.NID = 0;
  367.         // DialogTriggerZone.NID = 0;
  368.         // EnemyAttractionZone.NID = 0;
  369.     }
  370.  
  371.     public function save_state(?filename: String = "level0.chl"): Void {
  372.         var ss: String = "";
  373.        
  374.         for(i in edit_entities){
  375.             if(i == null) continue;
  376.             var current_editable: Editable = cast(i.getComponent(Editable));
  377.             if(current_editable == null) continue;
  378.  
  379.             ss = insertLine(ss, current_editable.edit_id);
  380.             ss = insertLine(ss, i.x);
  381.             ss = insertLine(ss, i.y);
  382.             ss = insertLine(ss, current_editable.locked ? "1" : "0");
  383.             ss = insertLine(ss, 'group:s\"${current_editable.group}\"');
  384.  
  385.             //fields
  386.             for(j in 0...current_editable.fields.length){
  387.                 var isLast: Bool = (j == current_editable.fields.length-1);
  388.                 if(current_editable.fields_type[j] == "s"){
  389.                     var string_to_save: String = Reflect.field(current_editable.entity, current_editable.fields[j]);
  390.                     string_to_save = StringTools.replace(string_to_save, " ", "&");
  391.  
  392.                     ss = insertLine(ss, '${current_editable.fields[j]}:${current_editable.fields_type[j]}\"${string_to_save}\"', isLast ? "" : " ");
  393.                 }else{
  394.                     ss = insertLine(ss, '${current_editable.fields[j]}:${current_editable.fields_type[j]}${Reflect.field(current_editable.entity, current_editable.fields[j])}', isLast ? "" : " ");
  395.                 }
  396.             }
  397.  
  398.             if(i != edit_entities[edit_entities.length-1]){
  399.                 ss = insertLine(ss, '
  400. ', "");
  401.             }
  402.         }
  403.  
  404.         Files.saveStringToFile(ss, "data/levels/" + filename);
  405.  
  406.  
  407.  
  408.         var filename_wp = filename.substring(0, filename.length-4);
  409.         for(i in levels_json.levels){
  410.             if(i == filename_wp){
  411.                 return;
  412.             }
  413.         }
  414.  
  415.         levels_json.levels.push(filename_wp);
  416.         cuttlefish.io.Files.saveStringToFile(haxe.Json.stringify(levels_json), "data/levels.json");
  417.     }
  418.  
  419.     public function load_state(?filename: String = "level0.chl", ?done: Void -> Void = null): Void {
  420.  
  421.         actions = new Array<String>();
  422.  
  423.         // if(selected_entity != null){
  424.         //  var box: CollisionBox = cast(selected_entity.getComponent(CollisionBox));
  425.         //  box.isDebug = false;
  426.         // }
  427.         // selected_entity = null;
  428.  
  429.         resetIDs();
  430.  
  431.         kha.Assets.loadBlobFromPath("data/levels/" + filename, function(a: Blob){
  432.                    
  433.             current_file = filename;
  434.             for(j in 0...edit_entities.length){
  435.                 if(edit_entities[j] != null){
  436.                     if(!Std.is(edit_entities[j], Player)
  437.                             && !Std.is(edit_entities[j], Rammon)){
  438.                         // edit_entities[j].id = "null";
  439.                         if(edit_entities[j] != null){
  440.                             if(!edit_entities[j].toDestroy){
  441.                                 edit_entities[j]._destroy();
  442.                             }
  443.                         }
  444.                     }
  445.                 }
  446.             }
  447.  
  448.  
  449.             edit_entities = new Array<Entity>();
  450.             edit_entities.push(scene.getEntityById("player"));
  451.             edit_entities.push(scene.getEntityById("rammon"));
  452.  
  453.             var loadedText: String = a.toString();
  454.  
  455.             var tokens: Array<String> = loadedText.split("
  456. ");
  457.  
  458.             for(i in 0...tokens.length){
  459.                 var data_of_entity: Array<String> = tokens[i].split(" ");
  460.  
  461.                 var name: String = data_of_entity[0];
  462.                 var entity_x: Float = Std.parseFloat(data_of_entity[1]);
  463.                 var entity_y: Float = Std.parseFloat(data_of_entity[2]);
  464.                 var entity_locked: Bool = data_of_entity[3] == "1" ? true : false;
  465.                 var data: Array<String> = new Array<String>();
  466.  
  467.                 if(data_of_entity.length >= 5){
  468.                     for(j in 4...data_of_entity.length){
  469.                         var args: Array<String> = data_of_entity[j].split(":");
  470.  
  471.                         var arg_name: String = args[0];
  472.                         var arg_type: String = args[1].charAt(0);
  473.                         var arg_value: String = args[1].substring(1,args[1].length);
  474.  
  475.                         if(arg_type == "s"){
  476.                             arg_value = arg_value.substring(1, arg_value.length-1);
  477.  
  478.                             //change & to space
  479.                             arg_value = StringTools.replace(arg_value, "&", " ");
  480.                         }
  481.  
  482.                         data.push(arg_name);
  483.                         data.push(arg_type);
  484.                         data.push(arg_value);
  485.  
  486.                         // Console.print('${arg_name} = ${arg_value}, typeof ${arg_type}');
  487.                     }
  488.                 }
  489.  
  490.                 createEntityFromData(name, entity_x, entity_y, entity_locked, data);
  491.  
  492.             }
  493.             switch(filename){
  494.                 case "mansion_outside.chl": {
  495.                     Camera.lock(-1000, -2850, 3600, 700);
  496.                 }
  497.                 default: {
  498.                     Camera.unlock();
  499.                 }
  500.             }
  501.  
  502.             if(done != null) {
  503.                 done();
  504.             }
  505.             // var tokens: Array<String> = loadedText.split(" ");
  506.  
  507.             // var entity_to_create: String = "";
  508.             // var entity_x: Float = 0;
  509.             // var entity_y: Float = 0;
  510.             // var created: Bool = false;
  511.  
  512.             // for(i in 0...Math.floor(tokens.length/3)){
  513.             //  entity_to_create = tokens[i*3];
  514.             //  entity_x = Std.parseFloat(tokens[i*3+1]);
  515.             //  entity_y = Std.parseFloat(tokens[i*3+2]);
  516.  
  517.             //  createEntityFromData(entity_to_create, entity_x, entity_y);
  518.             // }
  519.  
  520.         }, function(error: kha.AssetError){
  521.             Console.print('Error: ${error.url}: ${error.error}');
  522.         });
  523.  
  524.        
  525.     }
  526.  
  527.     inline function arrows_movement(): Void {
  528.         if(Keyboard.check(KeyCode.Shift)){
  529.             if(Keyboard.checkPressed(KeyCode.Right)) selected_entity.x += 3;
  530.             if(Keyboard.checkPressed(KeyCode.Left)) selected_entity.x -= 3;
  531.             if(Keyboard.checkPressed(KeyCode.Down)) selected_entity.y += 3;
  532.             if(Keyboard.checkPressed(KeyCode.Up)) selected_entity.y -= 3;
  533.         }else{
  534.             if(Keyboard.checkPressed(KeyCode.Right)) selected_entity.x += 1;
  535.             if(Keyboard.checkPressed(KeyCode.Left)) selected_entity.x -= 1;
  536.             if(Keyboard.checkPressed(KeyCode.Down)) selected_entity.y += 1;
  537.             if(Keyboard.checkPressed(KeyCode.Up)) selected_entity.y -= 1;
  538.         }
  539.     }
  540.  
  541.     function createEntityFromData(name: String, x: Float, y: Float, locked: Bool, data: Array<String>): Void {
  542.         var createdEntity: Entity = null;
  543.  
  544.         switch(name) {
  545.             case "player":
  546.                 // scene.add(new Player(x, y));
  547.                 var player = scene.getEntityById("player");
  548.                 player.x = x;
  549.                 player.y = y;
  550.                 createdEntity = player;
  551.                 Camera.me.setPosition(player.x-Camera.getWidth()/2,player.y-Camera.getHeight()/2 - 32);
  552.                 // Camera.me.setPosition(x-Camera.getWidth()/2,y-Camera.getHeight()/2);
  553.                 // cast(createdEntity, Player).setPos(x, y);
  554.             case "NPC":
  555.                 var npc = new NPC_Entity(x, y);
  556.                 scene.add(npc);
  557.                 npc.setRect(32,32);
  558.                 // npc.setDialog("boop");
  559.                 npc.setDepth(1);
  560.                 createdEntity = npc;
  561.             case "rammon":
  562.                 var rammon = scene.getEntityById("rammon");
  563.                 rammon.x = x;
  564.                 rammon.y = y;
  565.                 createdEntity = rammon;
  566.             case "visualobject":
  567.                 var vo = new VisualObject(x, y);
  568.                 scene.add(vo);
  569.                 createdEntity = vo;
  570.             case "darkjune":
  571.                 var j = new DarkJune(x, y);
  572.                 scene.add(j);
  573.                 createdEntity = j;
  574.             case "block":
  575.                 setAllCollisionVisible(true);
  576.  
  577.                 var block = new Block(x, y);
  578.                 scene.add(block);
  579.                 createdEntity = block;
  580.             case "inv_chest":
  581.                 var chest = new InventoryChest(x,y);
  582.                 scene.add(chest);
  583.                 createdEntity = chest;
  584.             case "light":
  585.                 var light = new Light(x, y);
  586.                 scene.add(light);
  587.                 createdEntity = light;
  588.             case "scast":
  589.                 var scast = new ShadowCast(x, y);
  590.                 scene.add(scast);
  591.                 createdEntity = scast;
  592.  
  593.             case "location":
  594.                 var location = new LocationZone(x, y);
  595.                 scene.add(location);
  596.                 createdEntity = location;
  597.  
  598.             case "sleep_zone":
  599.                 var loc = new SleepZone(x, y);
  600.                 scene.add(loc);
  601.                 createdEntity = loc;
  602.             case "egroup":
  603.                 var enemygroup = new EnemyGroup(x, y);
  604.                 scene.add(enemygroup);
  605.                 createdEntity = enemygroup;
  606.             case "dzone":
  607.                 var dzone = new DialogTriggerZone(x, y);
  608.                 scene.add(dzone);
  609.                 createdEntity = dzone;
  610.             case "czone":
  611.                 var czone = new CutsceneZone(x,y);
  612.                 scene.add(czone);
  613.                 createdEntity = czone;
  614.             case "scrzone":
  615.                 var szone = new ScriptZone(x, y);
  616.                 scene.add(szone);
  617.                 createdEntity = szone;
  618.             case "ezone":
  619.                 var enem = new EnemyAttractionZone(x, y);
  620.                 scene.add(enem);
  621.                 createdEntity = enem;
  622.             case "eset_zone":
  623.                 var zone = new EnemySetZone(x,y);
  624.                 scene.add(zone);
  625.                 createdEntity = zone;
  626.  
  627.             case "computer":
  628.                 var comp = new ComputerZone(x, y);
  629.                 scene.add(comp);
  630.                 createdEntity = comp;
  631.             case "note":
  632.                 var note = new Note(x, y);
  633.                 scene.add(note);
  634.                 createdEntity = note;
  635.             case "bugs":
  636.                 var bugs = new Bugs(x, y);
  637.                 scene.add(bugs);
  638.                 createdEntity = bugs;
  639.             case "part_sys":
  640.                 var p = new ParticleSystem(x, y);
  641.                 scene.add(p);
  642.                 createdEntity = p;
  643.         }
  644.  
  645.         if(createdEntity != null){
  646.             var createdEditable: Editable = cast(createdEntity.getComponent(Editable));
  647.            
  648.             createdEditable.locked = locked;
  649.  
  650.             if(data.length == 0) return;
  651.             for(i in 0...Math.floor(data.length/3)){
  652.  
  653.                 if(data[i*3] == "group"){
  654.                     // trace(data[i*3 +2]);
  655.                     createdEditable.group = data[i*3 + 2];
  656.                     createdEditable.changeVisualField("group", data[i*3 + 2]);
  657.                     continue;
  658.                 }
  659.  
  660.                 // var no_save: Bool = Reflect.hasField(Reflect.field(createdEntity, data[i*3]), "nosave");
  661.  
  662.                 // if(no_save){
  663.                 //  trace('${data[i*3]}');
  664.                 // }
  665.  
  666.                 // if(Reflect.hasField(createdEntity, data[i*3])){
  667.                     switch(data[i*3 + 1]){
  668.                         case "s":
  669.                             Reflect.setField(createdEntity, data[i*3], data[i*3+2]);
  670.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "s", data[i*3+2]);
  671.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  672.                         case "l":
  673.                             Reflect.setField(createdEntity, data[i*3], data[i*3+2]);
  674.  
  675.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  676.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "l", data[i*3+2]);
  677.                         case "f":
  678.                             Reflect.setField(createdEntity, data[i*3], Std.parseFloat(data[i*3+2]));
  679.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "f", data[i*3+2]);
  680.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  681.                         case "i":
  682.                             Reflect.setField(createdEntity, data[i*3], Std.parseInt(data[i*3+2]));
  683.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "i", data[i*3+2]);
  684.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  685.                         default:
  686.                     }
  687.                 // }else{
  688.                 //  Console.print('${createdEntity.id} dont have a ${data[i*3]}');
  689.                 // }
  690.             }
  691.         }
  692.     }
  693.  
  694.     public override function init(): Void {
  695.         super.init();
  696.  
  697.         camera = Camera.me;
  698.         console = Console.me;
  699.  
  700.         start_x = 0;
  701.         start_y = 0;
  702.  
  703.         camera_start_x = 0;
  704.         camera_start_y = 0;
  705.         collision_system = new CollisionSystem();
  706.         scene.addSystem(collision_system);
  707.         setDepth(-10000);
  708.  
  709.         // camera.setSize(Std.int(camera.width - 64*9), Std.int(camera.height - 40*9));
  710.         // camera.setPosition(camera.x + 64*4.5, camera.y + 40*4.5);
  711.     }
  712.  
  713.     public function update_objects(): Void {
  714.  
  715.         if(Mouse.checkReleased(Mouse.LEFT)){
  716.             if(holding_object != -1){
  717.                 if(Mouse.me.realy <= Engine.core.window_height - 64){
  718.  
  719.                     var mx: Float = Math.floor(Mouse.me.x);
  720.                     var my: Float = Math.floor(Mouse.me.y);
  721.                     try{
  722.                         var entity: Entity = cast _createEntity(id_to_class[objects_to_create[holding_object]], mx, my);
  723.                         scene.add(entity);
  724.                         actions.push('create ${entity.id}');
  725.                     }catch(e: Dynamic){
  726.                         trace(objects_to_create[holding_object]);
  727.                         trace(e);
  728.                     }
  729.  
  730.                     /*
  731.                     switch(objects_to_create[holding_object]){
  732.                         case "NPC":
  733.                             var npc = new NPC_Entity(mx,my);
  734.                             scene.add(npc);
  735.                             npc.setRect(32,32);
  736.                             // npc.setDialog("boop");
  737.                             npc.setDepth(1);
  738.                             actions.push('create ${npc.id}');
  739.                         case "image":
  740.                             var image = new VisualObject(mx, my);
  741.                             scene.add(image);
  742.                             actions.push('create ${image.id}');
  743.                         case "block":
  744.                             setAllCollisionVisible(true);
  745.  
  746.                             var block = new Block(mx, my);
  747.                             scene.add(block);
  748.                             cast(block.getComponent(Editable), Editable).group = "invisible";
  749.                             cast(block.getComponent(Editable), Editable).changeVisualField("group", "invisible");
  750.                             actions.push('create ${block.id}');
  751.                         case "inv_chest":
  752.                             var chest = new InventoryChest(mx, my);
  753.                             scene.add(chest);
  754.                             cast(chest.getComponent(Editable), Editable).group = "invisible";
  755.                             cast(chest.getComponent(Editable), Editable).changeVisualField("group", "invisible");
  756.                             actions.push('create ${chest.id}');
  757.  
  758.                         case "light":
  759.                             var light = new Light(mx ,my);
  760.                             scene.add(light);
  761.                             actions.push('create ${light.id}');
  762.                         case "scast":
  763.                             var scast = new ShadowCast(mx, my);
  764.                             scene.add(scast);
  765.                             cast(scast.getComponent(Editable), Editable).group = "invisible";
  766.                             cast(scast.getComponent(Editable), Editable).changeVisualField("group", "invisible");
  767.                             actions.push('create ${scast.id}');
  768.                         case "location":
  769.                             var location = new LocationZone(mx, my);
  770.                             scene.add(location);
  771.                             actions.push('create ${location.id}');
  772.                         case "sleep":
  773.                             var loc = new SleepZone(mx, my);
  774.                             scene.add(loc);
  775.                             actions.push('create ${loc.id}');
  776.                         case "egroup":
  777.                             var enemygroup = new EnemyGroup(mx, my);
  778.                             scene.add(enemygroup);
  779.                             actions.push('create ${enemygroup.id}');
  780.                         case "dzone":
  781.                             var dzone = new DialogTriggerZone(mx, my);
  782.                             scene.add(dzone);
  783.                             cast(dzone.getComponent(Editable), Editable).group = "dialogs";
  784.                             actions.push('create ${dzone.id}');
  785.                         case "czone":
  786.                             var czone = new CutsceneZone(mx,my);
  787.                             scene.add(czone);
  788.                             cast(czone.getComponent(Editable), Editable).group = "dialogs";
  789.                             actions.push('create ${czone.id}');
  790.                         case "scrzone":
  791.                             var szone = new ScriptZone(mx, my);
  792.                             scene.add(szone);
  793.                             cast(szone.getComponent(Editable), Editable).group = "dialogs";
  794.                             actions.push('create ${szone.id}');
  795.                         case "ezone":
  796.                             var enemy_zone = new EnemyAttractionZone(mx, my);
  797.                             scene.add(enemy_zone);
  798.                             actions.push('create ${enemy_zone.id}');
  799.                         case "computer":
  800.                             var computer_zone = new ComputerZone(mx, my);
  801.                             scene.add(computer_zone);
  802.                             actions.push('create ${computer_zone.id}');
  803.  
  804.                         default:
  805.                             Console.print("nah");
  806.                     }
  807.                     */
  808.                    
  809.                     holding_object = -1;
  810.                     show_objects = false;
  811.                 }
  812.             }
  813.         }
  814.     }
  815.  
  816.     public function updateZoom(): Void {
  817.         var w = Engine.core.view_width;
  818.         var h = Engine.core.view_height;
  819.  
  820.         var aspect = w/h;
  821.  
  822.         var nh = 1000;
  823.         var nw = nh * aspect;
  824.  
  825.         var mw = (camera.width - Math.floor(nw*(current_zoom/100)))/2;
  826.         var mh = (camera.height - Math.floor(nh*(current_zoom/100)))/2;
  827.  
  828.         camera.setSize(Math.floor(nw*(current_zoom/100)), Math.floor(nh*(current_zoom/100)));
  829.         camera.setPosition(camera.x + mw, camera.y + mh);
  830.     }
  831.  
  832.     public function _tween(obj: Dynamic, p: String, time: Float, val: Float){
  833.         var t = Delta.tween(obj);
  834.         return t.createTween(p, time,
  835.                 new FloatTween(t, p, val, time));
  836.     }
  837.  
  838.     public function zoomTime(v: Float, t: Float): Void {
  839.         var w = Engine.core.view_width;
  840.         var h = Engine.core.view_height;
  841.  
  842.         var aspect = w/h;
  843.  
  844.         var nh = 1000;
  845.         var nw = nh * aspect;
  846.  
  847.         var mw = (camera.width - Std.int(nw*(current_zoom/100)))/2;
  848.         var mh = (camera.height - Std.int(nh*(current_zoom/100)))/2;
  849.  
  850.         camera.setSize(Std.int(nw*(current_zoom/100)), Std.int(nh*(current_zoom/100)));
  851.         _tween(this, "current_zoom", t, v)
  852.             .ease(tween.easing.Sine.easeInOut)
  853.             .onUpdate(function(v2: Float){
  854.                 updateZoom();
  855.             });
  856.     }
  857.  
  858.     @:generic
  859.     function _createEntity<T: haxe.Constraints.Constructible<(Float, Float) -> Void>>(a: Class<T>, x: Float, y: Float): T {
  860.         // return new T(x, y);
  861.         return Type.createInstance(a, [x, y]);
  862.     }
  863.  
  864.     var id_to_class: Map<String, Class<haxe.Constraints.Constructible<(Float, Float) -> Void>>> = [
  865.         "NPC" => NPC_Entity,
  866.  
  867.         "visualobject" => VisualObject,
  868.         "darkjune" => DarkJune,
  869.         "image" => VisualObject,
  870.  
  871.         "block" => Block,
  872.         "inv_chest" => InventoryChest,
  873.         "light" => Light,
  874.         "scast" => ShadowCast,
  875.         "location" => LocationZone,
  876.         "sleep_zone" => SleepZone,
  877.         "egroup" => EnemyGroup, //fix
  878.         "dzone" => DialogTriggerZone,
  879.         "czone" => CutsceneZone,
  880.  
  881.         "srczone" => ScriptZone,
  882.         "scrzone" => ScriptZone,
  883.  
  884.         "ezone" => EnemyAttractionZone,
  885.         "eset_zone" => EnemySetZone,
  886.         "note" => Note,
  887.         "computer" => ComputerZone,
  888.         "bugs" => Bugs,
  889.         "part_sys" => ParticleSystem,
  890.     ];
  891.  
  892.     function create_cached_entity(cached_entity_name: String, data_fields: Array<Editable.EditableField>): Void {
  893.         var entity: Entity = null;
  894.                     var mx = Mouse.me.x;
  895.                     var my = Mouse.me.y;
  896.         var createdEntity: Entity = null;
  897.         var x = mx;
  898.         var y = my;
  899.  
  900.         if(cached_entity_name == "player" || cached_entity_name == "rammon"){
  901.             trace('copy player or rammon');
  902.             return;
  903.         }
  904.         createdEntity = cast _createEntity(id_to_class[cached_entity_name], x, y);
  905.         scene.add(createdEntity);
  906.  
  907.         // switch(cached_entity_name) {
  908.         //  case "player":
  909.         //      // scene.add(new Player(x, y));
  910.         //      scene.getEntityById("player").x = x;
  911.         //      scene.getEntityById("player").y = y;
  912.         //      createdEntity = scene.getEntityById("player");
  913.         //  case "NPC":
  914.         //      var npc = new NPC_Entity(x, y);
  915.         //      scene.add(npc);
  916.         //      npc.setRect(32,32);
  917.         //      // npc.setDialog("boop");
  918.         //      npc.setDepth(1);
  919.         //      createdEntity = npc;
  920.         //  case "rammon":
  921.         //      scene.getEntityById("rammon").x = x;
  922.         //      scene.getEntityById("rammon").y = y;
  923.         //      createdEntity = scene.getEntityById("rammon");
  924.         //  case "visualobject":
  925.         //      var vo = new VisualObject(x, y);
  926.         //      scene.add(vo);
  927.         //      createdEntity = vo;
  928.         //  case "block":
  929.         //      setAllCollisionVisible(true);
  930.  
  931.         //      var block = new Block(x, y);
  932.         //      scene.add(block);
  933.         //      createdEntity = block;
  934.         //  case "inv_chest":
  935.         //      var chest = new InventoryChest(x, y);
  936.         //      scene.add(chest);
  937.         //      createdEntity = chest;
  938.         //  case "light":
  939.         //      var light = new Light(x, y);
  940.         //      scene.add(light);
  941.         //      createdEntity = light;
  942.         //  case "scast":
  943.         //      var scast = new ShadowCast(x, y);
  944.         //      scene.add(scast);
  945.         //      createdEntity = scast;
  946.  
  947.         //  case "location":
  948.         //      var location = new LocationZone(x, y);
  949.         //      scene.add(location);
  950.         //      createdEntity = location;
  951.  
  952.         //  case "sleep_zone":
  953.         //      var loc = new SleepZone(x, y);
  954.         //      scene.add(loc);
  955.         //      createdEntity = loc;
  956.         //  case "egroup":
  957.         //      var enemygroup = new EnemyGroup(x, y);
  958.         //      scene.add(enemygroup);
  959.         //      createdEntity = enemygroup;
  960.         //  case "dzone":
  961.         //      var dzone = new DialogTriggerZone(x, y);
  962.         //      scene.add(dzone);
  963.         //      createdEntity = dzone;
  964.         //  case "czone":
  965.         //      var czone = new CutsceneZone(x,y);
  966.         //      scene.add(czone);
  967.         //      createdEntity = czone;
  968.         //  case "scrzone":
  969.         //      var szone = new ScriptZone(x,y);
  970.         //      scene.add(szone);
  971.         //      createdEntity = szone;
  972.         //  case "ezone":
  973.         //      var enem = new EnemyAttractionZone(x, y);
  974.         //      scene.add(enem);
  975.         //      createdEntity = enem;
  976.  
  977.         //  case "computer":
  978.         //      var comp = new ComputerZone(x, y);
  979.         //      scene.add(comp);
  980.         //      createdEntity = comp;
  981.         // }
  982.  
  983.         if(createdEntity != null) {
  984.             var createdEditable: Editable = cast(createdEntity.getComponent(Editable));
  985.             createdEditable.group = cached_entity_group;
  986.            
  987.             // createdEditable.locked = locked;
  988.             var data: Array<String> = [];
  989.  
  990.             for(i in data_fields){
  991.                 data.push(i.var_name);
  992.                 data.push(i.type);
  993.                 data.push(i.value);
  994.             }
  995.  
  996.             for(i in 0...Math.floor(data.length/3)){
  997.  
  998.                 if(data[i*3] == "group"){
  999.                     // trace(data[i*3 + 2]);
  1000.                     // createdEditable.group = data[i*3 + 2];
  1001.                     // createdEditable.changeVisualField("group", data[i*3 + 2]);
  1002.                     continue;
  1003.                 }
  1004.  
  1005.                 // if(Reflect.hasField(createdEntity, data[i*3])){
  1006.                     switch(data[i*3 + 1]){
  1007.                         case "s":
  1008.                             Reflect.setField(createdEntity, data[i*3], data[i*3+2]);
  1009.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "s", data[i*3+2]);
  1010.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  1011.                         case "l":
  1012.                             Reflect.setField(createdEntity, data[i*3], data[i*3+2]);
  1013.  
  1014.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  1015.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "l", data[i*3+2]);
  1016.                         case "f":
  1017.                             Reflect.setField(createdEntity, data[i*3], Std.parseFloat(data[i*3+2]));
  1018.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "f", data[i*3+2]);
  1019.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  1020.                         case "i":
  1021.                             Reflect.setField(createdEntity, data[i*3], Std.parseInt(data[i*3+2]));
  1022.                             if(createdEditable.onChangeValue != null) createdEditable.onChangeValue(data[i*3], "i", data[i*3+2]);
  1023.                             createdEditable.changeVisualField(data[i*3], data[i*3+2]);
  1024.                         default:
  1025.                     }
  1026.                 // }else{
  1027.                 //  Console.print('${createdEntity.id} dont have a ${data[i*3]}');
  1028.                 // }
  1029.             }
  1030.         }
  1031.     }
  1032.  
  1033.     function setAllCollisionVisible(a: Bool): Void {
  1034.         for(i in edit_entities){
  1035.             var ie: Editable = cast(i.getComponent(Editable));
  1036.             if(ie.hasTag("hidable")){
  1037.                 ie.visible = a;
  1038.             }
  1039.         }
  1040.     }
  1041.  
  1042.     var cached_entity_name: String = "";
  1043.     var cached_entity_fields: Array<Editable.EditableField>;
  1044.     var cached_entity_group: String = "";
  1045.  
  1046.     var scaling: Bool = false;
  1047.     var scaling_entity: Entity = null;
  1048.  
  1049.     var light_autooff: Bool = false;
  1050.  
  1051.     public override function update(dt: Float): Void {
  1052.         super.update(dt);
  1053.  
  1054.  
  1055.         if(Keyboard.checkPressed(KeyCode.Tab)){
  1056.             enabled = !enabled;
  1057.  
  1058.             if(light_autooff){
  1059.                 if(enabled) {
  1060.                     Engine.core.is_bloom = false;
  1061.                     cast(scene.getEntityById("light_system"), LightSystem).enabled = false;
  1062.                 }else{
  1063.                     Engine.core.is_bloom = true;
  1064.                     cast(scene.getEntityById("light_system"), LightSystem).enabled = true;
  1065.                 }
  1066.             }
  1067.        
  1068.             if(!enabled){
  1069.                 if(selected_entity != null){   
  1070.                     var box: CollisionBox = cast(selected_entity.getComponent(CollisionBox));
  1071.                     box.isDebug = false;
  1072.                    
  1073.                     selected_entity = null;
  1074.                 }
  1075.             }
  1076.         }
  1077.  
  1078.         //NOPE
  1079.         // if(Keyboard.checkPressed(KeyCode.M)){
  1080.         //  SaveManager.saveSceneYaml(edit_entities);
  1081.         // }
  1082.  
  1083.  
  1084.         Graphics.debugBackgroundDraw = enabled;
  1085.         if(!enabled) return;
  1086.  
  1087.         update_objects();
  1088.  
  1089.         if(selected_entity != null){
  1090.             var _editable: Editable = cast(selected_entity.getComponent(Editable));
  1091.             if(_editable != null){
  1092.                 _editable.update_meta();
  1093.             }
  1094.  
  1095.             //hotkey for locking and unlocking an entity
  1096.             if(Keyboard.checkPressed(KeyCode.Q)){
  1097.                 _editable.locked = !_editable.locked;
  1098.                 actions.push('locked ${selected_entity.id} ${_editable.locked ? "1" : "0"}');
  1099.             }
  1100.  
  1101.             if(Keyboard.checkPressed(KeyCode.C) && Keyboard.check(KeyCode.Control)){
  1102.                 // trace('${_editable.edit_id} copied.');
  1103.                 cached_entity_name = _editable.edit_id;
  1104.                 cached_entity_group = _editable.group;
  1105.  
  1106.                 //TODO: hard copy to new Array
  1107.                 // cached_entity_fields = _editable.fields_editable;
  1108.                 cached_entity_fields = [];
  1109.                 for(i in _editable.fields_editable){
  1110.                     cached_entity_fields.push({
  1111.                         x: i.x,
  1112.                         y: i.y,
  1113.                         width: i.width,
  1114.                         height: i.height,
  1115.                         name: i.name,
  1116.                         var_name: i.var_name,
  1117.                         value: i.value,
  1118.                         type: i.type,
  1119.                         options: i.options,
  1120.                         show_options: i.show_options,
  1121.                         options_offset: i.options_offset,
  1122.                         options_atlas: i.options_atlas,
  1123.                         editing: i.editing,
  1124.                         slider: i.slider,
  1125.                         slider_min: i.slider_min,
  1126.                         slider_max: i.slider_max,
  1127.                         slider_changing: i.slider_changing,
  1128.                         inEditable: i.inEditable,
  1129.                         button: i.button,
  1130.                     });
  1131.                 }
  1132.             }
  1133.         }
  1134.         if(Keyboard.checkPressed(KeyCode.V) && Keyboard.check(KeyCode.Control)){
  1135.             if(cached_entity_name != ""){
  1136.                 create_cached_entity(cached_entity_name, cached_entity_fields);
  1137.             }
  1138.         }
  1139.  
  1140.         for(i in inputs){
  1141.             i.x = Camera.getX() + Camera.getWidth()/2;
  1142.             i.y = Camera.getY() + Camera.getHeight()/2;
  1143.             i.update();
  1144.         }
  1145.  
  1146.         for(i in 0...buttons.length){
  1147.             buttons[i].update(inputs[i]);
  1148.         }
  1149.  
  1150.         var shifted = Keyboard.check(KeyCode.Shift);
  1151.  
  1152.         //TODO:
  1153.         //scale depended
  1154.         var mx: Float = Mouse.me.realx*2;
  1155.         var my: Float = Mouse.me.realy*2;
  1156.  
  1157.         var controlled = Keyboard.check(KeyCode.Control);
  1158.  
  1159.         if(shifted){
  1160.             if(Keyboard.checkPressed(KeyCode.G)){
  1161.                 draw_grid = !draw_grid;
  1162.             }
  1163.         }else{
  1164.             if(Keyboard.checkPressed(KeyCode.G)){
  1165.                 var window = new UI_Window(Mouse.me.realx, Mouse.me.realy);
  1166.                 window.manager = MainScene.testUI;
  1167.                 MainScene.testUI.windows.push(window);
  1168.                 window.setTitle("Grid Settings");
  1169.                 window.createInput(Std.string(snap_x), "w", function(a){
  1170.                     snap_x = Std.parseFloat(a);
  1171.                 });
  1172.                 window.createInput(Std.string(snap_x), "h", function(a){
  1173.                     snap_y = Std.parseFloat(a);
  1174.                 });
  1175.             }
  1176.  
  1177.             if(Keyboard.checkPressed(KeyCode.L)){
  1178.                 var window = new UI_Window(Mouse.me.realx, Mouse.me.realy);
  1179.                 window.manager = MainScene.testUI;
  1180.                 MainScene.testUI.windows.push(window);
  1181.                 window.setTitle("Light System");
  1182.                 cast(scene.getEntityById("light_system"), LightSystem).debugWindow(window);
  1183.  
  1184.             }
  1185.         }
  1186.  
  1187.         if(controlled){
  1188.             if(!shifted){
  1189.                 if(Keyboard.checkPressed(KeyCode.S)){
  1190.                     if(current_file != ""){
  1191.                         save_state(current_file);
  1192.                         Console.print('${current_file} saved.');
  1193.                     }
  1194.                 }
  1195.             }else{
  1196.                 if(Keyboard.checkPressed(KeyCode.S)){
  1197.                     buttons[0].activate();
  1198.                 }      
  1199.             }
  1200.         }
  1201.  
  1202.         if(Keyboard.checkPressed(KeyCode.Delete)){
  1203.             if(selected_entity != null){
  1204.                 if(!Std.is(selected_entity, Player)
  1205.                         && !Std.is(selected_entity, Rammon)){
  1206.                     var temp_entity = selected_entity;
  1207.  
  1208.                     var box: CollisionBox = cast(selected_entity.getComponent(Editable), Editable).edit_box;
  1209.                     box.isDebug = false;
  1210.  
  1211.                     edit_entities.remove(selected_entity);
  1212.  
  1213.                     deleted_entities.push(temp_entity);
  1214.                     actions.push('delete ${deleted_entities.length-1}');
  1215.                     scene.remove(temp_entity.id);
  1216.  
  1217.                     cast(scene.getSystem("collision_system"), CollisionSystem).removeComponent(box);
  1218.  
  1219.                     //temp_entity.destroy();
  1220.                     selected_entity = null;
  1221.                 }
  1222.             }
  1223.         }
  1224.  
  1225.         if(selected_entity != null)
  1226.             inline arrows_movement();
  1227.  
  1228.         if(controlled){
  1229.             if(Keyboard.checkPressed(KeyCode.Z)){
  1230.                 var last_action: String = actions.pop();
  1231.                 if(last_action != null){
  1232.                     var tokens = last_action.split(" ");
  1233.                     switch(tokens[0]){
  1234.                         case "delete":
  1235.                             setAllCollisionVisible(true);
  1236.  
  1237.                             //what about entity specific components that included in some systems?
  1238.                             //TODO: Block and collision system boxes
  1239.                             //FIXME: error btw
  1240.                             scene.add(deleted_entities[Std.parseInt(tokens[1])]);
  1241.                             cast(scene.getSystem("collision_system"), CollisionSystem).addComponent((cast(deleted_entities[Std.parseInt(tokens[1])].getComponent(Editable), Editable)).edit_box);
  1242.                             deleted_entities.pop();
  1243.                         case "create":
  1244.                             setAllCollisionVisible(true);
  1245.  
  1246.                             var entity: Entity = scene.getEntityById(tokens[1]);
  1247.                             edit_entities.remove(entity);
  1248.                             entity.destroy();
  1249.                             entity = null;
  1250.                         case "locked":
  1251.                             var entity: Entity = scene.getEntityById(tokens[1]);
  1252.                             cast(entity.getComponent(Editable), Editable).locked = tokens[2] == "1" ? false : true;
  1253.                         case "change":
  1254.                             var entity: Entity = scene.getEntityById(tokens[1]);
  1255.                             var var_name: String = tokens[2];
  1256.                             var var_type: String = tokens[3];
  1257.                             var var_from: String = tokens[4];
  1258.                             var var_to: String = tokens[5];
  1259.  
  1260.                             switch(var_type){
  1261.                                 case "f":
  1262.                                     Reflect.setField(entity, var_name, Std.parseFloat(var_from));
  1263.                                     if(cast(entity.getComponent(Editable),Editable).onChangeValue != null) cast(entity.getComponent(Editable),Editable).onChangeValue(var_name, "f", var_from);
  1264.                                     cast(entity.getComponent(Editable), Editable).changeVisualField(var_name, var_from);
  1265.                                 case "i":
  1266.                                     Reflect.setField(entity, var_name, Std.parseInt(var_from));
  1267.                                     if(cast(entity.getComponent(Editable),Editable).onChangeValue != null) cast(entity.getComponent(Editable),Editable).onChangeValue(var_name, "i", var_from);
  1268.                                     cast(entity.getComponent(Editable), Editable).changeVisualField(var_name, var_from);
  1269.                                 case "s":
  1270.                                     Reflect.setField(entity, var_name, var_from);
  1271.                                     if(cast(entity.getComponent(Editable),Editable).onChangeValue != null) cast(entity.getComponent(Editable),Editable).onChangeValue(var_name, "s", var_from);
  1272.                                     cast(entity.getComponent(Editable), Editable).changeVisualField(var_name, var_from);
  1273.                                 case "l":
  1274.                                     Reflect.setField(entity, var_name, var_from);
  1275.                                     if(cast(entity.getComponent(Editable),Editable).onChangeValue != null) cast(entity.getComponent(Editable),Editable).onChangeValue(var_name, "l", var_from);
  1276.                                     cast(entity.getComponent(Editable), Editable).changeVisualField(var_name, var_from);
  1277.                                 default:
  1278.                                     Console.print("Wrong type when Ctrl+Z");
  1279.  
  1280.                             }
  1281.  
  1282.                         case "move":
  1283.                             var entity: Entity = scene.getEntityById(tokens[1]);
  1284.                             var from_x: Float = Std.parseFloat(tokens[2]);
  1285.                             var from_y: Float = Std.parseFloat(tokens[3]);
  1286.                             var to_x: Float = Std.parseFloat(tokens[4]);
  1287.                             var to_y: Float = Std.parseFloat(tokens[5]);
  1288.  
  1289.                             entity.x = from_x;
  1290.                             entity.y = from_y;
  1291.                     }
  1292.                 }
  1293.             }
  1294.         }
  1295.  
  1296.         if(Keyboard.checkPressed(KeyCode.C) && !controlled){
  1297.  
  1298.             var window = new UI_Window(Mouse.me.realx, Mouse.me.realy);
  1299.             window.manager = MainScene.testUI;
  1300.             MainScene.testUI.windows.push(window);
  1301.             window.setTitle("Group Manager");
  1302.  
  1303.             for(i in groups){
  1304.                 window.createButton(i, () -> {
  1305.                     for(j in edit_entities){
  1306.                         var ie: Editable = cast(j.getComponent(Editable));
  1307.                         // trace('${i} vs ${ie.group}: ${j.id}');
  1308.                         if(ie.group == i){
  1309.                             ie.visible = !ie.visible;
  1310.                         }
  1311.                     }
  1312.                 });
  1313.             }
  1314.         }
  1315.  
  1316.         //
  1317.         //  Window settings.
  1318.         //
  1319.         if(Keyboard.checkPressed(KeyCode.W)){
  1320.             var window = new UI_Window(1280/2, 800/2);
  1321.             window.manager = MainScene.testUI;
  1322.             MainScene.testUI.windows.push(window);
  1323.             window.setTitle("Window Settings");
  1324.  
  1325.             window.createInput(Std.string(cuttlefish.Engine.core.window_width), "width", function(a: String){
  1326.  
  1327.             });
  1328.             window.createInput(Std.string(cuttlefish.Engine.core.window_height), "height", function(a: String){
  1329.  
  1330.             });
  1331.             window.createInput(Std.string(Engine.core.bloom_tresh), "tresh1", function(a: String){
  1332.                 Engine.core.bloom_tresh = Std.parseFloat(a);
  1333.             });
  1334.             window.createInput(Std.string(Engine.core.bloom_tresh2), "tresh2", function(a: String){
  1335.                 Engine.core.bloom_tresh2 = Std.parseFloat(a);
  1336.             });
  1337.             window.createInput(Std.string(Engine.core.bloom_vign_out), "vign_outter", function(a: String){
  1338.                 Engine.core.bloom_vign_out = Std.parseFloat(a);
  1339.             });
  1340.             window.createInput(Std.string(Engine.core.bloom_vign_inn), "vign_inner", function(a: String){
  1341.                 Engine.core.bloom_vign_inn = Std.parseFloat(a);
  1342.             });
  1343.             window.createInput(Std.string(Engine.core.bloom_r), "r", function(a: String){
  1344.                 Engine.core.bloom_r = Std.parseFloat(a);
  1345.             });
  1346.             window.createInput(Std.string(Engine.core.bloom_g), "g", function(a: String){
  1347.                 Engine.core.bloom_g = Std.parseFloat(a);
  1348.             });
  1349.             window.createInput(Std.string(Engine.core.bloom_b), "b", function(a: String){
  1350.                 Engine.core.bloom_b = Std.parseFloat(a);
  1351.             });
  1352.             window.createButton("Resize", function(){
  1353.                 var iw: cuttlefish.ui.UI_Input = cast window.components[0];
  1354.                 var ih: cuttlefish.ui.UI_Input = cast window.components[1];
  1355.                 cuttlefish.Engine.core.resize(
  1356.                         Std.parseInt(iw.str),
  1357.                         Std.parseInt(ih.str)
  1358.                         );
  1359.             });
  1360.             window.createButton("Debug Info", function(){
  1361.                 this.debug_info = !this.debug_info;
  1362.             });
  1363.             window.createButton("Draw Mouse Pos", function(){
  1364.                 this.draw_mouse_pos = !this.draw_mouse_pos;
  1365.             });
  1366.             window.createButton("Bloom", function(){
  1367.                 Engine.core.is_bloom = !Engine.core.is_bloom;
  1368.             });
  1369.         }
  1370.  
  1371.         if(Keyboard.checkPressed(KeyCode.A)){
  1372.             var window = new UI_Window(1280/2, 800/2);
  1373.             window.manager = MainScene.testUI;
  1374.             MainScene.testUI.windows.push(window);
  1375.             window.setTitle("Add Object");
  1376.             window.focus = true;
  1377.             MainScene.testUI.windowFocus(window);
  1378.  
  1379.             window.createSelectField(objects_to_create, objects_sprite, "ui", function(item: UI_SelectItem) {
  1380.                 for(i in 0...objects_to_create.length){
  1381.                     if(item.name == objects_to_create[i]){
  1382.                         holding_object = i;
  1383.                         skipClick = true;
  1384.                     }
  1385.                 }
  1386.  
  1387.                 // item.createItem();
  1388.                 window.delayDestroy();
  1389.             });
  1390.  
  1391.             window.center();
  1392.         }
  1393.  
  1394.         final zoomSpeedX: Int = 64;
  1395.         final zoomSpeedY: Int = 40;
  1396.  
  1397.         if(selected_entity == null){
  1398.             var w = Engine.core.window_width;
  1399.             var h = Engine.core.window_height;
  1400.  
  1401.             if(Mouse.checkWheelUp()){
  1402.                 // camera.setSize(Std.int(camera.width + zoomSpeedX), Std.int(camera.height + zoomSpeedY));
  1403.                 // camera.setPosition(camera.x - zoomSpeedX/2, camera.y - zoomSpeedY/2);
  1404.                 current_zoom -= 5;
  1405.  
  1406.                 camera.setSize(Std.int(w*(current_zoom/100)), Std.int(h*(current_zoom/100)));
  1407.             }
  1408.             if(Mouse.checkWheelDown()){
  1409.                 // camera.setSize(Std.int(camera.width - zoomSpeedX), Std.int(camera.height - zoomSpeedY));
  1410.                 // camera.setPosition(camera.x + zoomSpeedX/2, camera.y + zoomSpeedY/2);
  1411.                 current_zoom += 5;
  1412.  
  1413.                 camera.setSize(Std.int(w*(current_zoom/100)), Std.int(h*(current_zoom/100)));
  1414.  
  1415.             }
  1416.         }
  1417.  
  1418.         final cz = 200 / current_zoom;
  1419.         if(Mouse.checkPressed(Mouse.RIGHT)) {
  1420.             start_x = Mouse.me.realx * (cz);
  1421.             start_y = Mouse.me.realy * (cz);
  1422.  
  1423.             camera_start_x = camera.x + camera.offset_x;
  1424.             camera_start_y = camera.y + camera.offset_y;
  1425.  
  1426.             camera_dragged = true;
  1427.         }
  1428.  
  1429.         if(camera_dragged) {
  1430.             camera.setPosition(camera_start_x + (start_x - Mouse.me.realx* (cz)), camera_start_y + (start_y - Mouse.me.realy* (cz)));
  1431.         }
  1432.  
  1433.         if(Mouse.checkReleased(Mouse.RIGHT)) {
  1434.             camera_dragged = false;
  1435.         }
  1436.  
  1437.         if(Keyboard.checkPressed(E) && selected_entity != null){
  1438.             cast(selected_entity.getComponent(Editable), Editable).createWindow(Mouse.me.x, Mouse.me.y);
  1439.         }
  1440.  
  1441.         if(Mouse.checkPressed(Mouse.LEFT) && !skipClick) {
  1442.             if(selected_entity == null){
  1443.                 var syst: CollisionSystem = cast(scene.getSystem("collision_system"));
  1444.                 var entities = syst.instancesPosition(Mouse.me.x, Mouse.me.y);
  1445.                 if(entities.length > 0){
  1446.                     var entity: Entity = null;
  1447.                    
  1448.                     if(entities.length == 1){
  1449.                         if(cast(entities[0].getComponent(Editable), Editable).visible) entity = entities[0];
  1450.  
  1451.                         if(entity != null){
  1452.                             var _editable: Editable = cast entity.getComponent(Editable);
  1453.                             var box: CollisionBox = _editable.edit_box;
  1454.                             if(box != null){
  1455.                                 if(syst.hasBox(box)){
  1456.                                     if(!_editable.locked || Keyboard.check(Control)){
  1457.                                         selected_entity = entity;
  1458.                                         box.isDebug = true;
  1459.  
  1460.                                         // cast(entity.getComponent(Editable), Editable).createWindow(Mouse.me.x, Mouse.me.y);
  1461.  
  1462.                                         if(!(_editable.locked)){
  1463.                                             entity_dragging = true;
  1464.                                             entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1465.                                             entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1466.                                             pickedFromX = selected_entity.x;
  1467.                                             pickedFromY = selected_entity.y;
  1468.                                         }
  1469.                                     }
  1470.                                 }
  1471.                             }
  1472.                         }
  1473.                     }else{
  1474.                         var second_pass_entities: Array<Entity> = [];
  1475.                         if(Keyboard.check(Control)){
  1476.                             for(i in entities){
  1477.                                 if(cast(i.getComponent(Editable), Editable).visible){
  1478.                                     var entity = i;
  1479.                                     var _editable: Editable = cast entity.getComponent(Editable);
  1480.                                     var box: CollisionBox = _editable.edit_box;
  1481.                                     //When you are not holding right click we just ignore everything that is locked
  1482.                                     second_pass_entities.push(i);
  1483.                                     // if(entity == null){
  1484.                                     //  entity = i;
  1485.                                     // }else{
  1486.                                     //  if(i.depth < entity.depth){
  1487.                                     //      entity = i;
  1488.                                     //  }
  1489.                                     // }
  1490.                                 }
  1491.                             }
  1492.  
  1493.                             haxe.ds.ArraySort.sort(second_pass_entities,function(a,b){
  1494.                                 if(a.getDepth() < b.getDepth()) return 1;
  1495.                                 else if(a.getDepth() > b.getDepth()) return -1;
  1496.                                 else return 0;
  1497.                             });
  1498.  
  1499.                             var entity = second_pass_entities[second_pass_entities.length-1];
  1500.  
  1501.                             if(entity != null){
  1502.                                 var _editable: Editable = cast entity.getComponent(Editable);
  1503.                                 var box: CollisionBox = _editable.edit_box;
  1504.                                 if(box != null){
  1505.                                     if(syst.hasBox(box)){
  1506.                                         if(!_editable.locked || Keyboard.check(Control)){
  1507.                                             selected_entity = entity;
  1508.                                             box.isDebug = true;
  1509.  
  1510.                                             // cast(entity.getComponent(Editable), Editable).createWindow(Mouse.me.x, Mouse.me.y);
  1511.  
  1512.                                             if(!(_editable.locked)){
  1513.                                                 entity_dragging = true;
  1514.                                                 entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1515.                                                 entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1516.                                                 pickedFromX = selected_entity.x;
  1517.                                                 pickedFromY = selected_entity.y;
  1518.                                             }
  1519.                                         }
  1520.                                     }
  1521.                                 }
  1522.                             }
  1523.                         }else{
  1524.                             for(i in entities){
  1525.                                 if(cast(i.getComponent(Editable), Editable).visible){
  1526.                                     var entity = i;
  1527.                                     var _editable: Editable = cast entity.getComponent(Editable);
  1528.                                     var box: CollisionBox = _editable.edit_box;
  1529.                                     //When you are not holding right click we just ignore everything that is locked
  1530.                                     if(!_editable.locked){
  1531.                                         second_pass_entities.push(i);
  1532.                                     }
  1533.                                     // if(entity == null){
  1534.                                     //  entity = i;
  1535.                                     // }else{
  1536.                                     //  if(i.depth < entity.depth){
  1537.                                     //      entity = i;
  1538.                                     //  }
  1539.                                     // }
  1540.                                 }
  1541.                             }
  1542.  
  1543.                             haxe.ds.ArraySort.sort(second_pass_entities,function(a,b){
  1544.                                 if(a.getDepth() < b.getDepth()) return 1;
  1545.                                 else if(a.getDepth() > b.getDepth()) return -1;
  1546.                                 else return 0;
  1547.                             });
  1548.  
  1549.                             var entity = second_pass_entities[second_pass_entities.length-1];
  1550.  
  1551.                             if(entity != null){
  1552.                                 var _editable: Editable = cast entity.getComponent(Editable);
  1553.                                 var box: CollisionBox = _editable.edit_box;
  1554.                                 if(box != null){
  1555.                                     if(syst.hasBox(box)){
  1556.                                         if(!_editable.locked || Keyboard.check(Control)){
  1557.                                             selected_entity = entity;
  1558.                                             box.isDebug = true;
  1559.  
  1560.                                             // cast(entity.getComponent(Editable), Editable).createWindow(Mouse.me.x, Mouse.me.y);
  1561.  
  1562.                                             if(!(_editable.locked)){
  1563.                                                 entity_dragging = true;
  1564.                                                 entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1565.                                                 entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1566.                                                 pickedFromX = selected_entity.x;
  1567.                                                 pickedFromY = selected_entity.y;
  1568.                                             }
  1569.                                         }
  1570.                                     }
  1571.                                 }
  1572.                             }
  1573.                         }
  1574.                     }
  1575.                    
  1576.                 }
  1577.             }else{
  1578.                 if(cast(selected_entity.getComponent(Editable), Editable).inEditing) return;
  1579.                 var syst: CollisionSystem = cast(scene.getSystem("collision_system"));
  1580.  
  1581.                 var entities = syst.instancesPosition(Mouse.me.x, Mouse.me.y);
  1582.  
  1583.  
  1584.                 var entity: Entity = null;
  1585.  
  1586.                 if(entities.length > 0){
  1587.                     if(entities.length == 1){
  1588.                         if(cast(entities[0].getComponent(Editable), Editable).visible) entity = entities[0];
  1589.  
  1590.                         if(entity == selected_entity) {
  1591.                             if(!(cast(entity.getComponent(Editable), Editable).locked)){
  1592.                                 entity_dragging = true;
  1593.                                 entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1594.                                 entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1595.                                 pickedFromX = selected_entity.x;
  1596.                                 pickedFromY = selected_entity.y;
  1597.                             }
  1598.                         }else {
  1599.                             var _editable: Editable = cast entity.getComponent(Editable);
  1600.                             var box: CollisionBox = _editable.edit_box;
  1601.  
  1602.                             box = cast(selected_entity.getComponent(Editable), Editable).edit_box;
  1603.                             box.isDebug = false;
  1604.                             selected_entity = null;
  1605.  
  1606.                             if(!_editable.locked || Keyboard.check(Control)){
  1607.                                 box = _editable.edit_box;
  1608.                                 selected_entity = entity;
  1609.                                 box.isDebug = true;
  1610.  
  1611.                                 if(!cast(selected_entity.getComponent(Editable), Editable).locked){
  1612.                                     entity_dragging = true;
  1613.                                     entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1614.                                     entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1615.                                     pickedFromX = selected_entity.x;
  1616.                                     pickedFromY = selected_entity.y;
  1617.                                 }
  1618.                             }
  1619.                         }
  1620.                     }else{
  1621.  
  1622.  
  1623.                         var second_pass_entities: Array<Entity> = [];
  1624.                         if(Keyboard.check(Control)){
  1625.                             if(entities.indexOf(selected_entity) != -1){
  1626.                                 if(!(cast(selected_entity.getComponent(Editable), Editable).locked)){
  1627.                                     entity_dragging = true;
  1628.                                     entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1629.                                     entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1630.                                     pickedFromX = selected_entity.x;
  1631.                                     pickedFromY = selected_entity.y;
  1632.                                 }
  1633.                             }else{
  1634.                                 var box: CollisionBox = cast(selected_entity.getComponent(Editable), Editable).edit_box;
  1635.                                 box.isDebug = false;
  1636.                                 selected_entity = null;
  1637.  
  1638.                                 for(i in entities){
  1639.                                     if(cast(i.getComponent(Editable), Editable).visible){
  1640.                                         //When you are not holding right click we just ignore everything that is locked
  1641.                                         second_pass_entities.push(i);
  1642.                                         // if(entity == null){
  1643.                                         //  entity = i;
  1644.                                         // }else{
  1645.                                         //  if(i.depth < entity.depth){
  1646.                                         //      entity = i;
  1647.                                         //  }
  1648.                                         // }
  1649.                                     }
  1650.                                 }
  1651.  
  1652.                                 if(second_pass_entities.length > 0){
  1653.                                     haxe.ds.ArraySort.sort(second_pass_entities,function(a,b){
  1654.                                         if(a.getDepth() < b.getDepth()) return 1;
  1655.                                         else if(a.getDepth() > b.getDepth()) return -1;
  1656.                                         else return 0;
  1657.                                     });
  1658.  
  1659.                                     var entity = second_pass_entities[second_pass_entities.length-1];
  1660.  
  1661.                                     var _editable: Editable = cast entity.getComponent(Editable);
  1662.                                     box = _editable.edit_box;
  1663.  
  1664.                                     selected_entity = entity;
  1665.                                     box.isDebug = true;
  1666.                                 }
  1667.                             }
  1668.                         }else{
  1669.                             if(entities.indexOf(selected_entity) != -1){
  1670.                                 if(!(cast(selected_entity.getComponent(Editable), Editable).locked)){
  1671.                                     entity_dragging = true;
  1672.                                     entity_dragging_xo = Mouse.me.x - selected_entity.x;
  1673.                                     entity_dragging_yo = Mouse.me.y - selected_entity.y;
  1674.                                     pickedFromX = selected_entity.x;
  1675.                                     pickedFromY = selected_entity.y;
  1676.                                 }
  1677.                             }else{
  1678.                                 var box: CollisionBox = cast(selected_entity.getComponent(Editable), Editable).edit_box;
  1679.                                 box.isDebug = false;
  1680.                                 selected_entity = null;
  1681.  
  1682.                                 for(i in entities){
  1683.                                     if(cast(i.getComponent(Editable), Editable).visible){
  1684.                                         var entity = i;
  1685.                                         var _editable: Editable = cast entity.getComponent(Editable);
  1686.                                         box = _editable.edit_box;
  1687.                                         if(!_editable.locked){
  1688.                                             second_pass_entities.push(i);
  1689.                                         }
  1690.                                     }
  1691.                                 }
  1692.  
  1693.                                 if(second_pass_entities.length > 0){
  1694.                                     haxe.ds.ArraySort.sort(second_pass_entities,function(a,b){
  1695.                                         if(a.getDepth() < b.getDepth()) return 1;
  1696.                                         else if(a.getDepth() > b.getDepth()) return -1;
  1697.                                         else return 0;
  1698.                                     });
  1699.  
  1700.                                     var entity = second_pass_entities[second_pass_entities.length-1];
  1701.  
  1702.                                     var _editable: Editable = cast entity.getComponent(Editable);
  1703.                                     box = _editable.edit_box;
  1704.  
  1705.                                     selected_entity = entity;
  1706.                                     box.isDebug = true;
  1707.                                 }
  1708.                             }
  1709.                         }
  1710.                         // for(i in entities){
  1711.  
  1712.                         //  if(cast(i.getComponent(Editable), Editable).visible){
  1713.                         //      if(entity == null){
  1714.                         //          entity = i;
  1715.                         //      }else{
  1716.                         //          if(i.depth < entity.depth){
  1717.                         //              entity = i;
  1718.                         //          }
  1719.                         //      }
  1720.                         //  }
  1721.                         // }
  1722.                     }
  1723.                 }else{
  1724.                     var box: CollisionBox = cast(selected_entity.getComponent(Editable), Editable).edit_box;
  1725.                     box.isDebug = false;
  1726.  
  1727.                     selected_entity = null;
  1728.                 }
  1729.             }
  1730.         }else{
  1731.             if(skipClick){
  1732.                 skipClick = false;
  1733.             }
  1734.         }
  1735.  
  1736.         if(entity_dragging){
  1737.             if(!shifted){
  1738.                 selected_entity.x = Math.floor(Mouse.me.x - entity_dragging_xo);
  1739.                 selected_entity.y = Math.floor(Mouse.me.y - entity_dragging_yo);
  1740.             }else{
  1741.                 selected_entity.x = Math.floor((Mouse.me.x - entity_dragging_xo)/snap_x)*snap_x;
  1742.                 selected_entity.y = Math.floor((Mouse.me.y - entity_dragging_yo)/snap_y)*snap_y;
  1743.             }
  1744.            
  1745.         }
  1746.  
  1747.         if(Mouse.checkReleased(Mouse.LEFT)){
  1748.             if(entity_dragging){
  1749.                 entity_dragging = false;
  1750.                 if(pickedFromX != selected_entity.x && pickedFromY != selected_entity.y){
  1751.                     actions.push('move ${selected_entity.id} ${pickedFromX} ${pickedFromY} ${selected_entity.x} ${selected_entity.y}');
  1752.                 }
  1753.             }
  1754.         }
  1755.  
  1756.     }
  1757.  
  1758.     public var draw_mouse_pos: Bool = false;
  1759.  
  1760.     public override function gui(): Void {
  1761.         //things
  1762.  
  1763.         if(debug_info){
  1764.             Graphics.drawString('fps: ${Engine.getFPS()}', 0, 0);
  1765.             Graphics.drawString('upd: ${CMath.precFloat(Engine.getUpdateTime()*60)}', 0, 32);
  1766.             Graphics.drawString('drw: ${CMath.precFloat(Engine.getRenderTime()*60)}', 0, 64);
  1767.         }
  1768.  
  1769.         if(draw_mouse_pos) {
  1770.             Graphics.drawString('${Mouse.me.x}, ${Mouse.me.y}', Mouse.me.realx, Mouse.me.realy);
  1771.         }
  1772.  
  1773.         if(!enabled) return;
  1774.         super.gui();
  1775.         // Graphics.drawString('All entities to edit: ${edit_entities.length}', Camera.getX() + Camera.getWidth() - Graphics.stringWidth('All entities to edit: ${edit_entities.length}')*Graphics.fontScale, Camera.getY());
  1776.         Graphics.drawString('${current_zoom}%', Camera.getX() + Camera.getWidth() - Graphics.stringWidth('${current_zoom}%')*Graphics.fontScale, Camera.getY());
  1777.         if(selected_entity != null) {
  1778.             // Graphics.drawRect(false, selected_entity.x, selected_entity.y, 32, 32);
  1779.             // Graphics.drawString("hey", 0, 0);
  1780.             var _editable: Editable = cast(selected_entity.getComponent(Editable));
  1781.             _editable.draw_meta(Camera.getX(), Camera.getBottom() - Camera.getHeight()/2);
  1782.         }
  1783.  
  1784.         for(i in 0...buttons.length){
  1785.             buttons[i].draw(icons[i]);
  1786.         }
  1787.  
  1788.         for(i in inputs){
  1789.             i.draw();
  1790.         }
  1791.  
  1792.         if(show_objects){
  1793.             Graphics.setColor(Graphics.Black);
  1794.             Graphics.drawRect(true,Camera.getX() + 64*3, Camera.getBottom() - 64, Camera.getWidth() - 64*3 -2, 64 -2);
  1795.             Graphics.setColor(Graphics.White);
  1796.  
  1797.             var mx: Float = Mouse.me.realx;
  1798.             var my: Float = Mouse.me.realy;
  1799.             var object_id: Int = Math.floor((mx - (64*3)) / (64));
  1800.  
  1801.             if(my < Camera.getBottom() - 64){
  1802.                 object_id = -1;
  1803.             }
  1804.  
  1805.             for(i in 0...objects_to_create.length){
  1806.                 if(object_id == i){
  1807.                     Graphics.drawAtlasImage(AtlasManager.getAtlas("ui"),objects_sprite[i], Camera.getX() + 64*3 + 64*i + 16, Camera.getBottom() - 64 - 16 + 16, 0.5, 0.5);
  1808.  
  1809.                     Graphics.drawString(objects_to_create[i],
  1810.                             Camera.getX() + 64*3 + 64*i + 32 - Graphics.stringWidth(objects_to_create[i])/2,
  1811.                             Camera.getBottom() - 64 - Graphics.stringHeight(objects_to_create[i]) - 16);
  1812.                 }else{
  1813.                     Graphics.drawAtlasImage(AtlasManager.getAtlas("ui"),objects_sprite[i], Camera.getX() + 64*3 + 64*i + 16, Camera.getBottom() - 64 + 16, 0.5, 0.5);
  1814.                 }
  1815.                 // final lastScale = Graphics.fontScale;
  1816.             }
  1817.         }
  1818.  
  1819.         if(holding_object != -1){
  1820.             Graphics.setColor(Graphics.Gray);
  1821.             Graphics.drawAtlasImage(AtlasManager.getAtlas("ui"),objects_sprite[holding_object], Mouse.me.realx, Mouse.me.realy);
  1822.             Graphics.setColor(Graphics.White);
  1823.         }
  1824.  
  1825.         Graphics.drawString(current_file, Camera.getCenterX() - Graphics.stringWidth(current_file)*Graphics.fontScale/2, Camera.getY());
  1826.  
  1827.         if(draw_grid){
  1828.             var sx = Math.round(Camera.getLeft() / snap_size) - 1;
  1829.             var ex = Math.round((Camera.getLeft() + Camera.getWidth()) / snap_size) + 1;
  1830.  
  1831.             var sy = Math.round(Camera.getTop()/snap_size) -1 ;
  1832.             var ey = Math.round((Camera.getTop()+Camera.getHeight()) / snap_size) + 1;
  1833.  
  1834.             for(i in sx...ex){
  1835.                 for(j in sy...ey){
  1836.                     Graphics.drawLine(i*snap_size, sy*snap_size, i*snap_size, ey*snap_size, 2);
  1837.                     Graphics.drawLine(sx*snap_size, j*snap_size, ex*snap_size, j*snap_size, 2);
  1838.                 }
  1839.             }
  1840.         }
  1841.  
  1842.          // for(i in 0...actions.length){
  1843.          //     Graphics.drawString(actions[i], 0, i*32);
  1844.          // }
  1845.     }
  1846.  
  1847. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement