|
-
- local CRConfig = require("luaScript.Views.CreateRoom.Com.CRConfig")
-
- -- 主界面
- local CreateRoomItemNew = class("CreateRoomItemNew", cc.UIView)
-
- function CreateRoomItemNew:ctor(datas, defaultValues, gameId, gameRule)
- CreateRoomItemNew.super.ctor(self);
-
- local filename = string.format("CreateRoomRule_%03d", gameId)
-
- self.gameId = gameId
- self.gameRule = gameRule
- self.datas = datas
- self.defaultValues = defaultValues
-
- if self.defaultValues and table.nums(self.defaultValues) <= 0 then
- self.defaultValues = nil
- end
-
- self.ui = loadUI("res/ui/ui_chuangjian/ui_chuangjian_0.ui");
- self:addChild(self.ui)
-
- end
-
- function CreateRoomItemNew:getNode()
- return self.ui
- end
-
- function CreateRoomItemNew:removeFromParent()
- if self.ui then
- self.ui:removeFromParent()
- end
- end
-
- function CreateRoomItemNew:onEnter()
- CreateRoomItemNew.super.onEnter(self)
-
- -- 监听支付方式的变化
- self.ui:bindEvent(app, CRConfig.CREATE_ROOM_VALUE_CHANGE, handler(self, self.onValueChanged))
-
- local line = self.ui.Items.ImageView_0
-
- self.uiGroups = {}
-
- for i,v in pairsByKeys(self.datas) do
- local itemGroup = CRConfig.createGroupNode(v, self.defaultValues)
- if itemGroup and itemGroup.ui then
- self.uiGroups[v.key] = itemGroup
- self.ui.Items.Layout_1:addChild(itemGroup.ui)
- self.ui.Items.Layout_1:addChild(line:getCopied())
- end
- end
-
- line:setVisible(false)
-
- self.ui.Items.Layout_1:requestDoLayout()
- self.ui.Items.Layout_1:doLayout()
-
- local contentSize = self.ui.Items.Layout_1:getContentSize()
- logD("CreateRoomItemNew:init() 111 contentSize = ",table.tostring(contentSize))
- self.ui.Items.Layout:setContentSize(contentSize)
-
- -- 使用默认值更新界面
- for k,item in pairs(self.uiGroups) do
- item:updateByDefaultValue()
- end
- end
-
- function CreateRoomItemNew:getLayoutContentSize()
- if self.ui then
- return self.ui:getContentSize()
- else
- return nil
- end
- end
-
- -- 获得局数对应的房卡消耗
- function CreateRoomItemNew:getCreateRoomCost(jushu)
- local costs = app.serverConfigs:getSubGameCostInfo(self.gameId)
- for k,v in pairs(costs) do
- if tonumber(v.round) == tonumber(jushu) then
- if self.deductRule == 0 then -- 房主支付
- return v.cost
- elseif self.deductRule == 1 then -- AA支付
- return v.aaCost
- else
- return 666
- end
- end
- end
- return 888
- end
-
- function CreateRoomItemNew:onValueChanged(event)
- -- 只监听支付方式的变化
- if not event or not event.key or event.key ~= "deductRule" then
- return
- end
-
- self.deductRule = tonumber(event.value)
-
- app:dispatchEvent({name = CRConfig.CREATE_ROOM_DEDUCTRULE_CHANGE, key = event.key, value = event.value})
- end
-
- function CreateRoomItemNew:getRuleResult()
- local result = {}
- for k,v in pairs(self.uiGroups) do
- local values = v:getValue()
- for kk,vv in pairs(values) do
- result[kk] = vv;
- end
- end
- result.gameId = self.gameId
- result.gameRule = self.gameRule
- logD("CreateRoomItemNew:getRuleResult() result = ", table.tostring(result))
- local strResult = json.encode(result)
- return 0,strResult
- end
-
-
- return CreateRoomItemNew
|