本文整理汇总了C++中Dictionary类的典型用法代码示例。如果您正苦于以下问题:C++ Dictionary类的具体用法?C++ Dictionary怎么用?C++ Dictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetDictionary
/**************************************************************
*
* * Entry: none
*
* * Exit: inflated dictionary with maxLength as its longest word(s)
*
* * Purpose: change word length to match difficulty
*
* ***************************************************************/
void SetDictionary ( int maxLength ) {
myDict = Dictionary( maxLength );
if ( !myDict.Filled() )
myDict = PreFabDict::UsePreFabDict();
}
示例2: ERR_CONTINUE
void EditorSceneImporterFBXConv::_parse_materials(State& state) {
for(int i=0;i<state.materials.size();i++) {
Dictionary material = state.materials[i];
ERR_CONTINUE(!material.has("id"));
String id = _id(material["id"]);
Ref<FixedMaterial> mat = memnew( FixedMaterial );
if (material.has("diffuse")) {
mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,_get_color(material["diffuse"]));
}
if (material.has("specular")) {
mat->set_parameter(FixedMaterial::PARAM_SPECULAR,_get_color(material["specular"]));
}
if (material.has("emissive")) {
mat->set_parameter(FixedMaterial::PARAM_EMISSION,_get_color(material["emissive"]));
}
if (material.has("shininess")) {
float exp = material["shininess"];
mat->set_parameter(FixedMaterial::PARAM_SPECULAR_EXP,exp);
}
if (material.has("opacity")) {
Color c = mat->get_parameter(FixedMaterial::PARAM_DIFFUSE);
c.a=material["opacity"];
mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,c);
}
if (material.has("textures")) {
Array textures = material["textures"];
for(int j=0;j<textures.size();j++) {
Dictionary texture=textures[j];
Ref<Texture> tex;
if (texture.has("filename")) {
String filename=texture["filename"];
String path=state.base_path+"/"+filename.replace("\\","/");
if (state.texture_cache.has(path)) {
tex=state.texture_cache[path];
} else {
tex = ResourceLoader::load(path,"ImageTexture");
if (tex.is_null()) {
if (state.missing_deps)
state.missing_deps->push_back(path);
}
state.texture_cache[path]=tex; //add anyway
}
}
if (tex.is_valid() && texture.has("type")) {
String type=texture["type"];
if (type=="DIFFUSE")
mat->set_texture(FixedMaterial::PARAM_DIFFUSE,tex);
else if (type=="SPECULAR")
mat->set_texture(FixedMaterial::PARAM_SPECULAR,tex);
else if (type=="SHININESS")
mat->set_texture(FixedMaterial::PARAM_SPECULAR_EXP,tex);
else if (type=="NORMAL")
mat->set_texture(FixedMaterial::PARAM_NORMAL,tex);
else if (type=="EMISSIVE")
mat->set_texture(FixedMaterial::PARAM_EMISSION,tex);
}
}
}
state.material_cache[id]=mat;
}
}
示例3: _get_transform_mixed
Transform EditorSceneImporterFBXConv::_get_transform_mixed(const Dictionary& d,const Dictionary& dbase) {
Array translation;
if (d.has("translation"))
translation=d["translation"];
else if (dbase.has("translation"))
translation=dbase["translation"];
Array rotation;
if (d.has("rotation"))
rotation=d["rotation"];
else if (dbase.has("rotation"))
rotation=dbase["rotation"];
Array scale;
if (d.has("scale"))
scale=d["scale"];
else if (dbase.has("scale"))
scale=dbase["scale"];
Transform t;
if (translation.size()) {
Array tr = translation;
if (tr.size()>=3) {
t.origin.x=tr[0];
t.origin.y=tr[1];
t.origin.z=tr[2];
}
}
if (rotation.size()) {
Array r = rotation;
if (r.size()>=4) {
Quat q;
q.x = r[0];
q.y = r[1];
q.z = r[2];
q.w = r[3];
t.basis=Matrix3(q);
}
}
if (scale.size()) {
Array sc = scale;
if (sc.size()>=3) {
Vector3 s;
s.x=sc[0];
s.y=sc[1];
s.z=sc[2];
t.basis.scale(s);
}
}
return t;
}
示例4: zero
void NetworkConfig::_fromDictionary(const Dictionary &d)
{
static const std::string zero("0");
static const std::string one("1");
// NOTE: d.get(name) throws if not found, d.get(name,default) returns default
_nwid = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_NETWORK_ID).c_str());
if (!_nwid)
throw std::invalid_argument("configuration contains zero network ID");
_timestamp = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_TIMESTAMP).c_str());
_revision = Utils::hexStrToU64(d.get(ZT_NETWORKCONFIG_DICT_KEY_REVISION,"1").c_str()); // older controllers don't send this, so default to 1
memset(_etWhitelist,0,sizeof(_etWhitelist));
std::vector<std::string> ets(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOWED_ETHERNET_TYPES).c_str(),",","",""));
for(std::vector<std::string>::const_iterator et(ets.begin());et!=ets.end();++et) {
unsigned int tmp = Utils::hexStrToUInt(et->c_str()) & 0xffff;
_etWhitelist[tmp >> 3] |= (1 << (tmp & 7));
}
_issuedTo = Address(d.get(ZT_NETWORKCONFIG_DICT_KEY_ISSUED_TO));
_multicastLimit = Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_LIMIT,zero).c_str());
if (_multicastLimit == 0) _multicastLimit = ZT_MULTICAST_DEFAULT_LIMIT;
_allowPassiveBridging = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ALLOW_PASSIVE_BRIDGING,zero).c_str()) != 0);
_private = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_PRIVATE,one).c_str()) != 0);
_enableBroadcast = (Utils::hexStrToUInt(d.get(ZT_NETWORKCONFIG_DICT_KEY_ENABLE_BROADCAST,one).c_str()) != 0);
_name = d.get(ZT_NETWORKCONFIG_DICT_KEY_NAME);
if (_name.length() > ZT1_MAX_NETWORK_SHORT_NAME_LENGTH)
throw std::invalid_argument("network short name too long (max: 255 characters)");
_description = d.get(ZT_NETWORKCONFIG_DICT_KEY_DESC,std::string());
// In dictionary IPs are split into V4 and V6 addresses, but we don't really
// need that so merge them here.
std::string ipAddrs(d.get(ZT_NETWORKCONFIG_DICT_KEY_IPV4_STATIC,std::string()));
{
std::string v6s(d.get(ZT_NETWORKCONFIG_DICT_KEY_IPV6_STATIC,std::string()));
if (v6s.length()) {
if (ipAddrs.length())
ipAddrs.push_back(',');
ipAddrs.append(v6s);
}
}
std::vector<std::string> ipAddrsSplit(Utils::split(ipAddrs.c_str(),",","",""));
for(std::vector<std::string>::const_iterator ipstr(ipAddrsSplit.begin());ipstr!=ipAddrsSplit.end();++ipstr) {
InetAddress addr(*ipstr);
switch(addr.ss_family) {
case AF_INET:
if ((!addr.netmaskBits())||(addr.netmaskBits() > 32))
continue;
break;
case AF_INET6:
if ((!addr.netmaskBits())||(addr.netmaskBits() > 128))
continue;
break;
default: // ignore unrecognized address types or junk/empty fields
continue;
}
_staticIps.push_back(addr);
}
if (_staticIps.size() > ZT1_MAX_ZT_ASSIGNED_ADDRESSES)
throw std::invalid_argument("too many ZT-assigned IP addresses");
std::sort(_staticIps.begin(),_staticIps.end());
std::unique(_staticIps.begin(),_staticIps.end());
std::vector<std::string> activeBridgesSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES,"").c_str(),",","",""));
for(std::vector<std::string>::const_iterator a(activeBridgesSplit.begin());a!=activeBridgesSplit.end();++a) {
if (a->length() == ZT_ADDRESS_LENGTH_HEX) { // ignore empty or garbage fields
Address tmp(*a);
if (!tmp.isReserved())
_activeBridges.push_back(tmp);
}
}
std::sort(_activeBridges.begin(),_activeBridges.end());
std::unique(_activeBridges.begin(),_activeBridges.end());
Dictionary multicastRateEntries(d.get(ZT_NETWORKCONFIG_DICT_KEY_MULTICAST_RATES,std::string()));
for(Dictionary::const_iterator i(multicastRateEntries.begin());i!=multicastRateEntries.end();++i) {
std::vector<std::string> params(Utils::split(i->second.c_str(),",","",""));
if (params.size() >= 3)
_multicastRates[MulticastGroup(i->first)] = MulticastRate(Utils::hexStrToUInt(params[0].c_str()),Utils::hexStrToUInt(params[1].c_str()),Utils::hexStrToUInt(params[2].c_str()));
}
std::vector<std::string> relaysSplit(Utils::split(d.get(ZT_NETWORKCONFIG_DICT_KEY_RELAYS,"").c_str(),",","",""));
for(std::vector<std::string>::const_iterator r(relaysSplit.begin());r!=relaysSplit.end();++r) {
std::size_t semi(r->find(';')); // address;ip/port,...
if (semi == ZT_ADDRESS_LENGTH_HEX) {
std::pair<Address,InetAddress> relay(
Address(r->substr(0,semi)),
((r->length() > (semi + 1)) ? InetAddress(r->substr(semi + 1)) : InetAddress()) );
if ((relay.first)&&(!relay.first.isReserved()))
_relays.push_back(relay);
}
}
std::sort(_relays.begin(),_relays.end());
std::unique(_relays.begin(),_relays.end());
_com.fromString(d.get(ZT_NETWORKCONFIG_DICT_KEY_CERTIFICATE_OF_MEMBERSHIP,std::string()));
}
示例5: ERR_FAIL_COND
void EditorSceneImporterFBXConv::_add_surface(State& state,Ref<Mesh>& m,const Dictionary &part) {
if (part.has("meshpartid")) {
String id = part["meshpartid"];
ERR_FAIL_COND(!state.surface_cache.has(id));
Ref<Material> mat;
if (part.has("materialid")) {
String matid=part["materialid"];
if (state.material_cache.has(matid)) {
mat=state.material_cache[matid];
}
}
int idx = m->get_surface_count();
Array array = state.surface_cache[id].array;
DVector<float> indices = array[Mesh::ARRAY_BONES];
if (indices.size() && part.has("bones")) {
Map<int,int> index_map;
Array bones=part["bones"];
for(int i=0;i<bones.size();i++) {
Dictionary bone=bones[i];
String name=_id(bone["node"]);
if (state.bones.has(name)) {
int idx=state.bones[name].skeleton->find_bone(name);
if (idx==-1)
idx=0;
index_map[i]=idx;
}
}
int ilen=indices.size();
{
DVector<float>::Write iw=indices.write();
for(int j=0;j<ilen;j++) {
int b = iw[j];
ERR_CONTINUE(!index_map.has(b));
b=index_map[b];
iw[j]=b;
}
}
array[Mesh::ARRAY_BONES]=indices;
}
m->add_surface(state.surface_cache[id].primitive,array);
m->surface_set_material(idx,mat);
m->surface_set_name(idx,id);
}
}
示例6: open
void CodecContext::open(Dictionary &options, const Codec &codec, error_code &ec)
{
auto prt = options.release();
open(codec, &prt, ec);
options.assign(prt);
}
示例7: main
int
main (int argc, char **argv)
{
int c;
char * restricted_files = NULL;
char * output_file = NULL;
char * dictionary_files = NULL;
while (1)
{
static struct option long_options[] =
{
/* These options set a flag. */
{"verbose", no_argument, &verbose_flag, 1},
{"brief", no_argument, &verbose_flag, 0},
{"deobscure", no_argument, &deobscure_flag, 1},
/* These options don't set a flag.
We distinguish them by their indices. */
{"dictionary", required_argument, 0, 'd'},
{"restricted", required_argument, 0, 'e'},
{"output", required_argument, 0, 'o'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "d:e:o:",
long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c)
{
case 0:
/* If this option set a flag, do nothing else now. */
if (long_options[option_index].flag != 0)
break;
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case 'd':
dictionary_files = optarg;
printf ("option -d with value `%s'\n", optarg);
break;
case 'e':
restricted_files = optarg;
printf ("option -e with value `%s'\n", optarg);
break;
case 'o':
output_file = optarg;
printf ("option -o with value `%s'\n", optarg);
break;
case '?':
/* getopt_long already printed an error message. */
break;
default:
abort ();
}
}
/* Instead of reporting ‘--verbose’
and ‘--brief’ as they are encountered,
we report the final status resulting from them. */
if (verbose_flag)
puts ("verbose flag is set");
char * files[1000];
unsigned fileindex = 0;
files[0] = NULL;
/* Print any remaining command line arguments (not options). */
if (optind < argc) {
printf ("non-option ARGV-elements: ");
while (optind < argc) {
files[fileindex++] = argv[optind];
printf ("%s ", argv[optind++]);
}
cout << fileindex << endl;
files[fileindex] = NULL;
cout << fileindex << endl;
}
char * ptr = NULL;
if (deobscure_flag) {
Dictionary d;
d.loadFile(strtok(dictionary_files, ","));
while ((ptr = strtok(NULL, ",")))
d.loadFile(ptr);
} else {
Restricted r;
r.loadFile(strtok(restricted_files, ","));
while ((ptr = strtok(NULL, ",")))
//.........这里部分代码省略.........
示例8: godot_dictionary_erase
void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key) {
Dictionary *self = (Dictionary *)p_self;
const Variant *key = (const Variant *)p_key;
self->erase(*key);
}
示例9: switch
//.........这里部分代码省略.........
if (res.is_null()) {
f->store_32(OBJECT_EMPTY);
return; // don't save it
}
if (res->get_path().length() && res->get_path().find("::")==-1) {
f->store_32(OBJECT_EXTERNAL_RESOURCE);
save_unicode_string(res->get_save_type());
String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
save_unicode_string(path);
} else {
if (!resource_map.has(res)) {
f->store_32(OBJECT_EMPTY);
ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
ERR_FAIL();
}
f->store_32(OBJECT_INTERNAL_RESOURCE);
f->store_32(resource_map[res]);
//internal resource
}
} break;
case Variant::INPUT_EVENT: {
f->store_32(VARIANT_INPUT_EVENT);
WARN_PRINT("Can't save InputEvent (maybe it could..)");
} break;
case Variant::DICTIONARY: {
f->store_32(VARIANT_DICTIONARY);
Dictionary d = p_property;
f->store_32(uint32_t(d.size())|(d.is_shared()?0x80000000:0));
List<Variant> keys;
d.get_key_list(&keys);
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
//if (!_check_type(dict[E->get()]))
// continue;
write_variant(E->get());
write_variant(d[E->get()]);
}
} break;
case Variant::ARRAY: {
f->store_32(VARIANT_ARRAY);
Array a=p_property;
f->store_32(uint32_t(a.size())|(a.is_shared()?0x80000000:0));
for(int i=0;i<a.size();i++) {
write_variant(a[i]);
}
} break;
case Variant::RAW_ARRAY: {
f->store_32(VARIANT_RAW_ARRAY);
DVector<uint8_t> arr = p_property;
int len=arr.size();
示例10: switch
void FileSystemDock::_notification(int p_what) {
switch(p_what) {
case NOTIFICATION_RESIZED: {
bool new_mode = get_size().height < get_viewport_rect().size.height*3/4;
if (new_mode != split_mode ) {
split_mode=new_mode;
//print_line("SPLIT MODE? "+itos(split_mode));
if (split_mode) {
file_list_vb->hide();
tree->set_custom_minimum_size(Size2(0,0));
tree->set_v_size_flags(SIZE_EXPAND_FILL);
button_back->show();
} else {
tree->show();
file_list_vb->show();
tree->set_custom_minimum_size(Size2(0,200)*EDSCALE);
tree->set_v_size_flags(SIZE_FILL);
button_back->hide();
if (!EditorFileSystem::get_singleton()->is_scanning()) {
_fs_changed();
}
}
}
} break;
case NOTIFICATION_ENTER_TREE: {
if (initialized)
return;
initialized=true;
EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"_fs_changed");
EditorResourcePreview::get_singleton()->connect("preview_invalidated",this,"_preview_invalidated");
button_reload->set_icon( get_icon("Reload","EditorIcons"));
button_favorite->set_icon( get_icon("Favorites","EditorIcons"));
//button_instance->set_icon( get_icon("Add","EditorIcons"));
//button_open->set_icon( get_icon("Folder","EditorIcons"));
button_back->set_icon( get_icon("Filesystem","EditorIcons"));
if (display_mode == DISPLAY_THUMBNAILS) {
button_display_mode->set_icon(get_icon("FileList","EditorIcons"));
} else {
button_display_mode->set_icon(get_icon("FileThumbnail","EditorIcons"));
}
button_display_mode->connect("pressed",this,"_change_file_display");
//file_options->set_icon( get_icon("Tools","EditorIcons"));
files->connect("item_activated",this,"_select_file");
button_hist_next->connect("pressed",this,"_fw_history");
button_hist_prev->connect("pressed",this,"_bw_history");
search_icon->set_texture( get_icon("Zoom","EditorIcons"));
button_hist_next->set_icon( get_icon("Forward","EditorIcons"));
button_hist_prev->set_icon( get_icon("Back","EditorIcons"));
file_options->connect("item_pressed",this,"_file_option");
button_back->connect("pressed",this,"_go_to_tree",varray(),CONNECT_DEFERRED);
current_path->connect("text_entered",this,"_go_to_dir");
_update_tree(); //maybe it finished already
if (EditorFileSystem::get_singleton()->is_scanning()) {
_set_scannig_mode();
}
} break;
case NOTIFICATION_PROCESS: {
if (EditorFileSystem::get_singleton()->is_scanning()) {
scanning_progress->set_val(EditorFileSystem::get_singleton()->get_scanning_progress()*100);
}
} break;
case NOTIFICATION_EXIT_TREE: {
} break;
case NOTIFICATION_DRAG_BEGIN: {
Dictionary dd = get_viewport()->gui_get_drag_data();
if (tree->is_visible() && dd.has("type") ) {
if ( (String(dd["type"])=="files") || (String(dd["type"])=="files_and_dirs") || (String(dd["type"])=="resource")) {
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
}
if ( (String(dd["type"])=="favorite") ) {
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
}
}
} break;
case NOTIFICATION_DRAG_END: {
tree->set_drop_mode_flags(0);
//.........这里部分代码省略.........
示例11: godot_dictionary_clear
void GDAPI godot_dictionary_clear(godot_dictionary *p_self) {
Dictionary *self = (Dictionary *)p_self;
self->clear();
}
示例12: close
bool Tokenizer<N, P>::open(const Param ¶m) {
close();
const std::string prefix = param.template get<std::string>("dicdir");
CHECK_FALSE(unkdic_.open(create_filename
(prefix, UNK_DIC_FILE).c_str()))
<< unkdic_.what();
CHECK_FALSE(property_.open(param)) << property_.what();
Dictionary *sysdic = new Dictionary;
CHECK_FALSE(sysdic->open
(create_filename(prefix, SYS_DIC_FILE).c_str()))
<< sysdic->what();
CHECK_FALSE(sysdic->type() == 0)
<< "not a system dictionary: " << prefix;
property_.set_charset(sysdic->charset());
dic_.push_back(sysdic);
const std::string userdic = param.template get<std::string>("userdic");
if (!userdic.empty()) {
scoped_fixed_array<char, BUF_SIZE> buf;
scoped_fixed_array<char *, BUF_SIZE> dicfile;
std::strncpy(buf.get(), userdic.c_str(), buf.size());
const size_t n = tokenizeCSV(buf.get(), dicfile.get(), dicfile.size());
for (size_t i = 0; i < n; ++i) {
Dictionary *d = new Dictionary;
CHECK_FALSE(d->open(dicfile[i])) << d->what();
CHECK_FALSE(d->type() == 1)
<< "not a user dictionary: " << dicfile[i];
CHECK_FALSE(sysdic->isCompatible(*d))
<< "incompatible dictionary: " << dicfile[i];
dic_.push_back(d);
}
}
dictionary_info_ = 0;
dictionary_info_freelist_.free();
for (int i = static_cast<int>(dic_.size() - 1); i >= 0; --i) {
DictionaryInfo *d = dictionary_info_freelist_.alloc();
d->next = dictionary_info_;
d->filename = dic_[i]->filename();
d->charset = dic_[i]->charset();
d->size = dic_[i]->size();
d->lsize = dic_[i]->lsize();
d->rsize = dic_[i]->rsize();
d->type = dic_[i]->type();
d->version = dic_[i]->version();
dictionary_info_ = d;
}
unk_tokens_.clear();
for (size_t i = 0; i < property_.size(); ++i) {
const char *key = property_.name(i);
const Dictionary::result_type n = unkdic_.exactMatchSearch(key);
CHECK_FALSE(n.value != -1) << "cannot find UNK category: " << key;
const Token *token = unkdic_.token(n);
size_t size = unkdic_.token_size(n);
unk_tokens_.push_back(std::make_pair(token, size));
}
space_ = property_.getCharInfo(0x20); // ad-hoc
bos_feature_.reset_string(param.template get<std::string>("bos-feature"));
const std::string tmp = param.template get<std::string>("unk-feature");
unk_feature_.reset(0);
if (!tmp.empty()) {
unk_feature_.reset_string(tmp);
}
CHECK_FALSE(*bos_feature_ != '\0')
<< "bos-feature is undefined in dicrc";
max_grouping_size_ = param.template get<size_t>("max-grouping-size");
if (max_grouping_size_ == 0) {
max_grouping_size_ = DEFAULT_MAX_GROUPING_SIZE;
}
return true;
}
示例13: update
void WordsWithTotalChoices::update(Dictionary const& dictionary, Word const guess)
{
choices_.push_back(guess);
count_ += dictionary.anagramCount(guess);
}
示例14: _variant_to_jvalue
jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant* p_arg, bool force_jobject = false) {
jvalret v;
switch(p_type) {
case Variant::BOOL: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Boolean");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(Z)V");
jvalue val;
val.z = (bool)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.val.l = obj;
v.obj=obj;
env->DeleteLocalRef(bclass);
} else {
v.val.z=*p_arg;
};
} break;
case Variant::INT: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Integer");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(I)V");
jvalue val;
val.i = (int)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.val.l = obj;
v.obj=obj;
env->DeleteLocalRef(bclass);
} else {
v.val.i=*p_arg;
};
} break;
case Variant::REAL: {
if (force_jobject) {
jclass bclass = env->FindClass("java/lang/Double");
jmethodID ctor = env->GetMethodID(bclass, "<init>", "(D)V");
jvalue val;
val.d = (double)(*p_arg);
jobject obj = env->NewObjectA(bclass, ctor, &val);
v.val.l = obj;
v.obj=obj;
env->DeleteLocalRef(bclass);
} else {
v.val.f=*p_arg;
};
} break;
case Variant::STRING: {
String s = *p_arg;
jstring jStr = env->NewStringUTF(s.utf8().get_data());
v.val.l=jStr;
v.obj=jStr;
} break;
case Variant::STRING_ARRAY: {
DVector<String> sarray = *p_arg;
jobjectArray arr = env->NewObjectArray(sarray.size(),env->FindClass("java/lang/String"),env->NewStringUTF(""));
for(int j=0;j<sarray.size();j++) {
jstring str = env->NewStringUTF( sarray[j].utf8().get_data() );
env->SetObjectArrayElement(arr,j,str);
env->DeleteLocalRef(str);
}
v.val.l=arr;
v.obj=arr;
} break;
case Variant::DICTIONARY: {
Dictionary dict = *p_arg;
jclass dclass = env->FindClass("org/godotengine/godot/Dictionary");
jmethodID ctor = env->GetMethodID(dclass, "<init>", "()V");
jobject jdict = env->NewObject(dclass, ctor);
Array keys = dict.keys();
jobjectArray jkeys = env->NewObjectArray(keys.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
for (int j=0; j<keys.size(); j++) {
jstring str = env->NewStringUTF(String(keys[j]).utf8().get_data());
env->SetObjectArrayElement(jkeys, j, str);
env->DeleteLocalRef(str);
};
jmethodID set_keys = env->GetMethodID(dclass, "set_keys", "([Ljava/lang/String;)V");
jvalue val;
val.l = jkeys;
env->CallVoidMethodA(jdict, set_keys, &val);
//.........这里部分代码省略.........
示例15: show
bool GameOverScene::initDict(cocos2d::CCDictionary *dic)
{
ThirdPartyHelper::setAd(SET_AD_SHOW);
godelay = 0;
Size vs = Director::getInstance()->getVisibleSize();
Vec2 vo = Director::getInstance()->getVisibleOrigin();
int step = ((CCInteger*)dic->objectForKey("step"))->getValue();
int level = ((CCInteger*)dic->objectForKey("level"))->getValue();
UserDefault::getInstance()->setBoolForKey(StringUtils::format("level%d_lock",level+1).c_str(), false);
UserDefault::getInstance()->flush();
auto gameover = ui::Text::create(StringUtils::format("Level %d Pass!",level+1), Common_Font, 70);
gameover->setPosition(Vec2(vs.width/2, vs.height/3*2 + vo.y));
gameover->setColor(Color3B::BLACK);
this->addChild(gameover);
show(gameover);
int best = UserDefault::getInstance()->getIntegerForKey(StringUtils::format("level%d_step",level).c_str(), INT16_MAX);
if (step<best) {
best = step;
UserDefault::getInstance()->setIntegerForKey(StringUtils::format("level%d_step",level).c_str(), best);
}
auto scorelabel = ui::Text::create(StringUtils::format("Step:%d",step), Common_Font, 50);
scorelabel->setPosition(Vec2(vs.width/2, vs.height/2+scorelabel->getContentSize().height/2 + vo.y));
scorelabel->setColor(Color3B::BLACK);
this->addChild(scorelabel);
show(scorelabel);
auto bestlabel = ui::Text::create(StringUtils::format("Best:%d",best), Common_Font, 50);
bestlabel->setPosition(Vec2(vs.width/2, vs.height/2-bestlabel->getContentSize().height/2 + vo.y));
bestlabel->setColor(Color3B::BLACK);
this->addChild(bestlabel);
show(bestlabel);
float by = vs.height/6 + vo.y;
float fs = 40;
if (level >= LVCOUNT-1) {
}else{
auto replay = ui::Button::create("rb.png");
replay->setTitleText("Next");
replay->setTitleFontSize(fs);
replay->setPosition(Vec2(vs.width/2, vs.height/3 + vo.y));
replay->addTouchEventListener([level](Ref *ps,ui::Widget::TouchEventType type){
if (type == ui::Widget::TouchEventType::ENDED) {
Dictionary *dict = Dictionary::create();
dict->setObject(CCInteger::create(level+1),"level");
Director::getInstance()->replaceScene(PlayScene::createScene(dict));
}
});
this->addChild(replay);
show(replay);
}
auto back = ui::Button::create("rr.png");
back->setPosition(Vec2(vs.width/3, by));
back->setTitleFontSize(fs);
back->setTitleText("Back");
back->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){
if (type == ui::Widget::TouchEventType::ENDED) {
Director::getInstance()->replaceScene(HelloWorld::createScene());
}
});
this->addChild(back);
show(back);
auto share = LHShareButton::defaultButton("rr.png","Lucky Puzzle!");
share->setTitleFontSize(fs);
share->setTitleText("Share");
share->setPosition(Vec2(vs.width/3*2, by));
this->addChild(share);
show(share);
return true;
}