forked from geode-sdk/android-launcher
cleanup naming conventions
This commit is contained in:
9 files changed
+254
-253
No files matched your search
@@ -218,21 +218,21 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun runOnGLThread(pRunnable: Runnable) {
|
override fun runOnGLThread(runnable: Runnable) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showDialog(pTitle: String, pMessage: String) {
|
override fun showDialog(title: String, message: String) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEditTextDialog(
|
override fun showEditTextDialog(
|
||||||
pTitle: String,
|
title: String,
|
||||||
pMessage: String,
|
message: String,
|
||||||
pInputMode: Int,
|
inputMode: Int,
|
||||||
pInputFlag: Int,
|
inputFlag: Int,
|
||||||
pReturnType: Int,
|
returnType: Int,
|
||||||
pMaxLength: Int
|
maxLength: Int
|
||||||
) {
|
) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package dev.xyze.geodelauncher.utils
|
package dev.xyze.geodelauncher.utils
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
|
||||||
object GJConstants {
|
object GJConstants {
|
||||||
const val PACKAGE_NAME = "com.robtopx.geometryjump"
|
const val PACKAGE_NAME = "com.robtopx.geometryjump"
|
||||||
|
|
||||||
@@ -9,5 +11,6 @@ object GJConstants {
|
|||||||
const val LAUNCHER_FIX_LIB_NAME = "launcherfix"
|
const val LAUNCHER_FIX_LIB_NAME = "launcherfix"
|
||||||
|
|
||||||
// this value is hardcoded into GD
|
// this value is hardcoded into GD
|
||||||
|
@SuppressLint("SdCardPath")
|
||||||
const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}"
|
const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}"
|
||||||
}
|
}
|
||||||
@@ -16,33 +16,34 @@ import kotlin.math.ceil
|
|||||||
|
|
||||||
@Suppress("KotlinJniMissingFunction")
|
@Suppress("KotlinJniMissingFunction")
|
||||||
object Cocos2dxBitmap {
|
object Cocos2dxBitmap {
|
||||||
private lateinit var sContext: WeakReference<Context>
|
private lateinit var context: WeakReference<Context>
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeInitBitmapDC(pWidth: Int, pHeight: Int, pPixels: ByteArray)
|
private external fun nativeInitBitmapDC(pWidth: Int, pHeight: Int, pPixels: ByteArray)
|
||||||
|
|
||||||
fun setContext(pContext: Context) {
|
fun setContext(context: Context) {
|
||||||
sContext = WeakReference(pContext)
|
this.context = WeakReference(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
fun createTextBitmap(
|
fun createTextBitmap(
|
||||||
pString: String,
|
string: String,
|
||||||
pFontName: String,
|
fontName: String,
|
||||||
pFontSize: Int,
|
fontSize: Int,
|
||||||
pAlignment: Int,
|
alignment: Int,
|
||||||
pWidth: Int,
|
width: Int,
|
||||||
pHeight: Int
|
height: Int
|
||||||
) {
|
) {
|
||||||
createTextBitmapShadowStroke(
|
createTextBitmapShadowStroke(
|
||||||
pString,
|
string,
|
||||||
pFontName,
|
fontName,
|
||||||
pFontSize,
|
fontSize,
|
||||||
1.0f,
|
1.0f,
|
||||||
1.0f,
|
1.0f,
|
||||||
1.0f,
|
1.0f,
|
||||||
pAlignment,
|
alignment,
|
||||||
pWidth,
|
width,
|
||||||
pHeight,
|
height,
|
||||||
false,
|
false,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
@@ -54,19 +55,20 @@ object Cocos2dxBitmap {
|
|||||||
1.0f
|
1.0f
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
fun createTextBitmapShadowStroke(
|
fun createTextBitmapShadowStroke(
|
||||||
pString: String,
|
string: String,
|
||||||
pFontName: String,
|
fontName: String,
|
||||||
pFontSize: Int,
|
fontSize: Int,
|
||||||
fontTintR: Float,
|
fontTintR: Float,
|
||||||
fontTintG: Float,
|
fontTintG: Float,
|
||||||
fontTintB: Float,
|
fontTintB: Float,
|
||||||
pAlignment: Int,
|
alignment: Int,
|
||||||
pWidth: Int,
|
width: Int,
|
||||||
pHeight: Int,
|
height: Int,
|
||||||
shadow: Boolean,
|
shadow: Boolean,
|
||||||
shadowDX: Float,
|
shadowDX: Float,
|
||||||
shadowDY: Float,
|
shadowDY: Float,
|
||||||
@@ -78,21 +80,21 @@ object Cocos2dxBitmap {
|
|||||||
strokeSize: Float
|
strokeSize: Float
|
||||||
) {
|
) {
|
||||||
val bitmapTotalHeight: Int
|
val bitmapTotalHeight: Int
|
||||||
val horizontalAlignment = pAlignment and 15
|
val horizontalAlignment = alignment and 15
|
||||||
val verticalAlignment = pAlignment shr 4 and 15
|
val verticalAlignment = alignment shr 4 and 15
|
||||||
val pString2 = refactorString(pString)
|
val pString2 = refactorString(string)
|
||||||
val paint = newPaint(pFontName, pFontSize, horizontalAlignment)
|
val paint = newPaint(fontName, fontSize, horizontalAlignment)
|
||||||
paint.setARGB(
|
paint.setARGB(
|
||||||
MotionEvent.ACTION_MASK,
|
MotionEvent.ACTION_MASK,
|
||||||
(255.0 * fontTintR.toDouble()).toInt(),
|
(255.0 * fontTintR.toDouble()).toInt(),
|
||||||
(255.0 * fontTintG.toDouble()).toInt(),
|
(255.0 * fontTintG.toDouble()).toInt(),
|
||||||
(255.0 * fontTintB.toDouble()).toInt()
|
(255.0 * fontTintB.toDouble()).toInt()
|
||||||
)
|
)
|
||||||
val textProperty = computeTextProperty(pString2, pWidth, pHeight, paint)
|
val textProperty = computeTextProperty(pString2, width, height, paint)
|
||||||
bitmapTotalHeight = if (pHeight == 0) {
|
bitmapTotalHeight = if (height == 0) {
|
||||||
textProperty.mTotalHeight
|
textProperty.totalHeight
|
||||||
} else {
|
} else {
|
||||||
pHeight
|
height
|
||||||
}
|
}
|
||||||
var bitmapPaddingX = 0.0f
|
var bitmapPaddingX = 0.0f
|
||||||
var bitmapPaddingY = 0.0f
|
var bitmapPaddingY = 0.0f
|
||||||
@@ -110,14 +112,14 @@ object Cocos2dxBitmap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val bitmap = Bitmap.createBitmap(
|
val bitmap = Bitmap.createBitmap(
|
||||||
textProperty.mMaxWidth + bitmapPaddingX.toInt(),
|
textProperty.maxWidth + bitmapPaddingX.toInt(),
|
||||||
bitmapPaddingY.toInt() + bitmapTotalHeight,
|
bitmapPaddingY.toInt() + bitmapTotalHeight,
|
||||||
Bitmap.Config.ARGB_8888
|
Bitmap.Config.ARGB_8888
|
||||||
)
|
)
|
||||||
val canvas = Canvas(bitmap)
|
val canvas = Canvas(bitmap)
|
||||||
val fontMetricsInt = paint.fontMetricsInt
|
val fontMetricsInt = paint.fontMetricsInt
|
||||||
var y = computeY(fontMetricsInt, pHeight, textProperty.mTotalHeight, verticalAlignment)
|
var y = computeY(fontMetricsInt, height, textProperty.totalHeight, verticalAlignment)
|
||||||
val lines = textProperty.mLines
|
val lines = textProperty.lines
|
||||||
val length = lines.size
|
val length = lines.size
|
||||||
for (i in 0 until length) {
|
for (i in 0 until length) {
|
||||||
val line = lines[i]
|
val line = lines[i]
|
||||||
@@ -125,16 +127,16 @@ object Cocos2dxBitmap {
|
|||||||
line!!,
|
line!!,
|
||||||
computeX(
|
computeX(
|
||||||
line,
|
line,
|
||||||
textProperty.mMaxWidth,
|
textProperty.maxWidth,
|
||||||
horizontalAlignment
|
horizontalAlignment
|
||||||
).toFloat() + renderTextDeltaX,
|
).toFloat() + renderTextDeltaX,
|
||||||
y.toFloat() + renderTextDeltaY,
|
y.toFloat() + renderTextDeltaY,
|
||||||
paint
|
paint
|
||||||
)
|
)
|
||||||
y += textProperty.mHeightPerLine
|
y += textProperty.heightPerLine
|
||||||
}
|
}
|
||||||
if (stroke) {
|
if (stroke) {
|
||||||
val paintStroke = newPaint(pFontName, pFontSize, horizontalAlignment)
|
val paintStroke = newPaint(fontName, fontSize, horizontalAlignment)
|
||||||
paintStroke.style = Paint.Style.STROKE
|
paintStroke.style = Paint.Style.STROKE
|
||||||
paintStroke.strokeWidth = 0.5f * strokeSize
|
paintStroke.strokeWidth = 0.5f * strokeSize
|
||||||
paintStroke.setARGB(
|
paintStroke.setARGB(
|
||||||
@@ -143,8 +145,8 @@ object Cocos2dxBitmap {
|
|||||||
strokeG.toInt() * MotionEvent.ACTION_MASK,
|
strokeG.toInt() * MotionEvent.ACTION_MASK,
|
||||||
strokeB.toInt() * MotionEvent.ACTION_MASK
|
strokeB.toInt() * MotionEvent.ACTION_MASK
|
||||||
)
|
)
|
||||||
var y2 = computeY(fontMetricsInt, pHeight, textProperty.mTotalHeight, verticalAlignment)
|
var y2 = computeY(fontMetricsInt, height, textProperty.totalHeight, verticalAlignment)
|
||||||
val lines2 = textProperty.mLines
|
val lines2 = textProperty.lines
|
||||||
val length2 = lines2.size
|
val length2 = lines2.size
|
||||||
for (i2 in 0 until length2) {
|
for (i2 in 0 until length2) {
|
||||||
val line2 = lines2[i2]
|
val line2 = lines2[i2]
|
||||||
@@ -152,36 +154,36 @@ object Cocos2dxBitmap {
|
|||||||
line2!!,
|
line2!!,
|
||||||
computeX(
|
computeX(
|
||||||
line2,
|
line2,
|
||||||
textProperty.mMaxWidth,
|
textProperty.maxWidth,
|
||||||
horizontalAlignment
|
horizontalAlignment
|
||||||
).toFloat() + renderTextDeltaX,
|
).toFloat() + renderTextDeltaX,
|
||||||
y2.toFloat() + renderTextDeltaY,
|
y2.toFloat() + renderTextDeltaY,
|
||||||
paintStroke
|
paintStroke
|
||||||
)
|
)
|
||||||
y2 += textProperty.mHeightPerLine
|
y2 += textProperty.heightPerLine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initNativeObject(bitmap)
|
initNativeObject(bitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newPaint(pFontName: String, pFontSize: Int, pHorizontalAlignment: Int): Paint {
|
private fun newPaint(fontName: String, fontSize: Int, horizontalAlignment: Int): Paint {
|
||||||
val paint = Paint()
|
val paint = Paint()
|
||||||
paint.color = -1
|
paint.color = -1
|
||||||
paint.textSize = pFontSize.toFloat()
|
paint.textSize = fontSize.toFloat()
|
||||||
paint.isAntiAlias = true
|
paint.isAntiAlias = true
|
||||||
if (pFontName.endsWith(".ttf")) {
|
if (fontName.endsWith(".ttf")) {
|
||||||
try {
|
try {
|
||||||
sContext.get()?.apply {
|
context.get()?.apply {
|
||||||
paint.typeface = Cocos2dxTypefaces[this, pFontName]
|
paint.typeface = Cocos2dxTypefaces[this, fontName]
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Cocos2dxBitmap", "error to create ttf type face: $pFontName")
|
Log.e("Cocos2dxBitmap", "error to create ttf type face: $fontName")
|
||||||
paint.typeface = Typeface.create(pFontName, Typeface.NORMAL)
|
paint.typeface = Typeface.create(fontName, Typeface.NORMAL)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
paint.typeface = Typeface.create(pFontName, Typeface.NORMAL)
|
paint.typeface = Typeface.create(fontName, Typeface.NORMAL)
|
||||||
}
|
}
|
||||||
when (pHorizontalAlignment) {
|
when (horizontalAlignment) {
|
||||||
2 -> paint.textAlign = Paint.Align.RIGHT
|
2 -> paint.textAlign = Paint.Align.RIGHT
|
||||||
3 -> paint.textAlign = Paint.Align.CENTER
|
3 -> paint.textAlign = Paint.Align.CENTER
|
||||||
else -> paint.textAlign = Paint.Align.LEFT
|
else -> paint.textAlign = Paint.Align.LEFT
|
||||||
@@ -190,20 +192,20 @@ object Cocos2dxBitmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun computeTextProperty(
|
private fun computeTextProperty(
|
||||||
pString: String,
|
string: String,
|
||||||
pWidth: Int,
|
width: Int,
|
||||||
pHeight: Int,
|
height: Int,
|
||||||
pPaint: Paint
|
paint: Paint
|
||||||
): TextProperty {
|
): TextProperty {
|
||||||
val fm = pPaint.fontMetricsInt
|
val fm = paint.fontMetricsInt
|
||||||
val h = ceil((fm.bottom - fm.top).toDouble()).toInt()
|
val h = ceil((fm.bottom - fm.top).toDouble()).toInt()
|
||||||
var maxContentWidth = 0
|
var maxContentWidth = 0
|
||||||
val lines = splitString(pString, pWidth, pHeight, pPaint)
|
val lines = splitString(string, width, height, paint)
|
||||||
if (pWidth != 0) {
|
if (width != 0) {
|
||||||
maxContentWidth = pWidth
|
maxContentWidth = width
|
||||||
} else {
|
} else {
|
||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
val temp = ceil(pPaint.measureText(line, 0, line!!.length).toDouble()).toInt()
|
val temp = ceil(paint.measureText(line, 0, line!!.length).toDouble()).toInt()
|
||||||
if (temp > maxContentWidth) {
|
if (temp > maxContentWidth) {
|
||||||
maxContentWidth = temp
|
maxContentWidth = temp
|
||||||
}
|
}
|
||||||
@@ -212,45 +214,45 @@ object Cocos2dxBitmap {
|
|||||||
return TextProperty(maxContentWidth, h, lines)
|
return TextProperty(maxContentWidth, h, lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeX(@Suppress("UNUSED_PARAMETER") pText: String?, pMaxWidth: Int, pHorizontalAlignment: Int): Int {
|
private fun computeX(@Suppress("UNUSED_PARAMETER") text: String?, maxWidth: Int, horizontalAlignment: Int): Int {
|
||||||
return when (pHorizontalAlignment) {
|
return when (horizontalAlignment) {
|
||||||
2 -> pMaxWidth
|
2 -> maxWidth
|
||||||
3 -> pMaxWidth / 2
|
3 -> maxWidth / 2
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeY(
|
private fun computeY(
|
||||||
pFontMetricsInt: FontMetricsInt,
|
fontMetricsInt: FontMetricsInt,
|
||||||
pConstrainHeight: Int,
|
constrainHeight: Int,
|
||||||
pTotalHeight: Int,
|
totalHeight: Int,
|
||||||
pVerticalAlignment: Int
|
verticalAlignment: Int
|
||||||
): Int {
|
): Int {
|
||||||
val y = -pFontMetricsInt.top
|
val y = -fontMetricsInt.top
|
||||||
return if (pConstrainHeight <= pTotalHeight) {
|
return if (constrainHeight <= totalHeight) {
|
||||||
y
|
y
|
||||||
} else when (pVerticalAlignment) {
|
} else when (verticalAlignment) {
|
||||||
1 -> -pFontMetricsInt.top
|
1 -> -fontMetricsInt.top
|
||||||
2 -> -pFontMetricsInt.top + (pConstrainHeight - pTotalHeight)
|
2 -> -fontMetricsInt.top + (constrainHeight - totalHeight)
|
||||||
3 -> -pFontMetricsInt.top + (pConstrainHeight - pTotalHeight) / 2
|
3 -> -fontMetricsInt.top + (constrainHeight - totalHeight) / 2
|
||||||
else -> y
|
else -> y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun splitString(
|
private fun splitString(
|
||||||
pString: String,
|
string: String,
|
||||||
pMaxWidth: Int,
|
maxWidth: Int,
|
||||||
pMaxHeight: Int,
|
maxHeight: Int,
|
||||||
pPaint: Paint
|
paint: Paint
|
||||||
): Array<String?> {
|
): Array<String?> {
|
||||||
val lines: Array<String?> = pString.split("\\n").toTypedArray()
|
val lines: Array<String?> = string.split("\\n").toTypedArray()
|
||||||
val fm = pPaint.fontMetricsInt
|
val fm = paint.fontMetricsInt
|
||||||
val maxLines = pMaxHeight / ceil((fm.bottom - fm.top).toDouble()).toInt()
|
val maxLines = maxHeight / ceil((fm.bottom - fm.top).toDouble()).toInt()
|
||||||
return if (pMaxWidth != 0) {
|
return if (maxWidth != 0) {
|
||||||
val strList = LinkedList<String?>()
|
val strList = LinkedList<String?>()
|
||||||
for (line in lines) {
|
for (line in lines) {
|
||||||
if (ceil(pPaint.measureText(line).toDouble()).toInt() > pMaxWidth) {
|
if (ceil(paint.measureText(line).toDouble()).toInt() > maxWidth) {
|
||||||
strList.addAll(divideStringWithMaxWidth(line, pMaxWidth, pPaint))
|
strList.addAll(divideStringWithMaxWidth(line, maxWidth, paint))
|
||||||
} else {
|
} else {
|
||||||
strList.add(line)
|
strList.add(line)
|
||||||
}
|
}
|
||||||
@@ -266,7 +268,7 @@ object Cocos2dxBitmap {
|
|||||||
val ret = arrayOfNulls<String>(strList.size)
|
val ret = arrayOfNulls<String>(strList.size)
|
||||||
strList.toArray(ret)
|
strList.toArray(ret)
|
||||||
ret
|
ret
|
||||||
} else if (pMaxHeight == 0 || lines.size <= maxLines) {
|
} else if (maxHeight == 0 || lines.size <= maxLines) {
|
||||||
lines
|
lines
|
||||||
} else {
|
} else {
|
||||||
val strList2 = LinkedList<String?>()
|
val strList2 = LinkedList<String?>()
|
||||||
@@ -280,28 +282,28 @@ object Cocos2dxBitmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun divideStringWithMaxWidth(
|
private fun divideStringWithMaxWidth(
|
||||||
pString: String?,
|
string: String?,
|
||||||
pMaxWidth: Int,
|
maxWidth: Int,
|
||||||
pPaint: Paint
|
paint: Paint
|
||||||
): LinkedList<String?> {
|
): LinkedList<String?> {
|
||||||
val charLength = pString!!.length
|
val charLength = string!!.length
|
||||||
var start = 0
|
var start = 0
|
||||||
val strList = LinkedList<String?>()
|
val strList = LinkedList<String?>()
|
||||||
var i = 1
|
var i = 1
|
||||||
while (i <= charLength) {
|
while (i <= charLength) {
|
||||||
val tempWidth = ceil(pPaint.measureText(pString, start, i).toDouble()).toInt()
|
val tempWidth = ceil(paint.measureText(string, start, i).toDouble()).toInt()
|
||||||
if (tempWidth >= pMaxWidth) {
|
if (tempWidth >= maxWidth) {
|
||||||
val lastIndexOfSpace = pString.substring(0, i).lastIndexOf(" ")
|
val lastIndexOfSpace = string.substring(0, i).lastIndexOf(" ")
|
||||||
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start) {
|
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start) {
|
||||||
strList.add(pString.substring(start, lastIndexOfSpace))
|
strList.add(string.substring(start, lastIndexOfSpace))
|
||||||
i = lastIndexOfSpace + 1
|
i = lastIndexOfSpace + 1
|
||||||
} else if (tempWidth > pMaxWidth) {
|
} else if (tempWidth > maxWidth) {
|
||||||
strList.add(pString.substring(start, i - 1))
|
strList.add(string.substring(start, i - 1))
|
||||||
i--
|
i--
|
||||||
} else {
|
} else {
|
||||||
strList.add(pString.substring(start, i))
|
strList.add(string.substring(start, i))
|
||||||
}
|
}
|
||||||
while (i < charLength && pString[i] == ' ') {
|
while (i < charLength && string[i] == ' ') {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
start = i
|
start = i
|
||||||
@@ -309,7 +311,7 @@ object Cocos2dxBitmap {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
if (start < charLength) {
|
if (start < charLength) {
|
||||||
strList.add(pString.substring(start))
|
strList.add(string.substring(start))
|
||||||
}
|
}
|
||||||
return strList
|
return strList
|
||||||
}
|
}
|
||||||
@@ -376,29 +378,27 @@ object Cocos2dxBitmap {
|
|||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private fun getStringWithEllipsis(pString: String, width: Float, fontSize: Float): String {
|
private fun getStringWithEllipsis(string: String, width: Float, fontSize: Float): String {
|
||||||
if (TextUtils.isEmpty(pString)) {
|
if (TextUtils.isEmpty(string)) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
val paint = TextPaint()
|
val paint = TextPaint()
|
||||||
paint.typeface = Typeface.DEFAULT
|
paint.typeface = Typeface.DEFAULT
|
||||||
paint.textSize = fontSize
|
paint.textSize = fontSize
|
||||||
return TextUtils.ellipsize(pString, paint, width, TextUtils.TruncateAt.END).toString()
|
return TextUtils.ellipsize(string, paint, width, TextUtils.TruncateAt.END).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TextProperty constructor(/* access modifiers changed from: private */
|
private class TextProperty constructor(
|
||||||
val mMaxWidth: Int, /* access modifiers changed from: private */
|
val maxWidth: Int,
|
||||||
val mHeightPerLine: Int, pLines: Array<String?>
|
val heightPerLine: Int, pLines: Array<String?>
|
||||||
) {
|
) {
|
||||||
/* access modifiers changed from: private */
|
val lines: Array<String?>
|
||||||
val mLines: Array<String?>
|
|
||||||
|
|
||||||
/* access modifiers changed from: private */
|
val totalHeight: Int
|
||||||
val mTotalHeight: Int
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mTotalHeight = pLines.size * mHeightPerLine
|
totalHeight = pLines.size * heightPerLine
|
||||||
mLines = pLines
|
lines = pLines
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,9 @@ import androidx.appcompat.widget.AppCompatEditText
|
|||||||
class Cocos2dxEditText(context: Context) : AppCompatEditText(context) {
|
class Cocos2dxEditText(context: Context) : AppCompatEditText(context) {
|
||||||
var cocos2dxGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
var cocos2dxGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
||||||
|
|
||||||
override fun onKeyDown(pKeyCode: Int, pKeyEvent: KeyEvent): Boolean {
|
override fun onKeyDown(keyCode: Int, keyEvent: KeyEvent): Boolean {
|
||||||
super.onKeyDown(pKeyCode, pKeyEvent)
|
super.onKeyDown(keyCode, keyEvent)
|
||||||
if (pKeyCode != KeyEvent.KEYCODE_BACK) {
|
if (keyCode != KeyEvent.KEYCODE_BACK) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
cocos2dxGLSurfaceView?.requestFocus()
|
cocos2dxGLSurfaceView?.requestFocus()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.cocos2dx.lib
|
package org.cocos2dx.lib
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.opengl.GLSurfaceView
|
import android.opengl.GLSurfaceView
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@@ -17,33 +16,33 @@ private const val HANDLER_CLOSE_IME_KEYBOARD = 3
|
|||||||
|
|
||||||
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var mCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView
|
lateinit var cocos2dxGLSurfaceView: Cocos2dxGLSurfaceView
|
||||||
private lateinit var sHandler: Handler
|
private lateinit var handler: Handler
|
||||||
private lateinit var sCocos2dxTextInputWrapper: Cocos2dxTextInputWrapper
|
private lateinit var cocos2dxTextInputWrapper: Cocos2dxTextInputWrapper
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun openIMEKeyboard() {
|
fun openIMEKeyboard() {
|
||||||
val msg = Message()
|
val msg = Message()
|
||||||
msg.what = HANDLER_OPEN_IME_KEYBOARD
|
msg.what = HANDLER_OPEN_IME_KEYBOARD
|
||||||
msg.obj = mCocos2dxGLSurfaceView.getContentText()
|
msg.obj = cocos2dxGLSurfaceView.getContentText()
|
||||||
sHandler.sendMessage(msg)
|
handler.sendMessage(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun closeIMEKeyboard() {
|
fun closeIMEKeyboard() {
|
||||||
val msg = Message()
|
val msg = Message()
|
||||||
msg.what = HANDLER_CLOSE_IME_KEYBOARD
|
msg.what = HANDLER_CLOSE_IME_KEYBOARD
|
||||||
sHandler.sendMessage(msg)
|
handler.sendMessage(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var mCocos2dxRenderer: Cocos2dxRenderer
|
private lateinit var cocos2dxRenderer: Cocos2dxRenderer
|
||||||
|
|
||||||
var cocos2dxEditText: Cocos2dxEditText? = null
|
var cocos2dxEditText: Cocos2dxEditText? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
|
||||||
field?.setOnEditorActionListener(sCocos2dxTextInputWrapper)
|
field?.setOnEditorActionListener(cocos2dxTextInputWrapper)
|
||||||
field?.cocos2dxGLSurfaceView = this
|
field?.cocos2dxGLSurfaceView = this
|
||||||
requestFocus()
|
requestFocus()
|
||||||
}
|
}
|
||||||
@@ -54,24 +53,23 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
// if (Build.VERSION.SDK_INT >= 11) {
|
// if (Build.VERSION.SDK_INT >= 11) {
|
||||||
preserveEGLContextOnPause = true
|
preserveEGLContextOnPause = true
|
||||||
// }
|
// }
|
||||||
mCocos2dxGLSurfaceView = this
|
cocos2dxGLSurfaceView = this
|
||||||
sCocos2dxTextInputWrapper = Cocos2dxTextInputWrapper(this)
|
cocos2dxTextInputWrapper = Cocos2dxTextInputWrapper(this)
|
||||||
sHandler = @SuppressLint("HandlerLeak")
|
Cocos2dxGLSurfaceView.handler = object : Handler(Looper.getMainLooper()) {
|
||||||
object : Handler(Looper.getMainLooper()) {
|
|
||||||
override fun handleMessage(msg: Message) {
|
override fun handleMessage(msg: Message) {
|
||||||
when (msg.what) {
|
when (msg.what) {
|
||||||
HANDLER_OPEN_IME_KEYBOARD -> {
|
HANDLER_OPEN_IME_KEYBOARD -> {
|
||||||
if (cocos2dxEditText?.requestFocus() == true) {
|
if (cocos2dxEditText?.requestFocus() == true) {
|
||||||
cocos2dxEditText?.apply {
|
cocos2dxEditText?.apply {
|
||||||
removeTextChangedListener(
|
removeTextChangedListener(
|
||||||
sCocos2dxTextInputWrapper
|
cocos2dxTextInputWrapper
|
||||||
)
|
)
|
||||||
setText("")
|
setText("")
|
||||||
val text = msg.obj as String
|
val text = msg.obj as String
|
||||||
append(text)
|
append(text)
|
||||||
sCocos2dxTextInputWrapper.setOriginText(text)
|
cocos2dxTextInputWrapper.setOriginText(text)
|
||||||
addTextChangedListener(
|
addTextChangedListener(
|
||||||
sCocos2dxTextInputWrapper
|
cocos2dxTextInputWrapper
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(
|
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(
|
||||||
@@ -86,7 +84,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
HANDLER_CLOSE_IME_KEYBOARD -> {
|
HANDLER_CLOSE_IME_KEYBOARD -> {
|
||||||
cocos2dxEditText?.apply {
|
cocos2dxEditText?.apply {
|
||||||
removeTextChangedListener(
|
removeTextChangedListener(
|
||||||
sCocos2dxTextInputWrapper
|
cocos2dxTextInputWrapper
|
||||||
)
|
)
|
||||||
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(
|
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(
|
||||||
windowToken,
|
windowToken,
|
||||||
@@ -96,7 +94,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
|
|
||||||
requestFocus()
|
requestFocus()
|
||||||
Log.d("GLSurfaceView", "HideSoftInput")
|
Log.d("GLSurfaceView", "HideSoftInput")
|
||||||
mCocos2dxRenderer.handleTextClosed()
|
cocos2dxRenderer.handleTextClosed()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
else -> return
|
else -> return
|
||||||
@@ -106,32 +104,32 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
queueEvent { mCocos2dxRenderer.handleOnPause() }
|
queueEvent { cocos2dxRenderer.handleOnPause() }
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
queueEvent { mCocos2dxRenderer.handleOnResume() }
|
queueEvent { cocos2dxRenderer.handleOnResume() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTouchEvent(pMotionEvent: MotionEvent): Boolean {
|
override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
|
||||||
val pointerNumber = pMotionEvent.pointerCount
|
val pointerNumber = motionEvent.pointerCount
|
||||||
val ids = IntArray(pointerNumber)
|
val ids = IntArray(pointerNumber)
|
||||||
val xs = FloatArray(pointerNumber)
|
val xs = FloatArray(pointerNumber)
|
||||||
val ys = FloatArray(pointerNumber)
|
val ys = FloatArray(pointerNumber)
|
||||||
for (i in 0 until pointerNumber) {
|
for (i in 0 until pointerNumber) {
|
||||||
ids[i] = pMotionEvent.getPointerId(i)
|
ids[i] = motionEvent.getPointerId(i)
|
||||||
xs[i] = pMotionEvent.getX(i)
|
xs[i] = motionEvent.getX(i)
|
||||||
ys[i] = pMotionEvent.getY(i)
|
ys[i] = motionEvent.getY(i)
|
||||||
}
|
}
|
||||||
return when (pMotionEvent.action and MotionEvent.ACTION_MASK) {
|
return when (motionEvent.action and MotionEvent.ACTION_MASK) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
MotionEvent.ACTION_DOWN -> {
|
||||||
val idDown = pMotionEvent.getPointerId(0)
|
val idDown = motionEvent.getPointerId(0)
|
||||||
val xDown = xs[0]
|
val xDown = xs[0]
|
||||||
val f = ys[0]
|
val f = ys[0]
|
||||||
queueEvent {
|
queueEvent {
|
||||||
mCocos2dxRenderer.handleActionDown(
|
cocos2dxRenderer.handleActionDown(
|
||||||
idDown,
|
idDown,
|
||||||
xDown,
|
xDown,
|
||||||
f
|
f
|
||||||
@@ -140,15 +138,15 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_UP -> {
|
MotionEvent.ACTION_UP -> {
|
||||||
val idUp = pMotionEvent.getPointerId(0)
|
val idUp = motionEvent.getPointerId(0)
|
||||||
val f2 = xs[0]
|
val f2 = xs[0]
|
||||||
val f3 = ys[0]
|
val f3 = ys[0]
|
||||||
queueEvent { mCocos2dxRenderer.handleActionUp(idUp, f2, f3) }
|
queueEvent { cocos2dxRenderer.handleActionUp(idUp, f2, f3) }
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
queueEvent {
|
queueEvent {
|
||||||
mCocos2dxRenderer.handleActionMove(
|
cocos2dxRenderer.handleActionMove(
|
||||||
ids,
|
ids,
|
||||||
xs,
|
xs,
|
||||||
ys
|
ys
|
||||||
@@ -158,7 +156,7 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
MotionEvent.ACTION_CANCEL -> {
|
MotionEvent.ACTION_CANCEL -> {
|
||||||
queueEvent {
|
queueEvent {
|
||||||
mCocos2dxRenderer.handleActionCancel(
|
cocos2dxRenderer.handleActionCancel(
|
||||||
ids,
|
ids,
|
||||||
xs,
|
xs,
|
||||||
ys
|
ys
|
||||||
@@ -167,12 +165,12 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_POINTER_DOWN -> {
|
MotionEvent.ACTION_POINTER_DOWN -> {
|
||||||
val indexPointerDown = pMotionEvent.action shr 8
|
val indexPointerDown = motionEvent.action shr 8
|
||||||
val idPointerDown = pMotionEvent.getPointerId(indexPointerDown)
|
val idPointerDown = motionEvent.getPointerId(indexPointerDown)
|
||||||
val xPointerDown = pMotionEvent.getX(indexPointerDown)
|
val xPointerDown = motionEvent.getX(indexPointerDown)
|
||||||
val y = pMotionEvent.getY(indexPointerDown)
|
val y = motionEvent.getY(indexPointerDown)
|
||||||
queueEvent {
|
queueEvent {
|
||||||
mCocos2dxRenderer.handleActionDown(
|
cocos2dxRenderer.handleActionDown(
|
||||||
idPointerDown,
|
idPointerDown,
|
||||||
xPointerDown,
|
xPointerDown,
|
||||||
y
|
y
|
||||||
@@ -181,12 +179,12 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_POINTER_UP -> {
|
MotionEvent.ACTION_POINTER_UP -> {
|
||||||
val indexPointUp = pMotionEvent.action shr 8
|
val indexPointUp = motionEvent.action shr 8
|
||||||
val idPointerUp = pMotionEvent.getPointerId(indexPointUp)
|
val idPointerUp = motionEvent.getPointerId(indexPointUp)
|
||||||
val xPointerUp = pMotionEvent.getX(indexPointUp)
|
val xPointerUp = motionEvent.getX(indexPointUp)
|
||||||
val y2 = pMotionEvent.getY(indexPointUp)
|
val y2 = motionEvent.getY(indexPointUp)
|
||||||
queueEvent {
|
queueEvent {
|
||||||
mCocos2dxRenderer.handleActionUp(
|
cocos2dxRenderer.handleActionUp(
|
||||||
idPointerUp,
|
idPointerUp,
|
||||||
xPointerUp,
|
xPointerUp,
|
||||||
y2
|
y2
|
||||||
@@ -199,43 +197,43 @@ class Cocos2dxGLSurfaceView(context: Context) : GLSurfaceView(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSizeChanged(
|
override fun onSizeChanged(
|
||||||
pNewSurfaceWidth: Int,
|
newSurfaceWidth: Int,
|
||||||
pNewSurfaceHeight: Int,
|
newSurfaceHeight: Int,
|
||||||
pOldSurfaceWidth: Int,
|
oldSurfaceWidth: Int,
|
||||||
pOldSurfaceHeight: Int
|
oldSurfaceHeight: Int
|
||||||
) {
|
) {
|
||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
mCocos2dxRenderer.setScreenWidthAndHeight(pNewSurfaceWidth, pNewSurfaceHeight)
|
cocos2dxRenderer.setScreenWidthAndHeight(newSurfaceWidth, newSurfaceHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKeyDown(pKeyCode: Int, pKeyEvent: KeyEvent): Boolean {
|
override fun onKeyDown(keyCode: Int, keyEvent: KeyEvent): Boolean {
|
||||||
return when (pKeyCode) {
|
return when (keyCode) {
|
||||||
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU -> {
|
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_MENU -> {
|
||||||
if (pKeyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton) {
|
if (keyEvent.repeatCount != 0 || BaseRobTopActivity.blockBackButton) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
queueEvent { mCocos2dxRenderer.handleKeyDown(pKeyCode) }
|
queueEvent { cocos2dxRenderer.handleKeyDown(keyCode) }
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onKeyDown(pKeyCode, pKeyEvent)
|
else -> super.onKeyDown(keyCode, keyEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setCocos2dxRenderer(renderer: Cocos2dxRenderer) {
|
fun setCocos2dxRenderer(renderer: Cocos2dxRenderer) {
|
||||||
this.mCocos2dxRenderer = renderer
|
this.cocos2dxRenderer = renderer
|
||||||
setRenderer(this.mCocos2dxRenderer)
|
setRenderer(this.cocos2dxRenderer)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getContentText(): String {
|
private fun getContentText(): String {
|
||||||
return mCocos2dxRenderer.getContentText()
|
return cocos2dxRenderer.getContentText()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertText(pText: String) {
|
fun insertText(text: String) {
|
||||||
queueEvent { mCocos2dxRenderer.handleInsertText(pText) }
|
queueEvent { cocos2dxRenderer.handleInsertText(text) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteBackward() {
|
fun deleteBackward() {
|
||||||
queueEvent { mCocos2dxRenderer.handleDeleteBackward() }
|
queueEvent { cocos2dxRenderer.handleDeleteBackward() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,21 +12,21 @@ object Cocos2dxHelper {
|
|||||||
// private val sAssetManager: AssetManager? = null
|
// private val sAssetManager: AssetManager? = null
|
||||||
// private val sCocos2dxAccelerometer: Cocos2dxAccelerometer? = null
|
// private val sCocos2dxAccelerometer: Cocos2dxAccelerometer? = null
|
||||||
// private val sAccelerometerEnabled = false
|
// private val sAccelerometerEnabled = false
|
||||||
private var sPackageName: String? = null
|
private var packageName: String? = null
|
||||||
private var sFileDirectory: String? = null
|
private var fileDirectory: String? = null
|
||||||
|
|
||||||
// private var sContext: Context? = null
|
// private var sContext: Context? = null
|
||||||
private var sCocos2dxHelperListener: Cocos2dxHelperListener? = null
|
private var cocos2dxHelperListener: Cocos2dxHelperListener? = null
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
external fun nativeSetApkPath(pApkPath: String)
|
external fun nativeSetApkPath(apkPath: String)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeSetEditTextDialogResult(pBytes: ByteArray)
|
private external fun nativeSetEditTextDialogResult(bytes: ByteArray)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getCocos2dxWritablePath(): String? {
|
fun getCocos2dxWritablePath(): String? {
|
||||||
return sFileDirectory
|
return fileDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -34,12 +34,12 @@ object Cocos2dxHelper {
|
|||||||
Process.killProcess(Process.myPid())
|
Process.killProcess(Process.myPid())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init(pContext: Context, pCocos2dxHelperListener: Cocos2dxHelperListener) {
|
fun init(context: Context, cocos2dxHelperListener: Cocos2dxHelperListener) {
|
||||||
val applicationInfo: ApplicationInfo = pContext.applicationInfo
|
val applicationInfo: ApplicationInfo = context.applicationInfo
|
||||||
// sContext = pContext
|
// sContext = pContext
|
||||||
sCocos2dxHelperListener = pCocos2dxHelperListener
|
this.cocos2dxHelperListener = cocos2dxHelperListener
|
||||||
sPackageName = applicationInfo.packageName
|
packageName = applicationInfo.packageName
|
||||||
sFileDirectory = pContext.filesDir.absolutePath
|
fileDirectory = context.filesDir.absolutePath
|
||||||
|
|
||||||
nativeSetApkPath(applicationInfo.sourceDir)
|
nativeSetApkPath(applicationInfo.sourceDir)
|
||||||
// Cocos2dxHelper.sCocos2dxAccelerometer = Cocos2dxAccelerometer(pContext)
|
// Cocos2dxHelper.sCocos2dxAccelerometer = Cocos2dxAccelerometer(pContext)
|
||||||
@@ -50,22 +50,22 @@ object Cocos2dxHelper {
|
|||||||
// }
|
// }
|
||||||
// Cocos2dxHelper.sCocos2dSound = Cocos2dxSound(pContext, simultaneousStreams)
|
// Cocos2dxHelper.sCocos2dSound = Cocos2dxSound(pContext, simultaneousStreams)
|
||||||
// Cocos2dxHelper.sAssetManager = pContext.getAssets()
|
// Cocos2dxHelper.sAssetManager = pContext.getAssets()
|
||||||
Cocos2dxBitmap.setContext(pContext)
|
Cocos2dxBitmap.setContext(context)
|
||||||
// Cocos2dxETCLoader.setContext(pContext)
|
// Cocos2dxETCLoader.setContext(pContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Cocos2dxHelperListener {
|
interface Cocos2dxHelperListener {
|
||||||
fun runOnGLThread(pRunnable: Runnable)
|
fun runOnGLThread(runnable: Runnable)
|
||||||
|
|
||||||
fun showDialog(pTitle: String, pMessage: String)
|
fun showDialog(title: String, message: String)
|
||||||
|
|
||||||
fun showEditTextDialog(
|
fun showEditTextDialog(
|
||||||
pTitle: String,
|
title: String,
|
||||||
pMessage: String,
|
message: String,
|
||||||
pInputMode: Int,
|
inputMode: Int,
|
||||||
pInputFlag: Int,
|
inputFlag: Int,
|
||||||
pReturnType: Int,
|
returnType: Int,
|
||||||
pMaxLength: Int
|
maxLength: Int
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ import javax.microedition.khronos.opengles.GL10
|
|||||||
class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setAnimationInterval(@Suppress("UNUSED_PARAMETER") pAnimationInterval: Double) {
|
fun setAnimationInterval(@Suppress("UNUSED_PARAMETER") animationInterval: Double) {
|
||||||
// this function is useless for gd
|
// this function is useless for gd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,10 +19,10 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
|||||||
private external fun nativeGetContentText(): String
|
private external fun nativeGetContentText(): String
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeInsertText(pText: String)
|
private external fun nativeInsertText(text: String)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeKeyDown(pKeyCode: Int): Boolean
|
private external fun nativeKeyDown(keyCode: Int): Boolean
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeOnPause()
|
private external fun nativeOnPause()
|
||||||
@@ -37,63 +37,63 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
|||||||
private external fun nativeTextClosed()
|
private external fun nativeTextClosed()
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeTouchesBegin(pID: Int, pX: Float, pY: Float)
|
private external fun nativeTouchesBegin(id: Int, x: Float, y: Float)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeTouchesCancel(
|
private external fun nativeTouchesCancel(
|
||||||
pIDs: IntArray,
|
ids: IntArray,
|
||||||
pXs: FloatArray,
|
xs: FloatArray,
|
||||||
pYs: FloatArray
|
ys: FloatArray
|
||||||
)
|
)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeTouchesEnd(pID: Int, pX: Float, pY: Float)
|
private external fun nativeTouchesEnd(id: Int, x: Float, y: Float)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeTouchesMove(pIDs: IntArray, pXs: FloatArray, pYs: FloatArray)
|
private external fun nativeTouchesMove(ids: IntArray, xs: FloatArray, ys: FloatArray)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private external fun nativeInit(pWidth: Int, pHeight: Int)
|
private external fun nativeInit(width: Int, height: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var mLastTickInNanoSeconds: Long = 0
|
private var lastTickInNanoSeconds: Long = 0
|
||||||
private var mScreenWidth = 0
|
private var screenWidth = 0
|
||||||
private var mScreenHeight = 0
|
private var screenHeight = 0
|
||||||
|
|
||||||
fun setScreenWidthAndHeight(pSurfaceWidth: Int, pSurfaceHeight: Int) {
|
fun setScreenWidthAndHeight(surfaceWidth: Int, surfaceHeight: Int) {
|
||||||
mScreenWidth = pSurfaceWidth
|
screenWidth = surfaceWidth
|
||||||
mScreenHeight = pSurfaceHeight
|
screenHeight = surfaceHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceCreated(pGL10: GL10?, pEGLConfig: EGLConfig?) {
|
override fun onSurfaceCreated(gl10: GL10?, eglConfig: EGLConfig?) {
|
||||||
nativeInit(this.mScreenWidth, this.mScreenHeight)
|
nativeInit(screenWidth, screenHeight)
|
||||||
this.mLastTickInNanoSeconds = System.nanoTime()
|
lastTickInNanoSeconds = System.nanoTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceChanged(pGL10: GL10?, pWidth: Int, pHeight: Int) {}
|
override fun onSurfaceChanged(gl10: GL10?, width: Int, height: Int) {}
|
||||||
|
|
||||||
override fun onDrawFrame(gl: GL10?) {
|
override fun onDrawFrame(gl: GL10?) {
|
||||||
nativeRender()
|
nativeRender()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleActionDown(pID: Int, pX: Float, pY: Float) {
|
fun handleActionDown(id: Int, x: Float, y: Float) {
|
||||||
nativeTouchesBegin(pID, pX, pY)
|
nativeTouchesBegin(id, x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleActionUp(pID: Int, pX: Float, pY: Float) {
|
fun handleActionUp(id: Int, x: Float, y: Float) {
|
||||||
nativeTouchesEnd(pID, pX, pY)
|
nativeTouchesEnd(id, x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleActionCancel(pIDs: IntArray, pXs: FloatArray, pYs: FloatArray) {
|
fun handleActionCancel(ids: IntArray, xs: FloatArray, ys: FloatArray) {
|
||||||
nativeTouchesCancel(pIDs, pXs, pYs)
|
nativeTouchesCancel(ids, xs, ys)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleActionMove(pIDs: IntArray, pXs: FloatArray, pYs: FloatArray) {
|
fun handleActionMove(ids: IntArray, xs: FloatArray, ys: FloatArray) {
|
||||||
nativeTouchesMove(pIDs, pXs, pYs)
|
nativeTouchesMove(ids, xs, ys)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleKeyDown(pKeyCode: Int) {
|
fun handleKeyDown(keyCode: Int) {
|
||||||
nativeKeyDown(pKeyCode)
|
nativeKeyDown(keyCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleOnPause() {
|
fun handleOnPause() {
|
||||||
@@ -104,8 +104,8 @@ class Cocos2dxRenderer : GLSurfaceView.Renderer {
|
|||||||
nativeOnResume()
|
nativeOnResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleInsertText(pText: String) {
|
fun handleInsertText(text: String) {
|
||||||
nativeInsertText(pText)
|
nativeInsertText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleDeleteBackward() {
|
fun handleDeleteBackward() {
|
||||||
|
|||||||
@@ -8,62 +8,62 @@ import android.view.KeyEvent
|
|||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
class Cocos2dxTextInputWrapper(private val mCocos2dxGLSurfaceView: Cocos2dxGLSurfaceView) : TextWatcher, OnEditorActionListener {
|
class Cocos2dxTextInputWrapper(private val cocos2dxGLSurfaceView: Cocos2dxGLSurfaceView) : TextWatcher, OnEditorActionListener {
|
||||||
private var mOriginText: String? = null
|
private var originText: String? = null
|
||||||
private var mText: String? = null
|
private var text: String? = null
|
||||||
|
|
||||||
private val isFullScreenEdit: Boolean
|
private val isFullScreenEdit: Boolean
|
||||||
get() = (mCocos2dxGLSurfaceView.cocos2dxEditText?.context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).isFullscreenMode
|
get() = (cocos2dxGLSurfaceView.cocos2dxEditText?.context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).isFullscreenMode
|
||||||
|
|
||||||
fun setOriginText(pOriginText: String?) {
|
fun setOriginText(originText: String?) {
|
||||||
mOriginText = pOriginText
|
this.originText = originText
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterTextChanged(s: Editable) {
|
override fun afterTextChanged(s: Editable) {
|
||||||
if (!isFullScreenEdit) {
|
if (!isFullScreenEdit) {
|
||||||
var nModified = s.length - mText!!.length
|
var nModified = s.length - text!!.length
|
||||||
if (nModified > 0) {
|
if (nModified > 0) {
|
||||||
mCocos2dxGLSurfaceView.insertText(
|
cocos2dxGLSurfaceView.insertText(
|
||||||
s.subSequence(mText!!.length, s.length).toString()
|
s.subSequence(text!!.length, s.length).toString()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
while (nModified < 0) {
|
while (nModified < 0) {
|
||||||
mCocos2dxGLSurfaceView.deleteBackward()
|
cocos2dxGLSurfaceView.deleteBackward()
|
||||||
nModified++
|
nModified++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mText = s.toString()
|
text = s.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforeTextChanged(
|
override fun beforeTextChanged(
|
||||||
pCharSequence: CharSequence,
|
charSequence: CharSequence,
|
||||||
start: Int,
|
start: Int,
|
||||||
count: Int,
|
count: Int,
|
||||||
after: Int
|
after: Int
|
||||||
) {
|
) {
|
||||||
mText = pCharSequence.toString()
|
text = charSequence.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTextChanged(pCharSequence: CharSequence, start: Int, before: Int, count: Int) {}
|
override fun onTextChanged(pCharSequence: CharSequence, start: Int, before: Int, count: Int) {}
|
||||||
override fun onEditorAction(pTextView: TextView, pActionID: Int, pKeyEvent: KeyEvent?): Boolean {
|
override fun onEditorAction(textView: TextView, actionID: Int, keyEvent: KeyEvent?): Boolean {
|
||||||
if (mCocos2dxGLSurfaceView.cocos2dxEditText == pTextView && isFullScreenEdit) {
|
if (cocos2dxGLSurfaceView.cocos2dxEditText == textView && isFullScreenEdit) {
|
||||||
for (i in mOriginText!!.length downTo 1) {
|
for (i in originText!!.length downTo 1) {
|
||||||
mCocos2dxGLSurfaceView.deleteBackward()
|
cocos2dxGLSurfaceView.deleteBackward()
|
||||||
}
|
}
|
||||||
var text = pTextView.text.toString()
|
var text = textView.text.toString()
|
||||||
if (text.compareTo("") == 0) {
|
if (text.compareTo("") == 0) {
|
||||||
text = "\n"
|
text = "\n"
|
||||||
}
|
}
|
||||||
if (10 != text[text.length - 1].code) {
|
if (10 != text[text.length - 1].code) {
|
||||||
text += 10.toChar()
|
text += 10.toChar()
|
||||||
}
|
}
|
||||||
mCocos2dxGLSurfaceView.insertText(text)
|
cocos2dxGLSurfaceView.insertText(text)
|
||||||
}
|
}
|
||||||
if (pActionID != 6) {
|
if (actionID != 6) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
mCocos2dxGLSurfaceView.requestFocus()
|
cocos2dxGLSurfaceView.requestFocus()
|
||||||
Cocos2dxGLSurfaceView.closeIMEKeyboard()
|
Cocos2dxGLSurfaceView.closeIMEKeyboard()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ import kotlin.jvm.Synchronized
|
|||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
|
|
||||||
object Cocos2dxTypefaces {
|
object Cocos2dxTypefaces {
|
||||||
private val sTypefaceCache = HashMap<String, Typeface>()
|
private val typefaceCache = HashMap<String, Typeface>()
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
operator fun get(pContext: Context, pAssetName: String): Typeface? {
|
operator fun get(pContext: Context, pAssetName: String): Typeface? {
|
||||||
var typeface: Typeface?
|
var typeface: Typeface?
|
||||||
var typeface2: Typeface
|
var typeface2: Typeface
|
||||||
synchronized(Cocos2dxTypefaces::class.java) {
|
synchronized(Cocos2dxTypefaces::class.java) {
|
||||||
if (!sTypefaceCache.containsKey(pAssetName)) {
|
if (!typefaceCache.containsKey(pAssetName)) {
|
||||||
typeface2 = if (pAssetName.startsWith("/")) {
|
typeface2 = if (pAssetName.startsWith("/")) {
|
||||||
Typeface.createFromFile(pAssetName)
|
Typeface.createFromFile(pAssetName)
|
||||||
} else {
|
} else {
|
||||||
Typeface.createFromAsset(pContext.assets, pAssetName)
|
Typeface.createFromAsset(pContext.assets, pAssetName)
|
||||||
}
|
}
|
||||||
sTypefaceCache[pAssetName] = typeface2
|
typefaceCache[pAssetName] = typeface2
|
||||||
}
|
}
|
||||||
typeface = sTypefaceCache[pAssetName]
|
typeface = typefaceCache[pAssetName]
|
||||||
}
|
}
|
||||||
return typeface
|
return typeface
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user