int main(int argc, char const *argv[]) { list_t *list = (list_t*)malloc(sizeof (list_t)); init(list); //make a node add_at(list, (void*)2, 0); assert(list->head && list->tail); assert((int) get(list, 0) == 2); //do more adding int i = 3; for(; i < 15; ++i){ add_front(list, (void*)i); assert(list->head && list->tail); assert((int) get(list, 0) == i); } assert((int) get(list, list->size - 1) == 2); assert((int) fold_left(list, add_list, (void*)0) == 104); assert((int) fold_left(list, add_list, (void*)0) == (int)fold_right(list, add_list, (void*)0)); add_back(list, (void*)0); assert(list->tail->data == (void*)0); assert((int) get(list, list->size - 1) == 0); add_front(list, (void*)2); add_front(list, (void*)2); assert((int) fold_left(list, count_2, (void*)0) == 3); remove_data(list, (void*)2, is_2); return 0; }
EditorSectorMenu::EditorSectorMenu() : sector(Editor::current()->currentsector), sector_name_ptr(sector->get_name_ptr()), original_name(*sector_name_ptr), size(sector->get_editor_size()), new_size(size) { add_label(_("Sector") + " " + sector->get_name()); add_hl(); add_textfield(_("Name"), sector_name_ptr); add_script(_("Initialization script"), sector->get_init_script_ptr()); add_color(_("Ambient light"), sector->get_ambient_light_ptr()); add_numfield(_("Gravity"), §or->gravity); std::vector<std::string> music_formats; music_formats.push_back(".ogg"); music_formats.push_back(".music"); add_file(_("Music"), §or->music, music_formats); add_hl(); add_intfield(_("Width"), &(new_size.width)); add_intfield(_("Height"), &(new_size.height)); add_entry(MNID_RESIZESECTOR, _("Resize")); add_hl(); add_back(_("OK")); }
void cmd_path(char modifier, char *path) { if (path) { path[strlen(path)-1] = '\0'; if (path[strlen(path)-1] == '/') { path[strlen(path)-1] = '\0'; } } if (modifier == '+') { char *new_path = strdup(path); if (!new_path) { fprintf(stderr, "error: could not allocate memory to add path, %s\n", strerror(errno)); } add_back(&PATH, new_path); } else if (modifier == '-') { //remove all matches with path from list. remove_all_str(&PATH, path); } else { struct Node *curr = PATH.head; while (curr) { printf("%s", (char *)curr->data); if (curr != PATH.tail_node) { printf(":"); } curr = curr->next; } printf("\n"); } }
KeyboardMenu::KeyboardMenu(InputManager& input_manager) : m_input_manager(input_manager) { add_label(_("Setup Keyboard")); add_hl(); add_controlfield(Controller::UP, _("Up")); add_controlfield(Controller::DOWN, _("Down")); add_controlfield(Controller::LEFT, _("Left")); add_controlfield(Controller::RIGHT, _("Right")); add_controlfield(Controller::JUMP, _("Jump")); add_controlfield(Controller::ACTION, _("Action")); add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); add_controlfield(Controller::PEEK_UP, _("Peek Up")); add_controlfield(Controller::PEEK_DOWN, _("Peek Down")); if (g_config->developer_mode || g_config->console_enabled) { add_controlfield(Controller::CONSOLE, _("Console")); } if (g_config->developer_mode) { add_controlfield(Controller::CHEAT_MENU, _("Cheat Menu")); } add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), &g_config->keyboard_config.jump_with_up_kbd); add_hl(); add_back(_("Back")); refresh(); }
KeyboardMenu::KeyboardMenu(InputManager& input_manager) : m_input_manager(input_manager) { add_label(_("Setup Keyboard")); add_hl(); add_controlfield(Controller::UP, _("Up")); add_controlfield(Controller::DOWN, _("Down")); add_controlfield(Controller::LEFT, _("Left")); add_controlfield(Controller::RIGHT, _("Right")); add_controlfield(Controller::JUMP, _("Jump")); add_controlfield(Controller::ACTION, _("Action")); add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); add_controlfield(Controller::PEEK_UP, _("Peek Up")); add_controlfield(Controller::PEEK_DOWN, _("Peek Down")); if (g_config->developer_mode) { add_controlfield(Controller::CONSOLE, _("Console")); } if (g_config->developer_mode) { add_controlfield(Controller::CHEAT_MENU, _("Cheat Menu")); } add_hl(); add_inactive(_("The following feature is deprecated.")); // l10n: Continuation of string "The following feature is deprecated." add_inactive(_("It will be removed from the next release")); // l10n: Continuation of string "It will be removed from the next release" add_inactive(_("of SuperTux.")); add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), &g_config->keyboard_config.jump_with_up_kbd); add_hl(); add_back(_("Back")); refresh(); }
void JoystickMenu::recreate_menu() { clear(); add_label(_("Setup Joystick")); add_hl(); add_toggle(MNID_AUTO_JOYSTICK_CFG, _("Manual Configuration"), &m_auto_joystick_cfg) .set_help(_("Use manual configuration instead of SDL2's automatic GameController support")); if (m_input_manager.use_game_controller()) { m_joysticks_available = false; } else { if (m_input_manager.joystick_manager->get_num_joysticks() > 0) { m_joysticks_available = true; add_controlfield(static_cast<int>(Control::UP), _("Up")); add_controlfield(static_cast<int>(Control::DOWN), _("Down")); add_controlfield(static_cast<int>(Control::LEFT), _("Left")); add_controlfield(static_cast<int>(Control::RIGHT), _("Right")); add_controlfield(static_cast<int>(Control::JUMP), _("Jump")); add_controlfield(static_cast<int>(Control::ACTION), _("Action")); add_controlfield(static_cast<int>(Control::START), _("Pause/Menu")); add_controlfield(static_cast<int>(Control::PEEK_LEFT), _("Peek Left")); add_controlfield(static_cast<int>(Control::PEEK_RIGHT), _("Peek Right")); add_controlfield(static_cast<int>(Control::PEEK_UP), _("Peek Up")); add_controlfield(static_cast<int>(Control::PEEK_DOWN), _("Peek Down")); if (g_config->developer_mode) { add_controlfield(static_cast<int>(Control::CONSOLE), _("Console")); } if (g_config->developer_mode) { add_controlfield(static_cast<int>(Control::CHEAT_MENU), _("Cheat Menu")); add_controlfield(static_cast<int>(Control::DEBUG_MENU), _("Debug Menu")); } add_toggle(MNID_JUMP_WITH_UP, _("Jump with Up"), &g_config->joystick_config.m_jump_with_up_joy); } else { m_joysticks_available = false; add_inactive(_("No Joysticks found")); add_entry(MNID_SCAN_JOYSTICKS, _("Scan for Joysticks")); } } add_hl(); add_back(_("Back")); refresh(); }
OptionsMenu::OptionsMenu() { add_label(_("Options")); add_hl(); add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen); add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled); add_toggle(MNID_MUSIC, _("Music"), config->music_enabled); add_submenu(_("Setup Keys"), main_controller->get_key_options_menu()); add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu()); add_hl(); add_back(_("Back")); }
/************************ * FUNCTION DEFINITIONS * ************************/ struct Token *make_token(char *token_string, char mod) { struct Token *token; struct SLList *args; if (!(token = (struct Token *)malloc(sizeof(struct Token)))) { fprintf(stderr, "error: %s\n", strerror(errno)); } if (!(args = (struct SLList *)malloc(sizeof(struct SLList)))) { fprintf(stderr, "error: %s\n", strerror(errno)); } init_token(token); init_list(args); //extract the necessary data from the command token string. char *working_token_string = strdup(token_string); if (!working_token_string) { fprintf(stderr, "error: could not allocate memory for token string, %s\n", strerror(errno)); } char *token_part = strtok(working_token_string, " "); char *token_part_dyn = malloc(strlen(token_part)+1); strcpy(token_part_dyn, token_part); token->name = token_part_dyn; do { add_back(args, token_part_dyn); token_part = strtok(NULL, " "); if (token_part) { token_part_dyn = malloc(strlen(token_part)+1); strcpy(token_part_dyn, token_part); } } while (token_part); free(working_token_string); token->args = args; //assign correct modifier indicator based on mod character. if (mod == '|') { token->mod = PIPE; } else if (mod == '>') { token->mod = OUTPUT_REDIR; } else if (mod == 'e') { token->mod = ERR_OUTPUT_REDIR; } else if (mod == '<') { token->mod = INPUT_REDIR; } else { token->mod = NO_MODIFIER; } return token; }
void EditorLevelsetMenu::initialize() { levelset_type = world->m_is_levelset ? 1 : 0; add_label(_("Level subset properties")); add_hl(); add_textfield(_("Name"), &(world->m_title)); add_textfield(_("Description"), &(world->m_description)); add_string_select(1, _("Type"), &levelset_type, {_("Worldmap"), _("Levelset")}); add_hl(); add_back(_("OK")); }
ColorMenu::ColorMenu(Color* color_) : color(color_) { add_label(_("Mix the colour")); add_hl(); add_colorchannel( &(color->red), Color(1.0f, 0.0f, 0.0f)); add_colorchannel( &(color->green), Color(0.0f, 1.0f, 0.0f)); add_colorchannel( &(color->blue), Color(0.0f, 0.0f, 1.0f)); add_colorchannel( &(color->alpha), Color(0.0f, 0.0f, 0.0f)); add_colordisplay(color); add_hl(); add_back(_("OK")); }
// Divide two digit strings. Divides r by y/yl. Stores quotient in // q/ql and leaves the remainder in r. Size of r is yl+ql. static _fast void digit_div(onedig_t *r, const onedig_t *y, unsigned yl, onedig_t *q, unsigned ql) { r += ql; for (int i = ql; --r, --i >= 0;) { onedig_t qh = guess_q(r + yl, y + yl - 1); if (multiply_and_subtract(r, y, yl, qh) == 0) { --qh; add_back(r, y, yl); } if (q != 0) q[i] = qh; } }
/* * Parses and keeps a list of commands with pointers to their arguments * and then carries out the requested actions. Returns 0 on success. */ int process_input(char *input) { struct SLList tokens; init_list(&tokens); char *input_current_start = input; const char special_delims[] = "<>|"; // break up tokens into the list and collect argument lists for them. do { int token_str_length = strcspn(input_current_start, special_delims); char *tmp_token_string = (char *)malloc(token_str_length+1); if (!tmp_token_string) { fprintf(stderr, "error: could not allocate memory to process token, %s\n", strerror(errno)); return -1; } strncpy(tmp_token_string, input_current_start, token_str_length); // if this is the last token, replace the ending '\n' before adding to list. if (tmp_token_string[token_str_length-1] == '\n') { tmp_token_string[token_str_length-1] = '\0'; } else { tmp_token_string[token_str_length] = '\0'; } char modifier = input_current_start[token_str_length]; if (input_current_start[token_str_length-1] == '2' && input_current_start[token_str_length] == '>') { modifier = 'e'; tmp_token_string[token_str_length-1] = '\0'; } add_back(&tokens, make_token(tmp_token_string, modifier)); input_current_start += token_str_length+1; free(tmp_token_string); } while (*(input_current_start-2) != '\n'); // carry out the instructions formed by the tokens. //traverse(&tokens, (void *)evaluate); evaluate(&tokens); // TODO: add any necessary clean up. return 0; }
LanguageMenu::LanguageMenu() { add_label(_("Language")); add_hl(); add_entry(MNID_LANGUAGE_AUTO_DETECT, _("<auto-detect>")); add_entry(MNID_LANGUAGE_ENGLISH, "English"); int mnid = MNID_LANGUAGE_NEXT; std::set<tinygettext::Language> languages = dictionary_manager->get_languages(); for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++) { add_entry(mnid++, i->get_name()); } add_hl(); add_back(_("Back")); }
void EditorLevelsetMenu::initialize() { add_label(_("Level subset properties")); add_hl(); add_textfield(_("Name"), &(world->m_title)); add_textfield(_("Description"), &(world->m_description)); std::string worldmap_file = FileSystem::join(world->get_basedir(), "worldmap.stwm"); if (PHYSFS_exists(worldmap_file.c_str())) { add_toggle(-1, _("Do not use worldmap"), &(world->m_is_levelset)); add_entry(MNID_EDITWORLDMAP, _("Edit worldmap")); } else { add_entry(MNID_NEWWORLDMAP, _("Create worldmap")); } add_hl(); add_back(_("OK")); }
void BadguySelectMenu::refresh_menu() { items.clear(); add_label(_("List of enemies")); add_hl(); add_string_select(-2, _("Enemy"), &selected, all_badguys); add_entry(-3, _("Add")); add_hl(); int i = 0; for (auto& badguy : *badguys) { add_entry(i, badguy); i++; } add_hl(); add_back(_("OK")); }
EditorLevelMenu::EditorLevelMenu() : old_tileset(Editor::current()->get_level()->m_tileset) { bool worldmap = Editor::current()->get_worldmap_mode(); auto level = Editor::current()->get_level(); add_label(worldmap ? _("Worldmap properties") :_("Level properties")); add_hl(); add_textfield(_("Name"), &(level->m_name)); add_textfield(_("Author"), &(level->m_author)); add_textfield(_("Contact"), &(level->m_contact)); add_textfield(_("License"), &(level->m_license)); add_file(_("Tileset"), &(level->m_tileset), std::vector<std::string>(1, ".strf")); if (!worldmap) { add_numfield(_("Target time"), &(level->m_target_time)); } add_hl(); add_back(_("OK")); }
CheatMenu::CheatMenu() { std::vector<Player*> players = Sector::get().get_players(); auto player = players.empty() ? nullptr : players[0]; add_label(_("Cheats")); add_hl(); add_entry(MNID_GROW, _("Bonus: Grow")); add_entry(MNID_FIRE, _("Bonus: Fire")); add_entry(MNID_ICE, _("Bonus: Ice")); add_entry(MNID_AIR, _("Bonus: Air")); add_entry(MNID_EARTH, _("Bonus: Earth")); add_entry(MNID_STAR, _("Bonus: Star")); add_entry(MNID_SHRINK, _("Shrink Tux")); add_entry(MNID_KILL, _("Kill Tux")); add_entry(MNID_FINISH, _("Finish Level")); add_entry(MNID_GHOST, (player != nullptr && player->get_ghost_mode()) ? _("Leave Ghost Mode") : _("Activate Ghost Mode")); add_hl(); add_back(_("Back")); }
void EditorLevelSelectMenu::initialize() { auto editor = Editor::current(); auto basedir = m_world->get_basedir(); editor->deactivate_request = true; m_levelset = std::unique_ptr<Levelset>(new Levelset(basedir)); add_label(m_world->get_title()); add_hl(); for (int i = 0; i < m_levelset->get_num_levels(); ++i) { std::string filename = m_levelset->get_level_filename(i); std::string full_filename = FileSystem::join(basedir, filename); std::string title = GameManager::current()->get_level_name(full_filename); add_entry(i, title); } add_hl(); add_entry(-1, _("Create Level")); add_entry(-3, _("Level subset properties")); add_back(_("Back"),-2); }
ContribLevelsetMenu::ContribLevelsetMenu(std::unique_ptr<World> world) : m_world(std::move(world)), m_levelset() { assert(m_world->is_levelset()); m_levelset = std::unique_ptr<Levelset>(new Levelset(m_world->get_basedir())); auto savegame = Savegame::from_file(m_world->get_savegame_filename()); LevelsetState state = savegame->get_levelset_state(m_world->get_basedir()); add_label(m_world->get_title()); add_hl(); for (int i = 0; i < m_levelset->get_num_levels(); ++i) { std::string filename = m_levelset->get_level_filename(i); std::string full_filename = FileSystem::join(m_world->get_basedir(), filename); std::string title = LevelParser::get_level_name(full_filename); LevelState level_state = state.get_level_state(filename); std::ostringstream out; if (level_state.solved) { out << title << " [*]"; } else { out << title << " [ ]"; } add_entry(i, out.str()); } add_hl(); add_back(_("Back")); }
int main(void) { llist* list = create_list(); lnode* new_node; lnode* found_node; point* p = create_point(0, 0); list->head = NULL; /* test case 1 - what does an empty list contain? */ printf("TEST CASE 1\n"); traverse(list, print_point_node); printf("\n"); /* test case 2 - what happens when you add a node to the front of an empty list? */ printf("TEST CASE 2\n"); new_node = create_node(create_point(2,5)); add_front(list, new_node); traverse(list, print_point_node); printf("\n"); /* test case 3 - what happens when you add a node to the front of a list with one node? */ printf("TEST CASE 3\n"); new_node = create_node(create_point(3,7)); add_front(list, new_node); traverse(list, print_point_node); printf("\n"); /* test case 4 - what happens when you add a node to the front of a list with more than one node? */ printf("TEST CASE 4\n"); new_node = create_node(create_point(1,4)); add_front(list, new_node); traverse(list, print_point_node); printf("\n"); /* test case 5 - what happens when you remove a node from the front of a list with more than one node? */ printf("TEST CASE 5\n"); remove_front(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 6 - what happens when you remove a node from the front of a list with one node? */ printf("TEST CASE 6\n"); remove_front(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 7 - what happens when you remove a node from the front of an empty list? */ printf("TEST CASE 7\n"); remove_front(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 8 - what happens when you add a node to the back of an empty list? */ printf("TEST CASE 8\n"); new_node = create_node(create_point(2,5)); add_back(list, new_node); traverse(list, print_point_node); printf("\n"); /* test case 9 - what happens when you add a node to the back of a list with one node? */ printf("TEST CASE 9\n"); new_node = create_node(create_point(3,7)); add_back(list, new_node); traverse(list, print_point_node); printf("\n"); /* test case 10 - what happens when you add a node to the back of a list with more than one node? */ printf("TEST CASE 10\n"); new_node = create_node(create_point(1,4)); add_back(list, new_node); traverse(list, print_point_node); printf("\n"); /* test case 11 - what happens when you remove a node from the back of a list with more than one node? */ printf("TEST CASE 11\n"); remove_back(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 12 - what happens when you remove a node from the back of a list with one node? */ printf("TEST CASE 12\n"); remove_back(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 13 - what happens when you remove a node from the back of an empty list? */ printf("TEST CASE 13\n"); remove_back(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 14 - what happens when you try to find an occurrence of a given data point in an empty list? */ printf("TEST CASE 14\n"); p->x = 3; p->y = 7; found_node = find_occurrence(list, p, compare_point_data); print_point_node(found_node); printf("\n"); /* test case 15 - what happens when you try to find an occurrence of a given data point in a list of that one node? */ printf("TEST CASE 15\n"); p->x = 3; p->y = 7; new_node = create_node(create_point(3, 7)); add_front(list, new_node); found_node = find_occurrence(list, p, compare_point_data); print_point_node(found_node); printf("\n"); /* test case 16 - what happens when you try to find an occurrence of a given data point in a list of one different node? */ printf("TEST CASE 16\n"); p->x = 5; p->y = 14; found_node = find_occurrence(list, p, compare_point_data); print_point_node(found_node); printf("\n"); /* test case 17 - what happens when you try to find an occurrence of a given data point in a list of lots of nodes (one matching)? NOTE: if your list contains multiple nodes with matching data, returning any of them is fine. */ printf("TEST CASE 17\n"); new_node = create_node(create_point(5,2)); add_front(list, new_node); new_node = create_node(create_point(6,30)); add_back(list, new_node); new_node = create_node(create_point(1,1)); add_front(list, new_node); p->x = 3; p->y = 7; found_node = find_occurrence(list, p, compare_point_data); print_point_node(found_node); printf("\n"); /* test case 18 - what happens when you try to find an occurrence of a given data point in a list of lots of nodes (none matching)? */ printf("TEST CASE 18\n"); p->x = 5; p->y = 14; found_node = find_occurrence(list, p, compare_point_data); print_point_node(found_node); printf("\n"); /* test case 19 - what happens when you try to free a list of lots of nodes? YOU WILL HAVE TO RUN VALGRIND TO MAKE SURE YOU GET NO ERRORS HERE. Memory leaks are otherwise invisible! */ printf("TEST CASE 19\n"); free_list(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 20 - what happens when you try to free a list of one node? YOU WILL HAVE TO RUN VALGRIND TO MAKE SURE YOU GET NO ERRORS HERE. */ printf("TEST CASE 20\n"); new_node = create_node(create_point(7,14)); add_front(list, new_node); free_list(list, free_point_node); traverse(list, print_point_node); printf("\n"); /* test case 21 - what happens when you try to free an empty list? YOU WILL HAVE TO RUN VALGRIND TO MAKE SURE YOU GET NO ERRORS HERE. */ printf("TEST CASE 21\n"); free_list(list, free_point_node); traverse(list, print_point_node); printf("\n"); free(p); free(list); return 0; }
void AddonMenu::refresh() { clear(); AddonManager& adm = AddonManager::get_instance(); // refresh list of addons m_addons = adm.get_addons(); // sort list std::sort(m_addons.begin(), m_addons.end(), generate_addons_menu_sorter); add_label(_("Add-ons")); add_hl(); // FIXME: don't use macro, use AddonManager::online_available() or so #ifdef HAVE_LIBCURL add_entry(0, std::string(_("Check Online"))); #else add_inactive(0, std::string(_("Check Online (disabled)"))); #endif //add_hl(); for (unsigned int i = 0; i < m_addons.size(); i++) { const Addon& addon = *m_addons[i]; std::string text = ""; if (!addon.kind.empty()) { std::string kind = addon.kind; if(addon.kind == "Levelset") { kind = _("Levelset"); } else if(addon.kind == "Worldmap") { kind = _("Worldmap"); } else if(addon.kind == "World") { kind = _("World"); } else if(addon.kind == "Level") { kind = _("Level"); } if(!addon.author.empty()) { text = str(boost::format(_("%s \"%s\" by \"%s\"")) % kind % addon.title % addon.author); } else { // Only addon type and name, no need for translation. text = str(boost::format("%s \"%s\"") % kind % addon.title); } } else { if (!addon.author.empty()) { text = str(boost::format(_("\"%s\" by \"%s\"")) % addon.title % addon.author); } else { // Only addon name, no need for translation. text = str(boost::format("\"%s\"") % addon.title); } } add_toggle(ADDON_LIST_START_ID + i, text, addon.loaded); } add_hl(); add_back(_("Back")); }
EditorLevelsetSelectMenu::EditorLevelsetSelectMenu() : m_contrib_worlds() { Editor::current()->deactivate_request = true; // Generating contrib levels list by making use of Level Subset std::vector<std::string> level_worlds; std::unique_ptr<char*, decltype(&PHYSFS_freeList)> files(PHYSFS_enumerateFiles("levels"), PHYSFS_freeList); for(const char* const* filename = files.get(); *filename != 0; ++filename) { std::string filepath = FileSystem::join("levels", *filename); PHYSFS_Stat statbuf; PHYSFS_stat(filepath.c_str(), &statbuf); if(statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY) { level_worlds.push_back(filepath); } } add_label(_("Choose level subset")); add_hl(); int i = 0; for (std::vector<std::string>::const_iterator it = level_worlds.begin(); it != level_worlds.end(); ++it) { try { std::unique_ptr<World> world = World::load(*it); if (!world->hide_from_contribs()) { Savegame savegame(world->get_savegame_filename()); savegame.load(); if (world->is_levelset()) { int level_count = 0; const auto& state = savegame.get_levelset_state(world->get_basedir()); for(const auto& level_state : state.level_states) { if(level_state.filename == "") continue; level_count += 1; } std::ostringstream title; title << "[" << world->get_title() << "]"; if (level_count == 0) { title << " " << _("*NEW*"); } else { title << " (" << level_count << " " << _("levels") << ")"; } add_entry(i++, title.str()); m_contrib_worlds.push_back(std::move(world)); } else if (world->is_worldmap()) { int level_count = 0; const auto& state = savegame.get_worldmap_state(world->get_worldmap_filename()); for(const auto& level_state : state.level_states) { if(level_state.filename == "") continue; level_count += 1; } std::ostringstream title; title << world->get_title(); if (level_count == 0) { title << " " << _("*NEW*"); } else { title << " (" << level_count << " " << _("levels") << ")"; } add_entry(i++, title.str()); m_contrib_worlds.push_back(std::move(world)); } else { log_warning << "unknown World type" << std::endl; } } } catch(std::exception& e) { log_info << "Couldn't parse levelset info for '" << *it << "': " << e.what() << std::endl; } } add_hl(); add_submenu(_("New level subset"), MenuStorage::EDITOR_NEW_LEVELSET_MENU); add_back(_("Back"),-2); }
void FileSystemMenu::refresh_items() { items.clear(); directories.clear(); files.clear(); directory = FileSystem::normalize(directory); add_label(directory); add_hl(); int item_id = 0; // Do not allow leaving the data directory if (directory != "/") { directories.push_back(".."); } char** dir_files = PHYSFS_enumerateFiles(directory.c_str()); if (dir_files) { for(const char* const* file = dir_files; *file != nullptr; ++file) { std::string filepath = FileSystem::join(directory, *file); if(PhysFSFileSystem::is_directory(filepath)) { directories.push_back(*file); } else { if (AddonManager::current()->is_from_old_addon(filepath)) { continue; } if(has_right_suffix(*file)) { files.push_back(*file); } } } PHYSFS_freeList(dir_files); } for(const auto& item : directories) { add_entry(item_id, "[" + std::string(item) + "]"); item_id++; } for(const auto& item : files) { add_entry(item_id, item); item_id++; } add_hl(); add_back(_("Cancel")); active_item = 2; // Re-center menu on_window_resize(); }
void AddonMenu::rebuild_menu() { clear(); add_label(_("Add-ons")); add_hl(); if (m_installed_addons.empty()) { if (!m_repository_addons.empty()) { add_inactive(MNID_NOTHING_NEW, _("No Addons installed")); } else { add_inactive(MNID_NOTHING_NEW, _("No Addons found")); } } else { int idx = 0; for (const auto& addon_id : m_installed_addons) { const Addon& addon = m_addon_manager.get_installed_addon(addon_id); std::string text = generate_menu_item_text(addon); add_toggle(MAKE_INSTALLED_MENU_ID(idx), text, addon.is_enabled()); idx += 1; } } add_hl(); { bool have_new_stuff = false; int idx = 0; for (const auto& addon_id : m_repository_addons) { const Addon& addon = m_addon_manager.get_repository_addon(addon_id); try { // addon is already installed, so check if they are the same Addon& installed_addon = m_addon_manager.get_installed_addon(addon_id); if (installed_addon.get_md5() == addon.get_md5() || installed_addon.get_version() > addon.get_version()) { log_debug << "ignoring already installed addon " << installed_addon.get_id() << std::endl; } else { log_debug << installed_addon.get_id() << " is installed, but updated: '" << installed_addon.get_md5() << "' vs '" << addon.get_md5() << "' '" << installed_addon.get_version() << "' vs '" << addon.get_version() << "'" << std::endl; std::string text = generate_menu_item_text(addon); add_entry(MAKE_REPOSITORY_MENU_ID(idx), str(boost::format( _("Install %s *NEW*") ) % text)); have_new_stuff = true; } } catch(const std::exception& err) { // addon is not installed std::string text = generate_menu_item_text(addon); add_entry(MAKE_REPOSITORY_MENU_ID(idx), str(boost::format( _("Install %s") ) % text)); have_new_stuff = true; } idx += 1; } if (!have_new_stuff && m_addon_manager.has_been_updated()) { add_inactive(MNID_NOTHING_NEW, _("No new Addons found")); } } if (!m_addon_manager.has_online_support()) { add_inactive(MNID_CHECK_ONLINE, std::string(_("Check Online (disabled)"))); } else { add_entry(MNID_CHECK_ONLINE, std::string(_("Check Online"))); } add_hl(); add_back(_("Back")); }
OptionsMenu::OptionsMenu(bool complete) : next_magnification(0), next_aspect_ratio(0), next_resolution(0), magnifications(), aspect_ratios(), resolutions() { add_label(_("Options")); add_hl(); magnifications.clear(); // These values go from screen:640/projection:1600 to // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600) magnifications.push_back(_("auto")); magnifications.push_back("40%"); magnifications.push_back("50%"); magnifications.push_back("62.5%"); magnifications.push_back("80%"); magnifications.push_back("100%"); magnifications.push_back("125%"); magnifications.push_back("160%"); magnifications.push_back("200%"); magnifications.push_back("250%"); // Gets the actual magnification: if (g_config->magnification != 0.0f) //auto { std::ostringstream out; out << (g_config->magnification*100) << "%"; std::string magn = out.str(); size_t count = 0; for (std::vector<std::string>::iterator i = magnifications.begin(); i != magnifications.end(); ++i) { if (*i == magn) { next_magnification = count; magn.clear(); break; } ++count; } if (!magn.empty()) //magnification not in our list but accept anyway { next_magnification = magnifications.size(); magnifications.push_back(magn); } } aspect_ratios.clear(); aspect_ratios.push_back(_("auto")); aspect_ratios.push_back("5:4"); aspect_ratios.push_back("4:3"); aspect_ratios.push_back("16:10"); aspect_ratios.push_back("16:9"); aspect_ratios.push_back("1368:768"); // Gets the actual aspect ratio: if (g_config->aspect_size != Size(0, 0)) //auto { std::ostringstream out; out << g_config->aspect_size.width << ":" << g_config->aspect_size.height; std::string aspect_ratio = out.str(); size_t cnt_ = 0; for(std::vector<std::string>::iterator i = aspect_ratios.begin(); i != aspect_ratios.end(); ++i) { if(*i == aspect_ratio) { aspect_ratio.clear(); next_aspect_ratio = cnt_; break; } ++cnt_; } if (!aspect_ratio.empty()) { next_aspect_ratio = aspect_ratios.size(); aspect_ratios.push_back(aspect_ratio); } } resolutions.clear(); int display_mode_count = SDL_GetNumDisplayModes(0); std::string last_display_mode; for(int i = 0; i < display_mode_count; ++i) { SDL_DisplayMode mode; int ret = SDL_GetDisplayMode(0, i, &mode); if (ret != 0) { log_warning << "failed to get display mode: " << SDL_GetError() << std::endl; } else { std::ostringstream out; out << mode.w << "x" << mode.h; if(mode.refresh_rate) out << "@" << mode.refresh_rate; if(last_display_mode == out.str()) continue; last_display_mode = out.str(); resolutions.insert(resolutions.begin(), out.str()); } } resolutions.push_back("Desktop"); std::string fullscreen_size_str = "Desktop"; { std::ostringstream out; if (g_config->fullscreen_size != Size(0, 0)) { out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height; if (g_config->fullscreen_refresh_rate) out << "@" << g_config->fullscreen_refresh_rate; fullscreen_size_str = out.str(); } } size_t cnt = 0; for (std::vector<std::string>::iterator i = resolutions.begin(); i != resolutions.end(); ++i) { if (*i == fullscreen_size_str) { fullscreen_size_str.clear(); next_resolution = cnt; break; } ++cnt; } if (!fullscreen_size_str.empty()) { next_resolution = resolutions.size(); resolutions.push_back(fullscreen_size_str); } if (complete) { // Language and profile changes are only be possible in the // main menu, since elsewhere it might not always work fully add_submenu(_("Select Language"), MenuStorage::LANGUAGE_MENU) ->set_help(_("Select a different language to display text in")); add_submenu(_("Select Profile"), MenuStorage::PROFILE_MENU) ->set_help(_("Select a profile to play with")); } add_toggle(MNID_FULLSCREEN,_("Fullscreen"), &g_config->use_fullscreen) ->set_help(_("Fill the entire screen")); MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"), &next_resolution, resolutions); fullscreen_res->set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)")); MenuItem* magnification = add_string_select(MNID_MAGNIFICATION, _("Magnification"), &next_magnification, magnifications); magnification->set_help(_("Change the magnification of the game area")); MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"), &next_aspect_ratio, aspect_ratios); aspect->set_help(_("Adjust the aspect ratio")); if (SoundManager::current()->is_audio_enabled()) { add_toggle(MNID_SOUND, _("Sound"), &g_config->sound_enabled) ->set_help(_("Disable all sound effects")); add_toggle(MNID_MUSIC, _("Music"), &g_config->music_enabled) ->set_help(_("Disable all music")); } else { add_inactive( _("Sound (disabled)")); add_inactive( _("Music (disabled)")); } add_submenu(_("Setup Keyboard"), MenuStorage::KEYBOARD_MENU) ->set_help(_("Configure key-action mappings")); add_submenu(_("Setup Joystick"), MenuStorage::JOYSTICK_MENU) ->set_help(_("Configure joystick control-action mappings")); MenuItem* enable_transitions = add_toggle(MNID_TRANSITIONS, _("Enable transitions"), &g_config->transitions_enabled); enable_transitions->set_help(_("Enable screen transitions and smooth menu animation")); if (g_config->developer_mode) { add_toggle(MNID_DEVELOPER_MODE, _("Developer Mode"), &g_config->developer_mode); } if (g_config->is_christmas() || g_config->christmas_mode) { add_toggle(MNID_CHRISTMAS_MODE, _("Christmas Mode"), &g_config->christmas_mode); } add_hl(); add_back(_("Back")); }
void add_header(Header* _header) { add_back(_header); }
int evaluate(struct SLList *tokens) { struct SLList cmds; init_list(&cmds); IOModifier prev_mod = NO_MODIFIER; struct ExecutableCmd *exe = (struct ExecutableCmd *)malloc(sizeof(struct ExecutableCmd)); init_executable_cmd(exe); while (tokens->length != 0) { struct Token *tok = pop_front(tokens); // check for output redirection conflicts here. if ( prev_mod == PIPE ) { if (exe->output_redir_to) { // conflict // dump the token and cmd lists. destroy_token(tok); while ( (tok = pop_front(tokens)) ) destroy_token(tok); destroy_exe_cmd(exe); destroy_cmd_list(&cmds); fprintf(stderr, "error: syntax error in output redirection.\n"); return -1; } add_back(&cmds, exe); exe = (struct ExecutableCmd *)malloc(sizeof(struct ExecutableCmd)); init_executable_cmd(exe); prev_mod = NO_MODIFIER; } // use previous token's mod, if mod exists, // and this token's info to populate redirection of exe. if (prev_mod == INPUT_REDIR) { exe->input_redir_from = make_file_path(tok->name); } else if (prev_mod == OUTPUT_REDIR) { exe->output_redir_to = make_file_path(tok->name); } else if (prev_mod == ERR_OUTPUT_REDIR) { exe->err_output_redir_to = make_file_path(tok->name); } if ( prev_mod == NO_MODIFIER ) { if ( (exe->full_path = find_cmd(tok->name)) != NULL ) { exe->args = populate_args(tok); if (tok->mod == NO_MODIFIER) { add_back(&cmds, exe); } } else { fprintf(stderr, "error: not a valid command.\n"); destroy_token(tok); destroy_exe_cmd(exe); destroy_cmd_list(&cmds); return -1; } } else if (tok->mod == NO_MODIFIER) { add_back(&cmds, exe); } prev_mod = tok->mod; destroy_token(tok); } // Execute the commands. int exe_status = execute_cmds(&cmds); // TODO: destroy the cmds list. destroy_cmd_list(&cmds); // return 0 if everything went peachy. return exe_status; }