Skip to content

Commit

Permalink
split information menu across v1+v2 / v3
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Oct 30, 2023
1 parent 138c563 commit 5ff2694
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/ReceiveCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,8 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {

} else {
try {
send_message_box(c, c->require_server_state()->information_contents->at(item_id).c_str());
auto contents = c->require_server_state()->information_contents_for_client(c);
send_message_box(c, contents->at(item_id).c_str());
} catch (const out_of_range&) {
send_message_box(c, "$C6No such information exists.");
}
Expand Down
31 changes: 26 additions & 5 deletions src/ServerState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,26 +773,41 @@ void ServerState::parse_config(const JSON& json, bool is_reload) {

shared_ptr<Menu> information_menu_v2(new Menu(MenuID::INFORMATION, "Information"));
shared_ptr<Menu> information_menu_v3(new Menu(MenuID::INFORMATION, "Information"));
shared_ptr<vector<string>> information_contents(new vector<string>());
shared_ptr<vector<string>> information_contents_v2(new vector<string>());
shared_ptr<vector<string>> information_contents_v3(new vector<string>());

information_menu_v2->items.emplace_back(InformationMenuItemID::GO_BACK, "Go back",
"Return to the\nmain menu", MenuItem::Flag::INVISIBLE_IN_INFO_MENU);
information_menu_v3->items.emplace_back(InformationMenuItemID::GO_BACK, "Go back",
"Return to the\nmain menu", MenuItem::Flag::INVISIBLE_IN_INFO_MENU);
{
auto blank_json = JSON::list();
const JSON& default_json = json.get("InformationMenuContents", blank_json);
const JSON& v2_json = json.get("InformationMenuContentsV1V2", default_json);
const JSON& v3_json = json.get("InformationMenuContentsV3", default_json);

uint32_t item_id = 0;
for (const auto& item : json.at("InformationMenuContents").as_list()) {
for (const auto& item : v2_json.as_list()) {
string name = item->get_string(0);
string short_desc = item->get_string(1);
information_menu_v2->items.emplace_back(item_id, name, short_desc, 0);
information_contents_v2->emplace_back(item->get_string(2));
item_id++;
}

item_id = 0;
for (const auto& item : v3_json.as_list()) {
string name = item->get_string(0);
string short_desc = item->get_string(1);
information_menu_v3->items.emplace_back(item_id, name, short_desc, MenuItem::Flag::REQUIRES_MESSAGE_BOXES);
information_contents->emplace_back(item->get_string(2));
information_contents_v3->emplace_back(item->get_string(2));
item_id++;
}
}
this->information_menu_v2 = information_menu_v2;
this->information_menu_v3 = information_menu_v3;
this->information_contents = information_contents;
this->information_contents_v2 = information_contents_v2;
this->information_contents_v3 = information_contents_v3;

auto generate_redirect_destinations_menu = [&](vector<pair<string, uint16_t>>& ret_pds, const char* key) -> shared_ptr<const Menu> {
shared_ptr<Menu> ret(new Menu(MenuID::REDIRECT_DESTINATIONS, "Other servers"));
Expand Down Expand Up @@ -1131,7 +1146,13 @@ void ServerState::load_dol_files() {
this->dol_file_index.reset(new DOLFileIndex("system/dol"));
}

shared_ptr<const QuestIndex> ServerState::quest_index_for_client(shared_ptr<Client> c) const {
shared_ptr<const vector<string>> ServerState::information_contents_for_client(shared_ptr<const Client> c) const {
return ((c->version() == GameVersion::DC) || (c->version() == GameVersion::PC))
? this->information_contents_v2
: this->information_contents_v3;
}

shared_ptr<const QuestIndex> ServerState::quest_index_for_client(shared_ptr<const Client> c) const {
return (c->flags & Client::Flag::IS_EPISODE_3)
? this->ep3_download_quest_index
: this->default_quest_index;
Expand Down
6 changes: 4 additions & 2 deletions src/ServerState.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {

std::shared_ptr<const Menu> information_menu_v2;
std::shared_ptr<const Menu> information_menu_v3;
std::shared_ptr<std::vector<std::string>> information_contents;
std::shared_ptr<std::vector<std::string>> information_contents_v2;
std::shared_ptr<std::vector<std::string>> information_contents_v3;
std::shared_ptr<const Menu> redirect_destinations_menu_dc;
std::shared_ptr<const Menu> redirect_destinations_menu_pc;
std::shared_ptr<const Menu> redirect_destinations_menu_gc;
Expand Down Expand Up @@ -221,7 +222,8 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::shared_ptr<const ItemParameterTable> item_parameter_table_for_version(GameVersion version) const;
std::string describe_item(GameVersion version, const ItemData& item, bool include_color_codes) const;

std::shared_ptr<const QuestIndex> quest_index_for_client(std::shared_ptr<Client> c) const;
std::shared_ptr<const std::vector<std::string>> information_contents_for_client(std::shared_ptr<const Client> c) const;
std::shared_ptr<const QuestIndex> quest_index_for_client(std::shared_ptr<const Client> c) const;

void set_port_configuration(const std::vector<PortConfiguration>& port_configs);

Expand Down
6 changes: 5 additions & 1 deletion system/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@
// Information menu contents. Each entry is a list containing [title,
// short description, full contents]. In the short description and full
// contents, you can use PSO escape codes with the $ character (for example,
// $Cx for colors).
// $Cx for colors). You can show different information menus to V1/V2 clients
// and V3 clients; to do so, copy InformationMenuContents to
// InformationMenuContentsV1V2 and InformationMenuContentsV3 and edit them as
// needed. (If either the V1V2 or V3 version of the information menu is not
// defined, this default version is used instead.)
"InformationMenuContents": [
["Lobby commands", "Show commands used\nin the lobby", "These commands can be used in the lobby.\n\n$C6%sli$C7: Show basic information about the lobby\n$C6%sarrow <color-id>$C7: Change your lobby arrow color\n$C6%sln [name]$C7: Change the lobby type (for you only)\n$C6%sexit$C7: Leave the current game or lobby\n$C6%spatch <name>$C7: Run a patch on your client\n\n$C8Episode 3 only:$C7\n$C6%ssong <song-id>$C7: Play a jukebox song"],
["Game commands", "Show commands used\nin games", "These commands can be used to customize games.\n\n$C8Before starting a game:$C7\n$C6%ssecid <section-id>$C7: Set your override section ID\n$C6%srand <seed>$C7: Set your override random seed\n\n$C8When in a game:$C7\n$C6%sli$C7: Show basic information about the game\n$C6%swhat$C7: Describe the nearest item on the ground\n$C6%smaxlevel <level>$C7: Set maximum level to join\n$C6%sminlevel <level>$C7: Set minimum level to join\n$C6%spassword [password]$C7: Lock or unlock the game"],
Expand Down

0 comments on commit 5ff2694

Please sign in to comment.