1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

big images; basic heroes support

This commit is contained in:
Michael 2023-08-12 13:19:58 +02:00 committed by GitHub
parent d0522b0fee
commit b4f6c7abab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 19 deletions

View File

@ -80,7 +80,7 @@ void OptionsTab::recreate()
} }
} }
size_t OptionsTab::CPlayerSettingsHelper::getImageIndex() size_t OptionsTab::CPlayerSettingsHelper::getImageIndex(bool big)
{ {
enum EBonusSelection //frames of bonuses file enum EBonusSelection //frames of bonuses file
{ {
@ -104,7 +104,7 @@ size_t OptionsTab::CPlayerSettingsHelper::getImageIndex()
case PlayerSettings::RANDOM: case PlayerSettings::RANDOM:
return TOWN_RANDOM; return TOWN_RANDOM;
default: default:
return (*CGI->townh)[factionIndex]->town->clientInfo.icons[true][false] + 2; return (*CGI->townh)[factionIndex]->town->clientInfo.icons[true][false] + (big ? 0 : 2);
} }
case HERO: case HERO:
switch(settings.hero) switch(settings.hero)
@ -161,14 +161,14 @@ size_t OptionsTab::CPlayerSettingsHelper::getImageIndex()
return 0; return 0;
} }
std::string OptionsTab::CPlayerSettingsHelper::getImageName() std::string OptionsTab::CPlayerSettingsHelper::getImageName(bool big)
{ {
switch(type) switch(type)
{ {
case OptionsTab::TOWN: case OptionsTab::TOWN:
return "ITPA"; return big ? "ITPt": "ITPA";
case OptionsTab::HERO: case OptionsTab::HERO:
return "PortraitsSmall"; return big ? "PortraitsLarge": "PortraitsSmall";
case OptionsTab::BONUS: case OptionsTab::BONUS:
return "SCNRSTAR"; return "SCNRSTAR";
} }
@ -422,7 +422,7 @@ OptionsTab::SelectionWindow::SelectionWindow(PlayerSettings settings, PlayerInfo
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
pos = Rect(0, 0, 400, 400); pos = Rect(0, 0, 700, 700);
backgroundTexture = std::make_shared<CFilledTexture>("DIBOXBCK", pos); backgroundTexture = std::make_shared<CFilledTexture>("DIBOXBCK", pos);
updateShadow(); updateShadow();
@ -438,20 +438,20 @@ void OptionsTab::SelectionWindow::genContentCastles(PlayerSettings settings, Pla
PlayerSettings set = PlayerSettings(); PlayerSettings set = PlayerSettings();
set.castle = set.RANDOM; set.castle = set.RANDOM;
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN); CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, 0, 0)); components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, (ELEMENTS_PER_LINE / 2) * 58 + (58 - 48) / 2, (64 - 32) / 2));
int i = 0; int i = 0;
for(auto & elem : playerInfo.allowedFactions) for(auto & elem : playerInfo.allowedFactions)
{ {
int x = i%3; int x = i % ELEMENTS_PER_LINE;
int y = i/3+1; int y = i / ELEMENTS_PER_LINE + 1;
PlayerSettings set = PlayerSettings(); PlayerSettings set = PlayerSettings();
set.castle = elem; set.castle = elem;
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN); CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, x * 48, y * 32)); components.push_back(std::make_shared<CAnimImage>(helper.getImageName(true), helper.getImageIndex(true), 0, x * 58, y * 64));
factions.push_back(elem); factions.push_back(elem);
i++; i++;
@ -460,7 +460,29 @@ void OptionsTab::SelectionWindow::genContentCastles(PlayerSettings settings, Pla
void OptionsTab::SelectionWindow::genContentHeroes(PlayerSettings settings, PlayerInfo playerInfo) void OptionsTab::SelectionWindow::genContentHeroes(PlayerSettings settings, PlayerInfo playerInfo)
{ {
std::vector<bool> allowedHeroesFlag = SEL->getMapInfo()->mapHeader->allowedHeroes;
std::set<HeroTypeID> allowedHeroes;
for(int i = 0; i < allowedHeroesFlag.size(); i++)
if(allowedHeroesFlag[i])
allowedHeroes.insert(HeroTypeID(i));
int i = 0;
for(auto & elem : allowedHeroes)
{
int x = (i % ELEMENTS_PER_LINE) + (ELEMENTS_PER_LINE + 1);
int y = i / ELEMENTS_PER_LINE + 1;
PlayerSettings set = PlayerSettings();
set.hero = elem;
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(true), helper.getImageIndex(true), 0, x * 58, y * 64));
heroes.push_back(elem);
i++;
}
} }
void OptionsTab::SelectionWindow::apply() void OptionsTab::SelectionWindow::apply()
@ -477,13 +499,13 @@ FactionID OptionsTab::SelectionWindow::getElementCastle(const Point & cursorPosi
FactionID faction; FactionID faction;
faction = PlayerSettings().NONE; faction = PlayerSettings().NONE;
if (loc.x == 0 && loc.y == 0) if (loc.x == ELEMENTS_PER_LINE / 2 && loc.y == 0)
faction = PlayerSettings().RANDOM; faction = PlayerSettings().RANDOM;
else if(loc.y > 0 && loc.x < 3) else if(loc.y > 0 && loc.x < ELEMENTS_PER_LINE)
{ {
int index = loc.x + (loc.y - 1) * 3; int index = loc.x + (loc.y - 1) * ELEMENTS_PER_LINE;
if (index < factions.size()) if (index < factions.size())
faction = factions[loc.x + (loc.y - 1) * 3]; faction = factions[loc.x + (loc.y - 1) * ELEMENTS_PER_LINE];
} }
return faction; return faction;
@ -501,8 +523,8 @@ int OptionsTab::SelectionWindow::getElementBonus(const Point & cursorPosition)
Point OptionsTab::SelectionWindow::getElement(const Point & cursorPosition) Point OptionsTab::SelectionWindow::getElement(const Point & cursorPosition)
{ {
int x = (cursorPosition.x - pos.x) / 48; int x = (cursorPosition.x - pos.x) / 58;
int y = (cursorPosition.y - pos.y) / 32; int y = (cursorPosition.y - pos.y) / 64;
return Point(x, y); return Point(x, y);
} }

View File

@ -61,8 +61,8 @@ public:
{} {}
/// visible image settings /// visible image settings
size_t getImageIndex(); size_t getImageIndex(bool big = false);
std::string getImageName(); std::string getImageName(bool big = false);
std::string getName(); /// name visible in options dialog std::string getName(); /// name visible in options dialog
std::string getTitle(); /// title in popup box std::string getTitle(); /// title in popup box
@ -97,11 +97,13 @@ public:
class SelectionWindow : public CWindowObject class SelectionWindow : public CWindowObject
{ {
const int ELEMENTS_PER_LINE = 5;
std::shared_ptr<CFilledTexture> backgroundTexture; std::shared_ptr<CFilledTexture> backgroundTexture;
std::vector<std::shared_ptr<CIntObject>> components; std::vector<std::shared_ptr<CIntObject>> components;
std::vector<FactionID> factions; std::vector<FactionID> factions;
std::vector<SHeroName> heroes; std::vector<HeroTypeID> heroes;
void genContentCastles(PlayerSettings settings, PlayerInfo playerInfo); void genContentCastles(PlayerSettings settings, PlayerInfo playerInfo);
void genContentHeroes(PlayerSettings settings, PlayerInfo playerInfo); void genContentHeroes(PlayerSettings settings, PlayerInfo playerInfo);