// SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "ui/desk_records.hpp" #include #include #include "game/lineup.hpp" #include "game/messages.hpp" #include "game/schedule.hpp" #include "ui/manager.hpp" #include "formats/textd.hpp" namespace bmh::ui { std::filesystem::path asset_path(const std::filesystem::path&, const std::string&); namespace { void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h) { if (sx < 0 || sy < 0 || x < 0 || y < 0 || sx+w>src.width || sy+h>src.height || x+w>out.width || y+h>out.height) throw FormatError("desk records: Original asset bounds"); for(int yy=0;yy(g.manager_teams.size(),4); const int active=g.memory.has(::bmh::layout::ActiveManager)?g.memory.u8(::bmh::layout::ActiveManager):-1; const int managers=g.memory.has(::bmh::layout::ManagerCount)?g.memory.u8(::bmh::layout::ManagerCount):int(count); const bool current=g.memory.has(::bmh::layout::DeskPosition)&&g.memory.u8(::bmh::layout::DeskPosition)=g.manager_records.size()||g.manager_records[at]==0)continue; if(g.manager_teams[slot]==team)return int(slot)==active&¤t?0x7a:0x75; } if(g.memory.has(::bmh::layout::AlltimeTable_TeamColor_RuntimeField)&&g.memory.u16(::bmh::layout::AlltimeTable_TeamColor_RuntimeField)==team)return 0xf7; return 0x5f; } } DeskRecordsState fair_play_state_from_game(const GameState& g, int league, const Image& underlay,int manager_slot) { if(league<0||league>=9) throw FormatError("fair play: invalid Source league"); const int first=league_first_team(league), count=kLeagueSizes[league]; if(first<0||count<=0||first+count>138||g.club_ids.size() teams(static_cast(count)); std::vector keys(static_cast(count)); for(int i=0;i>8)*4+(cards&0xff)); } // FairPlayStateFromGame passes ascending=1 to the same in-place Source quicksort. quicksort_by_key(teams.data(),keys.data(),count,true); DeskRecordsState out; out.kind=DeskRecordKind::fair_play;out.league=league;out.underlay=underlay; out.original_panel=!g.memory.has(::bmh::layout::SolidPanelBackground)||g.memory.u8(::bmh::layout::SolidPanelBackground)==0; if(manager_slot>=0&&size_t(manager_slot)>8),int(keys[size_t(i)]),g.club_name(team),source_team_color(g,team)}); } return out; } DeskRecordsScreen::DeskRecordsScreen(const std::filesystem::path& data, DeskRecordsState state) : exe_(load_le(asset_path(data,"BMH.exe"))),texts_(load_textd(asset_path(data,"TEXTD.BLK"))), font_(load_font(asset_path(data/"F","BMH3.FNT"))),sprite_font_(data), background_(load_vga(asset_path(data/"KB","129.VGA"))),state_(std::move(state)) { if(state_.underlay.width!=320||state_.underlay.height!=240) throw FormatError("desk records: missing accepted desk underlay"); if(state_.kind==DeskRecordKind::fair_play) { kb56_=load_vga(asset_path(data/"KB","56.VGA")); const int bottom=int(state_.fair_play_rows.size())*9+38; if(state_.league<0||state_.league>=9||state_.fair_play_rows.size()!=size_t(kLeagueSizes[state_.league])|| kb56_.width<296||kb56_.height<9+(bottom-28-1)) throw FormatError("fair play: incomplete Original view"); } else if(state_.highscore.ranked) { kb51_=load_vga(asset_path(data/"KB","51.VGA")); if(kb51_.width<112||kb51_.height<74||state_.highscore.rows.size()!=5) throw FormatError("highscore: incomplete Original view"); } else if(state_.highscore.rows.size()!=5) throw FormatError("highscore: incomplete Original view"); if(state_.kind==DeskRecordKind::highscore&&!state_.highscore.ranked) alternate_=std::make_unique(load_game_end_alternate_score_assets(data),state_.underlay,state_.gradient_text); } void DeskRecordsScreen::text(Image& out,int x,int baseline,std::string_view value,uint8_t color,bool shadow) const { const int width=font_.text_width(value), top=baseline-font_.baseline; const int offset=shadow?2:0; if(x<0||x+width+offset>out.width||top<0||top+font_.height+offset>out.height)return; if(shadow)font_.draw(out,x+2,top+2,value,0x40); if(!state_.gradient_text){font_.draw(out,x,top,value,color);return;} Image mask(std::max(1,width),font_.height); font_.draw(mask,0,0,value,1); int index=0;while(index<32&&exe_.u8(::bmh::layout::Advertising_Text_RuntimeField2+uint32_t(index))!=color)++index; for(int y=0;yrender(); } Image out=state_.decorated_background?background_:Image(320,240); if(!state_.decorated_background){ fill_rect(out,0,4,320,13,0x44);fill_rect(out,1,5,318,11,0x39); fill_rect(out,0,228,320,10,0x44);fill_rect(out,1,229,318,8,0x39); } if(state_.kind==DeskRecordKind::fair_play) { // LoadGameEndTaxAnimationAssets(0,26,28,296,count*9+38): exact absolute Source edges. const int right=296, bottom=int(state_.fair_play_rows.size())*9+38; if(state_.original_panel) copy(out,kb56_,26,9,27,29,right-27,bottom-29); else fill_rect(out,26,28,right-26+1,bottom-28+1,0x42); for(int y=28;y<=bottom;++y)out.at(26,y)=0x46; for(int x=26;x<=right;++x)out.at(x,28)=0x46; for(int x=26;x<=right;++x)out.at(x,bottom)=0x40; for(int y=28;y<=bottom;++y)out.at(right,y)=0x40; const auto heading=original_to_utf8(texts_.strings.at((::bmh::layout::DeskRecords_FillRect_TextPointer5-::bmh::layout::TextPointerTable)/4)); const int heading_x=SpriteFont::centered_title_x(sprite_font_.text_width(heading)); sprite_font_.draw(out,heading_x,13,heading,5); sprite_font_.draw(out,5,235,original_to_utf8(state_.manager_name),5); for(size_t i=0;iphase()==AlternateScorePhase::AwaitAck) { if(alternate_->acknowledge()) { closed_=true; return true; } return false; } if(alternate_->phase()==AlternateScorePhase::Cancelled) { closed_=true; return true; } if(alternate_->phase()!=AlternateScorePhase::Calculator)return false; if(right) { alternate_->cancel(); closed_=true; return true; } const bool changed=alternate_->mouse_down(x,y); if(alternate_->phase()==AlternateScorePhase::Cancelled)closed_=true; return changed; } bool DeskRecordsScreen::pointer_up(int,int,bool) { if(closed_||!alternate_)return false; return alternate_->mouse_up(); } bool DeskRecordsScreen::text_input(std::string_view input) { if(closed_||!alternate_)return false; return alternate_->text(input); } bool DeskRecordsScreen::key_input(std::string_view key) { if(closed_)return false; if(!alternate_)return false; // SDLFlushEvents2 only returns on mouse down or quit. return alternate_->key(key); } } // namespace bmh::ui