void ttitle_screen::update_tip(twindow& window, const bool previous) { next_tip_of_day(tips_, previous); const config *tip = get_tip_of_day(tips_); assert(tip); find_widget<tlabel>(&window, "tip", false).set_label((*tip)["text"]); find_widget<tlabel>(&window, "source", false).set_label((*tip)["source"]); /** * @todo Convert the code to use a multi_page so the invalidate is not * needed. */ window.invalidate_layout(); }
/** Return the text for one of the tips-of-the-day. */ static const config* get_tip_of_day(config& tips_of_day) { if (tips_of_day.empty()) { read_tips_of_day(tips_of_day); } const config::child_list& tips = tips_of_day.get_children("tip"); // next_tip_of_day rotate tips, so better stay iterator-safe for (size_t t=0; t < tips.size(); t++, next_tip_of_day(tips_of_day)) { const config* tip = tips.front(); if (tip == NULL) continue; const std::vector<shared_string> needed_units = utils::split_shared((*tip)["encountered_units"],','); if (needed_units.empty()) { return tip; } const std::set<shared_string>& seen_units = preferences::encountered_units(); // test if one of the listed unit types is already encountered // if if's a number, test if we have encountered more than this for (std::vector<shared_string>::const_iterator i = needed_units.begin(); i != needed_units.end(); i++) { int needed_units_nb = lexical_cast_default<int>(*i,-1); if (needed_units_nb !=-1) { if (needed_units_nb <= static_cast<int>(seen_units.size())) { return tip; } } else if (seen_units.find(*i) != seen_units.end()) { return tip; } } } // not tip match, someone forget to put an always-match one return NULL; }
loadscreen::loadscreen(CVideo &screen, const int &percent): filesystem_counter(0), setconfig_counter(0), parser_counter(0), disable_increments(false), screen_(screen), textarea_(), logo_surface_(NULL), logo_drawn_(false), pby_offset_(0), prcnt_(percent) { // int randNum = (rand() % 8) + 1; int randNum = (rand() % 11) + 1; // MG ZZZ char num[3]; sprintf(num, "%d", randNum); std::string file = "misc/loading"; file.append(1, num[0]); file += ".pvrtc"; std::string path = game_config::path + "/data/core/images/" + file; #ifdef __IPAD__ int pvrtcSize = 1024; #else int pvrtcSize = 512; #endif GLsizei dataSize = (pvrtcSize * pvrtcSize * 4) / 8; FILE *fp = fopen(path.c_str(), "rb"); if (!fp) { std::cerr << "\n\n*** ERROR loading loadscreen " << path.c_str() << "\n\n"; return; } unsigned char *data = (unsigned char*) malloc(dataSize); int bytesRead = fread(data, 1, dataSize, fp); // assert(bytesRead == dataSize); // ZZZ fclose(fp); glGenTextures(1, &logo_texture_); //glBindTexture(GL_TEXTURE_2D, logo_texture_); cacheBindTexture(GL_TEXTURE_2D, logo_texture_, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, pvrtcSize, pvrtcSize, 0, dataSize, data); #ifndef NDEBUG GLenum err = glGetError(); if (err != GL_NO_ERROR) { char buffer[512]; sprintf(buffer, "\n\n*** ERROR uploading compressed texture %s: glError: 0x%04X\n\n", path.c_str(), err); std::cerr << buffer; } #endif free(data); textarea_.x = textarea_.y = textarea_.w = textarea_.h = 0; next_tip_of_day(tips_of_day); }