You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.0 KiB

  1. local CRConfig = require("luaScript.Views.CreateRoom.Com.CRConfig")
  2. -- 主界面
  3. local CreateRoomItemNew = class("CreateRoomItemNew", cc.UIView)
  4. function CreateRoomItemNew:ctor(datas, defaultValues, gameId, gameRule)
  5. CreateRoomItemNew.super.ctor(self);
  6. local filename = string.format("CreateRoomRule_%03d", gameId)
  7. self.gameId = gameId
  8. self.gameRule = gameRule
  9. self.datas = datas
  10. self.defaultValues = defaultValues
  11. if self.defaultValues and table.nums(self.defaultValues) <= 0 then
  12. self.defaultValues = nil
  13. end
  14. self.ui = loadUI("res/ui/ui_chuangjian/ui_chuangjian_0.ui");
  15. self:addChild(self.ui)
  16. end
  17. function CreateRoomItemNew:getNode()
  18. return self.ui
  19. end
  20. function CreateRoomItemNew:removeFromParent()
  21. if self.ui then
  22. self.ui:removeFromParent()
  23. end
  24. end
  25. function CreateRoomItemNew:onEnter()
  26. CreateRoomItemNew.super.onEnter(self)
  27. -- 监听支付方式的变化
  28. self.ui:bindEvent(app, CRConfig.CREATE_ROOM_VALUE_CHANGE, handler(self, self.onValueChanged))
  29. local line = self.ui.Items.ImageView_0
  30. self.uiGroups = {}
  31. for i,v in pairsByKeys(self.datas) do
  32. local itemGroup = CRConfig.createGroupNode(v, self.defaultValues)
  33. if itemGroup and itemGroup.ui then
  34. self.uiGroups[v.key] = itemGroup
  35. self.ui.Items.Layout_1:addChild(itemGroup.ui)
  36. self.ui.Items.Layout_1:addChild(line:getCopied())
  37. end
  38. end
  39. line:setVisible(false)
  40. self.ui.Items.Layout_1:requestDoLayout()
  41. self.ui.Items.Layout_1:doLayout()
  42. local contentSize = self.ui.Items.Layout_1:getContentSize()
  43. logD("CreateRoomItemNew:init() 111 contentSize = ",table.tostring(contentSize))
  44. self.ui.Items.Layout:setContentSize(contentSize)
  45. -- 使用默认值更新界面
  46. for k,item in pairs(self.uiGroups) do
  47. item:updateByDefaultValue()
  48. end
  49. end
  50. function CreateRoomItemNew:getLayoutContentSize()
  51. if self.ui then
  52. return self.ui:getContentSize()
  53. else
  54. return nil
  55. end
  56. end
  57. -- 获得局数对应的房卡消耗
  58. function CreateRoomItemNew:getCreateRoomCost(jushu)
  59. local costs = app.serverConfigs:getSubGameCostInfo(self.gameId)
  60. for k,v in pairs(costs) do
  61. if tonumber(v.round) == tonumber(jushu) then
  62. if self.deductRule == 0 then -- 房主支付
  63. return v.cost
  64. elseif self.deductRule == 1 then -- AA支付
  65. return v.aaCost
  66. else
  67. return 666
  68. end
  69. end
  70. end
  71. return 888
  72. end
  73. function CreateRoomItemNew:onValueChanged(event)
  74. -- 只监听支付方式的变化
  75. if not event or not event.key or event.key ~= "deductRule" then
  76. return
  77. end
  78. self.deductRule = tonumber(event.value)
  79. app:dispatchEvent({name = CRConfig.CREATE_ROOM_DEDUCTRULE_CHANGE, key = event.key, value = event.value})
  80. end
  81. function CreateRoomItemNew:getRuleResult()
  82. local result = {}
  83. for k,v in pairs(self.uiGroups) do
  84. local values = v:getValue()
  85. for kk,vv in pairs(values) do
  86. result[kk] = vv;
  87. end
  88. end
  89. result.gameId = self.gameId
  90. result.gameRule = self.gameRule
  91. logD("CreateRoomItemNew:getRuleResult() result = ", table.tostring(result))
  92. local strResult = json.encode(result)
  93. return 0,strResult
  94. end
  95. return CreateRoomItemNew