Skip to content

Commit

Permalink
g/j2: Fill out game options menu (#3003)
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser authored Sep 23, 2023
1 parent 4871f5d commit 1091040
Show file tree
Hide file tree
Showing 20 changed files with 1,358 additions and 205 deletions.
12 changes: 12 additions & 0 deletions common/util/FontUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,18 @@ const GameTextFontBank* get_font_bank(GameTextVersion version) {
return g_font_banks.at(version);
}

const GameTextFontBank* get_font_bank_from_game_version(GameVersion version) {
// Jak 1 has been patched to use V2
switch (version) {
case GameVersion::Jak1:
return get_font_bank(GameTextVersion::JAK1_V2);
case GameVersion::Jak2:
return get_font_bank(GameTextVersion::JAK2);
default:
ASSERT_MSG(false, "Unsupported game for get_font_bank_from_game_version");
}
}

const GameTextFontBank* get_font_bank(const std::string& name) {
if (auto it = sTextVerEnumMap.find(name); it == sTextVerEnumMap.end()) {
throw std::runtime_error(fmt::format("unknown text version {}", name));
Expand Down
2 changes: 2 additions & 0 deletions common/util/FontUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <vector>

#include "common/common_types.h"
#include "common/versions/versions.h"

// version of the game text file's text encoding. Not real, but we need to differentiate them
// somehow, since the encoding changes.
Expand Down Expand Up @@ -92,5 +93,6 @@ extern GameTextFontBank g_font_bank_jak2;
extern std::map<GameTextVersion, GameTextFontBank*> g_font_banks;

const GameTextFontBank* get_font_bank(GameTextVersion version);
const GameTextFontBank* get_font_bank_from_game_version(GameVersion version);
const GameTextFontBank* get_font_bank(const std::string& name);
bool font_bank_exists(GameTextVersion version);
21 changes: 21 additions & 0 deletions common/util/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,28 @@ std::string to_lower(const std::string& str) {
std::transform(str.begin(), str.end(), new_str.begin(), ::tolower);
return new_str;
}

bool hex_char(char c) {
return !((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F'));
}

std::string titlize(const std::string& str) {
// Iterate through the string, capitalizing any character that either comes first, or is preceeded
// by whitespace
const auto trimmed_string = trim(str);
std::string new_str = "";
bool capitalize_next_char = true;
for (const auto& character : trimmed_string) {
if (capitalize_next_char) {
new_str.push_back(toupper(character));
capitalize_next_char = false;
} else {
if (character == ' ') {
capitalize_next_char = true;
}
new_str.push_back(character);
}
}
return new_str;
}
} // namespace str_util
1 change: 1 addition & 0 deletions common/util/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ std::string to_upper(const std::string& str);
std::string to_lower(const std::string& str);
/// Is this a valid character for a hex number?
bool hex_char(char c);
std::string titlize(const std::string& str);
} // namespace str_util
25 changes: 24 additions & 1 deletion decompiler/config/jak2/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -7353,7 +7353,6 @@
(progress-camera-options-first-vert #x1282)
(progress-camera-options-third-horz #x1283)
(progress-camera-options-third-vert #x1284)
(progress-reset-to-default #x1285)
(progress-normal #x1286)
(progress-inverted #x1287)
(progress-ps2-parts #x1288)
Expand All @@ -7365,6 +7364,30 @@
(progress-frame-rate #x128e)
(progress-misc-game-options #x128f)
(progress-speedrunner-mode #x1290)
(progress-menu-input-options #x1291)
(progress-restore-defaults #x1292)
(progress-menu-controller-options #x1293)
(progress-controller-options-select-controller #x1294)
(progress-controller-options-analog-deadzone #x1295)
(progress-controller-options-ignore-if-unfocused #x1296)
(progress-controller-options-led-hp #x1297)
(progress-controller-options-led-darkjak #x1298)
(progress-input-options-enable-keyboard #x1299)
(progress-input-options-enable-mouse #x129a)
(progress-menu-mouse-options #x129b)
(progress-mouse-options-track-camera #x129c)
(progress-mouse-options-horz-sens #x129d)
(progress-mouse-options-vert-sens #x129e)
(progress-mouse-options-player-movement #x129f)
(progress-input-options-auto-hide-cursor #x1300)
(progress-menu-reassign-binds #x1301)
(progress-reassign-binds-controller #x1302)
(progress-reassign-binds-keyboard #x1303)
(progress-reassign-binds-mouse #x1304)
(progress-multiselect-no-items-found #x1305)
(progress-keybinds-waiting-for-bind #x1306)
(progress-keybinds-unset #x1307)
(progress-unknown-option #x1308)
)
;; ---text-id-h:text-id

Expand Down
30 changes: 30 additions & 0 deletions game/assets/jak2/temp-text-id-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"1280": "1000",
"1286": "1001",
"1287": "1002",
"1289": "1030",
"128e": "1060",
"128f": "100f",
"1290": "1500",
"1291": "1600",
"1292": "1007",
"1293": "160d",
"1294": "1601",
"1295": "1602",
"1296": "1603",
"1297": "1604",
"1299": "160e",
"129a": "160f",
"129b": "1610",
"129c": "1606",
"129d": "1607",
"129e": "1608",
"129f": "1609",
"1300": "1613",
"1301": "1611",
"1302": "160a",
"1303": "160b",
"1304": "160c",
"1307": "1614",
"1308": "1615"
}
36 changes: 30 additions & 6 deletions game/assets/jak2/text/game_custom_text_en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
"1261": "Bad Weather",
"1262": "Nice Weather",
"1280": "Camera Options",
"1281": "Left/Right (First Person)",
"1282": "Up/Down (First Person)",
"1283": "Left/Right (Third Person)",
"1284": "Up/Down (Third Person)",
"1281": "Left/Right (1st Person)",
"1282": "Up/Down (1st Person)",
"1283": "Left/Right (3rd Person)",
"1284": "Up/Down (3rd Person)",
"1285": "Reset to Default",
"1286": "Normal",
"1287": "Inverted",
Expand All @@ -122,6 +122,30 @@
"128c": "High",
"128d": "Credits",
"128e": "Frame Rate (Experimental)",
"128f": "Misc. Options",
"1290": "Speedrunner Mode"
"128f": "Miscellaneous",
"1290": "Speedrunner Mode",
"1291": "Input Options",
"1292": "Restore Defaults",
"1293": "Controller Options",
"1294": "Select Controller",
"1295": "Analog Deadzone",
"1296": "Ignore If Window Unfocused",
"1297": "Controller Led For HP",
"1298": "Controller Led For Dark Jak",
"1299": "Enable Keyboard",
"129a": "Enable Mouse",
"129b": "Mouse Options",
"129c": "Track Camera",
"129d": "Horizontal Sensitivity",
"129e": "Vertical Sensitivity",
"129f": "Player Movement",
"1300": "Auto Hide Cursor",
"1301": "Reassign Binds",
"1302": "Controller Binds",
"1303": "Keyboard Binds",
"1304": "Mouse Binds",
"1305": "No Options",
"1306": "Waiting",
"1307": "Unset",
"1308": "Unknown"
}
22 changes: 22 additions & 0 deletions game/assets/jak2/update-text-from-jak1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Jak 2 shares many of the same custom menu strings as jak 1 obviously
# this is to copy them over so they are already translated.

# TODO - make it enumerate all languages

import json


with open("temp-text-id-mapping.json", "r", encoding="utf-8") as f:
mapping = json.load(f)

with open("./text/game_custom_text_en-US.json", "r", encoding="utf-8") as f:
jak2_file = json.load(f)

with open("../jak1/text/game_custom_text_en-US.json", "r", encoding="utf-8") as f:
jak1_file = json.load(f)

for jak2_id, jak1_id in mapping.items():
jak2_file[jak2_id] = jak1_file[jak1_id].title()

with open("./text/game_custom_text_en-US.json", "w", encoding="utf-8") as f:
json.dump(jak2_file, f, indent=2)
31 changes: 28 additions & 3 deletions game/kernel/common/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common/log/log.h"
#include "common/symbols.h"
#include "common/util/FileUtil.h"
#include "common/util/FontUtils.h"
#include "common/util/Timer.h"
#include "common/util/string_util.h"

Expand Down Expand Up @@ -455,7 +456,15 @@ u64 pc_get_display_name(u32 id, u32 str_dest_ptr) {
if (name.empty()) {
return bool_to_symbol(false);
}
strcpy(Ptr<String>(str_dest_ptr).c()->data(), str_util::to_upper(name).c_str());
if (g_game_version == GameVersion::Jak1) {
// The Jak 1 font has only caps
name = str_util::to_upper(name).c_str();
}
// Encode the string to the game font
const auto encoded_name = get_font_bank_from_game_version(g_game_version)
->convert_utf8_to_game(str_util::titlize(name).c_str());
strcpy(Ptr<String>(str_dest_ptr).c()->data(), encoded_name.c_str());
strcpy(Ptr<String>(str_dest_ptr).c()->data(), str_util::titlize(encoded_name).c_str());
return bool_to_symbol(true);
}

Expand Down Expand Up @@ -600,7 +609,16 @@ u64 pc_get_controller_name(u32 id, u32 str_dest_ptr) {
if (name.empty()) {
return bool_to_symbol(false);
}
strcpy(Ptr<String>(str_dest_ptr).c()->data(), str_util::to_upper(name).c_str());

if (g_game_version == GameVersion::Jak1) {
// The Jak 1 font has only caps
name = str_util::to_upper(name).c_str();
}
// Encode the string to the game font
const auto encoded_name = get_font_bank_from_game_version(g_game_version)
->convert_utf8_to_game(str_util::titlize(name).c_str());
strcpy(Ptr<String>(str_dest_ptr).c()->data(), encoded_name.c_str());
strcpy(Ptr<String>(str_dest_ptr).c()->data(), str_util::titlize(encoded_name).c_str());
return bool_to_symbol(true);
}

Expand All @@ -624,7 +642,14 @@ u64 pc_get_current_bind(s32 bind_assignment_info, u32 str_dest_ptr) {
if (name.empty()) {
return bool_to_symbol(false);
}
strcpy(Ptr<String>(str_dest_ptr).c()->data(), str_util::to_upper(name).c_str());
if (g_game_version == GameVersion::Jak1) {
// The Jak 1 font has only caps
name = str_util::to_upper(name).c_str();
}
// Encode the string to the game font
const auto encoded_name = get_font_bank_from_game_version(g_game_version)
->convert_utf8_to_game(str_util::titlize(name).c_str());
strcpy(Ptr<String>(str_dest_ptr).c()->data(), encoded_name.c_str());
return bool_to_symbol(true);
}
// TODO - return something that lets the runtime use a translatable string if unknown
Expand Down
2 changes: 1 addition & 1 deletion goal_src/jak1/kernel/gstring.gc
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@
(define *temp-string* (new 'global 'string 256 (the string #f)))
(define *temp-string2* (new 'global 'string 256 (the string #f)))
(define *pc-cpp-temp-string*
"A conveniant place to retrieve a string from C++"
"A convenient place to retrieve a string from C++"
(new 'global 'string 256 (the-as string #f)))

(defmacro string-format (&rest args)
Expand Down
5 changes: 5 additions & 0 deletions goal_src/jak2/engine/ui/progress/progress-draw.gc
Original file line number Diff line number Diff line change
Expand Up @@ -6709,7 +6709,9 @@
(set-hud-piece-position! (-> obj sprites 3) (+ sv-64 242 s1-0) (+ s2-0 -4))
(set! sv-256 (-> *display* frames (-> *display* on-screen) global-buf))
(set! sv-272 (-> sv-256 base))
;; bar
((method-of-type hud-sprite draw) (the-as hud-sprite (-> obj sprites)) sv-256 (-> *level* default-level))
;; bar background
(draw-sprite2d-xy
sv-256
(+ s1-0 s0-0 (the int (* 230.0 (-> (the-as (pointer float) sv-208)))))
Expand All @@ -6718,8 +6720,11 @@
9
(the-as rgba sv-240)
)
;; notch
(draw (-> obj sprites 1) sv-256 (-> *level* default-level))
;; left icon
(draw (-> obj sprites 2) sv-256 (-> *level* default-level))
;; right icon
(draw (-> obj sprites 3) sv-256 (-> *level* default-level))
(let ((a3-13 (-> sv-256 base)))
(let ((v1-183 (the-as object (-> sv-256 base))))
Expand Down
25 changes: 24 additions & 1 deletion goal_src/jak2/engine/ui/text-id-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@
(progress-camera-options-first-vert #x1282)
(progress-camera-options-third-horz #x1283)
(progress-camera-options-third-vert #x1284)
(progress-reset-to-default #x1285)
(progress-normal #x1286)
(progress-inverted #x1287)
(progress-ps2-parts #x1288)
Expand All @@ -693,6 +692,30 @@
(progress-frame-rate #x128e)
(progress-misc-game-options #x128f)
(progress-speedrunner-mode #x1290)
(progress-menu-input-options #x1291)
(progress-restore-defaults #x1292)
(progress-menu-controller-options #x1293)
(progress-controller-options-select-controller #x1294)
(progress-controller-options-analog-deadzone #x1295)
(progress-controller-options-ignore-if-unfocused #x1296)
(progress-controller-options-led-hp #x1297)
(progress-controller-options-led-darkjak #x1298)
(progress-input-options-enable-keyboard #x1299)
(progress-input-options-enable-mouse #x129a)
(progress-menu-mouse-options #x129b)
(progress-mouse-options-track-camera #x129c)
(progress-mouse-options-horz-sens #x129d)
(progress-mouse-options-vert-sens #x129e)
(progress-mouse-options-player-movement #x129f)
(progress-input-options-auto-hide-cursor #x1300)
(progress-menu-reassign-binds #x1301)
(progress-reassign-binds-controller #x1302)
(progress-reassign-binds-keyboard #x1303)
(progress-reassign-binds-mouse #x1304)
(progress-multiselect-no-items-found #x1305)
(progress-keybinds-waiting-for-bind #x1306)
(progress-keybinds-unset #x1307)
(progress-unknown-option #x1308)
)
;; ---text-id

Expand Down
6 changes: 4 additions & 2 deletions goal_src/jak2/kernel-defs.gc
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,16 @@
(define-extern __pc-get-tex-remap (function int int int))

;; Input Related Functions
;; TODO - add get current controller index
(define-extern pc-get-controller-count (function int))
(define-extern pc-get-controller-name (function int string))
(define-extern pc-get-controller-name (function int string string))
(deftype bind-assignment-info (structure)
((port int32)
(device-type int32)
(for-buttons? symbol)
(input-idx int32)
(analog-min-range? symbol)))
(define-extern pc-get-current-bind (function bind-assignment-info string))
(define-extern pc-get-current-bind (function bind-assignment-info string symbol))
(define-extern pc-waiting-for-bind? (function symbol))
(define-extern pc-set-waiting-for-bind! (function int symbol symbol int none))
(define-extern pc-stop-waiting-for-bind! (function none))
Expand All @@ -177,6 +178,7 @@
(define-extern pc-set-mouse-options! (function symbol symbol symbol none))
(define-extern pc-set-mouse-camera-sens! (function float float none))
(define-extern pc-current-controller-has-led? (function symbol))
(define-extern pc-current-controller-has-rumble? (function symbol))
(define-extern pc-set-controller-led! (function int int int int none))
(define-extern pc-ignore-background-controller-events! (function symbol none))
(define-extern pc-reset-bindings-to-defaults! (function int int none))
Expand Down
4 changes: 4 additions & 0 deletions goal_src/jak2/kernel/gstring.gc
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@
;; up from 256 bytes in jak 1
(define *temp-string* (new 'global 'string 2048 (the-as string #f)))

(define *pc-cpp-temp-string*
"A convenient place to retrieve a string from C++"
(new 'global 'string 2048 (the-as string #f)))

(defmacro string-format (&rest args)
"Formats into *temp-string* and returns it, for in-place string formating.
DO NOT USE *temp-string* WITH THIS MACRO! It is read as input AFTER all of the args evaluate."
Expand Down
2 changes: 2 additions & 0 deletions goal_src/jak2/pc/pckernel.gc
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,5 @@
(defmacro adjust-game-x (x)
`(adjust-game-x-centered CENTER_X ,x))

(defmacro adjust-game-x-int (x-float)
`(the int (adjust-game-x-centered CENTER_X (the float ,x-float))))
Loading

0 comments on commit 1091040

Please sign in to comment.