---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by luojunxin.
--- DateTime: 2020/6/24 16:07
---


UI_ENTITY_LIST_VIEW = "EntityListView";
local Ui = Ui or class(UI_ENTITY_LIST_VIEW, LUiBase);
_G.UI_ENTITY_LIST_VIEW = UI_ENTITY_LIST_VIEW;

function Ui:ctor()
    self.m_bOpen = false;
    self.m_szName = UI_ENTITY_LIST_VIEW;
end

function Ui:dtor()
    --
end

function Ui:GameTick()
    --
end

function Ui:GameDraw()
    ImGui.SetNextWindowSize(ImVec2(250, 500), ImGuiCond_.ImGuiCond_FirstUseEver);
    _, self.m_bOpen = ImGui.Begin(self.m_szName, self.m_bOpen);
    self:draw();
    ImGui.End();
end

function Ui:draw()
    local nCount = 0;
    local szCurrID = g_DataStorage:GetCurrentID();
    ImGui.SetNextItemWidth(-1);
    ImGui.Columns(2);
    ImGui.Separator();
    ImGui.Text("ID"); ImGui.NextColumn();
    ImGui.Text("Name"); ImGui.NextColumn();
    ImGui.Separator();
    for k,v in pairs(g_DataStorage.m_actors) do
        if ImGui.Selectable(v.m_id, szCurrID == k, ImGuiSelectableFlags_.ImGuiSelectableFlags_SpanAllColumns) then
            local tempActor = g_DataStorage:GetCurrentEntity();
            if tempActor ~= nil then tempActor:SetOutlineState(false) end
            g_DataStorage:SetCurrentID(k);
            g_DataStorage:GetCurrentEntity():SetOutlineState(true);
        end
        if szCurrID == k and ImGui.BeginPopupContextItem("entity context menu", 1) then
            if ImGui.SmallButton("delete") then
                local action = LActionEntityRemove:new();
                action:Init(k);
                g_UndoRedoManager:AddAction(action);
                g_DataStorage.m_actors[action.szID] = nil;
                action.target:SetVisible(false);
            end
            ImGui.EndPopup();
        end
        ImGui.NextColumn();
        ImGui.Text(v.m_name); ImGui.NextColumn();
    end
end

UiInst = Ui:new();
