#include "VegaMain.h" #include "Tournament.h" //////////////////////////// class option image three state button /////////////////// void OptionImage::ReFocus() { SetFocus(); } OptionImage::OptionImage() { WhenAction = THISBACK(ReFocus); } void OptionImage::Paint(Draw& w) { Size sz = GetSize(); if(!IsTransparent()) w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace); Size isz = Vega5Img::imgYes().GetSize(); //although maybe it would be good to calc from the biggest...? Size tsz = GetSmartTextSize(w, label, font); int ty = (sz.cy - tsz.cy) / 2; //text up-down int iy = (tsz.cy - isz.cy) / 2 + ty; bool ds = !IsShowEnabled(); Image m = (!notnull || threestate) && IsNull(option) ? ds ? Vega5Img::imgMaybe : IsPush() ? Vega5Img::imgYes : Vega5Img::imgMaybe : option == 1 ? ds ? (switchimage ? Vega5Img::imgYes : Vega5Img::imgYes) : IsPush() ? (switchimage ? Vega5Img::imgYes : Vega5Img::imgYes) : (switchimage ? Vega5Img::imgYes : Vega5Img::imgYes) : ds ? (switchimage ? Vega5Img::imgNo : Vega5Img::imgNo) : IsPush() ? (switchimage ? Vega5Img::imgNo : Vega5Img::imgNo) : (switchimage ? Vega5Img::imgNo : Vega5Img::imgNo); w.DrawImage(0, iy, m); DrawSmartText(w, isz.cx + 4, ty, tsz.cx, label, font, ds ? SGray : SBlack, VisibleAccessKeys() ? accesskey : 0); //text length problem - tsz.cx - doesn't work? - adjust *.lay!!! } /////////////////////////////// void Avail3(One& ctrl) { //ctrl.Create().ThreeState().SetImage(Vega5Img::imgYes(), Vega5Img::imgNo(), Vega5Img::imgMaybe()); ctrl.Create().SetImage(Vega5Img::imgYes(), Vega5Img::imgNo(), Vega5Img::imgMaybe()); } int FilterCommaSpace(int c) { if (c == ';' || c =='\\') return false; else return c; } int FilterComma(int c) { if (c == ';') return false; else return c; } VegaTab1::VegaTab1() { // set the widths of each coloumn // arr.ColumnWidths("25 3 5 12 8 8 2 3 3 3 3"); int i; countID=1; //è un indice incrementale che cresce sempre CtrlLayout(*this); SizePos(); //id, label, width arr.AddColumn("ID", t_("ID"), 3).HeaderTab().WhenAction = THISBACK1(SortRecord, 0); //0 arr.AddColumn("Name", t_("Team Name"), 17).HeaderTab().WhenAction = THISBACK1(SortRecord, 1); //1 arr.AddColumn("Origin", t_("Origin"), 17).HeaderTab().WhenAction = THISBACK1(SortRecord, 2); ; //2 arr.AddColumn("Federation", t_("Fed"), 17).HeaderTab().WhenAction = THISBACK1(SortRecord, 3); ; //3 arr.AddColumn("Rating", t_("Rating"), 6).HeaderTab().WhenAction = THISBACK1(SortRecord, 4); //4 arr.AddColumn("Status", t_("Status"), 6); //.Ctrls(Avail3); //5 //drop list widget edtTitleP.Add("GM"); edtTitleP.Add("WGM"); edtTitleP.Add("IM"); edtTitleP.Add("WIM"); edtTitleP.Add("FM"); edtTitleP.Add("WFM"); edtTitleP.Add("M"); edtTitleP.Add("CM"); edtTitleP.Add("1N"); edtTitleP.Add("2N"); edtTitleP.Add("3N"); edtTitleP.Add("A"); edtTitleP.Add("B"); edtTitleP.Add("C"); edtTitleP.Add("D"); edtTitleP.Add("E"); edtTitleP.Add("F"); edtTitleP.Add("G"); edtTitleP.Add("H"); edtTitleP.Add("NC"); edtTitleP.Add("--"); edtTitleP <<= "GM"; // optGenderP.SetImage(Vega5Img::female(), Vega5Img::male()); // false state, true state // optGenderP <<= 1; // optStatusP.SetImage(Vega5Img::imgNo(), Vega5Img::imgYes()); // false state, true state optGenderP <<= "m"; optStatusP <<= 1; arrPlayer.TabAddsRow(false); arrPlayer.AddColumn("Name", t_("Name"), 17).Edit(edtNameP.MaxChars(25)); arrPlayer.AddColumn("Country", t_("Fed"), 3).Edit(edtCountryP.MaxChars(20)); arrPlayer.AddColumn("Birthday", t_("Birthday"), 5).Edit(edtBirth.MaxChars(10)); arrPlayer.AddColumn("Gender", t_("G"), 2).Edit(optGenderP); arrPlayer.AddColumn("Title", t_("Title"), 5).Edit(edtTitleP); arrPlayer.AddColumn("IDFIDE", t_("ID FIDE"), 5).Edit(edtIDFideP.Min(0).MaxChars(8)) ; arrPlayer.AddColumn("RatFIDE", t_("Rtg FIDE"), 5).Edit(edtRtgFideP.Min(0).MaxChars(4)) ; arrPlayer.AddColumn("IDNat", t_("ID Nat"), 5).Edit(edtIDNatP.Min(0).MaxChars(8)) ; arrPlayer.AddColumn("RatNat", t_("Rtg Nat"), 5).Edit(edtRtgNatP.Min(0).MaxChars(4)) ; arrPlayer.AddColumn("K", t_("K"), 3).Edit(edtKP.Min(0).MaxChars(2)) ; arrPlayer.AddColumn("Status", t_("Status"), 4).Edit(optStatusP); // for (i=0; i=TD.MAX_PLAYERS && !modifyFLAG) { Exclamation( t_("Too much players! Stop with the registration")); return; } // if( TD.IS_SWISS && TD.IS_CLOSED_REGISTRATION && !modifyFLAG) { // if (!PromptYesNo(t_("Do you want to add a Late-Comer to the tournament?&You will not be able to delete him again")) ) // return; // } //set default in case of null or empty fields if ( IsNull(AsString(~editOrigin)) ) editOrigin <<= "---"; if ( IsNull(AsString(~editCountry)) ) editCountry <<= "---"; if ( IsNull(AsString(~editRatFIDE)) ) editRatFIDE <<= 0; if (modifyFLAG) { //Modify int int_row; int_row=arr.GetCursor(); if (int_row < 0) return; // prevent the crash of the application when int_row = -1) arr.Set( int_row, 1, ~editName); arr.Set( int_row, 2, ~editOrigin); arr.Set( int_row, 3, ~editCountry); arr.Set( int_row, 4, ~editRatFIDE); arr.Set( int_row, 5, ~btnAvail); TD.SaveVegFile(true); // make active the player for the next round int id = StrIntValue( AsString( arr.Get(int_row, 0)) ); // get ID String strID = AsString( id ); TeamArchive& team = db.Get(strID); team.name = TrimRight(TrimLeft( AsString(~editName) ) ); team.origin = AsString(~editOrigin); team.country = AsString(~editCountry); team.ratingfide = 0; //for the moment team.isAvailable = AsString(~btnAvail); for (i=0; iGet(i-1, "Name")) ); if (~opt[2]) s << NFormat( "%3.3s ", AsString(arr->Get(i-1, "Country"))); if (~opt[3]) s << NFormat( "%8.8s ", AsString(arr->Get(i-1, "Birthday"))); if (~opt[4]) s << NFormat( "%s ", AsString(arr->Get(i-1, "Gender"))); if (~opt[5]) s << NFormat( "%3.3s ", AsString(arr->Get(i-1, "Title"))); if (~opt[6]) s << NFormat( "%8.8s ", AsString(arr->Get(i-1, "IDFIDE"))); if (~opt[7]) s << NFormat( "%8.8s ", AsString(arr->Get(i-1, "RatFIDE"))); if (~opt[8]) s << NFormat( "%8.8s ", AsString(arr->Get(i-1, "IDNat"))); if (~opt[9]) s << NFormat( "%8.8s ", AsString(arr->Get(i-1, "RatNat"))); if (~opt[10]) s << NFormat( "%2s ", AsString(arr->Get(i-1, "K"))); out.PutLine(s); } } else { out.PutLine("\n The following players got a BYE:\n"); for (i=1; i<=TD.NPlayer; i++) { String s = ""; if ( IsNull(player[i].isAvailable) ) { if (~opt[0]) s << NFormat( "%3d ", i); if (~opt[1]) s << NFormat( "%-25.25s ", player[i].name); if (~opt[2]) s << NFormat( "%3.3s ", player[i].country); if (~opt[3]) s << NFormat( "%8.8s ", player[i].data); if (~opt[4]) s << NFormat( "%s ", player[i].sex); if (~opt[5]) s << NFormat( "%3.3s ", player[i].codetitle); if (~opt[6]) s << NFormat( "%8d ", player[i].idfide); if (~opt[7]) s << NFormat( "%5d ", player[i].ratingfide); if (~opt[8]) s << NFormat( "%8d ", player[i].idnat); if (~opt[9]) s << NFormat( "%5d ", player[i].ratingnat); if (~opt[10]) s << NFormat( "%2d ", player[i].kcoeff); if (~opt[11]) s << NFormat( "%2s", player[i].isAvailable); out.PutLine(s); } } out.PutLine("\n The following player(s) withdrew:\n"); for (i=1; i<=TD.NPlayer; i++) { String s = ""; if (player[i].isAvailable== "0") { if (~opt[0]) s << NFormat( "%3d ", i); if (~opt[1]) s << NFormat( "%-25.25s ", player[i].name); if (~opt[2]) s << NFormat( "%3.3s ", player[i].country); if (~opt[3]) s << NFormat( "%8.8s ", player[i].data); if (~opt[4]) s << NFormat( "%s ", player[i].sex); if (~opt[5]) s << NFormat( "%3.3s ", player[i].codetitle); if (~opt[6]) s << NFormat( "%8d ", player[i].idfide); if (~opt[7]) s << NFormat( "%5d ", player[i].ratingfide); if (~opt[8]) s << NFormat( "%8d ", player[i].idnat); if (~opt[9]) s << NFormat( "%5d ", player[i].ratingnat); if (~opt[10]) s << NFormat( "%2d ", player[i].kcoeff); if (~opt[11]) s << NFormat( "%2s", player[i].isAvailable); out.PutLine(s); } } } out.Close(); Close(); printed = true; } void PrintTableDlg::PrintPartecipantsHTML() { int i; String name[12]; name[0] = "ID"; name[1] = "Name"; name[2] = "Fed"; name[3] = "Birthday"; name[4] = "Gender"; name[5] = "Title"; name[6] = "ID_FIDE"; name[7] = "RtgF"; name[8] = "ID_Nat"; name[9] = "RtgN"; name[10]= "K"; name[11]= "Status"; // produce HTML files FileOut savehtml(TD.PATHDIRWWW + "players.html"); savehtml << TD.HTMLCommonHeader(); savehtml << TD.HTMLNavBar(); savehtml << "

" << TD.NAMETORNEO << "

\n"; savehtml << "

" << TD.PLACETORNEO << " - " << TD.DATATORNEO_B <<", "<\n"; savehtml << "

List of participants

\n"; savehtml << " \n"; savehtml << "\n"; savehtml << ""; for (i=0; i<=10; i++) //exclude the Status field if (~opt[i]) savehtml << name[i]; savehtml << "\n"; for (i=1; i<=TD.NPlayer; i++) { if ((i+1)&1) savehtml << " "; else savehtml << " "; if (~opt[0]) savehtml << NFormat( " ", i); if (~opt[1]) savehtml << NFormat( "", AsString(arr->Get(i-1, "Name")) ); if (~opt[2]) savehtml << NFormat( "", AsString(arr->Get(i-1, "Country"))); if (~opt[3]) savehtml << NFormat( "", AsString(arr->Get(i-1, "Birthday"))); if (~opt[4]) savehtml << NFormat( "", AsString(arr->Get(i-1, "Gender"))); if (~opt[5]) savehtml << NFormat( "", AsString(arr->Get(i-1, "Title"))); if (~opt[6]) savehtml << NFormat( "", AsString(arr->Get(i-1, "IDFIDE"))); if (~opt[7]) savehtml << NFormat( "", AsString(arr->Get(i-1, "RatFIDE"))); if (~opt[8]) savehtml << NFormat( "", AsString(arr->Get(i-1, "IDNat"))); if (~opt[9]) savehtml << NFormat( "", AsString(arr->Get(i-1, "RatNat"))); if (~opt[10]) savehtml << NFormat( "", AsString(arr->Get(i-1, "K"))); savehtml << " \n"; } savehtml << "\n"; savehtml << "
%d%s%s%s%s%s%s%s%s%s%s
\n"; savehtml << "

Generated by Vega

\n"; savehtml << "\n\n"; savehtml.Close(); } /***************************** ModifyCrossTable Dialog ****************************/ ModifyCrossTableDlg::ModifyCrossTableDlg(int idplayer) { CtrlLayout(*this, "Modify the Cross Table"); id = idplayer; lblPlayer.SetLabel( AsString(id) + " " + player[id].name); edtRound <<= TD.currentRound; edtRound.Tip(t_("Set the round to display all other data")); //edtRes <<= "0"; edtOpp.Tip(t_("Game against player 0=BYE&is considered forfeited")); edtRes.Add("0"); edtRes.Add("½"); edtRes.Add("1"); edtRes.Add("Null"); edtRes.Tip(t_("'Null' set the game as 'unplayed'")); edtCol.Add("White"); edtCol.Add("Black"); edtCol.Add("NOCOL"); edtCol.Add("NO TB"); FillEditCB(); btnClose.WhenAction = THISBACK(Close); btnOk.WhenAction = THISBACK(DoneCB); edtRound.WhenAction = THISBACK(FillEditCB); } void ModifyCrossTableDlg::FillEditCB() { int round = StrIntValue(AsString(~edtRound)); if (round<1 || round>TD.currentRound) { Exclamation(t_("Round out of range")); return; } if (TD.IS_SWISS) { int opp = TD.playerOpponent[id][round]; int col = TD.playerColor[id][round]; int res = TD.roundResult[id][round]; edtOpp <<= opp; if (opp==0 || col==0) edtCol <<= "NOCOL"; else if (col == 1) edtCol <<= "White"; else if (col == -1) edtCol <<= "Black"; else if (res == 8) edtCol <<= "NO TB"; if (res == 0 || res == 4) edtRes <<= "0"; else if (res == 1 || res == 3) edtRes <<= "1"; else if (res == 2 || res == 6) edtRes <<= "½"; else if (opp==0 && col==0 && res==0) edtRes <<= "Null"; } else { int opp = TD.playerOpponentRR[id][round]; int col = TD.playerColorRR[id][round]; int res = TD.roundResultRR[id][round]; edtOpp <<= opp; if (opp==0 || col==0) edtCol <<= "NOCOL"; else if (col == 1) edtCol <<= "White"; else if (col == -1) edtCol <<= "Black"; else if (res == 8) edtCol <<= "NO TB"; if (res == 0 || res == 4) edtRes <<= "0"; else if (res == 1 || res == 3) edtRes <<= "1"; else if (res == 2 || res == 6) edtRes <<= "½"; else if (opp==0 && col==0 && res==0) edtRes <<= "Null"; } } void ModifyCrossTableDlg::DoneCB() { String res, col; int round, idOpp; round = StrIntValue(AsString(~edtRound)); if (round<1 || round>TD.currentRound) { Exclamation(t_("Round out of range")); return; } idOpp = StrIntValue(AsString(~edtOpp)); if (idOpp<0 || idOpp>TD.NPlayer || idOpp==id) { Exclamation(t_("Set a valid opponent for the selected player")); return; } if (TD.IS_SWISS) { //swiss if (idOpp == 0) TD.playerOpponent[id][round] = 0; else TD.playerOpponent[id][round] = idOpp; res = AsString(~edtRes); if ( res=="Null" ) {TD.playerOpponent[id][round] = TD.roundResult[id][round] = TD.playerColor[id][round] = 0; TD.AdjournCrossTableSwiss(TD.currentRound); //return; Close(); } if (idOpp==0) { if ( res=="1" ) TD.roundResult[id][round] = 3; else if ( res=="½" ) TD.roundResult[id][round] = 6; else if ( res=="0" ) TD.roundResult[id][round] = 4; } else { if ( res=="1" ) TD.roundResult[id][round] = 1; else if ( res=="½" ) TD.roundResult[id][round] = 2; else if ( res=="0" ) TD.roundResult[id][round] = 0; } col = AsString(~edtCol); if ( col == "NOCOL" ) TD.playerColor[id][round] = 0; //NO_COLOR; else if ( col == "Black" ) TD.playerColor[id][round] = -1; //BLACK_COLOR; else if ( col == "White" ) TD.playerColor[id][round] = 1; //WHITE_COLOR; else { TD.playerColor[id][round] = 0; TD.roundResult[id][round] = 8; // generic code for forfeited game with no bucholz } TD.AdjournCrossTableSwiss(TD.currentRound); } else { // round robin if (idOpp == 0) TD.playerOpponentRR[id][round] = 0; else TD.playerOpponentRR[id][round] = idOpp; res = AsString(~edtRes); if ( res=="Null" ) { TD.playerOpponentRR[id][round] = TD.roundResultRR[id][round] = TD.playerColorRR[id][round] = 0; TD.AdjournCrossTableRR(TD.currentRound); Close(); //return; } if (idOpp==0) { if ( res=="1" ) TD.roundResultRR[id][round] = 3; else if ( res=="½" ) TD.roundResultRR[id][round] = 6; else if ( res=="0" ) TD.roundResultRR[id][round] = 4; } else { if ( res=="1" ) TD.roundResultRR[id][round] = 1; else if ( res=="½" ) TD.roundResultRR[id][round] = 2; else if ( res=="0" ) TD.roundResultRR[id][round] = 0; } col = AsString(~edtCol); if ( col == "NOCOL" ) TD.playerColorRR[id][round] = 0; //NO_COLOR; else if ( col == "Black" ) TD.playerColorRR[id][round] = -1; //BLACK_COLOR; else if ( col == "White" ) TD.playerColorRR[id][round] = 1; //WHITE_COLOR; else { TD.playerColorRR[id][round] = 0; TD.roundResultRR[id][round] = 8; // generic code for forfeited game with no bucholz } TD.AdjournCrossTableRR(TD.currentRound); } Close(); }