背景和头像缺失

This commit is contained in:
2026-03-01 13:48:24 +08:00
parent 9ae4e8e614
commit eaaf7f8c9b
554 changed files with 1871 additions and 1718 deletions

View File

@@ -1,18 +1,18 @@
#include "Utility.h"
#include "Utility.h"
#include "ui/CocosGUI.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "iconv.h"
#else
#include <jni.h>
#include "platform/android/jni/JniHelper.h"
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "android/jni/JniHelper.h"
#endif
#include "Helps.h"
//////////////////////////////////////////////////////////////////////////
/**
* 获取utf8字符串长度
* @param utf8 utf8字符串
* @return 字符串长度
* 计算utf8字符串长度
* @param utf8 utf8字符串
* @return 字符串长度
*/
int utf8_len(const char *utf8)
{
@@ -39,9 +39,9 @@ int utf8_cmp(const char* str1, const char* str2)
}
/**
* 获取ucs2字符串长度
* @param ucs2 ucs2字符串
* @return 字符串长度
* 计算ucs2字符串长度
* @param ucs2 ucs2字符串
* @return 字符串长度
*/
int ucs2_len(const unsigned short* ucs2)
{
@@ -63,59 +63,59 @@ int ucs2_len(const unsigned short* ucs2)
int code_convert(const char *from_charset, const char *to_charset, const char *inbuf, size_t inlen, char *outbuf, size_t outlen)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
iconv_t cd;
const char *temp = inbuf;
const char **pin = &temp;
char **pout = &outbuf;
const UINT CP_GBK = 936;
int wlen = MultiByteToWideChar(CP_GBK, 0, inbuf, inlen, NULL, 0);
if (wlen <= 0) return -1;
wchar_t* wbuf = new wchar_t[wlen + 1];
MultiByteToWideChar(CP_GBK, 0, inbuf, inlen, wbuf, wlen);
wbuf[wlen] = 0;
int ulen = WideCharToMultiByte(CP_UTF8, 0, wbuf, wlen, NULL, 0, NULL, NULL);
if (ulen <= 0 || ulen >= (int)outlen) { delete[] wbuf; return -1; }
memset(outbuf, 0, outlen);
cd = iconv_open(to_charset, from_charset);
if (cd == 0) return -1;
if (-1 == iconv(cd, pin, &inlen, pout, &outlen)) return -1;
iconv_close(cd);
WideCharToMultiByte(CP_UTF8, 0, wbuf, wlen, outbuf, ulen, NULL, NULL);
delete[] wbuf;
return 0;
#endif
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
memset(outbuf,0,outlen);
JNIEnv* env = cocos2d::JniHelper::getEnv();
if (!env) return -1;
jbyteArray inputBytes = env->NewByteArray(inlen);
env->SetByteArrayRegion(inputBytes, 0, inlen, (const jbyte*)inbuf);
jstring fromCharset = env->NewStringUTF(from_charset);
jstring toCharset = env->NewStringUTF(to_charset);
jclass stringClass = env->FindClass("java/lang/String");
jmethodID ctor = env->GetMethodID(stringClass, "<init>", "([BLjava/lang/String;)V");
jobject jstr = env->NewObject(stringClass, ctor, inputBytes, fromCharset);
jmethodID getBytes = env->GetMethodID(stringClass, "getBytes", "(Ljava/lang/String;)[B");
jbyteArray outputBytes = (jbyteArray)env->CallObjectMethod(jstr, getBytes, toCharset);
if (outputBytes) {
jsize outputLen = env->GetArrayLength(outputBytes);
if ((size_t)outputLen < outlen) {
env->GetByteArrayRegion(outputBytes, 0, outputLen, (jbyte*)outbuf);
// Android: use JNI to convert GBK -> UTF-8 via Java charset
memset(outbuf, 0, outlen);
if (strcmp(from_charset, "gbk") == 0 || strcmp(from_charset, "GBK") == 0)
{
cocos2d::JniMethodInfo minfo;
if (cocos2d::JniHelper::getStaticMethodInfo(minfo, "com/jxkh/queyi/Native", "convertGbkToUtf8", "([B)Ljava/lang/String;"))
{
jbyteArray jBytes = minfo.env->NewByteArray(inlen);
minfo.env->SetByteArrayRegion(jBytes, 0, inlen, (const jbyte*)inbuf);
jstring jResult = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID, jBytes);
if (jResult)
{
const char* utf8Str = minfo.env->GetStringUTFChars(jResult, NULL);
size_t utf8Len = strlen(utf8Str);
if (utf8Len < outlen)
{
memcpy(outbuf, utf8Str, utf8Len);
}
minfo.env->ReleaseStringUTFChars(jResult, utf8Str);
minfo.env->DeleteLocalRef(jResult);
}
minfo.env->DeleteLocalRef(jBytes);
minfo.env->DeleteLocalRef(minfo.classID);
return 0;
}
env->DeleteLocalRef(outputBytes);
}
env->DeleteLocalRef(jstr);
env->DeleteLocalRef(toCharset);
env->DeleteLocalRef(fromCharset);
env->DeleteLocalRef(inputBytes);
env->DeleteLocalRef(stringClass);
// Fallback: direct copy
size_t copyLen = (inlen < outlen) ? inlen : outlen - 1;
memcpy(outbuf, inbuf, copyLen);
return 0;
#endif
return 0;
}
namespace utility
{
/**
* 获取utf8字符串长度
* @param utf8 utf8字符串
* @return 字符串长度
* 计算utf8字符串长度
* @param utf8 utf8字符串
* @return 字符串长度
*/
int utf8_len(std::string utf8)
{
@@ -125,15 +125,15 @@ namespace utility
{
return 0;
unsigned int i;
unsigned long nBytes=0;//UFT8可用1-6个字节编码,ASCII用一个字节
unsigned long nBytes=0;//UFT8可用1-6个字节编码,ASCII用一个字节
unsigned char chr;
int bAllAscii=1; //如果全部都是ASCII, 说明不是UTF-8
int bAllAscii=1; //如果全部都是ASCII, 说明不是UTF-8
for(i=0;i<length;i++)
{
chr= *(str+i);
if( (chr&0x80) != 0 ) // 判断是否ASCII编码,如果不是,说明有可能是UTF-8,ASCII用7位编码,用一个字节存,最高位标记为0,o0xxxxxxx
if( (chr&0x80) != 0 ) // 判断是否ASCII编码,如果不是,说明有可能是UTF-8,ASCII用7位编码,用一个字节存,最高位标记为0,o0xxxxxxx
bAllAscii= 0;
if(nBytes==0) //如果不是ASCII码,应该是多字节符,计算字节数
if(nBytes==0) //如果不是ASCII码,应该是多字节符,计算字节数
{
if(chr>=0x80)
{
@@ -154,7 +154,7 @@ namespace utility
nBytes--;
}
}
else //多字节符的非首字节,应为 10xxxxxx
else //多字节符的非首字节,应为 10xxxxxx
{
if( (chr&0xC0) != 0x80 )
{
@@ -163,16 +163,40 @@ namespace utility
nBytes--;
}
}
if( nBytes > 0 ) //违规则
if( nBytes > 0 ) //违规则
{
return 0;
}
if( bAllAscii ) //如果全部都是ASCII, 说明不是UTF-8
if( bAllAscii ) //如果全部都是ASCII, 说明不是UTF-8
{
return 0;
}
return 1;
}
static bool isValidUtf8(const char* data, size_t len)
{
const unsigned char* p = (const unsigned char*)data;
bool hasMultiByte = false;
size_t i = 0;
while (i < len)
{
if (p[i] <= 0x7F) { i++; continue; }
hasMultiByte = true;
int seqLen = 0;
if ((p[i] & 0xE0) == 0xC0) seqLen = 2;
else if ((p[i] & 0xF0) == 0xE0) seqLen = 3;
else if ((p[i] & 0xF8) == 0xF0) seqLen = 4;
else return false;
if (i + seqLen > len) return false;
for (int j = 1; j < seqLen; j++)
{
if ((p[i + j] & 0xC0) != 0x80) return false;
}
i += seqLen;
}
return hasMultiByte;
}
std::string a_u8(std::string gbk)
{
size_t inlen = strlen(gbk.c_str());
@@ -180,6 +204,10 @@ namespace utility
{
return std::string();
}
if (isValidUtf8(gbk.c_str(), inlen))
{
return gbk;
}
char * outbuf = new char[inlen * 4+2];
std::string strRet = gbk;
if(code_convert("gbk", "utf-8", gbk.c_str(), inlen, outbuf, inlen * 4+2 ) == 0)
@@ -188,6 +216,7 @@ namespace utility
}
delete [] outbuf;
return strRet;
}
std::string u8_a(std::string utf8)
{
@@ -210,7 +239,7 @@ namespace utility
return strRet;
}
/*gbk转为UTF16*/
/*gbk转为UTF16*/
std::string a2l(const char *inbuf)
{
size_t inlen = strlen(inbuf);
@@ -223,7 +252,7 @@ namespace utility
}
/*utf16转为UTF8*/
/*utf16转为UTF8*/
std::string l2u(const char *inbuf)
{
size_t inlen = ucs2_len((const unsigned short*)&inbuf[0]);
@@ -296,7 +325,7 @@ namespace utility
pSprFace->setAnchorPoint(Vec2(0, 0));
pSprFace->setFlippedY(true);
// 头像遮罩
// 头像剪切
auto textureCache = Director::getInstance()->getTextureCache();
auto texMask = textureCache->addImage("Platform/lobby/head_mask.png");
CC_ASSERT(texMask != nullptr);
@@ -433,7 +462,7 @@ namespace utility
}
}
//根据宽度截取昵号长度(参数:昵称,字体文件名,字体大小,限定宽度)
//超出宽度用星号代替(参数:昵称字体文件字体大小,超出宽度)
std::string getShortName(const std::string& strName, const std::string& strFont, float fFontSize, float fOverWidth)
{
size_t nCount = strName.size();
@@ -461,7 +490,7 @@ namespace utility
if (fTotalWidth >= fOverWidth)
{
return strName.substr(0, i - (bChinese ? 3 : 1)) + a_u8("...");
return strName.substr(0, i - (bChinese ? 3 : 1)) + a_u8("");
}
}
@@ -492,7 +521,7 @@ namespace utility
if (nTempNum > nFontNum)
{
return strName.substr(0, i - (bChinese ? 3 : 1)) + a_u8("...");
return strName.substr(0, i - (bChinese ? 3 : 1)) + a_u8("");
}
}
@@ -512,17 +541,17 @@ namespace utility
std::string GetUserLevel(SCORE lGrade)
{
static std::string Levels[] = {
"等级:雀",
"等级:雀",
"等级:雀头",
"等级:铜雀",
"等级:银雀",
"等级:金雀",
"等级:雀",
"等级:雀",
"等级:雀",
"等级:雀圣",
"等级:雀神"
"等级:雀",
"等级:雀",
"等级:雀头",
"等级:铜雀",
"等级:银雀",
"等级:金雀",
"等级:雀",
"等级:雀",
"等级:雀",
"等级:雀圣",
"等级:雀神"
};
static SCORE lLevels[] = { 200, 500, 1000, 2000, 4000, 6000, 10000, 15000, 20000, 30000 };
@@ -553,4 +582,4 @@ namespace utility
return Helps::MD5Encrypt(timeString);
}
}
}

View File

@@ -15,14 +15,14 @@ namespace utility
#define a_u8c(str) utility::a_u8(str).c_str()
int utf8_len(std::string utf8);
//gbk转utf8
//gbk转utf8
std::string a_u8(std::string gbk);
//utf8转gbk
//utf8转gbk
std::string u8_a(std::string utf8);
//gbk转为UTF16
//gbk转为UTF16
std::string a2l(const char *inbuf);
//utf16转为UTF8
//utf16转为UTF8
std::string l2u(const char *inbuf);
void mlog(const char * format, ...);
@@ -205,12 +205,12 @@ namespace utility
return result;
}
//超出宽度用星号代替(参数:昵称字体文件字体大小,超出宽度)
//超长字符名号处理(参数:昵称字体文件字体大小、最大宽度)
std::string getShortName(const std::string& strName, const std::string& strFont, float fFontSize, float fOverWidth);
std::string getShortName(const std::string& strName, int nFontNum);
// 分转字符串;
// 分转字符串
std::string ScoreToString(SCORE lScore);
std::string GetUserLevel(SCORE lGrade);

View File

@@ -6,7 +6,7 @@
#endif
#ifndef uint32
#define uint32 unsigned long int
#define uint32 unsigned int
#endif
typedef struct