//Shop FFC Item with Yes/No Menu //For: JudasRising //By: ZoriaRPG //13-June-2016 //v0.3.3 const int TILE_SOLD_SIGN = 0; const int SHOP_REGISTER = 6; //Screen->D used for shop items. const int SHOP_SOLD_ITEM1 = 1b; const int SHOP_SOLD_ITEM2 = 10b; const int SHOP_SOLD_ITEM3 = 11b; const int SHOP_PRICE_COLOUR_FOREGROUND = 0x01; //White const int SHOP_PRICE_COLOUR_BACKGROUND = 0x0F; //Black const int SHOP_PRICE_TEXT_X_OFFSET_FOREGROUND = 9; const int SHOP_PRICE_TEXT_X_OFFSET_BACKGROUND = 10; const int SHOP_PRICE_TEXT_Y_OFFSET_FOREGROUND = 13; const int SHOP_PRICE_TEXT_Y_OFFSET_BACKGROUND = 14; const int SHOP_PRICE_FONT = 1; const in SHOP_LINK_PROXIMITY_TO_ITEM = 12; const int SHOP_LINK_MUST_FACE_ITEM = 1; //Set to 0 to disable. const int SFX_SHOP_ERROR = 0; const int MSG_SHOP_ERROR = 0; ffc script ShopItemMenu{ void run(int itm, int price, int str, int itemtile, int sound, int holdup_type, int only_once, int itemnumber_in_shop){ if ( FFC_ShopFlag(SHOP_SOLD_ITEM_1) && itemnumber_in_shop == 1 ) this->Date = TILE_SOLD_SIGN; else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_2) && itemnumber_in_shop == 2 ) this->Date = TILE_SOLD_SIGN; else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_3) && itemnumber_in_shop == 3 ) this->Date = TILE_SOLD_SIGN; else this->Data = itemtile; int str_price[6]; itoa(str_price,price); //Store the price in a string to display it. int choice; while(true){ if ( this->Tile == TILE_SOLD_SIGN ) { this->Script = 0; Quit(); } Screen->DrawString(1,this-X+SHOP_PRICE_TEXT_X_OFFSET_BACKGROUND, this->Y+SHOP_PRICE_TEXT_Y_OFFSET_BACKGROUND, SHOP_PRICE_FONT, SHOP_PRICE_COLOUR_BACKGROUND, 0, TF_NORMAL, str_price, OP_OPAQUE); //Background Screen->DrawString(1,this-X+SHOP_PRICE_TEXT_X_OFFSET_FOREGROUND, this->Y+SHOP_PRICE_TEXT_Y_OFFSET_FOREGROUND, SHOP_PRICE_FONT, SHOP_PRICE_COLOUR_BACKGROUND, 0, TF_NORMAL, str_price, OP_OPAQUE); //Foreground if ( __DistX(this,SHOP_LINK_PROXIMITY_TO_ITEM) && __DistY(this,SHOP_LINK_PROXIMITY_TO_ITEM) && ( __LinkFacing(this) || !SHOP_LINK_MUST_FACE_ITEM ) ) { if ( Link->PressR ) { //Show info on ittem, then... //yes/no menu //if ( price <= Game->Counter[CR_RUPEES] ) { //Yes/No choice = BuyYesNo(msg); if ( choice == 2 ) { //Bought it. if ( Game->Counter[CR_RUPEES] >= price ) { //Bought and can buy it... Game->DCounter[CR_RUPEES] -= price; if ( sound ) Game->PlaySound(sound); item it = Screen->CreateItem(itm); it->X = Link->X; it->Y = Link->Y; it->Z = Link->Z; if ( holdup_type ) { Link->Action = holdup_type + 3; Link->ItemHeld = itm; } if ( only_once ) { //Set the flags. int flag; if ( itemnumber_in_shop == 1 ) flag == SHOP_SOLD_ITEM1; if ( itemnumber_in_shop == 2 ) flag == SHOP_SOLD_ITEM2; if ( itemnumber_in_shop == 3 ) flag == SHOP_SOLD_ITEM3; if ( only_once ) FFC_SetShopFlag(flag, true); } } else { //Errors if ( SFX_SHOP_ERROR ) Game->PlaySound(SFX_SHOP_ERROR); if ( MSG_SHOP_ERROR ) Screen->Message(MSG_SHOP_ERROR); } } //BuyItemYesNo(str,itm,price,sound,holdup_type,only_once,itemnumber_in_shop); //} //Price check and error shiuld be part of the *menu* function //else { //display error //} else choice = 0; //Clear the choice selection. ` } } } Waitframe(); } } //The following three functions are from my std.zh update, with leading underscores added in the event that you upgrade, to prevent conflicts. bool __DistX(ffc a, int distance, bool fromcentre) { int dist; if ( a->X > Link->X ) dist = a->X - Link->X; else dist = Link->X - a->X; return ( dist <= distance ); } //Link to ffc distance bool __DistY(ffc a, int distance, bool fromcentre) { int dist; if ( a->Y > Link->Y ) dist = a->Y - Link->Y; else dist = Link->Y - a->Y; return ( dist <= distance ); } bool __LinkFacing(ffc f){ if ( Link->Dir == DIR_UP && Link->Y < f->Y ) return true; if ( Link->Dir == DIR_DOWN && Link->Y > f->Y ) return true; if ( Link->Dir == DIR_RIGHT && Link->X < f->X ) return true; if ( Link->Dir == DIR_LEFT && Link->X > f->X ) return true; return false; } } //Global Functions int FFC_ShopFlag(int flag){ return Screen->D[SHOP_REGISTER]&flag != 0; } void FFC_SetShopFlag(int flag, bool state){ if(state) Screen->D[SHOP_REGISTER] |= flag; else Screen->D[SHOP_REGISTER] &= ~flag; } int BuyYesNo(int msg) { int lineBreak[]="@26"; int line1[]="@choice(1)Item Info@26"; int line2[]="@choice(2)Buy@tab(56)@choice(3)Cancel@domenu(1)@suspend()"; SetUpWindow(WINDOW_SLOT_1, WINDOW_STYLE_2, 32, 32, SIZE_LARGE); Tango_LoadString(WINDOW_SLOT_1, line1); Tango_AppendString(WINDOW_SLOT_1, line2); Tango_ActivateSlot(WINDOW_SLOT_1); while(!Tango_MenuIsActive()){ Waitframe(); } // Save the state again... int slotState[278]; int menuState[960]; int cursorPos; Tango_SaveSlotState(WINDOW_SLOT_1, slotState); Tango_SaveMenuState(menuState); int done = 0; int choice; while(true){ while( Tango_MenuIsActive() ) { cursorPos=Tango_GetMenuCursorPosition(); Waitframe(); } choice = Tango_GetLastMenuChoice(); if ( choice == 1 ) { // Item Info int text[256]; Game->GetMessage(text,msg); //Load msg into the buffer. ShowString(text, WINDOW_SLOT_2, WINDOW_STYLE_3, 48, 48); } else if ( choice == 2 ) { //Buy done = choice; menuArg = choice; } else if ( choice == 3 ) { //Cancel done = choice; } else if ( Link->PressEx1 ) { done = 1; } else done = 3; if ( done ) { break; // return choice; } else { Tango_RestoreSlotState(WINDOW_SLOT_1, slotState); Tango_RestoreMenuState(menuState); Tango_SetMenuCursorPosition(cursorPos); } } Tango_ClearSlot(WINDOW_SLOT_1); return done; }