LogoArcartX Doc
UI篇

自定义聊天栏

自定义聊天栏

我只知道一件事,就是我什么都不知道。

自定义聊天栏

  • ArcartX 的UI控件提供了聊天栏所需的所有功能,您可以通过UI控件来实现自定义聊天栏。
  • 此外,使用ArcartX替换原版聊天栏,还可支持额外的卡片消息、特殊颜色、表情符号等功能。

一个简单的聊天栏配置

  • 涉及聊天栏的控件有 ChatTextBox(聊天栏输入框) Chat(聊天栏) Suggestion(命令补全)

  • 下面是一个简单的聊天栏配置示例:

  • 第一部分是聊天栏的HUD部分

ui:
  isHud: true
  hide:
    - chat_panel # 隐藏原版聊天栏
controls:
  adaptive:
    type: adaptive
    attribute:
      point: ~bottom_left
      width: 1920
      height: 1080
    children:
      chat:
        type: chat
        attribute:
          width: 700
          height: 400
          point: ~bottom_left
          background: ~0,0,0,80
          fontSize: 28
          y: -280
          x: 35
  • 第二部分是替换原版聊天栏输入框界面
ui:
  match:
    - ChatScreen # 匹配原版聊天界面
  background: false
  # 这俩记得打开,不然交互不了HUD
  transfer: true # 传递交互
  through: true # 穿透
controls:
  adaptive:
    type: adaptive
    attribute:
      point: ~bottom_left
      width: 1920
      height: 1080
    children:
      background:
        type: texture
        attribute:
          point: ~bottom_left
          width: 700
          height: 24
          x: 35
          y: -250
          normal: ~0,0,0,80
      input:
        type: chatTextBox
        val: input
        attribute:
          point: ~bottom_left
          length: 64
          x: 75
          y: -250
          fontSize: 28
          width: 615
          height: 20
        action:
         create: |-
          self.setFocus(true)
        children:
          suggestion:
            type: Suggestion
            attribute:
              fontSize: 28
              background: ~0,0,0,80
  • 这个直接复制黏贴创建配置,即可看到效果:
自定义聊天栏
  • 这个聊天栏支持特殊颜色和表情符号:
自定义聊天栏

卡片消息

  • 这个功能来自于曾经让我非常苦恼的一件事,我希望有个消息盒子来弹出我的好友请求、邀请组队消息甚至是抢“红包”,于是便有了这个功能。
  • 它是将一个控件加入到聊天栏,注意,聊天栏最多存储10个卡片消息,超出10个会将最早创建的卡片消息显示为“卡片消息已失效”。
  • 效果:
自定义聊天栏
  • 这个卡片消息如上所述,它实际上就是一个控件,所以您可以创建一个背景、按钮、文本等控件来实现您的卡片消息。
  • 它的配置位于插件的 chat_card 文件夹,您可以创建多个卡片消息模板。
root_control:
  type: card # 注意这里必须是card类型
  attribute:
    width: 20 # 填写正确的尺寸以便聊天栏控件排列
    height: 50 # 如果你的聊天栏本身已经套了一层自适应布局控件,这里不需要再套一层
  children:
    texture:
      type: texture
      attribute:
        width: 500
        height: 50
        normal: ~255,0,0
        hover: ~255,255,0
        texts: "'我是一个卡片消息' + self.parent.data['name']"
        fontSize: 32
      action:
        click: |-
          Message.chat('点我干嘛')
  • 卡片消息需要使用API发送,每个卡片消息可以附带一个 Map<String,String> 数据,正如上面示例配置的这一行'我是一个卡片消息' + self.parent.data['name'],它会将数据中的name值渲染到文本中。

  • 发送卡片消息的API如下:

  • Kotlin

// 卡片消息配置路径:例如配置位于ArcartX/chat_card/example.yml 此处填写example 如果位于子文件夹使用斜杠分割
player.arcartXHandler?.sendChatCard("卡片消息配置路径", mapOf("name" to player.name))
  • Java
// 卡片消息配置路径:例如配置位于ArcartX/chat_card/example.yml 此处填写example 如果位于子文件夹使用斜杠分割
ArcartXPlayer arcartXPlayer = PlayerUtils.getArcartXHandler(player);
if(arcartXPlayer != null){
    arcartXPlayer.sendChatCard("卡片消息配置路径", Map.of("name",player.getName()));
}

On this page