Fix unframed desktop date and folder input (by Codex)

This commit is contained in:
Codex committed 2026-11-02 16:14:11 +01:00
1 parent 9c10a2bfeb
commit 8b1dc16233
4 files changed
+191 -67

No files matched your search

+12 -10
View File
@@ -5744,19 +5744,20 @@ bool CareerSession::dispatch_desktop_layout(const ui::DeskRequest& request, uint
(expected[at+13]&0x7f)!=folder||expected[at+12]>=50) {
error="invalid_desk_folder_child_return"; return false;
}
bool owner_open=false;
bool owner_visible=false;
for(size_t item=1;item<kItems;++item) {
if(expected[item*kStride+12]!=50+folder||(expected[item*kStride+13]&0x80)==0) continue;
// The frame bit does not hide folder contents; require a visible linked owner.
if(expected[item*kStride+12]!=50+folder||(expected[item*kStride+1]&0x10)!=0) continue;
int cursor=0;size_t visited=0;
while(++visited<kItems) {
const int next=expected[size_t(cursor)*kStride+5];
if(next==int(item)) { owner_open=true;break; }
if(next==int(item)) { owner_visible=true;break; }
if(next<=0||next>=int(kItems)) break;
cursor=next;
}
if(owner_open) break;
if(owner_visible) break;
}
if(!owner_open) { error="desk_folder_child_owner_closed"; return false; }
if(!owner_visible) { error="desk_folder_child_owner_hidden"; return false; }
const int max_x=std::max(1,319-int(expected[at+3])),max_y=std::max(1,239-int(expected[at+4]));
const int source_x=int(moved_x&0xefff);
const bool snap=g_.memory.has(::bmh::layout::CareerSession_DispatchDesktopLayout_RuntimeField2)&&g_.memory.u8(::bmh::layout::CareerSession_DispatchDesktopLayout_RuntimeField2)==0;
@@ -5797,19 +5798,20 @@ bool CareerSession::dispatch_desktop_layout(const ui::DeskRequest& request, uint
(expected[at+13]&0x7f)!=folder||expected[at+12]>=50) {
error="invalid_desk_bin_restore";return false;
}
bool owner_open=false;
bool owner_visible=false;
for(size_t item=1;item<kItems;++item) {
if(expected[item*kStride+12]!=50+folder||(expected[item*kStride+13]&0x80)==0) continue;
// The frame bit does not hide folder contents; require a visible linked owner.
if(expected[item*kStride+12]!=50+folder||(expected[item*kStride+1]&0x10)!=0) continue;
int cursor=0;size_t visited=0;
while(++visited<kItems) {
const int next=expected[size_t(cursor)*kStride+5];
if(next==int(item)) { owner_open=true;break; }
if(next==int(item)) { owner_visible=true;break; }
if(next<=0||next>=int(kItems)) break;
cursor=next;
}
if(owner_open)break;
if(owner_visible)break;
}
if(!owner_open) { error="desk_bin_restore_folder_closed";return false; }
if(!owner_visible) { error="desk_bin_restore_folder_hidden";return false; }
int tail=0;size_t guard=0;
while(expected[size_t(tail)*kStride+5]!=0) {
if(++guard>=kItems) { error="invalid_desk_layout_chain";return false; }
+8 -3
View File
@@ -309,8 +309,12 @@ std::optional<DeskItem> DesktopScreen::folder_child_at(int x,int y) const {
const int inset = folder.kind >= 50 && !folder.open ? 8 : 0;
if (x < folder.x || y < folder.y || x >= folder.x + folder.width - inset ||
y >= folder.y + folder.height - inset) continue;
if(folder.disabled||folder.kind<50||folder.kind>52||!folder.open) return std::nullopt;
const int folder_id=folder.kind-50,left=folder.x+9,top=folder.y+8,right=folder.x+folder.width-4,bottom=folder.y+folder.height-4;
if(folder.disabled||folder.kind<50||folder.kind>52) return std::nullopt;
// The open bit adds a frame; unframed folders still draw usable tiles.
// Match DeskDrawerRenderer's content origin and wrapping bounds.
const int frame = folder.open ? 4 : 0;
const int folder_id=folder.kind-50,left=folder.x+frame+5,top=folder.y+frame+4;
const int right=folder.x+frame+folder.width-4,bottom=folder.y+frame+folder.height-4;
int child_x=left,child_y=top;
for(uint8_t id:state_.folder_icon_slots[size_t(folder_id)]) {
if(child_x+32>right) child_x=left,child_y+=27;
@@ -653,7 +657,8 @@ DeskRequest DesktopScreen::click(int x, int y, bool right) {
// The corner closes through the same transaction as the quickbar.
if (item.open && state_.drawer_handles && x <= item.x + 3 && y <= item.y + 3)
return close_drawer(item);
if (item.kind == 58 && item.open) return request(DeskRequestKind::advance_turn, item);
// The date remains an advance control with or without its optional frame.
if (item.kind == 58) return request(DeskRequestKind::advance_turn, item);
if (item.kind == 55 && item.open && !state_.national_team && x - item.x - 4 > 34 && x - item.x - 4 < 87)
return request(DeskRequestKind::change_ticket_price, item, (x - item.x - 4 - 35) / 3 + 8);
if (item.kind == 64 && item.open) return request(DeskRequestKind::change_option, item, std::clamp((x - item.x - 4) / 33, 0, 4));
+40
View File
@@ -780,6 +780,31 @@ int main(int argc, char** argv) {
child_return.layout_after[3*16+6]==49,
"RMB drag from the rendered 32×25 folder tile returns it to the visible chain");
check(folder_drag.take_sound_ids().empty(),"folder-child release cannot replay its down-event append");
// Unframed folders render the same tiles four pixels nearer the origin.
auto unframed_child_desk=child_desk;
unframed_child_desk.layout_snap=true;
unframed_child_desk.items.back().open=false;
unframed_child_desk.items.back().width=50;
unframed_child_desk.items.back().height=41;
unframed_child_desk.layout_records[49][13]=0;
unframed_child_desk.layout_records[13]=unframed_child_desk.layout_records[3];
unframed_child_desk.layout_records[13][12]=12;
unframed_child_desk.folder_icon_slots[0]={13};
DesktopScreen unframed_child(data,unframed_child_desk);
check(unframed_child.pointer_down(46,45).kind==DeskRequestKind::none &&
unframed_child.pointer_up(46,45).kind==DeskRequestKind::advance_turn,
"LMB on an unframed folder tile activates its native kickoff action");
DesktopScreen unframed_drag(data,unframed_child_desk);
unframed_drag.pointer_down(46,45,true);
check(unframed_drag.take_sound_ids()==std::vector<uint8_t>({15,12,15}),
"unframed child starts extraction rather than dragging the folder body");
unframed_drag.pointer_move(176,100);
const auto unframed_return=unframed_drag.pointer_up(176,100,true);
check(unframed_return.item_id==13 && unframed_return.menu_kind==12 &&
unframed_return.layout_operation==DeskLayoutOperation::return_folder_child &&
unframed_return.layout_after[13*16]==175 && unframed_return.layout_after[13*16+2]==95 &&
unframed_return.layout_after[49*16+5]==13,
"RMB extraction uses the rendered unframed tile origin and returns the kickoff icon");
DesktopScreen folder_drop(data,child_desk);
folder_drop.pointer_down(50,49,true); folder_drop.take_sound_ids();
folder_drop.pointer_move(55,52);
@@ -1119,6 +1144,21 @@ int main(int argc, char** argv) {
check(desk.click(20,40).kind == DeskRequestKind::none,"no duplicate advance request");
++d.revision; desk.acknowledge(d);
check(desk.click(165,125).kind == DeskRequestKind::advance_turn,"kickoff icon advances");
auto unframed_date=d;
unframed_date.items.front().open=false;
unframed_date.layout_records[1][13]&=0x7f;
DesktopScreen date_click(data,unframed_date);
check(date_click.pointer_down(20,40).kind==DeskRequestKind::none,
"date press waits for its release without entering layout drag");
const auto date_turn=date_click.pointer_up(20,40);
check(date_turn.kind==DeskRequestKind::advance_turn && date_turn.menu_kind==58 &&
date_turn.manager_slot==d.manager_slot && date_turn.revision==d.revision &&
date_click.pointer_up(20,40).kind==DeskRequestKind::none,
"unframed date body emits exactly one authenticated advance action");
DesktopScreen date_drag(data,unframed_date);
date_drag.pointer_down(20,40,true); date_drag.pointer_move(40,60);
check(date_drag.pointer_up(40,60,true).layout_operation==DeskLayoutOperation::move_item,
"unframed date retains right-button movement");
check(desk.render().pixels == pixels,"commands cannot mutate the saved game view");
desk.reject_action("unsupported_menu");
check(!desk.pending() && desk.render().pixels == pixels,"rejected command preserves state");
+131 -54
View File
@@ -6816,6 +6816,64 @@ void check_stadium_investment_controller(const std::filesystem::path& data) {
std::filesystem::remove_all(saves);
}
void check_date_widget_controller(const std::filesystem::path& data) {
for(bool framed : {true,false}) {
StartupFlow flow(data);
flow.click(150,215); flow.click(5,225,true); flow.click(5,225,true);
flow.click(90,169);
check(flow.pending_career()!=nullptr,"date fixture requests a new career");
std::unique_ptr<app::CareerSession> session=std::make_unique<app::CareerSession>(data,0x44415445);
std::string error;
const auto request=*flow.pending_career();
for(const auto& manager : request.managers)
check(session->confirm_manager(request.options,manager,error),"date fixture confirms its manager");
CareerInitializationResult initialized;
check(session->finish(initialized,error),"date fixture reaches an actual turn-driver desk");
uint64_t revision=initialized.desktop.revision;
const auto date=std::find_if(initialized.desktop.items.begin(),initialized.desktop.items.end(),
[](const DeskItem& item){return item.kind==58;});
check(date!=initialized.desktop.items.end(),"date fixture exposes the desktop date widget");
const auto at=layout::DesktopsUnsigned+uint32_t(initialized.desktop.manager_slot)*0x360u+uint32_t(date->id)*16u+13u;
auto& memory=session->state().memory;
memory.set8(at,uint8_t((memory.u8(at)&0x7f)|(framed?0x80:0)));
const int x=date->x+20,y=date->y+20;
initialized.desktop=session->desktop_projection(revision);
initialized.preparation=session->preparation_projection(revision);
auto preparation=initialized.preparation;
flow.attach_initialized_career(std::move(initialized));
flow.attach_preparation_context(std::move(preparation));
check(flow.pointer_down(x,y).request==FlowRequest::none,"date press waits for its release");
const auto advance=flow.click(x,y);
check(advance.request==FlowRequest::kickoff && advance.desk_action.menu_kind==58,
"framed and unframed date releases route through the shared kickoff action");
openbmh::audio::Playback playback;
std::optional<uint64_t> audio_session;
const auto serve=[&](const FlowResult& action) {
const auto failure=app::serve_flow_request(flow,action,session,data,data,0x44415445,
revision,playback,audio_session,false);
if(!failure.empty()) throw std::runtime_error("date widget dispatch failed: "+failure);
};
const auto before=save_stream(session->state());
const auto before_revision=revision;
const auto before_game=session->game(); const auto before_rand=session->rand();
auto stale=advance; ++stale.desk_action.revision;
serve(stale);
check(save_stream(session->state())==before && revision==before_revision &&
session->game().seed()==before_game.seed() && session->game().calls()==before_game.calls() &&
session->rand().seed()==before_rand.seed() && session->rand().calls()==before_rand.calls(),
"stale date request leaves the pending owner, native state and both RNG streams unchanged");
const auto before_date=session->state().date;
serve(advance);
check(session->state().date>before_date && revision>before_revision &&
flow.screen_name()=="desktop" && !flow.desktop()->pending(),
"date widget completes a real calendar event and acknowledges the next desk");
const auto after=save_stream(session->state()); const auto after_revision=revision;
serve(advance);
check(save_stream(session->state())==after && revision==after_revision,
"consumed date action cannot advance the calendar twice");
}
}
void check_menu_layout_session_io(const std::filesystem::path& data) {
StartupFlow flow(data);
flow.click(150, 215); flow.click(5, 225, true); flow.click(5, 225, true);
@@ -6942,64 +7000,82 @@ void check_menu_layout_session_io(const std::filesystem::path& data) {
session->rand().seed()==move_rand.seed()&&session->rand().calls()==move_rand.calls(),
"desktop layout movement preserves both RNG streams");
// Exercise the newly source-backed folder-child return and bin-mode
// Exercise framed and unframed folder-child return and bin-mode
// transfer through the authenticated CareerSession boundary, not only the
// DesktopScreen request projection.
constexpr uint32_t native_layout=::bmh::layout::Desktops;
const uint32_t native_base=native_layout+uint32_t(manager)*0x360u;
for(size_t i=0;i<bytes_count;++i)game.memory.set8(native_base+uint32_t(i),0xff);
auto put=[&](size_t item,size_t offset,uint8_t value){game.memory.set8(native_base+uint32_t(item*16+offset),value);};
put(0,5,49);put(0,6,0);
put(49,0,40);put(49,1,0);put(49,2,40);put(49,3,100);put(49,4,65);
put(49,5,0);put(49,6,0);put(49,12,50);put(49,13,0x80);
put(3,0,0);put(3,1,0);put(3,2,0);put(3,3,32);put(3,4,25);
put(3,5,0xff);put(3,6,0xff);put(3,12,2);put(3,13,0);
auto folder_desk=session->desktop_projection(revision);
DesktopScreen child_return_screen(data,folder_desk);
child_return_screen.pointer_down(50,49,true);
child_return_screen.pointer_move(175,100);
const auto return_request=child_return_screen.pointer_up(175,100,true);
const auto before_return_rng=session->game();const auto before_return_rand=session->rand();
check(return_request.layout_operation==ui::DeskLayoutOperation::return_folder_child&&
session->dispatch_desktop_layout(return_request,revision,error)&&error.empty()&&
game.memory.u8(native_base+3*16+5)==0&&game.memory.u8(native_base+3*16+6)==49&&
game.memory.u8(native_base+49*16+5)==3,
"authenticated folder child return appends to the visible chain");
check(session->game().seed()==before_return_rng.seed()&&session->game().calls()==before_return_rng.calls()&&
session->rand().seed()==before_return_rand.seed()&&session->rand().calls()==before_return_rand.calls(),
"folder child return consumes no RNG");
const auto returned_desk=session->desktop_projection(revision);
const auto returned_child=std::find_if(returned_desk.items.begin(),returned_desk.items.end(),
[](const ui::DeskItem& item){return item.id==3;});
check(returned_child!=returned_desk.items.end(),"returned child is projected as a desk item");
const auto saved_child_x=game.memory.u16(native_base+3*16);
const auto saved_child_y=game.memory.u8(native_base+3*16+2);
auto bin_desk=returned_desk;bin_desk.shortcut_bar_always=true;
DesktopScreen bin_screen(data,bin_desk);
bin_screen.click(2,215); // Source local_50 bin mode toggle.
const auto bin_request=bin_screen.click(returned_child->x+1,returned_child->y+1,true);
const auto before_bin_rng=session->game();const auto before_bin_rand=session->rand();
check(bin_request.layout_operation==ui::DeskLayoutOperation::send_to_folder&&
session->dispatch_desktop_layout(bin_request,revision,error)&&error.empty()&&
game.memory.u8(native_base+3*16+5)==0xff&&game.memory.u8(native_base+3*16+6)==0xff&&
game.memory.u8(native_base+3*16+13)==0,
"bin mode moves the item into its original associated folder without clearing its coordinates");
check(session->game().seed()==before_bin_rng.seed()&&session->game().calls()==before_bin_rng.calls()&&
session->rand().seed()==before_bin_rand.seed()&&session->rand().calls()==before_bin_rand.calls(),
"folder bin transfer consumes no RNG");
auto binned_desk=session->desktop_projection(revision);binned_desk.shortcut_bar_always=true;
DesktopScreen restore_screen(data,binned_desk);
restore_screen.click(2,215);
const int folder_x=std::find_if(binned_desk.items.begin(),binned_desk.items.end(),
[](const ui::DeskItem& item){return item.id==49;})->x;
const int folder_y=std::find_if(binned_desk.items.begin(),binned_desk.items.end(),
[](const ui::DeskItem& item){return item.id==49;})->y;
const auto restore_request=restore_screen.click(folder_x+10,folder_y+9,true);
check(restore_request.layout_operation==ui::DeskLayoutOperation::restore_folder_child&&
session->dispatch_desktop_layout(restore_request,revision,error)&&error.empty()&&
game.memory.u8(native_base+3*16+5)==0&&game.memory.u8(native_base+49*16+5)==3&&
game.memory.u16(native_base+3*16)==saved_child_x&&game.memory.u8(native_base+3*16+2)==saved_child_y,
"right-clicking a folder child in bin mode restores its saved original position");
for(int child_id : {3,13}) for(bool framed : {true,false}) {
for(size_t i=0;i<bytes_count;++i)game.memory.set8(native_base+uint32_t(i),0xff);
auto put=[&](size_t item,size_t offset,uint8_t value){game.memory.set8(native_base+uint32_t(item*16+offset),value);};
put(0,5,49);put(0,6,0);
put(49,0,40);put(49,1,0);put(49,2,40);put(49,3,100);put(49,4,65);
put(49,5,0);put(49,6,0);put(49,12,50);put(49,13,framed?0x80:0);
put(size_t(child_id),0,0);put(size_t(child_id),1,0);put(size_t(child_id),2,0);put(size_t(child_id),3,32);put(size_t(child_id),4,25);
put(size_t(child_id),5,0xff);put(size_t(child_id),6,0xff);put(size_t(child_id),12,uint8_t(child_id-1));put(size_t(child_id),13,0);
auto folder_desk=session->desktop_projection(revision);
DesktopScreen child_return_screen(data,folder_desk);
child_return_screen.pointer_down(50,49,true);
child_return_screen.pointer_move(175,100);
const auto return_request=child_return_screen.pointer_up(175,100,true);
const auto before_return_rng=session->game();const auto before_return_rand=session->rand();
const auto return_revision=revision;
const auto before_return=capture_slot();
auto stale_return=return_request; ++stale_return.revision;
check(!session->dispatch_desktop_layout(stale_return,revision,error) &&
revision==return_revision && capture_slot()==before_return,
"folder extraction rejects a stale revision atomically");
// A linked folder with the native hidden flag owns no visible child input.
put(49,1,0x10);
auto hidden_return=return_request;
hidden_return.layout_before[49*16+1]=hidden_return.layout_after[49*16+1]=0x10;
const auto hidden_before=capture_slot();
check(!session->dispatch_desktop_layout(hidden_return,revision,error) &&
revision==return_revision && capture_slot()==hidden_before,
"folder extraction rejects a hidden owner without modifying its chain");
put(49,1,0);
check(return_request.layout_operation==ui::DeskLayoutOperation::return_folder_child&&
session->dispatch_desktop_layout(return_request,revision,error)&&error.empty()&&
game.memory.u8(native_base+uint32_t(child_id)*16+5)==0&&game.memory.u8(native_base+uint32_t(child_id)*16+6)==49&&
game.memory.u8(native_base+49*16+5)==child_id,
"authenticated folder child return appends to the visible chain");
check(session->game().seed()==before_return_rng.seed()&&session->game().calls()==before_return_rng.calls()&&
session->rand().seed()==before_return_rand.seed()&&session->rand().calls()==before_return_rand.calls(),
"folder child return consumes no RNG");
const auto returned_desk=session->desktop_projection(revision);
const auto returned_child=std::find_if(returned_desk.items.begin(),returned_desk.items.end(),
[&](const ui::DeskItem& item){return item.id==child_id;});
check(returned_child!=returned_desk.items.end(),"returned child is projected as a desk item");
if(child_id==13) continue; // Source excludes the kickoff icon from bin-mode removal.
const auto saved_child_x=game.memory.u16(native_base+uint32_t(child_id)*16);
const auto saved_child_y=game.memory.u8(native_base+uint32_t(child_id)*16+2);
auto bin_desk=returned_desk;bin_desk.shortcut_bar_always=true;
DesktopScreen bin_screen(data,bin_desk);
bin_screen.click(2,215); // Source local_50 bin mode toggle.
const auto bin_request=bin_screen.click(returned_child->x+1,returned_child->y+1,true);
const auto before_bin_rng=session->game();const auto before_bin_rand=session->rand();
check(bin_request.layout_operation==ui::DeskLayoutOperation::send_to_folder&&
session->dispatch_desktop_layout(bin_request,revision,error)&&error.empty()&&
game.memory.u8(native_base+uint32_t(child_id)*16+5)==0xff&&game.memory.u8(native_base+uint32_t(child_id)*16+6)==0xff&&
game.memory.u8(native_base+uint32_t(child_id)*16+13)==0,
"bin mode moves the item into its original associated folder without clearing its coordinates");
check(session->game().seed()==before_bin_rng.seed()&&session->game().calls()==before_bin_rng.calls()&&
session->rand().seed()==before_bin_rand.seed()&&session->rand().calls()==before_bin_rand.calls(),
"folder bin transfer consumes no RNG");
auto binned_desk=session->desktop_projection(revision);binned_desk.shortcut_bar_always=true;
DesktopScreen restore_screen(data,binned_desk);
restore_screen.click(2,215);
const int folder_x=std::find_if(binned_desk.items.begin(),binned_desk.items.end(),
[](const ui::DeskItem& item){return item.id==49;})->x;
const int folder_y=std::find_if(binned_desk.items.begin(),binned_desk.items.end(),
[](const ui::DeskItem& item){return item.id==49;})->y;
const auto restore_request=restore_screen.click(folder_x+10,folder_y+9,true);
check(restore_request.layout_operation==ui::DeskLayoutOperation::restore_folder_child&&
session->dispatch_desktop_layout(restore_request,revision,error)&&error.empty()&&
game.memory.u8(native_base+uint32_t(child_id)*16+5)==0&&game.memory.u8(native_base+49*16+5)==3&&
game.memory.u16(native_base+uint32_t(child_id)*16)==saved_child_x&&game.memory.u8(native_base+uint32_t(child_id)*16+2)==saved_child_y,
"right-clicking a folder child in bin mode restores its saved original position");
}
}
int main(int argc, char** argv) {
@@ -7035,6 +7111,7 @@ int main(int argc, char** argv) {
check_readonly_views(data);
check_desk_records_controller(data);
check_menu_layout_session_io(data);
check_date_widget_controller(data);
check_calendar_readonly_controller(data);
check_indoor_standings_controller(data);
check_strengths_semantic_and_controller(data);