Compare commits
No files matched your search
@@ -1,2 +1,3 @@
|
||||
* text=auto eol=lf
|
||||
*.bat text eol=crlf
|
||||
third_party/** -text
|
||||
@@ -62,4 +62,4 @@ jobs:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
RELEASE_TAG: ${{ github.ref_name }}
|
||||
run: |
|
||||
gh release create "$RELEASE_TAG" dist/*.zip dist/SHA256SUMS dist/QA-REPORT.json --draft --verify-tag --title "OpenBMH $RELEASE_TAG" --notes-file docs/release/1.0.9/RELEASE_NOTES.md
|
||||
gh release create "$RELEASE_TAG" dist/*.zip dist/SHA256SUMS dist/QA-REPORT.json --draft --verify-tag --title "OpenBMH $RELEASE_TAG" --notes-file docs/release/1.0.12/RELEASE_NOTES.md
|
||||
+22
-8
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(OpenBMH VERSION 1.0.9 LANGUAGES CXX C)
|
||||
project(OpenBMH VERSION 1.0.12 LANGUAGES CXX C)
|
||||
if(APPLE)
|
||||
# Enable native languages before dependencies/subdirectories inherit rules.
|
||||
enable_language(OBJC OBJCXX)
|
||||
@@ -213,6 +213,7 @@ add_library(bmhcore STATIC
|
||||
src/formats/textd.cpp
|
||||
src/formats/fbm.cpp
|
||||
src/formats/le.cpp
|
||||
src/formats/diamond_image.cpp
|
||||
src/formats/m3d.cpp
|
||||
src/formats/savestate.cpp
|
||||
src/game/schedule.cpp
|
||||
@@ -240,6 +241,7 @@ add_library(bmhcore STATIC
|
||||
src/game/matchday_setup.cpp
|
||||
src/game/prediction.cpp
|
||||
src/game/month.cpp
|
||||
src/game/search_profile.cpp
|
||||
src/game/desk.cpp
|
||||
src/game/cup.cpp
|
||||
src/game/club_info.cpp
|
||||
@@ -283,12 +285,9 @@ if(MSVC)
|
||||
endif()
|
||||
|
||||
# --- Game data launcher (src/launch): find, unpack and check the original game data ---------
|
||||
# ZIP: miniz (MIT), 7z: the C decoder of the LZMA SDK (public domain), file dialog:
|
||||
# ZIP: miniz 3.0.2 (MIT, vendored in third_party/miniz), 7z: the C decoder of the LZMA SDK (public domain), file dialog:
|
||||
# nativefiledialog-extended (zlib). All pinned; fetched like SDL2.
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(miniz
|
||||
URL https://github.com/richgel999/miniz/releases/download/3.0.2/miniz-3.0.2.zip
|
||||
URL_HASH SHA256=ada38db0b703a56d3dd6d57bf84a9c5d664921d870d8fea4db153979fb5332c5)
|
||||
FetchContent_Declare(lzma_sdk
|
||||
GIT_REPOSITORY https://github.com/ip7z/7zip.git
|
||||
GIT_TAG 24.09
|
||||
@@ -300,8 +299,9 @@ FetchContent_Declare(nfd
|
||||
GIT_REPOSITORY https://github.com/btzy/nativefiledialog-extended.git
|
||||
GIT_TAG v1.2.1
|
||||
GIT_SHALLOW TRUE)
|
||||
FetchContent_MakeAvailable(miniz lzma_sdk nfd)
|
||||
FetchContent_MakeAvailable(lzma_sdk nfd)
|
||||
|
||||
set(miniz_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/miniz") # vendored: no download that can fail
|
||||
add_library(bmh_miniz STATIC ${miniz_SOURCE_DIR}/miniz.c)
|
||||
target_include_directories(bmh_miniz PUBLIC ${miniz_SOURCE_DIR})
|
||||
set(BMH_LZMA_C ${lzma_sdk_SOURCE_DIR}/C)
|
||||
@@ -1087,9 +1087,16 @@ set(BMH_TEST_SPORTSCHAU_APP_TESTS_INPUT_1 "" CACHE PATH "External input 1 for sp
|
||||
bmh_add_data_test(NAME sportschau_app_tests REQUIRED_OPTIONS BMH_TEST_SPORTSCHAU_APP_TESTS_INPUT_1 COMMAND sportschau_app_tests "${BMH_DATA}"
|
||||
"${BMH_TEST_SPORTSCHAU_APP_TESTS_INPUT_1}")
|
||||
|
||||
# The runtime component deliberately contains only the two products and notices.
|
||||
# openbmh.dat (the game texts of the original executables, tools/diamond_constants) ships next to the programs and is copied
|
||||
# next to the built programs as well, where the game looks for it.
|
||||
foreach(product IN ITEMS openbmh_play openbmh_cli)
|
||||
add_custom_command(TARGET ${product} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/data/openbmh.dat" "$<TARGET_FILE_DIR:${product}>")
|
||||
endforeach()
|
||||
|
||||
# The runtime component deliberately contains only the two products, openbmh.dat and notices.
|
||||
install(TARGETS openbmh_play openbmh_cli RUNTIME DESTINATION . COMPONENT Runtime)
|
||||
install(FILES README.md LICENSE THIRD_PARTY_NOTICES.md ACKNOWLEDGEMENTS.md CONTRIBUTING.md
|
||||
install(FILES README.md LICENSE THIRD_PARTY_NOTICES.md ACKNOWLEDGEMENTS.md CONTRIBUTING.md data/openbmh.dat
|
||||
DESTINATION . COMPONENT Runtime)
|
||||
install(DIRECTORY docs/ DESTINATION docs COMPONENT Runtime)
|
||||
if(MSVC)
|
||||
@@ -1192,6 +1199,13 @@ add_test(NAME daily_interest_unit_tests COMMAND daily_interest_unit_tests)
|
||||
add_executable(transfer_seller_actions_tests tests/transfer_seller_actions_tests.cpp)
|
||||
target_link_libraries(transfer_seller_actions_tests PRIVATE bmhcore)
|
||||
add_test(NAME transfer_seller_actions_tests COMMAND transfer_seller_actions_tests)
|
||||
add_executable(diamond_image_tests tests/diamond_image_tests.cpp)
|
||||
target_link_libraries(diamond_image_tests PRIVATE bmhcore)
|
||||
add_test(NAME diamond_image_tests COMMAND diamond_image_tests - "${CMAKE_CURRENT_SOURCE_DIR}/data/openbmh.dat")
|
||||
bmh_add_data_test(NAME diamond_image_data_tests COMMAND diamond_image_tests "${BMH_DATA}" "${CMAKE_CURRENT_SOURCE_DIR}/data/openbmh.dat")
|
||||
add_executable(search_profile_tests tests/search_profile_tests.cpp)
|
||||
target_link_libraries(search_profile_tests PRIVATE bmhcore)
|
||||
add_test(NAME search_profile_tests COMMAND search_profile_tests)
|
||||
|
||||
add_executable(transfer_seller_app_tests tests/transfer_seller_app_tests.cpp ${BMH_APP_SESSION_SDL_SOURCE})
|
||||
target_link_libraries(transfer_seller_app_tests PRIVATE bmhui openbmh_audio ${BMH_SDL_TARGET})
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# OpenBMH
|
||||
|
||||
**Classic-Version: 1.0.9.** Die originalgetreue Linie bleibt in diesem Repository.
|
||||
**Classic-Version: 1.0.12.** Die originalgetreue Linie bleibt in diesem Repository.
|
||||
Erweiterte Ligen, die gemeinsame deutsche/englische Karriere und der Dateneditor
|
||||
werden separat als **[OpenBMH-Extended 1.0 Beta](https://github.com/Weyoune/OpenBMH-extended)** entwickelt.
|
||||
|
||||
|
||||
A faithful, standalone community reconstruction of *Bundesliga Manager Hattrick*, using the player's original installation and SDL2 interface.
|
||||
|
||||
OpenBMH 1.0 builds on v0.1.2 with reviewed bug fixes and starts directly with the original game data. Original game files, graphics, audio and manuals are not distributed. German CD-compatible BMH and verified Diamond editions are the primary release targets. Football Limited remains experimental; the older floppy executable is not supported.
|
||||
OpenBMH 1.0 builds on v0.1.2 with reviewed bug fixes and starts directly with the original game data. Original game files, graphics, audio, texts and manuals are not distributed. German CD-compatible BMH and verified Diamond editions are the primary release targets. Football Limited remains experimental; the older floppy executable is not supported.
|
||||
|
||||
This is an independent community project, with no affiliation with or endorsement by the original rights holders, the DFL or the Bundesliga. It is an engine implementation, not an official source release or a remaster.
|
||||
|
||||
@@ -15,9 +15,9 @@ This is an independent community project, with no affiliation with or endorsemen
|
||||
|
||||
Check the [releases page](https://github.com/Weyoune/openbmh/releases) for available packages and their platform notes. A Windows package uses the name `OpenBMH-<version>-windows-x64.zip`. Availability and native validation are stated for each release; source build instructions do not establish platform support on their own.
|
||||
|
||||
1. Have your own supported game installation available.
|
||||
1. Have your own supported game installation available. OpenBMH needs its asset files (texts, master database, pictures, fonts, sounds) and **either** `BMH.EXE` (`FLTD.EXE` for the English game) **or** `openbmh.dat`, which ships next to the programs in the release package and holds the game texts of the original executables; the numbers of those executables are built into OpenBMH. If both are there, the executable is used. If neither is there, OpenBMH asks for the game directory or for `BMH.EXE`.
|
||||
2. Extract the OpenBMH package into a separate directory, or alongside the game files.
|
||||
3. Start `OpenBMH` (`OpenBMH.exe` on Windows). Select the game directory or executable when prompted. A ZIP or 7z containing one game installation can also be selected.
|
||||
3. Start `OpenBMH` (`OpenBMH.exe` on Windows). Select the game directory (or `BMH.EXE`) when prompted. A ZIP or 7z containing one game installation can also be selected.
|
||||
|
||||
From a terminal in the extracted package on Linux or macOS:
|
||||
|
||||
@@ -30,7 +30,7 @@ In Windows PowerShell, use `.\OpenBMH.exe` and `.\openbmh_cli.exe` instead.
|
||||
|
||||
To report a problem, start the game with `-debug`. It then writes `openbmh-debug.log` (timestamped events, errors and refused actions) and `openbmh-stderr.log` into the `debug` sub folder of the save directory, and saves the game there after every match day (`DBG00001.FBM`, `DBG00002.FBM`, ...). Attach the log and the last save to the report.
|
||||
|
||||
Use a writable save directory and keep backups of existing games. German editions are the primary compatibility target. **Football Limited / English data support is experimental**; original V2.20 save import and some edition-specific behaviour remain limited. See the [release notes](docs/release/1.0.9/RELEASE_NOTES.md).
|
||||
Use a writable save directory and keep backups of existing games. German editions are the primary compatibility target. **Football Limited / English data support is experimental**; original V2.20 save import and some edition-specific behaviour remain limited. See the [release notes](docs/release/1.0.12/RELEASE_NOTES.md).
|
||||
|
||||
## Features and direction
|
||||
|
||||
@@ -104,7 +104,7 @@ Reports with reproducible steps, documentation corrections and focused patches a
|
||||
|
||||
## How the project was developed
|
||||
|
||||
The implementation grew from study of file formats and behaviour of a legally obtained game installation. The public repository contains independently written implementation and format documentation. It does not contain the proprietary implementation or its extracted resources.
|
||||
The implementation grew from study of file formats and behaviour of a legally obtained game installation. The public repository contains independently written implementation and format documentation. It also contains the numeric tables and constants of the Diamond edition 3.7 executable (rates, positions, prices; `src/formats/diamond_constants.inc`, generated by `tools/diamond_constants`) so that the game runs from its asset files alone. It does not contain the executable's program code or any original game text, graphics, audio or master data.
|
||||
|
||||
## License and thanks
|
||||
|
||||
|
||||
Binary file not shown.
@@ -146,7 +146,9 @@ This index includes registered and reserved names. `ListOptions` and `Help` from
|
||||
| `BuyPlayer` | player:Player | VER-KAUFEN on a market player: the offer editor |
|
||||
| `HirePlayer` | player:Player, months:int(12\|24) | VER-LEIHEN on a market player: the loan offer |
|
||||
| `OpenOffers` | player:Player | Open Offers. See current Help for behaviour and bounds. |
|
||||
| `OpenSearch` | – | Open Search. See current Help for behaviour and bounds. |
|
||||
| `ShowSearchProfile` | – | SUCHEN: your search profile as 18 values (positions, age, strength, attributes, sides, price classes) |
|
||||
| `SuggestSearchProfile` | [whole:bool], [apply:bool] | VORSCHLAG: the profile your squad asks for; `apply` stores it and lists the matching players |
|
||||
| `SetSearchProfile` | values:[18 numbers], [apply:bool] | SUCHEN: store the profile; all values 0 or all 1 count as no search; `apply` lists the players on the transfer list that fit (the original's "Spieler ... ist interessant!" boxes) |
|
||||
| `OpenPoach` | – | ABWERBEN: pick a player of another club (Transfer.Poach) |
|
||||
| `ShowTransferNews` | [count:int] | Show Transfer News. See current Help for behaviour and bounds. |
|
||||
| `ShowTeamInfo` | – | Show Team Info. See current Help for behaviour and bounds. |
|
||||
|
||||
@@ -209,7 +209,9 @@
|
||||
"Transfer";"BuyPlayer";"player:Player";"VER-KAUFEN on a market player: the offer editor";"E_RULE";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"HirePlayer";"player:Player, months:int(12|24)";"VER-LEIHEN on a market player: the loan offer";"E_RULE";"";"";"ready";"06-verein.md"
|
||||
"Transfer";"OpenOffers";"player:Player";"Open Offers. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"OpenSearch";"–";"Open Search. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"ShowSearchProfile";"–";"SUCHEN: your search profile as 18 values";"";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"SuggestSearchProfile";"[whole:bool], [apply:bool]";"VORSCHLAG: the profile your squad asks for; apply stores it and lists the matches";"E_RULE";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"SetSearchProfile";"values:[18 numbers], [apply:bool]";"SUCHEN: store the search profile; apply lists the matching players";"E_BAD_ARGUMENT";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"OpenPoach";"–";"ABWERBEN: pick a player of another club (Transfer.Poach)";"—";"";"";"ready";"06-verein.md"
|
||||
"Transfer";"ShowTransferNews";"[count:int]";"Show Transfer News. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md"
|
||||
"Transfer";"ShowTeamInfo";"–";"Show Team Info. See current Help for behaviour and bounds.";"—";"";"";"partial";"06-verein.md"
|
||||
|
||||
|
@@ -0,0 +1,75 @@
|
||||
# Measurement against Diamond 3.7: matchdays, weekly processing, month change, season end
|
||||
|
||||
OpenBMH Classic follows the game and match engine of BMH 2026-27 DIAMOND Edition 3.7. Besides the routine-by-routine
|
||||
comparisons (see the 1.0.9 release notes) the engine is checked against **recordings of the real 3.7** running in an
|
||||
emulator (DOSBox-X). A recorder reads the emulator's memory without touching the game: at every match minute, at every
|
||||
change of the calendar day and at every pause it stores the random number states (game and C library generator) and all
|
||||
tables the engine reads (squads, player words, team flags, cards, managers, stock market, transfer list, mailbox, ...).
|
||||
The port replays the same turn from the save game that precedes it and is compared at every one of these checkpoints.
|
||||
|
||||
The recorder and the automation that operates the original are not part of this repository (they need the original
|
||||
program); the checker is `tests/week_check.cpp`.
|
||||
|
||||
## Scope of the November 2026 series
|
||||
|
||||
- 73 recorded "Weiter" turns of one career, from the first Saturday in August 2026 (game day 38) through the whole
|
||||
first season, the season end on 1 July 2027 (day 365) and most of the second season up to April 2028 (day 645).
|
||||
The human manager's club played every matchday (league, cup and the indoor tournament). Incoming transfer offers
|
||||
were declined.
|
||||
- **Match phase:** 7,642 recorded match minutes, every one inside the interval of random draws that the port passes
|
||||
through, none outside. Final whistle, stoppage time and the first extra-time pass match in every turn, in the second
|
||||
season as well.
|
||||
- **Weekly processing:** 70 runs of the routine ported from the original (days 43 to 645). At the desk after each turn
|
||||
the random states and **all tables are identical** to the recording.
|
||||
- **Month change:** 17 runs (1 September 2026 to 1 April 2028, among them the change of the year and the summer break).
|
||||
Identical at the desk afterwards.
|
||||
- **Season end:** one run (day 365 with the last weekly processing and the month change, from the last matchday of the
|
||||
season on 8 May 2027 to the desk of 1 July 2027). Identical, all tables.
|
||||
- **Indoor tournament:** eleven rounds (see below).
|
||||
- Training, the stock market, the matchday preparation and the kick-off of the next matchday are part of the same turns
|
||||
and match as well (the match groups built by the port equal the first minute snapshot of the next matchday).
|
||||
|
||||
Of the 73 evaluated turns 71 are identical at the desk (random states and all tables; the transfer list is shown
|
||||
separately, see below). The other two are explained:
|
||||
|
||||
- One differs in a single lineup flag of one player slot that the original clears when the manager's lineup page is
|
||||
shown (a routine of the user interface, not of the engine); the recording passed through that page.
|
||||
- The last round of the indoor tournament ends with the tournament processing of the original (prizes, next
|
||||
fixtures); the checker replays only the playing part of an indoor round, so that part is not compared.
|
||||
|
||||
## Indoor tournament
|
||||
|
||||
All eleven recorded rounds play their 40 minutes with the same random draws as the original. At the kick-off, however,
|
||||
the six strength values of the side records differ by 1 to 4 points in about half of the rounds (the port is mostly
|
||||
higher); ordinary matches show no such difference. This is tracked as issue 82. The desk after the round is identical in
|
||||
ten of eleven rounds (the eleventh is the tournament end above).
|
||||
|
||||
## How to read the "DIFF" lines of the checker
|
||||
|
||||
The recorder takes a day snapshot when the date changes, i.e. **inside** the original's processing of that day; the
|
||||
port's state belongs to the end of the processing. The checker therefore prints such checkpoints as "late snapshot ...
|
||||
draws ahead of the port's state, not counted". They are not differences of the engine: the checkpoint after them (and the
|
||||
desk at the end of the turn) is identical in every counted turn. The transfer list is compared but not counted (the
|
||||
amounts of new bids depend on stale data in the original, documented in the source); a few desks show a handful of
|
||||
bytes there and the line says so.
|
||||
|
||||
## Recordings that were not used
|
||||
|
||||
Four turns of the series were dropped, none because of a difference of the engine: two were disturbed by the operation
|
||||
of the original (a mouse click that listed two players for transfer; a turn that clicked through several matchdays
|
||||
and did not keep the recorder running), two belong to the start of the second season before the first matchday
|
||||
(the season start screens with the Super Cup; no minutes were recorded). A first recording of the season end failed
|
||||
because the recorder gave up after 60 s of the long end-of-season processing; recorded again with a longer wait it
|
||||
matches.
|
||||
|
||||
## Not covered
|
||||
|
||||
- Only one career and one human manager. Contract expiry on 1 July and the other manager decisions at the season end
|
||||
were not driven by a human in this series.
|
||||
- The start of the second season between the desk of 1 July and the first matchday (Super Cup, season start screens)
|
||||
was played without recording.
|
||||
- Offers made by the weekly processing to the human manager (new transfer bids): the amounts depend on a stale stack
|
||||
value in the original and are not reproduced (documented in the source).
|
||||
- Foul and card chances are derived from the constants of the 3.7 code and show no difference in the recorded
|
||||
minutes, but a deliberate comparison of the single routine was not made.
|
||||
- A second season end and later seasons; the end of the indoor tournament.
|
||||
@@ -0,0 +1,61 @@
|
||||
# OpenBMH Classic 1.0.10
|
||||
|
||||
This release adds the transfer market search dialog, fixes the "Angebot" button
|
||||
of the poaching dialog and corrects the asking price shown in the market. It
|
||||
requires the player's own game installation. Extended development remains
|
||||
separate in [OpenBMH-Extended](https://github.com/Weyoune/OpenBMH-extended).
|
||||
|
||||
## Changes since 1.0.9
|
||||
|
||||
- **Suchen and Vorschlag in the transfer market.** Both buttons did nothing.
|
||||
They now open the search profile dialog of the original (positions, age,
|
||||
strength, attributes, sides, price classes). "Suchen" opens the stored
|
||||
profile, "Vorschlag" the profile your squad asks for. Closing with the
|
||||
confirm button stores the profile and announces the listed players that
|
||||
fit, one message box each; the right mouse button or Esc closes it and
|
||||
switches the search off. The rules (closing rule, matching, suggestion) were
|
||||
compared with the Diamond 3.7 routines on ten savegames without a
|
||||
difference. The console has the same steps: `ShowSearchProfile`,
|
||||
`SuggestSearchProfile`, `SetSearchProfile`.
|
||||
- **Abwerben: "Angebot" button.** Two causes. The engine asks the selling
|
||||
manager and the buyer a yes/no question when a poaching offer is decided;
|
||||
the graphical client did not provide the question dialog. And the agreement
|
||||
of the poached player ("Ihr erstes Angebot wird angenommen!") had no message
|
||||
dialog, which refused the whole offer. Both exist now. A refused offer or
|
||||
transfer action also shows its reason (and writes it to the debug log)
|
||||
instead of a dead button.
|
||||
- **Verkaufen on a listed player.** Clicking a player who is already on the transfer
|
||||
list and then VERKAUFEN did nothing when no offer had arrived yet. It now asks
|
||||
the question of the original, "Wollen Sie ... vom Transfermarkt holen?": yes takes
|
||||
the player off the list (he stays in the squad), no leads on to the offers.
|
||||
- **Pressed buttons.** Suchen, Vorschlag, Abwerben and the other buttons of
|
||||
the market are drawn pressed while the mouse button is held.
|
||||
- **Scouting message.** Confirming the search dialog first shows the message
|
||||
of the scouting department, then one box per fitting listing.
|
||||
- **Asking price in the market list.** The list showed the asking fee scaled
|
||||
by 1.25, the factor of an older Diamond build. Diamond 3.7 rounds to whole
|
||||
10,000 (the offer editor and the weekly processing already did).
|
||||
- **Tests.** The controller tests now drive the whole route of reviewing and
|
||||
accepting offers on an own listing, of relisting a player after a declined
|
||||
listing and of the search dialog.
|
||||
|
||||
## Open points
|
||||
|
||||
- **"Angebote prüfen" / listing again after a declined offer.** Reported by the
|
||||
Diamond author. The console and the controller tests show the expected
|
||||
behaviour (offers can be reviewed and accepted before expiry; a player who
|
||||
left the list after a decline can be listed again). It could not be
|
||||
reproduced, so a debug log (`-debug`) or exact steps are still needed.
|
||||
- **Measurement against Diamond 3.7.** The match engine (minute, duels, shots)
|
||||
and the whole weekly processing with the bid amounts are not yet compared
|
||||
with the real 3.7. The bid amounts of new offers depend on stale data in the
|
||||
original and cannot be reproduced exactly (documented in the source).
|
||||
- Earlier open points remain: "player card: original atlas bounds" (#77), sporadic
|
||||
double clicks (#58) and the macOS match scene speed (#70).
|
||||
|
||||
## Known limits
|
||||
|
||||
The compatibility and long-career limits documented for
|
||||
[1.0.3](../1.0.3/RELEASE_NOTES.md) remain. Football Limited is experimental;
|
||||
its original V2.20 save layout remains unsupported. Keep backups of saves.
|
||||
macOS packages are unsigned terminal executables, not notarised app bundles.
|
||||
@@ -0,0 +1,87 @@
|
||||
# OpenBMH Classic 1.0.11
|
||||
|
||||
This release lets the game run from the asset files alone, adds the transfer
|
||||
market search dialog, fixes the "Angebot" button of the poaching dialog and the
|
||||
selling of a listed player, and corrects the asking price shown in the market.
|
||||
Extended development remains separate in
|
||||
[OpenBMH-Extended](https://github.com/Weyoune/OpenBMH-extended).
|
||||
|
||||
## BMH.EXE or openbmh.dat
|
||||
|
||||
- A game needs its asset files and **either** the executable (`BMH.EXE`, or
|
||||
`FLTD.EXE` for the English game) **or** the file **openbmh.dat**. If both are
|
||||
there, the executable is used as before. If neither is there, OpenBMH asks for
|
||||
a game directory or for `BMH.EXE`.
|
||||
- The numbers of the Diamond 3.7 executable (tables, rates, positions, prices) and
|
||||
of the English Football Limited are built into the program. `openbmh.dat` holds
|
||||
the game texts of those executables (live commentary, messages). It ships next
|
||||
to `OpenBMH` and `openbmh_cli` in the release package and is found in the
|
||||
game folder, in the program folder and in the current folder (or where
|
||||
`OPENBMH_DAT` points to). A folder, ZIP or 7z with only the asset files
|
||||
(`TEXTD.BLK` and `M3D.MAN`, or `TEXTE.BLK` and `M3E.MAN`, plus the
|
||||
picture, font and sound folders) is a complete game when `openbmh.dat` is
|
||||
found.
|
||||
- The default manager name is "OpenBMH" instead of "Nobody".
|
||||
- A recorded session gives the same output as with the real `BMH.EXE`.
|
||||
## Changes since 1.0.9 (1.0.10 was never published; its changes are part of this release)
|
||||
|
||||
- **Suchen and Vorschlag in the transfer market.** Both buttons did nothing.
|
||||
They now open the search profile dialog of the original (positions, age,
|
||||
strength, attributes, sides, price classes). "Suchen" opens the stored
|
||||
profile, "Vorschlag" the profile your squad asks for. Closing with the
|
||||
confirm button stores the profile and announces the listed players that
|
||||
fit, one message box each; the right mouse button or Esc closes it and
|
||||
switches the search off. The rules (closing rule, matching, suggestion) were
|
||||
compared with the Diamond 3.7 routines on ten savegames without a
|
||||
difference. The console has the same steps: `ShowSearchProfile`,
|
||||
`SuggestSearchProfile`, `SetSearchProfile`.
|
||||
- **Abwerben: "Angebot" button.** Two causes. The engine asks the selling
|
||||
manager and the buyer a yes/no question when a poaching offer is decided;
|
||||
the graphical client did not provide the question dialog. And the agreement
|
||||
of the poached player ("Ihr erstes Angebot wird angenommen!") had no message
|
||||
dialog, which refused the whole offer. Both exist now. A refused offer or
|
||||
transfer action also shows its reason (and writes it to the debug log)
|
||||
instead of a dead button.
|
||||
- **Verkaufen on a listed player.** Clicking a player who is already on the transfer
|
||||
list and then VERKAUFEN did nothing when no offer had arrived yet. It now asks
|
||||
the question of the original, "Wollen Sie ... vom Transfermarkt holen?": yes takes
|
||||
the player off the list (he stays in the squad), no leads on to the offers.
|
||||
- **Pressed buttons.** Suchen, Vorschlag, Abwerben and the other buttons of
|
||||
the market are drawn pressed while the mouse button is held.
|
||||
- **Scouting message.** Confirming the search dialog first shows the message
|
||||
of the scouting department, then one box per fitting listing.
|
||||
- **Asking price in the market list.** The list showed the asking fee scaled
|
||||
by 1.25, the factor of an older Diamond build. Diamond 3.7 rounds to whole
|
||||
10,000 (the offer editor and the weekly processing already did).
|
||||
- **Tests.** The controller tests now drive the whole route of reviewing and
|
||||
accepting offers on an own listing, of relisting a player after a declined
|
||||
listing and of the search dialog.
|
||||
|
||||
## Measurement against Diamond 3.7
|
||||
|
||||
- The match engine of a recorded matchday in the real 3.7 (DOSBox-X) matches the
|
||||
port in all 94 minutes, with the random number state at kick-off, in every
|
||||
minute, at the final whistle and at the next desk.
|
||||
- Two apparent deviations (from minute 10, and on the days after the match) were
|
||||
errors of the comparison tool, not of the engine, and are fixed or explained there.
|
||||
|
||||
## Open points
|
||||
|
||||
- **"Angebote prüfen" / listing again after a declined offer.** Reported by the
|
||||
Diamond author. The console and the controller tests show the expected
|
||||
behaviour. It could not be reproduced, so a debug log (`-debug`) or exact
|
||||
steps are still needed.
|
||||
- The bid amounts of new offers in the weekly processing depend on stale data in
|
||||
the original and cannot be reproduced exactly (documented in the source).
|
||||
- Only one matchday and the days after it were recorded from the real 3.7; the
|
||||
weekly processing, month changes and transfers are not yet compared.
|
||||
- The graphical client has not yet been tried with `openbmh.dat` and asset files only.
|
||||
- Earlier open points remain: "player card: original atlas bounds" (#77), sporadic
|
||||
double clicks (#58) and the macOS match scene speed (#70).
|
||||
|
||||
## Known limits
|
||||
|
||||
The compatibility and long-career limits documented for
|
||||
[1.0.3](../1.0.3/RELEASE_NOTES.md) remain. Football Limited is experimental;
|
||||
its original V2.20 save layout remains unsupported. Keep backups of saves.
|
||||
macOS packages are unsigned terminal executables, not notarised app bundles.
|
||||
@@ -0,0 +1,83 @@
|
||||
# OpenBMH Classic 1.0.12
|
||||
|
||||
This release makes the buttons of the dialogs behave like the original: a button
|
||||
without a lasting state is drawn pressed while the mouse button is held. It also
|
||||
carries everything of [1.0.11](../1.0.11/RELEASE_NOTES.md) (the game from asset
|
||||
files plus `openbmh.dat`, the transfer market search, the poaching and selling
|
||||
fixes). Extended development remains separate in
|
||||
[OpenBMH-Extended](https://github.com/Weyoune/OpenBMH-extended).
|
||||
|
||||
## Pressed buttons
|
||||
|
||||
Many dialogs drew their buttons raised at all times, the original shows them
|
||||
pressed for as long as the mouse button is down (the friendly match question
|
||||
already did). Now pressed while held:
|
||||
|
||||
- **Bank:** the two buttons of stocks, property, savings and credit, the OK of
|
||||
its notices, Ja/Nein of the credit fee question and the keys of its calculator.
|
||||
- **Spieler kaufen (offer editor):** Team-Info, Spieler-Info, Angebot, Abbruch and
|
||||
the calculator keys.
|
||||
- **Aufstellung:** Daten A/B and Spielfeld; **Spielfeld page:** Daten and Kurz
|
||||
(the action starts after a short moment, as the pressed look has to be seen).
|
||||
- **Contracts:** the buttons under the offer and the team premium panels
|
||||
(Team-Prämien), OK of the answer and the calculator keys.
|
||||
- **Advertising:** Abbrechen/Annehmen of an offer, OK of its notices and the keys of
|
||||
its calculator.
|
||||
- **Player card:** Schließen, Statistik and Zurück; **training camp:** the booking
|
||||
button and OK; **file dialog:** Ja/Nein of the overwrite question and the page
|
||||
button of a long list; **manager confirmation:** JA and NEIN; **transfer
|
||||
decision:** OK of the confirmation.
|
||||
- **Start menu (game setup):** the minus and plus buttons show the original's
|
||||
darker pressed picture while the mouse button is held (also in the joining
|
||||
manager's setup). It is a different picture (36x36 pixels, drawn two pixels right
|
||||
and down of the raised button on the plain background), not a shifted copy of the
|
||||
button, and was compared pixel for pixel with a recording of the real game.
|
||||
- The notices that wait for any click (Sportschau, cup draw, game end screens) have
|
||||
no button and are unchanged. Toggles that stay on (training, filters) keep their
|
||||
lasting state.
|
||||
|
||||
## Transfer market
|
||||
|
||||
- **Verkaufen on a listed player chosen in the market list.** Choosing an own listed
|
||||
player in the right-hand list and pressing VERKAUFEN gave "Noch keine Angebote"
|
||||
(or went straight to the offers) instead of the question of the original,
|
||||
"Wollen Sie ... vom Transfermarkt holen?". It now asks first, as it already did for
|
||||
a player chosen in the squad list: yes takes him off the list, no leads on to the
|
||||
offers.
|
||||
|
||||
- **No status text in the footer.** The transfer market replaced the club name in the
|
||||
bottom row with status texts (rejections, hints). The original has no such line; the
|
||||
club name now always stays there.
|
||||
|
||||
- **League table: club names in full.** Names were cut after about 17 characters
|
||||
("EINTRACHT FRANKFU"); the original shows them completely ("EINTRACHT FRANKFURT",
|
||||
"TSG 1899 HOFFENHEIM") and lets the games column cover what reaches into it.
|
||||
|
||||
## Internal
|
||||
|
||||
- The drawing of the wide push button, of the calculator window (panel and keys) and
|
||||
of the dialog frame is now shared (`ui/button_frame.hpp`,
|
||||
`ui/calculator_widgets.hpp`, `ui/dialog_frame.hpp`) instead of being copied in
|
||||
about twenty dialogs. A test compares the shared drawing pixel for pixel with the
|
||||
former one. A few buttons whose former drawing differs by one pixel (statistics
|
||||
rankings, team statistics, opportunities, analytics) were left as they are.
|
||||
|
||||
## Open points
|
||||
|
||||
- The pressed look was checked by tests and by reading the drawing code, not yet
|
||||
against a recording of the real Diamond 3.7; the exact timing of the short press on
|
||||
the Spielfeld page is an estimate.
|
||||
- **"Angebote prüfen" / listing again after a declined offer.** Could not be
|
||||
reproduced; a debug log (`-debug`) or exact steps are still needed.
|
||||
- The graphical client has not yet been tried with `openbmh.dat` and asset files only.
|
||||
- The weekly processing, month changes and transfers are not yet compared with the
|
||||
real 3.7 (only one matchday and the days after it were).
|
||||
- Earlier open points remain: "player card: original atlas bounds" (#77), sporadic
|
||||
double clicks (#58) and the macOS match scene speed (#70).
|
||||
|
||||
## Known limits
|
||||
|
||||
The compatibility and long-career limits documented for
|
||||
[1.0.3](../1.0.3/RELEASE_NOTES.md) remain. Football Limited is experimental;
|
||||
its original V2.20 save layout remains unsupported. Keep backups of saves.
|
||||
macOS packages are unsigned terminal executables, not notarised app bundles.
|
||||
@@ -4440,9 +4440,21 @@ std::optional<TransferActionResult> CareerSession::dispatch_transfer_market(
|
||||
TransferActionResult result;
|
||||
if (request.kind == ui::TransferMarketRequestKind::review_offers) {
|
||||
const auto view = project_transfer_offer_list(next_state, request.bid.list_entry);
|
||||
const int selected = view.offer_count ? review(next_state, view) : -1;
|
||||
result.player = view.player; result.list_entry = view.list_entry;
|
||||
result.status = TransferActionStatus::pending;
|
||||
// VERKAUFEN on a listed player: "Wollen Sie <name> vom Transfermarkt holen?". Yes frees the list
|
||||
// slot (the player stays in the squad), no goes on to the offers.
|
||||
bool withdrawn = false;
|
||||
if (request.ask_withdraw && hooks.confirm) {
|
||||
const std::string question = message_text(next_state, ::bmh::layout::TransferMarket_WithdrawQuestion_TextPointer) +
|
||||
next_state.player_name(view.player) +
|
||||
message_text(next_state, ::bmh::layout::TransferMarket_WithdrawQuestion_TextPointer2);
|
||||
if (hooks.confirm(next_state, request.manager_slot, question)) {
|
||||
next_state.squad_slots.at(0xb70u + size_t(view.list_entry)) = 0xfff;
|
||||
withdrawn = true;
|
||||
}
|
||||
}
|
||||
const int selected = !withdrawn && view.offer_count ? review(next_state, view) : -1;
|
||||
if (selected != -1) {
|
||||
auto allocator = TransferAllocatorContext::unsupported;
|
||||
if (turn_driver_.transfer_allocator_context == PendingOfferAllocatorGate::zero)
|
||||
@@ -6026,6 +6038,38 @@ bool CareerSession::apply_desk_setting(int manager, bool price, int index, int v
|
||||
return true;
|
||||
}
|
||||
|
||||
// The stored search profile of a manager slot (all zero for an invalid slot).
|
||||
SearchProfile CareerSession::search_profile(int manager) const { return bmh::search_profile(g_, manager); }
|
||||
|
||||
// The profile "Vorschlag" proposes for the manager's squad; nothing is stored.
|
||||
SearchProfile CareerSession::suggest_search_profile(int manager, bool whole_squad) const {
|
||||
return bmh::suggest_search_profile(g_, manager, whole_squad);
|
||||
}
|
||||
|
||||
// Stores an edited search profile like the closing dialog does and, with `apply`, returns the transfer-list entries
|
||||
// that fit it. Only the active manager of a club with a transfer market may do this, and not while another window
|
||||
// owns the session. The revision rises only when the stored bytes changed.
|
||||
std::optional<CareerSession::SearchProfileDispatch> CareerSession::dispatch_search_profile(int manager,
|
||||
const SearchProfile& profile, bool cancelled, bool apply, uint64_t& revision, std::string& error) {
|
||||
if (balance_draft_ || balance_dispatch_active_ || strengths_owner_ || strengths_dispatch_active_ ||
|
||||
top_scorers_owner_ || top_scorers_dispatch_active_ || stadium_.block_expansion || other_games_owner_ ||
|
||||
other_games_dispatch_active_ || transfer_offer_editor_ || market_dispatch_active_ ||
|
||||
pending_offer_dispatch_active_ || calendar_advance_active_) { error = "search_profile_blocked"; return std::nullopt; }
|
||||
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() || g_.manager_teams[size_t(manager)] == kNoTeam ||
|
||||
!g_.memory.has(::bmh::layout::ActiveManager) || g_.memory.u8(::bmh::layout::ActiveManager) != manager ||
|
||||
revision == std::numeric_limits<uint64_t>::max()) { error = "invalid_search_profile_owner"; return std::nullopt; }
|
||||
if (!search_profile_valid(profile)) { error = "invalid_search_profile"; return std::nullopt; }
|
||||
const auto before = bmh::search_profile(g_, manager);
|
||||
SearchProfileDispatch result;
|
||||
result.active = set_search_profile(g_, manager, profile, cancelled);
|
||||
const auto stored = bmh::search_profile(g_, manager);
|
||||
result.profile = stored;
|
||||
if (stored != before) ++revision;
|
||||
if (apply) result.hits = search_profile_hits(g_, manager);
|
||||
error.clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
// Validates the owner and the price range (8-25) and applies the ticket price; revision plus one.
|
||||
bool CareerSession::dispatch_ticket_price(const TicketPriceRequest& request, uint64_t& revision,
|
||||
std::string& error) {
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "game/pending_offer.hpp"
|
||||
#include "game/poach.hpp"
|
||||
#include "game/human_buyer_sale.hpp"
|
||||
#include "game/search_profile.hpp"
|
||||
#include "game/weekly.hpp"
|
||||
#include "ui/flow.hpp"
|
||||
#include "ui/desk_state.hpp"
|
||||
@@ -178,6 +179,21 @@ public:
|
||||
uint64_t& revision, std::string& error,
|
||||
const std::function<int(const GameState&, const TransferOfferListView&)>& review = {});
|
||||
|
||||
// The search profile of a human manager (transfer market buttons "Suchen" and "Vorschlag", game/search_profile.hpp).
|
||||
// `search_profile` is the stored profile, `suggest_search_profile` the one the squad asks for (nothing is stored).
|
||||
// `dispatch_search_profile` stores an edited profile the way the closing dialog does (`cancelled` = left by right
|
||||
// click, which switches the profile off) and, with `apply`, lists the transfer-list entries that fit it right now.
|
||||
// The revision rises only when the stored profile changed.
|
||||
SearchProfile search_profile(int manager) const;
|
||||
SearchProfile suggest_search_profile(int manager, bool whole_squad) const;
|
||||
struct SearchProfileDispatch {
|
||||
SearchProfile profile{};
|
||||
bool active = false;
|
||||
std::vector<SearchProfileHit> hits;
|
||||
};
|
||||
std::optional<SearchProfileDispatch> dispatch_search_profile(int manager, const SearchProfile& profile, bool cancelled,
|
||||
bool apply, uint64_t& revision, std::string& error);
|
||||
|
||||
struct TransferMarketPreviewDispatch {
|
||||
ui::PreparationState preparation;
|
||||
ui::TransferMarketPreview quote;
|
||||
|
||||
+45
-5
@@ -542,6 +542,40 @@ void serve_transfer_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Search dialog closed (Suchen / Vorschlag): store the profile; with apply, the listings that fit are announced one
|
||||
// by one through the notice presenter, like the original's message boxes. Only a changed profile raises the revision.
|
||||
if (request.kind == ui::TransferMarketRequestKind::store_search_profile) {
|
||||
if (entry_policy != HumanBuyerMarketEntryPolicy::normal_interactive) {
|
||||
flow.reject_preparation_action("Der Original-Suchdialog ist in diesem Einstieg nicht verfügbar.");
|
||||
return;
|
||||
}
|
||||
std::string error;
|
||||
const uint64_t before = revision;
|
||||
const bool stored = TransferActions(session).apply(revision, [&] {
|
||||
const auto result = session.dispatch_search_profile(request.manager_slot, request.search_profile,
|
||||
request.search_cancelled, request.search_apply, revision, error);
|
||||
if (!result) return false;
|
||||
// Confirming ("Suchen") first reports that the scouting department looks (Source sub_19409 sub_57ECA with
|
||||
// the scouting text), then one box per listing that fits.
|
||||
if (presenters.notice && request.search_apply)
|
||||
presenters.notice(session.state(), HumanBuyerSaleNotice{request.manager_slot, -1, -1,
|
||||
::bmh::layout::Month_SearchProfileNews_TextPointer4,
|
||||
message_text(session.state(), ::bmh::layout::Month_SearchProfileNews_TextPointer4), 0x40});
|
||||
if (presenters.notice)
|
||||
for (const auto& hit : result->hits)
|
||||
presenters.notice(session.state(), HumanBuyerSaleNotice{request.manager_slot, hit.entry, -1,
|
||||
::bmh::layout::Month_SearchProfileNews_TextPointer3, hit.message, 0x40});
|
||||
return true;
|
||||
});
|
||||
if (!stored) {
|
||||
flow.reject_preparation_action("Das Suchprofil konnte nicht gespeichert werden.");
|
||||
} else if (revision != before) {
|
||||
flow.acknowledge_preparation(session.preparation_projection(revision), {});
|
||||
} else {
|
||||
flow.acknowledge_unchanged_transfer_market();
|
||||
}
|
||||
return;
|
||||
}
|
||||
// All other kinds (bid, list, review offers): run through TransferActions::market with the
|
||||
// sale hooks. The notice presenter is wrapped to remember whether a notice was shown, so the
|
||||
// callback can keep the original notice/acknowledge order.
|
||||
@@ -571,7 +605,8 @@ void serve_transfer_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
notice = applied.action.status == TransferActionStatus::accepted
|
||||
? "Das Angebot wurde angenommen."
|
||||
: applied.action.status == TransferActionStatus::pending
|
||||
? "Spieler bleibt auf der Transferliste."
|
||||
? (applied.changed ? "Spieler wurde von der Transferliste genommen."
|
||||
: "Spieler bleibt auf der Transferliste.")
|
||||
: "Angebot abgelehnt; Transferliste unverändert.";
|
||||
}
|
||||
if (!applied.changed && source_finished) flow.acknowledge_unchanged_transfer_market();
|
||||
@@ -579,8 +614,10 @@ void serve_transfer_action(ui::StartupFlow& flow, CareerSession& session,
|
||||
else flow.acknowledge_preparation(session.preparation_projection(revision), std::move(notice));
|
||||
}, review);
|
||||
if (!outcome) throw FormatError(error);
|
||||
} catch (const std::exception&) {
|
||||
flow.reject_preparation_action("Diese Transferaktion konnte nicht übernommen werden.");
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "transfer action: %s\n", e.what());
|
||||
if (app::debug::enabled()) app::debug::log(std::string("transfer action refused: ") + e.what());
|
||||
flow.reject_preparation_action(std::string("Diese Transferaktion konnte nicht übernommen werden (") + e.what() + ").");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,8 +642,11 @@ void serve_transfer_offer(ui::StartupFlow& flow, CareerSession& session,
|
||||
flow.acknowledge_transfer_offer(std::move(applied.preparation), std::move(applied.editor));
|
||||
});
|
||||
if (!result) throw FormatError(error);
|
||||
} catch (const std::exception&) {
|
||||
flow.reject_transfer_offer("Diese Angebotsaktion konnte nicht übernommen werden.");
|
||||
} catch (const std::exception& e) {
|
||||
// The reason goes to the debug log and to stderr, and the player sees it: a refused offer must not look like a dead button.
|
||||
std::fprintf(stderr, "transfer offer: %s\n", e.what());
|
||||
if (app::debug::enabled()) app::debug::log(std::string("transfer offer refused: ") + e.what());
|
||||
flow.reject_transfer_offer(std::string("Diese Angebotsaktion konnte nicht übernommen werden (") + e.what() + ").");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
-5
@@ -461,11 +461,16 @@ int main(int argc, char** argv) {
|
||||
random = random_before;
|
||||
return -2;
|
||||
}
|
||||
// Clicks act on button release.
|
||||
if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
// Clicks act on button release; a button held down is drawn pressed meanwhile.
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
|
||||
if (screen.press(event.button.x, event.button.y)) {
|
||||
present_season(screen.render(), "OpenBMH - contracts");
|
||||
}
|
||||
} else if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) {
|
||||
changed |= screen.click(event.button.x, event.button.y,
|
||||
event.button.button == SDL_BUTTON_RIGHT);
|
||||
changed = true; // also ends a pressed look that did not lead to a change
|
||||
} else if (event.type == SDL_MOUSEMOTION) {
|
||||
changed |= screen.move(event.motion.x, event.motion.y);
|
||||
} else if (event.type == SDL_TEXTINPUT) {
|
||||
@@ -1070,6 +1075,15 @@ int main(int argc, char** argv) {
|
||||
*market_backdrop, "OpenBMH - transfer_market_notice") == PendingOfferAnswer::unsupported)
|
||||
throw std::runtime_error("transfer market presenter stopped");
|
||||
};
|
||||
// PresentManagerDialog yes/no question: poaching asks the selling manager whether the offered fee is
|
||||
// fine and the buyer whether he pays the fee the DFB sets. Without this hook the engine refuses a poaching
|
||||
// offer (the ANGEBOT button of the Abwerben dialog then does nothing).
|
||||
hooks.confirm = [&, market_backdrop](const GameState& staged, int manager, const std::string& text) {
|
||||
const auto answer = present_pending_dialog(staged, ui::loan_return_question_dialog(staged, manager, text),
|
||||
*market_backdrop, "OpenBMH - transfer_market_question");
|
||||
if (answer == PendingOfferAnswer::unsupported) throw std::runtime_error("transfer market presenter stopped");
|
||||
return answer == PendingOfferAnswer::yes;
|
||||
};
|
||||
return hooks;
|
||||
};
|
||||
// Forward declarations: the club, player and statistics presenters call each other, so
|
||||
@@ -2537,12 +2551,18 @@ int main(int argc, char** argv) {
|
||||
while (quit_confirmation.poll(&event)) {
|
||||
if (event.type == SDL_QUIT) { running = false; return; }
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT))
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) {
|
||||
decision_screen.pointer_down(event.button.button == SDL_BUTTON_RIGHT);
|
||||
else if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT))
|
||||
// OK of the confirmation looks pressed while the mouse button is held
|
||||
if (event.button.button == SDL_BUTTON_LEFT && confirmation &&
|
||||
decision_screen.press(event.button.x, event.button.y))
|
||||
rendered_phase = UINT64_MAX;
|
||||
} else if (event.type == SDL_MOUSEBUTTONUP &&
|
||||
(event.button.button == SDL_BUTTON_LEFT || event.button.button == SDL_BUTTON_RIGHT)) {
|
||||
(void)decision_screen.pointer_up(event.button.x, event.button.y,
|
||||
event.button.button == SDL_BUTTON_RIGHT, elapsed);
|
||||
if (confirmation && !decision_screen.confirmation_dismissed()) rendered_phase = UINT64_MAX;
|
||||
}
|
||||
}
|
||||
if (confirmation ? decision_screen.confirmation_dismissed() : decision_screen.outcome_dismissed()) return;
|
||||
SDL_Delay(10);
|
||||
@@ -4171,6 +4191,19 @@ int main(int argc, char** argv) {
|
||||
// Remember where the right press began, to detect releases without a matching press.
|
||||
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_RIGHT)
|
||||
right_press_screen = flow.screen_name();
|
||||
// Buttons without a lasting state look pressed while the mouse button is held (bank, offer editor,
|
||||
// lineup, pitch). The pitch runs its action at the press itself, so the pressed look is held briefly.
|
||||
if (e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT &&
|
||||
flow.press_hold(e.button.x, e.button.y)) {
|
||||
const auto image = process_timer_image(flow.render());
|
||||
for (size_t i = 0; i < pixels.size(); ++i) pixels[i] = palette.argb[image.pixels[i]];
|
||||
SDL_UpdateTexture(texture, nullptr, pixels.data(), 320 * 4);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer);
|
||||
dirty = false;
|
||||
if (flow.in_pitch()) SDL_Delay(90);
|
||||
}
|
||||
// Screens that react to the press itself get pointer_down() now.
|
||||
if(!selector_consumed&&e.type==SDL_MOUSEBUTTONDOWN&&(flow.desktop()||flow.in_balance()||flow.in_desk_records()||flow.in_achievements()||flow.in_indoor_standings()||flow.in_reschedule_calendar()||flow.in_league_pairings()||flow.in_family_table()||flow.in_toto_calculator()||flow.in_stadium()||flow.in_environment()||flow.in_strengths()||flow.in_top_scorers()||flow.in_opportunities()||flow.in_statistics_menu()||flow.in_statistics_page()||flow.in_analytics()||flow.in_other_games()||flow.in_pitch()||flow.in_settings())&&
|
||||
(e.button.button==SDL_BUTTON_LEFT||e.button.button==SDL_BUTTON_RIGHT)) {
|
||||
|
||||
@@ -202,7 +202,8 @@ std::string TransferActions::rejection(const ui::TransferMarketRequest& request,
|
||||
} else if (request.kind != ui::TransferMarketRequestKind::open_offer &&
|
||||
request.kind != ui::TransferMarketRequestKind::preview_quote &&
|
||||
request.kind != ui::TransferMarketRequestKind::open_poach &&
|
||||
request.kind != ui::TransferMarketRequestKind::review_offers)
|
||||
request.kind != ui::TransferMarketRequestKind::review_offers &&
|
||||
request.kind != ui::TransferMarketRequestKind::store_search_profile)
|
||||
return "Diese Transferaktion ist nicht verfügbar.";
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "cli/console/detail.hpp"
|
||||
#include "game/desk_actions.hpp"
|
||||
#include "game/human_buyer_sale.hpp"
|
||||
#include "game/messages.hpp"
|
||||
#include "game/poach.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "ui/club_info.hpp"
|
||||
@@ -516,8 +517,76 @@ void Console::register_transfer_commands() {
|
||||
show_offer();
|
||||
});
|
||||
|
||||
// --- the search profile (buttons Suchen / Vorschlag of the market, game/search_profile.hpp) ---------------
|
||||
// The 18 values of the profile in the order of the original dialog; the console shows and takes them as a list.
|
||||
static const char* const kProfileLabels[18] = {
|
||||
"Goalkeeper", "Defender", "Midfielder", "Forward", "AgeMin(16+)", "AgeMax(16+)", "StrengthMin", "StrengthMax",
|
||||
"AttrCondition", "AttrTechnique", "AttrForm", "Side1", "Side2", "Side3", "Side4", "PriceLow", "PriceMid", "PriceHigh"};
|
||||
auto show_profile = [this](const SearchProfile& p, const char* heading) {
|
||||
std::vector<std::vector<std::string>> rows;
|
||||
for (size_t i = 0; i < p.size(); ++i)
|
||||
rows.push_back({kProfileLabels[i], std::to_string(i == 0 ? p[i] & ~kSearchProfileOff : p[i])});
|
||||
emit_table({heading, "Value"}, rows);
|
||||
std::string list;
|
||||
for (size_t i = 0; i < p.size(); ++i) list += (i ? "," : "") + std::to_string(i == 0 ? p[i] & ~kSearchProfileOff : p[i]);
|
||||
emit('i', std::string("profile ") + (p[0] & kSearchProfileOff ? "OFF" : "active") + "; as SetSearchProfile([" + list + "])");
|
||||
};
|
||||
auto manager_slot = [market] { return market().manager_slot; };
|
||||
add({"Transfer", "ShowSearchProfile", {}, "SUCHEN: your search profile (18 values; positions, age, strength, attributes, sides, price classes)", false},
|
||||
[this, manager_slot, show_profile](const Values&) { show_profile(session_->search_profile(manager_slot()), "Search profile"); });
|
||||
add({"Transfer", "SuggestSearchProfile", {boolean("whole", true), boolean("apply", true)},
|
||||
"VORSCHLAG: the profile your squad asks for (whole = count the substitutes); apply = store it and list the matches", false},
|
||||
[this, manager_slot, show_profile, flush_notices](const Values& v) {
|
||||
const int manager = manager_slot();
|
||||
const auto suggestion = session_->suggest_search_profile(manager, v.boolean("whole", false));
|
||||
show_profile(suggestion, "Suggestion");
|
||||
if (v.boolean("apply", false)) {
|
||||
std::string error;
|
||||
const auto result = session_->dispatch_search_profile(manager, suggestion, false, true, revision_, error);
|
||||
if (!result) require_engine(false, "search profile", error);
|
||||
emit('i', utf8(message_text(session_->state(), ::bmh::layout::Month_SearchProfileNews_TextPointer4)));
|
||||
emit('+', std::to_string(result->hits.size()) + " listed player(s) fit the profile");
|
||||
for (const auto& hit : result->hits) emit('i', utf8(hit.message));
|
||||
}
|
||||
});
|
||||
Param profile_values = detail::text("values");
|
||||
profile_values.display = "values:[18 numbers] (see ShowSearchProfile)";
|
||||
add({"Transfer", "SetSearchProfile", {profile_values, boolean("apply", true)},
|
||||
"SUCHEN: store the search profile (the 18 values of ShowSearchProfile, switches 0/1, age 0..24 = 16..40, strength 0..99); apply = list the matches now", false},
|
||||
[this, manager_slot, show_profile](const Values& v) {
|
||||
std::string list = v.text("values");
|
||||
if (list.size() >= 2 && list.front() == '[' && list.back() == ']') list = list.substr(1, list.size() - 2);
|
||||
SearchProfile profile{};
|
||||
size_t count = 0, start = 0;
|
||||
while (start <= list.size()) {
|
||||
const size_t comma = list.find(',', start);
|
||||
std::string item = list.substr(start, comma == std::string::npos ? std::string::npos : comma - start);
|
||||
item.erase(0, item.find_first_not_of(' '));
|
||||
item.erase(item.find_last_not_of(' ') + 1);
|
||||
if (item.empty() || item.find_first_not_of("0123456789") != std::string::npos || item.size() > 3)
|
||||
fail("E_BAD_ARGUMENT", "the profile values are numbers separated by commas");
|
||||
if (count >= profile.size()) fail("E_BAD_ARGUMENT", "the profile has 18 values");
|
||||
profile[count++] = uint8_t(std::min(255, std::stoi(item)));
|
||||
if (comma == std::string::npos) break;
|
||||
start = comma + 1;
|
||||
}
|
||||
if (count != profile.size()) fail("E_BAD_ARGUMENT", "the profile has 18 values, not " + std::to_string(count));
|
||||
if (!search_profile_valid(profile))
|
||||
fail("E_BAD_ARGUMENT", "switches are 0 or 1, the age values 0..24 and the strength values 0..99");
|
||||
std::string error;
|
||||
const auto result = session_->dispatch_search_profile(manager_slot(), profile, false, v.boolean("apply", true), revision_, error);
|
||||
if (!result) require_engine(false, "search profile", error);
|
||||
emit('+', result->active ? "search profile stored"
|
||||
: "search profile stored but switched off (all values 0 or all 1 count as no search)");
|
||||
if (v.boolean("apply", true)) {
|
||||
emit('i', utf8(message_text(session_->state(), ::bmh::layout::Month_SearchProfileNews_TextPointer4)));
|
||||
emit('+', std::to_string(result->hits.size()) + " listed player(s) fit the profile");
|
||||
for (const auto& hit : result->hits) emit('i', utf8(hit.message));
|
||||
}
|
||||
});
|
||||
|
||||
// the rest of the market (06-verein 5): later steps of stage 3 or engine gaps
|
||||
for (const char* name : {"SetSquadView", "SetSquadSheet", "SetMarketVisible", "ShowPlayer", "OpenOffers", "OpenSearch",
|
||||
for (const char* name : {"SetSquadView", "SetSquadSheet", "SetMarketVisible", "ShowPlayer", "OpenOffers",
|
||||
"ShowTransferNews", "ShowTeamInfo"})
|
||||
add({"Transfer", name, {}, "not in the console yet", false},
|
||||
[name](const Values&) { fail("E_ENGINE_GAP", std::string(name) + " is not in the console yet"); });
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,169 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Implementation of diamond_image.hpp: the images built from the embedded numbers of the generated .inc files plus the
|
||||
// texts of openbmh.dat.
|
||||
#include "formats/diamond_image.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace bmh {
|
||||
|
||||
namespace {
|
||||
|
||||
struct Chunk { uint32_t address; uint32_t size; const uint8_t* bytes; };
|
||||
struct Range { uint32_t address; uint32_t length; };
|
||||
|
||||
namespace german {
|
||||
#include "formats/diamond_constants.inc"
|
||||
} // namespace german
|
||||
namespace english {
|
||||
#include "formats/fltd_constants.inc"
|
||||
} // namespace english
|
||||
|
||||
constexpr char kMagic[12] = "OPENBMH-DAT"; // 11 characters and the NUL
|
||||
constexpr char kFileName[] = "openbmh.dat";
|
||||
|
||||
std::string lower(std::string s) {
|
||||
for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t word(const Bytes& b, size_t at) {
|
||||
if (at + 4 > b.size()) throw FormatError("openbmh.dat: truncated");
|
||||
return uint32_t(b[at]) | uint32_t(b[at + 1]) << 8 | uint32_t(b[at + 2]) << 16 | uint32_t(b[at + 3]) << 24;
|
||||
}
|
||||
|
||||
LeImage build(uint32_t base, uint32_t size, const Chunk* first, const Chunk* last) {
|
||||
Bytes bytes(size, 0);
|
||||
for (const Chunk* chunk = first; chunk != last; ++chunk)
|
||||
std::copy(chunk->bytes, chunk->bytes + chunk->size, bytes.begin() + (chunk->address - base));
|
||||
return LeImage::from_bytes(base, std::move(bytes));
|
||||
}
|
||||
|
||||
std::filesystem::path executable_directory() {
|
||||
std::error_code ec;
|
||||
#ifdef _WIN32
|
||||
wchar_t buffer[32768];
|
||||
const DWORD n = GetModuleFileNameW(nullptr, buffer, DWORD(std::size(buffer)));
|
||||
if (n == 0 || n >= std::size(buffer)) return {};
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
#elif defined(__APPLE__)
|
||||
char buffer[4096];
|
||||
uint32_t size = sizeof buffer;
|
||||
if (_NSGetExecutablePath(buffer, &size) != 0) return {};
|
||||
return std::filesystem::weakly_canonical(buffer, ec).parent_path();
|
||||
#else
|
||||
char buffer[4096];
|
||||
const ssize_t n = readlink("/proc/self/exe", buffer, sizeof buffer - 1);
|
||||
if (n <= 0) return {};
|
||||
buffer[n] = 0;
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path file_in(const std::filesystem::path& directory) {
|
||||
if (directory.empty()) return {};
|
||||
std::error_code ec;
|
||||
for (const auto& entry : std::filesystem::directory_iterator(directory, ec))
|
||||
if (entry.is_regular_file(ec) && lower(entry.path().filename().string()) == kFileName) return entry.path();
|
||||
return {};
|
||||
}
|
||||
|
||||
void add_texts(LeImage& image, int edition, const std::filesystem::path& game_directory) {
|
||||
const auto file = find_texts_file(game_directory);
|
||||
if (file.empty()) return;
|
||||
try {
|
||||
apply_texts(image, edition, read_file(file));
|
||||
} catch (const std::exception&) {
|
||||
// a damaged texts file leaves the texts empty; the game itself still runs
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::filesystem::path find_texts_file(const std::filesystem::path& game_directory) {
|
||||
if (const char* env = std::getenv("OPENBMH_DAT"); env && *env) {
|
||||
if (std::string_view(env) == "-") return {}; // "no texts file at all" (tests of the launcher)
|
||||
std::error_code ec;
|
||||
if (std::filesystem::is_regular_file(env, ec)) return env;
|
||||
}
|
||||
for (const auto& directory : {game_directory, executable_directory(), std::filesystem::path(".")})
|
||||
if (auto file = file_in(directory); !file.empty()) return file;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string texts_signature(const std::filesystem::path& game_directory) {
|
||||
const auto file = find_texts_file(game_directory);
|
||||
if (file.empty()) return {};
|
||||
try {
|
||||
const Bytes data = read_file(file);
|
||||
uint64_t hash = 1469598103934665603ull; // FNV-1a
|
||||
for (uint8_t b : data) hash = (hash ^ b) * 1099511628211ull;
|
||||
return std::to_string(data.size()) + "-" + std::to_string(hash);
|
||||
} catch (const std::exception&) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool apply_texts(LeImage& image, int edition, const Bytes& file) {
|
||||
if (file.size() < sizeof kMagic + 4 || !std::equal(kMagic, kMagic + sizeof kMagic, file.begin()))
|
||||
throw FormatError("openbmh.dat: not an OpenBMH data file");
|
||||
const Range* known = edition == 1 ? std::begin(german::kTextRanges) : std::begin(english::kTextRanges);
|
||||
const Range* known_end = edition == 1 ? std::end(german::kTextRanges) : std::end(english::kTextRanges);
|
||||
const uint32_t sets = word(file, sizeof kMagic);
|
||||
if (sets > 16) throw FormatError("openbmh.dat: too many sets");
|
||||
size_t at = sizeof kMagic + 4;
|
||||
bool found = false;
|
||||
for (uint32_t s = 0; s < sets; ++s) {
|
||||
const uint32_t id = word(file, at), count = word(file, at + 4);
|
||||
if (count > 65536) throw FormatError("openbmh.dat: too many ranges");
|
||||
const size_t table = at + 8;
|
||||
size_t data = table + size_t(count) * 8;
|
||||
for (uint32_t n = 0; n < count; ++n) {
|
||||
const uint32_t address = word(file, table + n * 8ull), length = word(file, table + n * 8ull + 4);
|
||||
if (data + length > file.size()) throw FormatError("openbmh.dat: truncated");
|
||||
if (int(id) == edition) {
|
||||
const bool allowed = std::any_of(known, known_end,
|
||||
[&](const Range& r) { return r.address == address && length <= r.length; });
|
||||
if (!allowed) throw FormatError("openbmh.dat: a range is not a text of the game");
|
||||
image.patch(address, file.data() + data, length);
|
||||
found = true;
|
||||
}
|
||||
data += length;
|
||||
}
|
||||
at = data;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
LeImage diamond_constants_image(const std::filesystem::path& game_directory) {
|
||||
LeImage image = build(german::kImageBase, german::kImageSize, std::begin(german::kChunks), std::end(german::kChunks));
|
||||
add_texts(image, 1, game_directory);
|
||||
return image;
|
||||
}
|
||||
|
||||
LeImage english_constants_image(const std::filesystem::path& game_directory) {
|
||||
LeImage image = build(english::kImageBase, english::kImageSize, std::begin(english::kChunks), std::end(english::kChunks));
|
||||
add_texts(image, 2, game_directory);
|
||||
return image;
|
||||
}
|
||||
|
||||
bool is_executable_name(const std::filesystem::path& file_name) { return lower(file_name.string()) == "bmh.exe"; }
|
||||
|
||||
} // namespace bmh
|
||||
@@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The game without BMH.exe and FLTD.EXE: OpenBMH carries the numbers of the Diamond 3.7 executable (tables, rates,
|
||||
// positions, prices; the generated formats/diamond_constants.inc) and of the English Football Limited
|
||||
// (formats/fltd_constants.inc) and needs only the asset files of the game. The game texts that live in the executables
|
||||
// (live commentary, messages) are not part of the source: they are in the data file openbmh.dat, which ships with the
|
||||
// release next to the programs (tools/diamond_constants/generate.py makes it). Without that file those texts are empty.
|
||||
//
|
||||
// load_le() returns diamond_constants_image() for a BMH.exe that does not exist, so every reader of the executable image
|
||||
// works unchanged. A BMH.exe that is there is used as before (it carries its own edition's numbers and texts). For an
|
||||
// English installation the launcher (launch/fltd.cpp) writes english_constants_image() as the image of the game
|
||||
// directory when FLTD.EXE is missing.
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
#include "formats/le.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
// openbmh.dat: "OPENBMH-DAT" NUL, u32 set count, then per set u32 edition (1 German, 2 English), u32 range count, count
|
||||
// times (u32 address, u32 length), then the bytes of all ranges. A range must be one of the edition's text ranges, so
|
||||
// the file can never change a number of the image.
|
||||
//
|
||||
// The file is looked for in: the environment variable OPENBMH_DAT ("-" = none at all), the folder of the game data, the folder of the
|
||||
// running program, the current folder. Returns an empty path when there is none.
|
||||
std::filesystem::path find_texts_file(const std::filesystem::path& game_directory);
|
||||
|
||||
// A short text that changes when the texts file changes (empty without a file): used to rebuild cached English games.
|
||||
std::string texts_signature(const std::filesystem::path& game_directory);
|
||||
|
||||
// The German (Diamond 3.7) image built from the embedded numbers plus the texts of openbmh.dat (found for
|
||||
// `game_directory`).
|
||||
LeImage diamond_constants_image(const std::filesystem::path& game_directory = {});
|
||||
|
||||
// The English Football Limited image in the German address space (what launch::translate_fltd() makes from
|
||||
// FLTD.EXE), built from the embedded numbers plus the texts of openbmh.dat.
|
||||
LeImage english_constants_image(const std::filesystem::path& game_directory = {});
|
||||
|
||||
// Puts the texts of an openbmh.dat file (edition 1 or 2) into `image`. Throws FormatError for malformed data or for a
|
||||
// range that is not a text range of that edition. Returns false when the file has no set of that edition.
|
||||
bool apply_texts(LeImage& image, int edition, const Bytes& file);
|
||||
|
||||
// Whether `file_name` is the name of the executable (BMH.exe in any case).
|
||||
bool is_executable_name(const std::filesystem::path& file_name);
|
||||
|
||||
} // namespace bmh
|
||||
@@ -1415,6 +1415,10 @@ inline constexpr auto Month_ReturnLoans_TextPointer7 = 0xaee44;
|
||||
inline constexpr auto Month_ReturnLoans_TextPointer8 = 0xaee48;
|
||||
inline constexpr auto Month_SearchProfileNews_TextPointer = 0xaedd8;
|
||||
inline constexpr auto Month_SearchProfileNews_TextPointer2 = 0xaf254;
|
||||
inline constexpr auto Month_SearchProfileNews_TextPointer3 = 0xaf258; // ending of the message box after "Suchen"
|
||||
inline constexpr auto Month_SearchProfileNews_TextPointer4 = 0xaf25c; // "Ihre Scouting-Abteilung ...": shown first when the dialog is confirmed
|
||||
inline constexpr auto TransferMarket_WithdrawQuestion_TextPointer = 0xaf2a4; // "Wollen Sie " (+ player name)
|
||||
inline constexpr auto TransferMarket_WithdrawQuestion_TextPointer2 = 0xaf2a8; // " vom Transfermarkt holen?"
|
||||
inline constexpr auto NationalFriendlyPayerPrefixText = 0xa000f;
|
||||
inline constexpr auto NextDeskManager = 0xbd6cc;
|
||||
inline constexpr auto NoClubText = 0xaec74;
|
||||
@@ -1915,6 +1919,10 @@ inline constexpr auto TransferMarket_Rect_TextPointer2 = 0xa0045;
|
||||
inline constexpr auto TransferMarket_Rect_TextPointer3 = 0xae148;
|
||||
inline constexpr auto TransferMarket_Rect_TextPointer4 = 0xae14c;
|
||||
inline constexpr auto TransferMarket_Rect_TextPointer5 = 0xae150;
|
||||
// Search dialog (buttons Suchen / Vorschlag): seven 5-byte rows (y, step in px, cells, slider flag, profile offset)
|
||||
// and the text pointer of its confirm button.
|
||||
inline constexpr auto TransferMarket_SearchRows_RuntimeField = 0xa20fb;
|
||||
inline constexpr auto TransferMarket_SearchButton_TextPointer = 0xae144;
|
||||
inline constexpr auto TransferMarket_Rect_TextPointer6 = 0xaecac;
|
||||
inline constexpr auto TransferMarket_Rect_TextPointer7 = 0xaf250;
|
||||
inline constexpr auto TransferMarket_Render_TextPointer = 0xaf264;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+66
-1
@@ -6,7 +6,11 @@
|
||||
// LeImage::cstring() reads NUL-terminated strings from the image. No global state.
|
||||
#include "formats/le.hpp"
|
||||
|
||||
#include "formats/diamond_image.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,10 +26,63 @@ struct Object {
|
||||
|
||||
std::string LeImage::cstring(uint32_t address) const {
|
||||
std::string s;
|
||||
while (contains(address) && u8(address) != 0) s.push_back(char(u8(address++)));
|
||||
const uint32_t first = address;
|
||||
while (contains(address) && bytes_[address - base_] != 0) s.push_back(char(bytes_[address++ - base_]));
|
||||
if (le_trace::hook) le_trace::hook(first, uint32_t(s.size()) + 1, 't');
|
||||
return s;
|
||||
}
|
||||
|
||||
namespace le_trace {
|
||||
void (*hook)(uint32_t, uint32_t, char) = nullptr;
|
||||
|
||||
namespace {
|
||||
// One flag byte per image address: 1 number read, 2 string read, 4 start of a bulk read.
|
||||
std::vector<uint8_t>& marks() {
|
||||
static std::vector<uint8_t> value(0x100000, 0);
|
||||
return value;
|
||||
}
|
||||
std::string& trace_path() {
|
||||
static std::string value;
|
||||
return value;
|
||||
}
|
||||
void record(uint32_t address, uint32_t length, char kind) {
|
||||
auto& m = marks();
|
||||
const uint8_t flag = kind == 'n' ? 1 : kind == 't' ? 2 : 4;
|
||||
if (address < 0x10000 || address - 0x10000 >= m.size()) return;
|
||||
if (length == 0) length = 1;
|
||||
for (uint32_t i = 0; i < length && address - 0x10000 + i < m.size(); ++i) m[address - 0x10000 + i] |= flag;
|
||||
}
|
||||
// Appends the marked ranges ("<flag> <start> <length>" in hex, one per line) to the trace file.
|
||||
void flush() {
|
||||
if (trace_path().empty()) return;
|
||||
std::ofstream out(trace_path(), std::ios::app);
|
||||
const auto& m = marks();
|
||||
for (uint8_t flag : {uint8_t(1), uint8_t(2), uint8_t(4)}) {
|
||||
size_t i = 0;
|
||||
while (i < m.size()) {
|
||||
if (!(m[i] & flag)) { ++i; continue; }
|
||||
size_t j = i;
|
||||
while (j < m.size() && (m[j] & flag)) ++j;
|
||||
out << std::hex << unsigned(flag) << ' ' << (i + 0x10000) << ' ' << (j - i) << '\n';
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void enable_from_environment() {
|
||||
static bool done = false;
|
||||
if (done) return;
|
||||
done = true;
|
||||
if (const char* path = std::getenv("OPENBMH_LE_TRACE"); path && *path) {
|
||||
trace_path() = path;
|
||||
(void)marks(); // constructed before atexit(flush) is registered, so it is destroyed after flush has run
|
||||
hook = record;
|
||||
std::atexit(flush);
|
||||
}
|
||||
}
|
||||
} // namespace le_trace
|
||||
|
||||
namespace {
|
||||
constexpr char kImageMagic[14] = "OPENBMH-IMAGE"; // 13 characters and the NUL
|
||||
}
|
||||
@@ -41,6 +98,14 @@ void save_image(const LeImage& image, const std::filesystem::path& path) {
|
||||
}
|
||||
|
||||
LeImage load_le(const std::filesystem::path& path) {
|
||||
le_trace::enable_from_environment();
|
||||
// The game runs from its asset files alone: for a BMH.exe that is not there the embedded numbers of the Diamond 3.7 executable
|
||||
// and the texts of openbmh.dat stand in for it.
|
||||
{
|
||||
std::error_code ec;
|
||||
if (is_executable_name(path.filename()) && !std::filesystem::exists(path, ec))
|
||||
return diamond_constants_image(path.has_parent_path() ? path.parent_path() : std::filesystem::path("."));
|
||||
}
|
||||
const Bytes raw = read_file(path);
|
||||
if (raw.size() >= sizeof kImageMagic + 8 && std::equal(kImageMagic, kImageMagic + sizeof kImageMagic, raw.begin())) {
|
||||
const auto word = [&](size_t at) { return uint32_t(raw[at] | raw[at + 1] << 8 | raw[at + 2] << 16) | uint32_t(raw[at + 3]) << 24; };
|
||||
|
||||
+16
-2
@@ -16,19 +16,33 @@
|
||||
|
||||
namespace bmh {
|
||||
|
||||
// Read recording for building the embedded constants (formats/diamond_constants.inc): when the environment variable
|
||||
// OPENBMH_LE_TRACE names a file, every image read is noted (numbers, strings, bulk pointers) and appended to that
|
||||
// file when the program ends. Without the variable the hook is a null pointer and costs one branch per read.
|
||||
namespace le_trace {
|
||||
extern void (*hook)(uint32_t address, uint32_t length, char kind); // kind: 'n' number, 't' string, 'b' bulk pointer
|
||||
void enable_from_environment();
|
||||
} // namespace le_trace
|
||||
|
||||
class LeImage {
|
||||
public:
|
||||
uint32_t base() const { return base_; }
|
||||
uint32_t size() const { return uint32_t(bytes_.size()); }
|
||||
bool contains(uint32_t address) const { return address >= base_ && address - base_ < bytes_.size(); }
|
||||
uint8_t u8(uint32_t address) const { return bytes_.at(address - base_); }
|
||||
uint8_t u8(uint32_t address) const {
|
||||
if (le_trace::hook) le_trace::hook(address, 1, 'n');
|
||||
return bytes_.at(address - base_);
|
||||
}
|
||||
uint16_t u16(uint32_t address) const { return uint16_t(u8(address) | u8(address + 1) << 8); }
|
||||
uint32_t u32(uint32_t address) const { return uint32_t(u16(address)) | uint32_t(u16(address + 2)) << 16; }
|
||||
// A NUL terminated string at `address` (ISO 646-DE bytes, see textd.hpp).
|
||||
std::string cstring(uint32_t address) const;
|
||||
// The string a pointer variable at `address` points to (e.g. Weekly_AdvertisingOffers_TextPointer).
|
||||
std::string string_at_pointer(uint32_t address) const { return cstring(u32(address)); }
|
||||
const uint8_t* data(uint32_t address) const { return bytes_.data() + (address - base_); }
|
||||
const uint8_t* data(uint32_t address) const {
|
||||
if (le_trace::hook) le_trace::hook(address, 0, 'b');
|
||||
return bytes_.data() + (address - base_);
|
||||
}
|
||||
// Overwrites bytes inside a prepared image for verified address translation.
|
||||
void patch(uint32_t address, const uint8_t* bytes, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) bytes_.at(address - base_ + i) = bytes[i];
|
||||
|
||||
+3
-39
@@ -24,6 +24,7 @@
|
||||
#include "game/messages.hpp"
|
||||
#include "game/prediction.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "game/search_profile.hpp"
|
||||
#include "game/season.hpp"
|
||||
#include "game/weekly.hpp"
|
||||
#include "game/human_buyer_sale.hpp"
|
||||
@@ -915,46 +916,9 @@ ContractInsuranceResult contract_insurance(GameState& g, int manager, int row, i
|
||||
}
|
||||
|
||||
void search_profile_news(GameState& g, int manager, uint32_t list, int player) {
|
||||
const StaticMemory& mem = g.memory;
|
||||
const size_t rec = size_t(manager) * kRecord;
|
||||
auto b = [&](size_t off) { return int(g.manager_records.at(rec + off)); };
|
||||
const int team = g.manager_teams.at(size_t(manager));
|
||||
// The matching rule is shared with the search dialog (search_profile.cpp, original sub_190B5).
|
||||
player &= 0xFFF;
|
||||
if (team == kNoTeam || (mem.u16(list + 8) & 0x7FFF) == team || (b(0x1f6) & 0x40)) return;
|
||||
const uint32_t w364 = g.players.at(size_t(player)).w364, w35c = g.players.at(size_t(player)).w35c;
|
||||
// position wanted (or none selected) and age within the range
|
||||
if (b(0x1f6 + (w364 & 3)) == 0 && b(0x1f9) + b(0x1f8) + b(0x1f7) + b(0x1f6) != 0) return;
|
||||
const int age = int((w364 >> 21) & 0x1F);
|
||||
if (age < b(0x1fa) || age > b(0x1fb)) return;
|
||||
// strength by the selected attributes (condition, technique, form; none = all three)
|
||||
int8_t selected = int8_t(b(0x200) + b(0x1fe) + b(0x1ff));
|
||||
if (selected == 0) selected = 3;
|
||||
int sum = 0, n = 0, form = 0;
|
||||
if (b(0x1fe) != 0 || selected == 3) sum = int((w35c >> 14) & 0x7F), n = 1;
|
||||
if (b(0x1ff) != 0 || selected == 3) sum = int16_t(sum) + int((w35c >> 7) & 0x7F), n++;
|
||||
if (b(0x200) != 0 || selected == 3) form = int(w35c & 0x7F);
|
||||
int16_t strength;
|
||||
if (n == 0) {
|
||||
strength = int16_t((form - 0x23) * 3 + 10);
|
||||
} else {
|
||||
strength = int16_t(uint32_t(sum) / uint32_t(n));
|
||||
if (form != 0) strength = int16_t(uint32_t(strength * int16_t((int16_t(form) >> 3) + 0x5e)) / 100);
|
||||
}
|
||||
if (strength < b(0x1fc) || strength > b(0x1fd)) return;
|
||||
// left / right foot and wing preferences (w35c bits 21-23 and 24-26)
|
||||
const int lane = int((w35c >> 21) & 7), foot = int((w35c >> 24) & 7);
|
||||
bool low_foot = b(0x201) || b(0x203), high_foot = b(0x202) || b(0x204);
|
||||
if (low_foot && high_foot) low_foot = high_foot = false;
|
||||
bool low_lane = b(0x201) || b(0x202), high_lane = b(0x203) || b(0x204);
|
||||
if (low_lane && high_lane) low_lane = high_lane = false;
|
||||
if ((low_lane && lane >= 3) || (high_lane && lane <= 4) || (low_foot && foot >= 3) || (high_foot && foot <= 4)) return;
|
||||
// the price class (asking price 70..130 %) against the classes wanted
|
||||
int8_t price_class = int8_t((mem.u8(list + 0x54) - 0x46) / 0x14);
|
||||
price_class = std::clamp<int8_t>(price_class, 0, 2);
|
||||
const int8_t classes = int8_t(b(0x207) + b(0x205) + b(0x206));
|
||||
int highest = 2;
|
||||
while (highest >= 0 && b(0x205 + size_t(highest)) == 0) highest--;
|
||||
if (classes == 0 || price_class <= highest)
|
||||
if (search_profile_matches_listing(g, manager, list, player))
|
||||
post_composed(g, manager, message_text(g, ::bmh::layout::Month_SearchProfileNews_TextPointer) + g.player_name(player) + message_text(g, ::bmh::layout::Month_SearchProfileNews_TextPointer2));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Search profile of a human manager: storage, closing rule, "Vorschlag" and matching against the transfer list
|
||||
// (see search_profile.hpp). Original routines: sub_19409 (dialog, closing rule), sub_18F06 (suggestion),
|
||||
// sub_19A38 (position strengths), sub_190B5 (match one listing) of the Diamond 3.7 executable.
|
||||
#include "game/search_profile.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/messages.hpp"
|
||||
|
||||
namespace bmh {
|
||||
namespace {
|
||||
|
||||
constexpr size_t kRecord = 0xB0C; // manager record
|
||||
constexpr uint32_t kTransferList = ::bmh::layout::EditorList;
|
||||
constexpr uint32_t kListEntry = 0x58;
|
||||
constexpr int kPoolFirst = 0xb70; // the transfer list lives in the first 40 pool slots
|
||||
// Fewest players per position (goalkeeper, defender, midfielder, forward) before the suggestion asks for one.
|
||||
constexpr int kMinimumPerPosition[4] = {2, 6, 7, 5};
|
||||
|
||||
// Strength of a player as shown in the squad bars (original sub_199D0 with the halving flag set):
|
||||
// (first attribute + second attribute) * (94 + form / 8) / 100 / 2, limited to 0..99.
|
||||
int bar_strength(uint32_t w35c) {
|
||||
const int first = int((w35c >> 14) & 0x7F), second = int((w35c >> 7) & 0x7F), form = int(w35c & 0x7F);
|
||||
int16_t value = int16_t(int16_t(first + second) * ((form >> 3) + 94) / 100);
|
||||
value = int16_t(value / 2);
|
||||
if (value < 0) value = 0;
|
||||
if (value > 99) value = 99;
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t record_byte(const GameState& g, int manager, size_t offset) {
|
||||
return g.manager_records.at(size_t(manager) * kRecord + offset);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SearchProfile search_profile(const GameState& g, int manager) {
|
||||
SearchProfile profile{};
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() ||
|
||||
(size_t(manager) + 1) * kRecord > g.manager_records.size()) return profile;
|
||||
for (size_t i = 0; i < profile.size(); ++i) profile[i] = record_byte(g, manager, kSearchProfileOffset + i);
|
||||
return profile;
|
||||
}
|
||||
|
||||
bool search_profile_valid(SearchProfile profile) {
|
||||
profile[0] &= 0x3F; // the dialog starts from the stored profile without the "off" bit
|
||||
for (size_t i = 0; i < profile.size(); ++i) {
|
||||
const bool range = i >= 4 && i <= 7;
|
||||
if (!range && profile[i] > 1) return false; // switches
|
||||
if (i >= 4 && i <= 5 && profile[i] > 24) return false; // age bar: 25 cells
|
||||
if (i >= 6 && i <= 7 && profile[i] > 99) return false; // strength bar: 100 cells
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool search_profile_active(SearchProfile profile, bool cancelled) {
|
||||
profile[0] &= 0x3F;
|
||||
int sum = 0;
|
||||
for (uint8_t value : profile) sum += value;
|
||||
return !(sum == 0 || sum == 18 || cancelled);
|
||||
}
|
||||
|
||||
bool set_search_profile(GameState& g, int manager, SearchProfile profile, bool cancelled) {
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() ||
|
||||
(size_t(manager) + 1) * kRecord > g.manager_records.size() || !search_profile_valid(profile)) return false;
|
||||
profile[0] &= 0x3F;
|
||||
if (!search_profile_active(profile, cancelled)) profile[0] |= kSearchProfileOff;
|
||||
for (size_t i = 0; i < profile.size(); ++i)
|
||||
g.manager_records.at(size_t(manager) * kRecord + kSearchProfileOffset + i) = profile[i];
|
||||
return (profile[0] & kSearchProfileOff) == 0;
|
||||
}
|
||||
|
||||
std::array<uint16_t, 5> position_strengths(const GameState& g, int club, bool whole_squad) {
|
||||
unsigned sum[5] = {}, count[5] = {};
|
||||
const SquadRange range = squad_range(club);
|
||||
for (size_t i = 0; i < 24; ++i) {
|
||||
if (i >= 11 && !whole_squad) continue;
|
||||
const size_t slot = range.first + i;
|
||||
if (slot >= g.squad_slots.size()) break;
|
||||
const int player = g.squad_slots[slot] & 0xFFF;
|
||||
if (player == 0xFFF) continue;
|
||||
const Player& p = g.players.at(size_t(player));
|
||||
const int position = int(p.w364 & 3);
|
||||
const int value = bar_strength(p.w35c);
|
||||
++count[position]; ++count[4];
|
||||
sum[position] += unsigned(value); sum[4] += unsigned(value);
|
||||
}
|
||||
std::array<uint16_t, 5> average{};
|
||||
for (size_t k = 0; k < 5; ++k) average[k] = count[k] ? uint16_t(sum[k] / count[k]) : 0;
|
||||
return average;
|
||||
}
|
||||
|
||||
SearchProfile suggest_search_profile(const GameState& g, int manager, bool whole_squad) {
|
||||
SearchProfile profile{};
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return profile;
|
||||
const int club = g.manager_teams[size_t(manager)];
|
||||
// Players per position in the first 24 squad slots (the count stops at the first empty slot).
|
||||
int present[4] = {};
|
||||
const SquadRange range = squad_range(club);
|
||||
for (size_t i = 0; i < 24; ++i) {
|
||||
const size_t slot = range.first + i;
|
||||
if (slot >= g.squad_slots.size()) break;
|
||||
const int player = g.squad_slots[slot] & 0xFFF;
|
||||
if (player == 0xFFF) break;
|
||||
++present[g.players.at(size_t(player)).w364 & 3];
|
||||
}
|
||||
const auto average = position_strengths(g, club, whole_squad);
|
||||
int weakest = 0, weakest_value = 127;
|
||||
for (int position = 0; position < 4; ++position) {
|
||||
if (present[position] - kMinimumPerPosition[position] < 0) profile[size_t(position)] = 1;
|
||||
if (int(average[size_t(position)]) < weakest_value) {
|
||||
weakest_value = int(int8_t(average[size_t(position)]));
|
||||
weakest = position;
|
||||
}
|
||||
}
|
||||
profile[size_t(weakest)] = 1;
|
||||
// Whole squad, all four positions: team averages of the first and of the second attribute.
|
||||
const int first = team_average(g, club, 0xF1).value;
|
||||
const int second = team_average(g, club, 0xF2).value;
|
||||
int ratio = 100;
|
||||
if (uint16_t(second) != 0) ratio = 100 * uint16_t(first) / uint16_t(second);
|
||||
if (std::abs(100 - ratio) > 9) profile[size_t(8 + (ratio > 100 ? 1 : 0))] = 1;
|
||||
int16_t upper = int16_t(second + 20);
|
||||
upper = std::clamp<int16_t>(upper, 0, 99);
|
||||
profile[4] = 2;
|
||||
profile[5] = 12;
|
||||
profile[6] = uint8_t(second);
|
||||
profile[7] = uint8_t(upper);
|
||||
return profile;
|
||||
}
|
||||
|
||||
bool search_profile_matches_listing(const GameState& g, int manager, uint32_t list, int player) {
|
||||
if (manager < 0 || size_t(manager) >= g.manager_teams.size() ||
|
||||
(size_t(manager) + 1) * kRecord > g.manager_records.size()) return false;
|
||||
const StaticMemory& mem = g.memory;
|
||||
const auto b = [&](size_t offset) { return int(record_byte(g, manager, offset)); };
|
||||
const int team = g.manager_teams[size_t(manager)];
|
||||
player &= 0xFFF;
|
||||
if (team == kNoTeam || (mem.u16(list + 8) & 0x7FFF) == team || (b(kSearchProfileOffset) & kSearchProfileOff)) return false;
|
||||
const uint32_t w364 = g.players.at(size_t(player)).w364, w35c = g.players.at(size_t(player)).w35c;
|
||||
// position wanted (or none selected) and age within the range
|
||||
if (b(0x1f6 + (w364 & 3)) == 0 && b(0x1f9) + b(0x1f8) + b(0x1f7) + b(0x1f6) != 0) return false;
|
||||
const int age = int((w364 >> 21) & 0x1F);
|
||||
if (age < b(0x1fa) || age > b(0x1fb)) return false;
|
||||
// strength by the selected attributes (first, second, form; none = all three)
|
||||
int8_t selected = int8_t(b(0x200) + b(0x1fe) + b(0x1ff));
|
||||
if (selected == 0) selected = 3;
|
||||
int sum = 0, n = 0, form = 0;
|
||||
if (b(0x1fe) != 0 || selected == 3) sum = int((w35c >> 14) & 0x7F), n = 1;
|
||||
if (b(0x1ff) != 0 || selected == 3) sum = int16_t(sum) + int((w35c >> 7) & 0x7F), n++;
|
||||
if (b(0x200) != 0 || selected == 3) form = int(w35c & 0x7F);
|
||||
int16_t strength;
|
||||
if (n == 0) {
|
||||
strength = int16_t((form - 0x23) * 3 + 10);
|
||||
} else {
|
||||
strength = int16_t(uint32_t(sum) / uint32_t(n));
|
||||
if (form != 0) strength = int16_t(uint32_t(strength * int16_t((int16_t(form) >> 3) + 0x5e)) / 100);
|
||||
}
|
||||
if (strength < b(0x1fc) || strength > b(0x1fd)) return false;
|
||||
// left / right foot and wing preferences (w35c bits 21-23 and 24-26)
|
||||
const int lane = int((w35c >> 21) & 7), foot = int((w35c >> 24) & 7);
|
||||
bool low_foot = b(0x201) || b(0x203), high_foot = b(0x202) || b(0x204);
|
||||
if (low_foot && high_foot) low_foot = high_foot = false;
|
||||
bool low_lane = b(0x201) || b(0x202), high_lane = b(0x203) || b(0x204);
|
||||
if (low_lane && high_lane) low_lane = high_lane = false;
|
||||
if ((low_lane && lane >= 3) || (high_lane && lane <= 4) || (low_foot && foot >= 3) || (high_foot && foot <= 4)) return false;
|
||||
// the price class (asking price 70..130 %) against the classes wanted
|
||||
int8_t price_class = int8_t((mem.u8(list + 0x54) - 0x46) / 0x14);
|
||||
price_class = std::clamp<int8_t>(price_class, 0, 2);
|
||||
const int8_t classes = int8_t(b(0x207) + b(0x205) + b(0x206));
|
||||
int highest = 2;
|
||||
while (highest >= 0 && b(0x205 + size_t(highest)) == 0) highest--;
|
||||
return classes == 0 || price_class <= highest;
|
||||
}
|
||||
|
||||
bool search_profile_matches(const GameState& g, int manager, int entry) {
|
||||
if (entry < 0 || entry >= 40 || size_t(kPoolFirst + entry) >= g.squad_slots.size()) return false;
|
||||
const int player = g.squad_slots[size_t(kPoolFirst + entry)] & 0xFFF;
|
||||
if (player == 0xFFF) return false;
|
||||
return search_profile_matches_listing(g, manager, kTransferList + uint32_t(entry) * kListEntry, player);
|
||||
}
|
||||
|
||||
std::vector<SearchProfileHit> search_profile_hits(const GameState& g, int manager) {
|
||||
std::vector<SearchProfileHit> hits;
|
||||
for (int entry = 0; entry < 40; ++entry) {
|
||||
if (!search_profile_matches(g, manager, entry)) continue;
|
||||
const int player = g.squad_slots[size_t(kPoolFirst + entry)] & 0xFFF;
|
||||
hits.push_back({entry, player,
|
||||
message_text(g, ::bmh::layout::Month_SearchProfileNews_TextPointer) + g.player_name(player) +
|
||||
message_text(g, ::bmh::layout::Month_SearchProfileNews_TextPointer3)});
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
} // namespace bmh
|
||||
@@ -0,0 +1,71 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The search profile of a human manager (transfer market buttons "Suchen" and "Vorschlag", original
|
||||
// sub_19409 / sub_18F06 / sub_190B5). The profile is 18 bytes in the manager record at +0x1f6:
|
||||
// [0..3] positions wanted (goalkeeper, defender, midfielder, forward); none set = every position
|
||||
// [4..5] age range (stored as 0..24, i.e. age - 16), [6..7] strength range (0..99)
|
||||
// [8..10] strength is judged by condition / technique / form (none set = all three)
|
||||
// [11..14] foot and wing preference, [15..17] price classes wanted (asking price 70..130 %)
|
||||
// Bit 0x40 of byte 0 marks the profile as switched off. Implementation: search_profile.cpp.
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "game/state.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
using SearchProfile = std::array<uint8_t, 18>;
|
||||
constexpr size_t kSearchProfileOffset = 0x1f6;
|
||||
constexpr uint8_t kSearchProfileOff = 0x40;
|
||||
|
||||
// The stored profile of a manager slot (all zero for an invalid slot).
|
||||
SearchProfile search_profile(const GameState& g, int manager);
|
||||
|
||||
// Whether the values can come out of the dialog: bytes 0..3 and 8..17 are switches (0 or 1, the "off" bit is
|
||||
// ignored in byte 0), the age bar has 25 cells (bytes 4 and 5 are 0..24) and the strength bar 100 (bytes 6 and 7 are 0..99).
|
||||
bool search_profile_valid(SearchProfile profile);
|
||||
|
||||
// Whether a profile closed with `cancelled` (right click) or not counts as an active search: the "off" bit of
|
||||
// byte 0 is ignored, every value 0 or every value 1 (the sum is 0 or 18) switches the search off, and so does
|
||||
// leaving the dialog by right click. The dialog uses the result for the button state, the engine for the stored bit.
|
||||
bool search_profile_active(SearchProfile profile, bool cancelled);
|
||||
|
||||
// Stores the profile the way the original dialog does when it is closed: a profile with every value 0 or
|
||||
// every value 1 is switched off (bit 0x40), and so is any profile that was left by right click
|
||||
// (`cancelled`). Returns whether the stored profile is active. Fails (false, nothing stored) for an
|
||||
// invalid manager slot or invalid values (see search_profile_valid) - check these first to tell
|
||||
// "refused" from "switched off".
|
||||
bool set_search_profile(GameState& g, int manager, SearchProfile profile, bool cancelled);
|
||||
|
||||
// Average strengths per position class of the manager's own squad (original sub_19A38): index 0..3
|
||||
// goalkeeper..forward, index 4 the whole squad. `whole_squad` also counts the substitutes (24 slots
|
||||
// instead of the first 11).
|
||||
std::array<uint16_t, 5> position_strengths(const GameState& g, int club, bool whole_squad);
|
||||
|
||||
// The "Vorschlag" profile (original sub_18F06) from the squad of the manager: positions with too few
|
||||
// players or the weakest line, age range 2..12, strength from the condition average to +20, and the
|
||||
// attribute (condition or technique) in which the squad is clearly weaker.
|
||||
SearchProfile suggest_search_profile(const GameState& g, int manager, bool whole_squad);
|
||||
|
||||
// The matching rule itself for the listing record at `list` (EditorList entry address) holding `player`.
|
||||
// Shared with the news of month.cpp (search_profile_news).
|
||||
bool search_profile_matches_listing(const GameState& g, int manager, uint32_t list, int player);
|
||||
|
||||
// Whether the listing in transfer-list entry `entry` (0..39) fits the manager's active profile
|
||||
// (original sub_190B5 up to the message). Listings of his own club never match.
|
||||
bool search_profile_matches(const GameState& g, int manager, int entry);
|
||||
|
||||
struct SearchProfileHit {
|
||||
int entry = -1; // transfer-list entry 0..39
|
||||
int player = -1; // player id
|
||||
std::string message; // "<player name> ..." as shown in the original message box
|
||||
};
|
||||
|
||||
// Confirming the dialog with "Suchen": every listing that fits the profile right now (original
|
||||
// sub_190B5 with the message-box variant), in list order.
|
||||
std::vector<SearchProfileHit> search_profile_hits(const GameState& g, int manager);
|
||||
|
||||
} // namespace bmh
|
||||
+3
-2
@@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
#include "formats/diamond_image.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
|
||||
@@ -169,9 +170,9 @@ bool prepare_english_game(const fs::path& source, const fs::path& target, std::s
|
||||
}
|
||||
if (auto f = find_file(source, "TEXTE.BLK")) copy(*f, target / "TEXTD.BLK");
|
||||
if (auto f = find_file(source, "M3E.MAN")) copy(*f, target / "M3D.MAN");
|
||||
// FLTD.EXE is optional: without it the numbers built into OpenBMH and the texts of openbmh.dat stand in (formats/diamond_image.hpp)
|
||||
const auto exe = find_file(source, "FLTD.EXE");
|
||||
if (!exe) throw std::runtime_error("FLTD.EXE is missing");
|
||||
save_image(translate_fltd(*exe), target / "BMH.exe");
|
||||
save_image(exe ? translate_fltd(*exe) : english_constants_image(source), target / "BMH.exe");
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
error = e.what();
|
||||
|
||||
+62
-15
@@ -18,6 +18,7 @@
|
||||
#include <system_error>
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
#include "formats/diamond_image.hpp"
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/m3d.hpp"
|
||||
#include "formats/textd.hpp"
|
||||
@@ -71,6 +72,26 @@ std::optional<Family> family_of_exe(const std::string& file_name) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Whether `directory` holds the asset files of the English game and the built-in numbers have their texts (openbmh.dat):
|
||||
// then FLTD.EXE is not needed. Without openbmh.dat the game needs the executable.
|
||||
bool has_english_assets(const fs::path& directory) {
|
||||
std::error_code ec;
|
||||
if (!fs::is_directory(directory, ec)) return false;
|
||||
const auto kb = find_file(directory, "KB");
|
||||
return find_file(directory, "TEXTE.BLK") && find_file(directory, "M3E.MAN") && kb && fs::is_directory(*kb, ec) &&
|
||||
!find_texts_file(directory).empty();
|
||||
}
|
||||
|
||||
// Whether `directory` holds the asset files of the German game and the built-in numbers have their texts (openbmh.dat):
|
||||
// then BMH.EXE is not needed. Without openbmh.dat the game needs the executable.
|
||||
bool has_german_assets(const fs::path& directory) {
|
||||
std::error_code ec;
|
||||
if (!fs::is_directory(directory, ec)) return false;
|
||||
const auto kb = find_file(directory, "KB");
|
||||
return find_file(directory, "TEXTD.BLK") && find_file(directory, "M3D.MAN") && kb && fs::is_directory(*kb, ec) &&
|
||||
!find_texts_file(directory).empty();
|
||||
}
|
||||
|
||||
// Every game EXE directly in `directory`.
|
||||
std::vector<std::pair<Family, fs::path>> game_exes(const fs::path& directory) {
|
||||
std::vector<std::pair<Family, fs::path>> out;
|
||||
@@ -150,24 +171,26 @@ std::string text_title(const std::string& raw) {
|
||||
void check_german(GameCheck& c) {
|
||||
// (a translated English game has BMH.exe in the OpenBMH image format, launch/fltd.hpp)
|
||||
bool image = false;
|
||||
if (const auto exe = find_file(c.directory, "BMH.EXE")) {
|
||||
const auto exe = find_file(c.directory, "BMH.EXE");
|
||||
if (exe) {
|
||||
std::ifstream in(*exe, std::ios::binary);
|
||||
char head[13] = {};
|
||||
in.read(head, sizeof head);
|
||||
image = std::string(head, sizeof head) == "OPENBMH-IMAGE";
|
||||
require(c, c.directory, "BMH.EXE", image ? 0 : 602527, "BMH.EXE");
|
||||
}
|
||||
require(c, c.directory, "BMH.EXE", image ? 0 : 602527, "BMH.EXE");
|
||||
|
||||
require(c, c.directory, "TEXTD.BLK", 0, "TEXTD.BLK");
|
||||
require(c, c.directory, "M3D.MAN", 0, "M3D.MAN");
|
||||
for (const Required& r : kCommon) require(c, c.directory, r.name, r.size, r.name);
|
||||
require_media(c);
|
||||
if (!c.problems.empty()) return;
|
||||
// the files must also load: the engine reads tables from the EXE, the texts and the
|
||||
// database of clubs and players
|
||||
// the files must also load: the engine reads tables from the EXE (or the built-in numbers and texts), the
|
||||
// texts and the database of clubs and players
|
||||
try {
|
||||
load_le(*find_file(c.directory, "BMH.EXE"));
|
||||
load_le(exe ? *exe : c.directory / "BMH.EXE");
|
||||
} catch (const std::exception& e) {
|
||||
c.problems.push_back(std::string("BMH.EXE cannot be read: ") + e.what());
|
||||
c.problems.push_back(std::string("BMH.EXE") + " cannot be read: " + e.what());
|
||||
}
|
||||
try {
|
||||
const TextDb texts = load_textd(*find_file(c.directory, "TEXTD.BLK"));
|
||||
@@ -187,7 +210,8 @@ void check_german(GameCheck& c) {
|
||||
}
|
||||
|
||||
void check_english(GameCheck& c) {
|
||||
require(c, c.directory, "FLTD.EXE", 507925, "FLTD.EXE");
|
||||
// (FLTD.EXE is optional: the numbers and texts of Football Limited are built into OpenBMH)
|
||||
if (find_file(c.directory, "FLTD.EXE")) require(c, c.directory, "FLTD.EXE", 507925, "FLTD.EXE");
|
||||
require(c, c.directory, "TEXTE.BLK", 0, "TEXTE.BLK");
|
||||
require(c, c.directory, "M3E.MAN", 0, "M3E.MAN");
|
||||
for (const Required& r : kCommon) require(c, c.directory, r.name, r.size, r.name);
|
||||
@@ -258,11 +282,18 @@ ResolvedGame unpack(const fs::path& file, const fs::path& cache) {
|
||||
if (is_archive_name(base)) nested = true;
|
||||
if (upper(base) == "INSTALL.EXE") installer = true;
|
||||
}
|
||||
// no executable: the asset files are enough (the text block marks the game's folder)
|
||||
if (exes.empty())
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
if (entries[i].directory) continue;
|
||||
const std::string& n = entries[i].name;
|
||||
{ const std::string leaf = upper(n.substr(n.find_last_of('/') + 1)); if (leaf == "TEXTD.BLK" || leaf == "TEXTE.BLK") exes.push_back(i); }
|
||||
}
|
||||
if (exes.empty()) {
|
||||
if (installer) r.error = "The archive holds an installer (INSTALL.EXE), not an installed game.";
|
||||
else if (nested) r.error = "The archive contains further archives (a box with several editions). "
|
||||
"Please choose the archive of one edition.";
|
||||
else r.error = "The archive contains no BMH.EXE or FLTD.EXE.";
|
||||
else r.error = "The archive contains no BMH.EXE, FLTD.EXE or game asset files (TEXTD.BLK, TEXTE.BLK).";
|
||||
return r;
|
||||
}
|
||||
if (exes.size() > 1) {
|
||||
@@ -334,19 +365,32 @@ GameCheck check_game_directory(const fs::path& path) {
|
||||
std::error_code ec;
|
||||
fs::path dir = fs::is_directory(path, ec) ? path : path.parent_path();
|
||||
auto exes = game_exes(dir);
|
||||
if (exes.empty()) {
|
||||
if (exes.empty() && !has_german_assets(dir) && !has_english_assets(dir)) {
|
||||
// an edition folder with the game one level below (e.g. "BMH 2026-27 supported rule profile\BMH")
|
||||
std::vector<fs::path> candidates;
|
||||
for (const auto& e : fs::directory_iterator(dir, ec))
|
||||
if (e.is_directory(ec) && !game_exes(e.path()).empty()) candidates.push_back(e.path());
|
||||
if (e.is_directory(ec) && (!game_exes(e.path()).empty() || has_german_assets(e.path()) || has_english_assets(e.path()))) candidates.push_back(e.path());
|
||||
if (candidates.size() == 1) {
|
||||
dir = candidates[0];
|
||||
exes = game_exes(dir);
|
||||
}
|
||||
}
|
||||
c.directory = dir;
|
||||
// The German game without BMH.EXE: the asset files are enough (the numbers of the executable are built in).
|
||||
if (exes.empty() && has_german_assets(dir)) {
|
||||
c.family = GameFamily::german;
|
||||
check_german(c);
|
||||
c.playable = c.problems.empty();
|
||||
return c;
|
||||
}
|
||||
// The English game without FLTD.EXE: the asset files are enough as well.
|
||||
if (exes.empty() && has_english_assets(dir)) {
|
||||
c.family = GameFamily::english;
|
||||
check_english(c);
|
||||
return c;
|
||||
}
|
||||
if (exes.empty()) {
|
||||
c.problems.push_back("no BMH.EXE or FLTD.EXE in " + path_to_utf8(dir));
|
||||
c.problems.push_back("no BMH.EXE or FLTD.EXE in " + path_to_utf8(dir) + ". The game needs either BMH.EXE (FLTD.EXE for the English game) and the asset files, or openbmh.dat (from the release package) and the asset files.");
|
||||
return c;
|
||||
}
|
||||
// a named EXE decides; otherwise the German game before the English one
|
||||
@@ -382,25 +426,27 @@ ResolvedGame resolve_game(const fs::path& input, const fs::path& cache) {
|
||||
// The English Football Limited runs on the same engine through a German-layout data
|
||||
// directory, built once in the cache (launch/fltd.hpp); its name follows FLTD.EXE.
|
||||
if (game.error.empty() && game.check.family == GameFamily::english && game.check.problems.empty()) {
|
||||
const fs::path prepared = cache / ("en-" + content_hash(game.check.exe));
|
||||
const fs::path prepared = cache / ("en-" + (game.check.exe.empty() ? std::string("embedded") : content_hash(game.check.exe)));
|
||||
const fs::path marker = prepared / ".openbmh-english";
|
||||
// the version of the translation (launch/fltd.cpp, fltd_map.inc): a cache built
|
||||
// by another version is built again
|
||||
constexpr const char* kTranslation = "english translation 17"; // 17: English monthly environment tables (16: overwrite question)
|
||||
constexpr const char* kTranslation = "english translation 18"; // 18: numbers built in (no FLTD.EXE needed), 17: English monthly environment tables (16: overwrite question)
|
||||
const std::string texts = texts_signature(game.check.directory); // an English game made without openbmh.dat is made again with it
|
||||
const std::string version = std::string(kTranslation) + (game.check.exe.empty() ? " " + texts : std::string());
|
||||
std::string built;
|
||||
{
|
||||
std::ifstream in(marker);
|
||||
std::getline(in, built);
|
||||
}
|
||||
std::error_code ec;
|
||||
if (built != kTranslation) {
|
||||
if (built != version) {
|
||||
fs::remove_all(prepared, ec);
|
||||
std::string error;
|
||||
if (!prepare_english_game(game.check.directory, prepared, error)) {
|
||||
game.error = "The English version cannot be prepared: " + error;
|
||||
return game;
|
||||
}
|
||||
std::ofstream(marker) << kTranslation << "\n" << path_to_utf8(game.check.directory) << "\n";
|
||||
std::ofstream(marker) << version << "\n" << path_to_utf8(game.check.directory) << "\n";
|
||||
}
|
||||
game.check.directory = prepared;
|
||||
game.check.playable = true;
|
||||
@@ -469,6 +515,7 @@ std::string describe(const ResolvedGame& game) {
|
||||
if (!c.title.empty()) text += c.title + "\n";
|
||||
text += path_to_utf8(c.directory) + "\n";
|
||||
for (const auto& p : c.problems) text += "- " + p + "\n";
|
||||
for (const auto& n : c.notes) text += "Note: " + n + "\n";
|
||||
if (!c.unsupported.empty()) text += c.unsupported + "\n";
|
||||
if (c.playable) text += "The game data is complete.\n";
|
||||
return text;
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
// OpenBMH has one game and match engine (the supported rule profile rules); the original files are only
|
||||
// data. The check therefore asks whether the data is complete and readable, not which
|
||||
// edition it is. Fan extras next to the files (pictures, manuals) are ignored.
|
||||
//
|
||||
// The German game does not need BMH.EXE: the numbers of the executable are built into OpenBMH (formats/diamond_image.hpp).
|
||||
// A directory with the asset files (TEXTD.BLK, M3D.MAN, the picture, font and sound folders) is a complete game; the
|
||||
// texts of the executable are built in as well. The same holds for the English game (TEXTE.BLK, M3E.MAN; FLTD.EXE).
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
@@ -32,6 +36,8 @@ struct GameCheck {
|
||||
std::filesystem::path exe; // the EXE as found (its case may differ)
|
||||
std::string title; // e.g. "Bundesliga Manager Hattrick 2026-27 (supported rule profile)"
|
||||
std::vector<std::string> problems; // missing or unreadable files; empty = data complete
|
||||
// Hints that do not stop the game.
|
||||
std::vector<std::string> notes;
|
||||
// Data complete and the engine can run it. False also for complete data the engine does
|
||||
// not run yet (`unsupported` says why).
|
||||
bool playable = false;
|
||||
|
||||
@@ -157,6 +157,9 @@ bmh_add_data_test(NAME ui_environment_tests REQUIRED_OPTIONS BMH_TEST_UI_ENVIRON
|
||||
add_executable(ui_achievements_tests achievements_tests.cpp)
|
||||
target_link_libraries(ui_achievements_tests PRIVATE bmhui)
|
||||
bmh_add_data_test(NAME ui_achievements_tests COMMAND ui_achievements_tests "${BMH_DATA}")
|
||||
add_executable(ui_button_frame_tests button_frame_tests.cpp)
|
||||
target_link_libraries(ui_button_frame_tests PRIVATE bmhui)
|
||||
add_test(NAME ui_button_frame_tests COMMAND ui_button_frame_tests)
|
||||
add_executable(ui_sprite_font_tests sprite_font_tests.cpp)
|
||||
target_link_libraries(ui_sprite_font_tests PRIVATE bmhui)
|
||||
bmh_add_data_test(NAME ui_sprite_font_tests COMMAND ui_sprite_font_tests "${BMH_DATA}")
|
||||
|
||||
+43
-38
@@ -6,6 +6,9 @@
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/environment.hpp"
|
||||
#include "ui/advertising.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -759,11 +762,11 @@ Image AdvertisingScreen::render() const {
|
||||
|
||||
copy(image, logos_, 32, 217, 138, 174, 11, 14);
|
||||
|
||||
button(image, 89, 191, 66, state_.cancel_label);
|
||||
button(image, 89, 191, 66, state_.cancel_label, pressed_button_ == 0);
|
||||
// The original shows ABBRECHEN only when the selected offer cannot be accepted
|
||||
// (for example while a running sponsor contract is not terminable).
|
||||
if (offer_acceptable())
|
||||
button(image, 164, 191, 66, state_.accept_label);
|
||||
button(image, 164, 191, 66, state_.accept_label, pressed_button_ == 1);
|
||||
}
|
||||
}
|
||||
if (hovered_target_ >= 0) {
|
||||
@@ -779,21 +782,37 @@ Image AdvertisingScreen::render() const {
|
||||
return image;
|
||||
}
|
||||
|
||||
void AdvertisingScreen::button(Image& image, int x, int y, int width, std::string_view label) const {
|
||||
// FormatError3's normal KB/0 bevel. Source promotes any wide button shorter
|
||||
// than ten pixels to a ten-pixel button before tiling its centre.
|
||||
constexpr int height = 10;
|
||||
copy(image, widgets_, 24, 74, x, y, 31, height);
|
||||
int used = 31;
|
||||
while (width - used > 20) {
|
||||
const int count = std::min(8, width - used - 20);
|
||||
copy(image, widgets_, 24, 84, x + used, y, count, height);
|
||||
used += count;
|
||||
}
|
||||
copy(image, widgets_, 45 - (width - used), 94, x + used, y, width - used, height);
|
||||
void AdvertisingScreen::button(Image& image, int x, int y, int width, std::string_view label, bool pressed) const {
|
||||
// FormatError3's KB/0 bevel (button_frame.hpp: raised with shadow, or pressed while the mouse button is held).
|
||||
// Source promotes any wide button shorter than ten pixels to a ten-pixel button before tiling its centre.
|
||||
const int shift = draw_wide_button_frame(image, widgets_, x, y, width, pressed);
|
||||
if (!label.empty())
|
||||
sprite_font_.draw(image, x + width / 2 - sprite_font_.text_width(label) / 2, y + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
sprite_font_.draw(image, x + shift + width / 2 - sprite_font_.text_width(label) / 2, y + shift + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(pressed)));
|
||||
}
|
||||
|
||||
// Mouse DOWN on ABBRECHEN or the accept button of the open offer: drawn pressed until the release.
|
||||
bool AdvertisingScreen::press(int x, int y) {
|
||||
int id = -1;
|
||||
// OK of an acknowledging notification (id 2); a warning is timed and has no button
|
||||
if (notification_open() && !close_requested_ && !pending_ && !state_.notification_warning &&
|
||||
source_dialog_button_at(TaxDialogKind::acknowledgement, false, x, y) == GameEndTaxDialog::Button::acknowledge)
|
||||
id = 2;
|
||||
else if (offer_open_ && !close_requested_ && !pending_ && !notification_open() && !spending_calculator_open_ &&
|
||||
y >= 191 && y <= 200) {
|
||||
if (x >= 89 && x <= 154) id = 0;
|
||||
else if (x >= 164 && x <= 229 && offer_acceptable()) id = 1;
|
||||
}
|
||||
// a key of the open spending calculator
|
||||
int key = -1;
|
||||
if (spending_calculator_open_ && !notification_open() && !pending_ && !close_requested_)
|
||||
for (int i = 0; i < 15; ++i)
|
||||
if (calculator_key_hit(x, y, 103 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
|
||||
55 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
|
||||
const bool changed = id != pressed_button_ || key != pressed_key_;
|
||||
pressed_button_ = id;
|
||||
pressed_key_ = key;
|
||||
return changed;
|
||||
}
|
||||
|
||||
void AdvertisingScreen::pattern_rect(Image& out, int x, int y, int width, int height) const {
|
||||
@@ -803,30 +822,13 @@ void AdvertisingScreen::pattern_rect(Image& out, int x, int y, int width, int he
|
||||
}
|
||||
|
||||
void AdvertisingScreen::source_frame(Image& out, int x, int y, int width, int height, bool shadow) const {
|
||||
if (shadow) { fill_rect(out, x + 2, y + height, width, 2, 0x40); fill_rect(out, x + width, y + 2, 2, height, 0x40); }
|
||||
pattern_rect(out, x + 4, y + 4, width - 7, height - 7);
|
||||
copy(out, widgets_, 0, 0, x, y, 4, 4);
|
||||
copy(out, widgets_, 4, 0, x + width - 4, y, 4, 4);
|
||||
copy(out, widgets_, 0, 4, x, y + height - 4, 4, 4);
|
||||
copy(out, widgets_, 4, 4, x + width - 4, y + height - 4, 4, 4);
|
||||
for (int at = 4; at < width - 4; at += 74) {
|
||||
const int n = std::min(74, width - 4 - at);
|
||||
copy(out, widgets_, 0, 104, x + at, y, n, 4);
|
||||
copy(out, widgets_, 0, 108, x + at, y + height - 4, n, 4);
|
||||
}
|
||||
for (int at = 4; at < height - 4; at += 96) {
|
||||
const int n = std::min(96, height - 4 - at);
|
||||
copy(out, widgets_, 0, 8, x, y + at, 4, n);
|
||||
copy(out, widgets_, 4, 8, x + width - 4, y + at, 4, n);
|
||||
}
|
||||
draw_dialog_frame(out, widgets_, exe_, x, y, width, height, shadow); // dialog_frame.hpp
|
||||
}
|
||||
|
||||
void AdvertisingScreen::draw_spending_calculator(Image& out) const {
|
||||
constexpr int x0 = 103, y0 = 55;
|
||||
if (calculator_.width < 113 || calculator_.height < 150) return;
|
||||
copy(out, calculator_, 0, 0, x0, y0, 113, 136);
|
||||
fill_rect(out, x0 + 113, y0 + 2, 2, 136, 0x40);
|
||||
fill_rect(out, x0 + 2, y0 + 136, 113, 2, 0x40);
|
||||
draw_calculator_panel(out, calculator_, x0, y0); // calculator_widgets.hpp
|
||||
const std::string& title = selected_spending_slot_ == 16 ? state_.merchandise_calculator_title :
|
||||
state_.budget_calculator_title;
|
||||
const std::string bytes = utf8_to_original(title);
|
||||
@@ -836,9 +838,9 @@ void AdvertisingScreen::draw_spending_calculator(Image& out) const {
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
|
||||
const int y = y0 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
|
||||
copy(out, calculator_, 0, 136, x, y, 15, 14);
|
||||
const int p = draw_calculator_key(out, calculator_, x, y, pressed_key_ == i);
|
||||
// Render calls the raw font renderer for key legends.
|
||||
text(out, x + 5, y + 9, keys.substr(size_t(i), 1), 98, 15, false);
|
||||
text(out, x + 5 + p, y + 9 + p, keys.substr(size_t(i), 1), 98, 15, false);
|
||||
}
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i + 15) * 2);
|
||||
@@ -859,7 +861,8 @@ void AdvertisingScreen::draw_notification(Image& out) const {
|
||||
notice.body=utf8_to_original(state_.notification_text);
|
||||
notice.source_manager_flags=state_.notification_warning?0x40:0x80;
|
||||
draw_source_dialog(out,{widgets_,faces_,badge_atlas_?&*badge_atlas_:nullptr,
|
||||
font_,large_font_,exe_,sprite_font_,texts_},notice,state_.font_gradient);
|
||||
font_,large_font_,exe_,sprite_font_,texts_},notice,state_.font_gradient,
|
||||
pressed_button_ == 2 ? std::optional<GameEndTaxDialog::Button>(GameEndTaxDialog::Button::acknowledge) : std::nullopt);
|
||||
}
|
||||
|
||||
bool AdvertisingScreen::dismiss_notification() {
|
||||
@@ -1052,6 +1055,8 @@ bool AdvertisingScreen::move(int x, int y) {
|
||||
}
|
||||
|
||||
bool AdvertisingScreen::click(int x, int y) {
|
||||
pressed_button_ = -1; // the release ends the pressed look
|
||||
pressed_key_ = -1;
|
||||
pointer_position_ = std::array<int, 2>{x, y};
|
||||
if (close_requested_ || pending_ || x < 0 || y < 0 || x >= 320 || y >= 240) return false;
|
||||
if (notification_open()) return dismiss_notification();
|
||||
|
||||
@@ -113,6 +113,8 @@ public:
|
||||
Image render() const;
|
||||
bool move(int x, int y);
|
||||
bool click(int x, int y);
|
||||
// Mouse DOWN on a button of the open offer: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
bool key(std::string_view key);
|
||||
bool open_offers(int display_slot);
|
||||
bool text(std::string_view input);
|
||||
@@ -175,7 +177,9 @@ private:
|
||||
void draw_notification(Image&) const;
|
||||
void pattern_rect(Image&, int x, int y, int width, int height) const;
|
||||
void source_frame(Image&, int x, int y, int width, int height, bool shadow = true) const;
|
||||
void button(Image&, int x, int y, int width, std::string_view label) const;
|
||||
void button(Image&, int x, int y, int width, std::string_view label, bool pressed = false) const;
|
||||
int pressed_key_ = -1; // spending calculator key held down by the mouse
|
||||
int pressed_button_ = -1; // offer button held down by the mouse (0 cancel, 1 accept)
|
||||
};
|
||||
|
||||
} // namespace bmh::ui
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/balance_plan.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
@@ -100,12 +101,11 @@ void BalanceScreen::draw_buttons(Image& o)const{
|
||||
button(170,63,at(texts_,::bmh::layout::BalancePlan_DrawButtons_TextPointer+uint32_t(state_.draft.view)*4),0);button(245,63,at(texts_,::bmh::layout::BalancePlan_DrawButtons_TextPointer2),1);
|
||||
}
|
||||
void BalanceScreen::draw_calculator(Image& o)const{
|
||||
if(!calculator_open_)return;const int cx=state_.calculator_x,cy=state_.calculator_y;copy(o,calculator_art_,0,0,cx,cy,113,136);
|
||||
fill(o,cx+113,cy+2,2,136,0x40);fill(o,cx+2,cy+136,113,2,0x40);
|
||||
if(!calculator_open_)return;const int cx=state_.calculator_x,cy=state_.calculator_y;draw_calculator_panel(o,calculator_art_,cx,cy); // calculator_widgets.hpp
|
||||
auto draw=[&](int x,int baseline,std::string_view raw,uint8_t color,bool gradient=true){const int w=body_.text_width(raw),top=baseline-body_.baseline;if(x<0||top<0||x+w>o.width||top+body_.height>o.height)return;if(!gradient||!state_.gradient){body_.draw(o,x,top,raw,color);return;}Image mask(std::max(1,w),body_.height);body_.draw(mask,0,0,raw,1);int idx=0;while(idx<32&&exe_.u8(::bmh::layout::Advertising_Text_RuntimeField2+uint32_t(idx))!=color)++idx;for(int yy=0;yy<body_.height;++yy)for(int xx=0;xx<w;++xx)if(mask.at(xx,yy))o.at(x+xx,top+yy)=idx<32?exe_.u8(::bmh::layout::Advertising_Text_RuntimeField+uint32_t(idx*6+yy)):color;};
|
||||
std::string title(at(texts_,active_profile_.source_text_address));draw(cx+8+(105-8)/2-body_.text_width(title)/2,cy+14,title,0x62);
|
||||
const bool flash=current_milliseconds_<calculator_flash_until_;
|
||||
for(int i=0;i<15;++i){int x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+uint32_t(i)*2),y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+uint32_t(i));const bool down=pressed_calculator_control_==i||(flash&&flash_calculator_control_==i);copy(o,calculator_art_,down?15:0,136,x+(down?1:0),y+(down?1:0),down?14:15,down?13:14);draw(x+(down?6:5),y+(down?10:9),kKeys.substr(size_t(i),1),0x62,false);}
|
||||
for(int i=0;i<15;++i){int x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+uint32_t(i)*2),y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+uint32_t(i));const bool down=pressed_calculator_control_==i||(flash&&flash_calculator_control_==i);draw_calculator_key(o,calculator_art_,x,y,down);draw(x+(down?6:5),y+(down?10:9),kKeys.substr(size_t(i),1),0x62,false);}
|
||||
for(size_t i=0;i<8;++i)if(active_profile_.presets[i]){int x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+uint32_t(i+15)*2),y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+uint32_t(i+15));auto t=calc7(*active_profile_.presets[i]);draw(x+47-body_.text_width(t),y+12,t,0x62);}
|
||||
auto value=calculator_value_edited_?calc8(calculator_value_):calc7(calculator_value_);const int value_x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+23*2),value_y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+23);draw(value_x+47-body_.text_width(value),value_y+12,value,0x00);
|
||||
}
|
||||
|
||||
+57
-44
@@ -5,6 +5,8 @@
|
||||
// accepts a request.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/bank.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -585,9 +587,7 @@ BankRequest BankScreen::finish_credit() {
|
||||
void BankScreen::draw_calculator(Image& out) const {
|
||||
// BalanceFromGame uses the 113x136 source crop from KB6 at the caller's
|
||||
// a449d/a449f origin, then draws the source text and 23 calculator cells.
|
||||
copy_region(out, calculator_art_, 0, 0, 103, 55, 113, 136);
|
||||
rect(out, 105, 191, 113, 2, 0x40);
|
||||
rect(out, 216, 57, 2, 136, 0x40);
|
||||
draw_calculator_panel(out, calculator_art_, 103, 55); // calculator_widgets.hpp
|
||||
std::string title = texts_.strings.size() > 838 ? texts_[838] : std::string{};
|
||||
title += state_.account_text.empty() ? money(state_.balance) : state_.account_text;
|
||||
const int title_width = font_.text_width(title);
|
||||
@@ -596,8 +596,8 @@ void BankScreen::draw_calculator(Image& out) const {
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
const int x = 103 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
|
||||
const int y = 55 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
|
||||
copy_region(out, calculator_art_, 0, 136, x, y, 15, 14);
|
||||
body_baseline_raw(out, x + 5, y + 9, std::string(1, "0123456789DRCJN"[i]), 0x62, false);
|
||||
const int p = draw_calculator_key(out, calculator_art_, x, y, pressed_key_ == i);
|
||||
body_baseline_raw(out, x + 5 + p, y + 9 + p, std::string(1, "0123456789DRCJN"[i]), 0x62, false);
|
||||
}
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if (calculator_presets_[size_t(i)] == UINT32_MAX) continue;
|
||||
@@ -620,8 +620,10 @@ void BankScreen::draw_manager_dialog(Image& out, std::string_view message, bool
|
||||
notice.body=utf8_to_original(message);
|
||||
notice.source_manager_flags=with_ack_button?0x80:0x40;
|
||||
if(credit_fee_confirmation_open_&&!with_ack_button)notice.kind=TaxDialogKind::question;
|
||||
const auto held=static_cast<GameEndTaxDialog::Button>(pressed_dialog_);
|
||||
draw_source_dialog(out,{widgets_,faces_,badge_atlas_?&*badge_atlas_:nullptr,
|
||||
font_,large_font_,exe_,sprite_font_,texts_},notice,state_.gradient_text);
|
||||
font_,large_font_,exe_,sprite_font_,texts_},notice,state_.gradient_text,
|
||||
held==GameEndTaxDialog::Button::none?std::nullopt:std::optional<GameEndTaxDialog::Button>(held));
|
||||
}
|
||||
void BankScreen::draw_investment_warning(Image& out) const {
|
||||
draw_manager_dialog(out, state_.investment_limit_text, false);
|
||||
@@ -782,16 +784,13 @@ Image BankScreen::render() const {
|
||||
}
|
||||
const auto draw_button = [&](int x, uint32_t text_address) {
|
||||
constexpr int y = 174, button_width = 64;
|
||||
rect(out, x + 2, y + 10, button_width, 2, 0x40); rect(out, x + button_width, y + 2, 2, 10, 0x40);
|
||||
copy_region(out, widgets_, 24, 74, x, y, 31, 10);
|
||||
int at = 31, remaining = button_width - 31;
|
||||
while (remaining > 20) { const int n = std::min(8, remaining - 20); copy_region(out, widgets_, 24, 84, x + at, y, n, 10); at += n; remaining -= n; }
|
||||
if (remaining > 0) copy_region(out, widgets_, 45 - remaining, 94, x + at, y, remaining, 10);
|
||||
const bool down = pressed_button_ == (x < 100 ? 0 : 1);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, button_width, down);
|
||||
const size_t id = text_id(text_address);
|
||||
if (id < texts_.strings.size()) {
|
||||
const std::string label = original_to_utf8(texts_[id]);
|
||||
sprite_font_.draw(out, x + (button_width - sprite_font_.text_width(label)) / 2, y + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
sprite_font_.draw(out, x + shift + (button_width - sprite_font_.text_width(label)) / 2, y + shift + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(down)));
|
||||
}
|
||||
};
|
||||
draw_button(60, ::bmh::layout::Bank_FormatError_RuntimeField18 + 4 * 4);
|
||||
@@ -831,18 +830,10 @@ Image BankScreen::render() const {
|
||||
draw_property_card(out, selected_fund_, 124, false);
|
||||
const auto source_button = [&](int x, std::string_view label) {
|
||||
constexpr int width = 64, y = 174;
|
||||
rect(out, x + 2, y + 10, width, 2, 0x40);
|
||||
rect(out, x + width, y + 2, 2, 10, 0x40);
|
||||
copy_region(out, widgets_, 24, 74, x, y, 31, 10);
|
||||
int at = 31, remaining = width - 31;
|
||||
while (remaining > 20) {
|
||||
const int n = std::min(8, remaining - 20);
|
||||
copy_region(out, widgets_, 24, 84, x + at, y, n, 10);
|
||||
at += n; remaining -= n;
|
||||
}
|
||||
if (remaining > 0) copy_region(out, widgets_, 45 - remaining, 94, x + at, y, remaining, 10);
|
||||
sprite_font_.draw(out, x + (width - sprite_font_.text_width(label)) / 2, y + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
const bool down = pressed_button_ == (x < 100 ? 0 : 1);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, down);
|
||||
sprite_font_.draw(out, x + shift + (width - sprite_font_.text_width(label)) / 2, y + shift + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(down)));
|
||||
};
|
||||
source_button(60, original_to_utf8(texts_[191]));
|
||||
source_button(185, original_to_utf8(texts_[192]));
|
||||
@@ -924,13 +915,10 @@ Image BankScreen::render() const {
|
||||
if (visible_tip_) body_baseline(out, 200, 167, db(::bmh::layout::Bank_FormatError_RuntimeField19 + uint32_t(*visible_tip_) * 4), 0xf7);
|
||||
auto source_button = [&](int x, std::string_view label) {
|
||||
constexpr int width = 64, y = 174;
|
||||
rect(out, x + 2, y + 10, width, 2, 0x40); rect(out, x + width, y + 2, 2, 10, 0x40);
|
||||
copy_region(out, widgets_, 24, 74, x, y, 31, 10);
|
||||
int at = 31, remain = width - 31;
|
||||
while (remain > 20) { const int n = std::min(8, remain - 20); copy_region(out, widgets_, 24, 84, x + at, y, n, 10); at += n; remain -= n; }
|
||||
if (remain > 0) copy_region(out, widgets_, 45 - remain, 94, x + at, y, remain, 10);
|
||||
sprite_font_.draw(out, x + (width - sprite_font_.text_width(label)) / 2, y + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
const bool down = pressed_button_ == (x < 100 ? 0 : 1);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, down);
|
||||
sprite_font_.draw(out, x + shift + (width - sprite_font_.text_width(label)) / 2, y + shift + 7,
|
||||
label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(down)));
|
||||
};
|
||||
source_button(60, original_to_utf8(texts_[191]));
|
||||
source_button(185, original_to_utf8(texts_[192]));
|
||||
@@ -948,18 +936,10 @@ Image BankScreen::render() const {
|
||||
body_baseline(out, 195, 82, state_.deposit_text.empty() ? money(state_.deposit) : state_.deposit_text, 0x00);
|
||||
auto source_button = [&](int x, std::string_view label) {
|
||||
const int width = 64, y = 174;
|
||||
rect(out, x + 2, y + 10, width, 2, 0x40);
|
||||
rect(out, x + width, y + 2, 2, 10, 0x40);
|
||||
copy_region(out, widgets_, 24, 74, x, y, 31, 10);
|
||||
int at = 31, remaining = width - 31;
|
||||
while (remaining > 20) {
|
||||
const int n = std::min(8, remaining - 20);
|
||||
copy_region(out, widgets_, 24, 84, x + at, y, n, 10);
|
||||
at += n; remaining -= n;
|
||||
}
|
||||
if (remaining > 0) copy_region(out, widgets_, 45 - remaining, 94, x + at, y, remaining, 10);
|
||||
sprite_font_.draw(out, x + (width - sprite_font_.text_width(label)) / 2, y + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
const bool down = pressed_button_ == (x < 100 ? 0 : 1);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, down);
|
||||
sprite_font_.draw(out, x + shift + (width - sprite_font_.text_width(label)) / 2, y + shift + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(down)));
|
||||
};
|
||||
source_button(60, original_to_utf8(texts_[193]));
|
||||
source_button(185, original_to_utf8(texts_[194]));
|
||||
@@ -1011,7 +991,40 @@ BankRequest BankScreen::submit() {
|
||||
state_.revision, withdrawing_ ? -int32_t(value) : int32_t(value)};
|
||||
pending_ = request; feedback_.clear(); return request;
|
||||
}
|
||||
// Mouse DOWN on one of the two bottom buttons (Kaufen/Verkaufen, Einzahlen/Abheben, OK/Abbruch of a credit): the button
|
||||
// is drawn pressed until the release. Returns true when the picture changed.
|
||||
bool BankScreen::press(int x, int y) {
|
||||
// the buttons of the manager notices and of the credit fee question (OK, Ja, Nein)
|
||||
const bool notice = credit_notice_open_ || property_notice_open_;
|
||||
const bool question = credit_fee_confirmation_open_ && !notice;
|
||||
int dialog = int(GameEndTaxDialog::Button::none);
|
||||
if (notice || question)
|
||||
dialog = int(source_dialog_button_at(question ? TaxDialogKind::question : TaxDialogKind::acknowledgement, false, x, y));
|
||||
const bool dialog_changed = dialog != pressed_dialog_;
|
||||
pressed_dialog_ = dialog;
|
||||
// a key of the open calculator
|
||||
int key = -1;
|
||||
if (calculator_open_ && !pending_)
|
||||
for (int i = 0; i < 15; ++i)
|
||||
if (calculator_key_hit(x, y, 103 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
|
||||
55 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
|
||||
const bool key_changed = key != pressed_key_;
|
||||
pressed_key_ = key;
|
||||
int id = -1;
|
||||
const bool has_buttons = (exchange_open_ || property_open_ || deposit_open_ || credit_open_) && !calculator_open_ &&
|
||||
!credit_notice_open_ && !credit_fee_confirmation_open_ && !property_notice_open_ && !investment_warning_open_ && !pending_;
|
||||
if (has_buttons && y >= 174 && y <= 184) {
|
||||
if (x >= 60 && x <= 124) id = 0;
|
||||
else if (x >= 185 && x <= 249) id = 1;
|
||||
}
|
||||
const bool changed = id != pressed_button_;
|
||||
pressed_button_ = id;
|
||||
return changed || dialog_changed || key_changed;
|
||||
}
|
||||
BankRequest BankScreen::click(int x, int y, bool right) {
|
||||
pressed_button_ = -1; // the release ends the pressed look
|
||||
pressed_dialog_ = int(GameEndTaxDialog::Button::none);
|
||||
pressed_key_ = -1;
|
||||
if (credit_notice_open_) {
|
||||
if (right || (x >= 95 && x <= 220 && y >= 166 && y <= 176)) {
|
||||
credit_notice_open_ = false;
|
||||
|
||||
@@ -112,6 +112,8 @@ public:
|
||||
BankScreen(const std::filesystem::path&, BankState);
|
||||
Image render() const;
|
||||
BankRequest click(int x, int y, bool right = false);
|
||||
// Mouse DOWN: draws the bottom button under the pointer pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
BankRequest key(std::string_view);
|
||||
bool text(std::string_view);
|
||||
bool close_requested() const { return close_requested_; }
|
||||
@@ -153,6 +155,9 @@ private:
|
||||
bool credit_fee_confirmation_open_ = false, credit_notice_open_ = false;
|
||||
bool credit_fees_accepted_ = false;
|
||||
bool selling_shares_ = false;
|
||||
int pressed_button_ = -1; // 0 left, 1 right bottom button while the mouse button is held
|
||||
int pressed_key_ = -1; // calculator key held down by the mouse
|
||||
int pressed_dialog_ = 0; // GameEndTaxDialog::Button (0 none) of an open notice/question held down by the mouse
|
||||
bool calculator_stock_count_ = false;
|
||||
bool calculator_property_count_ = false;
|
||||
int selected_stock_ = 11;
|
||||
|
||||
@@ -27,6 +27,16 @@ int main(int argc, char** argv) {
|
||||
check(screen.render().width == 320, "original bank room canvas");
|
||||
check(screen.click(270, 90).kind == BankRequestKind::none && screen.state_json().find("\"deposit_open\":true") != std::string::npos,
|
||||
"Kasse opens the deposit view locally");
|
||||
{ // a bottom button looks pressed while the mouse button is held and normal again after the release
|
||||
const auto raised = screen.render();
|
||||
check(!screen.press(10, 10), "no pressed look outside the buttons");
|
||||
check(screen.press(90, 180) && screen.render().pixels != raised.pixels, "Einzahlen shows the pressed look");
|
||||
check(!screen.press(90, 180), "an unchanged press does not redraw");
|
||||
screen.click(90, 180);
|
||||
screen.click(0, 0, true); // back to the Sparbuch page (the calculator was opened by the click)
|
||||
screen.click(270, 90);
|
||||
check(screen.render().pixels == raised.pixels, "the release ends the pressed look");
|
||||
}
|
||||
screen.click(90, 180);
|
||||
check(screen.calculator_open(), "Einzahlen button opens the original calculator");
|
||||
check(!screen.text("-500"), "rejects non-digit input");
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The frame of a wide push button (width > 31) as every dialog of the game draws it, in both looks:
|
||||
// raised - drop shadow at the right and bottom, bevel art at y=74 of the widget image;
|
||||
// pressed - no shadow, the button moved two pixels down and right, bevel art at y=44.
|
||||
// A button without a lasting state (Kaufen, Verkaufen, Angebot, Abbruch, ...) is shown pressed while the mouse button is
|
||||
// held down; the screens keep the held button in `pressed_*` members and draw it with this helper. Buttons that carry a
|
||||
// lasting state (a selected competition, a toggle that is on) use the same pressed look.
|
||||
//
|
||||
// This is the single place of the drawing; the dialogs only choose the position, width, state and label.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
#include "formats/vga.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
|
||||
// Draws the frame of a button of the given width (10 pixels high) with its top left corner at (x,y).
|
||||
// Returns the offset (0 raised, 2 pressed) that the label must be moved by; the label colour mode of the
|
||||
// pressed look is the one after the raised one in the executable (Advertising_Button_RuntimeField + 1).
|
||||
// transparent: a palette index of the widget image that is not copied (the dialogs that draw over a picture use 0xc0), -1 none.
|
||||
// background: the colour that replaces the drop shadow of a pressed button; -1 takes the pixel under the button's
|
||||
// lower left corner, as the original does.
|
||||
inline int draw_wide_button_frame(Image& out, const Image& art, int x, int y, int width, bool pressed,
|
||||
int transparent = -1, int background = -1) {
|
||||
constexpr int height = 10;
|
||||
const auto put = [&](int sx, int sy, int dx, int dy, int w, int h) {
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const int tx = dx + xx, ty = dy + yy, px = sx + xx, py = sy + yy;
|
||||
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height || px < 0 || py < 0 ||
|
||||
px >= art.width || py >= art.height) continue;
|
||||
const uint8_t color = art.pixels[size_t(py) * size_t(art.width) + size_t(px)];
|
||||
if (color != transparent) out.at(tx, ty) = color;
|
||||
}
|
||||
};
|
||||
const auto fill = [&](int fx, int fy, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, fy); yy < std::min(out.height, fy + h); ++yy)
|
||||
for (int xx = std::max(0, fx); xx < std::min(out.width, fx + w); ++xx) out.at(xx, yy) = color;
|
||||
};
|
||||
if (pressed) {
|
||||
// the place of the shadow shows the background again
|
||||
const uint8_t shade = background >= 0 ? uint8_t(background)
|
||||
: out.at(std::clamp(x, 0, out.width - 1), std::clamp(y + height, 0, out.height - 1));
|
||||
fill(x, y, width + 1, 2, shade);
|
||||
fill(x, y, 2, height + 1, shade);
|
||||
x += 2;
|
||||
y += 2;
|
||||
} else {
|
||||
fill(x + 2, y + height, width, 2, 0x40);
|
||||
fill(x + width, y + 2, 2, height, 0x40);
|
||||
}
|
||||
const int top = pressed ? 44 : 74;
|
||||
put(24, top, x, y, 31, height);
|
||||
int at = 31, left = width - 31;
|
||||
while (left > 20) {
|
||||
const int n = std::min(8, left - 20);
|
||||
put(24, top + 10, x + at, y, n, height);
|
||||
at += n;
|
||||
left -= n;
|
||||
}
|
||||
put(45 - left, top + 20, x + at, y, left, height);
|
||||
return pressed ? 2 : 0;
|
||||
}
|
||||
|
||||
} // namespace bmh::ui
|
||||
@@ -0,0 +1,119 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// button_frame.hpp: the shared wide push button must produce exactly the pixels of the drawing that every dialog used
|
||||
// before it was shared (the reference below is that drawing, written out once). Needs no game data: the art is synthetic.
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
#include "formats/diamond_image.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
|
||||
using namespace bmh;
|
||||
|
||||
namespace {
|
||||
|
||||
int failures = 0;
|
||||
|
||||
// The drawing as the dialogs had it: shadow or erased frame, left part, repeated 8 pixel strips, right end.
|
||||
int reference(Image& out, const Image& art, int x, int y, int width, bool pressed, int key, int bg) {
|
||||
const auto copy = [&](int sx, int sy, int dx, int dy, int w, int h) {
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t c = art.pixels[size_t(sy + yy) * art.width + size_t(sx + xx)];
|
||||
if (c != key && dx + xx >= 0 && dx + xx < out.width && dy + yy >= 0 && dy + yy < out.height)
|
||||
out.at(dx + xx, dy + yy) = c;
|
||||
}
|
||||
};
|
||||
const auto rect = [&](int rx, int ry, int w, int h, uint8_t c) {
|
||||
for (int yy = std::max(0, ry); yy < std::min(out.height, ry + h); ++yy)
|
||||
for (int xx = std::max(0, rx); xx < std::min(out.width, rx + w); ++xx) out.at(xx, yy) = c;
|
||||
};
|
||||
if (pressed) {
|
||||
const uint8_t c = bg >= 0 ? uint8_t(bg) : out.at(x, y + 10);
|
||||
rect(x, y, width + 1, 2, c); rect(x, y, 2, 11, c); x += 2; y += 2;
|
||||
} else { rect(x + 2, y + 10, width, 2, 0x40); rect(x + width, y + 2, 2, 10, 0x40); }
|
||||
const int sy = pressed ? 44 : 74;
|
||||
copy(24, sy, x, y, 31, 10);
|
||||
int at = 31, left = width - 31;
|
||||
while (left > 20) { const int n = std::min(8, left - 20); copy(24, sy + 10, x + at, y, n, 10); at += n; left -= n; }
|
||||
copy(45 - left, sy + 20, x + at, y, left, 10);
|
||||
return pressed ? 2 : 0;
|
||||
}
|
||||
|
||||
// The window frame as every dialog drew it before it was shared.
|
||||
void reference_frame(Image& o, const Image& a, const LeImage& exe, int x, int y, int w, int h, bool shadow) {
|
||||
const auto fill = [&](int fx, int fy, int fw, int fh, uint8_t c) {
|
||||
for (int yy = std::max(0, fy); yy < std::min(o.height, fy + fh); ++yy)
|
||||
for (int xx = std::max(0, fx); xx < std::min(o.width, fx + fw); ++xx) o.at(xx, yy) = c;
|
||||
};
|
||||
const auto copy = [&](int sx, int sy, int dx, int dy, int cw, int ch) {
|
||||
for (int yy = 0; yy < ch; ++yy) for (int xx = 0; xx < cw; ++xx)
|
||||
o.at(dx + xx, dy + yy) = a.pixels[size_t(sy + yy) * a.width + size_t(sx + xx)];
|
||||
};
|
||||
if (shadow) { fill(x + 2, y + h, w, 2, 0x40); fill(x + w, y + 2, 2, h, 0x40); }
|
||||
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx)
|
||||
o.at(x + xx, y + yy) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + size_t((yy - 4) & 15) * 16 + size_t((xx - 4) & 15));
|
||||
copy(0, 0, x, y, 4, 4); copy(4, 0, x + w - 4, y, 4, 4); copy(0, 4, x, y + h - 4, 4, 4); copy(4, 4, x + w - 4, y + h - 4, 4, 4);
|
||||
for (int at = 4; at < w - 4; at += 74) { const int n = std::min(74, w - 4 - at); copy(0, 104, x + at, y, n, 4); copy(0, 108, x + at, y + h - 4, n, 4); }
|
||||
for (int at = 4; at < h - 4; at += 96) { const int n = std::min(96, h - 4 - at); copy(0, 8, x, y + at, 4, n); copy(4, 8, x + w - 4, y + at, 4, n); }
|
||||
}
|
||||
|
||||
void frames_and_calculator(const Image& art) {
|
||||
const LeImage exe = diamond_constants_image();
|
||||
for (const auto [w, h] : {std::pair{217, 99}, std::pair{319, 90}, std::pair{113, 140}, std::pair{42, 42}, std::pair{300, 200}})
|
||||
for (const bool shadow : {false, true}) {
|
||||
Image a(320, 240, 5), b(320, 240, 5);
|
||||
ui::draw_dialog_frame(a, art, exe, 0, 11, w, h, shadow); // inside the picture: the reference does not clip
|
||||
reference_frame(b, art, exe, 0, 11, w, h, shadow);
|
||||
if (a.pixels != b.pixels) { std::fprintf(stderr, "FAIL: dialog frame %dx%d shadow %d\n", w, h, int(shadow)); ++failures; }
|
||||
}
|
||||
// the calculator: the panel is the 113x136 picture with its shadow, a key the 15x14 (pressed 14x13) picture
|
||||
Image big(130, 160);
|
||||
for (size_t i = 0; i < big.pixels.size(); ++i) big.pixels[i] = uint8_t((i * 29 + 5) % 253);
|
||||
for (const bool pressed : {false, true}) {
|
||||
Image a(320, 240, 7), b(320, 240, 7);
|
||||
const int shift = ui::draw_calculator_key(a, big, 50, 60, pressed);
|
||||
const int p = pressed ? 1 : 0;
|
||||
for (int yy = 0; yy < 14 - p; ++yy) for (int xx = 0; xx < 15 - p; ++xx)
|
||||
b.at(50 + p + xx, 60 + p + yy) = big.pixels[size_t(136 + yy) * big.width + size_t(15 * p + xx)];
|
||||
if (shift != p || a.pixels != b.pixels) { std::fprintf(stderr, "FAIL: calculator key pressed %d\n", int(pressed)); ++failures; }
|
||||
}
|
||||
Image panel(320, 240, 7), expected(320, 240, 7);
|
||||
ui::draw_calculator_panel(panel, big, 103, 55);
|
||||
for (int yy = 0; yy < 136; ++yy) for (int xx = 0; xx < 113; ++xx) expected.at(103 + xx, 55 + yy) = big.pixels[size_t(yy) * big.width + size_t(xx)];
|
||||
for (int yy = 0; yy < 136; ++yy) for (int xx = 0; xx < 2; ++xx) expected.at(103 + 113 + xx, 55 + 2 + yy) = 0x40;
|
||||
for (int yy = 0; yy < 2; ++yy) for (int xx = 0; xx < 113; ++xx) expected.at(103 + 2 + xx, 55 + 136 + yy) = 0x40;
|
||||
if (panel.pixels != expected.pixels) { std::fprintf(stderr, "FAIL: calculator panel\n"); ++failures; }
|
||||
if (!ui::calculator_key_hit(103, 70, 103, 70) || ui::calculator_key_hit(119, 70, 103, 70) ||
|
||||
ui::calculator_key_hit(103, 84, 103, 70)) { std::fprintf(stderr, "FAIL: calculator key hit test\n"); ++failures; }
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
Image art(80, 120);
|
||||
for (size_t i = 0; i < art.pixels.size(); ++i) art.pixels[i] = uint8_t((i * 37 + i / 7) % 251);
|
||||
art.at(30, 80) = 0xc0; art.at(31, 80) = 0xc0; // transparent samples inside the used slices
|
||||
art.at(30, 50) = 0xc0;
|
||||
for (const int width : {32, 51, 56, 60, 64, 70, 75, 80, 94, 125})
|
||||
for (const bool pressed : {false, true})
|
||||
for (const int key : {-1, 0xc0})
|
||||
for (const int bg : {-1, 0x42}) {
|
||||
Image a(320, 240), b(320, 240);
|
||||
for (size_t i = 0; i < a.pixels.size(); ++i) a.pixels[i] = b.pixels[i] = uint8_t(i % 97 + 3);
|
||||
const int shift_a = ui::draw_wide_button_frame(a, art, 61, 166, width, pressed, key, bg);
|
||||
const int shift_b = reference(b, art, 61, 166, width, pressed, key, bg);
|
||||
if (shift_a != shift_b || a.pixels != b.pixels) {
|
||||
std::fprintf(stderr, "FAIL: width %d pressed %d key %d background %d\n", width, int(pressed), key, bg);
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
// a button at the very edge of the picture is clipped, not an error
|
||||
Image edge(320, 240);
|
||||
ui::draw_wide_button_frame(edge, art, 300, 232, 75, true);
|
||||
ui::draw_wide_button_frame(edge, art, -10, -3, 75, false);
|
||||
frames_and_calculator(art);
|
||||
if (failures) return 1;
|
||||
std::puts("PASS shared button, dialog frame and calculator widgets");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The number calculator window of the game (bank, offers, advertising, contracts, stadium, ...): its panel with the
|
||||
// drop shadow and its keys. The position of the keys and presets comes from tables of the executable, the labels and
|
||||
// the title are drawn by each dialog; only the shared pictures are drawn here.
|
||||
// panel: 113x136 picture from the calculator art at (0,0), shadow 2 pixels right and below.
|
||||
// key: 15x14 picture at (0,136) of the art; a key held down by the mouse is the 14x13 picture at (15,136) drawn one
|
||||
// pixel down and right, and its legend moves by the same pixel.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
#include "formats/vga.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
|
||||
// A key of the calculator window is 16x14 pixels wide for hit tests; this tells whether (x,y) lies in the key at (kx,ky).
|
||||
inline bool calculator_key_hit(int x, int y, int kx, int ky) { return x >= kx && x < kx + 16 && y >= ky && y < ky + 14; }
|
||||
|
||||
// Draws the calculator panel with its top left corner at (x0,y0).
|
||||
inline void draw_calculator_panel(Image& out, const Image& art, int x0, int y0) {
|
||||
const auto put = [&](int sx, int sy, int dx, int dy, int w, int h) {
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const int tx = dx + xx, ty = dy + yy, px = sx + xx, py = sy + yy;
|
||||
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height || px < 0 || py < 0 ||
|
||||
px >= art.width || py >= art.height) continue;
|
||||
out.at(tx, ty) = art.pixels[size_t(py) * size_t(art.width) + size_t(px)];
|
||||
}
|
||||
};
|
||||
const auto fill = [&](int fx, int fy, int w, int h) {
|
||||
for (int yy = std::max(0, fy); yy < std::min(out.height, fy + h); ++yy)
|
||||
for (int xx = std::max(0, fx); xx < std::min(out.width, fx + w); ++xx) out.at(xx, yy) = 0x40;
|
||||
};
|
||||
put(0, 0, x0, y0, 113, 136);
|
||||
fill(x0 + 113, y0 + 2, 2, 136);
|
||||
fill(x0 + 2, y0 + 136, 113, 2);
|
||||
}
|
||||
|
||||
// Draws the picture of the key whose top left corner is (x,y). Returns the offset (0 or 1) by which the legend moves.
|
||||
inline int draw_calculator_key(Image& out, const Image& art, int x, int y, bool pressed) {
|
||||
const int p = pressed ? 1 : 0;
|
||||
for (int yy = 0; yy < 14 - p; ++yy) for (int xx = 0; xx < 15 - p; ++xx) {
|
||||
const int tx = x + p + xx, ty = y + p + yy, px = 15 * p + xx, py = 136 + yy;
|
||||
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height || px >= art.width || py >= art.height) continue;
|
||||
out.at(tx, ty) = art.pixels[size_t(py) * size_t(art.width) + size_t(px)];
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace bmh::ui
|
||||
@@ -4,6 +4,7 @@
|
||||
// views and converts button and row clicks into ClubInfoRequest values. It does not change the game itself.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/club_info.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -317,13 +318,8 @@ Image ClubInfoScreen::render() const {
|
||||
const bool active = (x == 1 && pressed_button_ == (projection_.has_squad ? ClubInfoButton::view : ClubInfoButton::category)) ||
|
||||
(x == 60 && pressed_button_ == ClubInfoButton::statistics) ||
|
||||
(x == 120 && pressed_button_ == ClubInfoButton::category);
|
||||
if (active) { const uint8_t base = out.at(x, 225); rect(out, x, 215, width + 1, 2, base); rect(out, x, 215, 2, height + 1, base); x += 2; }
|
||||
else { rect(out, x + 2, 225, width, 2, 0x40); rect(out, x + width, 217, 2, height, 0x40); }
|
||||
const int sy = active ? 44 : 74;
|
||||
copy(out, widgets_, 24, sy, x, 215 + (active ? 2 : 0), 31, 10);
|
||||
int at = 31, remain = width - 31;
|
||||
while (remain > 20) { const int n = std::min(8, remain - 20); copy(out, widgets_, 24, sy + 10, x + at, 215 + (active ? 2 : 0), n, 10); at += n; remain -= n; }
|
||||
copy(out, widgets_, 45 - remain, sy + 20, x + at, 215 + (active ? 2 : 0), remain, 10);
|
||||
(void)height;
|
||||
x += draw_wide_button_frame(out, widgets_, x, 215, width, active); // button_frame.hpp
|
||||
if (!label.empty()) {
|
||||
const int mode = exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(active));
|
||||
const int label_baseline = active ? 224 : 222;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/club_player_detail.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -131,22 +133,16 @@ void ClubPlayerDetailScreen::text(Image& out,int x,int baseline,std::string_view
|
||||
out.at(x+xx,baseline-font.baseline+yy)=projection_.gradient_text?exe_.u8(::bmh::layout::Advertising_Text_RuntimeField+gradient*6+yy):color;
|
||||
}
|
||||
void ClubPlayerDetailScreen::frame(Image& out,int x,int y,int w,int h) const {
|
||||
for(int yy=4;yy<h-3;++yy)for(int xx=4;xx<w-3;++xx)out.at(x+xx,y+yy)=exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField+((yy-4)%16)*16+(xx-4)%16);
|
||||
copy(out,widgets_,0,0,x,y,4,4);copy(out,widgets_,4,0,x+w-4,y,4,4);
|
||||
copy(out,widgets_,0,4,x,y+h-4,4,4);copy(out,widgets_,4,4,x+w-4,y+h-4,4,4);
|
||||
for(int at=4;at<w-4;at+=74){const int n=std::min(74,w-4-at);copy(out,widgets_,0,104,x+at,y,n,4);copy(out,widgets_,0,108,x+at,y+h-4,n,4);}
|
||||
for(int at=4;at<h-4;at+=96){const int n=std::min(96,h-4-at);copy(out,widgets_,0,8,x,y+at,4,n);copy(out,widgets_,4,8,x+w-4,y+at,4,n);}
|
||||
draw_dialog_frame(out,widgets_,exe_,x,y,w,h,false); // dialog_frame.hpp
|
||||
}
|
||||
void ClubPlayerDetailScreen::button(Image& out,int x,int y,int width,std::string_view value,bool active) const {
|
||||
const int height=width>31?10:9;
|
||||
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
|
||||
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
if(width>31){
|
||||
const int sy=active?44:74;
|
||||
copy(out,widgets_,24,sy,x,y,31,10);int at=31,remaining=width-31;
|
||||
while(remaining>20){const int n=std::min(8,remaining-20);copy(out,widgets_,24,sy+10,x+at,y,n,10);at+=n;remaining-=n;}
|
||||
copy(out,widgets_,45-remaining,sy+20,x+at,y,remaining,10);
|
||||
}else frame(out,x,y,width,height);
|
||||
if(width>31){const int shift=draw_wide_button_frame(out,widgets_,x,y,width,active);x+=shift;y+=shift;} // button_frame.hpp
|
||||
else{
|
||||
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
|
||||
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
frame(out,x,y,width,height);
|
||||
}
|
||||
const int font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(active));
|
||||
if(font==3){text(out,x,y+height/2+2,value,0,x+width);return;}
|
||||
int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
|
||||
|
||||
+51
-40
@@ -4,6 +4,9 @@
|
||||
// input into ContractRequest values. Applying an offer or insurance is left to the session.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/contracts.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -46,22 +49,7 @@ void pattern(Image& out, const LeImage& exe, int x, int y, int width, int height
|
||||
// Draws a panel in the original style: optional drop shadow, tiled pattern inside, four 4x4 corners
|
||||
// and edge strips (copied in pieces of at most 74 pixels horizontally and 96 vertically).
|
||||
void frame(Image& out, const LeImage& exe, const Image& widgets, int x, int y, int width, int height, bool shadow = true) {
|
||||
if (shadow) { fill(out, x + 2, y + height, width, 2, 0x40); fill(out, x + width, y + 2, 2, height, 0x40); }
|
||||
pattern(out, exe, x + 4, y + 4, width - 7, height - 7);
|
||||
copy_region(out, widgets, 0, 0, x, y, 4, 4);
|
||||
copy_region(out, widgets, 4, 0, x + width - 4, y, 4, 4);
|
||||
copy_region(out, widgets, 0, 4, x, y + height - 4, 4, 4);
|
||||
copy_region(out, widgets, 4, 4, x + width - 4, y + height - 4, 4, 4);
|
||||
for (int at = 4; at < width - 4; at += 74) {
|
||||
const int n = std::min(74, width - 4 - at);
|
||||
copy_region(out, widgets, 0, 104, x + at, y, n, 4);
|
||||
copy_region(out, widgets, 0, 108, x + at, y + height - 4, n, 4);
|
||||
}
|
||||
for (int at = 4; at < height - 4; at += 96) {
|
||||
const int n = std::min(96, height - 4 - at);
|
||||
copy_region(out, widgets, 0, 8, x, y + at, 4, n);
|
||||
copy_region(out, widgets, 4, 8, x + width - 4, y + at, 4, n);
|
||||
}
|
||||
draw_dialog_frame(out, widgets, exe, x, y, width, height, shadow); // dialog_frame.hpp
|
||||
}
|
||||
|
||||
// Fills a rectangle with one palette index; throws if it leaves the image.
|
||||
@@ -452,15 +440,9 @@ Image ContractsScreen::render() const {
|
||||
const std::array<std::string,4> tabs{original_to_utf8(texts_[117]),original_to_utf8(texts_[118]),original_to_utf8(texts_[119]),original_to_utf8(texts_[120])};
|
||||
for (int i = 0; i < (state_.mode_three?4:3); ++i) {
|
||||
const int x = i * 60 + 2, w = i == 3 ? 71 : 51;
|
||||
if(i!=tab_) {fill(out,x+2,225,w,2,0x40);fill(out,x+w,217,2,10,0x40);}
|
||||
else {const uint8_t color=out.at(x,225);fill(out,x,215,w+1,2,color);fill(out,x,215,2,11,color);}
|
||||
const int source_y = i == tab_ ? 44 : 74;
|
||||
const int dest_y = 215 + (i == tab_ ? 2 : 0);
|
||||
const int dest_x = x + (i == tab_ ? 2 : 0);
|
||||
copy_region(out, widgets_, 24, source_y, dest_x, dest_y, 31, 10);
|
||||
int tab_at = 31, remain = w - 31;
|
||||
while (remain > 20) { const int n = std::min(8, remain - 20); copy_region(out, widgets_, 24, source_y + 10, dest_x + tab_at, dest_y, n, 10); tab_at += n; remain -= n; }
|
||||
if (remain > 0) copy_region(out, widgets_, 45 - remain, source_y + 20, dest_x + tab_at, dest_y, remain, 10);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, 215, w, i == tab_); // button_frame.hpp
|
||||
const int dest_y = 215 + shift;
|
||||
const int dest_x = x + shift;
|
||||
sprite_font_.draw(out, dest_x + w/2 - sprite_font_.text_width(tabs[size_t(i)])/2, dest_y+7, tabs[size_t(i)], exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + (i==tab_)));
|
||||
}
|
||||
|
||||
@@ -469,14 +451,12 @@ Image ContractsScreen::render() const {
|
||||
frame(out, exe_, widgets_, x, y, w, h, shadow);
|
||||
};
|
||||
// Draws a button of width w: 31 pixel left part, repeated strips and the right end, with the label centred.
|
||||
auto button = [&](int x, int y, int w, std::string_view label) {
|
||||
fill(out, x + 2, y + 10, w, 2, 0x40); fill(out, x + w, y + 2, 2, 10, 0x40);
|
||||
copy_region(out, widgets_, 24, 74, x, y, 31, 10);
|
||||
int at = 31, remaining = w - 31;
|
||||
while (remaining > 20) { const int n = std::min(8, remaining - 20); copy_region(out, widgets_, 24, 84, x + at, y, n, 10); at += n; remaining -= n; }
|
||||
if (remaining > 0) copy_region(out, widgets_, 45 - remaining, 94, x + at, y, remaining, 10);
|
||||
const int font = exe_.u8(::bmh::layout::Advertising_Button_RuntimeField);
|
||||
sprite_font_.draw(out, x + (w - sprite_font_.text_width(label)) / 2, y + 7, label, font);
|
||||
// `id` is the button's number on the page; the one held down by the mouse is drawn pressed (button_frame.hpp).
|
||||
auto button = [&](int id, int x, int y, int w, std::string_view label) {
|
||||
const bool down = pressed_button_ == id;
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, w, down);
|
||||
const int font = exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(down));
|
||||
sprite_font_.draw(out, x + shift + (w - sprite_font_.text_width(label)) / 2, y + shift + 7, label, font);
|
||||
};
|
||||
// Looks up a text from the original text table by its pointer-table address.
|
||||
auto db = [&](uint32_t address) { return original_to_utf8(texts_[(address-::bmh::layout::TextPointerTable)/4]); };
|
||||
@@ -544,19 +524,18 @@ Image ContractsScreen::render() const {
|
||||
}
|
||||
}
|
||||
}
|
||||
button(5,top+76,51,db(::bmh::layout::Contracts_Out_ExecutableField17));button(90,top+76,80,db(::bmh::layout::Contracts_Out_ExecutableField18));
|
||||
if(!team&&state_.mode_three)button(261,top+76,51,db(page_==Page::player_offer?::bmh::layout::Contracts_Out_ExecutableField2: ::bmh::layout::Contracts_Out_ExecutableField));
|
||||
button(0,5,top+76,51,db(::bmh::layout::Contracts_Out_ExecutableField17));button(1,90,top+76,80,db(::bmh::layout::Contracts_Out_ExecutableField18));
|
||||
if(!team&&state_.mode_three)button(2,261,top+76,51,db(page_==Page::player_offer?::bmh::layout::Contracts_Out_ExecutableField2: ::bmh::layout::Contracts_Out_ExecutableField));
|
||||
} else if (page_ == Page::calculator) {
|
||||
// Calculator: background image at (10,10), drop shadow, label, 15 keys (digits and the letters D, R, C, J, N),
|
||||
// 8 preset buttons and the current input right-aligned. Key and preset positions come from tables in the executable.
|
||||
copy_region(out, calculator_, 0, 0, 10, 10, 113, 136);
|
||||
fill(out,123,12,2,136,0x40);fill(out,12,146,113,2,0x40);
|
||||
draw_calculator_panel(out, calculator_, 10, 10); // calculator_widgets.hpp
|
||||
const auto label=calculator_bonus_index_==-2?db(::bmh::layout::Contracts_Out_ExecutableField19):calculator_bonus_index_<0?db(::bmh::layout::Contracts_Out_ExecutableField14):db(::bmh::layout::Contracts_Out_ExecutableField4+calculator_bonus_index_*4);
|
||||
centered(18,115,24,label,98);
|
||||
for(int i=0;i<15;++i) {
|
||||
const int x=10+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+i*2), y=10+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+i);
|
||||
copy_region(out,calculator_,0,136,x,y,15,14);
|
||||
text(out,x+5,y+9,std::string(1,"0123456789DRCJN"[i]),98,-1);
|
||||
const int p=draw_calculator_key(out,calculator_,x,y,pressed_key_==i);
|
||||
text(out,x+5+p,y+9+p,std::string(1,"0123456789DRCJN"[i]),98,-1);
|
||||
}
|
||||
for(int i=0;i<8;++i) {
|
||||
const int x=10+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+(i+15)*2), y=10+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+i+15);
|
||||
@@ -576,7 +555,8 @@ Image ContractsScreen::render() const {
|
||||
notice.body=utf8_to_original(state_.feedback);
|
||||
notice.source_manager_flags=0x80;
|
||||
draw_source_dialog(out,{widgets_,faces_,&badge_atlas_,font_,large_font_,
|
||||
exe_,sprite_font_,texts_},notice,state_.gradient_text);
|
||||
exe_,sprite_font_,texts_},notice,state_.gradient_text,
|
||||
pressed_button_==3?std::optional<GameEndTaxDialog::Button>(GameEndTaxDialog::Button::acknowledge):std::nullopt);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -586,7 +566,38 @@ Image ContractsScreen::render() const {
|
||||
// (a request that the session acknowledges), the tab row switches tabs, left click on a name shows player info.
|
||||
// Calculator: keys, presets and accept/cancel. Offer and premium pages: term columns, premium lines and the buttons
|
||||
// at top+76 (back, send, switch page).
|
||||
// Mouse DOWN on one of the buttons below the offer or premium panel (back, send, switch page): drawn pressed until the
|
||||
// release. Returns true when the picture changed.
|
||||
bool ContractsScreen::press(int x, int y) {
|
||||
int id = -1;
|
||||
if (page_ == Page::result) {
|
||||
// OK of the manager's answer (id 3)
|
||||
if (source_dialog_button_at(TaxDialogKind::acknowledgement, false, x, y) == GameEndTaxDialog::Button::acknowledge) id = 3;
|
||||
} else if (page_ == Page::player_offer || page_ == Page::team_premiums) {
|
||||
const bool team = page_ == Page::team_premiums && team_premium_mode_;
|
||||
const auto selected = std::find_if(state_.players.begin(), state_.players.end(), [&](const auto& p) { return p.row == state_.selected_row; });
|
||||
const int top = team || selected == state_.players.end() || selected->row >= 13 ? 22 : 130;
|
||||
if (y >= top + 76 && y <= top + 85) {
|
||||
if (x < 60) id = 0;
|
||||
else if (x >= 90 && x <= 170) id = 1;
|
||||
else if (x >= 261 && x <= 312 && !team && state_.mode_three) id = 2;
|
||||
}
|
||||
}
|
||||
// a key of the open calculator
|
||||
int key = -1;
|
||||
if (page_ == Page::calculator)
|
||||
for (int i = 0; i < 15; ++i)
|
||||
if (calculator_key_hit(x, y, 10 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
|
||||
10 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
|
||||
const bool changed = id != pressed_button_ || key != pressed_key_;
|
||||
pressed_button_ = id;
|
||||
pressed_key_ = key;
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool ContractsScreen::click(int x, int y, bool right) {
|
||||
pressed_button_ = -1; // the release ends the pressed look
|
||||
pressed_key_ = -1;
|
||||
if (page_ == Page::result) {
|
||||
if (x >= 95 && x <= 220 && y >= 166 && y <= 176) { page_ = result_return_; result_backdrop_.reset(); state_.feedback.clear(); return true; }
|
||||
return false;
|
||||
|
||||
@@ -96,6 +96,8 @@ public:
|
||||
ContractsScreen(const std::filesystem::path&, ContractsState);
|
||||
Image render() const;
|
||||
bool click(int x, int y, bool right = false);
|
||||
// Mouse DOWN: the button under the pointer is drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
bool process_timer_expired(int pointer_x, int pointer_y);
|
||||
bool key(std::string_view);
|
||||
bool move(int x, int y);
|
||||
@@ -114,6 +116,8 @@ public:
|
||||
private:
|
||||
enum class Page : uint8_t { roster, player_offer, team_premiums, calculator, insurance, result };
|
||||
ContractsState state_;
|
||||
int pressed_button_ = -1; // button below the panel held down by the mouse
|
||||
int pressed_key_ = -1; // calculator key held down by the mouse
|
||||
LeImage exe_;
|
||||
Font font_;
|
||||
Font large_font_;
|
||||
|
||||
+2
-13
@@ -4,6 +4,7 @@
|
||||
// acknowledged DeskState updates. It also provides desk_request_json() and desk_menu_name().
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/desktop.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
@@ -147,19 +148,7 @@ void DesktopScreen::sprite_text(Image& out, int x, int baseline, std::string_vie
|
||||
}
|
||||
void DesktopScreen::frame(Image& out, int x, int y, int w, int h) const {
|
||||
if (w < 8 || h < 8) throw FormatError("desktop: invalid drawer size");
|
||||
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx)
|
||||
if (x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height)
|
||||
out.at(x + xx, y + yy) = exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + ((yy - 4) % 16) * 16 + (xx - 4) % 16);
|
||||
copy(out, widgets_, 0, 0, x, y, 4, 4); copy(out, widgets_, 4, 0, x + w - 4, y, 4, 4);
|
||||
copy(out, widgets_, 0, 4, x, y + h - 4, 4, 4); copy(out, widgets_, 4, 4, x + w - 4, y + h - 4, 4, 4);
|
||||
for (int k = 4; k < w - 4; k += 74) {
|
||||
const int n = std::min(74, w - 4 - k);
|
||||
copy(out, widgets_, 0, 104, x + k, y, n, 4); copy(out, widgets_, 0, 108, x + k, y + h - 4, n, 4);
|
||||
}
|
||||
for (int k = 4; k < h - 4; k += 96) {
|
||||
const int n = std::min(96, h - 4 - k);
|
||||
copy(out, widgets_, 0, 8, x, y + k, 4, n); copy(out, widgets_, 4, 8, x + w - 4, y + k, 4, n);
|
||||
}
|
||||
draw_dialog_frame(out, widgets_, exe_, x, y, w, h, false); // dialog_frame.hpp
|
||||
}
|
||||
void DesktopScreen::digits(Image& out, int value, int sx, int sy, int w, int h, int x, int y, int base, int gap) const {
|
||||
int count = 1;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The frame of a panel or dialog window as the game draws it everywhere: an optional drop shadow (2 pixels right and
|
||||
// below), the 16x16 background pattern that the executable carries, the four 4x4 corners of the widget image and its edge
|
||||
// strips (copied in pieces of at most 74 pixels horizontally and 96 vertically).
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/le.hpp"
|
||||
#include "formats/vga.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
|
||||
// Draws the frame of the window with top left corner (x,y) and size w x h.
|
||||
inline void draw_dialog_frame(Image& out, const Image& widgets, const LeImage& exe,
|
||||
int x, int y, int w, int h, bool shadow = true) {
|
||||
const auto fill = [&](int fx, int fy, int fw, int fh, uint8_t color) {
|
||||
for (int yy = std::max(0, fy); yy < std::min(out.height, fy + fh); ++yy)
|
||||
for (int xx = std::max(0, fx); xx < std::min(out.width, fx + fw); ++xx) out.at(xx, yy) = color;
|
||||
};
|
||||
const auto put = [&](int sx, int sy, int dx, int dy, int cw, int ch) {
|
||||
for (int yy = 0; yy < ch; ++yy) for (int xx = 0; xx < cw; ++xx) {
|
||||
const int tx = dx + xx, ty = dy + yy, px = sx + xx, py = sy + yy;
|
||||
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height || px < 0 || py < 0 ||
|
||||
px >= widgets.width || py >= widgets.height) continue;
|
||||
out.at(tx, ty) = widgets.pixels[size_t(py) * size_t(widgets.width) + size_t(px)];
|
||||
}
|
||||
};
|
||||
if (shadow) { fill(x + 2, y + h, w, 2, 0x40); fill(x + w, y + 2, 2, h, 0x40); }
|
||||
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx) {
|
||||
const int tx = x + xx, ty = y + yy;
|
||||
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height) continue;
|
||||
out.at(tx, ty) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField +
|
||||
size_t((yy - 4) & 15) * 16 + size_t((xx - 4) & 15));
|
||||
}
|
||||
put(0, 0, x, y, 4, 4);
|
||||
put(4, 0, x + w - 4, y, 4, 4);
|
||||
put(0, 4, x, y + h - 4, 4, 4);
|
||||
put(4, 4, x + w - 4, y + h - 4, 4, 4);
|
||||
for (int at = 4; at < w - 4; at += 74) {
|
||||
const int n = std::min(74, w - 4 - at);
|
||||
put(0, 104, x + at, y, n, 4);
|
||||
put(0, 108, x + at, y + h - 4, n, 4);
|
||||
}
|
||||
for (int at = 4; at < h - 4; at += 96) {
|
||||
const int n = std::min(96, h - 4 - at);
|
||||
put(0, 8, x, y + at, 4, n);
|
||||
put(4, 8, x + w - 4, y + at, 4, n);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bmh::ui
|
||||
@@ -110,6 +110,9 @@ public:
|
||||
FlowResult click(int x, int y, bool right = false, bool double_click = false);
|
||||
// Mouse button press (DOWN) entry point; click() handles the matching release.
|
||||
FlowResult pointer_down(int x,int y,bool right=false);
|
||||
// Left press on a screen whose buttons have no lasting state (bank, offer editor, ...): the button under the pointer is
|
||||
// drawn pressed until the release. Returns true when the screen must be presented at once.
|
||||
bool press_hold(int x,int y);
|
||||
// Timer expiry event together with the current pointer position.
|
||||
FlowResult process_timer_expired(int pointer_x = 0, int pointer_y = 0);
|
||||
bool timed_notice_open() const;
|
||||
|
||||
+12
-12
@@ -5,6 +5,8 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -154,12 +156,7 @@ private:
|
||||
}
|
||||
};
|
||||
void frame(Image& o,const Image& a,const LeImage& exe,int x,int y,int w,int h,bool shadow) {
|
||||
if(shadow){fill(o,x+2,y+h,w,2,0x40);fill(o,x+w,y+2,2,h,0x40);}
|
||||
for(int yy=4;yy<h-3;++yy)for(int xx=4;xx<w-3;++xx)
|
||||
o.at(x+xx,y+yy)=exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField+size_t((yy-4)&15)*16+size_t((xx-4)&15));
|
||||
copy(o,a,0,0,x,y,4,4);copy(o,a,4,0,x+w-4,y,4,4);copy(o,a,0,4,x,y+h-4,4,4);copy(o,a,4,4,x+w-4,y+h-4,4,4);
|
||||
for(int at=4;at<w-4;at+=74){int n=std::min(74,w-4-at);copy(o,a,0,104,x+at,y,n,4);copy(o,a,0,108,x+at,y+h-4,n,4);}
|
||||
for(int at=4;at<h-4;at+=96){int n=std::min(96,h-4-at);copy(o,a,0,8,x,y+at,4,n);copy(o,a,4,8,x+w-4,y+at,4,n);}
|
||||
draw_dialog_frame(o,a,exe,x,y,w,h,shadow); // dialog_frame.hpp
|
||||
}
|
||||
std::string source_number(int32_t value, unsigned minimum_digits) {
|
||||
const bool negative = value < 0;
|
||||
@@ -176,12 +173,7 @@ std::string source_number(int32_t value, unsigned minimum_digits) {
|
||||
}
|
||||
void button(Image& o,const Image& a,const SpriteFont& sf,const LeImage& exe,int x,int y,int w,
|
||||
std::string_view label,bool selected=false){
|
||||
if(selected){const auto under=o.at(x,y+10);fill(o,x,y,w+1,2,under);fill(o,x,y,2,11,under);x+=2;y+=2;}
|
||||
else {fill(o,x+2,y+10,w,2,0x40);fill(o,x+w,y+2,2,10,0x40);}
|
||||
const int sy=selected?44:74;
|
||||
copy(o,a,24,sy,x,y,31,10);int used=31;
|
||||
while(w-used>20){int n=std::min(8,w-used-20);copy(o,a,24,sy+10,x+used,y,n,10);used+=n;}
|
||||
copy(o,a,45-(w-used),sy+20,x+used,y,w-used,10);
|
||||
const int shift=draw_wide_button_frame(o,a,x,y,w,selected);x+=shift;y+=shift;
|
||||
sf.draw(o,x+w/2-sf.text_width(label)/2,y+7,label,exe.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
|
||||
}
|
||||
std::string_view text_at(const TextDb& texts,uint32_t address) {
|
||||
@@ -339,6 +331,14 @@ void draw_source_dialog(Image& out,const SourceDialogAssets& assets,const TaxDia
|
||||
button(out,assets.widgets,assets.sprite,assets.exe,175,166,75,no,pressed==Button::no);
|
||||
}
|
||||
}
|
||||
GameEndTaxDialog::Button source_dialog_button_at(TaxDialogKind kind,bool timed_notice,int x,int y){
|
||||
using Button=GameEndTaxDialog::Button;
|
||||
if(y<166||y>176)return Button::none;
|
||||
if(kind==TaxDialogKind::acknowledgement)return !timed_notice&&x>=95&&x<=220?Button::acknowledge:Button::none;
|
||||
if(x>=62&&x<=137)return Button::yes;
|
||||
if(x>=175&&x<=250)return Button::no;
|
||||
return Button::none;
|
||||
}
|
||||
GameEndTaxDialog::Button GameEndTaxDialog::hit_test(int x,int y)const{
|
||||
if(y<166||y>176)return Button::none;
|
||||
if(projection_.kind==TaxDialogKind::acknowledgement)
|
||||
|
||||
@@ -122,6 +122,10 @@ class SpriteFont;
|
||||
// including the existing season-end dialog, share PresentManagerDialog's drawing path.
|
||||
// SourceBadgeFallback classifies the raw club token before reading its badge selector.
|
||||
bool source_badge_fallback(int club_token);
|
||||
// The button of a manager notice (kind acknowledgement: OK, kind question: Ja/Nein) under the pointer, for the pressed look
|
||||
// that every screen showing such a dialog draws while the mouse button is held (draw_source_dialog's `pressed`).
|
||||
// A timed notice has no button.
|
||||
GameEndTaxDialog::Button source_dialog_button_at(TaxDialogKind kind, bool timed_notice, int x, int y);
|
||||
struct SourceDialogAssets {
|
||||
const Image& widgets;
|
||||
const Image& faces;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// It reports state through phase(), value() and accepted_value(); the caller decides what to do with them.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/game_end_alternate.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
@@ -180,7 +181,7 @@ Image GameEndAlternateScoreScreen::render(std::optional<unsigned> pressed) const
|
||||
for (unsigned i=0; i<15; ++i) {
|
||||
const int p=pressed && *pressed==i ? 1:0;
|
||||
const int x=x0+assets_.exe.u16(::bmh::layout::Advertising_Click_RuntimeField+2*i),y=y0+assets_.exe.u8(::bmh::layout::Advertising_Click_RuntimeField2+i);
|
||||
copy(out,assets_.calculator,15*p,136,x+p,y+p,15-p,14-p);
|
||||
draw_calculator_key(out,assets_.calculator,x,y,p!=0);
|
||||
draw_text(out,x+p+5,y+p+9,keys.substr(i,1),0x62,false);
|
||||
}
|
||||
for (unsigned i=0; i<8; ++i) {
|
||||
|
||||
@@ -601,6 +601,7 @@ std::optional<int> IncomingTransferScreen::pointer_up(int x, int y, bool right,
|
||||
// then the bid area (x 4..190, y from 0x8f, rows 0x11 pixels high). Empty slots, unsupported transactions
|
||||
// (except in the pending variant) and clicks after an answer are ignored.
|
||||
std::optional<int> IncomingTransferScreen::click(int x, int y, bool right, uint64_t elapsed_ms) {
|
||||
notice_pressed_ = false; // the release ends the pressed look
|
||||
if (confirmation_mode_) {
|
||||
if (!right && x >= 95 && x <= 220 && y >= 166 && y <= 176)
|
||||
confirmation_dismissed_ = true;
|
||||
@@ -676,7 +677,17 @@ void IncomingTransferScreen::draw_notice(Image& out) const {
|
||||
notice.body=state_.notice_text;
|
||||
notice.source_manager_flags=confirmation_mode_?0x80:0x40;
|
||||
draw_source_dialog(out,{widgets_,faces_,&badge_atlas_,body_,heading_,exe_,
|
||||
sprite_font_,texts_},notice,gradient_text_);
|
||||
sprite_font_,texts_},notice,gradient_text_,
|
||||
notice_pressed_ ? std::optional<GameEndTaxDialog::Button>(GameEndTaxDialog::Button::acknowledge) : std::nullopt);
|
||||
}
|
||||
|
||||
// Mouse DOWN on OK of a confirmation notice: drawn pressed until the release. Returns true when the picture changed.
|
||||
bool IncomingTransferScreen::press(int x, int y) {
|
||||
const bool on = confirmation_mode_ && !confirmation_dismissed_ &&
|
||||
source_dialog_button_at(TaxDialogKind::acknowledgement, false, x, y) == GameEndTaxDialog::Button::acknowledge;
|
||||
const bool changed = on != notice_pressed_;
|
||||
notice_pressed_ = on;
|
||||
return changed;
|
||||
}
|
||||
|
||||
} // namespace bmh::ui
|
||||
@@ -151,6 +151,8 @@ public:
|
||||
void pointer_down(bool right = false);
|
||||
std::optional<int> pointer_up(int x, int y, bool right = false, uint64_t elapsed_ms = 0);
|
||||
std::optional<int> click(int x, int y, bool right = false, uint64_t elapsed_ms = 0);
|
||||
// Mouse DOWN on OK of a confirmation: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
std::optional<int> key(std::string_view name);
|
||||
bool dismiss_notice();
|
||||
bool notice_active() const { return !state_.notice_text.empty() && notice_active_; }
|
||||
@@ -174,6 +176,7 @@ private:
|
||||
uint8_t outcome_speed_setting_ = 0;
|
||||
bool outcome_dismissed_ = false;
|
||||
bool confirmation_mode_ = false, confirmation_dismissed_ = false;
|
||||
bool notice_pressed_ = false; // OK of the confirmation held down by the mouse
|
||||
std::optional<Image> confirmation_backdrop_;
|
||||
Image widgets_, faces_, badge_atlas_, seller_badge_atlas_;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// session. It also defines the constants and time conversion helper declared in the header.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/league_pairings.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
@@ -250,15 +251,8 @@ Image LeaguePairingsScreen::render() const {
|
||||
for(int n=0;n<8;++n) {
|
||||
const int x=1+(n/4)*74,y=176+(n%4)*13;
|
||||
const bool selected=pressed_button_==n||(state_.source.preferences&(1u<<n));
|
||||
int dx=x,dy=y;
|
||||
if(selected) {
|
||||
const uint8_t background=out.at(x,y+10);fill(out,x,y,71,2,background);fill(out,x,y,2,11,background);
|
||||
dx+=2;dy+=2;
|
||||
} else {fill(out,x+2,y+10,70,2,0x40);fill(out,x+70,y+2,2,10,0x40);}
|
||||
const int sy=selected?44:74;copy(out,widgets_,24,sy,dx,dy,31,10);
|
||||
int used=31;while(70-used>20) {const int amount=std::min(8,70-used-20);
|
||||
copy(out,widgets_,24,sy+10,dx+used,dy,amount,10);used+=amount;}
|
||||
const int left=70-used;copy(out,widgets_,45-left,sy+20,dx+used,dy,left,10);
|
||||
const int shift=draw_wide_button_frame(out,widgets_,x,y,70,selected); // button_frame.hpp
|
||||
const int dx=x+shift,dy=y+shift;
|
||||
const auto label=original_to_utf8(state_.buttons[size_t(n)]);
|
||||
sprite_.draw(out,dx+35-sprite_.text_width(label)/2,dy+7,label,exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + uint32_t(selected)));
|
||||
}
|
||||
|
||||
@@ -392,7 +392,10 @@ Image LeagueTableScreen::render() const {
|
||||
text(image, 12, y, "(" + formatted_field(row.previous_rank, 2) +
|
||||
original_text(exe_, ::bmh::layout::CupDraw_DrawGroupOverview_TextPointer3), previous_color, 24);
|
||||
}
|
||||
text(image, 30, y, row.name, row.name_color, 78);
|
||||
// The original does not clip the name: 19 character names (BORUSSIA M'GLADBACH, TSG 1899 HOFFENHEIM) are
|
||||
// shown in full and the games column, drawn afterwards at x=0x72, simply covers what reaches into it
|
||||
// (checked against the real 3.7 table). 120 only guards against absurdly long names.
|
||||
text(image, 30, y, row.name, row.name_color, 120);
|
||||
const std::string matches = formatted_field(row.games, 2) + original_text(exe_, ::bmh::layout::CupDraw_DrawGroupOverview_TextPointer4) +
|
||||
formatted_field(row.wins, 2) + original_text(exe_, ::bmh::layout::CupDraw_DrawGroupOverview_TextPointer5) +
|
||||
formatted_field(row.draws, 2) + original_text(exe_, ::bmh::layout::CupDraw_DrawGroupOverview_TextPointer5) +
|
||||
|
||||
+18
-11
@@ -4,6 +4,7 @@
|
||||
// Swapping or preparing is done by the session, not here.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/lineup.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
@@ -168,17 +169,16 @@ void LineupScreen::sprite_text(Image& out,int x,int baseline,std::string_view va
|
||||
copy(out,letters_,sx,(font-4)*7,x,baseline-6,width,7,0);x+=width;
|
||||
}
|
||||
}
|
||||
void LineupScreen::button(Image& out,int x,int y,std::string_view value) const {
|
||||
constexpr int width=55,height=10;
|
||||
rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);
|
||||
copy(out,widgets_,24,74,x,y,31,10);
|
||||
int at=31,remaining=width-31;
|
||||
while(remaining>20){const int n=std::min(8,remaining-20);copy(out,widgets_,24,84,x+at,y,n,10);at+=n;remaining-=n;}
|
||||
copy(out,widgets_,45-remaining,94,x+at,y,remaining,10);
|
||||
if(exe_.u8(::bmh::layout::Advertising_Button_RuntimeField)==3)text(out,x,y+7,value,0,x+width);
|
||||
void LineupScreen::button(Image& out,int x,int y,std::string_view value,bool pressed) const {
|
||||
constexpr int width=55;
|
||||
// a button held down by the mouse is drawn pressed (button_frame.hpp): moved by two pixels, other label mode
|
||||
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,pressed);
|
||||
const int mode=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField+int(pressed));
|
||||
x+=shift;y+=shift;
|
||||
if(mode==3)text(out,x,y+7,value,0,x+width);
|
||||
else {
|
||||
int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
|
||||
sprite_text(out,x+width/2-length/2,y+7,value,exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
sprite_text(out,x+width/2-length/2,y+7,value,mode);
|
||||
}
|
||||
}
|
||||
std::vector<std::pair<int,int>> LineupScreen::rows() const {
|
||||
@@ -237,8 +237,8 @@ Image LineupScreen::render() const {
|
||||
number((p.statistics ? p.statistics->goals : le16(Bytes(p.board.begin(),p.board.end()),0x4a)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+number((p.statistics ? p.statistics->assists : le16(Bytes(p.board.begin(),p.board.end()),0x4c)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField),0x6c);
|
||||
}
|
||||
}
|
||||
button(out,1,215,texts_[(::bmh::layout::Lineup_Render_TextPointer-::bmh::layout::TextPointerTable)/4+(state_.view==LineupView::data_a?1:0)]);
|
||||
button(out,58,215,texts_[(::bmh::layout::Lineup_Render_TextPointer2-::bmh::layout::TextPointerTable)/4]);
|
||||
button(out,1,215,texts_[(::bmh::layout::Lineup_Render_TextPointer-::bmh::layout::TextPointerTable)/4+(state_.view==LineupView::data_a?1:0)],pressed_button_==0);
|
||||
button(out,58,215,texts_[(::bmh::layout::Lineup_Render_TextPointer2-::bmh::layout::TextPointerTable)/4],pressed_button_==1);
|
||||
return out;
|
||||
}
|
||||
LineupRequest LineupScreen::request(LineupRequestKind kind,int first,int second) {
|
||||
@@ -252,7 +252,14 @@ LineupRequest LineupScreen::initialize() {
|
||||
if(pending_||close_||state_.entry_prepared)return {};
|
||||
return request(LineupRequestKind::prepare_lineup);
|
||||
}
|
||||
// Mouse DOWN on a bottom button (Daten A/B, Spielfeld): drawn pressed until the release.
|
||||
bool LineupScreen::press(int x,int y) {
|
||||
int id=-1;
|
||||
if(!pending_&&!close_&&y>=215&&y<=224){if(x>=1&&x<=56)id=0;else if(x>=58&&x<=113)id=1;}
|
||||
const bool changed=id!=pressed_button_;pressed_button_=id;return changed;
|
||||
}
|
||||
LineupRequest LineupScreen::click(int x,int y,bool right) {
|
||||
pressed_button_=-1; // the release ends the pressed look
|
||||
if(pending_||close_)return {};
|
||||
if(right){if(selected_)selected_.reset();else close_=true;return {};}
|
||||
if(y>=215&&y<=224){
|
||||
|
||||
+4
-1
@@ -64,6 +64,8 @@ public:
|
||||
LineupRequest initialize();
|
||||
Image render() const;
|
||||
LineupRequest click(int x, int y, bool right = false);
|
||||
// Mouse DOWN on a bottom button: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
bool move(int x, int y); // local original name-column hover
|
||||
LineupRequest key(std::string_view key);
|
||||
bool close_requested() const { return close_; }
|
||||
@@ -88,7 +90,8 @@ private:
|
||||
std::vector<std::pair<int,int>> rows() const; // (squad row, baseline)
|
||||
void text(Image&, int x, int baseline, std::string_view, uint8_t color, int right = -1) const;
|
||||
void sprite_text(Image&, int x, int baseline, std::string_view, int font = 5) const;
|
||||
void button(Image&, int x, int y, std::string_view value) const;
|
||||
void button(Image&, int x, int y, std::string_view value, bool pressed = false) const;
|
||||
int pressed_button_ = -1; // bottom button held down by the mouse
|
||||
LineupRequest request(LineupRequestKind, int first = -1, int second = -1);
|
||||
};
|
||||
|
||||
|
||||
+22
-32
@@ -5,6 +5,8 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "formats/league_visibility.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -131,7 +133,9 @@ ManagerScreen::ManagerScreen(const std::filesystem::path& data, int slot, const
|
||||
if (id < 0 || id >= int(db_.club_names.size()) || !unique.insert(id).second)
|
||||
throw FormatError("manager selection: club order must contain unique valid master IDs");
|
||||
choice_.slot = slot; choice_.roster_revision = context_.revision;
|
||||
choice_.name = texts_[(::bmh::layout::Career_NewCareerMarketsAndMoods_ExecutableField - ::bmh::layout::TextPointerTable) / 4 + slot];
|
||||
// The default name of a new manager: OpenBMH (the original text blocks offer "Nobody" for every slot). The player can still
|
||||
// type another name; the name editor of the original keeps working on this string.
|
||||
choice_.name = "OpenBMH";
|
||||
while (club_locked(master_id(choice_.selection_club))) ++choice_.selection_club;
|
||||
choice_.master_club = master_id(choice_.selection_club);
|
||||
while (portrait_locked(choice_.portrait)) ++choice_.portrait;
|
||||
@@ -199,7 +203,19 @@ bool ManagerScreen::move(int x, int y) {
|
||||
if (next == hover_) return false;
|
||||
hover_ = next; return true;
|
||||
}
|
||||
// Mouse DOWN on JA or NEIN of the confirmation: the button is drawn pressed until the release.
|
||||
bool ManagerScreen::press(int x, int y) {
|
||||
int id = -1;
|
||||
if (view_ == ManagerView::confirmation && y >= 166 && y <= 176) {
|
||||
if (x >= 62 && x <= 137) id = 0;
|
||||
else if (x >= 175 && x <= 250) id = 1;
|
||||
}
|
||||
const bool changed = id != pressed_button_;
|
||||
pressed_button_ = id;
|
||||
return changed;
|
||||
}
|
||||
bool ManagerScreen::click(int x, int y, bool right) {
|
||||
pressed_button_ = -1; // the release ends the pressed look
|
||||
if (x < 0 || x >= 320 || y < 0 || y >= 240 || view_ == ManagerView::accepted || view_ == ManagerView::name_edit) return false;
|
||||
if (view_ == ManagerView::confirmation) {
|
||||
if (y >= 166 && y <= 176) {
|
||||
@@ -292,21 +308,7 @@ void ManagerScreen::small_text(Image& out, int x, int baseline, std::string_view
|
||||
out.at(x + xx, baseline - 5 + y) = exe_.u8(::bmh::layout::Advertising_Text_RuntimeField + gradient * 6 + y);
|
||||
}
|
||||
void ManagerScreen::frame(Image& out, int x, int y, int w, int h, bool shadow) const {
|
||||
if (shadow) {
|
||||
rect(out, x + 2, y + h, w, 2, 0x40);
|
||||
rect(out, x + w, y + 2, 2, h, 0x40);
|
||||
}
|
||||
pattern(out, x + 4, y + 4, w - 7, h - 7);
|
||||
copy(out, widgets_, 0, 0, x, y, 4, 4); copy(out, widgets_, 4, 0, x + w - 4, y, 4, 4);
|
||||
copy(out, widgets_, 0, 4, x, y + h - 4, 4, 4); copy(out, widgets_, 4, 4, x + w - 4, y + h - 4, 4, 4);
|
||||
for (int k = 4; k < w - 4; k += 74) {
|
||||
int n = std::min(74, w - 4 - k);
|
||||
copy(out, widgets_, 0, 104, x + k, y, n, 4); copy(out, widgets_, 0, 108, x + k, y + h - 4, n, 4);
|
||||
}
|
||||
for (int k = 4; k < h - 4; k += 96) {
|
||||
int n = std::min(96, h - 4 - k);
|
||||
copy(out, widgets_, 0, 8, x, y + k, 4, n); copy(out, widgets_, 4, 8, x + w - 4, y + k, 4, n);
|
||||
}
|
||||
draw_dialog_frame(out, widgets_, exe_, x, y, w, h, shadow); // dialog_frame.hpp
|
||||
}
|
||||
int ManagerScreen::sprite_text_width(std::string_view value) const {
|
||||
int width = 0;
|
||||
@@ -327,20 +329,8 @@ void ManagerScreen::sprite_text(Image& out, int x, int y, std::string_view value
|
||||
}
|
||||
}
|
||||
void ManagerScreen::button(Image& out, int x, int y, int w, std::string_view label, bool selected) const {
|
||||
if (selected) {
|
||||
const auto c = out.at(x, y + 10);
|
||||
rect(out, x, y, w + 1, 2, c); rect(out, x, y, 2, 11, c); x += 2; y += 2;
|
||||
} else {
|
||||
rect(out, x + 2, y + 10, w, 2, 0x40); rect(out, x + w, y + 2, 2, 10, 0x40);
|
||||
}
|
||||
int sy = selected ? 44 : 74;
|
||||
copy(out, widgets_, 24, sy, x, y, 31, 10);
|
||||
int k = 31;
|
||||
for (; w - k > 20;) {
|
||||
int n = std::min(8, w - k - 20);
|
||||
copy(out, widgets_, 24, sy + 10, x + k, y, n, 10); k += n;
|
||||
}
|
||||
copy(out, widgets_, 45 - (w - k), sy + 20, x + k, y, w - k, 10);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, w, selected);
|
||||
x += shift; y += shift;
|
||||
int font = exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected));
|
||||
sprite_text(out, x + w / 2 - sprite_text_width(label) / 2, y + 7, label, font);
|
||||
}
|
||||
@@ -397,8 +387,8 @@ Image ManagerScreen::render() const {
|
||||
small_text(out, 73 + 170 / 2 - small_.text_width(prompt) / 2, 140, prompt);
|
||||
// The original shows JA pushed in for a moment after it is clicked.
|
||||
button(out, 62, 166, 75, texts_[(::bmh::layout::GameEnd_Copy_TextPointer - ::bmh::layout::TextPointerTable) / 4],
|
||||
view_ == ManagerView::accepted);
|
||||
button(out, 175, 166, 75, texts_[(::bmh::layout::GameEnd_Copy_TextPointer2 - ::bmh::layout::TextPointerTable) / 4], false);
|
||||
view_ == ManagerView::accepted || pressed_button_ == 0);
|
||||
button(out, 175, 166, 75, texts_[(::bmh::layout::GameEnd_Copy_TextPointer2 - ::bmh::layout::TextPointerTable) / 4], pressed_button_ == 1);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
ManagerView view() const { return view_; }
|
||||
std::string screen_name() const;
|
||||
bool click(int x, int y, bool right = false);
|
||||
// Mouse DOWN on JA/NEIN of the confirmation: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
bool move(int x, int y);
|
||||
bool text(std::string_view utf8);
|
||||
bool key(std::string_view name);
|
||||
@@ -85,6 +87,7 @@ private:
|
||||
std::vector<ManagerChoice> confirmed_;
|
||||
SelectionContext context_;
|
||||
ManagerView view_ = ManagerView::selection;
|
||||
int pressed_button_ = -1; // JA (0) or NEIN (1) held down by the mouse
|
||||
std::filesystem::path data_;
|
||||
LeImage exe_;
|
||||
Database db_;
|
||||
|
||||
@@ -49,7 +49,16 @@ int main(int argc, char** argv) {
|
||||
s.click(5, 225, true); check(!s.click(20, 20), "confirmation requires a button");
|
||||
s.click(210, 169, true);
|
||||
check(s.choice() == chosen && s.view() == ManagerView::selection, "No preserves choices with either mouse button");
|
||||
s.click(5, 225, true); s.click(90, 169);
|
||||
s.click(5, 225, true);
|
||||
{ // JA and NEIN look pressed while the mouse button is held, normal again after the release
|
||||
const auto raised = s.render();
|
||||
check(!s.press(10, 10), "no pressed look outside the buttons");
|
||||
check(s.press(210, 169) && s.render().pixels != raised.pixels, "NEIN shows the pressed look");
|
||||
check(s.press(90, 169) && s.render().pixels != raised.pixels, "JA shows the pressed look");
|
||||
s.click(10, 10);
|
||||
check(s.render().pixels == raised.pixels, "the release ends the pressed look");
|
||||
}
|
||||
s.click(90, 169);
|
||||
check(s.view() == ManagerView::accepted && !s.click(90, 169), "accepted choice cannot repeat");
|
||||
|
||||
ManagerChoice first{0, "ONE", 0, 0, 1, 0};
|
||||
|
||||
+3
-19
@@ -4,6 +4,7 @@
|
||||
// only requested through pending() and takes effect when the session returns a new state.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/other_games.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
@@ -192,25 +193,8 @@ void OtherGamesScreen::draw_button(Image& out, int x, int y, int width,
|
||||
const bool down = pressed || selected;
|
||||
// FormatError3 shifts both a selected competition and a held button by (+2,+2).
|
||||
// Keep this Original inset; selection is not an unshifted alternate skin.
|
||||
const int dx = x + (down ? 2 : 0), dy = y + (down ? 2 : 0);
|
||||
if (down) {
|
||||
const uint8_t background = out.at(x, y + 10);
|
||||
fill(out, x, y, width + 1, 2, background);
|
||||
fill(out, x, y, 2, 11, background);
|
||||
} else {
|
||||
fill(out, x + 2, y + 10, width, 2, 0x40);
|
||||
fill(out, x + width, y + 2, 2, 10, 0x40);
|
||||
}
|
||||
const int sy = down ? 44 : 74;
|
||||
copy(out, widgets_, 24, sy, dx, dy, 31, 10, 0xc0);
|
||||
int used = 31;
|
||||
while (width - used > 20) {
|
||||
const int count = std::min(8, width - used - 20);
|
||||
copy(out, widgets_, 24, sy + 10, dx + used, dy, count, 10, 0xc0);
|
||||
used += count;
|
||||
}
|
||||
const int tail = width - used;
|
||||
copy(out, widgets_, 45 - tail, sy + 20, dx + used, dy, tail, 10, 0xc0);
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, down, 0xc0);
|
||||
const int dx = x + shift, dy = y + shift;
|
||||
const auto label = original_to_utf8(std::string(raw_label));
|
||||
sprite_.draw(out, dx + width / 2 - sprite_.text_width(label) / 2, dy + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + (down ? 1u : 0u)));
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
// never recomputed here.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/outgoing_transfer.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
@@ -394,9 +396,7 @@ void OutgoingTransferScreen::draw_editor_fields(Image& out) const {
|
||||
void OutgoingTransferScreen::draw_calculator(Image& out) const {
|
||||
constexpr int x0 = kCalculatorX, y0 = kCalculatorY;
|
||||
if (!calculator_open_ || !active_profile_.supported) return;
|
||||
copy_region(out, calculator_art_, 0, 0, x0, y0, 113, 136);
|
||||
fill_rect(out, x0 + 113, y0 + 2, 2, 136, 0x40);
|
||||
fill_rect(out, x0 + 2, y0 + 136, 113, 2, 0x40);
|
||||
draw_calculator_panel(out, calculator_art_, x0, y0); // calculator_widgets.hpp
|
||||
std::string title;
|
||||
if (active_profile_.source_text_address)
|
||||
title = std::string(text_at(texts_, active_profile_.source_text_address));
|
||||
@@ -426,8 +426,8 @@ void OutgoingTransferScreen::draw_calculator(Image& out) const {
|
||||
for (int i = 0; i < 15; ++i) {
|
||||
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
|
||||
const int y = y0 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
|
||||
copy_region(out, calculator_art_, 0, 136, x, y, 15, 14);
|
||||
draw_body(x + 5, y + 9, keys.substr(size_t(i), 1), 0x62, false);
|
||||
const int p = draw_calculator_key(out, calculator_art_, x, y, pressed_key_ == i);
|
||||
draw_body(x + 5 + p, y + 9 + p, keys.substr(size_t(i), 1), 0x62, false);
|
||||
}
|
||||
for (size_t i = 0; i < active_profile_.presets.size(); ++i) {
|
||||
if (!active_profile_.presets[i]) continue;
|
||||
@@ -448,28 +448,17 @@ void OutgoingTransferScreen::draw_footer(Image& out) const {
|
||||
// OpenTransferEditor registers four FormatError3 controls from a216c/a216e/a2170.
|
||||
// The address stride in OutgoingTransfer_DrawFooter_TextPointer is exactly one TEXTD pointer (four bytes):
|
||||
// IDs 230..233 are Team-Info, Spieler-Info, Angebot and Abbruch.
|
||||
constexpr int drawn_height = 10; // FormatError3 raises requested h=9 for width>31.
|
||||
for (size_t i = 0; i < kFooterButtonX.size(); ++i) {
|
||||
const int x = kFooterButtonX[i];
|
||||
// FormatError3 first calls ColorBottomRightBevel for the raised control's shadow.
|
||||
fill_rect(out, x + 2, kFooterButtonY + drawn_height, kFooterButtonWidth, 2, 0x40);
|
||||
fill_rect(out, x + kFooterButtonWidth, kFooterButtonY + 2, 2, drawn_height, 0x40);
|
||||
// FormatError3's standard KB0 frame; its requested nine-pixel height
|
||||
// is raised to ten for widths over 31, then the sprite is tiled.
|
||||
copy_region(out, button_art_, 24, 74, x, kFooterButtonY, 31, drawn_height);
|
||||
int used = 31;
|
||||
while (kFooterButtonWidth - used > 20) {
|
||||
const int count = std::min(8, kFooterButtonWidth - used - 20);
|
||||
copy_region(out, button_art_, 24, 84, x + used, kFooterButtonY, count, drawn_height);
|
||||
used += count;
|
||||
}
|
||||
const int remaining = kFooterButtonWidth - used;
|
||||
copy_region(out, button_art_, 45 - remaining, 94, x + used, kFooterButtonY,
|
||||
remaining, drawn_height);
|
||||
// FormatError3: shadow, KB0 frame (height raised to ten for widths over 31) and tiled middle; a button held
|
||||
// down by the mouse is drawn in the pressed look (button_frame.hpp).
|
||||
const bool down = pressed_button_ == int(i);
|
||||
const int shift = draw_wide_button_frame(out, button_art_, x, kFooterButtonY, kFooterButtonWidth, down);
|
||||
const auto label = original_to_utf8(text_at(texts_, ::bmh::layout::OutgoingTransfer_DrawFooter_TextPointer + uint32_t(i) * 4));
|
||||
const int text_width = sprite_font_.text_width(label);
|
||||
sprite_font_.draw(out, x + kFooterButtonWidth / 2 - text_width / 2,
|
||||
kFooterButtonY + 7, label, exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
sprite_font_.draw(out, x + shift + kFooterButtonWidth / 2 - text_width / 2,
|
||||
kFooterButtonY + shift + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(down)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,7 +481,28 @@ OutgoingTransferRequest OutgoingTransferScreen::process_timer_expired() {
|
||||
// presets edit the value and right click cancels it; otherwise right click cancels the screen, footer buttons send
|
||||
// team info, player info, submit (only when editable) or cancel; clicks on the fee, salary or (mode 3) contract/bonus
|
||||
// areas open the calculator. Opening the calculator is local state and sends no request.
|
||||
// Mouse DOWN on a footer button: it is drawn pressed until the release. Returns true when the picture changed.
|
||||
bool OutgoingTransferScreen::press(int x, int y) {
|
||||
int id = -1;
|
||||
if (!closed_ && !pending_ && !calculator_open_)
|
||||
for (size_t i = 0; i < kFooterButtonX.size(); ++i)
|
||||
if (x >= kFooterButtonX[i] && x <= kFooterButtonX[i] + kFooterButtonWidth && y >= kFooterButtonY &&
|
||||
y <= kFooterButtonY + kFooterButtonHeight) id = int(i);
|
||||
// a key of the open calculator
|
||||
int key = -1;
|
||||
if (!closed_ && !pending_ && calculator_open_ && active_profile_.supported)
|
||||
for (int i = 0; i < 15; ++i)
|
||||
if (calculator_key_hit(x, y, kCalculatorX + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
|
||||
kCalculatorY + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
|
||||
const bool changed = id != pressed_button_ || key != pressed_key_;
|
||||
pressed_button_ = id;
|
||||
pressed_key_ = key;
|
||||
return changed;
|
||||
}
|
||||
|
||||
OutgoingTransferRequest OutgoingTransferScreen::click(int x, int y, bool right, bool double_click) {
|
||||
pressed_button_ = -1; // the release ends the pressed look
|
||||
pressed_key_ = -1;
|
||||
if (closed_ || pending_) return {};
|
||||
if (double_click && !right && !calculator_open_ && y > 0x12 && y < 0x21) {
|
||||
state_.quote_loan = !state_.quote_loan;
|
||||
|
||||
@@ -97,6 +97,8 @@ public:
|
||||
OutgoingTransferEditorState state);
|
||||
Image render() const;
|
||||
OutgoingTransferRequest click(int x, int y, bool right = false, bool double_click = false);
|
||||
// Mouse DOWN: the footer button under the pointer is drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
// Source event8 returns calculator cancellation before closing its editor.
|
||||
OutgoingTransferRequest process_timer_expired();
|
||||
OutgoingTransferRequest key(std::string_view key);
|
||||
@@ -125,6 +127,8 @@ private:
|
||||
std::string numeric_text_, feedback_;
|
||||
bool calculator_open_ = false;
|
||||
bool closed_ = false;
|
||||
int pressed_button_ = -1; // footer button held down by the mouse
|
||||
int pressed_key_ = -1; // calculator key held down by the mouse
|
||||
std::optional<OutgoingTransferRequest> pending_;
|
||||
|
||||
OutgoingTransferIdentity identity() const;
|
||||
|
||||
@@ -182,6 +182,9 @@ TaxDialogProjection pending_offer_notice_dialog(const GameState& game,
|
||||
case ::bmh::layout::PendingOffer_FormatError_ExecutableField2: // SystemIdentity(manager|0x80): interactive ACK after normal settlement.
|
||||
case ::bmh::layout::PendingOffer_ConstructionNoticeDialog_TextPointer: // SettleHumanBuyerSale -> SystemIdentity: buyer subsidy, composed amounts.
|
||||
case ::bmh::layout::PendingOffer_FormatError_ExecutableField3: // SettleHumanBuyerSale -> SystemIdentity: buyer subsidy threshold exceeded.
|
||||
case ::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_ExecutableField: // poached player agrees: "Ihr erstes Angebot wird angenommen!" (without it the Angebot button of the Abwerben dialog failed).
|
||||
case ::bmh::layout::Month_SearchProfileNews_TextPointer3: // search dialog -> sub_57ECA: a listed player fits the profile.
|
||||
case ::bmh::layout::Month_SearchProfileNews_TextPointer4: // search dialog -> sub_57ECA: "your scouting department ..." after Suchen.
|
||||
out.source_manager_flags = uint8_t(notice.manager) | 0x80;
|
||||
break;
|
||||
case ::bmh::layout::PendingOffer_PendingOfferNoticeDialog_ExecutableField2: // SDLFlushEvents3(manager|0x40): timed warning.
|
||||
|
||||
+21
-14
@@ -4,6 +4,7 @@
|
||||
// authoritative positions; changes only appear after the session acknowledges a new lineup and extras.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/pitch.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
@@ -243,11 +244,11 @@ void PitchScreen::text(Image& out,int x,int baseline,std::string_view value,uint
|
||||
}
|
||||
void PitchScreen::button(Image& out,int x,int y,std::string_view value,bool selected)const{
|
||||
constexpr int width=43,height=10;
|
||||
if(selected){ // FormatError3 erases the upper/left frame, then offsets its pressed atlas by two pixels.
|
||||
rect(out,x,y,width+1,2,0x42);rect(out,x,y,2,height+1,0x42);x+=2;y+=2;
|
||||
}else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
const int sy=selected?44:74,font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected));
|
||||
copy(out,widgets_,24,sy,x,y,31,10);copy(out,widgets_,33,sy+20,x+31,y,12,10);
|
||||
// FormatError3 erases the upper/left frame (colour 0x42 here), then offsets its pressed atlas by two pixels
|
||||
// (button_frame.hpp).
|
||||
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,selected,-1,0x42);x+=shift;y+=shift;
|
||||
(void)height;
|
||||
const int font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected));
|
||||
if(font==3)text(out,x+width/2-font_.text_width(value)/2,y+7,value,0);
|
||||
else {int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
|
||||
int xx=x+width/2-length/2;for(unsigned char c:value){if(c<=31||c>=128)continue;const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);
|
||||
@@ -258,13 +259,10 @@ void PitchScreen::diamond_button(Image& out,int x,int y,std::string_view value,b
|
||||
// FormatError3: width60, height9 normalized to 10, with pressed frame and
|
||||
// runtime font byte Advertising_Button_RuntimeField+selected. Match the original +2 pressed offset.
|
||||
constexpr int width=60,height=10;
|
||||
int dx=x,dy=y;const int mode=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + unsigned(selected));
|
||||
if(selected){const uint8_t bg=out.at(x,y+height);rect(out,x,y,width+1,2,bg);rect(out,x,y,2,height+1,bg);dx+=2;dy+=2;}
|
||||
else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
const int row=selected?44:74;copy(out,widgets_,24,row,dx,dy,31,10,0xc0);
|
||||
int used=31;while(width-used>20){const int amount=std::min(8,width-used-20);
|
||||
copy(out,widgets_,24,row+10,dx+used,dy,amount,10,0xc0);used+=amount;}
|
||||
const int tail=width-used;copy(out,widgets_,45-tail,row+20,dx+used,dy,tail,10,0xc0);
|
||||
const int mode=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + unsigned(selected));
|
||||
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,selected,0xc0); // button_frame.hpp
|
||||
const int dx=x+shift,dy=y+shift;
|
||||
(void)height;
|
||||
if(mode==3){const auto native_value=utf8_to_original(value);
|
||||
text(out,dx+width/2-font_.text_width(native_value)/2,dy+7,native_value,0);}
|
||||
else sprite_.draw(out,dx+width/2-sprite_.text_width(value)/2,dy+7,value,mode);
|
||||
@@ -422,8 +420,8 @@ Image PitchScreen::render()const{
|
||||
if(automatic_page()&&extras_.mode!=1)for(int f=0;f<3;++f){
|
||||
const int x=241+f*27;copy(out,atlas_,196+f*24,38,x,205,24,18);
|
||||
copy(out,atlas_,256+((extras_.automatic_weights>>(2*f))&3)*16,32,x+19,211,4,5);}
|
||||
button(out,196,110,texts_[(::bmh::layout::Lineup_Render_TextPointer-::bmh::layout::TextPointerTable)/4+(state_.view==LineupView::data_a?1:0)]);
|
||||
button(out,196,123,texts_[(::bmh::layout::Pitch_Render_TextPointer-::bmh::layout::TextPointerTable)/4]);
|
||||
button(out,196,110,texts_[(::bmh::layout::Lineup_Render_TextPointer-::bmh::layout::TextPointerTable)/4+(state_.view==LineupView::data_a?1:0)],pressed_lower_button_==0);
|
||||
button(out,196,123,texts_[(::bmh::layout::Pitch_Render_TextPointer-::bmh::layout::TextPointerTable)/4],pressed_lower_button_==1);
|
||||
button(out,196,136,texts_[(::bmh::layout::Pitch_Render_TextPointer2-::bmh::layout::TextPointerTable)/4],(extras_.native_display_word&0x0010)!=0);
|
||||
if(extras_.mode!=1)button(out,196,149,texts_[(::bmh::layout::Pitch_Render_TextPointer3-::bmh::layout::TextPointerTable)/4],order_panel_open_);
|
||||
if(extras_.opponent_team>=0&&!extras_.indoor.value_or(false))
|
||||
@@ -757,7 +755,16 @@ PitchRequest PitchScreen::click(int x,int y,bool right){
|
||||
selected_=row;hovered_=row;ghost_.reset();return {};}
|
||||
return {};
|
||||
}
|
||||
// Mouse DOWN on one of the two momentary buttons of the desktop page (Daten A/B at y=110, Spielfeld/Kurz at y=123): drawn
|
||||
// pressed; pointer_down() runs the action and ends the pressed look. The toggles below them keep their lasting state.
|
||||
bool PitchScreen::press(int x,int y){
|
||||
int id=-1;
|
||||
if(!pending_&&!close_&&(extras_.native_display_word&0x08)!=0&&x>=196&&x<=239){
|
||||
if(y>=110&&y<=120)id=0;else if(y>=123&&y<=133)id=1;}
|
||||
const bool changed=id!=pressed_lower_button_;pressed_lower_button_=id;return changed;
|
||||
}
|
||||
PitchRequest PitchScreen::pointer_down(int x,int y,bool right){
|
||||
pressed_lower_button_=-1;
|
||||
source_down_release_barrier_=false;
|
||||
const uint16_t display_word=shooter_editor_open_
|
||||
? uint16_t(extras_.native_display_word&0xff0f)
|
||||
|
||||
@@ -98,6 +98,8 @@ public:
|
||||
// dispatches and acknowledges the returned native page-word request.
|
||||
PitchRequest request_page_control(int control);
|
||||
PitchRequest pointer_down(int x,int y,bool right=false);
|
||||
// Mouse DOWN on a momentary button: drawn pressed; pointer_down() then runs its action and ends the look.
|
||||
bool press(int x,int y);
|
||||
bool take_source_down_release_barrier(){const bool value=source_down_release_barrier_;source_down_release_barrier_=false;return value;}
|
||||
PitchRequest save_formation(int x, int y); // completed long press, own slots 4..7
|
||||
bool move(int x, int y);
|
||||
@@ -146,6 +148,7 @@ private:
|
||||
std::vector<std::pair<int,int>> rows() const;
|
||||
void text(Image&, int x, int baseline, std::string_view, uint8_t color) const;
|
||||
void button(Image&, int x, int y, std::string_view, bool selected = false) const;
|
||||
int pressed_lower_button_ = -1; // momentary button held down by the mouse (0 Daten, 1 Spielfeld/Kurz)
|
||||
void jersey(Image&, const LineupPlayer&, int depth, int lane, int color, bool number = true) const;
|
||||
PitchRequest request(PitchRequestKind, int row, int second = -1, int depth = -1, int lane = -1);
|
||||
PitchRequest automatic_request(PitchRequestKind, int index);
|
||||
|
||||
+22
-15
@@ -5,6 +5,8 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/player_card.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -217,22 +219,16 @@ void PlayerCardScreen::text(Image& out,int x,int baseline,std::string_view value
|
||||
out.at(x+xx,baseline-font.baseline+yy)=state_.lineup.gradient_text?exe_.u8(::bmh::layout::Advertising_Text_RuntimeField+gradient*6+yy):color;
|
||||
}
|
||||
void PlayerCardScreen::frame(Image& out,int x,int y,int w,int h) const {
|
||||
for(int yy=4;yy<h-3;++yy)for(int xx=4;xx<w-3;++xx)out.at(x+xx,y+yy)=exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField+((yy-4)%16)*16+(xx-4)%16);
|
||||
copy(out,widgets_,0,0,x,y,4,4);copy(out,widgets_,4,0,x+w-4,y,4,4);
|
||||
copy(out,widgets_,0,4,x,y+h-4,4,4);copy(out,widgets_,4,4,x+w-4,y+h-4,4,4);
|
||||
for(int at=4;at<w-4;at+=74){const int n=std::min(74,w-4-at);copy(out,widgets_,0,104,x+at,y,n,4);copy(out,widgets_,0,108,x+at,y+h-4,n,4);}
|
||||
for(int at=4;at<h-4;at+=96){const int n=std::min(96,h-4-at);copy(out,widgets_,0,8,x,y+at,4,n);copy(out,widgets_,4,8,x+w-4,y+at,4,n);}
|
||||
draw_dialog_frame(out,widgets_,exe_,x,y,w,h,false); // dialog_frame.hpp
|
||||
}
|
||||
void PlayerCardScreen::button(Image& out,int x,int y,int width,std::string_view value,bool active) const {
|
||||
const int height=width>31?10:9;
|
||||
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
|
||||
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
if(width>31){
|
||||
const int sy=active?44:74;
|
||||
copy(out,widgets_,24,sy,x,y,31,10);int at=31,remaining=width-31;
|
||||
while(remaining>20){const int n=std::min(8,remaining-20);copy(out,widgets_,24,sy+10,x+at,y,n,10);at+=n;remaining-=n;}
|
||||
copy(out,widgets_,45-remaining,sy+20,x+at,y,remaining,10);
|
||||
}else frame(out,x,y,width,height);
|
||||
if(width>31){const int shift=draw_wide_button_frame(out,widgets_,x,y,width,active);x+=shift;y+=shift;} // button_frame.hpp
|
||||
else{
|
||||
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
|
||||
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
frame(out,x,y,width,height);
|
||||
}
|
||||
const int font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(active));
|
||||
if(font==3){text(out,x,y+height/2+2,value,0,x+width);return;}
|
||||
int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
|
||||
@@ -326,7 +322,7 @@ Image PlayerCardScreen::render_card() const {
|
||||
if(i==5){const auto market=player_card_market_value(a,exe_);value=market?cash(*market,1)+exe_.cstring(::bmh::layout::ClubPlayerDetail_Copy_ExecutableField):"?";}
|
||||
text(out,x,base+11,value,0x6a);
|
||||
}
|
||||
button(out,8,211,60,label(::bmh::layout::ClubPlayerDetail_Copy_TextPointer7));button(out,80,211,96,label(::bmh::layout::ClubPlayerDetail_Copy_ExecutableField5),statistics_open_);
|
||||
button(out,8,211,60,label(::bmh::layout::ClubPlayerDetail_Copy_TextPointer7),pressed_button_==0);button(out,80,211,96,label(::bmh::layout::ClubPlayerDetail_Copy_ExecutableField5),statistics_open_||pressed_button_==1);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -365,11 +361,22 @@ Image PlayerCardScreen::render_statistics() const {
|
||||
}
|
||||
button(out,265,142,30,label(::bmh::layout::ClubPlayerDetail_RenderStatistics_ExecutableField),(statistics_flags_&0x40)!=0);
|
||||
button(out,265,153,30,label(::bmh::layout::ClubPlayerDetail_RenderStatistics_ExecutableField2),(statistics_flags_&0x80)!=0);
|
||||
button(out,8,185,140,label(::bmh::layout::ClubPlayerDetail_RenderStatistics_ExecutableField3));
|
||||
button(out,8,185,140,label(::bmh::layout::ClubPlayerDetail_RenderStatistics_ExecutableField3),pressed_button_==2);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Mouse DOWN on a button of the card (Schließen, Statistik, and Zurück of the statistics page): drawn pressed until
|
||||
// the release. Returns true when the picture changed.
|
||||
bool PlayerCardScreen::press(int x,int y) {
|
||||
int id=-1;
|
||||
if(!close_){
|
||||
if(statistics_open_){if(x>=8&&x<=148&&y>=185&&y<=195)id=2;}
|
||||
else if(y>=211&&y<=220){if(x>=8&&x<=68)id=0;else if(x>=80&&x<=176)id=1;}
|
||||
}
|
||||
const bool changed=id!=pressed_button_;pressed_button_=id;return changed;
|
||||
}
|
||||
bool PlayerCardScreen::click(int x,int y,bool right) {
|
||||
pressed_button_=-1; // the release ends the pressed look
|
||||
if(close_)return false;
|
||||
if(statistics_open_){
|
||||
if(right||(x>=8&&x<=148&&y>=185&&y<=195)){
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
PlayerCardScreen(const std::filesystem::path& data, PlayerCardState state, std::optional<Image> parent_frame = std::nullopt);
|
||||
Image render() const;
|
||||
bool click(int x, int y, bool right = false);
|
||||
// Mouse DOWN on a card button: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
bool key(std::string_view key);
|
||||
bool close_requested() const { return close_; }
|
||||
bool in_statistics() const { return statistics_open_; }
|
||||
@@ -61,6 +63,7 @@ private:
|
||||
std::array<Image, 2> loan_badges_;
|
||||
bool close_ = false;
|
||||
bool statistics_open_ = false;
|
||||
int pressed_button_ = -1; // 0 Schließen, 1 Statistik, 2 Zurück (statistics page) while the mouse button is held
|
||||
std::optional<Image> statistics_frame_; // previous UI frame for original button redraw edges
|
||||
std::optional<Image> restored_card_frame_; // card loop does not reconstruct its outer frame
|
||||
uint8_t statistics_flags_ = 0;
|
||||
|
||||
@@ -1086,6 +1086,22 @@ FlowResult StartupFlow::process_timer_expired(int pointer_x, int pointer_y) {
|
||||
return {}; // other modal callers retain their own input owner
|
||||
}
|
||||
|
||||
bool StartupFlow::press_hold(int x,int y) {
|
||||
if (advertising_) return advertising_->press(x, y);
|
||||
if (save_load_) return save_load_->press(x, y);
|
||||
if (player_card_) return player_card_->press(x, y); // the card covers its parent
|
||||
if (pitch_) return pitch_->press(x, y);
|
||||
if (lineup_) return lineup_->press(x, y);
|
||||
if (training_camp_) return training_camp_->press(x, y);
|
||||
if (bank_) return bank_->press(x, y);
|
||||
if (outgoing_transfer_) return outgoing_transfer_->press(x, y);
|
||||
if (manager_ && !desktop_) return manager_->press(x, y);
|
||||
// the setup screen at the start of a game, and its joining variant
|
||||
if (joining_) return !manager_ && !join_options_pending_ && !join_choice_pending_ && join_setup_ && join_setup_->press(x, y);
|
||||
if (screen_name() == "setup") return setup_.press(x, y);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Routes a mouse press to the active child page (checked in a fixed order); the submenu pages then forward their pending action through finish_*_input.
|
||||
FlowResult StartupFlow::pointer_down(int x,int y,bool right) {
|
||||
if(pitch_hold_release_barrier_&&!right)return {};
|
||||
@@ -1254,6 +1270,9 @@ FlowResult StartupFlow::pointer_down(int x,int y,bool right) {
|
||||
}
|
||||
if (environment_) return {environment_->pointer_down(x,y,right)};
|
||||
if (advertising_) return {advertising_->move(x,y)};
|
||||
// The transfer market draws the held button pressed (Suchen, Vorschlag, Abwerben, Data ...); the action follows on the release.
|
||||
if (transfer_market_ && !player_card_ && !outgoing_transfer_ && !toto_ && !pitch_ && !lineup_)
|
||||
return {transfer_market_->press(x,y,right)};
|
||||
if(pitch_){
|
||||
const std::string before=pitch_->state_json();
|
||||
const auto request=pitch_->pointer_down(x,y,right);
|
||||
|
||||
+29
-30
@@ -5,6 +5,8 @@
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/save_load.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -141,7 +143,7 @@ Image SaveLoadScreen::render() const {
|
||||
text(out, 106, 216, displayed_filename, filename_selected_ ? 0x27 : 0x6c, 140, footer_font_, true);
|
||||
|
||||
if (entries_.size() > 15) {
|
||||
button(out, 206, 183, 56, original_to_utf8(exe_.cstring(::bmh::layout::SaveLoad_Render_ExecutableField)));
|
||||
button(out, 206, 183, 56, original_to_utf8(exe_.cstring(::bmh::layout::SaveLoad_Render_ExecutableField)), pressed_more_ != 0);
|
||||
}
|
||||
|
||||
for (int row = 0; row < 15; ++row) {
|
||||
@@ -192,7 +194,9 @@ Image SaveLoadScreen::render() const {
|
||||
// OpenBMH deviates from the original: the host file picker uses the
|
||||
// shared dialog's system identity without a live manager portrait projection.
|
||||
draw_source_dialog(out, {widgets_, widgets_, nullptr, footer_font_, font_, exe_, sprite_font_, texts_},
|
||||
question, gradient_text_);
|
||||
question, gradient_text_,
|
||||
pressed_question_ == 0 ? std::nullopt : std::optional<GameEndTaxDialog::Button>(
|
||||
static_cast<GameEndTaxDialog::Button>(pressed_question_)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -244,37 +248,15 @@ bool SaveLoadScreen::info_press(int x, int y) {
|
||||
}
|
||||
|
||||
void SaveLoadScreen::frame(Image& out, int x, int y, int width, int height) const {
|
||||
pattern(out, exe_, x + 4, y + 4, width - 7, height - 7);
|
||||
copy(out, widgets_, 0, 0, x, y, 4, 4);
|
||||
copy(out, widgets_, 4, 0, x + width - 4, y, 4, 4);
|
||||
copy(out, widgets_, 0, 4, x, y + height - 4, 4, 4);
|
||||
copy(out, widgets_, 4, 4, x + width - 4, y + height - 4, 4, 4);
|
||||
for (int at = 4; at < width - 4; at += 74) {
|
||||
const int count = std::min(74, width - 4 - at);
|
||||
copy(out, widgets_, 0, 104, x + at, y, count, 4);
|
||||
copy(out, widgets_, 0, 108, x + at, y + height - 4, count, 4);
|
||||
}
|
||||
for (int at = 4; at < height - 4; at += 96) {
|
||||
const int count = std::min(96, height - 4 - at);
|
||||
copy(out, widgets_, 0, 8, x, y + at, 4, count);
|
||||
copy(out, widgets_, 4, 8, x + width - 4, y + at, 4, count);
|
||||
}
|
||||
draw_dialog_frame(out, widgets_, exe_, x, y, width, height, false); // dialog_frame.hpp
|
||||
}
|
||||
|
||||
void SaveLoadScreen::button(Image& out, int x, int y, int width, std::string_view label) const {
|
||||
// FormatError3 normal button bevel from KB/0.VGA, with Source horizontal tiling.
|
||||
const int sy = 74;
|
||||
copy(out, widgets_, 24, sy, x, y, 31, 10);
|
||||
int used = 31;
|
||||
while (width - used > 20) {
|
||||
const int count = std::min(8, width - used - 20);
|
||||
copy(out, widgets_, 24, sy + 10, x + used, y, count, 10);
|
||||
used += count;
|
||||
}
|
||||
copy(out, widgets_, 45 - (width - used), sy + 20, x + used, y, width - used, 10);
|
||||
void SaveLoadScreen::button(Image& out, int x, int y, int width, std::string_view label, bool pressed) const {
|
||||
// FormatError3 button bevel from KB/0.VGA with Source horizontal tiling (button_frame.hpp: raised or pressed).
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, pressed);
|
||||
if (!label.empty())
|
||||
sprite_font_.draw(out, x + width / 2 - sprite_font_.text_width(label) / 2, y + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField));
|
||||
sprite_font_.draw(out, x + shift + width / 2 - sprite_font_.text_width(label) / 2, y + shift + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(pressed)));
|
||||
}
|
||||
|
||||
void SaveLoadScreen::text(Image& out, int x, int baseline, std::string_view value,
|
||||
@@ -344,7 +326,24 @@ void SaveLoadScreen::request_action() {
|
||||
file_kind_, origin_item_id_};
|
||||
}
|
||||
|
||||
// Mouse DOWN on Ja/Nein of the overwrite question, or on the page button of a long file list: drawn pressed until
|
||||
// the release. Returns true when the picture changed.
|
||||
bool SaveLoadScreen::press(int x, int y) {
|
||||
int question = 0, more = 0;
|
||||
if (!info_ && !pending_) {
|
||||
if (overwrite_confirmation_open_)
|
||||
question = int(source_dialog_button_at(TaxDialogKind::question, false, x, y));
|
||||
else if (entries_.size() > 15 && x >= 206 && x <= 262 && y >= 183 && y <= 193) more = 1;
|
||||
}
|
||||
const bool changed = question != pressed_question_ || more != pressed_more_;
|
||||
pressed_question_ = question;
|
||||
pressed_more_ = more;
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool SaveLoadScreen::click(int x, int y, bool right, bool double_click) {
|
||||
pressed_question_ = 0; // the release ends the pressed look
|
||||
pressed_more_ = 0;
|
||||
if (info_) { info_.reset(); return true; }
|
||||
if (pending_) return false;
|
||||
if (overwrite_confirmation_open_) {
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
bool info_press(int x, int y);
|
||||
bool info_open() const { return bool(info_); }
|
||||
bool click(int x, int y, bool right = false, bool double_click = false);
|
||||
// Mouse DOWN on Ja/Nein of the overwrite question or the page button: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
bool key(std::string_view key);
|
||||
bool text(std::string_view value);
|
||||
const std::optional<SaveLoadRequest>& pending() const { return pending_; }
|
||||
@@ -85,7 +87,9 @@ private:
|
||||
void request_action();
|
||||
bool select_row(int y);
|
||||
void frame(Image&, int x, int y, int width, int height) const;
|
||||
void button(Image&, int x, int y, int width, std::string_view label = {}) const;
|
||||
void button(Image&, int x, int y, int width, std::string_view label = {}, bool pressed = false) const;
|
||||
int pressed_question_ = 0; // GameEndTaxDialog::Button (0 none) of the overwrite question held down by the mouse
|
||||
int pressed_more_ = 0; // page button of a long file list held down by the mouse
|
||||
void text(Image&, int x, int baseline, std::string_view value, uint8_t color, int max_width,
|
||||
const Font&, bool gradient = false) const;
|
||||
};
|
||||
|
||||
+40
-2
@@ -38,6 +38,9 @@ std::filesystem::path asset_path(const std::filesystem::path& directory, const s
|
||||
found = e.path();
|
||||
}
|
||||
}
|
||||
// The game runs from its asset files alone: BMH.exe may be missing, load_le() then uses the embedded numbers of the
|
||||
// Diamond executable (formats/diamond_image.hpp). The returned path simply does not exist.
|
||||
if (found.empty() && folded(name) == "bmh.exe") return directory / "BMH.exe";
|
||||
if (found.empty()) throw FormatError("missing original asset: " + (directory / name).string());
|
||||
return found;
|
||||
}
|
||||
@@ -81,7 +84,36 @@ SetupScreen::SetupScreen(const std::filesystem::path& data, SetupOptions current
|
||||
difficulty_arrows_locked_ = current.difficulty == 0;
|
||||
}
|
||||
|
||||
// The button (0..3 minus, 4..7 plus of duration, difficulty, managers, mode) under the pointer that can be used, or -1.
|
||||
int SetupScreen::button_at(int x, int y) const {
|
||||
for (int b = 0; b < 8; ++b) {
|
||||
if (joining_ && (!joining_arrow_permission_[b] ||
|
||||
(difficulty_arrows_locked_ && (b == 1 || b == 5))))
|
||||
continue;
|
||||
if (x >= button_x_[b] && x <= button_x_[b] + 0x33 && y >= button_y_[b] && y <= button_y_[b] + 0x28) return b;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Mouse DOWN on a minus or plus button: it is drawn pressed until the release (click()). Returns true when the
|
||||
// picture changed.
|
||||
bool SetupScreen::press(int x, int y) {
|
||||
const int id = x < 0 || y < 0 || x >= 320 || y >= 240 ? -1 : button_at(x, y);
|
||||
const bool changed = id != pressed_button_;
|
||||
pressed_button_ = id;
|
||||
return changed;
|
||||
}
|
||||
|
||||
SetupResult SetupScreen::click(int x, int y, bool right) {
|
||||
// the release ends the pressed look, which needs a redraw even when the value stays (a button at its limit)
|
||||
const bool was_pressed = pressed_button_ >= 0;
|
||||
pressed_button_ = -1;
|
||||
SetupResult result = handle_click(x, y, right);
|
||||
result.changed |= was_pressed;
|
||||
return result;
|
||||
}
|
||||
|
||||
SetupResult SetupScreen::handle_click(int x, int y, bool right) {
|
||||
if (x < 0 || y < 0 || x >= 320 || y >= 240) return {};
|
||||
if (right) return {false, SetupRequest::new_game};
|
||||
if (!joining_) {
|
||||
@@ -119,8 +151,14 @@ Image SetupScreen::render() const {
|
||||
if (joining_ && (!joining_arrow_permission_[b] ||
|
||||
(difficulty_arrows_locked_ && (b == 1 || b == 5))))
|
||||
continue;
|
||||
copy_rect(out, atlas_, 0x36 + (b > 3 ? 0x26 : 0), button_source_y_,
|
||||
button_x_[b], button_y_[b], 0x26, 0x26);
|
||||
// Held down by the mouse: the darker 36x36 picture in the bottom rows of the atlas (minus at x 0, plus at
|
||||
// x 36), drawn 2 pixels right and down of the raised button over the plain background (measured pixel for
|
||||
// pixel against a recording of the original).
|
||||
if (pressed_button_ == b)
|
||||
copy_rect(out, atlas_, b > 3 ? 36 : 0, atlas_.height - 36, button_x_[b] + 2, button_y_[b] + 2, 36, 36);
|
||||
else
|
||||
copy_rect(out, atlas_, 0x36 + (b > 3 ? 0x26 : 0), button_source_y_,
|
||||
button_x_[b], button_y_[b], 0x26, 0x26);
|
||||
}
|
||||
const int values[] = {options_.duration, options_.difficulty, options_.managers, options_.mode};
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
||||
@@ -42,9 +42,14 @@ public:
|
||||
SetupScreen(const std::filesystem::path& data, SetupOptions current);
|
||||
const SetupOptions& options() const { return options_; }
|
||||
SetupResult click(int x, int y, bool right_button = false);
|
||||
// Mouse DOWN on a minus or plus button: drawn pressed until the release (click()). True when the picture changed.
|
||||
bool press(int x, int y);
|
||||
Image render() const;
|
||||
|
||||
private:
|
||||
int button_at(int x, int y) const;
|
||||
SetupResult handle_click(int x, int y, bool right);
|
||||
int pressed_button_ = -1; // minus/plus button held down by the mouse
|
||||
SetupOptions options_;
|
||||
Image background_, atlas_;
|
||||
std::array<int, 8> button_x_{}, button_y_{};
|
||||
|
||||
+18
-38
@@ -4,6 +4,9 @@
|
||||
// construction. Source-tick timing for the calculator is advanced by the caller.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/stadium.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/calculator_widgets.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
@@ -72,23 +75,7 @@ void source_shadow(Image& out, int x, int y, int w, int h) {
|
||||
// corner pieces from the widget atlas, and the edge strips tiled in runs of 74 px (top/bottom) and 96 px (left/right).
|
||||
void source_frame(Image& out, const Image& atlas, const LeImage& exe,
|
||||
int x, int y, int w, int h, bool shadow = true) {
|
||||
if (shadow) { fill(out, x + 2, y + h, w, 2, 0x40); fill(out, x + w, y + 2, 2, h, 0x40); }
|
||||
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx)
|
||||
out.at(x + xx, y + yy) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + size_t((yy - 4) & 15) * 16 + size_t((xx - 4) & 15));
|
||||
copy_crop(out, atlas, 0, 0, x, y, 4, 4);
|
||||
copy_crop(out, atlas, 4, 0, x + w - 4, y, 4, 4);
|
||||
copy_crop(out, atlas, 0, 4, x, y + h - 4, 4, 4);
|
||||
copy_crop(out, atlas, 4, 4, x + w - 4, y + h - 4, 4, 4);
|
||||
for (int at = 4; at < w - 4; at += 74) {
|
||||
const int n = std::min(74, w - 4 - at);
|
||||
copy_crop(out, atlas, 0, 104, x + at, y, n, 4);
|
||||
copy_crop(out, atlas, 0, 108, x + at, y + h - 4, n, 4);
|
||||
}
|
||||
for (int at = 4; at < h - 4; at += 96) {
|
||||
const int n = std::min(96, h - 4 - at);
|
||||
copy_crop(out, atlas, 0, 8, x, y + at, 4, n);
|
||||
copy_crop(out, atlas, 4, 8, x + w - 4, y + at, 4, n);
|
||||
}
|
||||
draw_dialog_frame(out, atlas, exe, x, y, w, h, shadow); // dialog_frame.hpp
|
||||
}
|
||||
// Draws text with its baseline at `baseline` (skipped entirely if it would leave the screen vertically).
|
||||
// In gradient mode (executable flag == 2) a color found in the 32-entry gradient table is recolored per glyph row
|
||||
@@ -714,26 +701,22 @@ void StadiumScreen::original_button(Image& out, int x, int y, int w, int h,
|
||||
// wide buttons requested with height 9 are drawn 10 px high
|
||||
const int visible_h = w > 31 && h == 9 ? 10 : h;
|
||||
if (visible_h != 10 && !(w <= 31 && visible_h == 9)) throw FormatError("stadium: unsupported Original button height");
|
||||
if (selected) {
|
||||
const auto under = out.at(x, y + visible_h);
|
||||
fill(out, x, y, w <= 31 ? w + 1 : w, 2, under); fill(out, x, y, 2, visible_h + 1, under); x += 2; y += 2;
|
||||
} else { fill(out, x + 2, y + visible_h, w, 2, 0x40); fill(out, x + w, y + 2, 2, visible_h, 0x40); }
|
||||
if (w <= 31) {
|
||||
source_frame(out, widgets_, exe_, x, y, w, visible_h, false);
|
||||
if (w > 31) {
|
||||
// wide buttons: the shared frame (button_frame.hpp)
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, w, selected);
|
||||
x += shift; y += shift;
|
||||
sprite_font_.draw(out, x + w / 2 - sprite_font_.text_width(original_to_utf8(label)) / 2,
|
||||
y + visible_h / 2 + 2, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
|
||||
y + 7, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
|
||||
return;
|
||||
}
|
||||
const int sy = selected ? 44 : 74;
|
||||
copy_crop(out, widgets_, 24, sy, x, y, 31, 10);
|
||||
int used = 31;
|
||||
while (w - used > 20) {
|
||||
const int n = std::min(8, w - used - 20);
|
||||
copy_crop(out, widgets_, 24, sy + 10, x + used, y, n, 10); used += n;
|
||||
}
|
||||
copy_crop(out, widgets_, 45 - (w - used), sy + 20, x + used, y, w - used, 10);
|
||||
if (selected) {
|
||||
const auto under = out.at(x, y + visible_h);
|
||||
fill(out, x, y, w + 1, 2, under); fill(out, x, y, 2, visible_h + 1, under); x += 2; y += 2;
|
||||
} else { fill(out, x + 2, y + visible_h, w, 2, 0x40); fill(out, x + w, y + 2, 2, visible_h, 0x40); }
|
||||
// narrow buttons (w <= 31): the four-pixel frame around a pattern
|
||||
source_frame(out, widgets_, exe_, x, y, w, visible_h, false);
|
||||
sprite_font_.draw(out, x + w / 2 - sprite_font_.text_width(original_to_utf8(label)) / 2,
|
||||
y + 7, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
|
||||
y + visible_h / 2 + 2, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
|
||||
}
|
||||
|
||||
// Creates a request stamped with the identity of the current state (manager, club, scope, sequence and revision).
|
||||
@@ -873,9 +856,7 @@ Image StadiumScreen::render_block_expansion(Image out) const {
|
||||
Image StadiumScreen::render_block_calculator(Image out) const {
|
||||
if (!block_calculator_open_ || block_calculator_cancel_wait_ || !state_.block_expansion) return out;
|
||||
const int x0 = block_calculator_x_, y0 = block_calculator_y_;
|
||||
copy_crop(out, calculator_art_, 0, 0, x0, y0, 113, 136);
|
||||
fill(out, x0 + 113, y0 + 2, 2, 136, 0x40);
|
||||
fill(out, x0 + 2, y0 + 136, 113, 2, 0x40);
|
||||
draw_calculator_panel(out, calculator_art_, x0, y0); // calculator_widgets.hpp
|
||||
const auto& editor = *state_.block_expansion;
|
||||
const std::string title = texts_[1118];
|
||||
const int width = font_.text_width(title);
|
||||
@@ -886,8 +867,7 @@ Image StadiumScreen::render_block_calculator(Image out) const {
|
||||
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
|
||||
const int y = y0 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
|
||||
const bool pressed = block_calculator_pressed_key_ == i;
|
||||
copy_crop(out, calculator_art_, pressed ? 15 : 0, 136, x + (pressed ? 1 : 0),
|
||||
y + (pressed ? 1 : 0), 15 - int(pressed), 14 - int(pressed));
|
||||
draw_calculator_key(out, calculator_art_, x, y, pressed);
|
||||
text_at(out, x + 5 + int(pressed), y + 9 + int(pressed), keys.substr(size_t(i), 1), 0x62, false);
|
||||
}
|
||||
const uint32_t current = uint32_t(editor.quote.current_capacity_thousands) * 1000;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/team_statistics.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
@@ -31,22 +32,8 @@ void rect(Image& out, int x, int y, int w, int h, uint8_t value) {
|
||||
}
|
||||
void source_frame(Image& out, const Image& widgets, const LeImage& exe,
|
||||
int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = 0; yy < h - 7; ++yy) for (int xx = 0; xx < w - 7; ++xx)
|
||||
out.at(x + 4 + xx, y + 4 + yy) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + (yy & 15) * 16 + (xx & 15));
|
||||
copy(out, widgets, 0, 0, x, y, 4, 4); copy(out, widgets, 4, 0, x + w - 4, y, 4, 4);
|
||||
copy(out, widgets, 0, 4, x, y + h - 4, 4, 4); copy(out, widgets, 4, 4, x + w - 4, y + h - 4, 4, 4);
|
||||
for (int xx = 4; xx < w - 4; xx += 74) {
|
||||
const int amount = std::min(74, w - 4 - xx);
|
||||
copy(out, widgets, 0, 104, x + xx, y, amount, 4); copy(out, widgets, 0, 108, x + xx, y + h - 4, amount, 4);
|
||||
}
|
||||
for (int yy = 4; yy < h - 4; yy += 96) {
|
||||
const int amount = std::min(96, h - 4 - yy);
|
||||
copy(out, widgets, 0, 8, x, y + yy, 4, amount); copy(out, widgets, 4, 8, x + w - 4, y + yy, 4, amount);
|
||||
}
|
||||
int ramp = 0; while (ramp < 32 && exe.u8(::bmh::layout::Advertising_Text_RuntimeField2 + ramp) != color) ++ramp;
|
||||
const uint8_t shadow = exe.u8(::bmh::layout::Advertising_Text_RuntimeField + ramp * 6 + 5);
|
||||
rect(out, x + 2, y + h, w, 2, 0x40); rect(out, x + w, y + 2, 2, h, 0x40);
|
||||
(void)shadow;
|
||||
(void)color;
|
||||
draw_dialog_frame(out, widgets, exe, x, y, w, h, true); // dialog_frame.hpp
|
||||
}
|
||||
std::string source_field(int value, int width) {
|
||||
std::string s = std::to_string(value);
|
||||
|
||||
@@ -17,6 +17,18 @@ int main(int argc, char** argv) {
|
||||
const auto before = screen.options();
|
||||
check(before == SetupOptions{}, "original defaults");
|
||||
check(screen.render().pixels.size() == 320*240, "native framebuffer");
|
||||
{ // minus and plus look pressed (the darker picture) while held, raised again after the release
|
||||
SetupScreen probe(argv[1]);
|
||||
const auto raised = probe.render();
|
||||
check(!probe.press(5, 5) && !probe.press(130, 214), "no pressed look outside the buttons");
|
||||
check(probe.press(30, 30) && probe.render().pixels != raised.pixels, "minus shows the pressed look");
|
||||
check(!probe.press(30, 30), "an unchanged press does not redraw");
|
||||
check(probe.press(260, 30) && probe.render().pixels != raised.pixels, "plus shows the pressed look");
|
||||
probe.click(5, 5); // released elsewhere: the button is raised again and nothing is changed
|
||||
check(probe.render().pixels == raised.pixels && probe.options() == SetupOptions{}, "the release ends the pressed look");
|
||||
probe.press(260, 30);
|
||||
check(probe.click(260, 30).changed, "the release redraws even when the value cannot change");
|
||||
}
|
||||
check(!screen.click(-1, 30).changed && !screen.click(320, 239, true).changed, "outside viewport");
|
||||
check(screen.click(130, 214).request == SetupRequest::none, "gap between controls");
|
||||
check(screen.click(214, 215).request == SetupRequest::load_game, "disk requests load");
|
||||
|
||||
+3
-19
@@ -2,6 +2,7 @@
|
||||
// Implementation of TopScorersScreen (top_scorers.hpp): list and podium drawing, footer button handling including drag-off cancel, and request construction.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/top_scorers.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
@@ -109,25 +110,8 @@ void TopScorersScreen::draw_text(Image& out, int x, int baseline, std::string_vi
|
||||
|
||||
void TopScorersScreen::draw_button(Image& out, int x, int y, int width,
|
||||
std::string_view original_label, bool pressed) const {
|
||||
const int dx = x + (pressed ? 2 : 0), dy = y + (pressed ? 2 : 0);
|
||||
if (pressed) {
|
||||
const auto background = out.at(x, y + 10);
|
||||
fill(out, x, y, width + 1, 2, background);
|
||||
fill(out, x, y, 2, 11, background);
|
||||
} else {
|
||||
fill(out, x + 2, y + 10, width, 2, 0x40);
|
||||
fill(out, x + width, y + 2, 2, 10, 0x40);
|
||||
}
|
||||
const int source_y = pressed ? 44 : 74;
|
||||
copy(out, button_art_, 24, source_y, dx, dy, 31, 10);
|
||||
int used = 31;
|
||||
while (width - used > 20) {
|
||||
const int count = std::min(8, width - used - 20);
|
||||
copy(out, button_art_, 24, source_y + 10, dx + used, dy, count, 10);
|
||||
used += count;
|
||||
}
|
||||
const int tail = width - used;
|
||||
copy(out, button_art_, 45 - tail, source_y + 20, dx + used, dy, tail, 10);
|
||||
const int shift = draw_wide_button_frame(out, button_art_, x, y, width, pressed);
|
||||
const int dx = x + shift, dy = y + shift;
|
||||
const auto label = original_to_utf8(std::string(original_label));
|
||||
sprite_.draw(out, dx + width / 2 - sprite_.text_width(label) / 2, dy + 7, label,
|
||||
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + uint32_t(pressed)));
|
||||
|
||||
+10
-12
@@ -2,6 +2,7 @@
|
||||
// Implementation of TrainingScreen and the training projections (training.hpp): initialization state, skill bars under the pointer, request construction and JSON output.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/training.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
@@ -189,19 +190,16 @@ void TrainingScreen::sprite_text(Image& out, int x, int baseline, std::string_vi
|
||||
}
|
||||
}
|
||||
void TrainingScreen::button(Image& out, int x, int y, int width, int height, std::string_view label, bool active) const {
|
||||
if (!active) {
|
||||
rect(out, x + 2, y + height, width, 2, 0x40); rect(out, x + width, y + 2, 2, height, 0x40);
|
||||
} else {
|
||||
const uint8_t base = out.pixels.at(size_t(y + height) * out.width + x);
|
||||
rect(out, x, y, width + 1, 2, base); rect(out, x, y, 2, height + 1, base); x += 2; y += 2;
|
||||
}
|
||||
if (height < 11 && width > 31) {
|
||||
const int shift = active ? -30 : 0;
|
||||
copy(out, widgets_, 24, 74 + shift, x, y, 31, 10);
|
||||
int cursor = 31, left = width - 31;
|
||||
while (left > 20) { const int n = std::min(8, left - 20); copy(out, widgets_, 24, 84 + shift, x + cursor, y, n, 10); cursor += n; left -= n; }
|
||||
copy(out, widgets_, 45 - left, 94 + shift, x + cursor, y, left, 10);
|
||||
if (height == 10 && width > 31) {
|
||||
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, active); // button_frame.hpp
|
||||
x += shift; y += shift;
|
||||
} else {
|
||||
if (!active) {
|
||||
rect(out, x + 2, y + height, width, 2, 0x40); rect(out, x + width, y + 2, 2, height, 0x40);
|
||||
} else {
|
||||
const uint8_t base = out.pixels.at(size_t(y + height) * out.width + x);
|
||||
rect(out, x, y, width + 1, 2, base); rect(out, x, y, 2, height + 1, base); x += 2; y += 2;
|
||||
}
|
||||
// PatternStartsAt(0,0x12): original four-pixel frame and patterned interior.
|
||||
for (int yy = 4; yy < height - 3; ++yy) for (int xx = 4; xx < width - 3; ++xx)
|
||||
out.at(x + xx, y + yy) = exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + ((yy - 4) % 16) * 16 + (xx - 4) % 16);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Implementation of TrainingCampScreen and training_camp_from_game() (training_camp.hpp): resort rows with hover, price and star display, and booking/focus request construction.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/training_camp.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
@@ -243,13 +244,11 @@ Image TrainingCampScreen::render() const {
|
||||
sprite_text(out, 104, 235, visit_text, 5);
|
||||
if (chosen_resort_ >= 0 && state_.booking_allowed()) {
|
||||
constexpr int x = 223, y = 214, width = 64, height = 10;
|
||||
rect(out, x + 2, y + height, width, 2, 0x40); rect(out, x + width, y + 2, 2, height, 0x40);
|
||||
copy(out, buttons_, 24, 74, x, y, 31, height);
|
||||
int at = 31, remaining = width - 31;
|
||||
while (remaining > 20) { const int n = std::min(8, remaining - 20); copy(out, buttons_, 24, 84, x + at, y, n, height); at += n; remaining -= n; }
|
||||
copy(out, buttons_, 45 - remaining, 94, x + at, y, remaining, height);
|
||||
(void)height;
|
||||
// the booking button is drawn pressed while the mouse button is held (button_frame.hpp)
|
||||
const int shift = draw_wide_button_frame(out, buttons_, x, y, width, booking_pressed_);
|
||||
const int label_width = small_.text_width(texts_[1267]);
|
||||
text(out, x + width / 2 - label_width / 2, y + 7, texts_[1267], 0);
|
||||
text(out, x + shift + width / 2 - label_width / 2, y + shift + 7, texts_[1267], 0);
|
||||
}
|
||||
if (!rejection_.empty() || state_.feedback != TrainingCampFeedback::none) {
|
||||
std::string message;
|
||||
@@ -268,7 +267,8 @@ Image TrainingCampScreen::render() const {
|
||||
notice.source_manager_flags=state_.feedback==TrainingCampFeedback::booked ||
|
||||
state_.feedback==TrainingCampFeedback::none ? 0x80 : 0x40;
|
||||
draw_source_dialog(out,{buttons_,portraits_,&badge_,small_,large_,exe_,sprite_font_,texts_},
|
||||
notice,state_.gradient_text);
|
||||
notice,state_.gradient_text,
|
||||
notice_pressed_ ? std::optional<GameEndTaxDialog::Button>(GameEndTaxDialog::Button::acknowledge) : std::nullopt);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -284,7 +284,24 @@ TrainingCampRequest TrainingCampScreen::initialize_focus() {
|
||||
return *pending_;
|
||||
}
|
||||
|
||||
// Mouse DOWN on the booking button: drawn pressed until the release. Returns true when the picture changed.
|
||||
bool TrainingCampScreen::press(int x, int y) {
|
||||
const bool on = !pending_ && chosen_resort_ >= 0 && state_.booking_allowed() && rejection_.empty() &&
|
||||
state_.feedback == TrainingCampFeedback::none && x >= 223 && x < 287 && y >= 214 && y < 224;
|
||||
// OK of an acknowledging notice (booked or a plain rejection; the timed warnings have no button)
|
||||
const bool notice_shown = !pending_ && (!rejection_.empty() || state_.feedback != TrainingCampFeedback::none);
|
||||
const bool acknowledging = state_.feedback == TrainingCampFeedback::booked || state_.feedback == TrainingCampFeedback::none;
|
||||
const bool ok = notice_shown && acknowledging &&
|
||||
source_dialog_button_at(TaxDialogKind::acknowledgement, false, x, y) == GameEndTaxDialog::Button::acknowledge;
|
||||
const bool changed = on != booking_pressed_ || ok != notice_pressed_;
|
||||
booking_pressed_ = on;
|
||||
notice_pressed_ = ok;
|
||||
return changed;
|
||||
}
|
||||
|
||||
TrainingCampRequest TrainingCampScreen::click(int x, int y, bool right) {
|
||||
booking_pressed_ = false; // the release ends the pressed look
|
||||
notice_pressed_ = false;
|
||||
if (pending_) return {};
|
||||
if (right && timed_notice_open()) {
|
||||
rejection_.clear(); state_.feedback=TrainingCampFeedback::none; return {};
|
||||
|
||||
@@ -66,6 +66,8 @@ public:
|
||||
TrainingCampScreen(const std::filesystem::path& data, TrainingCampState state);
|
||||
Image render() const;
|
||||
TrainingCampRequest click(int x, int y, bool right = false);
|
||||
// Mouse DOWN on the booking button: drawn pressed until the release (click()).
|
||||
bool press(int x, int y);
|
||||
TrainingCampRequest key(std::string_view key);
|
||||
bool move(int x, int y);
|
||||
const TrainingCampState& state() const { return state_; }
|
||||
@@ -87,6 +89,8 @@ private:
|
||||
int selected_resort_ = -1;
|
||||
int preview_resort_ = -1; // Text(-1) preserves the last photo while clearing details.
|
||||
int chosen_resort_ = -1;
|
||||
bool booking_pressed_ = false; // booking button held down by the mouse
|
||||
bool notice_pressed_ = false; // OK of the notice held down by the mouse
|
||||
bool close_requested_ = false;
|
||||
std::optional<TrainingCampRequest> pending_;
|
||||
std::string rejection_;
|
||||
|
||||
+162
-32
@@ -3,6 +3,7 @@
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/transfer_market.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
@@ -134,8 +135,9 @@ TransferMarketState transfer_market_from_game(const GameState& g, uint64_t revis
|
||||
item.seller_name = g.club_name(item.seller);
|
||||
item.own_listing = item.seller == state.runtime_club;
|
||||
}
|
||||
// Asking fee as stored in the list entry, scaled as the original does (value/10000 times 0x30d4); must fit in int32.
|
||||
const uint64_t fee = uint64_t(g.memory.u32(entry + 0x2c) / 10000) * 0x30d4;
|
||||
// Asking fee as stored in the list entry, rounded down to whole 10000 as the original does (sub_3C940 of Diamond 3.7:
|
||||
// value/10000 times 10000; the older build scaled it by 0x30d4 = 1.25); must fit in int32.
|
||||
const uint64_t fee = uint64_t(g.memory.u32(entry + 0x2c) / 10000) * 10000;
|
||||
if (fee > uint64_t(std::numeric_limits<int32_t>::max())) throw FormatError("transfer market: asking fee out of range");
|
||||
item.asking_fee = int32_t(fee);
|
||||
item.salary_reference = g.memory.u32(entry + 0x30);
|
||||
@@ -171,6 +173,11 @@ TransferMarketState transfer_market_from_game(const GameState& g, uint64_t revis
|
||||
state.decorated_background=!g.memory.has(::bmh::layout::PlainBackground)||g.memory.u8(::bmh::layout::PlainBackground)==0;
|
||||
state.textured_panes=!g.memory.has(::bmh::layout::SolidPanelBackground)||g.memory.u8(::bmh::layout::SolidPanelBackground)==0;
|
||||
state.source_market_mode=g.memory.has(::bmh::layout::GameMode)?g.memory.u8(::bmh::layout::GameMode):uint8_t(0);
|
||||
// The search profile and the two suggestions of "Vorschlag" (a national coach has no market, so no profile).
|
||||
if(state.runtime_club!=kNoTeam) {
|
||||
state.search_profile=search_profile(g,manager);
|
||||
for(int whole=0;whole<2;++whole)state.search_suggestion[size_t(whole)]=suggest_search_profile(g,manager,whole!=0);
|
||||
}
|
||||
if(g.memory.has(::bmh::layout::ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField)&&g.memory.has(::bmh::layout::ClubPlayerDetail_ClubPlayerDetailFromGame_RuntimeField2))state.currency=std::pair<int32_t,int32_t>{int32_t(g.memory.u32(::bmh::layout::CurrencyMultiplier)),int32_t(g.memory.u32(::bmh::layout::CurrencyDivisor))};
|
||||
// Roster block shown on the left side of the screen (same data as the club info screen).
|
||||
state.roster.runtime_team=state.runtime_club;state.roster.original_club_name=state.club_name;
|
||||
@@ -319,7 +326,8 @@ std::string transfer_market_request_json(const TransferMarketRequest& r) {
|
||||
r.kind == TransferMarketRequestKind::open_offer ? "open_offer" :
|
||||
r.kind == TransferMarketRequestKind::preview_quote ? "preview_quote" :
|
||||
r.kind == TransferMarketRequestKind::open_poach ? "open_poach" :
|
||||
r.kind == TransferMarketRequestKind::review_offers ? "review_offers" : "none";
|
||||
r.kind == TransferMarketRequestKind::review_offers ? "review_offers" :
|
||||
r.kind == TransferMarketRequestKind::store_search_profile ? "store_search_profile" : "none";
|
||||
std::ostringstream out;
|
||||
out << "{\"kind\":\"" << kind << "\",\"manager_slot\":" << r.manager_slot
|
||||
<< ",\"runtime_club\":" << r.runtime_club << ",\"revision\":" << r.revision
|
||||
@@ -333,7 +341,12 @@ std::string transfer_market_request_json(const TransferMarketRequest& r) {
|
||||
<< ",\"fee\":" << r.bid.fee << ",\"annual_salary\":" << r.bid.annual_salary
|
||||
<< ",\"contract_years\":" << unsigned(r.bid.contract_years) << ",\"bonuses\":[";
|
||||
for (size_t i = 0; i < r.bid.bonuses.size(); ++i) { if (i) out << ','; out << r.bid.bonuses[i]; }
|
||||
out << "],\"selected_players\":[";
|
||||
out << "],\"search_profile\":[";
|
||||
for (size_t i = 0; i < r.search_profile.size(); ++i) { if (i) out << ','; out << unsigned(r.search_profile[i]); }
|
||||
out << "],\"search_cancelled\":" << (r.search_cancelled ? "true" : "false")
|
||||
<< ",\"search_apply\":" << (r.search_apply ? "true" : "false")
|
||||
<< ",\"ask_withdraw\":" << (r.ask_withdraw ? "true" : "false");
|
||||
out << ",\"selected_players\":[";
|
||||
for(size_t n=0;n<r.selected_players.size();++n){if(n)out<<',';const auto& p=r.selected_players[n];out<<"{\"list_entry\":"<<p.list_entry<<",\"source_slot\":"<<p.source_slot<<",\"player\":"<<p.player<<",\"seller\":"<<p.seller<<",\"squad_row\":"<<p.squad_row<<'}';}
|
||||
out << "]}";
|
||||
return out.str();
|
||||
@@ -347,7 +360,10 @@ TransferMarketScreen::TransferMarketScreen(const std::filesystem::path& data, Tr
|
||||
background_(load_vga(asset_path(data / "KB", "56.VGA"))),
|
||||
frame_(load_vga(asset_path(data / "KB", "129.VGA"))),widgets_(load_vga(asset_path(data / "KB", "0.VGA"))),
|
||||
atlas_(load_vga(asset_path(data / "KB", "2.VGA"))),flags_(load_vga(asset_path(data / "KB", "24.VGA"))),
|
||||
market_widgets_(load_vga(asset_path(data / "KB", "30.VGA"))) {
|
||||
market_widgets_(load_vga(asset_path(data / "KB", "30.VGA"))),
|
||||
search_panel_(load_vga(asset_path(data / "KB", "69.VGA"))) {
|
||||
if (search_panel_.width != 136 || search_panel_.height != 135)
|
||||
throw FormatError("transfer market: invalid search dialog asset");
|
||||
if (background_.width != 318 || background_.height != 207 || frame_.width!=320 || frame_.height!=240 || state_.manager_slot < 0 || state_.runtime_club < 0)
|
||||
throw FormatError("transfer market: invalid screen state or assets");
|
||||
if (state_.items.size() > 40) throw FormatError("transfer market: too many list rows");
|
||||
@@ -432,13 +448,11 @@ void TransferMarketScreen::original_text(Image& out,int x,int baseline,std::stri
|
||||
// Active buttons look pressed (the frame is drawn on the other side).
|
||||
void TransferMarketScreen::button(Image& out,int x,int y,int width,std::string_view label,bool active) const {
|
||||
const int height=width>31?10:9;
|
||||
if(active){const uint8_t c=out.at(x,y+height);rect(out,x,y,width+1,2,c);rect(out,x,y,2,height+1,c);x+=2;y+=2;}
|
||||
else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
if(width>31) {
|
||||
const int sy=active?44:74;copy(out,widgets_,24,sy,x,y,31,10);int at=31,left=width-31;
|
||||
while(left>20){const int n=std::min(8,left-20);copy(out,widgets_,24,sy+10,x+at,y,n,10);at+=n;left-=n;}
|
||||
copy(out,widgets_,45-left,sy+20,x+at,y,left,10);
|
||||
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,active);x+=shift;y+=shift; // button_frame.hpp
|
||||
} else {
|
||||
if(active){const uint8_t c=out.at(x,y+height);rect(out,x,y,width+1,2,c);rect(out,x,y,2,height+1,c);x+=2;y+=2;}
|
||||
else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
|
||||
for(int yy=4;yy<height-3;++yy)for(int xx=4;xx<width-3;++xx)
|
||||
out.at(x+xx,y+yy)=exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField+(yy-4)%16*16+(xx-4)%16);
|
||||
copy(out,widgets_,0,0,x,y,4,4);copy(out,widgets_,4,0,x+width-4,y,4,4);
|
||||
@@ -559,11 +573,11 @@ void TransferMarketScreen::draw_market_overview(Image& out) const {
|
||||
}
|
||||
original_text(out,201,183,padded(average[4]),0x6b);
|
||||
// Filter and mode buttons: positions and rectangles come from a table in the executable (6 bytes per entry).
|
||||
for(int n=4;n<13;++n)button(out,exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3+n*6),texts_[text_id(::bmh::layout::TransferMarket_Rect_TextPointer5)+size_t(n)],(view_flags_&(1u<<n))!=0);
|
||||
for(int n=4;n<13;++n)button(out,exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3+n*6),texts_[text_id(::bmh::layout::TransferMarket_Rect_TextPointer5)+size_t(n)],((view_flags_&(1u<<n))!=0)!=(pressed_button_==n));
|
||||
}
|
||||
button(out,1,215,51,texts_[text_id(data_b_?::bmh::layout::TransferMarket_Rect_TextPointer3: ::bmh::layout::TransferMarket_Rect_TextPointer4)],true);
|
||||
button(out,55,215,51,texts_[text_id(::bmh::layout::TransferMarket_Rect_TextPointer5)],full);
|
||||
for(int n=1;n<4;++n)if(!full&&state_.source_market_mode==3)button(out,exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3+n*6),texts_[text_id(::bmh::layout::TransferMarket_Rect_TextPointer5)+size_t(n)],(view_flags_&(1u<<n))!=0);
|
||||
button(out,1,215,51,texts_[text_id(data_b_?::bmh::layout::TransferMarket_Rect_TextPointer3: ::bmh::layout::TransferMarket_Rect_TextPointer4)],pressed_button_!=100);
|
||||
button(out,55,215,51,texts_[text_id(::bmh::layout::TransferMarket_Rect_TextPointer5)],full!=(pressed_button_==101));
|
||||
for(int n=1;n<4;++n)if(!full&&state_.source_market_mode==3)button(out,exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+n*6),exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3+n*6),texts_[text_id(::bmh::layout::TransferMarket_Rect_TextPointer5)+size_t(n)],((view_flags_&(1u<<n))!=0)!=(pressed_button_==n));
|
||||
}
|
||||
// Formats an amount like the original: converted with the currency multiplier/divisor,
|
||||
// left-padded to 9 characters and followed by the currency suffix.
|
||||
@@ -576,8 +590,9 @@ std::string TransferMarketScreen::original_money(int32_t value) const {
|
||||
if(result.size()<9)result.insert(0,9-result.size(),'%');
|
||||
return result+exe_.cstring(::bmh::layout::CurrencySuffixText);
|
||||
}
|
||||
// Renders the complete 320x240 screen: frame (or plain bars), title, club name, the overview and a
|
||||
// feedback line that replaces the club name line when set (shortened to fit 310 pixels).
|
||||
// Renders the complete 320x240 screen: frame (or plain bars), title, club name and the overview. The original has
|
||||
// no status line: the bottom row always shows the club name. feedback_ stays available in state_json() for hosts
|
||||
// and tests but is never drawn.
|
||||
Image TransferMarketScreen::render() const {
|
||||
Image out=state_.decorated_background?frame_:Image(320,240);
|
||||
if(!state_.decorated_background){rect(out,0,4,320,13,0x44);rect(out,1,5,318,11,0x39);rect(out,0,228,320,10,0x44);rect(out,1,229,318,8,0x39);}
|
||||
@@ -585,16 +600,7 @@ Image TransferMarketScreen::render() const {
|
||||
sprite_font_.draw(out,SpriteFont::centered_title_x(sprite_font_.text_width(title)),13,title);
|
||||
sprite_font_.draw(out,5,235,original_to_utf8(state_.club_name));
|
||||
draw_market_overview(out);
|
||||
if (!feedback_.empty()) {
|
||||
rect(out, 1, 227, 318, 12, 0x39);
|
||||
auto line = feedback_;
|
||||
while (!line.empty() && sprite_font_.text_width(line) > 310) {
|
||||
size_t at = line.size() - 1;
|
||||
while (at > 0 && (uint8_t(line[at]) & 0xc0) == 0x80) --at;
|
||||
line.resize(at);
|
||||
}
|
||||
sprite_font_.draw(out, 5, 235, line);
|
||||
}
|
||||
if (search_open_) draw_search(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -635,7 +641,7 @@ TransferMarketRequest TransferMarketScreen::make_listing(bool loan) {
|
||||
if (item.already_listed) {
|
||||
const auto listing = std::find_if(state_.items.begin(), state_.items.end(),
|
||||
[&](const auto& row) { return row.player == item.player && row.own_listing; });
|
||||
if (listing != state_.items.end()) return make_review(*listing);
|
||||
if (listing != state_.items.end()) return make_review(*listing, true);
|
||||
feedback_ = "Spieler steht bereits auf der Liste"; return {};
|
||||
}
|
||||
TransferMarketRequest request;
|
||||
@@ -674,11 +680,13 @@ TransferMarketRequest TransferMarketScreen::make_preview(bool purchase) {
|
||||
pending_=request;preview_.reset();return request;
|
||||
}
|
||||
// Creates a request to review the bids on one of the player's own listings; refuses if there are none.
|
||||
TransferMarketRequest TransferMarketScreen::make_review(const TransferMarketItem& item) {
|
||||
TransferMarketRequest TransferMarketScreen::make_review(const TransferMarketItem& item, bool ask_withdraw) {
|
||||
if (pending_) return {};
|
||||
if (item.offers == 0) { feedback_ = "Noch keine Angebote für diesen Spieler."; return {}; }
|
||||
// Without offers there is nothing to review; VERKAUFEN still has to ask whether the player leaves the list.
|
||||
if (item.offers == 0 && !ask_withdraw) { feedback_ = "Noch keine Angebote für diesen Spieler."; return {}; }
|
||||
TransferMarketRequest request;
|
||||
request.kind = TransferMarketRequestKind::review_offers;
|
||||
request.ask_withdraw = ask_withdraw;
|
||||
request.manager_slot = state_.manager_slot; request.runtime_club = state_.runtime_club;
|
||||
request.revision = state_.revision; request.bid.manager = state_.manager_slot;
|
||||
request.bid.list_entry = item.list_entry; request.bid.player = item.player;
|
||||
@@ -689,7 +697,9 @@ TransferMarketRequest TransferMarketScreen::make_review(const TransferMarketItem
|
||||
TransferMarketRequest TransferMarketScreen::make_open_offer(bool loan) {
|
||||
if(pending_||!selected_item_)return {};
|
||||
const auto& item=state_.items.at(size_t(*selected_item_));
|
||||
if(item.own_listing)return make_review(item);
|
||||
// An own listing chosen in the market list: VERKAUFEN first asks whether the player leaves the list (as for a player
|
||||
// chosen in the squad); "no" leads on to the offers.
|
||||
if(item.own_listing)return make_review(item,true);
|
||||
TransferMarketRequest request;request.kind=TransferMarketRequestKind::open_offer;request.offer_is_loan=loan;
|
||||
request.manager_slot=state_.manager_slot;request.runtime_club=state_.runtime_club;request.revision=state_.revision;
|
||||
if(item.own_bid)request.bid=*item.own_bid;
|
||||
@@ -701,7 +711,7 @@ TransferMarketRequest TransferMarketScreen::make_open_offer(bool loan) {
|
||||
// Selection by position over the market rows (x 201..297, y 25..115, 15 px per row) or the roster
|
||||
// names (x 9..60). A new selection requests a quote preview unless Komplett is on.
|
||||
TransferMarketRequest TransferMarketScreen::move(int x,int y) {
|
||||
if(pending_||close_requested_)return {};
|
||||
if(pending_||close_requested_||search_open_)return {};
|
||||
if(!(view_flags_&1)&&x>=201&&x<=297&&y>=25&&y<115) {
|
||||
const auto order=market_order();const size_t first=order.empty()?0:std::min(market_page_,(order.size()-1)/6)*6,index=first+size_t((y-25)/15);
|
||||
if(index<order.size()){if(selected_item_==order[index])return {};selected_item_=order[index];selected_squad_.reset();selected_snapshot_.reset();return make_preview(true);}
|
||||
@@ -728,7 +738,9 @@ TransferMarketRequest TransferMarketScreen::move(int x,int y) {
|
||||
// Left click handles the Data/Komplett buttons, poach and filter buttons, marking of rows, and the action bar
|
||||
// (y 202..212; the right part x>=254 means loan).
|
||||
TransferMarketRequest TransferMarketScreen::click(int x,int y,bool right) {
|
||||
pressed_button_=-1; // the release ends the held look of a button
|
||||
if(pending_||close_requested_)return {};
|
||||
if(search_open_)return click_search(x,y,right);
|
||||
if(right) {
|
||||
if(!(view_flags_&1)&&x>=185&&x<=319&&y>=21&&y<=163) {
|
||||
const auto rows=market_order();market_page_+=1;
|
||||
@@ -743,6 +755,14 @@ TransferMarketRequest TransferMarketScreen::click(int x,int y,bool right) {
|
||||
// Reset's logical4 follows Data and the three leading market
|
||||
// buttons: its physical EXE/TransferMarket_Click_RuntimeField entry3 is Abwerben.
|
||||
const int px=exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + 3*6),py=exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+3*6),pw=exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3+3*6);
|
||||
// The two buttons before Abwerben (Source entries 1 and 2): Suchen opens the search dialog with the stored
|
||||
// profile, Vorschlag with the profile the squad asks for (Source sub_19409; the dialog is local UI state).
|
||||
for(int search_button=1;search_button<=2&&state_.source_market_mode==3;++search_button) {
|
||||
const int sx=exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + search_button*6),sy=exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+search_button*6),sw=exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3+search_button*6);
|
||||
if(x<sx||x>sx+sw||y<sy||y>sy+10)continue;
|
||||
open_search(search_button==1?state_.search_profile:state_.search_suggestion[(view_flags_&0x400)?1:0]);
|
||||
return {};
|
||||
}
|
||||
if(state_.source_market_mode==3&&x>=px&&x<=px+pw&&y>=py&&y<=py+10) {
|
||||
TransferMarketRequest request;
|
||||
request.kind=TransferMarketRequestKind::open_poach;
|
||||
@@ -797,10 +817,117 @@ TransferMarketRequest TransferMarketScreen::click(int x,int y,bool right) {
|
||||
}
|
||||
return {};
|
||||
}
|
||||
// --- search dialog (Source sub_19409) --------------------------------------------------------------------------
|
||||
// Opens the dialog on a copy of `profile` (without the "off" bit of byte 0, as the Source dialog starts).
|
||||
void TransferMarketScreen::open_search(SearchProfile profile) {
|
||||
profile[0] &= 0x3F;
|
||||
search_edit_ = profile;
|
||||
search_open_ = true;
|
||||
}
|
||||
|
||||
// Draws the dialog: the 136x135 panel at (184,20), the seven bars (a dark stripe per row and the selected cells or the
|
||||
// range in the highlight colour), the price estimate of the profile and the confirm button.
|
||||
void TransferMarketScreen::draw_search(Image& out) const {
|
||||
copy(out, search_panel_, 0, 0, 184, 20, 136, 135);
|
||||
for (int row = 0; row < 7; ++row) {
|
||||
const uint32_t at = ::bmh::layout::TransferMarket_SearchRows_RuntimeField + uint32_t(row) * 5;
|
||||
const int y = exe_.u8(at), step = exe_.u8(at + 1), cells = exe_.u8(at + 2), slider = exe_.u8(at + 3), offset = exe_.u8(at + 4);
|
||||
rect(out, 217, y, 100, 2, 0x42); // Source rectangle (217,y)-(316,y+1)
|
||||
if (slider) {
|
||||
const int low = 100 * search_edit_.at(size_t(offset)) / cells, high = 100 * search_edit_.at(size_t(offset) + 1) / cells;
|
||||
rect(out, 217 + low, y, high - low + 1, 2, 0xF7);
|
||||
} else {
|
||||
for (int cell = 0, x = 217; cell < cells; ++cell, x += step)
|
||||
if (search_edit_.at(size_t(offset) + size_t(cell))) rect(out, x + 3, y, step - 5, 2, 0xF7);
|
||||
}
|
||||
}
|
||||
// Price estimate: five times the (inverted) age midpoint plus five times the strength midpoint, limited to 12..620.
|
||||
int value = 5 * (31 - (search_edit_[4] + search_edit_[5]) / 2) + 5 * ((search_edit_[7] + search_edit_[6]) / 2);
|
||||
value = std::clamp(value, 12, 620);
|
||||
value = value * (value >> 2) * ((value >> 3) + 100) / 10;
|
||||
auto price = original_money(10000 * (value / 10000));
|
||||
price.erase(0, price.find_first_not_of('%'));
|
||||
original_text(out, 216, 148, price, 0x7A);
|
||||
button(out, 277, 140, 40, texts_[text_id(::bmh::layout::TransferMarket_SearchButton_TextPointer)], pressed_button_ == 200);
|
||||
}
|
||||
|
||||
// A click inside the dialog: the confirm button closes it and applies the profile, the right button closes it and
|
||||
// switches the search off, a click on a bar row edits that row (Source: a switch toggles its cell; on a slider the
|
||||
// click moves the nearer end of the range, and the two ends never become equal).
|
||||
TransferMarketRequest TransferMarketScreen::click_search(int x, int y, bool right) {
|
||||
if (right) return close_search(true);
|
||||
if (x >= 277 && x <= 317 && y >= 140 && y <= 150) return close_search(false);
|
||||
if (x < 216 || x > 317) return {};
|
||||
for (int row = 0; row < 7; ++row) {
|
||||
const uint32_t at = ::bmh::layout::TransferMarket_SearchRows_RuntimeField + uint32_t(row) * 5;
|
||||
const int row_y = exe_.u8(at), step = exe_.u8(at + 1), cells = exe_.u8(at + 2), slider = exe_.u8(at + 3), offset = exe_.u8(at + 4);
|
||||
if (y < row_y - 2 || y > row_y + 3) continue;
|
||||
int value = (x - 217) / step;
|
||||
if (slider) {
|
||||
auto& low = search_edit_.at(size_t(offset));
|
||||
auto& high = search_edit_.at(size_t(offset) + 1);
|
||||
if ((int(low) + int(high)) / 2 < value && value != 0) {
|
||||
if (value > cells - 1) value = cells - 1;
|
||||
high = uint8_t(value);
|
||||
} else {
|
||||
low = uint8_t(std::max(0, value));
|
||||
}
|
||||
if (low == high) { if (low) --low; else ++high; }
|
||||
} else if (value >= 0 && value < cells) { // (the Source also toggles the byte after the row for a click on its last pixel column)
|
||||
search_edit_.at(size_t(offset) + size_t(value)) ^= 1;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Leaves the dialog and posts the profile to the session. Source sets view-flag bit 1 (the Suchen button) to whether
|
||||
// the closed profile is an active search.
|
||||
TransferMarketRequest TransferMarketScreen::close_search(bool cancelled) {
|
||||
search_open_ = false;
|
||||
view_flags_ = uint16_t((view_flags_ & ~2u) | (search_profile_active(search_edit_, cancelled) ? 2u : 0u));
|
||||
TransferMarketRequest request;
|
||||
request.kind = TransferMarketRequestKind::store_search_profile;
|
||||
request.manager_slot = state_.manager_slot; request.runtime_club = state_.runtime_club; request.revision = state_.revision;
|
||||
request.search_profile = search_edit_; request.search_cancelled = cancelled; request.search_apply = !cancelled;
|
||||
pending_ = request; feedback_.clear();
|
||||
return request;
|
||||
}
|
||||
|
||||
// The button under the pointer (same hit areas as click()): 100 Data, 101 Komplett, 1..3 the buttons before Abwerben (mode III),
|
||||
// 4..10 the position and page buttons, 11/12 the action bar (purchase / loan), 200 the confirm button of the search dialog.
|
||||
int TransferMarketScreen::button_at(int x, int y) const {
|
||||
if (search_open_) return x >= 277 && x <= 317 && y >= 140 && y <= 150 ? 200 : -1;
|
||||
if (x >= 1 && x <= 52 && y >= 215 && y <= 225) return 100;
|
||||
if (x >= 55 && x <= 106 && y >= 215 && y <= 225) return 101;
|
||||
if (view_flags_ & 1) return -1;
|
||||
for (int n = 1; n <= 10; ++n) {
|
||||
if (n <= 3 && state_.source_market_mode != 3) continue;
|
||||
const int bx = exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField + n * 6);
|
||||
const int by = exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField2 + n * 6);
|
||||
const int width = exe_.u16(::bmh::layout::TransferMarket_Click_RuntimeField3 + n * 6);
|
||||
if (x >= bx && x <= bx + width && y >= by && y <= by + 10) return n;
|
||||
}
|
||||
if (y >= 202 && y <= 212 && x >= 185 && x <= 318) return x >= 254 ? 12 : 11;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Mouse DOWN: the button under the pointer is drawn pressed until the release (the action itself happens in click()).
|
||||
bool TransferMarketScreen::press(int x, int y, bool right) {
|
||||
if (pending_ || close_requested_) return false;
|
||||
const int id = right ? -1 : button_at(x, y);
|
||||
const bool changed = id != pressed_button_;
|
||||
pressed_button_ = id;
|
||||
return changed;
|
||||
}
|
||||
|
||||
// Keyboard shortcuts: Esc closes, B or Enter opens an offer for the selected market item,
|
||||
// V or Enter lists the selected squad player.
|
||||
TransferMarketRequest TransferMarketScreen::key(std::string_view key) {
|
||||
if(pending_||close_requested_)return {};
|
||||
if(search_open_) { // the dialog only knows the mouse; Esc counts as the right button
|
||||
if(key=="ESC"||key=="ESCAPE")return close_search(true);
|
||||
return {};
|
||||
}
|
||||
if(key=="ESC"||key=="ESCAPE"){close_requested_=true;return {};}
|
||||
if(key=="B"&&selected_item_)return make_open_offer();
|
||||
if(key=="V"&&selected_squad_)return make_listing();
|
||||
@@ -889,7 +1016,10 @@ std::string TransferMarketScreen::state_json() const {
|
||||
<< ",\"active_field\":" << active_field_ << ",\"numeric_input\":" << json_quote(numeric_input_)
|
||||
<< ",\"pending\":" << (pending_ ? transfer_market_request_json(*pending_) : "null")
|
||||
<< ",\"feedback\":" << json_quote(feedback_)
|
||||
<< ",\"preview\":";
|
||||
<< ",\"pressed_button\":" << pressed_button_
|
||||
<< ",\"search_open\":" << (search_open_ ? "true" : "false") << ",\"search_edit\":[";
|
||||
for (size_t i = 0; i < search_edit_.size(); ++i) out << (i ? "," : "") << unsigned(search_edit_[i]);
|
||||
out << "],\"preview\":";
|
||||
if (preview_) {
|
||||
out << "{\"source_slot\":" << preview_->source_slot << ",\"player\":" << preview_->player
|
||||
<< ",\"seller\":" << preview_->seller << ",\"revision\":" << preview_->revision
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "game/poach.hpp"
|
||||
#include "ui/sprite_font.hpp"
|
||||
#include "game/desk_actions.hpp"
|
||||
#include "game/search_profile.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
|
||||
@@ -63,13 +64,18 @@ struct TransferMarketState {
|
||||
uint8_t source_market_mode = 0; // Unknown is not an inferred Mode III.
|
||||
std::optional<std::pair<int32_t,int32_t>> currency;
|
||||
std::array<uint16_t,5> active_strengths{},team_strengths{};
|
||||
// Search profile of the manager (buttons Suchen / Vorschlag): the stored profile and the two suggestions the squad
|
||||
// asks for (index 0 = first eleven, 1 = whole squad, chosen by the Komplett-style view flag 0x400).
|
||||
SearchProfile search_profile{};
|
||||
std::array<SearchProfile,2> search_suggestion{};
|
||||
};
|
||||
|
||||
TransferMarketState transfer_market_from_game(const GameState&, uint64_t revision);
|
||||
std::string transfer_market_state_json(const TransferMarketState&);
|
||||
TaxDialogProjection poach_notice_from_game(const GameState&,const PoachStart&,std::string original_message);
|
||||
|
||||
enum class TransferMarketRequestKind { none, submit_bid, list_player, open_offer, preview_quote, open_poach, review_offers };
|
||||
enum class TransferMarketRequestKind { none, submit_bid, list_player, open_offer, preview_quote, open_poach, review_offers,
|
||||
store_search_profile };
|
||||
struct TransferMarketSelection {
|
||||
int list_entry=-1,source_slot=-1,player=-1,seller=-1,squad_row=-1;
|
||||
};
|
||||
@@ -86,6 +92,13 @@ struct TransferMarketRequest {
|
||||
int preview_snapshot_index = -1;
|
||||
bool offer_is_loan = false;
|
||||
std::vector<TransferMarketSelection> selected_players;
|
||||
// store_search_profile: the edited profile when the search dialog is closed; `search_cancelled` = left by right click
|
||||
// (the profile is kept but switched off), `search_apply` = closed with the "Suchen" button (list the matches).
|
||||
SearchProfile search_profile{};
|
||||
bool search_cancelled = false, search_apply = false;
|
||||
// review_offers started by VERKAUFEN on an already listed own player: the original first asks
|
||||
// "Wollen Sie <name> vom Transfermarkt holen?" (yes = off the list, no = look at the offers).
|
||||
bool ask_withdraw = false;
|
||||
};
|
||||
std::string transfer_market_request_json(const TransferMarketRequest&);
|
||||
|
||||
@@ -107,11 +120,16 @@ public:
|
||||
TransferMarketScreen(const std::filesystem::path&, TransferMarketState);
|
||||
Image render() const;
|
||||
TransferMarketRequest click(int x, int y, bool right = false);
|
||||
// Mouse DOWN on a button: the button is drawn pressed until the release (click). Returns whether the picture changed.
|
||||
bool press(int x, int y, bool right = false);
|
||||
// TransferMarketScreen hover preview; host acknowledges the quote before more input.
|
||||
TransferMarketRequest move(int x, int y);
|
||||
TransferMarketRequest key(std::string_view);
|
||||
bool text(std::string_view);
|
||||
bool close_requested() const { return close_requested_; }
|
||||
// The search dialog (buttons Suchen / Vorschlag) is open: it owns every click until it is closed.
|
||||
bool search_open() const { return search_open_; }
|
||||
const SearchProfile& search_edit() const { return search_edit_; }
|
||||
const TransferMarketState& state() const { return state_; }
|
||||
const std::optional<TransferMarketRequest>& pending() const { return pending_; }
|
||||
void acknowledge(TransferMarketState, std::string notice = {});
|
||||
@@ -129,7 +147,7 @@ private:
|
||||
LeImage exe_;
|
||||
TextDb texts_;
|
||||
SpriteFont sprite_font_;
|
||||
Image background_, frame_, widgets_, atlas_, flags_, market_widgets_;
|
||||
Image background_, frame_, widgets_, atlas_, flags_, market_widgets_, search_panel_;
|
||||
uint16_t view_flags_ = 0x1f0;
|
||||
bool data_b_ = false;
|
||||
size_t market_page_ = 0;
|
||||
@@ -149,9 +167,18 @@ private:
|
||||
std::string numeric_input_, feedback_; // feedback is UTF-8, like host notices.
|
||||
int active_field_ = 0;
|
||||
bool close_requested_ = false;
|
||||
bool search_open_ = false;
|
||||
SearchProfile search_edit_{};
|
||||
// The button held by the mouse (draw id: 1..12 market buttons, 100 Data, 101 Komplett, 200 search confirm), -1 none.
|
||||
int pressed_button_ = -1;
|
||||
int button_at(int x, int y) const;
|
||||
void open_search(SearchProfile profile);
|
||||
void draw_search(Image&) const;
|
||||
TransferMarketRequest click_search(int x, int y, bool right);
|
||||
TransferMarketRequest close_search(bool cancelled);
|
||||
void draw_text(Image&, int x, int y, std::string_view, uint8_t color) const;
|
||||
void commit_numeric_field();
|
||||
TransferMarketRequest make_review(const TransferMarketItem&);
|
||||
TransferMarketRequest make_review(const TransferMarketItem&, bool ask_withdraw = false);
|
||||
TransferMarketRequest make_bid();
|
||||
TransferMarketRequest make_listing(bool loan=false);
|
||||
TransferMarketRequest make_open_offer(bool loan=false);
|
||||
|
||||
@@ -74,7 +74,9 @@ int main(int argc,char** argv){
|
||||
const auto rejected_frame = screen.render();
|
||||
screen.key("V");
|
||||
screen.reject_action("Anderer sichtbarer Hinweis");
|
||||
check(screen.render().pixels != rejected_frame.pixels, "host rejection is actually rendered in the footer");
|
||||
// the original has no status line: the footer keeps showing the club name, the text stays in state_json()
|
||||
check(screen.render().pixels == rejected_frame.pixels, "host rejection does not replace the club name in the footer");
|
||||
check(screen.state_json().find("Anderer sichtbarer Hinweis")!=std::string::npos,"host rejection stays in the state");
|
||||
|
||||
TransferMarketScreen selected(argv[1],s);
|
||||
auto marked_market=selected.click(210,28);selected.acknowledge_preview(s,quote(marked_market));
|
||||
@@ -94,9 +96,20 @@ int main(int argc,char** argv){
|
||||
review.acknowledge_unchanged();
|
||||
listed.items[0].offers=0;TransferMarketScreen waiting(argv[1],listed);
|
||||
auto hover_waiting=waiting.click(20,32);waiting.acknowledge_preview(listed,quote(hover_waiting));
|
||||
check(waiting.key("V").kind==TransferMarketRequestKind::none&&
|
||||
waiting.state_json().find("Noch keine Angebote")!=std::string::npos,
|
||||
"an own listing without incoming offers gives visible feedback");
|
||||
const auto withdraw=waiting.key("V");
|
||||
check(withdraw.kind==TransferMarketRequestKind::review_offers&&withdraw.ask_withdraw&&withdraw.bid.list_entry==4&&
|
||||
transfer_market_request_json(withdraw).find("\"ask_withdraw\":true")!=std::string::npos,
|
||||
"selling a listed own player without offers still asks whether he leaves the list");
|
||||
{ // the same question when the listed player is chosen in the market list (right panel), with and without offers
|
||||
for(const uint8_t offers:{uint8_t(0),uint8_t(1)}) {
|
||||
auto own_state=listed;own_state.items[0].offers=offers;
|
||||
TransferMarketScreen own(argv[1],own_state);
|
||||
auto chosen=own.click(210,28);own.acknowledge_preview(own_state,quote(chosen));
|
||||
const auto sell_listed=own.click(200,206);
|
||||
check(sell_listed.kind==TransferMarketRequestKind::review_offers&&sell_listed.ask_withdraw&&sell_listed.bid.list_entry==4,
|
||||
"selling an own listing chosen in the market list asks whether the player leaves the list");
|
||||
}
|
||||
}
|
||||
auto expired=fixture();expired.squad_slots[2932]=0x0fff;
|
||||
check(!transfer_market_from_game(expired,5).squad[0].already_listed,
|
||||
"cleared rejected/expired pool entry immediately makes the player listable again");
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "app/controller.hpp"
|
||||
#include "app/window_actions.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/pending_offer.hpp"
|
||||
#include "ui/contracts.hpp"
|
||||
#include "game/month.hpp"
|
||||
#include "game/desk_actions.hpp"
|
||||
@@ -409,6 +410,228 @@ void check_transfer_market_controller(const std::filesystem::path& data) {
|
||||
session->rand().seed() == listed_seed && session->rand().calls() == listed_calls,
|
||||
"consumed list request replay is inert");
|
||||
|
||||
{ // GUI route: the offers on an own listing are reviewed from the roster and accepted before the listing expires
|
||||
int entry = -1;
|
||||
for (int e = 0; e < 40; ++e) if ((game.squad_slots.at(0xb70 + size_t(e)) & 0xfff) == listed_player) entry = e;
|
||||
check(entry >= 0, "the own listing has a transfer-list entry");
|
||||
const uint32_t list = ::bmh::layout::EditorList + uint32_t(entry) * 0x58;
|
||||
MinuteReport bid_report;
|
||||
for (int tries = 0; tries < 400 && int16_t(game.memory.u16(list)) == -1; ++tries)
|
||||
transfer_bid(game, 0xb70 + entry, list, false, -1, session->game(), session->rand(), bid_report);
|
||||
check(!bid_report.unsupported && int16_t(game.memory.u16(list)) != -1, "the engine places a bid on the own listing");
|
||||
flow.send_key("ESC");
|
||||
flow.attach_preparation_context(session->preparation_projection(revision));
|
||||
const auto menu17 = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(),
|
||||
[](const DeskItem& item) { return item.kind == 17 && !item.disabled; });
|
||||
check(menu17 != flow.desktop()->state().items.end(), "the desktop still offers the market");
|
||||
flow.click(menu17->x + menu17->width / 2, menu17->y + menu17->height / 2);
|
||||
const auto marked = flow.click(20, list_y); // marking a roster player first asks for the value preview
|
||||
if (marked.request == FlowRequest::submenu_action)
|
||||
check(app::serve_flow_request(flow, marked, session, data, data, 0x1789abcd, revision, playback, audio_session, false,
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, {},
|
||||
app::HumanBuyerMarketEntryPolicy::normal_interactive).empty(), "the roster preview is served");
|
||||
const auto review_request = flow.click(200, 207);
|
||||
check(review_request.request == FlowRequest::submenu_action &&
|
||||
std::holds_alternative<TransferMarketRequest>(review_request.submenu_action) &&
|
||||
std::get<TransferMarketRequest>(review_request.submenu_action).kind == TransferMarketRequestKind::review_offers,
|
||||
"an already listed player opens the review of his offers");
|
||||
int offers_shown = 0;
|
||||
HumanBuyerSaleHooks hooks;
|
||||
hooks.allocator_gate = HumanBuyerSaleAllocatorGate::zero;
|
||||
hooks.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase;
|
||||
hooks.notice = [](const GameState&, const HumanBuyerSaleNotice&) {};
|
||||
const app::TransferOfferPresenter review = [&](const GameState&, const TransferOfferListView& view) {
|
||||
offers_shown = view.offer_count;
|
||||
return 0; // accept the first bid
|
||||
};
|
||||
const auto error = app::serve_flow_request(flow, review_request, session, data, data, 0x1789abcd,
|
||||
revision, playback, audio_session, false, {}, review, {}, {}, {}, {}, {}, {}, {},
|
||||
app::PendingOfferEntryPolicy::legacy_unpresented, hooks, app::HumanBuyerMarketEntryPolicy::normal_interactive);
|
||||
check(error.empty() && offers_shown > 0, "the review presents the offers");
|
||||
check((game.squad_slots.at(0xb70 + size_t(entry)) & 0xfff) != listed_player && !flow.pending_transfer_market(),
|
||||
"accepting a bid in the review sells the player and settles the request");
|
||||
}
|
||||
|
||||
{ // a declined listing: at expiry the player leaves the list (the seller declines every offer) and can be listed again
|
||||
const auto before = transfer_market_from_game(game, revision);
|
||||
int row2 = -1;
|
||||
for (int row = std::min(17, int(before.squad.size()) - 1); row >= 11 && row2 < 0; --row) {
|
||||
const auto& player = before.squad[size_t(row)];
|
||||
if (player.player < 0 || player.already_listed || player.row == listing_row) continue;
|
||||
auto trial_state = game; auto trial_rand = session->rand(); MinuteReport trial_report;
|
||||
if (list_manager_player(trial_state, before.manager_slot, player.row, trial_rand, trial_report).status ==
|
||||
TransferActionStatus::accepted && !trial_report.unsupported) row2 = player.row;
|
||||
}
|
||||
check(row2 >= 0, "another listable reserve player exists");
|
||||
MinuteReport report;
|
||||
const auto listed = list_manager_player(game, before.manager_slot, row2, session->rand(), report);
|
||||
check(listed.status == TransferActionStatus::accepted && listed.list_entry >= 0, "the second player is listed");
|
||||
const int entry = listed.list_entry;
|
||||
const uint32_t list = ::bmh::layout::EditorList + uint32_t(entry) * 0x58;
|
||||
for (int tries = 0; tries < 400 && int16_t(game.memory.u16(list)) == -1; ++tries)
|
||||
transfer_bid(game, 0xb70 + entry, list, false, -1, session->game(), session->rand(), report);
|
||||
check(int16_t(game.memory.u16(list)) != -1, "a bid arrives on the second listing");
|
||||
game.memory.set8(list + 0x56, 1); // expires with this countdown
|
||||
int declined = 0;
|
||||
game.transfer_offer_selector = [&](const GameState&, const TransferOfferListView&) { ++declined; return -1; };
|
||||
transfer_list_countdown(game, session->game(), session->rand(), report, false, TransferAllocatorContext::zero);
|
||||
game.transfer_offer_selector = {};
|
||||
check(!report.unsupported && declined > 0, "the seller was asked and declined");
|
||||
check((game.squad_slots.at(0xb70 + size_t(entry)) & 0xfff) == 0xfff, "after the decline the player has left the transfer list");
|
||||
|
||||
const auto fresh = transfer_market_from_game(game, revision);
|
||||
int y2 = -1, line = 36;
|
||||
for (size_t n = 0; n < fresh.roster.players.size(); ++n) {
|
||||
const auto& player = fresh.roster.players[n];
|
||||
if (player.borrowed) continue;
|
||||
if (n && (player.displayed_slot & 0xc000) != (fresh.roster.players[n-1].displayed_slot & 0xc000)) line += 2;
|
||||
if (player.player_id < 0) continue;
|
||||
if (player.physical_row == row2) { y2 = line - 3; break; }
|
||||
line += 7;
|
||||
}
|
||||
check(y2 >= 29 && y2 < 215, "the declined player is visible in the roster");
|
||||
flow.send_key("ESC");
|
||||
flow.attach_preparation_context(session->preparation_projection(revision));
|
||||
const auto menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(),
|
||||
[](const DeskItem& item) { return item.kind == 17 && !item.disabled; });
|
||||
check(menu != flow.desktop()->state().items.end(), "the desktop offers the market again");
|
||||
flow.click(menu->x + menu->width / 2, menu->y + menu->height / 2);
|
||||
HumanBuyerSaleHooks relist_hooks;
|
||||
relist_hooks.allocator_gate = HumanBuyerSaleAllocatorGate::zero;
|
||||
relist_hooks.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase;
|
||||
relist_hooks.notice = [](const GameState&, const HumanBuyerSaleNotice&) {};
|
||||
const auto serve_relist = [&](const FlowResult& result) {
|
||||
return app::serve_flow_request(flow, result, session, data, data, 0x1789abcd, revision, playback, audio_session, false,
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, relist_hooks,
|
||||
app::HumanBuyerMarketEntryPolicy::normal_interactive);
|
||||
};
|
||||
const auto marked_again = flow.click(20, y2);
|
||||
if (marked_again.request == FlowRequest::submenu_action) check(serve_relist(marked_again).empty(), "the roster preview is served");
|
||||
const auto relist = flow.click(200, 207);
|
||||
check(relist.request == FlowRequest::submenu_action && std::holds_alternative<TransferMarketRequest>(relist.submenu_action) &&
|
||||
std::get<TransferMarketRequest>(relist.submenu_action).kind == TransferMarketRequestKind::list_player,
|
||||
"a player who left the list after a decline can be listed again from the roster");
|
||||
check(serve_relist(relist).empty(), "the second listing is served");
|
||||
bool listed_again = false;
|
||||
for (int e = 0; e < 40; ++e) listed_again |= (game.squad_slots.at(0xb70 + size_t(e)) & 0xfff) ==
|
||||
(game.squad_slots.at(squad_range(before.runtime_club).first + size_t(row2)) & 0xfff);
|
||||
check(listed_again, "the declined player stands on the transfer list again");
|
||||
|
||||
// VERKAUFEN on a listed player asks "Wollen Sie ... vom Transfermarkt holen?"; no keeps the listing, yes takes him off
|
||||
const auto player_id = game.squad_slots.at(squad_range(before.runtime_club).first + size_t(row2)) & 0xfff;
|
||||
const auto on_list = [&] {
|
||||
for (int e = 0; e < 40; ++e) if ((game.squad_slots.at(0xb70 + size_t(e)) & 0xfff) == player_id) return true;
|
||||
return false;
|
||||
};
|
||||
std::string asked;
|
||||
bool answer = false;
|
||||
relist_hooks.confirm = [&](const GameState&, int, const std::string& text) { asked = text; return answer; };
|
||||
for (const bool yes : {false, true}) {
|
||||
answer = yes; asked.clear();
|
||||
auto selected = FlowResult{};
|
||||
auto sell_again = flow.click(200, 207); // after a "no" the player is still selected
|
||||
if (sell_again.request != FlowRequest::submenu_action) {
|
||||
selected = flow.click(20, y2);
|
||||
if (selected.request == FlowRequest::submenu_action) check(serve_relist(selected).empty(), "the listed player's preview is served");
|
||||
sell_again = flow.click(200, 207);
|
||||
}
|
||||
check(sell_again.request == FlowRequest::submenu_action && std::holds_alternative<TransferMarketRequest>(sell_again.submenu_action) &&
|
||||
std::get<TransferMarketRequest>(sell_again.submenu_action).kind == TransferMarketRequestKind::review_offers &&
|
||||
std::get<TransferMarketRequest>(sell_again.submenu_action).ask_withdraw,
|
||||
"selling a listed player starts the withdraw question even without offers");
|
||||
const app::TransferOfferPresenter no_bid = [](const GameState&, const TransferOfferListView&) { return -1; };
|
||||
check(app::serve_flow_request(flow, sell_again, session, data, data, 0x1789abcd, revision, playback, audio_session, false,
|
||||
{}, no_bid, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, relist_hooks,
|
||||
app::HumanBuyerMarketEntryPolicy::normal_interactive).empty(), "the withdraw question is served");
|
||||
check(!asked.empty(), "the question 'vom Transfermarkt holen' was asked");
|
||||
check(on_list() == !yes, yes ? "answering yes takes the player off the transfer list" : "answering no keeps the player on the list");
|
||||
}
|
||||
}
|
||||
|
||||
{ // the search dialog behind the buttons Suchen and Vorschlag (Source sub_19409)
|
||||
flow.send_key("ESC");
|
||||
flow.attach_preparation_context(session->preparation_projection(revision));
|
||||
const auto menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(),
|
||||
[](const DeskItem& item) { return item.kind == 17 && !item.disabled; });
|
||||
check(menu != flow.desktop()->state().items.end(), "the desktop offers the market for the search dialog");
|
||||
flow.click(menu->x + menu->width / 2, menu->y + menu->height / 2);
|
||||
const auto exe = load_le(asset_path(data, "BMH.exe"));
|
||||
const auto button_at = [&](int n) {
|
||||
return std::pair<int, int>{exe.u16(::bmh::layout::TransferMarket_Click_RuntimeField + uint32_t(n) * 6) + 2,
|
||||
exe.u16(::bmh::layout::TransferMarket_Click_RuntimeField2 + uint32_t(n) * 6) + 2};
|
||||
};
|
||||
HumanBuyerSaleHooks hooks;
|
||||
hooks.allocator_gate = HumanBuyerSaleAllocatorGate::zero;
|
||||
hooks.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase;
|
||||
std::vector<std::string> boxes;
|
||||
// Like the graphical client, every notice is turned into its dialog (an unknown notice there refuses the whole action).
|
||||
hooks.notice = [&](const GameState& state, const HumanBuyerSaleNotice& notice) {
|
||||
(void)pending_offer_notice_dialog(state, PendingOfferNotice{notice.manager, notice.raw_offer_slot,
|
||||
notice.source_text_address, notice.original_message});
|
||||
boxes.push_back(notice.original_message);
|
||||
};
|
||||
// All notices the transfer routes can raise have a dialog (the poached player's agreement and the scouting boxes included).
|
||||
for (const uint32_t address : {::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_TextPointer,
|
||||
::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_RuntimeField,
|
||||
::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_ExecutableField,
|
||||
::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField,
|
||||
::bmh::layout::DeskActions_Unsupported_ExecutableField, ::bmh::layout::DeskActions_Unsupported_ExecutableField2,
|
||||
::bmh::layout::DeskActions_Unsupported_ExecutableField3, ::bmh::layout::DeskActions_Unsupported_TextPointer3,
|
||||
::bmh::layout::Month_SearchProfileNews_TextPointer3, ::bmh::layout::Month_SearchProfileNews_TextPointer4})
|
||||
(void)pending_offer_notice_dialog(game, PendingOfferNotice{initial.manager_slot, -1, address, "x"});
|
||||
const auto serve_search = [&](const FlowResult& result) {
|
||||
return app::serve_flow_request(flow, result, session, data, data, 0x1789abcd, revision, playback, audio_session, false,
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, hooks,
|
||||
app::HumanBuyerMarketEntryPolicy::normal_interactive);
|
||||
};
|
||||
const int manager = initial.manager_slot;
|
||||
// Suchen: opens locally with the stored profile (the career starts with an inactive one: every value 1)
|
||||
const auto [search_x, search_y] = button_at(1);
|
||||
check(flow.click(search_x, search_y).request == FlowRequest::none &&
|
||||
flow.state_json().find("\"search_open\":true") != std::string::npos, "Suchen opens the dialog without a request");
|
||||
check(flow.state_json().find("\"search_edit\":[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]") != std::string::npos,
|
||||
"the dialog shows the stored profile (a new career: off bit, otherwise all 1) without its off bit");
|
||||
flow.click(272, 25); // switch the midfielder cell off (row y 25, 25 px cells)
|
||||
flow.click(316, 42); // age slider: the upper end to the right edge
|
||||
flow.click(316, 58); // strength slider: the upper end to 99
|
||||
check(flow.render().width == 320, "the market with the open search dialog renders");
|
||||
flow.move_action(200, 100); // the pointer moves under an open dialog are ignored
|
||||
const auto confirm = flow.click(285, 145); // the confirm button
|
||||
check(confirm.request == FlowRequest::submenu_action && std::holds_alternative<TransferMarketRequest>(confirm.submenu_action) &&
|
||||
std::get<TransferMarketRequest>(confirm.submenu_action).kind == TransferMarketRequestKind::store_search_profile,
|
||||
"the confirm button posts the profile");
|
||||
const auto& stored_request = std::get<TransferMarketRequest>(confirm.submenu_action);
|
||||
check(stored_request.search_apply && !stored_request.search_cancelled && stored_request.search_profile[2] == 0 &&
|
||||
stored_request.search_profile[5] == 24 && stored_request.search_profile[7] == 99,
|
||||
"the posted profile carries the edits");
|
||||
const uint64_t before_store = revision;
|
||||
check(serve_search(confirm).empty(), "the profile is stored by the production controller");
|
||||
const auto stored = search_profile(game, manager);
|
||||
check(revision == before_store + 1 && !(stored[0] & kSearchProfileOff) && stored[2] == 0 && stored[5] == 24 && stored[7] == 99,
|
||||
"the stored profile is active and has the edits");
|
||||
check(boxes.size() == search_profile_hits(game, manager).size() + 1 && boxes.size() > 1,
|
||||
"the scouting department reports first, then every listing that fits gets its message box");
|
||||
check(flow.state_json().find("\"search_open\":false") != std::string::npos && !flow.pending_transfer_market(),
|
||||
"the dialog is closed and the request settled");
|
||||
// Vorschlag opens with the profile the squad asks for; leaving by right click keeps it but switches the search off
|
||||
const auto [suggest_x, suggest_y] = button_at(2);
|
||||
check(flow.click(suggest_x, suggest_y).request == FlowRequest::none &&
|
||||
flow.state_json().find("\"search_open\":true") != std::string::npos, "Vorschlag opens the dialog");
|
||||
const auto expected = suggest_search_profile(game, manager, false);
|
||||
std::string expected_json = "\"search_edit\":[";
|
||||
for (size_t i = 0; i < expected.size(); ++i) expected_json += (i ? "," : "") + std::to_string(i == 0 ? expected[i] & 0x3f : expected[i]);
|
||||
check(flow.state_json().find(expected_json) != std::string::npos, "the dialog shows the suggestion of the squad");
|
||||
boxes.clear();
|
||||
const auto leave = flow.click(100, 100, true);
|
||||
check(leave.request == FlowRequest::submenu_action &&
|
||||
std::get<TransferMarketRequest>(leave.submenu_action).search_cancelled &&
|
||||
!std::get<TransferMarketRequest>(leave.submenu_action).search_apply, "the right button posts a cancelled profile");
|
||||
check(serve_search(leave).empty(), "the cancelled profile is stored");
|
||||
const auto switched_off = search_profile(game, manager);
|
||||
check((switched_off[0] & kSearchProfileOff) && switched_off[1] == expected[1] && boxes.empty(),
|
||||
"the suggestion is kept, switched off, and nothing is announced");
|
||||
}
|
||||
|
||||
// The old KB23 editor/legacy heuristic is no longer the ordinary GUI route.
|
||||
// Keep its controller capability checks on real Source KB31 events, with
|
||||
// the Core owner as the integration reference (not an independent EXE oracle).
|
||||
@@ -7266,6 +7489,9 @@ int main(int argc, char** argv) {
|
||||
if(argc==3 && std::string_view(argv[2])=="--live-intervention-only") {
|
||||
check_live_observer_determinism(data); return 0;
|
||||
}
|
||||
if(argc==3 && std::string_view(argv[2])=="--market-only") {
|
||||
check_transfer_market_controller(data);return 0;
|
||||
}
|
||||
if(argc==3 && std::string_view(argv[2])=="--poach-only") {
|
||||
check_poach_ui_components(data);return 0;
|
||||
}
|
||||
|
||||
@@ -1420,6 +1420,16 @@ void coverage_tests(const std::filesystem::path& data, const std::filesystem::pa
|
||||
block({"SellPlayer(row:19)", "BuyPlayer(" + id + ")", "ShowNegotiation", "SetOfferField(Fee, 100000)",
|
||||
"SetOfferField(Salary, 20000)", "ShowTeamInfo", "ShowPlayerInfo", "SubmitOffer", "GoBack", "GoBack"});
|
||||
}
|
||||
{
|
||||
// the search profile (buttons SUCHEN and VORSCHLAG): the suggestion, storing a profile, a refused value
|
||||
check(contains(block({"Key(M)", "SuggestSearchProfile"}), "profile active"), "coverage: the suggestion is a profile");
|
||||
block({"SetSearchProfile([1,1,0,0,0,24,0,99,0,0,0,0,0,0,0,0,0,0], false)", "ShowSearchProfile"});
|
||||
check(contains(block({"SetSearchProfile([1,1,1,1,0,24,0,99,0,0,0,0,0,0,0,0,0,0])"}), "search profile stored"),
|
||||
"coverage: a profile is stored");
|
||||
check(contains(block({"SetSearchProfile([2,1,1,1,0,24,0,99,0,0,0,0,0,0,0,0,0,0])"}, true), "E_BAD_ARGUMENT"),
|
||||
"coverage: a switch above 1 is refused");
|
||||
block({"GoBack"});
|
||||
}
|
||||
block({"Key(T)", "ShowTable(0)", "OpenTeamInfo(club:0)", "ShowTeamSquad", "ShowPlayer(row:0)", "CloseTeamInfo", "ShowTable(1)", "GoBack",
|
||||
"Open(HighScore)", "ShowHighScore", "GoBack", "Open(TopScorers)", "ShowScorers(Assists, League)", "SetList(Score)", "SetScope(Managers)", "GoBack", "Open(Fixtures)", "NextMatchday", "GoBack", "OpenMailbox", "ListMessages", "GoBack"});
|
||||
block({"Open(SaveGame)", "Save(COVER)", "GoBack"});
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The game without BMH.exe and FLTD.EXE (formats/diamond_image.*): the images built from the embedded numbers and texts
|
||||
// of the Diamond 3.7 executable and of the English Football Limited. Usage: diamond_image_tests [<BMH data dir> | -] [<openbmh.dat>]
|
||||
// (with a data directory the embedded German image is also compared byte for byte with its BMH.exe).
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "formats/diamond_image.hpp"
|
||||
#include "formats/le.hpp"
|
||||
|
||||
using namespace bmh;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t kImageStart = 0x10000, kMinimumSize = 0xB0000; // where the image begins and its least size
|
||||
int failures = 0;
|
||||
void require(bool ok, const char* what) {
|
||||
if (!ok) { std::cerr << "FAIL: " << what << "\n"; ++failures; }
|
||||
}
|
||||
|
||||
bool contains_text(const LeImage& image, const std::string& text) {
|
||||
const auto& b = image.bytes();
|
||||
return std::search(b.begin(), b.end(), text.begin(), text.end()) != b.end();
|
||||
}
|
||||
|
||||
// Without the texts file the images hold the numbers only; with it (argv[2], data/openbmh.dat) they also hold the texts.
|
||||
void german(const Bytes& dat) {
|
||||
LeImage image = diamond_constants_image();
|
||||
require(image.size() > kMinimumSize && image.base() == kImageStart, "the German image has the layout of the Diamond data object");
|
||||
// the letter tables of the cup draw and fixtures are numbers of the image
|
||||
require(contains_text(image, "abcdefghijklmnopqrst"), "the fixture letter tables are embedded");
|
||||
if (dat.empty()) return;
|
||||
require(apply_texts(image, 1, dat), "openbmh.dat has the German texts");
|
||||
require(contains_text(image, "DER LINIENRICHTER HAT DIE FAHNE OBEN"), "the German texts come from openbmh.dat");
|
||||
}
|
||||
|
||||
void english(const Bytes& dat) {
|
||||
LeImage image = english_constants_image();
|
||||
require(image.base() == kImageStart && image.size() > kMinimumSize, "the English image lies in the German address space");
|
||||
if (dat.empty()) return;
|
||||
require(apply_texts(image, 2, dat), "openbmh.dat has the English texts");
|
||||
require(contains_text(image, "Competition closed"), "the English texts come from openbmh.dat");
|
||||
}
|
||||
|
||||
void damaged_file(const Bytes& dat) {
|
||||
LeImage image = diamond_constants_image();
|
||||
bool threw = false;
|
||||
try { apply_texts(image, 1, Bytes{'n', 'o', 't', ' ', 'a', ' ', 'f', 'i', 'l', 'e', ' ', ' ', ' ', ' ', ' ', ' '}); } catch (const FormatError&) { threw = true; }
|
||||
require(threw, "a file without the magic is refused");
|
||||
if (dat.size() < 40) return;
|
||||
Bytes cut(dat.begin(), dat.begin() + 40);
|
||||
threw = false;
|
||||
try { apply_texts(image, 1, cut); } catch (const FormatError&) { threw = true; }
|
||||
require(threw, "a truncated file is refused");
|
||||
// a range that is not a text of the game cannot be written: the file never changes a number of the image
|
||||
Bytes bad = dat;
|
||||
for (size_t at = 12 + 4 + 8; at < 12 + 4 + 12; ++at) bad[at] ^= 0x55; // the address of the first German range
|
||||
threw = false;
|
||||
try { apply_texts(image, 1, bad); } catch (const FormatError&) { threw = true; }
|
||||
require(threw, "a range that is no text range is refused");
|
||||
}
|
||||
void missing_executable() {
|
||||
// a BMH.exe that is not there stands for the embedded German image
|
||||
const fs::path nowhere = fs::temp_directory_path() / "openbmh-no-such-directory" / "BMH.exe";
|
||||
const LeImage loaded = load_le(nowhere);
|
||||
const LeImage embedded = diamond_constants_image();
|
||||
require(loaded.bytes() == embedded.bytes() && loaded.base() == embedded.base(), "a missing BMH.exe loads the embedded image");
|
||||
require(is_executable_name("bmh.EXE") && !is_executable_name("TEXTD.BLK"), "is_executable_name");
|
||||
}
|
||||
|
||||
void against_real_executable(const fs::path& directory) {
|
||||
fs::path exe;
|
||||
for (const auto& entry : fs::directory_iterator(directory))
|
||||
if (is_executable_name(entry.path().filename())) exe = entry.path();
|
||||
if (exe.empty()) return;
|
||||
const LeImage real = load_le(exe);
|
||||
const LeImage embedded = diamond_constants_image();
|
||||
// the embedded image is the Diamond 3.7 data object: every byte of it that is not zero equals the executable
|
||||
if (real.size() != embedded.size()) { std::cout << "(the executable is not Diamond 3.7: embedded numbers not compared)\n"; return; }
|
||||
size_t compared = 0, different = 0;
|
||||
for (uint32_t i = 0; i < embedded.size(); ++i) {
|
||||
const uint8_t value = embedded.bytes()[i];
|
||||
if (!value) continue;
|
||||
++compared;
|
||||
if (real.bytes()[i] != value) ++different;
|
||||
}
|
||||
if (different) std::cout << "(the executable differs from the embedded Diamond 3.7 in " << different << " of " << compared << " bytes)\n";
|
||||
else std::cout << "all " << compared << " embedded bytes equal BMH.exe\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
Bytes dat;
|
||||
if (argc > 2) dat = read_file(argv[2]);
|
||||
german(dat);
|
||||
english(dat);
|
||||
damaged_file(dat);
|
||||
missing_executable();
|
||||
if (argc > 1 && std::string_view(argv[1]) != "-") against_real_executable(argv[1]);
|
||||
if (failures) return 1;
|
||||
std::cout << "PASS embedded German and English images\n";
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "FAIL: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ struct OrdinaryInput {
|
||||
if ((candidate.squad_slots.at(0xb70u + size_t(entry)) & 0xfff) != player ||
|
||||
(candidate.memory.u16(at + 8) & 0x7fff) != team || candidate.memory.u16(at) != 0xffff)
|
||||
continue;
|
||||
const uint32_t fee_base = (candidate.memory.u32(at + 0x2c) / 10000u) * 0x30d4u;
|
||||
const uint32_t fee_base = (candidate.memory.u32(at + 0x2c) / 10000u) * 10000u;
|
||||
const uint32_t salary_base = ((100u * candidate.memory.u32(at + 0x30)) / 10000u) * 100u;
|
||||
const uint32_t cash = read32(candidate.manager_records, 0x314);
|
||||
if (!fee_base || !salary_base || fee_base > cash / 3 || salary_base > 0x3fffffffu) continue;
|
||||
|
||||
@@ -1059,7 +1059,7 @@ int main(int argc,char** argv) try {
|
||||
const uint32_t list=c.request.list_address;
|
||||
TransferBidRequest bid;bid.manager=c.buyer_manager;bid.list_entry=c.request.list_entry;
|
||||
bid.player=c.player;bid.source_slot=int(c.request.source_pool_slot);bid.contract_years=2;bid.loan=true;
|
||||
const uint32_t fee_base=(g.memory.u32(list+0x2c)/10000u)*0x30d4u;
|
||||
const uint32_t fee_base=(g.memory.u32(list+0x2c)/10000u)*10000u;
|
||||
const uint32_t salary_base=((120u*g.memory.u32(list+0x30))/10000u)*100u;
|
||||
bid.fee=int32_t(fee_base*2u);bid.annual_salary=int32_t(salary_base*2u);
|
||||
for(size_t n=0;n<7;++n)bid.bonuses[n]=uint32_t(n+3);
|
||||
|
||||
@@ -44,7 +44,7 @@ struct ControlInput {
|
||||
"real seller listing helper");
|
||||
const uint32_t ordinary=::bmh::layout::EditorList+uint32_t(listing.list_entry)*0x58;
|
||||
TransferBidRequest bid;bid.manager=1;bid.list_entry=listing.list_entry;bid.player=listing.player;
|
||||
bid.fee=int32_t((state.memory.u32(ordinary+0x2c)/10000u)*0x30d4u);
|
||||
bid.fee=int32_t((state.memory.u32(ordinary+0x2c)/10000u)*10000u);
|
||||
bid.annual_salary=int32_t(((100u*state.memory.u32(ordinary+0x30))/10000u)*200u);
|
||||
bid.contract_years=1;
|
||||
check(submit_transfer_bid(state,bid,helper).status==TransferActionStatus::pending,
|
||||
|
||||
@@ -453,7 +453,7 @@ Control make_control(GameState& g,int free_row=-1,bool buyer_full=false,bool sal
|
||||
c.player=listing.player;c.seller_row=player_row(g,c.seller,c.player);
|
||||
check(c.seller_row>=0,"listed player remains in a concrete seller row");
|
||||
const uint32_t ordinary=::bmh::layout::EditorList+uint32_t(listing.list_entry)*0x58;
|
||||
const uint32_t fee_base=(g.memory.u32(ordinary+0x2c)/10000)*0x30d4;
|
||||
const uint32_t fee_base=(g.memory.u32(ordinary+0x2c)/10000)*10000;
|
||||
const uint32_t salary_base=((100u*g.memory.u32(ordinary+0x30))/10000)*100;
|
||||
TransferBidRequest bid;bid.manager=1;bid.list_entry=listing.list_entry;bid.player=listing.player;
|
||||
bid.fee=int32_t(fee_base);bid.annual_salary=int32_t(salary_base*2);bid.contract_years=1;
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "miniz.h"
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace bmh::launch;
|
||||
|
||||
namespace {
|
||||
void set_environment(const char* name, const char* value) {
|
||||
#ifdef _WIN32
|
||||
_putenv_s(name, value);
|
||||
#else
|
||||
if (*value) setenv(name, value, 1); else unsetenv(name);
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
const std::string unicode = "Unit-Ä-测试 folder/archive.zip";
|
||||
if (path_to_utf8(path_from_utf8(unicode)) != unicode)
|
||||
@@ -36,7 +49,28 @@ int main() try {
|
||||
const auto read = archive.read(0);
|
||||
if (std::string(read.begin(), read.end()) != payload) throw std::runtime_error("ZIP payload mismatch");
|
||||
std::filesystem::remove(path);
|
||||
std::cout << "Synthetic ZIP and Unicode path checks passed\n";
|
||||
|
||||
// A game folder is either BMH.EXE + assets or openbmh.dat + assets; without both the launcher asks for an executable.
|
||||
// (synthetic empty files: only the choice of the way is checked, not the game data)
|
||||
const auto folder = std::filesystem::temp_directory_path() /
|
||||
("openbmh-unit-game-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
std::filesystem::create_directories(folder / "KB");
|
||||
for (const char* name : {"TEXTD.BLK", "M3D.MAN"}) std::ofstream(folder / name).put('x');
|
||||
set_environment("OPENBMH_DAT", "-"); // no texts file anywhere (the program folder of the test may hold one)
|
||||
const auto without_dat = check_game_directory(folder);
|
||||
const auto mentions_dat = [](const GameCheck& c) {
|
||||
for (const auto& problem : c.problems) if (problem.find("openbmh.dat") != std::string::npos) return true;
|
||||
return false;
|
||||
};
|
||||
if (without_dat.playable || !mentions_dat(without_dat))
|
||||
throw std::runtime_error("assets without BMH.EXE and without openbmh.dat must ask for an executable");
|
||||
set_environment("OPENBMH_DAT", "");
|
||||
std::ofstream(folder / "openbmh.dat").put('x');
|
||||
const auto with_dat = check_game_directory(folder);
|
||||
if (with_dat.family != GameFamily::german || mentions_dat(with_dat))
|
||||
throw std::runtime_error("assets with openbmh.dat are a game without executable");
|
||||
std::filesystem::remove_all(folder);
|
||||
std::cout << "Synthetic ZIP, Unicode path and game folder checks passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
|
||||
@@ -23,7 +23,7 @@ class PackageAllowlistTests(unittest.TestCase):
|
||||
root = Path(directory)
|
||||
# Empty authored placeholders test names/structure, not executable behavior.
|
||||
for name in ['OpenBMH', 'openbmh_cli', 'README.md', 'LICENSE',
|
||||
'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md']:
|
||||
'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md', 'openbmh.dat']:
|
||||
(root / name).write_text('synthetic')
|
||||
notes = root / 'docs/release/1.0/RELEASE_NOTES.md'
|
||||
notes.parent.mkdir(parents=True)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Search profile of a human manager (game/search_profile.*): the closing rule of the dialog and the
|
||||
// matching of a transfer-list entry. The engine was also compared with the original routines sub_190B5 /
|
||||
// sub_18F06 of the Diamond 3.7 executable on whole savegames (private emulator harness, not part of this test).
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/search_profile.hpp"
|
||||
|
||||
using namespace bmh;
|
||||
|
||||
namespace {
|
||||
void require(bool value, const char* message) { if (!value) throw std::runtime_error(message); }
|
||||
|
||||
// Manager 0 manages club 3; one listing of a defender of club 5 (age field 6, price byte 0x5a = class 1).
|
||||
GameState fixture() {
|
||||
GameState g;
|
||||
g.manager_teams = {3};
|
||||
g.manager_records.resize(0xb0c);
|
||||
g.squad_slots.assign(3072, 0xfff);
|
||||
g.squad_slots[0xb70] = 0;
|
||||
g.players.resize(1);
|
||||
g.players[0].name = "Listed";
|
||||
g.players[0].w35c = 70u << 14 | 70u << 7 | 70u;
|
||||
g.players[0].w364 = 6u << 21 | 1u; // age field 6, position 1 (defender)
|
||||
g.memory.add_block(layout::EditorList, 44 * 0x58);
|
||||
g.memory.set16(layout::EditorList + 8, 5);
|
||||
g.memory.set8(layout::EditorList + 0x54, 0x5a);
|
||||
return g;
|
||||
}
|
||||
|
||||
SearchProfile open_profile() {
|
||||
SearchProfile p{};
|
||||
p[4] = 0; p[5] = 24; p[6] = 0; p[7] = 99;
|
||||
return p;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
{ // a fresh manager has no active profile
|
||||
auto g = fixture();
|
||||
g.manager_records[kSearchProfileOffset] = kSearchProfileOff;
|
||||
require(!search_profile_matches(g, 0, 0), "an inactive profile matches nothing");
|
||||
}
|
||||
{ // an open profile for defenders matches the listing, one for goalkeepers only does not
|
||||
auto g = fixture();
|
||||
auto p = open_profile(); p[1] = 1;
|
||||
require(set_search_profile(g, 0, p, false) && search_profile(g, 0) == p, "profile with a position is stored active");
|
||||
require(search_profile_matches(g, 0, 0), "defender profile matches the defender");
|
||||
p[1] = 0; p[0] = 1;
|
||||
require(set_search_profile(g, 0, p, false) && !search_profile_matches(g, 0, 0), "goalkeeper profile does not match");
|
||||
require(!search_profile_matches(g, 0, 1), "an empty list slot never matches");
|
||||
}
|
||||
{ // the dialog's closing rule
|
||||
auto g = fixture();
|
||||
SearchProfile zero{};
|
||||
require(!set_search_profile(g, 0, zero, false) && (search_profile(g, 0)[0] & kSearchProfileOff), "all zero switches the profile off");
|
||||
SearchProfile ones; ones.fill(1);
|
||||
require(!set_search_profile(g, 0, ones, false) && (search_profile(g, 0)[0] & kSearchProfileOff), "all one switches the profile off");
|
||||
auto p = open_profile(); p[2] = 1;
|
||||
require(!set_search_profile(g, 0, p, true) && (search_profile(g, 0)[0] & kSearchProfileOff), "leaving by right click switches the profile off");
|
||||
require(search_profile(g, 0)[2] == 1, "the edited values are kept when the dialog is cancelled");
|
||||
auto bad = p; bad[9] = 2;
|
||||
const auto before = search_profile(g, 0);
|
||||
require(!set_search_profile(g, 0, bad, false) && search_profile(g, 0) == before, "a switch above 1 is refused and nothing is stored");
|
||||
bad = p; bad[5] = 25;
|
||||
require(!set_search_profile(g, 0, bad, false), "the age bar has 25 cells");
|
||||
require(!set_search_profile(g, 5, p, false), "an invalid manager is refused");
|
||||
}
|
||||
{ // age and price class
|
||||
auto g = fixture();
|
||||
auto p = open_profile(); p[1] = 1; p[4] = 10; p[5] = 20;
|
||||
require(set_search_profile(g, 0, p, false) && !search_profile_matches(g, 0, 0), "age field 6 is outside 10..20");
|
||||
p[4] = 2; p[5] = 8; p[15] = 1; // only the cheapest price class wanted, the listing asks 90 % (class 1)
|
||||
require(set_search_profile(g, 0, p, false) && !search_profile_matches(g, 0, 0), "price class 1 is above the wanted class 0");
|
||||
p[16] = 1;
|
||||
require(set_search_profile(g, 0, p, false) && search_profile_matches(g, 0, 0), "price class 1 is wanted");
|
||||
}
|
||||
{ // the own club's listings never match
|
||||
auto g = fixture();
|
||||
g.memory.set16(layout::EditorList + 8, 3);
|
||||
auto p = open_profile(); p[1] = 1;
|
||||
require(set_search_profile(g, 0, p, false) && !search_profile_matches(g, 0, 0), "an own listing never matches");
|
||||
}
|
||||
std::cout << "PASS search profile closing rule and matching\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; }
|
||||
@@ -271,7 +271,10 @@ bool replay_matchday(GameState& b, std::vector<MatchGroup>& groups, GameRandom&
|
||||
MatchEngine trial{sc, gc, gg, wr, engine.referees};
|
||||
trial.month = engine.month;
|
||||
MinuteReport tr;
|
||||
trial.rerate_team(team, tr);
|
||||
{
|
||||
NoHook no_hook; // (the trial draws on copies: they must not count as draws of the port)
|
||||
trial.rerate_team(team, tr);
|
||||
}
|
||||
const bool hit = !tr.unsupported && gg.seed() == int32_t(std::stoll(field(after.line, "game_seed"))) &&
|
||||
wr.seed() == uint32_t(std::stoull(field(after.line, "rand_seed")));
|
||||
if (!hit) continue;
|
||||
@@ -1054,10 +1057,11 @@ const Entry* desk = &pause; // (after an offer message box the next pause)
|
||||
GameRandom gp = bg;
|
||||
WatcomRandom wp = br;
|
||||
bool g_ahead = false, w_ahead = false;
|
||||
long g_steps = 0, w_steps = 0; // draws the snapshot lies ahead of our state (reported below)
|
||||
for (long k = 0; k < 20000 && !g_ahead; k++, gp.range(0, 1))
|
||||
g_ahead = gp.seed() == int32_t(std::stoll(field(e.line, "game_seed")));
|
||||
g_ahead = gp.seed() == int32_t(std::stoll(field(e.line, "game_seed"))), g_steps = k;
|
||||
for (long k = 0; k < 20000 && !w_ahead; k++, wp.rand())
|
||||
w_ahead = wp.seed() == uint32_t(std::stoull(field(e.line, "rand_seed")));
|
||||
w_ahead = wp.seed() == uint32_t(std::stoull(field(e.line, "rand_seed"))), w_steps = k;
|
||||
if (!w_ahead) {
|
||||
// (a Watcom seed on no path of the stream: the snapshot caught a temporary generator
|
||||
// state, as with minute snapshots - not counted)
|
||||
@@ -1082,7 +1086,8 @@ const Entry* desk = &pause; // (after an offer message box the next pause)
|
||||
}
|
||||
}
|
||||
if (!g_ahead || !w_ahead) return false;
|
||||
std::printf(" (late snapshot: taken inside the processing of day %u, not counted)\n", b.date);
|
||||
std::printf(" (late snapshot: taken inside the processing of day %u, %ld game and %ld Watcom draws ahead of the "
|
||||
"port's state, both on the port's streams; not counted)\n", b.date, g_steps, w_steps);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
Vendored
+239
@@ -0,0 +1,239 @@
|
||||
## Changelog
|
||||
|
||||
### 3.0.2
|
||||
|
||||
- Fix buffer overrun in mz_utf8z_to_widechar on Windows
|
||||
|
||||
### 3.0.1
|
||||
|
||||
- Fix compilation error with MINIZ_USE_UNALIGNED_LOADS_AND_STORES=1
|
||||
|
||||
### 3.0.0
|
||||
|
||||
- Reduce memory usage for inflate. This changes `struct tinfl_decompressor_tag` and therefore requires a major version bump (breaks ABI compatibility)
|
||||
- Add padding to structures so it continues to work if features differ. This also changes some structures
|
||||
- Use _ftelli64, _fseeki64 and stat with MinGW32 and OpenWatcom
|
||||
- Fix varios warnings with OpenWatcom compiler
|
||||
- Avoid using unaligned memory access in UBSan builds
|
||||
- Set MINIZ_LITTLE_ENDIAN only if not set
|
||||
- Add MINIZ_NO_DEFLATE_APIS and MINIZ_NO_INFLATE_APIS
|
||||
- Fix use of uninitialized memory in tinfl_decompress_mem_to_callback()
|
||||
- Use wfopen on windows
|
||||
- Use _wstat64 instead _stat64 on windows
|
||||
- Use level_and_flags after MZ_DEFAULT_COMPRESSION has been handled
|
||||
- Improve endianess detection
|
||||
- Don't use unaligned stores and loads per default
|
||||
- Fix function declaration if MINIZ_NO_STDIO is used
|
||||
- Fix MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 not being set
|
||||
- Remove total files check (its 32-bit uint)
|
||||
- tinfl_decompress: avoid NULL ptr arithmetic UB
|
||||
- miniz_zip: fix mz_zip_reader_extract_to_heap to read correct sizes
|
||||
- Eliminate 64-bit operations on 32-bit machines
|
||||
- Disable treating warnings as error with MSVC
|
||||
- Disable building shared lib via CMake by default
|
||||
- Fixed alignment problems on MacOS
|
||||
- Fixed get error string for MZ_ZIP_TOTAL_ERRORS
|
||||
- Write correct FLEVEL 2-bit value in zlib header
|
||||
- miniz.pc.in: fix include path not containing the "miniz" suffix
|
||||
- Fix compatibility with FreeBSD
|
||||
- pkg-config tweaks
|
||||
- Fix integer overflow in header corruption check
|
||||
- Fix some warnings
|
||||
- tdefl_compress_normal: Avoid NULL ptr arithmetic UB
|
||||
- replace use of stdint.h types with mz_ variants
|
||||
|
||||
|
||||
### 2.2.0
|
||||
|
||||
- Fix examples with amalgamation
|
||||
- Modified cmake script to support shared library mode and find_package
|
||||
- Fix for misleading doc comment on `mz_zip_reader_init_cfile` function
|
||||
- Add include location tolerance and stop forcing `_GNU_SOURCE`
|
||||
- Fix: mz_zip_reader_locate_file_v2 returns an mz_bool
|
||||
- Fix large file system checks
|
||||
- Add #elif to enable an external mz_crc32() to be linked in
|
||||
- Write with dynamic size (size of file/data to be added not known before adding)
|
||||
- Added uncompress2 for zlib compatibility
|
||||
- Add support for building as a Meson subproject
|
||||
- Added OSSFuzz support; Integrate with CIFuzz
|
||||
- Add pkg-config file
|
||||
- Fixed use-of-uninitialized value msan error when copying dist bytes with no output bytes written.
|
||||
- mz_zip_validate_file(): fix memory leak on errors
|
||||
- Fixed MSAN use-of-uninitialized in tinfl_decompress when invalid dist is decoded. In this instance dist was 31 which s_dist_base translates as 0
|
||||
- Add flag to set (compressed) size in local file header
|
||||
- avoid use of uninitialized value in tdefl_record_literal
|
||||
|
||||
### 2.1.0
|
||||
|
||||
- More instances of memcpy instead of cast and use memcpy per default
|
||||
- Remove inline for c90 support
|
||||
- New function to read files via callback functions when adding them
|
||||
- Fix out of bounds read while reading Zip64 extended information
|
||||
- guard memcpy when n == 0 because buffer may be NULL
|
||||
- Implement inflateReset() function
|
||||
- Move comp/decomp alloc/free prototypes under guarding #ifndef MZ_NO_MALLOC
|
||||
- Fix large file support under Windows
|
||||
- Don't warn if _LARGEFILE64_SOURCE is not defined to 1
|
||||
- Fixes for MSVC warnings
|
||||
- Remove check that path of file added to archive contains ':' or '\'
|
||||
- Add !defined check on MINIZ_USE_ALIGNED_LOADS_AND_STORES
|
||||
|
||||
### 2.0.8
|
||||
|
||||
- Remove unimplemented functions (mz_zip_locate_file and mz_zip_locate_file_v2)
|
||||
- Add license, changelog, readme and example files to release zip
|
||||
- Fix heap overflow to user buffer in tinfl_status tinfl_decompress
|
||||
- Fix corrupt archive if uncompressed file smaller than 4 byte and the file is added by mz_zip_writer_add_mem*
|
||||
|
||||
### 2.0.7
|
||||
|
||||
- Removed need in C++ compiler in cmake build
|
||||
- Fixed a lot of uninitialized value errors found with Valgrind by memsetting m_dict to 0 in tdefl_init
|
||||
- Fix resource leak in mz_zip_reader_init_file_v2
|
||||
- Fix assert with mz_zip_writer_add_mem* w/MZ_DEFAULT_COMPRESSION
|
||||
- cmake build: install library and headers
|
||||
- Remove _LARGEFILE64_SOURCE requirement from apple defines for large files
|
||||
|
||||
### 2.0.6
|
||||
|
||||
- Improve MZ_ZIP_FLAG_WRITE_ZIP64 documentation
|
||||
- Remove check for cur_archive_file_ofs > UINT_MAX because cur_archive_file_ofs is not used after this point
|
||||
- Add cmake debug configuration
|
||||
- Fix PNG height when creating png files
|
||||
- Add "iterative" file extraction method based on mz_zip_reader_extract_to_callback.
|
||||
- Option to use memcpy for unaligned data access
|
||||
- Define processor/arch macros as zero if not set to one
|
||||
|
||||
### 2.0.4/2.0.5
|
||||
|
||||
- Fix compilation with the various omission compile definitions
|
||||
|
||||
### 2.0.3
|
||||
|
||||
- Fix GCC/clang compile warnings
|
||||
- Added callback for periodic flushes (for ZIP file streaming)
|
||||
- Use UTF-8 for file names in ZIP files per default
|
||||
|
||||
### 2.0.2
|
||||
|
||||
- Fix source backwards compatibility with 1.x
|
||||
- Fix a ZIP bit not being set correctly
|
||||
|
||||
### 2.0.1
|
||||
|
||||
- Added some tests
|
||||
- Added CI
|
||||
- Make source code ANSI C compatible
|
||||
|
||||
### 2.0.0 beta
|
||||
|
||||
- Matthew Sitton merged miniz 1.x to Rich Geldreich's vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed
|
||||
- Miniz is now split into several files
|
||||
- Miniz does now not seek backwards when creating ZIP files. That is the ZIP files can be streamed
|
||||
- Miniz automatically switches to the ZIP64 format when the created ZIP files goes over ZIP file limits
|
||||
- Similar to [SQLite](https://www.sqlite.org/amalgamation.html) the Miniz source code is amalgamated into one miniz.c/miniz.h pair in a build step (amalgamate.sh). Please use miniz.c/miniz.h in your projects
|
||||
- Miniz 2 is only source back-compatible with miniz 1.x. It breaks binary compatibility because structures changed
|
||||
|
||||
### v1.16 BETA Oct 19, 2013
|
||||
|
||||
Still testing, this release is downloadable from [here](http://www.tenacioussoftware.com/miniz_v116_beta_r1.7z). Two key inflator-only robustness and streaming related changes. Also merged in tdefl_compressor_alloc(), tdefl_compressor_free() helpers to make script bindings easier for rustyzip. I would greatly appreciate any help with testing or any feedback.
|
||||
|
||||
The inflator in raw (non-zlib) mode is now usable on gzip or similar streams that have a bunch of bytes following the raw deflate data (problem discovered by rustyzip author williamw520). This version should never read beyond the last byte of the raw deflate data independent of how many bytes you pass into the input buffer.
|
||||
|
||||
The inflator now has a new failure status TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS (-4). Previously, if the inflator was starved of bytes and could not make progress (because the input buffer was empty and the caller did not set the TINFL_FLAG_HAS_MORE_INPUT flag - say on truncated or corrupted compressed data stream) it would append all 0's to the input and try to soldier on. This is scary behavior if the caller didn't know when to stop accepting output (because it didn't know how much uncompressed data was expected, or didn't enforce a sane maximum). v1.16 will instead return TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS immediately if it needs 1 or more bytes to make progress, the input buf is empty, and the caller has indicated that no more input is available. This is a "soft" failure, so you can call the inflator again with more input and it will try to continue, or you can give up and fail. This could be very useful in network streaming scenarios.
|
||||
|
||||
- The inflator coroutine func. is subtle and complex so I'm being cautious about this release. I would greatly appreciate any help with testing or any feedback.
|
||||
I feel good about these changes, and they've been through several hours of automated testing, but they will probably not fix anything for the majority of prev. users so I'm
|
||||
going to mark this release as beta for a few weeks and continue testing it at work/home on various things.
|
||||
- The inflator in raw (non-zlib) mode is now usable on gzip or similar data streams that have a bunch of bytes following the raw deflate data (problem discovered by rustyzip author williamw520).
|
||||
This version should *never* read beyond the last byte of the raw deflate data independent of how many bytes you pass into the input buffer. This issue was caused by the various Huffman bitbuffer lookahead optimizations, and
|
||||
would not be an issue if the caller knew and enforced the precise size of the raw compressed data *or* if the compressed data was in zlib format (i.e. always followed by the byte aligned zlib adler32).
|
||||
So in other words, you can now call the inflator on deflate streams that are followed by arbitrary amounts of data and it's guaranteed that decompression will stop exactly on the last byte.
|
||||
- The inflator now has a new failure status: TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS (-4). Previously, if the inflator was starved of bytes and could not make progress (because the input buffer was empty and the
|
||||
caller did not set the TINFL_FLAG_HAS_MORE_INPUT flag - say on truncated or corrupted compressed data stream) it would append all 0's to the input and try to soldier on.
|
||||
This is scary, because in the worst case, I believe it was possible for the prev. inflator to start outputting large amounts of literal data. If the caller didn't know when to stop accepting output
|
||||
(because it didn't know how much uncompressed data was expected, or didn't enforce a sane maximum) it could continue forever. v1.16 cannot fall into this failure mode, instead it'll return
|
||||
TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS immediately if it needs 1 or more bytes to make progress, the input buf is empty, and the caller has indicated that no more input is available. This is a "soft"
|
||||
failure, so you can call the inflator again with more input and it will try to continue, or you can give up and fail. This could be very useful in network streaming scenarios.
|
||||
- Added documentation to all the tinfl return status codes, fixed miniz_tester so it accepts double minus params for Linux, tweaked example1.c, added a simple "follower bytes" test to miniz_tester.cpp.
|
||||
### v1.15 r4 STABLE - Oct 13, 2013
|
||||
|
||||
Merged over a few very minor bug fixes that I fixed in the zip64 branch. This is downloadable from [here](http://code.google.com/p/miniz/downloads/list) and also in SVN head (as of 10/19/13).
|
||||
|
||||
|
||||
### v1.15 - Oct. 13, 2013
|
||||
|
||||
Interim bugfix release while I work on the next major release with zip64 and streaming compression/decompression support. Fixed the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com), which could cause the locate files func to not find files when this flag was specified. Also fixed a bug in mz_zip_reader_extract_to_mem_no_alloc() with user provided read buffers (thanks kymoon). I also merged lots of compiler fixes from various github repo branches and Google Code issue reports. I finally added cmake support (only tested under for Linux so far), compiled and tested with clang v3.3 and gcc 4.6 (under Linux), added defl_write_image_to_png_file_in_memory_ex() (supports Y flipping for OpenGL use, real-time compression), added a new PNG example (example6.c - Mandelbrot), and I added 64-bit file I/O support (stat64(), etc.) for glibc.
|
||||
|
||||
- Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com) which could cause locate files to not find files. This bug
|
||||
would only have occurred in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place()
|
||||
(which used this flag). If you can't switch to v1.15 but want to fix this bug, just remove the uses of this flag from both helper funcs (and of course don't use the flag).
|
||||
- Bugfix in mz_zip_reader_extract_to_mem_no_alloc() from kymoon when pUser_read_buf is not NULL and compressed size is > uncompressed size
|
||||
- Fixing mz_zip_reader_extract_*() funcs so they don't try to extract compressed data from directory entries, to account for weird zipfiles which contain zero-size compressed data on dir entries.
|
||||
Hopefully this fix won't cause any issues on weird zip archives, because it assumes the low 16-bits of zip external attributes are DOS attributes (which I believe they always are in practice).
|
||||
- Fixing mz_zip_reader_is_file_a_directory() so it doesn't check the internal attributes, just the filename and external attributes
|
||||
- mz_zip_reader_init_file() - missing MZ_FCLOSE() call if the seek failed
|
||||
- Added cmake support for Linux builds which builds all the examples, tested with clang v3.3 and gcc v4.6.
|
||||
- Clang fix for tdefl_write_image_to_png_file_in_memory() from toffaletti
|
||||
- Merged MZ_FORCEINLINE fix from hdeanclark
|
||||
- Fix <time.h> include before config #ifdef, thanks emil.brink
|
||||
- Added tdefl_write_image_to_png_file_in_memory_ex(): supports Y flipping (super useful for OpenGL apps), and explicit control over the compression level (so you can
|
||||
set it to 1 for real-time compression).
|
||||
- Merged in some compiler fixes from paulharris's github repro.
|
||||
- Retested this build under Windows (VS 2010, including static analysis), tcc 0.9.26, gcc v4.6 and clang v3.3.
|
||||
- Added example6.c, which dumps an image of the mandelbrot set to a PNG file.
|
||||
- Modified example2 to help test the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY flag more.
|
||||
- In r3: Bugfix to mz_zip_writer_add_file() found during merge: Fix possible src file fclose() leak if alignment bytes+local header file write faiiled
|
||||
- In r4: Minor bugfix to mz_zip_writer_add_from_zip_reader(): Was pushing the wrong central dir header offset, appears harmless in this release, but it became a problem in the zip64 branch
|
||||
|
||||
### v1.14 - May 20, 2012
|
||||
|
||||
(SVN Only) Minor tweaks to get miniz.c compiling with the Tiny C Compiler, added #ifndef MINIZ_NO_TIME guards around utime.h includes. Adding mz_free() function, so the caller can free heap blocks returned by miniz using whatever heap functions it has been configured to use, MSVC specific fixes to use "safe" variants of several functions (localtime_s, fopen_s, freopen_s).
|
||||
|
||||
MinGW32/64 GCC 4.6.1 compiler fixes: added MZ_FORCEINLINE, #include <time.h> (thanks fermtect).
|
||||
|
||||
Compiler specific fixes, some from fermtect. I upgraded to TDM GCC 4.6.1 and now static __forceinline is giving it fits, so I'm changing all usage of __forceinline to MZ_FORCEINLINE and forcing gcc to use __attribute__((__always_inline__)) (and MSVC to use __forceinline). Also various fixes from fermtect for MinGW32: added #include , 64-bit ftell/fseek fixes.
|
||||
|
||||
### v1.13 - May 19, 2012
|
||||
|
||||
From jason@cornsyrup.org and kelwert@mtu.edu - Most importantly, fixed mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bits. Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files. Other stuff:
|
||||
|
||||
Eliminated a bunch of warnings when compiling with GCC 32-bit/64. Ran all examples, miniz.c, and tinfl.c through MSVC 2008's /analyze (static analysis) option and fixed all warnings (except for the silly "Use of the comma-operator in a tested expression.." analysis warning, which I purposely use to work around a MSVC compiler warning).
|
||||
|
||||
Created 32-bit and 64-bit Codeblocks projects/workspace. Built and tested Linux executables. The codeblocks workspace is compatible with Linux+Win32/x64. Added miniz_tester solution/project, which is a useful little app derived from LZHAM's tester app that I use as part of the regression test. Ran miniz.c and tinfl.c through another series of regression testing on ~500,000 files and archives. Modified example5.c so it purposely disables a bunch of high-level functionality (MINIZ_NO_STDIO, etc.). (Thanks to corysama for the MINIZ_NO_STDIO bug report.)
|
||||
|
||||
Fix ftell() usage in a few of the examples so they exit with an error on files which are too large (a limitation of the examples, not miniz itself). Fix fail logic handling in mz_zip_add_mem_to_archive_file_in_place() so it always calls mz_zip_writer_finalize_archive() and mz_zip_writer_end(), even if the file add fails.
|
||||
|
||||
- From jason@cornsyrup.org and kelwert@mtu.edu - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit.
|
||||
- Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files.
|
||||
- Eliminated a bunch of warnings when compiling with GCC 32-bit/64.
|
||||
- Ran all examples, miniz.c, and tinfl.c through MSVC 2008's /analyze (static analysis) option and fixed all warnings (except for the silly
|
||||
"Use of the comma-operator in a tested expression.." analysis warning, which I purposely use to work around a MSVC compiler warning).
|
||||
- Created 32-bit and 64-bit Codeblocks projects/workspace. Built and tested Linux executables. The codeblocks workspace is compatible with Linux+Win32/x64.
|
||||
- Added miniz_tester solution/project, which is a useful little app derived from LZHAM's tester app that I use as part of the regression test.
|
||||
- Ran miniz.c and tinfl.c through another series of regression testing on ~500,000 files and archives.
|
||||
- Modified example5.c so it purposely disables a bunch of high-level functionality (MINIZ_NO_STDIO, etc.). (Thanks to corysama for the MINIZ_NO_STDIO bug report.)
|
||||
- Fix ftell() usage in examples so they exit with an error on files which are too large (a limitation of the examples, not miniz itself).
|
||||
|
||||
### v1.12 - 4/12/12
|
||||
|
||||
More comments, added low-level example5.c, fixed a couple minor level_and_flags issues in the archive API's.
|
||||
level_and_flags can now be set to MZ_DEFAULT_COMPRESSION. Thanks to Bruce Dawson <bruced@valvesoftware.com> for the feedback/bug report.
|
||||
|
||||
### v1.11 - 5/28/11
|
||||
|
||||
Added statement from unlicense.org
|
||||
|
||||
### v1.10 - 5/27/11
|
||||
|
||||
- Substantial compressor optimizations:
|
||||
- Level 1 is now ~4x faster than before. The L1 compressor's throughput now varies between 70-110MB/sec. on a Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86).
|
||||
- Improved baseline L2-L9 compression perf. Also, greatly improved compression perf. issues on some file types.
|
||||
- Refactored the compression code for better readability and maintainability.
|
||||
- Added level 10 compression level (L10 has slightly better ratio than level 9, but could have a potentially large drop in throughput on some files).
|
||||
|
||||
### v1.09 - 5/15/11
|
||||
|
||||
Initial stable release.
|
||||
|
||||
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
Copyright 2013-2014 RAD Game Tools and Valve Software
|
||||
Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
|
||||
|
||||
All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Vendored
+7833
File diff suppressed because it is too large.
Load diff
Vendored
+1422
File diff suppressed because it is too large.
Load diff
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
## Miniz
|
||||
|
||||
Miniz is a lossless, high performance data compression library in a single source file that implements the zlib (RFC 1950) and Deflate (RFC 1951) compressed data format specification standards. It supports the most commonly used functions exported by the zlib library, but is a completely independent implementation so zlib's licensing requirements do not apply. Miniz also contains simple to use functions for writing .PNG format image files and reading/writing/appending .ZIP format archives. Miniz's compression speed has been tuned to be comparable to zlib's, and it also has a specialized real-time compressor function designed to compare well against fastlz/minilzo.
|
||||
|
||||
## Usage
|
||||
|
||||
Releases are available at the [releases page](https://github.com/richgel999/miniz/releases) as a pair of `miniz.c`/`miniz.h` files which can be simply added to a project. To create this file pair the different source and header files are [amalgamated](https://www.sqlite.org/amalgamation.html) during build. Alternatively use as cmake or meson module (or build system of your choice).
|
||||
|
||||
## Features
|
||||
|
||||
* MIT licensed
|
||||
* A portable, single source and header file library written in plain C. Tested with GCC, clang and Visual Studio.
|
||||
* Easily tuned and trimmed down by defines
|
||||
* A drop-in replacement for zlib's most used API's (tested in several open source projects that use zlib, such as libpng and libzip).
|
||||
* Fills a single threaded performance vs. compression ratio gap between several popular real-time compressors and zlib. For example, at level 1, miniz.c compresses around 5-9% better than minilzo, but is approx. 35% slower. At levels 2-9, miniz.c is designed to compare favorably against zlib's ratio and speed. See the miniz performance comparison page for example timings.
|
||||
* Not a block based compressor: miniz.c fully supports stream based processing using a coroutine-style implementation. The zlib-style API functions can be called a single byte at a time if that's all you've got.
|
||||
* Easy to use. The low-level compressor (tdefl) and decompressor (tinfl) have simple state structs which can be saved/restored as needed with simple memcpy's. The low-level codec API's don't use the heap in any way.
|
||||
* Entire inflater (including optional zlib header parsing and Adler-32 checking) is implemented in a single function as a coroutine, which is separately available in a small (~550 line) source file: miniz_tinfl.c
|
||||
* A fairly complete (but totally optional) set of .ZIP archive manipulation and extraction API's. The archive functionality is intended to solve common problems encountered in embedded, mobile, or game development situations. (The archive API's are purposely just powerful enough to write an entire archiver given a bit of additional higher-level logic.)
|
||||
|
||||
## Building miniz - Using vcpkg
|
||||
|
||||
You can download and install miniz using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install miniz
|
||||
|
||||
The miniz port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
## Known Problems
|
||||
|
||||
* No support for encrypted archives. Not sure how useful this stuff is in practice.
|
||||
* Minimal documentation. The assumption is that the user is already familiar with the basic zlib API. I need to write an API wiki - for now I've tried to place key comments before each enum/API, and I've included 6 examples that demonstrate how to use the module's major features.
|
||||
|
||||
## Special Thanks
|
||||
|
||||
Thanks to Alex Evans for the PNG writer function. Also, thanks to Paul Holden and Thorsten Scheuermann for feedback and testing, Matt Pritchard for all his encouragement, and Sean Barrett's various public domain libraries for inspiration (and encouraging me to write miniz.c in C, which was much more enjoyable and less painful than I thought it would be considering I've been programming in C++ for so long).
|
||||
|
||||
Thanks to Bruce Dawson for reporting a problem with the level_and_flags archive API parameter (which is fixed in v1.12) and general feedback, and Janez Zemva for indirectly encouraging me into writing more examples.
|
||||
|
||||
## Patents
|
||||
|
||||
I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](https://datatracker.ietf.org/doc/html/rfc1951#section-4). Also see the [gzip FAQ](https://web.archive.org/web/20160308045258/http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too.
|
||||
@@ -0,0 +1,134 @@
|
||||
"""Finds the game texts in a German-layout image (a Diamond BMH.exe, or the translated English FLTD.EXE).
|
||||
|
||||
generate.py keeps the numbers of the image in the source files (formats/*_constants.inc) and puts the game texts into
|
||||
the data file openbmh.dat that ships with the release. A range counts as text when it is
|
||||
|
||||
* a NUL terminated string that a pointer variable of the data object (or of the English data segment) points to, or
|
||||
* a string that a 32 bit immediate of the code points to (a "push offset text"), or
|
||||
* a long printable run with a space (a sentence), or
|
||||
* a string the program read as a string while a trace was recorded (OPENBMH_LE_TRACE, kind 2).
|
||||
|
||||
Letter permutation tables of the cup draw ('abcdefghijklmnopqr', all letters different) and file names are numbers /
|
||||
names, not texts, and stay in the constants. Used by generate.py.
|
||||
"""
|
||||
import re
|
||||
import struct
|
||||
|
||||
PRINTABLE = set(range(0x20, 0x7F))
|
||||
UMLAUTS = {0x84, 0x94, 0x81, 0x8E, 0x99, 0x9A, 0xE1} # CP437 letters seen in character sets
|
||||
TEXT_BYTES = PRINTABLE | UMLAUTS
|
||||
FILE_NAME = re.compile(r"[A-Za-z0-9_./\\*?-]*[./\\][A-Za-z0-9_./\\*?-]*")
|
||||
|
||||
|
||||
def string_end(data, base, start):
|
||||
"""Address after the NUL of the string starting at `start`, or None when it is not a clean string."""
|
||||
i = start - base
|
||||
n = 0
|
||||
while i < len(data) and data[i] != 0:
|
||||
if data[i] not in TEXT_BYTES and data[i] < 0x20:
|
||||
return None
|
||||
i += 1
|
||||
n += 1
|
||||
if n > 400:
|
||||
return None
|
||||
return i + 1 + base if i < len(data) else None
|
||||
|
||||
|
||||
def is_permutation(text):
|
||||
letters = text.lower()
|
||||
return letters.isalpha() and len(set(letters)) == len(letters) and len(letters) in (4, 6, 10, 12, 16, 18, 20)
|
||||
|
||||
|
||||
def ascending(text, n=4):
|
||||
"""True when the text holds n or more ascending consecutive characters (a character set 'abcdef', not a word)."""
|
||||
run = 1
|
||||
for a, b in zip(text, text[1:]):
|
||||
run = run + 1 if ord(b) == ord(a) + 1 else 1
|
||||
if run >= n:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def is_text(text):
|
||||
if not re.search(r"[A-Za-z]{3}", text) or is_permutation(text) or text.startswith(("f\\", "Ã")) or FILE_NAME.fullmatch(text):
|
||||
return False
|
||||
# a single token in one case is a name or a table fragment (BLASTER, KRON_FBM, V3.7, 'njpmd' from a fixture row), not a
|
||||
# sentence or a label of the game; letter and character-set tables are not texts either
|
||||
if " " not in text and (text.isupper() or text.islower() or re.fullmatch(r"[A-Z][A-Za-z0-9_.]*\d[A-Za-z0-9_.]*", text)):
|
||||
return False
|
||||
if ascending(text) or sum(c.isalpha() or c == " " for c in text) < 0.6 * len(text):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def text_ranges(data, base, targets, sources, code, layout_pointers, traced_strings):
|
||||
"""data: the image bytes at address `base`. targets: [(lo, hi)] where texts may lie, sources: [(lo, hi)] where
|
||||
pointer variables lie, code: [(lo, hi)] where immediates are searched. Returns sorted (start, length) incl. the NUL."""
|
||||
found = {}
|
||||
|
||||
def in_targets(address):
|
||||
return any(lo <= address < hi for lo, hi in targets)
|
||||
|
||||
def add(start, end):
|
||||
if in_targets(start) and end > start:
|
||||
found[start] = max(found.get(start, 0), end - start)
|
||||
|
||||
def text_at(value):
|
||||
end = string_end(data, base, value)
|
||||
if end and end - value >= 4:
|
||||
text = bytes(data[value - base:end - 1 - base]).decode("latin1")
|
||||
if is_text(text):
|
||||
return end
|
||||
return None
|
||||
|
||||
# 1. strings that pointer variables point to
|
||||
for lo, hi in sources:
|
||||
for at in range(lo, hi - 3, 4):
|
||||
value = struct.unpack_from("<I", data, at - base)[0]
|
||||
if in_targets(value) and value != at:
|
||||
end = text_at(value)
|
||||
if end:
|
||||
add(value, end)
|
||||
for pointer in layout_pointers:
|
||||
if pointer - base < 0 or pointer - base + 4 > len(data):
|
||||
continue
|
||||
value = struct.unpack_from("<I", data, pointer - base)[0]
|
||||
if in_targets(value):
|
||||
end = string_end(data, base, value)
|
||||
if end:
|
||||
add(value, end)
|
||||
# 1b. strings the code points to: after the fixups a "push offset text" holds the address as a 32 bit immediate
|
||||
for lo, hi in code:
|
||||
for at in range(lo, hi - 3):
|
||||
value = struct.unpack_from("<I", data, at - base)[0]
|
||||
if in_targets(value) and data[value - 1 - base] == 0:
|
||||
end = text_at(value)
|
||||
if end:
|
||||
add(value, end)
|
||||
# 2. long printable runs with a space (sentences)
|
||||
for lo, hi in targets:
|
||||
i = lo - base
|
||||
while i < hi - base:
|
||||
if data[i] in PRINTABLE:
|
||||
j = i
|
||||
while j < hi - base and data[j] in TEXT_BYTES:
|
||||
j += 1
|
||||
text = bytes(data[i:j]).decode("latin1")
|
||||
if j - i >= 8 and " " in text and re.search(r"[A-Za-z]{3}", text):
|
||||
add(i + base, j + base + (1 if j < len(data) and data[j] == 0 else 0))
|
||||
i = j
|
||||
else:
|
||||
i += 1
|
||||
# 3. strings the program read while a trace was recorded
|
||||
for start, length in traced_strings:
|
||||
text = bytes(data[start - base:start - base + max(length - 1, 0)]).decode("latin1")
|
||||
if is_text(text):
|
||||
add(start, start + length)
|
||||
merged = []
|
||||
for start in sorted(found):
|
||||
end = start + found[start]
|
||||
if merged and start <= merged[-1][1]:
|
||||
merged[-1][1] = max(merged[-1][1], end)
|
||||
else:
|
||||
merged.append([start, end])
|
||||
return [(s, e - s) for s, e in merged]
|
||||
@@ -0,0 +1,265 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generates the embedded game data of OpenBMH, so that the game runs from the asset files alone (no BMH.exe, no
|
||||
FLTD.EXE): src/formats/diamond_constants.inc (German, Diamond 3.7) and src/formats/fltd_constants.inc (English
|
||||
Football Limited) hold every non-zero byte of the numbers the engine reads - tables, rates, positions, prices - as runs of
|
||||
bytes; zero runs are not stored. The game texts (live commentary, messages) are NOT in the source: they go into the data
|
||||
file data/openbmh.dat that ships with the release (formats/diamond_image.hpp); the .inc files only list where they are.
|
||||
After regenerating, put the new SHA-256 of data/openbmh.dat into REVIEWED_BINARY_FILES of tools/public_release/check_public_tree.py.
|
||||
|
||||
German (a Diamond 3.7 BMH.exe, read here and never copied into the repository):
|
||||
python generate.py german --exe BMH.exe --trace trace1.txt [--trace trace2.txt ...] --out ../../src/formats/diamond_constants.inc
|
||||
The file backed part of the data object, plus the few bytes of the code object that the program reads as numbers or
|
||||
tables (instruction immediates such as the calendar setup). The code bytes come from the read traces of OPENBMH_LE_TRACE
|
||||
(formats/le.hpp: run the data dependent tests and scenarios with the variable set to a file; the lines are
|
||||
"<flag> <start> <length>" in hex, flag 1 = number read, 2 = string read, 4 = start of a bulk read) and from a window
|
||||
at every layout constant that names a place in the code objects.
|
||||
|
||||
English (the German layout image of FLTD.EXE, the cached "BMH.exe" of an English game that translate_fltd() made):
|
||||
python generate.py english --image BMH.exe --out ../../src/formats/fltd_constants.inc
|
||||
Every non-zero byte of the image.
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import struct
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
import classify # noqa: E402
|
||||
|
||||
DATA_LO, DATA_PAGES = 0xA0000, 12 # the initialised pages of the data object (file backed)
|
||||
DATA_HI = DATA_LO + DATA_PAGES * 4096
|
||||
CODE = (0x10000, 0x10000 + 438272)
|
||||
PATCH = (0x80000, 0x81000)
|
||||
EN_LO, EN_HI = 0x6B000, 0x776A8 # the English data segment, also placed at its own addresses
|
||||
|
||||
|
||||
def load_le(path):
|
||||
"""The loaded image of a DOS/4GW LE executable (objects at their link addresses, internal fixups applied)."""
|
||||
raw = Path(path).read_bytes()
|
||||
u16 = lambda o: struct.unpack_from("<H", raw, o)[0]
|
||||
u32 = lambda o: struct.unpack_from("<I", raw, o)[0]
|
||||
le = u32(0x3C)
|
||||
if u16(le) != 0x454C:
|
||||
raise SystemExit("no LE header")
|
||||
h = lambda off: u32(le + off)
|
||||
pages, page_size, last_page = h(0x14), h(0x28), h(0x2C)
|
||||
object_table, page_map = le + h(0x40), le + h(0x48)
|
||||
fixup_pages, fixup_records = le + h(0x68), le + h(0x6C)
|
||||
objects, data_pages = h(0x44), h(0x80)
|
||||
obj, lo, hi = [], 0xFFFFFFFF, 0
|
||||
for i in range(objects):
|
||||
o = object_table + i * 24
|
||||
ob = (u32(o), u32(o + 4), u32(o + 8), u32(o + 12), u32(o + 16)) # vsize, base, flags, page index, pages
|
||||
obj.append(ob)
|
||||
span = max(ob[0], ob[4] * page_size)
|
||||
lo, hi = min(lo, ob[1]), max(hi, ob[1] + (span + page_size - 1) // page_size * page_size)
|
||||
data = bytearray(hi - lo)
|
||||
page_address = [0] * (pages + 1)
|
||||
for vsize, base, flags, index, count in obj:
|
||||
for p in range(count):
|
||||
logical = index + p
|
||||
e = page_map + (logical - 1) * 4
|
||||
file_page = raw[e] << 16 | raw[e + 1] << 8 | raw[e + 2]
|
||||
va = base + p * page_size
|
||||
if logical <= pages:
|
||||
page_address[logical] = va
|
||||
if raw[e + 3] != 0:
|
||||
continue
|
||||
size = last_page if file_page == pages else page_size
|
||||
src = data_pages + (file_page - 1) * page_size
|
||||
size = min(size, len(raw) - src)
|
||||
data[va - lo:va - lo + size] = raw[src:src + size]
|
||||
|
||||
def put(pos, fmt, v):
|
||||
struct.pack_into(fmt, data, pos, v & ((1 << (8 * struct.calcsize(fmt))) - 1))
|
||||
|
||||
for pg in range(1, pages + 1):
|
||||
r = fixup_records + u32(fixup_pages + (pg - 1) * 4)
|
||||
end = fixup_records + u32(fixup_pages + pg * 4)
|
||||
while r < end:
|
||||
src, flags = raw[r], raw[r + 1]
|
||||
r += 2
|
||||
ftype, is_list = src & 0x0F, bool(src & 0x20)
|
||||
count, source_offset = 1, 0
|
||||
if is_list:
|
||||
count = raw[r]; r += 1
|
||||
else:
|
||||
source_offset = struct.unpack_from("<h", raw, r)[0]; r += 2
|
||||
if flags & 3:
|
||||
raise SystemExit("external fixup")
|
||||
if flags & 0x40:
|
||||
target_object = u16(r); r += 2
|
||||
else:
|
||||
target_object = raw[r]; r += 1
|
||||
target_offset = 0
|
||||
if ftype != 0x02:
|
||||
if flags & 0x10:
|
||||
target_offset = u32(r); r += 4
|
||||
else:
|
||||
target_offset = u16(r); r += 2
|
||||
offsets = []
|
||||
if is_list:
|
||||
for _ in range(count):
|
||||
offsets.append(struct.unpack_from("<h", raw, r)[0]); r += 2
|
||||
else:
|
||||
offsets.append(source_offset)
|
||||
target = obj[target_object - 1][1] + target_offset
|
||||
for so in offsets:
|
||||
sa = page_address[pg] + so
|
||||
pos = sa - lo
|
||||
if pos < 0 or pos + 4 > len(data):
|
||||
continue
|
||||
if ftype == 0x07: put(pos, "<I", target)
|
||||
elif ftype == 0x08: put(pos, "<I", target - (sa + 4))
|
||||
elif ftype == 0x05: put(pos, "<H", target)
|
||||
elif ftype == 0x02: put(pos, "<H", target_object)
|
||||
elif ftype == 0x06: put(pos, "<I", target); put(pos + 4, "<H", target_object)
|
||||
return lo, data
|
||||
|
||||
|
||||
def load_openbmh_image(path):
|
||||
raw = Path(path).read_bytes()
|
||||
if raw[:14] != b"OPENBMH-IMAGE\0":
|
||||
raise SystemExit("not an OPENBMH-IMAGE file")
|
||||
base, size = struct.unpack_from("<II", raw, 14)
|
||||
data = raw[22:]
|
||||
if len(data) != size:
|
||||
raise SystemExit("OPENBMH-IMAGE: wrong size")
|
||||
return base, bytearray(data)
|
||||
|
||||
|
||||
def read_traces(paths):
|
||||
numbers, bulk = [], []
|
||||
for path in paths:
|
||||
for line in Path(path).read_text().splitlines():
|
||||
flag, start, length = (int(x, 16) for x in line.split())
|
||||
if flag == 1:
|
||||
numbers.append((start, length))
|
||||
elif flag == 4:
|
||||
bulk.append((start, length))
|
||||
return numbers, bulk
|
||||
|
||||
|
||||
def read_string_traces(paths):
|
||||
out = []
|
||||
for path in paths:
|
||||
for line in Path(path).read_text().splitlines():
|
||||
flag, start, length = (int(x, 16) for x in line.split())
|
||||
if flag == 2:
|
||||
out.append((start, length))
|
||||
return out
|
||||
|
||||
|
||||
def merge(ranges, gap=0):
|
||||
out = []
|
||||
for start, end in sorted((s, s + l) for s, l in ranges):
|
||||
if out and start <= out[-1][1] + gap:
|
||||
out[-1][1] = max(out[-1][1], end)
|
||||
else:
|
||||
out.append([start, end])
|
||||
return out
|
||||
|
||||
|
||||
def nonzero_runs(data, base, lo, hi, gap=8):
|
||||
"""[start, end) runs that hold every non-zero byte of lo..hi; zero gaps up to `gap` bytes stay inside a run."""
|
||||
runs, cur = [], None
|
||||
for address in range(lo, hi):
|
||||
if data[address - base]:
|
||||
if cur and address - cur[1] <= gap:
|
||||
cur[1] = address + 1
|
||||
else:
|
||||
cur = [address, address + 1]
|
||||
runs.append(cur)
|
||||
return runs
|
||||
|
||||
|
||||
def write_inc(path, title, base, data, chunks, texts):
|
||||
out = ["// SPDX-License-Identifier: GPL-3.0-only",
|
||||
f"// Generated by tools/diamond_constants/generate.py from {title} - do not edit.",
|
||||
"// Every non-zero byte of the numbers the engine reads (tables, rates, positions, prices) as runs; the game texts",
|
||||
"// are not part of it: kTextRanges lists where they lie, their bytes come from openbmh.dat.",
|
||||
"// Included inside a namespace by formats/diamond_image.cpp.",
|
||||
f"inline constexpr uint32_t kImageBase = {base}, kImageSize = {len(data)};"]
|
||||
total = 0
|
||||
for i, (start, end) in enumerate(chunks):
|
||||
body = data[start - base:end - base]
|
||||
total += len(body)
|
||||
rows = [", ".join(f"0x{b:02X}" for b in body[k:k + 24]) for k in range(0, len(body), 24)]
|
||||
out.append(f"inline constexpr uint8_t kChunk{i}[] = {{\n " + ",\n ".join(rows) + "};")
|
||||
out.append("inline constexpr Chunk kChunks[] = {")
|
||||
for i, (start, end) in enumerate(chunks):
|
||||
out.append(f" {{{start}, {end - start}, kChunk{i}}},")
|
||||
out.append("};")
|
||||
out.append("inline constexpr Range kTextRanges[] = {")
|
||||
for start, length in texts:
|
||||
out.append(f" {{{start}, {length}}},")
|
||||
out.append("};")
|
||||
Path(path).write_text("\n".join(out) + "\n")
|
||||
print(f"{path}: {len(chunks)} chunks, {total} bytes of numbers; {len(texts)} text ranges, {sum(l for _, l in texts)} bytes of text")
|
||||
|
||||
|
||||
def zeroed(data, base, texts):
|
||||
out = bytearray(data)
|
||||
for start, length in texts:
|
||||
out[start - base:start - base + length] = bytes(length)
|
||||
return out
|
||||
|
||||
|
||||
def dat_set(edition, data, base, texts):
|
||||
out = struct.pack("<II", edition, len(texts))
|
||||
for start, length in texts:
|
||||
out += struct.pack("<II", start, length)
|
||||
for start, length in texts:
|
||||
out += bytes(data[start - base:start - base + length])
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--exe", required=True, help="a Diamond 3.7 BMH.exe")
|
||||
ap.add_argument("--english-image", required=True, help="the cached German layout image of FLTD.EXE (OPENBMH-IMAGE)")
|
||||
ap.add_argument("--trace", action="append", default=[])
|
||||
ap.add_argument("--layout", default=str(Path(__file__).parents[2] / "src/formats/executable_layout.hpp"))
|
||||
ap.add_argument("--out-dir", required=True, help="src/formats")
|
||||
ap.add_argument("--dat", required=True, help="data/openbmh.dat")
|
||||
args = ap.parse_args()
|
||||
layout = Path(args.layout).read_text()
|
||||
out_dir = Path(args.out_dir)
|
||||
|
||||
# German (Diamond 3.7)
|
||||
base, data = load_le(args.exe)
|
||||
numbers_read, bulk = read_traces(args.trace)
|
||||
strings_read = [(s, l) for s, l in read_string_traces(args.trace) if DATA_LO <= s < DATA_HI]
|
||||
pointers = [int(a, 16) for n, a in re.findall(r"inline constexpr auto (\w*TextPointer\w*) = 0x([0-9a-fA-F]+);", layout)]
|
||||
texts_de = classify.text_ranges(data, base, [(DATA_LO, DATA_HI)], [(DATA_LO, DATA_HI)], [CODE, PATCH], pointers, strings_read)
|
||||
wanted = []
|
||||
for s, l in numbers_read:
|
||||
if CODE[0] <= s < CODE[1] or PATCH[0] <= s < PATCH[1]:
|
||||
wanted.append((max(s - 4, 0), l + 8))
|
||||
for s, l in bulk:
|
||||
if CODE[0] <= s < CODE[1] or PATCH[0] <= s < PATCH[1]:
|
||||
wanted.append((s, 256))
|
||||
for name, address in re.findall(r"inline constexpr auto (\w+) = 0x([0-9a-fA-F]+);", layout):
|
||||
a = int(address, 16)
|
||||
if CODE[0] <= a < CODE[1] or PATCH[0] <= a < PATCH[1]:
|
||||
wanted.append((a, 16))
|
||||
numbers_de = zeroed(data, base, texts_de)
|
||||
chunks_de = sorted(nonzero_runs(numbers_de, base, DATA_LO, DATA_HI) + merge(wanted, 16))
|
||||
write_inc(out_dir / "diamond_constants.inc", "BMH 2026-27 Diamond edition 3.7", base, numbers_de, chunks_de, texts_de)
|
||||
|
||||
# English (Football Limited, in the German address space)
|
||||
ebase, edata = load_openbmh_image(args.english_image)
|
||||
en_segment = (EN_LO, EN_HI)
|
||||
texts_en = classify.text_ranges(edata, ebase, [(DATA_LO, DATA_HI), en_segment], [(DATA_LO, DATA_HI), en_segment], [], [], [])
|
||||
numbers_en = zeroed(edata, ebase, texts_en)
|
||||
write_inc(out_dir / "fltd_constants.inc", "the German layout image of FLTD.EXE (Football Limited)", ebase, numbers_en,
|
||||
nonzero_runs(numbers_en, ebase, ebase, ebase + len(edata)), texts_en)
|
||||
|
||||
blob = b"OPENBMH-DAT\0" + struct.pack("<I", 2) + dat_set(1, data, base, texts_de) + dat_set(2, edata, ebase, texts_en)
|
||||
Path(args.dat).write_bytes(blob)
|
||||
print(f"{args.dat}: {len(blob)} bytes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loaded 100 of 102 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user