cleanup naming conventions

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