void CRPGPlayer::ShowClassMenu( int team ) { IMenuStyle *style = menus->GetDefaultStyle(); IBaseMenu *menu = style->CreateMenu(&g_RPGPlugin, myself->GetIdentity()); menu->SetDefaultTitle(MENU_CLASS_TITLE); switch (team) { case TEAM_SURVIVORS: for (int i = 0; i < NUM_HUMAN_CLASSES; i++) { menu->AppendItem(HumanClasses[i], ItemDrawInfo(HumanClasses[i])); } break; case TEAM_UNDEAD: for (int i = 0; i < NUM_ZOMBIE_CLASSES; i++) { menu->AppendItem(ZombieClasses[i], ItemDrawInfo(ZombieClasses[i])); } break; } menu->InsertItem(MENU_CHOICE_RETURN, MENU_ITEM_RETURN, ItemDrawInfo(MENU_ITEM_RETURN)); menu->Display(this->GetIndex(), MENU_TIME_FOREVER ); }
void CRPGPlayer::ShowChar() { IMenuStyle *style = menus->GetDefaultStyle(); IBaseMenu *menu = style->CreateMenu(&g_RPGPlugin, myself->GetIdentity()); IMenuPanel *panel = menu->CreatePanel(); menu->SetDefaultTitle(MENU_CHAR_TITLE); panel->DrawTitle(MENU_CHAR_TITLE); char text[255]; sprintf(text, "Player ID: %d", GetSQLIndex()); panel->DrawItem(ItemDrawInfo(text)); int classnum = GetCurrentClass(); if (classnum > RPG_CLASS_NONE) { int team = GetCachedTeam(); if ( team == TEAM_SURVIVORS) { sprintf(text, "Class: %s", HumanClasses[classnum]); } else if (team == TEAM_UNDEAD) { sprintf(text, "Class: %s", ZombieClasses[classnum]); } else { sprintf(text, "Class: None"); } panel->DrawItem(ItemDrawInfo(text)); // item 1 sprintf(text, "Level: %d", GetLevel()); panel->DrawItem(ItemDrawInfo(text)); // item 2 sprintf(text, "Experience: %d", GetExperience()); panel->DrawItem(ItemDrawInfo(text)); // item 3 for (int i = 0; i < MAX_SKILLS; i++) // item 4-7 { sprintf(text, "%s - (Level %d)", SkillNames[skills[i].iIndex], skills[i].iLevel); panel->DrawItem(ItemDrawInfo(text)); } } panel->SendDisplay(GetIndex(), &g_RPGPlugin, MENU_TIME_FOREVER ); }
void CRPGPlayer::ShowSkillMenu() { if (GetCurrentClass() == RPG_CLASS_NONE ) { ShowClassMenu( GetPlayerInfo()->GetTeamIndex()); return; } if (GetFreeSkills() < 0) { ResetAccount(); gamehelpers->TextMsg(GetIndex(), HUD_PRINTTALK, "[ZPS-RPG] Your skills have been reset because of an error.\n"); } IMenuStyle *style = menus->GetDefaultStyle(); IBaseMenu *menu = style->CreateMenu(&g_RPGPlugin, myself->GetIdentity()); menu->SetDefaultTitle(MENU_SKILL_TITLE); char skillname[64]; unsigned int menustyle = ITEMDRAW_DEFAULT; for (int i = 0; i < MAX_SKILLS; i++) { sprintf(skillname, "%s (Level %d)", SkillNames[skills[i].iIndex], skills[i].iLevel); menustyle = ITEMDRAW_DEFAULT; if ((skills[i].iLevel >= 3) || (GetFreeSkills() == 0)) menustyle = ITEMDRAW_DISABLED; if( i == 3 ) // ULTIMATE { if ((skills[i].iLevel >= 1) || (GetLevel() < 6) || (GetFreeSkills() == 0)) { menustyle = ITEMDRAW_DISABLED; } } menu->AppendItem(SkillNames[skills[i].iIndex], ItemDrawInfo(skillname, menustyle)); } menu->AppendItem(MENU_ITEM_RESET, ItemDrawInfo("Reset Skills")); menu->InsertItem(6, MENU_ITEM_RETURN, ItemDrawInfo(MENU_ITEM_RETURN)); menu->SetMenuOptionFlags( menu->GetMenuOptionFlags() | MENUFLAG_BUTTON_EXIT ); menu->Display(this->GetIndex(), MENU_TIME_FOREVER); }
void CRPGPlayer::ShowBaseMenu() { IMenuStyle *style = menus->GetDefaultStyle(); IBaseMenu *menu = style->CreateMenu(&g_RPGPlugin, myself->GetIdentity()); menu->SetDefaultTitle(MENU_BASE_TITLE); for (int i = 0; i < BASEMENUCHOICES; i++) { menu->AppendItem(BaseMenuChoices[i], ItemDrawInfo(BaseMenuChoices[i])); } //menu->SetMenuOptionFlags( menu->GetMenuOptionFlags() | MENUFLAG_BUTTON_EXIT ); menu->Display(this->GetIndex(), MENU_TIME_FOREVER); }
void TopMenu::UpdateClientCategory(int client, unsigned int category, bool bSkipRootCheck) { bool has_access = false; /* Update the client's root menu just in case it needs it. This * will validate that we have both a valid client and a valid * category structure for that client. */ if (!bSkipRootCheck) { UpdateClientRoot(client); } /* Now it's guaranteed that our category tables will be usable */ topmenu_player_t *pClient = &m_clients[client]; topmenu_category_t *cat = m_Categories[category]; topmenu_player_category_t *player_cat = &(pClient->cats[category]); /* Does the category actually need updating? */ if (player_cat->serial == cat->serial) { return; } /* Destroy any existing menu */ if (player_cat->menu) { player_cat->menu->Destroy(); player_cat->menu = NULL; } if (pClient->last_category == category) { pClient->last_position = 0; } IBaseMenu *cat_menu = menus->GetDefaultStyle()->CreateMenu(this, myself->GetIdentity()); /* Categories get an "exit back" button */ cat_menu->SetMenuOptionFlags(cat_menu->GetMenuOptionFlags() | MENUFLAG_BUTTON_EXITBACK); /* Re-sort the category if needed */ SortCategoryIfNeeded(category); /* Build the menu with the sorted items first */ for (size_t i = 0; i < cat->sorted.size(); i++) { cat_menu->AppendItem(cat->sorted[i]->name, ItemDrawInfo("")); if (!has_access && adminsys->CheckAccess(client, cat->sorted[i]->cmdname, cat->sorted[i]->flags, false)) { has_access = true; } } /* Now handle unsorted items */ if (cat->unsorted.size()) { /* Build a list of the item names */ obj_by_name_t *item_list = new obj_by_name_t[cat->unsorted.size()]; for (size_t i = 0; i < cat->unsorted.size(); i++) { obj_by_name_t *item = &item_list[i]; topmenu_object_t *obj = cat->unsorted[i]; obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, item->name, sizeof(item->name)); item->obj_index = (unsigned int)i; if (!has_access && adminsys->CheckAccess(client, obj->cmdname, obj->flags, false)) { has_access = true; } } if (has_access) { /* Sort the names */ qsort(item_list, cat->unsorted.size(), sizeof(obj_by_name_t), _SortObjectNamesDescending); /* Add to the menu */ for (size_t i = 0; i < cat->unsorted.size(); i++) { cat_menu->AppendItem(cat->unsorted[item_list[i].obj_index]->name, ItemDrawInfo("")); } } delete [] item_list; } /* If the player has access to no items, don't draw a menu. */ if (!has_access) { cat_menu->Destroy(); player_cat->menu = NULL; player_cat->serial = cat->serial; return; } /* Set the menu's title */ if (m_bCacheTitles) { char renderbuf[128]; cat->obj->callbacks->OnTopMenuDisplayTitle(this, client, cat->obj->object_id, renderbuf, sizeof(renderbuf)); cat_menu->SetDefaultTitle(renderbuf); } /* We're done! */ player_cat->menu = cat_menu; player_cat->serial = cat->serial; }
void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer) { topmenu_player_t *pClient = &m_clients[client]; IGamePlayer *pPlayer = pGamePlayer ? pGamePlayer : playerhelpers->GetGamePlayer(client); /* Determine if an update is necessary */ bool is_update_needed = false; if (pClient->menu_serial != m_SerialNo) { is_update_needed = true; } else if (pPlayer->GetUserId() != pClient->user_id) { is_update_needed = true; } /* If no update is needed at the root level, just leave now */ if (!is_update_needed) { return; } /* First we need to flush the cache... */ TearDownClient(pClient); /* Now, rebuild the category list, but don't create menus */ if (m_Categories.size() == 0) { pClient->cat_count = 0; pClient->cats = NULL; } else { pClient->cat_count = (unsigned int)m_Categories.size(); pClient->cats = new topmenu_player_category_t[pClient->cat_count]; memset(pClient->cats, 0, sizeof(topmenu_player_category_t) * pClient->cat_count); } /* Re-sort the root categories if needed */ SortCategoriesIfNeeded(); /* Build the root menu */ IBaseMenu *root_menu = menus->GetDefaultStyle()->CreateMenu(this, myself->GetIdentity()); /* Add the sorted items */ for (size_t i = 0; i < m_SortedCats.size(); i++) { if (m_Categories[m_SortedCats[i]]->obj_list.size() == 0) { continue; } root_menu->AppendItem(m_Categories[m_SortedCats[i]]->obj->name, ItemDrawInfo("")); } /* Now we need to handle un-sorted items. This is slightly trickier, as we need to * pre-render each category name, and cache those names. Phew! */ if (m_UnsortedCats.size()) { obj_by_name_t *item_list = new obj_by_name_t[m_UnsortedCats.size()]; for (size_t i = 0; i < m_UnsortedCats.size(); i++) { obj_by_name_t *temp_obj = &item_list[i]; topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj; obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, temp_obj->name, sizeof(temp_obj->name)); temp_obj->obj_index = m_UnsortedCats[i]; } /* Sort our temp list */ qsort(item_list, m_UnsortedCats.size(), sizeof(obj_by_name_t), _SortObjectNamesDescending); /* Add the new sorted categories */ for (size_t i = 0; i < m_UnsortedCats.size(); i++) { if (m_Categories[item_list[i].obj_index]->obj_list.size() == 0) { continue; } root_menu->AppendItem(m_Categories[item_list[i].obj_index]->obj->name, ItemDrawInfo("")); } delete [] item_list; } /* Set the menu's title */ if (m_bCacheTitles) { char renderbuf[128]; m_pTitle->OnTopMenuDisplayTitle(this, client, 0, renderbuf, sizeof(renderbuf)); root_menu->SetDefaultTitle(renderbuf); } /* The client is now fully updated */ pClient->root = root_menu; pClient->user_id = pPlayer->GetUserId(); pClient->menu_serial = m_SerialNo; pClient->last_position = 0; pClient->last_category = 0; pClient->last_root_pos = 0; }