Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- /*
- https://ideone.com/CHxrfS
- You want to design the system so that sender tells what to do with action.
- If you need some options that are not a part of the paginated menus then you
- need to reserve senders for them. For example reserving from the beignning or end of the uint32 range a few values.
- In this system sender is either a reserved ID or the page ID.
- The action is either 0 or a valid item lowguid/ID.
- */
- // This is a globally known value
- // we want to substract the "next" and "previous" buttons from max items.
- const int max_items = 32-2;
- void ShowPage(int page, vector<int> const & items)
- {
- // Clear menu()
- if (page < 0) // show main page if invalid page
- page = 0;
- int count = 0; // added items count
- for (int i = page*max_items; i < items.size(); ++i) // go through all items, we want to start from page beginning
- {
- // you want here that action is for example item lowguid.
- // you want to pass the page here so if something goes wrong you can show the same pageid on gossip select.
- printf("Some Item, sender: %i action: %i\n", page, items[i]);
- ++count; // added an item, increase count of items
- if (count >= max_items)
- {
- // we are at limit, add next button and stop adding items
- printf("Next page, sender: %i action: %i\n", page+1, 0);
- break;
- }
- }
- if (page > 0)
- {
- if (count == 0)
- {
- // player trying to view a page that doesnt contain any items and isnt main page.
- // We want to show the main menu here or show the previous page.
- ShowPage(page-1, items);
- return;
- }
- // we are at limit, add next button and stop adding items
- printf("Previous page, sender: %i action: %i\n", page-1, 0);
- }
- // Send menu()
- }
- int main() {
- /*
- Through for loops and such you have gathered all items the player has in a list called "items".
- These items can be for example pointers to the items you get from GetItemByPos or similar.
- These are all the valid items to be shown in the menu.
- */
- vector<int> items = {};
- int number_of_example_items = 32;
- for (int i = 1; i <= number_of_example_items; ++i)
- items.push_back(i);
- ShowPage(0, items);
- ShowPage(1, items);
- ShowPage(100, items);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement