From 9b1f8214eea0c86d41f903a5feba9aac78603df1 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 12 Nov 2021 19:13:03 +0800 Subject: *misc --- .../Libraries/GameLab/Debug/init.lua | 5 +++ .../Libraries/GameLab/Engine/GUI/IMGUI.lua | 11 ++++++- .../Libraries/GameLab/Engine/GUI/init.lua | 2 +- .../Libraries/GameLab/Engine/Math/Rect.lua | 13 +++++++- .../Libraries/GameLab/Engine/Math/Vector2.lua | 12 ++++++++ .../Libraries/GameLab/Engine/Utils/EventCenter.lua | 23 -------------- .../GameLab/Engine/Utils/StateMachine.lua | 0 .../Libraries/GameLab/Engine/Utils/Util.lua | 0 .../Libraries/GameLab/Utils/init.lua | 4 +++ Data/Libraries/GameLab/Editor/Window/GUIWindow.lua | 36 ++++++++++++++-------- .../GameLab/Editor/Window/SplitWindow.lua | 26 +++++++++++----- Data/boot.lua | 1 + 12 files changed, 88 insertions(+), 45 deletions(-) create mode 100644 Data/DefaultContent/Libraries/GameLab/Debug/init.lua delete mode 100644 Data/DefaultContent/Libraries/GameLab/Engine/Utils/EventCenter.lua delete mode 100644 Data/DefaultContent/Libraries/GameLab/Engine/Utils/StateMachine.lua delete mode 100644 Data/DefaultContent/Libraries/GameLab/Engine/Utils/Util.lua create mode 100644 Data/DefaultContent/Libraries/GameLab/Utils/init.lua (limited to 'Data') diff --git a/Data/DefaultContent/Libraries/GameLab/Debug/init.lua b/Data/DefaultContent/Libraries/GameLab/Debug/init.lua new file mode 100644 index 0000000..47a507d --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/Debug/init.lua @@ -0,0 +1,5 @@ +local Debug = GameLab.Debug or {} +GameLab.Debug = Debug + + +return Debug \ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/GUI/IMGUI.lua b/Data/DefaultContent/Libraries/GameLab/Engine/GUI/IMGUI.lua index 2b763e7..33299a2 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/GUI/IMGUI.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/GUI/IMGUI.lua @@ -7,7 +7,8 @@ local Event = GameLab.Events.Event local imgui = { currentId = 0, -- 当前可分配的controlID -} + hotControl = 0, +} GUI.GetControlID = function() imgui.currentId = imgui.currentId + 1 @@ -31,6 +32,14 @@ GUI.EndFrame = function() end +GUI.SetHotControl = function(id) + imgui.hotControl = id +end + +GUI.GetHotControl = function() + return imgui.hotControl +end + ------------------------------------------------------------------------------------------------ -- 控件 ------------------------------------------------------------------------------------------------ diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/GUI/init.lua b/Data/DefaultContent/Libraries/GameLab/Engine/GUI/init.lua index 4b83ddc..4424a2a 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/GUI/init.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/GUI/init.lua @@ -1,3 +1,3 @@ local import = GameLab.import(...) -import("IMGUI") +import("imgui") diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua index ba18637..e52f8f0 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua @@ -14,6 +14,16 @@ Rect.Set = function(self, rect) self.w = rect.w or rect[4] end +Rect.GetPosition = function(self) + local v = GameLab.Engine.Math.Vector2.New(self.x, self.y) + return v +end + +Rect.GetSize = function(self) + local v = GameLab.Engine.Math.Vector2.New(self.width, self.height) + return v +end + Rect.CopyFrom = function(self, rect) self.x = rect.x self.y = rect.y @@ -22,7 +32,8 @@ Rect.CopyFrom = function(self, rect) end Rect.Contains = function(self, point) - + return point.x >= self.x and point.x <= self.x + self.width + and point.y >= self.y and point.y <= self.y + self.height end return Rect \ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua index 9a0e0a3..eb4c14b 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua @@ -5,4 +5,16 @@ Vector2.Ctor = function(self, x, y) self.y = y or 0 end +Vector2.__add = function(self, other) + self.x = self.x + other.x + self.y = self.y + other.y + return self +end + +Vector2.Add = function(self, other) + self.x = self.x + other.x + self.y = self.y + other.y + return self +end + return Vector2 \ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Utils/EventCenter.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Utils/EventCenter.lua deleted file mode 100644 index 664ecba..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Utils/EventCenter.lua +++ /dev/null @@ -1,23 +0,0 @@ -local EventCenter = {} - -EventCenter.Subscribe = function(event, callback) - -end - -EventCenter.Unsubscribe = function(event, callback) - -end - -EventCenter.UnsubscribeAll = function(event) - -end - -EventCenter.Publish = function(event, ...) - -end - -EventCenter.Clear = function() - -end - -Jin.EventCenter = EventCenter \ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Utils/StateMachine.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Utils/StateMachine.lua deleted file mode 100644 index e69de29..0000000 diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Utils/Util.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Utils/Util.lua deleted file mode 100644 index e69de29..0000000 diff --git a/Data/DefaultContent/Libraries/GameLab/Utils/init.lua b/Data/DefaultContent/Libraries/GameLab/Utils/init.lua new file mode 100644 index 0000000..0ca5131 --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/Utils/init.lua @@ -0,0 +1,4 @@ +local utils = GameLab.Utils or {} +GameLab.Utils = utils + +return uitls \ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua index cb05518..6f6335b 100644 --- a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua @@ -1,15 +1,17 @@ local GUIWindow = GameLab.GlobalClass("GameLab.Editor.Window.GUIWindow") local NativeGUIWindow = GameLab.Editor.Window.Internal.GUIWindow -local inspect = require("inspect") - -local Debug = GameLab.Debug -local GL = GameLab.Engine.GL -local Math = GameLab.Engine.Math -local Rendering = GameLab.Engine.Rendering - -local Rect = Math.Rect -local Event = GameLab.Events.Event +local inspect = require("inspect") +local Debug = require("GameLab.Debug") +local GL = require("GameLab.Engine.GL") +local Math = require("GameLab.Engine.Math") +local Rendering = require("GameLab.Engine.Rendering") +local Utils = require("GameLab.Utils") +local Events = require("GameLab.Events") + +local Rect = Math.Rect +local Event = Events.Event +local Vector2 = Math.Vector2 local i = 0 local col = { @@ -22,7 +24,7 @@ GUIWindow.Ctor = function(self) self.m_Native = NativeGUIWindow.New(self) self.m_ContainerWindow = nil self.m_SplitWindow = nil -- parent window - self.m_Position = Rect.New(0,0,0,0) -- 在父窗口中的位置和大小 + self.m_Position = Rect.New(0,0,0,0) -- 在父ContainerWindow中的位置和大小 self.m_EditorWindows = {} -- 编辑器脚本 i = i + 1 @@ -34,11 +36,19 @@ GUIWindow.SetContainerWindow = function(self, containerWindow) self.m_Native:SetContainerWindow(containerWindow:GetNative()) end +GUIWindow.AddEditorWindow = function(self) + +end + GUIWindow.SetPosition = function(self, pos) self.m_Position:Set(pos) self.m_Native:SetPosition(pos) end +GUIWindow.GetPosition = function(self) + return self.m_Position +end + GUIWindow.GetNative = function(self) return self.m_Native end @@ -48,8 +58,10 @@ GUIWindow.OnGUI = function(self) local event = Event.current - if self.m_SplitWindow then - self.m_SplitWindow:DoSplit(event) + if self.m_SplitWindow then + local e = Events.CopyEvent(event) + e.mousePosition:Add(self.m_Position:GetPosition()) + self.m_SplitWindow:DoSplit(e) end end diff --git a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua index 597e858..9dd6446 100644 --- a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua @@ -1,5 +1,7 @@ -local Debug = GameLab.Debug -local Rect = require("GameLab.Engine.Math.Rect") +local Debug = GameLab.Debug +local EEventType = GameLab.Events.EEventType +local Rect = require("GameLab.Engine.Math.Rect") +local GUI = require("GameLab.Engine.GUI") local Splitter = GameLab.Class("GameLab.Editor.Window.Internal.Splitter") @@ -22,21 +24,31 @@ SplitWindow.Ctor = function(self, mode, splitter) self.m_SubSplit = {} -- 子节点也是split windows self.m_GUIWindow = {} -- 不包含subSplit的有一个GUIWindow self.m_Splitter = {} + self.m_CurSplitter = nil self.m_ContainerWindow = nil if splitter ~= nil and type(splitter) == "table" then for _, v in ipairs(splitter) do local sp = Splitter.New(v) table.insert(self.m_Splitter, sp) end - end + end end -- 布局,设置GUIWindow的大小 SplitWindow.DoSplit = function(self, event) - -- local position = self:GetPosition() - -- for _, sp in ipairs(self.m_SubSplit) do - -- sp:DoSplit(event) - -- end + if self.m_Parent ~= nil then + self.m_Parent:DoSplit(event) + end + + local id = GUI.GetControlID() + + if event.type == EEventType.MouseDown then + + elseif event.type == EEventType.MouseDrag then + + elseif event.type == EEventType.MouseUp then + + end end -- 返回在containerWindow下的像素大小和位置 diff --git a/Data/boot.lua b/Data/boot.lua index 9d372c9..091aff0 100644 --- a/Data/boot.lua +++ b/Data/boot.lua @@ -24,6 +24,7 @@ end -- load gamelab modules require "GameLab" +require "GameLab.Utils" require "GameLab.Events" require "GameLab.Engine" require "GameLab.Engine.GUI" -- cgit v1.1-26-g67d0