local this = class("partShortKey", G_UIPartBase)
local _keyCodeTpl = L_GameTpl:getKeyCodeTpl()

function this.bind()
  return {txtDes = ""}
end

function this.methods()
end

function this:open()
  L_SettingStore:listenCallFunc(L_SettingStore.event.changeKey, self.onEvent_changeKey, self)
end

function this:close()
  L_SettingStore:unListenCallFunc(L_SettingStore.event.changeKey, self.onEvent_changeKey, self)
end

function this:onEvent_changeKey(settingId)
  if self.settingId ~= settingId then
    return
  end
  self:refreshKey(settingId)
end

function this:refreshTransform(parent, anchorType, offset, scale)
  local rTrans = self.bindComponents.rTrans
  rTrans:SetParent(parent)
  if anchorType then
    local cfg = L_Const.AnchorCfg[anchorType]
    rTrans.anchorMin = cfg.anchorMin
    rTrans.anchorMax = cfg.anchorMax
    rTrans.pivot = cfg.pivot
  end
  L_Vector3.setAnchored(rTrans, offset or L_Vector3.getTemp())
  L_Vector3.setSize(rTrans, scale or 1)
end

function this:refreshKey(id)
  self.settingId = id
  local val = L_SettingStore:getSetData(id)
  local tpl = _keyCodeTpl:getTplByKey(val)
  local name = tpl and _keyCodeTpl:getShortKey(tpl) or val or tostring(id)
  self.bind.txtDes = name
end

return this
