void MenuBook::logic() { if (book_name == "") return; else { loadBook(); visible = true; } if (!visible) return; tablist.logic(); if (closeButton->checkClick() || (inpt->pressing[ACCEPT] && !inpt->lock[ACCEPT])) { if (inpt->pressing[ACCEPT]) inpt->lock[ACCEPT] = true; clearBook(); snd->play(sfx_close); visible = false; book_name = ""; last_book_name = ""; book_loaded = false; } }
MenuBook::~MenuBook() { delete closeButton; clearBook(); }
void MenuBook::loadBook() { if (last_book_name != book_name) { last_book_name = ""; book_loaded = false; clearBook(); } if (book_loaded) return; // Read data from config file FileParser infile; // @CLASS MenuBook|Description of books in books/ if (infile.open(book_name)) { last_book_name = book_name; while (infile.next()) { if (parseMenuKey(infile.key, infile.val)) continue; infile.val = infile.val + ','; // @ATTR close|point|Position of the close button. if(infile.key == "close") { int x = popFirstInt(infile.val); int y = popFirstInt(infile.val); closeButton->setBasePos(x, y); } // @ATTR background|filename|Filename for the background image. else if (infile.key == "background") { setBackground(popFirstString(infile.val)); } else if (infile.section == "") { infile.error("MenuBook: '%s' is not a valid key.", infile.key.c_str()); } if (infile.new_section) { // for sections that are stored in collections, add a new object here if (infile.section == "text") { text.push_back(NULL); textData.push_back(""); textColor.push_back(Color()); justify.push_back(0); textFont.push_back(""); size.push_back(Rect()); } else if (infile.section == "image") { image.push_back(NULL); image_dest.push_back(Point()); } } if (infile.section == "text") loadText(infile); else if (infile.section == "image") loadImage(infile); } infile.close(); } // setup image dest for (unsigned i=0; i < image.size(); i++) { image[i]->setDest(image_dest[i]); } // render text to surface for (unsigned i=0; i<text.size(); i++) { font->setFont(textFont[i]); Point pSize = font->calc_size(textData[i], size[i].w); Image *graphics = render_device->createImage(size[i].w, pSize.y); if (justify[i] == JUSTIFY_CENTER) font->render(textData[i], size[i].w/2, 0, justify[i], graphics, size[i].w, textColor[i]); else if (justify[i] == JUSTIFY_RIGHT) font->render(textData[i], size[i].w, 0, justify[i], graphics, size[i].w, textColor[i]); else font->render(textData[i], 0, 0, justify[i], graphics, size[i].w, textColor[i]); text[i] = graphics->createSprite(); graphics->unref(); } align(); book_loaded = true; }
main() { int selection = 0; int entryNum = 0; entry *phoneBook; phoneBook = (entry*)malloc(sizeof(entry)); do { printf("\n---------------------------------------------"); printf("\nPhone Book\n[1]\tAdd Friend\n[2]\tDelete Friend\n[3]\tShow Phone Book\n[4]\tSearch Phone Book\n[5]\tRandom Entry\n[6]\tAlphebetical Phone Book\n[7]\tClear Phone Book\n[8]\tSave Phone Book\n[9]\tLoad Phone Book\n[0]\tExit\n:"); scanf("%d",&selection); switch(selection) { case 1: { printf("\nYou have selected \"Add Friend\"."); addFriend(phoneBook,&entryNum); break; } case 2: { printf("\nYou have selected \"Delete Friend\"."); delFriend(phoneBook,&entryNum); break; } case 3: { printf("\nYou have selected \"Show Phone Book\"."); showBook(phoneBook,&entryNum); break; } case 4: { printf("\nYou have selected \"Search Phone Book\"."); findFriend(phoneBook,&entryNum); break; } case 5: { printf("\nYou have selected \"Random Entry\"."); randEntry(phoneBook,&entryNum); break; } case 6: { printf("\nYou have selected \"Alphabetical Phone Book\"."); alphaBook(phoneBook,&entryNum); break; } case 7: { printf("\nYou have selected \"Clear Phone Book\"."); clearBook(phoneBook,&entryNum); break; } case 8: { printf("\nYou have selected \"Save Phone Book\"."); saveBook(phoneBook,&entryNum); break; } case 9: { printf("\nYou have selected \"Load Phone Book\"."); phoneBook=loadBook(phoneBook,&entryNum); break; } case 0: { printf("\nYou have selected \"Exit\"."); printf("\nHave a nice day!"); free(phoneBook); break; } default: { printf("\nINVALID OPTION!"); break; } } }while (selection!=0); }