遊戲的mvvm架構學習筆記

2021-10-21 19:48:58 字數 3631 閱讀 8596

遊戲的mvvm架構

loxodon.framework.xlua 是乙個xlua的開源的mvvm框架

loxodonframework是乙個輕量級的mvvm(model-view-viewmodel)框架,它是專門為unity3d遊戲開發設計的

require

("framework.system"

)local context = cs.loxodon.framework.contexts.context

local ******command = cs.loxodon.framework.commands.******command

local asynctask = cs.loxodon.framework.asynchronous[

"asynctask`1[system.object]"

]local observableobject =

require

("framework.observableobject"

)local observabledictionary =

require

("framework.observabledictionary"

)local interactionrequest =

require

("framework.interactionrequest"

)---

--模組

--@module loginviewmodel

local m=

class

("loginviewmodel"

,observableobject)

--執行父類observableobject的建構函式,這個重要,否則無法監聽資料改變

--[[--

建構函式

@param #table self

@param #table t 初始化引數

]]function m:

ctor

(t) m.super.

ctor

(self,t)

self.username = self.globalpreferences:

getstring

("last_username",""

);self.password =

"" self.account =

nil self.errors =

observabledictionary()

self.logincommand =

******command

(function

() self:

login()

end,

true

) self.cancelcommand =

******command

(function

() self.interactionfinished:

raise

(nil

)end

,true

) self.interactionfinished =

interactionrequest

(self)

self.toastrequest =

interactionrequest

(self)

endfunction m:

validateusername()

endfunction m:

validatepassword()

endfunction m:

login()

endreturn m

require

("framework.system"

)local loading = cs.loxodon.framework.views.loading

local toast = cs.loxodon.framework.views.toast

-----模組

--@module loginview

local m=

class

("loginview"

,target)

function m:

oncreate

(bundle)

local bindingset = self:

createbindingset()

; bindingset:

bind()

:for

("oninteractionfinished"):

to("interactionfinished"

) bindingset:

bind()

:for

("ontoastshow"):

to("toastrequest"

) bindingset:

bind

(self.username)

:for

("text"

,"onendedit"):

to("username"):

twoway()

bindingset:

bind

(self.usernameerrorprompt)

:for

("text"):

to("errors['username']"):

oneway()

bindingset:

bind

(self.password)

:for

("text"

,"onendedit"):

to("password"):

twoway()

bindingset:

bind

(self.passworderrorprompt)

:for

("text"):

to("errors['password']"):

oneway()

bindingset:

bind

(self.confirmbutton)

:for

("onclick"):

to("logincommand"

) bindingset:

bind

(self.cancelbutton)

:for

("onclick"):

to("cancelcommand"

) bindingset:

build()

endfunction m:

oninteractionfinished

(sender, args)

self:

dismiss()

endfunction m:

ontoastshow

(sender, args)

local notification = args.context

ifnot notification then

return

end toast.

show

(self, notification,2)

;end

return m

WPF學習筆記五之MVVM

1.概念 mvvm是model view viewmodel的縮寫形式,它通常被用於wpf或silverlight開發。這三者之間的關係如下圖所示 模型 model model 可以理解為帶有字段,屬性的類。檢視 view view 可以理解為我們所看到的ui。檢視模型 view model vie...

架構學習筆記

裝飾者模式隱含的是通過一條條裝飾鏈去實現具體物件,每一條裝飾鏈都始於乙個componet物件,每個裝飾者物件後面緊跟著另乙個裝飾者物件,而物件鏈終於concretecomponet物件。concretecomponent 讓decorator物件為自己新增功能。有時候使用concretecompon...

MySQL 學習筆記 架構

1 mysql伺服器邏輯架構圖 第一層 該服務並不是mysql所獨有的,大多數基於網路的客戶端 伺服器的工具或者服務都有的類似的架構。比如連線處理 授權認證 安全等等。第二層 mysql的核心服務功能,包括查詢解析 分析 優化 快取以及所有的內建函式 日期 時間 加密 所有跨存引擎的功能都在這裡實現...