---
--- Date         : 2020-05-28 09:02:49
--- Author       : HUAFEI2.
--- LastEditors  : LICHAO7
--- LastEditTime : 2020-08-14 16:14:45
--- Description  : 调整整理菜单
---

--
-- !!!这里只是处理基本菜单结构，可以添加主菜单的选项，请根据具体功能分类添加子项或新建大的功能分类
-- !!!如果有测试功能、临时功能等，请添加至others_com.lua中
--

_G.UI_MAIN_MENU_BAR = "MainMenuBar";
local Ui = Ui or class(_G.UI_MAIN_MENU_BAR, LUiBase);
local OthersCom = ReLoadScript("ugc_common/script/cases/main_menu_bar/others_com.lua");
local UndoRedo = ReLoadScript("ugc_common/script/cases/main_menu_bar/undo_redo_list.lua")

function Ui:ctor()
    self.m_szName    = UI_MAIN_MENU_BAR;
    self.m_bOpen     = true;
    self.m_bShowDemo = false;
    self.m_szMenuMainRole        = util.a2u8("主角");
    self.m_szMenuVehicle         = util.a2u8("载具");
    self.m_szMenuSimpleFlight    = util.a2u8("飞行器");
    self.m_szMenuVehicleList     = util.a2u8("车");
    self.m_szSceneEditor         = util.a2u8("场景编辑");
    self.m_szMenuItemChangeCloth = util.a2u8("换装");
    self.m_szMenuItemFaceMaker   = util.a2u8("捏脸");
    self.m_szMenuSetting         = util.a2u8("设置");
    self.m_szGameSetting         = util.a2u8("游戏设置");
    self.m_szMenuModelAssemble   = util.a2u8("组装");
    self.m_szEntityEditor        = util.a2u8("物件编辑")
    self.m_szSaveMap             = util.a2u8("保存地图");
    self.m_szLoadMap             = util.a2u8("重新加载地图");
    self.m_szMenuOthers          = util.a2u8("其他测试项");
    self.m_szUndo                = util.a2u8("撤销");
    self.m_szRedo                = util.a2u8("重做");
    self.m_szUndoRedoList        = util.a2u8("v");
    self.m_szMenuDestruction     = util.a2u8("破碎");
    -- Mobile UI
    self.m_szMyList              = util.a2u8("我的");
    self.m_szGeneralSetting      = util.a2u8("通用设置");
    self.m_szCheckUpdate         = util.a2u8("检查更新");
    self.m_szImportFile          = util.a2u8("导入文件");
    self.m_szAR                  = util.a2u8("AR选项");
    self.m_szEnterAR             = util.a2u8("进入AR");
    self.m_szExitAR              = util.a2u8("退出AR");
    self.m_szARSetting           = util.a2u8("AR设置");
    self.m_szRecorder            = util.a2u8("拍照/录屏")
    self.m_szRoleManager         = util.a2u8("角色管理");

end

function Ui:GameDraw()
    local bOpen = ImGui.BeginMainMenuBar();
    if bOpen ~= true then
        return;
    end

    -- Any
    self:DrawMainRoleMenu();
    -- For pc
    self:DrawVehicleMenu();
    self:DrawDestructionMenu();
    self:DrawSceneEditor();
    -- Any
    self:DrawSetting();
    self:DrawDebugCom();
    self:DrawOthersCom();

    -- For Mobile
    self:DrawMyList()
    self:DrawARList()

    ImGui.EndMainMenuBar();
end

---
--- 绘制载具菜单
---
function Ui:DrawVehicleMenu()
    if not PLATFORM_PC then return end;

    if ImGui.BeginMenu(self.m_szMenuVehicle) then
        local bOpen = _G.g_uiManager:GetOpenClose(_G.UI_VEHICLE);
        _G.g_uiManager:SetOpenClose(_G.UI_VEHICLE, not bOpen);
        ImGui.EndMenu();
    end
end

---
--- 绘制破碎系统菜单
---
function Ui:DrawDestructionMenu()
    if true then return end;
    if not PLATFORM_PC then return end;

    if ImGui.BeginMenu(self.m_szMenuDestruction) then
        local bOpen = _G.g_uiManager:GetOpenClose(_G.UI_DESTRUCTION);
        _G.g_uiManager:SetOpenClose(_G.UI_DESTRUCTION, not bOpen);
        ImGui.EndMenu();
    end
end

---
--- 绘制SceneEditor相关菜单
---
function Ui:DrawSceneEditor()
    if not PLATFORM_PC then return end;

    if g_UndoRedoManager:CanUndo() then
        if ImGui.MenuItem(self.m_szUndo, "CTRL+Z", false) then
            g_UndoRedoManager:Undo();
        end
    else
        ImGui.MenuItem(self.m_szUndo, "CTRL+Z", false, false);
    end

    if ImGui.BeginMenu(self.m_szUndoRedoList) then
        UndoRedo.DrawUndoRedoList();
        ImGui.EndMenu();
    end

    if g_UndoRedoManager:CanRedo() then
        if ImGui.MenuItem(self.m_szRedo, "CTRL+Y", false) then
            g_UndoRedoManager:Redo();
        end
    else
        ImGui.MenuItem(self.m_szRedo, "CTRL+Y", false, false);
    end

    if ImGui.BeginMenu(self.m_szSceneEditor) then
        if ImGui.MenuItem(self.m_szEntityEditor) then
            local bOpen = g_uiManager:GetOpenClose(UI_MODEL_LIST_VIEW);
            bOpen = bOpen and g_uiManager:GetOpenClose(UI_ENTITY_LIST_VIEW);
            bOpen = bOpen and g_uiManager:GetOpenClose(UI_ENTITY_PROPERTY_VIEW);
            g_uiManager:SetOpenClose(UI_MODEL_LIST_VIEW, not bOpen);
            g_uiManager:SetOpenClose(UI_ENTITY_LIST_VIEW, not bOpen);
            g_uiManager:SetOpenClose(UI_ENTITY_PROPERTY_VIEW, not bOpen);
        end

        if ImGui.MenuItem(self.m_szSaveMap) then
            g_DataStorage:Save();
        end

        if ImGui.MenuItem(self.m_szLoadMap) then
            g_DataStorage:Load();
        end

        ImGui.EndMenu();
    end
end

---
--- 绘制主角菜单
---
function Ui:DrawMainRoleMenu()
    if ImGui.BeginMenu(self.m_szMenuMainRole) then
        if ImGui.MenuItem(self.m_szMenuItemChangeCloth) then
            local bOpen = g_uiManager:GetOpenClose(UI_CHANGE_CLOTH);
            g_uiManager:SetOpenClose(UI_CHANGE_CLOTH, not bOpen);
        end
        if ImGui.MenuItem(self.m_szMenuItemFaceMaker) then
            local bOpen = g_uiManager:GetOpenClose(UI_MAKE_FACE);
            g_uiManager:SetOpenClose(UI_MAKE_FACE, not bOpen);
        end
        if ImGui.MenuItem(self.m_szRoleManager) and not PLATFORM_PC then
            local bOpen = g_uiManager:GetOpenClose(UI_SCHOOL_ROLE_LIST);
            g_uiManager:SetOpenClose(UI_SCHOOL_ROLE_LIST, not bOpen);
        end
        ImGui.EndMenu();
    end
end

function Ui:DrawSetting()
    if ImGui.BeginMenu(self.m_szMenuSetting) then
        if ImGui.MenuItem(self.m_szGameSetting) then
            local bOpen = g_uiManager:GetOpenClose(UI_GAME_SETTING);
            g_uiManager:SetOpenClose(UI_GAME_SETTING, not bOpen);
        end
        ImGui.EndMenu();
    end
end

---
--- 绘制调试菜单（仅g_App:IsDebug()==true时生效）
---
function Ui:DrawDebugCom()
    if not g_App:IsDebug() then return end;

    if ImGui.BeginMenu("Debug") then
        if ImGui.MenuItem("Reload") then
            g_App:ReloadModule("ugc_common/script/core/reload.lua");
        end

        if ImGui.MenuItem("Console") then
            local bOpen = _G.g_uiManager:GetOpenClose(_G.UI_INGAME_CONSOLE);
            _G.g_uiManager:SetOpenClose(_G.UI_INGAME_CONSOLE, not bOpen);
        end
        ImGui.EndMenu();
    end
end

---
--- 绘制其他选项菜单（仅g_App:IsDebug()==true时生效）
---
function Ui:DrawOthersCom()
    if not g_App:IsDebug() then return end;

    if ImGui.BeginMenu(self.m_szMenuOthers) then
        OthersCom.DrawOthersCom(self);
        ImGui.EndMenu();
    end
    if self.m_bShowDemo then
        self.m_bShowDemo = ImGui.ShowDemoWindow(self.m_bShowDemo);
    end
end

---
--- 绘制我的选项菜单
---
function Ui:DrawMyList()
    if PLATFORM_PC then return end

    if ImGui.BeginMenu(self.m_szMyList) then
        if ImGui.MenuItem(self.m_szGeneralSetting) then
            local bOpen = g_uiManager:GetOpenClose(UI_GENERAL_SETTING);
            g_uiManager:SetOpenClose(UI_GENERAL_SETTING, not bOpen);
        end
        if ImGui.MenuItem(self.m_szCheckUpdate) then
            KLPlatformNative:CheckUpdate()
        end
        if ImGui.MenuItem(self.m_szImportFile) then
            KLPlatformNative:ImportFile()
        end
        ImGui.EndMenu()
    end
end

function Ui:DrawARList()
    if PLATFORM_PC then return end

    if ImGui.BeginMenu(self.m_szAR) then
        if ImGui.MenuItem(self.m_szEnterAR) then
            KLPlatformNative:StartAR()
        end

        if ImGui.MenuItem(self.m_szARSetting) then
            local bOpen = g_uiManager:GetOpenClose(UI_AR_SETTING);
            g_uiManager:SetOpenClose(UI_AR_SETTING, not bOpen);
        end

        if KLPlatformNative:IsARMode() then
            if ImGui.MenuItem(self.m_szRecorder) then
                KLPlatformNative:ChangeRecordingState(true)
                KLPlatformNative:ShowRecording()
                KLPlatformNative:SetVideoRecorderCfg()
            end
        end

        if ImGui.MenuItem(self.m_szExitAR) then
            KLPlatformNative:StopAR()
            g_CameraController:ResetCamera()
            g_ActorManager:ResetActorCreatedInfo();
            local tPlayer = g_ActorManager:GetLocalPlayer();
            tPlayer:SetAdditionnalObjectVisibal("选择特效a003.sfx", false);
            tPlayer:SetWorldPosition(0,0,0)
            tPlayer:SetWorldRotation(0,0,0)
            tPlayer:SetWorldScale(1,1,1)
        end
        ImGui.EndMenu()
    end
end

UiInst = Ui:new();
