private void DrawUiHierarchyFrame() { var size = ImGui.GetContentRegionAvail(); var itemSpacing = ImGui.GetStyle().ItemSpacing + NVector2.UnitY * 4; ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, itemSpacing); ImGui.Text($"{ImGuiEx.IcoMoon.ListIcon} Hierarchy"); ImGui.BeginChildFrame(2, size - NVector2.UnitY * 256); { // create sprite bool itemHovered = false; ImGui.Text($"{ImGuiEx.IcoMoon.ImagesIcon} Entities"); ImGui.SameLine(); if (_state.Textures.Count > 0) { if (ImGui.SmallButton($"{ImGuiEx.IcoMoon.PlusIcon}##1")) { ImGui.OpenPopup("Create entity"); ImGuiEx.DoEntityCreatorReset(); } } else { ImGuiEx.DisabledButton($"{ImGuiEx.IcoMoon.PlusIcon}"); } ImGuiEx.DoEntityCreatorModal(_state.Textures.Keys.ToArray(), (name, selectedTexture) => { Entity entity = new Entity(name, selectedTexture); var propDef = _state.PropertyDefinitions[POSITION_PROPERTY]; entity.SetCurrentPropertyValue(propDef, propDef.CreateInstance()); _state.Animator.CreateTrack(propDef.Type, name, POSITION_PROPERTY); var fiPropDef = _state.PropertyDefinitions[FRAMEINDEX_PROPERTY]; entity.SetCurrentPropertyValue(fiPropDef, fiPropDef.CreateInstance()); _state.Animator.CreateTrack(fiPropDef.Type, name, FRAMEINDEX_PROPERTY); _state.Entities[entity.Id] = entity; }); // show all created entities ImGui.Indent(); foreach (var entity in _state.Entities.Values) { bool selected = selectedEntityId == entity.Id; ImGui.Selectable(entity.Id, ref selected); if (selected) { selectedTextureId = string.Empty; selectedEntityId = entity.Id; } if (ImGui.IsItemHovered()) { itemHovered = true; hoveredentityId = entity.Id; } } ImGui.Unindent(); if (!itemHovered) { hoveredentityId = string.Empty; } // Add textures ImGui.Text($"{ImGuiEx.IcoMoon.TextureIcon} Textures"); ImGui.SameLine(); if (ImGui.SmallButton($"{ImGuiEx.IcoMoon.PlusIcon}##2")) { _openFdDefinition = ImGuiEx.CreateFilePickerDefinition(Assembly.GetExecutingAssembly() .Location, "Open", ".png"); ImGui.OpenPopup("Load texture"); } DoPopup("Load texture", ref _openFdDefinition, () => { var key = Path.GetFileNameWithoutExtension(_openFdDefinition.SelectedFileName); if (!_state.Textures.ContainsKey(key)) { var path = _openFdDefinition.SelectedRelativePath; var texture = Texture2D.FromFile(GraphicsDevice, path); _state.Textures[key] = new TextureFrame(texture, path, new NVector2(32, 32), new NVector2(16, 16)); } }); // show all loaded textures ImGui.Indent(); foreach (var texture in _state.Textures.Keys) { bool selected = selectedTextureId == texture; ImGui.Selectable(texture, ref selected); if (selected) { selectedEntityId = string.Empty; selectedTextureId = texture; } } ImGui.Unindent(); ImGui.TreePop(); } ImGui.EndChildFrame(); ImGui.PopStyleVar(); }