////////////////////////////////////// /// Shop FFC Item with Yes/No Menu /// /// Requested By: JudasRising /// /// By: ZoriaRPG /// /// 21-June-2016 /// /// v0.4.0 /// /////////////////////////////////////////////////////////////////////////////////////// //General Settings const int SHOP_REGISTER = 6; //Screen->D used for shop items. //Combos and Tiles const int TILE_SOLD_SIGN = 0; //The sold ign, if using the sell-out feature. const int SHOP_SIGNS_CHANGE_WHEN_ALL_ITEMS_SOLD = 0; //If this is set to '1', then signs will chane again if none of the itms are available to buy any longer. const int TILE_SHOP_CLOSED_FOREVER = 0; //Set to a combo of your choice if all the items are sold out, forever. //The small button icon that appears next to an item, to allow link to know he can interact with it. //THe tile should have a graphic that occupies the upper-rightmost 8x8pixels, as a 'minitile'. const int SHOP_BUY_BUTTON_TILE = 0; //Tile of the 'R' button, or whatever button you use to activate the 'buy' menu. const int SHOP_BUY_BUTTON_TILE_CSET = 0; const int SHOP_BUY_BUTTON_TILE_OPACITY = 128; const int SHOP_BUY_BUTTON_TILE_LAYER = 2; const int SHOP_BUY_BUTTON_TILE_X_OFFSET = 9; const int SHOP_BUY_BUTTON_TILE_Y_OFFST = - 8; const int SHOP_BUY_BUTTON_TILE_BLOCKW = 1; const int SHOP_BUY_BUTTON_TILE_BLOCKH = 1; //Text Settings for shop prices const int SHOP_PRICE_FONT = 1; const int SHOP_PRICE_COLOUR_FOREGROUND = 0x01; //White const int SHOP_PRICE_COLOUR_BACKGROUND = 0x0F; //Black const int SHOP_PRICE_TEXT_LAYER = 2; 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; //Sound and String const int SFX_SHOP_ERROR = 0; //Sound to play when buying an item. const int MSG_SHOP_ERROR = 0; //Message to display if Link is out of funds. //Shop Functionality Setings const int SHOP_LINK_PROXIMITY_X_TO_ITEM = 12; //X-Distance in pixels for required proximity to activate menu. const int SHOP_LINK_PROXIMITY_Y_TO_ITEM = 12; //Y-Distance in pixels for required proximity to activate menu. const int SHOP_LINK_MUST_FACE_ITEM = 1; //Set to 0 to disable. //Tango slot constants. const int WINDOW_SLOT_1 = 0; const int WINDOW_SLOT_2 = 1; const int WINDOW_SLOT_3 = 2; const int WINDOW_SLOT_4 = 3; const int WINDOW_SLOT_5 = 4; //Values that you probably should not change. //! These are th4e binary flags for items, used in conjunction with one-time-only sales. const int SHOP_SOLD_ITEM_1 = 000000001b; const int SHOP_SOLD_ITEM_2 = 000000010b; const int SHOP_SOLD_ITEM_3 = 000000100b; const int SHOP_SOLD_ITEM_4 = 000001000b; const int SHOP_SOLD_ITEM_5 = 000010000b; const int SHOP_SOLD_ITEM_6 = 000100000b; const int SHOP_SOLD_ITEM_7 = 001000000b; const int SHOP_SOLD_ITEM_8 = 010000000b; const int SHOP_SOLD_ITEM_9 = 100000000b; // There are certainly other ways to handle these... // Vars used by the Tango menu. int menuCommand; int menuArg; //Tango Menu Init void SetUpWindow(int slot, int style, int x, int y, int size) { SetStyleSize(style, size); Tango_ClearSlot(slot); Tango_SetSlotStyle(slot, style); Tango_SetSlotPosition(slot, x, y); } //Quick way to drop a string into a Tango dialogue box. void ShowString(int string, int slot, int style, int x, int y) { SetUpWindow(slot, style, x, y, SIZE_LARGE); Tango_LoadString(slot, string); Tango_ActivateSlot(slot); while(Tango_SlotIsActive(slot)) Waitframe(); } //The main shop ffc. ffc script ShopItemMenu{ void run(int itm, int price, int msg, 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->Data = TILE_SOLD_SIGN; if ( FFC_ShopFlag(SHOP_SOLD_ITEM_1) && itemnumber_in_shop == 1 ) this->Data = TILE_SOLD_SIGN; else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_2) && itemnumber_in_shop == 2 ) this->Data = TILE_SOLD_SIGN; else if ( FFC_ShopFlag(SHOP_SOLD_ITEM_3) && itemnumber_in_shop == 3 ) this->Data = TILE_SOLD_SIGN; else if ( itemtile ) 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->Data == TILE_SOLD_SIGN || TILE_SHOP_CLOSED_FOREVER) { this->Script = 0; Quit(); } if ( SHOP_SIGNS_CHANGE_WHEN_ALL_ITEMS_SOLD && IsShopAllSoldOut() ) this->Data = TILE_SHOP_CLOSED_FOREVER; Screen->DrawString(SHOP_PRICE_TEXT_LAYER,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(SHOP_PRICE_TEXT_LAYER,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_X_TO_ITEM,true) && __DistY(this,SHOP_LINK_PROXIMITY_Y_TO_ITEM,true) && ( __LinkFacing(this) || !SHOP_LINK_MUST_FACE_ITEM ) ) { //Draw the button tile overlay. if ( SHOP_BUY_BUTTON_TILE ) Screen->DrawTile( SHOP_BUY_BUTTON_TILE_LAYER, this->X + SHOP_BUY_BUTTON_TILE_X_OFFSET, this->Y + SHOP_BUY_BUTTON_TILE_Y_OFFSET, SHOP_BUY_BUTTON_TILE, SHOP_BUY_BUTTON_TILE_BLOCKW, SHOP_BUY_BUTTON_TILE_BLOCKH, SHOP_BUY_BUTTON_TILE_CSET, -1, -1, 0, 0, 0, 0, true, SHOP_BUY_BUTTON_TILE_OPACITY); 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->HeldItem = itm; } if ( only_once ) { //Set the flags. if ( itemnumber_in_shop == 1 ) FFC_SetShopFlag(SHOP_SOLD_ITEM_1, true); if ( itemnumber_in_shop == 2 ) FFC_SetShopFlag(SHOP_SOLD_ITEM_2, true); if ( itemnumber_in_shop == 3 ) FFC_SetShopFlag(SHOP_SOLD_ITEM_3, true); this->Data = TILE_SOLD_SIGN; } } else { //Errors if ( SFX_SHOP_ERROR ) Game->PlaySound(SFX_SHOP_ERROR); if ( MSG_SHOP_ERROR ) Screen->Message(MSG_SHOP_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 //Check a shop item sold-out flag. bool FFC_ShopFlag(int flag){ return ( (Screen->D[SHOP_REGISTER]<<0)&flag) != 0; } //Set a shop item sold-out flag. void FFC_SetShopFlag(int flag, bool state){ if(state) (Screen->D[SHOP_REGISTER]<<0 |= flag; else (Screen->D[SHOP_REGISTER]<<0 &= ~flag; } int FFC_NumShopItems(){ ffc f; int count; int ff[]="ShopItemMenu"; int ffid = Game->GetFFCScript(ff); for ( int q = 1; q < 32; q++ ){ f = Screen->LoadFFC(q); if ( f->Script == ffid ) count++; } return count; } void FFC_SetNumberShopItems(){ int val[6]; val[0]= Screen->D[SHOP_REGISTER]; val[1]= val[0] << 0; //Integer side val[2] = val[0] - val[1]; //Decimal side. val[3] = val[2] * 10000; //Decimal to Int val[4] = FFC_NumShopItems(); //Read how many shops are running. val[5] = val[4] / 10000; //Turn it into a decimal. Screen->D[SHOP_REGISTER]; = val[1]+val[5]; //Preserve the integer, and replace the decimal. } int FFC_GetNumberShopItems(){ int val[3]; val[0]= Screen->D[SHOP_REGISTER]; val[1]= val[0] << 0; //Integer side val[2] = val[0] - val[1]; //Decimal side. return val[2]; } //Check if all items are sold out. Works only if there are three items sold out. bool IsShopAllSoldOut(){ return ( Screen->D[SHOP_REGISTER] >= 7 ); } //The 'yes/no' menu called by the ffc. int BuyYesNo(int msg) { int lineBreak[]="@26"; int line1[]="@choice(1)Item Info@26"; int line2[]="@choice(2)Buy@26@choice(3)Cancel@domenu(1)@suspend()"; SetUpWindow(WINDOW_SLOT_1, WINDOW_STYLE_3, 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(msg,text); //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; } //Global Scripts //Mandatory init script: If you already have an init script, merge them. global script Init { void run(){ SetCommonStyleData(WINDOW_STYLE_1); SetCommonStyleData(WINDOW_STYLE_2); SetCommonStyleData(WINDOW_STYLE_3); } } //Example global active (slot 2) script. global script Tango{ void run(){ Tango_Start(); StartGhostZH(); while(true) { UpdateGhostZH1(); Tango_Update1(); Waitdraw(); UpdateGhostZH2(); Tango_Update2(); Waitframe(); } } }