The stadium and its surroundings as two pages with a card model on one plate
The ground is drawn after the design: eight stands as deep as they have places, the equipment, the fourteen objects around it, trees, cars and people on one base plate. The stage works out itself which part lies under the pointer, the wheel zooms and dragging moves the view. The part's card, the figures and the building firm's offer follow the notes of the other pages. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
17c6d0a1d3
commit
c60b0e9b2c
14 files changed
+1025
-1178
No files matched your search
@@ -25,36 +25,111 @@ void App::sync_stadium_draft() {
|
||||
if(stadium_view_.at("dialog")=="block")if(auto *button=element("stadium-place-number"))button->SetInnerRML("<span class=\"control-label\">"+std::to_string(stadium_view_.at("draft").at("places").get<int64_t>())+"</span>");
|
||||
dirty_=true;
|
||||
}
|
||||
// The camera of the card model: a new focus starts a flight of 0.6 seconds, during which
|
||||
// only the picture is drawn anew; reduced motion jumps.
|
||||
// Choosing a part of the model, and laying the view back to where it started.
|
||||
bool App::stadium_focus_action(const std::string &action,Rml::Element *target) {
|
||||
if(action!="stadium-focus"||!target)return false;
|
||||
// the camera stands still: a click only chooses the part (the screen drops a part that
|
||||
// does not belong to its view)
|
||||
const auto next=std::string(target->GetAttribute<Rml::String>("data-id",""));
|
||||
if(action=="stadium-reset") {
|
||||
stadium_view_defaults(stadium_view_);
|
||||
stadium_cams_.erase(stadium_view_.at("view")=="panorama"?"panorama":"inside");
|
||||
focus_after_render_="stadium-reset";refresh();return true;
|
||||
}
|
||||
if((action!="stadium-focus"&&action!="stadium-pick")||!target)return false;
|
||||
// the click that ends a drag of the view chooses nothing
|
||||
if(stadium_dragged_){stadium_dragged_=false;return true;}
|
||||
// a click on the stage chooses what lies under the pointer, or lets go of the chosen part
|
||||
const auto next=action=="stadium-pick"?stadium_hover_:std::string(target->GetAttribute<Rml::String>("data-id",""));
|
||||
if(next==stadium_focus_)return true;
|
||||
stadium_flying_=false;
|
||||
stadium_focus_=next;
|
||||
focus_after_render_=next.find(':')!=std::string::npos?"stadium-card-build":"";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
void App::stadium_camera_tick() {
|
||||
if(!stadium_flying_)return;
|
||||
if(menu_!="stadium"||!world_){stadium_flying_=false;return;}
|
||||
const double t=std::min(1.0,double(SDL_GetTicks64()-stadium_flight_start_)/600.0);
|
||||
stadium_camera_=stadium3d::mix(stadium_camera_from_,stadium_camera_to_,t);
|
||||
if(t>=1){stadium_flying_=false;refresh();return;}
|
||||
stadium_view_defaults(stadium_view_);
|
||||
const auto overview=stadium_overview(stadium_view_.at("future").get<bool>());
|
||||
auto *art=element("stadium-model-art");
|
||||
if(!overview.value("ok",false)||!art){stadium_flying_=false;refresh();return;}
|
||||
std::string seat_colour;
|
||||
if(const auto *own=world_->find("clubs",overview.value("club",std::string()));own&&!own->value("crest","").empty())seat_colour=renderer_.crest_colour(own->value("crest",""));
|
||||
if(seat_colour.empty())seat_colour="#3d6f8f";
|
||||
const auto drawing=stadium3d::draw(stadium3d::build(overview,seat_colour,theme_=="silver"),stadium_camera_,1790,1600);
|
||||
art->SetInnerRML(picture(renderer_.diagram("stadium-model",drawing.svg,1790),1790,1600));
|
||||
// Looking around on the stage: the wheel zooms towards the pointer, dragging moves the view,
|
||||
// and the pointer over a part shows what stands there. Only the place of the picture changes;
|
||||
// nothing is drawn anew.
|
||||
bool App::stadium_stage_event(Rml::Event &event) {
|
||||
auto *stage=element("stadium-stage");auto *world=element("stadium-world");
|
||||
if(!stage||!world)return false;
|
||||
const auto type=event.GetType();
|
||||
if(type!="mousemove"&&type!="mousedown"&&type!="mouseup"&&type!="mousescroll")return false;
|
||||
const bool outer=stadium_view_.value("view",std::string())=="panorama";
|
||||
// the pointer on the stage, in units of the page
|
||||
const double mx=(event.GetParameter<float>("mouse_x",0)-stage->GetAbsoluteLeft())/scale_/2.25,my=(event.GetParameter<float>("mouse_y",0)-stage->GetAbsoluteTop())/scale_/2.25;
|
||||
const bool on_world=event.GetTargetElement()&&event.GetTargetElement()->GetId()=="stadium-model-ground";
|
||||
// the part under the pointer: the one in front wins
|
||||
const auto under=[&](const std::array<double,3> &cam)->std::string {
|
||||
if(!on_world)return {};
|
||||
const double x=(mx-cam[1])/cam[0],y=(my-cam[2])/cam[0];std::string found;
|
||||
for(const auto &part:stadium_hots_)
|
||||
for(const auto &quad:part.quads) {
|
||||
const auto a=stadium_scene::project(quad.a),b=stadium_scene::project(quad.b),d=stadium_scene::project(quad.d);
|
||||
const double ux=b.x-a.x,uy=b.y-a.y,vx=d.x-a.x,vy=d.y-a.y,det=ux*vy-uy*vx;
|
||||
if(std::abs(det)<1e-6)continue;
|
||||
const double s=((x-a.x)*vy-(y-a.y)*vx)/det,t=(ux*(y-a.y)-uy*(x-a.x))/det;
|
||||
if(s>=0&&s<=1&&t>=0&&t<=1){found=part.id;break;}
|
||||
}
|
||||
return found;
|
||||
};
|
||||
const auto part_element=[&](const std::string &id){return id.empty()?nullptr:element("stadium-part-"+id.substr(0,id.find(':'))+"-"+id.substr(id.find(':')+1));};
|
||||
const auto hover=[&](const std::string &id) {
|
||||
if(id==stadium_hover_)return;
|
||||
if(auto *old=part_element(stadium_hover_))old->SetClass("hover",false);
|
||||
if(auto *now=part_element(id))now->SetClass("hover",true);
|
||||
stadium_hover_=id;dirty_=true;
|
||||
};
|
||||
const auto place=[&](std::array<double,3> cam) {
|
||||
constexpr double w=stadium_scene::width,h=stadium_scene::height;
|
||||
cam[0]=std::clamp(cam[0],.75,3.2);
|
||||
cam[1]=std::clamp(cam[1],std::min(240.0,w-w*cam[0]-240),std::max(240.0,w-w*cam[0]-240));
|
||||
cam[2]=std::clamp(cam[2],std::min(240.0,h-h*cam[0]-240),std::max(240.0,h-h*cam[0]-240));
|
||||
stadium_cams_[outer?"panorama":"inside"]=cam;
|
||||
world->SetProperty("left",pg(cam[1]));world->SetProperty("top",pg(cam[2]));world->SetProperty("transform","scale("+scalar(cam[0])+")");
|
||||
dirty_=true;
|
||||
};
|
||||
auto *tip=element("stadium-tip");
|
||||
if(type=="mousescroll") {
|
||||
if(!on_world)return false;
|
||||
auto cam=stadium_cam(outer);
|
||||
const double zoom=std::clamp(cam[0]*std::exp(-event.GetParameter<float>("wheel_delta_y",0)*.16),.75,3.2);
|
||||
cam[1]=mx-(mx-cam[1])*zoom/cam[0];cam[2]=my-(my-cam[2])*zoom/cam[0];cam[0]=zoom;
|
||||
place(cam);
|
||||
if(tip)tip->SetProperty("display","none");
|
||||
event.StopImmediatePropagation();return true;
|
||||
}
|
||||
if(type=="mousedown") {
|
||||
stadium_dragged_=false;hover(under(stadium_cam(outer)));
|
||||
if(on_world&&event.GetParameter<int>("button",0)==0)stadium_drag_={{"x",mx},{"y",my},{"moved",false}};
|
||||
return false;
|
||||
}
|
||||
if(type=="mouseup") {
|
||||
if(stadium_drag_.is_object()&&stadium_drag_.at("moved")==true)stadium_dragged_=true;
|
||||
stadium_drag_=Json();
|
||||
return false;
|
||||
}
|
||||
if(stadium_drag_.is_object()) {
|
||||
const double dx=mx-stadium_drag_.at("x").get<double>(),dy=my-stadium_drag_.at("y").get<double>();
|
||||
if(stadium_drag_.at("moved")!=true&&std::hypot(dx,dy)<5)return false;
|
||||
auto cam=stadium_cam(outer);cam[1]+=dx;cam[2]+=dy;
|
||||
stadium_drag_={{"x",mx},{"y",my},{"moved",true}};
|
||||
place(cam);hover({});
|
||||
if(tip)tip->SetProperty("display","none");
|
||||
return true;
|
||||
}
|
||||
// what the pointer is on
|
||||
hover(under(stadium_cam(outer)));
|
||||
if(!tip)return false;
|
||||
std::string name,state;
|
||||
if(auto *n=part_element(stadium_hover_)){name=n->GetAttribute<Rml::String>("data-tip-name","");state=n->GetAttribute<Rml::String>("data-tip-state","");}
|
||||
const auto shown=name+"|"+state;
|
||||
if(name.empty()) {
|
||||
if(!stadium_tip_.empty()){stadium_tip_.clear();tip->SetProperty("display","none");dirty_=true;}
|
||||
return false;
|
||||
}
|
||||
if(stadium_tip_!=shown){stadium_tip_=shown;tip->SetInnerRML("<strong>"+esc(name)+"</strong><span>"+esc(state)+"</span>");}
|
||||
tip->SetProperty("display","block");
|
||||
stadium_tip_at_={std::min(mx+16,stadium_scene::width-330),std::max(4.0,my-34)};
|
||||
tip->SetProperty("left",pg(stadium_tip_at_[0]));tip->SetProperty("top",pg(stadium_tip_at_[1]));
|
||||
dirty_=true;
|
||||
return false;
|
||||
}
|
||||
bool App::stadium_action(const std::string &action,Rml::Element *target) {
|
||||
if(engine_mode_)return engine_stadium_action(action,target);
|
||||
@@ -154,13 +229,7 @@ bool App::stadium_event(Rml::Event &event) {
|
||||
else return false;
|
||||
event.StopImmediatePropagation();return true;
|
||||
}
|
||||
if(!dialog&&stadium_view_.at("view")=="panorama"&&(type=="mousemove"||type=="focus"||type=="blur")) {
|
||||
const auto hint=[&](Rml::Element *from) {for(auto *n=from;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-stadium-hint"))return n->GetAttribute<Rml::String>("data-stadium-hint","");return Rml::String();};
|
||||
auto text=hint(target);
|
||||
if(type=="focus"&&text.empty()&&target&&target->GetId()!="stadium-back"&&target->GetId()!="stadium-future"&&target->GetId()!="window-close")return false;
|
||||
if(type=="blur")text="";
|
||||
if(stadium_view_.at("hint")!=text) {stadium_view_["hint"]=text;if(auto *n=element("stadium-interaction-hint"))n->SetInnerRML("<span>"+esc(text.empty()?"Ein Element im Stadionumfeld auswählen.":text)+"</span>");dirty_=true;}
|
||||
}
|
||||
if(!dialog&&stadium_stage_event(event))return true;
|
||||
Rml::Element *place_range=nullptr;
|
||||
for(auto *node=target;node&&node!=doc_;node=node->GetParentNode())if(node->GetId()=="stadium-place-range"){place_range=node;break;}
|
||||
if(dialog&&type=="keydown"&&place_range&&stadium_view_.at("dialog")=="block"&&(key==Rml::Input::KI_HOME||key==Rml::Input::KI_END)) {
|
||||
@@ -192,7 +261,6 @@ bool App::stadium_event(Rml::Event &event) {
|
||||
if(target->HasAttribute("data-stadium-feature")) {
|
||||
const auto field=target->GetAttribute<Rml::String>("data-stadium-feature","");if(field!="seats"&&field!="roof")return true;
|
||||
stadium_view_["draft"][field]=target->HasAttribute("checked");stadium_view_["feedback"]="";
|
||||
if(auto *image=element("stadium-feature-image-"+field)){const bool checked=stadium_view_.at("draft").at(field).get<bool>();image->SetInnerRML(picture(renderer_.diagram("stadium-feature-"+field+(checked?"-built-":"-empty-")+theme_,stadium_feature_svg(field,checked,theme_),232),116,116));}
|
||||
sync_stadium_draft();event.StopImmediatePropagation();return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user