Team premiums and the manager confirmation show pressed buttons

The back, send and switch buttons below the contract offer and team premium
panels and JA/NEIN of the manager confirmation are drawn pressed while the
mouse button is held, using the shared frame of ui/button_frame.hpp.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-11-08 17:49:57 +01:00
1 parent fb72de3895
commit b6bc17a381
7 files changed
+67 -15

No files matched your search

+7 -2
View File
@@ -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) {
+29 -10
View File
@@ -4,6 +4,7 @@
// 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/button_frame.hpp"
#include "ui/game_end.hpp"
#include <algorithm>
@@ -469,14 +470,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,8 +543,8 @@ 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.
@@ -586,7 +585,27 @@ 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::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;
}
}
const bool changed = id != pressed_button_;
pressed_button_ = id;
return changed;
}
bool ContractsScreen::click(int x, int y, bool right) {
pressed_button_ = -1; // the release ends the pressed look
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;
+3
View File
@@ -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,7 @@ 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
LeImage exe_;
Font font_;
Font large_font_;
+14 -2
View File
@@ -201,7 +201,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) {
@@ -399,8 +411,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;
}
+3
View File
@@ -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_;
+10 -1
View File
@@ -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};
+1
View File
@@ -1092,6 +1092,7 @@ bool StartupFlow::press_hold(int x,int y) {
if (lineup_) return lineup_->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);
return false;
}