diff options
Diffstat (limited to 'Data')
13 files changed, 124 insertions, 128 deletions
diff --git a/Data/DefaultContent/Libraries/GameLab/Class.lua b/Data/DefaultContent/Libraries/GameLab/Class.lua index 62369e1..0b424a6 100644 --- a/Data/DefaultContent/Libraries/GameLab/Class.lua +++ b/Data/DefaultContent/Libraries/GameLab/Class.lua @@ -1,38 +1,79 @@ --- Declare class
+-- GameLab内置class模块
+-- 保留方法名:New, Ctor, Is
+-- 保留字段:_type, _base
-local _class = function (className)
- local class = {}
- local pkgName = (type(className) == "string") and string.match(className, "^(.+)%.%w+$") or ""
- local shortName = (type(className) == "string") and string.match(className, "%.*(%w+)$") or ""
- class._type = { -- 类型元数据,GameLab的类型都会包含这些
+local TrackClassInstances = false
+
+local _class = function (name, ctor)
+ local c = {}
+
+ local isstring = type(name) == "string"
+ local pkg = "unknown"
+ local short = "unknown"
+ if isstring then
+ pkg = string.match(name, "^(.+)%.%w+$")
+ short = string.match(name, "%.*(%w+)$")
+ end
+
+ c._type = {
mode = "lua",
- name = shortName or "",
- package = pkgName or "",
- fullName = className
+ name = short,
+ package = pkg,
+ fullName = name
}
- class.__index = class
- class.New = function(...)
- local instance = {}
- setmetatable(instance, class)
- instance:Ctor(...)
- return instance
+
+ c.__index = c
+
+ c.New = function(...)
+ local obj = {}
+ setmetatable(obj, c)
+ obj:Ctor(...)
+ return obj
end
- return class
+
+ c.Is = function(self, klass)
+ local m = getmetatable(self)
+ while m do
+ if m == klass then
+ return true
+ end
+ m = m._base
+ end
+ return false
+ end
+
+ if ctor and type(ctor) == "function" then
+ c.Ctor = ctor
+ end
+
+ local mt = {}
+
+ mt.__call = function(dummy, ...)
+ return c.New(...)
+ end
+
+ setmetatable(c, mt)
+
+ return c
end
--- 提供ClassName和PkgName作为类型的元数据,可以留空,但是最好提供,会作为类型判断的依据
-local Class = function(className)
- local cls = _class(className)
- cls.Extend = function(childName)
+local class = function(name, ctor)
+ local c = _class(name, ctor)
+
+ c.Extend = function(childName)
local child = _class(childName)
- if cls then
- setmetatable(child, cls)
- child.base = cls
+ if c then
+ setmetatable(child, c)
+ child._base = c
end
return child
end
- return cls
+
+ c._base = nil
+
+ return c
end
-GameLab.Class = Class
-return Class
\ No newline at end of file +GameLab.Class = class
+
+return class
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Camera.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Core/Camera.lua deleted file mode 100644 index 5fcfbe7..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Camera.lua +++ /dev/null @@ -1,5 +0,0 @@ -local Camera = {} - - - -return Camera
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Component.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Core/Component.lua deleted file mode 100644 index 00bf2ca..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Component.lua +++ /dev/null @@ -1,11 +0,0 @@ -local Component = {} - -Component.New = function() - -end - -Component.GetGameObject = function() - -end - -Jin.Component = Component
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Game.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Core/Game.lua deleted file mode 100644 index 51ce25f..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Game.lua +++ /dev/null @@ -1,14 +0,0 @@ - --- Game entry - -local Game = {} - -Game.OnEvent = function(e) - -end - -Game.MainLoop = function() - -end - -return Game
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Core/GameObject.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Core/GameObject.lua deleted file mode 100644 index ee0d143..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Core/GameObject.lua +++ /dev/null @@ -1,7 +0,0 @@ -local GameObject = {} - -GameObject.AddComponent = function(self, comp) - -end - -Jin.GameObject = GameObject diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Sprite.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Core/Sprite.lua deleted file mode 100644 index 47cb50d..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Core/Sprite.lua +++ /dev/null @@ -1,21 +0,0 @@ --- Quadķװʺ2DϷ -local Sprite = {} - -Sprite.New = function(quad) - local spr = {} - spr.quad = Jin.Quad.New(quad) - spr.pivot = Jin.Vector2.New(0.5, 0) - spr.transform = Jin.Transform.New() - spr.depth = 0 - return spr -end - -Sprite.SetDepth = function(self, depth) - spr.depth = depth -end - -Sprite.SetTexture = function(self, tex, reset_quad) - -end - -Jin.Sprite = Sprite
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua index 3655184..ecfc9ff 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua @@ -39,7 +39,7 @@ Vector4.Scale = function(self, scale) end
-Vector4.one = Vector4.New(1,1,1,1)
-Vector4.zero = Vector4.New(0,0,0,0)
+Vector4.one = Vector4(1,1,1,1)
+Vector4.zero = Vector4(0,0,0,0)
return Vector4
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua index 2785bdf..e70de4f 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua @@ -9,7 +9,7 @@ end Color.ToColor32 = function(self) local Color32 = GameLab.find("GameLab.Engine.Rendering.Color32") - local c32 = Color32.New() + local c32 = Color32() c32.r = self.r * 255 c32.g = self.g * 255 c32.b = self.b * 255 @@ -24,13 +24,13 @@ Color.Clear = function(self) self.a = 0 end -Color.red = Color.New(1,0,0,1) -Color.green = Color.New(0,1,0,1) -Color.blue = Color.New(0,0,1,1) -Color.magenta = Color.New(1,0,1,1) -Color.red = Color.New(1,0,0,1) -Color.yellow = Color.New(1,1,0,1) -Color.black = Color.New(0,0,0,1) -Color.white = Color.New(1,1,1,1) +Color.red = Color(1,0,0,1) +Color.green = Color(0,1,0,1) +Color.blue = Color(0,0,1,1) +Color.magenta = Color(1,0,1,1) +Color.red = Color(1,0,0,1) +Color.yellow = Color(1,1,0,1) +Color.black = Color(0,0,0,1) +Color.white = Color(1,1,1,1) return Color
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua index 48902b6..d1cacd7 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua @@ -9,7 +9,7 @@ end Color32.ToColor = function(self) local Color = GameLab.find("GameLab.Engine.Rendering.Color") - local c = Color.New() + local c = Color() c.r = self.r / 255 c.g = self.g / 255 c.b = self.b / 255 @@ -24,13 +24,13 @@ Color32.Clear = function(self) self.a = 0 end -Color32.red = Color32.New(255,0,0,255) -Color32.green = Color32.New(0,255,0,255) -Color32.blue = Color32.New(0,0,255,255) -Color32.magenta = Color32.New(255,0,255,255) -Color32.red = Color32.New(255,0,0,255) -Color32.yellow = Color32.New(255,255,0,255) -Color32.black = Color32.New(0,0,0,255) -Color32.white = Color32.New(255,255,255,255) +Color32.red = Color32(255,0,0,255) +Color32.green = Color32(0,255,0,255) +Color32.blue = Color32(0,0,255,255) +Color32.magenta = Color32(255,0,255,255) +Color32.red = Color32(255,0,0,255) +Color32.yellow = Color32(255,255,0,255) +Color32.black = Color32(0,0,0,255) +Color32.white = Color32(255,255,255,255) return Color32
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua b/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua index dcb5fba..7104480 100644 --- a/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua +++ b/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua @@ -1,18 +1,19 @@ local Class = GameLab.Class or require("GameLab.Class") -- 声明类的同时添加到G表 -local GlobalClass = function(className) - local cls = Class(className) +local GlobalClass = function(name, ctor) + local c = Class(name, ctor) - local shortName = string.match(className, "%.*(%w+)$") + local short = string.match(name, "%.*(%w+)$") + local pkgs = string.gmatch(name, "%.*(%w+)%.") local t = _G - for pkg in string.gmatch(className, "%.*(%w+)%.") do + for pkg in pkgs do t[pkg] = t[pkg] or {} t = t[pkg] end - t[shortName] = cls + t[short] = c - return cls + return c end GameLab.GlobalClass = GlobalClass diff --git a/Data/Libraries/GameLab/Editor/Window/ContainerWindow.lua b/Data/Libraries/GameLab/Editor/Window/ContainerWindow.lua index 1e75cdc..4b6f1bc 100644 --- a/Data/Libraries/GameLab/Editor/Window/ContainerWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/ContainerWindow.lua @@ -11,8 +11,8 @@ ContainerWindow.Ctor = function(self, position, showMode, min, max) self.m_RootSplitWindow = Window.SplitWindow.New(Window.ESplitMode.Horizontal) end -ContainerWindow.SetTitle = function(self) - self.m_Native:SetTitle(self) +ContainerWindow.SetTitle = function(self, title) + self.m_Native:SetTitle(title) end ContainerWindow.SetIcon = function(self) diff --git a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua index 51ee128..bbd368e 100644 --- a/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/GUIWindow.lua @@ -1,3 +1,15 @@ +--[[
+GameLab编辑器窗口
+
+窗口层级 触发事件 逻辑窗口 数量 说明
+ContainerWindow 是 [1,n] 有唯一的一个MainWindow,可以有多个其余ShowMode的窗口
+|- SplitWindow 是 1:1 一个ContainerWindow下只有一个root SplitWindow,然后以树形结构嵌套子窗口GUIWindow或SplitWindow
+ |- GUIWindow 是 1:[n,0] 一个SplitWindow下可能有GUIWindow,也可能是SplitWindow
+ |- EditorWindow 是 1:[n,1] 一个GUIWindow下至少有一个EditorWindow
+
+ContinerWindow和GUIWindow是windows事件产生的窗口,SplitWindow和EditorWindow是逻辑窗口,本身不会
+产生输入事件
+]]
local GUIWindow = GameLab.GlobalClass("GameLab.Editor.Window.GUIWindow")
local NativeGUIWindow = GameLab.Editor.Window.Internal.GUIWindow
@@ -38,7 +50,7 @@ GUIWindow.SetContainerWindow = function(self, containerWindow) end
GUIWindow.AddEditorWindow = function(self)
-
+
end
GUIWindow.SetPosition = function(self, pos)
diff --git a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua index 8f126a9..9a398c2 100644 --- a/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua +++ b/Data/Libraries/GameLab/Editor/Window/SplitWindow.lua @@ -3,6 +3,8 @@ local EEventType = GameLab.Events.EEventType local Math = require "GameLab.Engine.Math" local GUI = require "GameLab.Engine.GUI" local inspect = require "inspect" +local ECursor = GameLab.Editor.Window.ECursor +local Window = GameLab.Editor.Window local Rect = Math.Rect @@ -24,22 +26,21 @@ local SplitState = { } -- 抽象的窗口,用来处理布局 -local SplitWindow = GameLab.GlobalClass("GameLab.Editor.Window.SplitWindow") - -SplitWindow.Ctor = function(self, mode, splitter) +local SplitWindow = GameLab.GlobalClass("GameLab.Editor.Window.SplitWindow", function(self, mode, splitter) + self.m_ControlID = nil self.m_ContainerWindow = nil self.m_SplitMode = mode self.m_Parent = nil -- 父节点是一个split window或者空 self.m_SubWindows = {} -- 子窗口,可以是SplitWindow或GUIWindow self.m_Splitter = {} - self.m_Position = Rect.New() + self.m_Position = Rect() if splitter ~= nil and type(splitter) == "table" then for _, v in ipairs(splitter) do - local sp = Splitter.New(v) + local sp = Splitter(v) table.insert(self.m_Splitter, sp) end end -end +end) -- 布局,设置GUIWindow的大小 SplitWindow.DoSplit = function(self, event) @@ -47,12 +48,11 @@ SplitWindow.DoSplit = function(self, event) self.m_Parent:DoSplit(event) end - local id = GUI.GetControlID() + self.m_ControlID = GUI.GetControlID() if event.type == EEventType.MouseDown then - local bHandled = false for i, sp in ipairs(self.m_Splitter) do - local rect = Rect.New() + local rect = Rect() if self.m_SplitMode == ESplitMode.Horizontal then local x = sp.value * self.m_Position.width + self.m_Position.x - sp.size / 2 local w = sp.size @@ -70,14 +70,13 @@ SplitWindow.DoSplit = function(self, event) end if rect:Contains(event.mousePosition) then SplitState.currentSplitter = sp - GUI.SetHotControl(id) - bHandled = true + GUI.SetHotControl(self.m_ControlID) break end end elseif event.type == EEventType.MouseDrag then local hot = GUI.GetHotControl() - if hot == id then + if hot == self.m_ControlID then local splitter = SplitState.currentSplitter if splitter ~= nil then local mousePos = event.mousePosition @@ -93,7 +92,8 @@ SplitWindow.DoSplit = function(self, event) end end elseif event.type == EEventType.MouseUp then - if GUI.GetHotControl() == id then + if GUI.GetHotControl() == self.m_ControlID then + GUI.SetHotControl(0) SplitState.currentSplitter = nil end end @@ -105,7 +105,7 @@ SplitWindow.SetPosition = function(self, position) for i, subWindow in ipairs(self.m_SubWindows) do local prev = i > 1 and self.m_Splitter[i-1].value or 0 local next = i <= #self.m_Splitter and self.m_Splitter[i].value or 1 - local pos = Rect.New() + local pos = Rect() pos:CopyFrom(position) if self.m_SplitMode == ESplitMode.Horizontal then pos.x = pos.x + prev * position.width @@ -119,7 +119,7 @@ SplitWindow.SetPosition = function(self, position) end SplitWindow.GetPosition = function(self) - local pos = Rect.New() + local pos = Rect() pos:CopyFrom(self.m_Position) return pos end |