MiniExtend UI

对应源文件: ui.lua


UI 作用域

MiniExtend UI 前身为 Customui ,但以面相对象方式描述界面与元件,且支持 MiniExtend Object

约定

大多数 UI 下的函数都会包含一个 [, playerid] 参数,它表示要响应该操作的玩家 id ,该参数不会被检查,如果 playerid 的布尔值为 false ,则以 objid 代替。
UI 下的所有未表明返回值的函数或方法,一律返回 true 表示调用 API 成功,返回 false 表示失败

UI.getRootSize() 函数


UI 下的类之间的关系

类名 类描述 父类 具象
UIView UI 界面 /
Element UI 元件 / ×
Texture UI 图片 Element
Button UI 按钮 Texture
Label UI 文字 Element
EditBox UI 输入框 Label

UI.UIView

一个 UI.UIView 对象代表了一个 UI 界面,以下简称 UIView

构造函数

属性

方法

UI.Element

一个 UI.Element 对象代表一个 UI 元件,以下简称 Element
该类非具象类,不能直接构造 Element 对象,应构造 Element 子类的对象。

属性

方法

UI.Texture

一个 UI.Texture 对象代表一个 UI 图片元件,以下简称 Texture
使用 UI.Texture:new(uiview, elementid); 来构造一个 Texture 对象。

方法

UI.Button

一个 UI.Button 对象代表一个 UI 图片元件,以下简称 Button
使用 UI.Button:new(uiview, elementid); 来构造一个 Button 对象。

属性

UI.Label

一个 UI.Label 对象代表一个 UI 文字元件,以下简称 Label
使用 UI.Label:new(uiview, elementid); 来构造一个 Label 对象。

方法

UI.EditBox

一个 UI.EditBox 对象代表一个 UI 输入框元件,以下简称 EditBox
使用 UI.EditBox:new(uiview, elementid); 来构造一个 EditBox 对象。

属性

实例

情形

已知一 UI 界面 u 下有一个输入框元件 e 和一个文字元件 l ,要求如下:

分析

代码

Env.__init__()
-- 需替换以下 id
local uiview_id = [[]]
local editBox_id = [[]]
local label_id = [[]]
local button_id = [[]]
uiview = UI.UIView:new(uiview_id)
editBox = uiview:newEditBox(editBox_id)
label = uiview:newLabel(label_id)
button = uiview:newButton(button_id)
-- 初始化
registerEvent([[Game.AnyPlayer.EnterGame]], function(param)
    uiview:show()
    label:setText("")
    editBox:setText("输入 16 进制数")
end)
function button.clickEvent(param)
    -- 清空输入框
    editBox:setText("")
end
function editBox.lostFocusEvent(param)
    local num = tonumber(param["content"], 16)
    if num then
        label:setText(tostring(num))
    else
        label:setText("错误的输入")
    end
    editBox:setText("输入 16 进制数")
end