Skip to content

Commit

Permalink
feat: text display opacity 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
cccgh5 committed Aug 28, 2023
1 parent 7fed167 commit f6b7620
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,31 @@ class NmsTextDisplayService(
@Qualifier("base-component") private val baseComponentService: BaseComponentService
) : AbstractDisplayService<NmsTextDisplayWrapper>(nmsDisplayService, HQDisplayType.TextDisplay) {
private val setTextFunction = reflectionWrapper.getFunction(getTargetClass(), "c", listOf(baseComponentService.getTargetClass()))
private val setTextOpacityFunction = reflectionWrapper.getFunction(getTargetClass(), "g", listOf(Float::class))
private val setBackgroundColorFunction = reflectionWrapper.getFunction(getTargetClass(), "c", listOf(Int::class))
private val DATA_LINE_WIDTH_ID = reflectionWrapper.getStaticField(getTargetClass(), "aM").run {
private val dataLineWidthId = reflectionWrapper.getStaticField(getTargetClass(), "aM").run {
isAccessible = true
call()!!
}
private val dataTextOpacityId = reflectionWrapper.getStaticField(getTargetClass(), "aN").run {
isAccessible = true
call()!!
}


fun setText(displayWrapper: NmsTextDisplayWrapper, text: BaseComponent) {
val baseCompWrapper = baseComponentService.wrapFromJson(ComponentSerializer.toString(text))
setTextFunction.call(displayWrapper.getUnwrappedInstance(), baseCompWrapper.getUnwrappedInstance())
}

fun setTextOpacity(displayWrapper: NmsTextDisplayWrapper, opacity: Float) {
setTextOpacityFunction.call(displayWrapper.getUnwrappedInstance(), opacity)
}

fun setBackgroundColor(displayWrapper: NmsTextDisplayWrapper, color: Color) {
setBackgroundColorFunction.call(displayWrapper.getUnwrappedInstance(), color.asARGB())
}

fun setLineWith(displayWrapper: NmsTextDisplayWrapper, lineWidth: Int) {
nmsDisplayService.setEntityData(displayWrapper, DATA_LINE_WIDTH_ID, lineWidth)
nmsDisplayService.setEntityData(displayWrapper, dataLineWidthId, lineWidth)
}

fun setOpacity(displayWrapper: NmsTextDisplayWrapper, opacity: Byte) {
nmsDisplayService.setEntityData(displayWrapper, dataTextOpacityId, opacity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class VirtualTextDisplay(
switchMetaMask()
}

// 1.0 ~ 0
var opacity: Float = 1.0f
set(value) {
field = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class NmsTextDisplayWrapper(
}

fun setOpacity(opacity: Float) {
service.setTextOpacity(this, opacity)
val fixedValue = (opacity * 255).run {
if (this < 0) 0
else (this % 256).toInt()
}
service.setOpacity(this, fixedValue.toByte())
}

fun setBackgroundColor(color: Color) {
Expand Down

0 comments on commit f6b7620

Please sign in to comment.