Skip to content

Commit

Permalink
Collections wip gui
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Apr 27, 2024
1 parent 5683dd4 commit 5c9bded
Show file tree
Hide file tree
Showing 10 changed files with 734 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/common/GuiCom_Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const int CGui::colCar[16] = {34, 80, 27, wi, wi, wi, wi, 37, 45, 24}; // car
const int CGui::colCh [16] = {16, 200, 120, 50, 80, 80, 60, 40}; // champs
const int CGui::colChL[16] = {16, 180, 90, 100, 50, 60, 60, 60, 50}; // challs
const int CGui::colSt [16] = {30, 170, 100, 90, 50, 80, 70}; // stages
const int CGui::colCol[16] = {16, 180, 90, 100, 50, 50}; // collect
#endif

// get scenery color string from track name
Expand Down
4 changes: 1 addition & 3 deletions src/common/data/CollectXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ bool CollectXml::LoadXml(std::string file, TracksIni* trks, bool check)
if (eSim)
{
a = eSim->Attribute("mode"); if (a) c.sim_mode = std::string(a);
a = eSim->Attribute("abs"); if (a) c.abs = s2i(a) > 0;
a = eSim->Attribute("tcs"); if (a) c.tcs = s2i(a) > 0;

a = eSim->Attribute("damage"); if (a) c.damage_type = s2i(a); // range chk..

Expand All @@ -68,7 +66,7 @@ bool CollectXml::LoadXml(std::string file, TracksIni* trks, bool check)

// track
XMLElement* eTr = eCol->FirstChildElement("track");
while (eTr)
if (eTr)
{
a = eTr->Attribute("name"); if (a) c.track = std::string(a);
}
Expand Down
3 changes: 1 addition & 2 deletions src/common/data/CollectXml.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ class Collect
std::string sim_mode = "normal";
int damage_type = 2, boost_type = 1, flip_type = 2, rewind_type = 1;

// Hud
// Hud-
bool minimap = 1, chk_arr = 0, chk_beam = 0,
trk_ghost = 0, pacenotes = 0, trail = 0; // deny using it if false
bool abs = 0, tcs = 0; // deny if false

// Pass -1 means not needed, you can use one or more conditions
// float totalTime = -1.f, avgPoints = -1.f, avgPos = -1.f;
Expand Down
2 changes: 1 addition & 1 deletion src/game/CGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class CGui : public BGui

// 🚗📃 Car list (all Car = Vehicle)
///---------------------------------------------------
const static int colCar[16],colCh[16],colChL[16],colSt[16];
const static int colCar[16],colCh[16],colChL[16],colSt[16],colCol[16];

void CarListUpd(bool resetNotFound=false);
void AddCarL(std::string name, const CarInfo* ci);
Expand Down
5 changes: 4 additions & 1 deletion src/game/CGui_Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ void CGui::btnMainMenu(WP wp)
case Games_Tutorial: pSet->iMenu = MN_Tutorial; break;
case Games_Champ: pSet->iMenu = MN_Champ; break;
case Games_Challenge: pSet->iMenu = MN_Chall; break;

case Games_Collection: pSet->iMenu = MN_Collect; break;
case Games_Career: pSet->iMenu = MN_Career; break; // todo
case Games_Back: pSet->iMenu = MN1_Setup; break;
}
app->gui->toggleGui(false);
Expand Down Expand Up @@ -178,7 +181,7 @@ void CGui::tabMainMenu(Tab tab, size_t id)
if (id != 0) return; // <back
tab->setIndexSelected(1); // dont switch to 0

if (pSet->iMenu >= MN_Single && pSet->iMenu <= MN_Chall)
if (pSet->iMenu >= MN_Single && pSet->iMenu <= MN_Career)
pSet->iMenu = MN1_Games;
else
pSet->iMenu = MN1_Main;
Expand Down
45 changes: 8 additions & 37 deletions src/game/Challenges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ void CGui::BackFromChs()
{
pSet->gui.champ_num = -1;
pSet->gui.chall_num = -1;
pSet->gui.collect_num = -1;
pChall = 0;
CarListUpd(); // off filtering
}

bool CGui::isChallGui()
{
//return imgChall && imgChall->getVisible();
return pSet->iMenu == MN_Chall;
}

Expand All @@ -43,7 +43,7 @@ void CGui::tabChallType(Tab wp, size_t id)
#define MAX_CHL_TYP 11


/// Challenges list fill
/// 🥇📃 Challenges list fill
//----------------------------------------------------------------------------------------------------------------------
void CGui::ChallsListUpdate()
{
Expand Down Expand Up @@ -103,7 +103,7 @@ void CGui::fillChallsList(std::vector<int> vIds)
liChalls->addItem(""/*clr+ toStr(n/10)+toStr(n%10)*/, i+1); int l = liChalls->getItemCount()-1;
liChalls->setSubItemNameAt(1,l, clr+ chl.nameGui.c_str());
liChalls->setSubItemNameAt(2,l, gcom->clrsDiff[chl.diff]+ TR("#{Diff"+toStr(chl.diff)+"}"));
liChalls->setSubItemNameAt(3,l, StrChallCars(chl));
liChalls->setSubItemNameAt(3,l, chl.cars.GetStr(data->cars));

liChalls->setSubItemNameAt(4,l, gcom->clrsDiff[std::min(8,ntrks*2/3+1)]+ iToStr(ntrks,3));
liChalls->setSubItemNameAt(5,l, gcom->clrsDiff[std::min(8,int(chl.time/3.f/60.f))]+ StrTime2(chl.time));
Expand Down Expand Up @@ -149,45 +149,15 @@ void CGui::listChallChng(MyGUI::MultiList2* chlist, size_t id)
}


// list allowed cars types and cars
String CGui::StrChallCars(const Chall& ch)
{
String str;
int i,s;

s = ch.carTypes.size();
for (i=0; i < s; ++i)
{
const String& ct = ch.carTypes[i];
str += data->cars->colormap[ct]; // car type color
str += ct;
if (i+1 < s) str += ",";
}
//int id = data->carsXml.carmap[*i];
//data->carsXml.cars[id-1];
if (!str.empty())
str += " ";

s = ch.cars.size();
for (i=0; i < s; ++i)
{
const String& c = ch.cars[i];
int id = data->cars->carmap[c]-1; // get car color from type
if (id >= 0) str += data->cars->colormap[ data->cars->cars[id].type ];
str += c;
if (i+1 < s) str += ",";
}
return str;
}

// chall allows car
bool CGui::IsChallCar(String name)
{
if (!liChalls || liChalls->getIndexSelected()==ITEM_NONE) return true;

int chId = *liChalls->getItemDataAt<int>(liChalls->getIndexSelected())-1;
int id = *liChalls->getItemDataAt<int>(liChalls->getIndexSelected())-1;

return data->IsChallCar(&data->chall->all[chId], name);
return data->chall->all[id].cars.Allows(data->cars, name);
// return data->IsChallCar(&data->chall->all[chId], name);
}


Expand All @@ -198,6 +168,7 @@ void CGui::btnChallStart(WP)
if (liChalls->getIndexSelected()==ITEM_NONE) return;
pSet->gui.champ_num = -1;
pSet->gui.chall_num = *liChalls->getItemDataAt<int>(liChalls->getIndexSelected())-1;
pSet->gui.collect_num = -1;

// if already finished, restart - will loose progress and scores ..
int chId = pSet->gui.chall_num, p = pSet->game.champ_rev ? 1 : 0;
Expand Down Expand Up @@ -607,7 +578,7 @@ void CGui::UpdChallDetail(int id)

// cars --------
s1 += "\n"; s2 += "\n";
s1 += TR("#F08080#{Vehicles}\n"); s2 += "#FFA0A0" + StrChallCars(ch)+"\n";
s1 += TR("#F08080#{Vehicles}\n"); s2 += "#FFA0A0" + ch.cars.GetStr(data->cars)+"\n";
if (ch.carChng)
{ s1 += TR("#C0B0B0#{CarChange}\n"); s2 += TR("#A0B8A0#{Allowed}")+"\n"; }

Expand Down
61 changes: 47 additions & 14 deletions src/game/ChampChall.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "pch.h"
#include "Def_Str.h"
#include "settings.h"
#include "CData.h"
#include "TracksXml.h"
#include "ChampsXml.h"
#include "ChallengesXml.h"
#include "CollectXml.h"
#include "GuiCom.h"
#include "paths.h"
#include "game.h"
Expand All @@ -24,14 +26,17 @@ using namespace MyGUI;
///______________________________________________________________________________________________
void App::Ch_NewGame()
{
if (pSet->game.champ_num >= (int)data->champs->all.size() ||
pSet->game.chall_num >= (int)data->chall->all.size()) // range
{ pSet->game.champ_num = -1;
pSet->game.chall_num = -1; }
// range
int& iChamp = pSet->game.champ_num;
int& iChall = pSet->game.chall_num;
int& iCollect = pSet->game.collect_num;
if (iChamp >= (int)data->champs->all.size()) iChamp = -1;
if (iChall >= (int)data->chall->all.size()) iChall = -1;
if (iCollect >= (int)data->collect->all.size()) iCollect = -1;

pGame->timer.end_sim = false;
int iChamp = pSet->game.champ_num;
int iChall = pSet->game.chall_num;

//---------------------------------------------------------
if (iChall >= 0)
{
/// 🥇 challenge stage
Expand Down Expand Up @@ -76,6 +81,7 @@ void App::Ch_NewGame()
pGame->pause = true; // wait for stage wnd close
pGame->timer.waiting = true;
}
//---------------------------------------------------------
else if (iChamp >= 0)
{
/// 🏆 championship stage
Expand All @@ -98,7 +104,27 @@ void App::Ch_NewGame()

pGame->pause = true; // wait for stage wnd close
pGame->timer.waiting = true;
}else
}
//---------------------------------------------------------
else if (iCollect >= 0)
{
/// 💎 collection
ProgressCollect& pc = gui->progressC.chs[iCollect];
const Collect& col = data->collect->all[iCollect];
// const ChampTrack& trk = ch.trks[pc.curTrack];
pSet->game.track = col.track; pSet->game.track_user = 0;
pSet->game.track_reversed = 0;
pSet->game.num_laps = 0;

pSet->game.boost_type = col.boost_type;
pSet->game.flip_type = col.flip_type;
pSet->game.rewind_type = col.rewind_type;
pSet->game.BoostDefault(); //

pGame->pause = false; // wait for wnd close ..?
pGame->timer.waiting = true;
}
else
{ pGame->pause = false; // single race
pGame->timer.waiting = false;
}
Expand Down Expand Up @@ -146,29 +172,36 @@ int App::GetRacePos(float timeCur, float timeTrk, float carTimeMul, bool coldSta

/// 🪟 upd Gui vis tutor champ chall
//-----------------------------------------------------------------------------------------------
void CGui::UpdChampTabVis()
void CGui::UpdChsTabVis()
{
if (!liChamps || !tabChamp || !btStChamp) return;
if (!liChamps || !tabChamp || !btStChamp || !btStCollect) return;
bool game = pSet->iMenu == MN_Single, champ = pSet->iMenu == MN_Champ,
tutor = pSet->iMenu == MN_Tutorial, chall = pSet->iMenu == MN_Chall;
bool any = tutor || champ || chall;
tutor = pSet->iMenu == MN_Tutorial, chall = pSet->iMenu == MN_Chall,
collect = pSet->iMenu == MN_Collect, career = pSet->iMenu == MN_Career;
bool chAny = tutor || champ || chall || collect || career;

imgTut->setVisible(tutor); btStTut->setVisible(tutor);
tabChamp->setVisible(champ); imgChamp->setVisible(champ); btStChamp->setVisible(champ);
tabChall->setVisible(chall); imgChall->setVisible(chall); btStChall->setVisible(chall);
btNewGameCar->setVisible(!any);
btNewGameCar->setVisible(!chAny);
imgCollect->setVisible(collect); btStCollect->setVisible(collect);
imgCareer->setVisible(career);

liChamps->setVisible(!chall); liChamps->setColour(tutor ? Colour(0.85,0.8,0.75) : Colour(0.75,0.8,0.85));
liChalls->setVisible( chall); liChalls->setColour(Colour(0.74,0.7,0.82));
liCollect->setVisible( collect); liCollect->setColour(Colour(1,0.74,0.7));
panCh->setColour(tutor ? Colour(0.9,0.8,0.7) : champ ? Colour(0.7,0.9,0.8) : Colour(0.77,0.75,0.92));

if (chall) ChallsListUpdate();
else ChampsListUpdate();
if (collect) CollectListUpdate(); else
if (chall) ChallsListUpdate(); else
ChampsListUpdate();

//if (pSet->inRace == Race_Single)
// BackFromChs();

edChInfo->setCaption(
career ? "" :
collect ? TR("#{CollectInfo}") :
chall ? TR("#{ChallInfo2}")+"\n"+TR("#{ChallInfo}") :
tutor ? TR("#{TutorInfo}")+"\n"+TR("#{ChampInfo}") :
TR("#{ChampInfo2}")+"\n"+TR("#{ChampInfo}"));
Expand Down
17 changes: 16 additions & 1 deletion src/game/Championships.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ void CGui::updChampListDim()
xt = 0.03*wi.width, yt = 0.10*wi.height; // pos
liChalls->setCoord(xt, yt, sw + 8/**/, 0.40/*height*/*wi.height);
liChalls->setVisible(isChallGui());

// Collect -----
if (!liCollect) return;

sum = 0; cnt = liCollect->getColumnCount(); sw = 0;
for (c=0; c < cnt; ++c) sum += colCol[c];
for (c=0; c < cnt; ++c)
{
w = c==cnt-1 ? 18 : float(colCol[c]) / sum * 0.76/*width*/ * wi.width * 0.97/**/;
liCollect->setColumnWidthAt(c, w); sw += w;
}
xt = 0.03*wi.width, yt = 0.10*wi.height; // pos
liCollect->setCoord(xt, yt, sw + 8/**/, 0.40/*height*/*wi.height);
liCollect->setVisible(isCollectGui());
}


Expand Down Expand Up @@ -238,8 +252,9 @@ void CGui::listChampChng(MyGUI::MultiList2* chlist, size_t id)
void CGui::btnChampStart(WP)
{
if (liChamps->getIndexSelected()==ITEM_NONE) return;
pSet->gui.chall_num = -1;
pSet->gui.champ_num = *liChamps->getItemDataAt<int>(liChamps->getIndexSelected())-1;
pSet->gui.chall_num = -1;
pSet->gui.collect_num = -1;

// if already finished, restart - will loose progress and scores ..
int chId = pSet->gui.champ_num, p = pSet->game.champ_rev ? 1 : 0;
Expand Down
Loading

0 comments on commit 5c9bded

Please sign in to comment.