Skip to content

Commit

Permalink
Improvement to civilization button icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed May 17, 2016
1 parent d33be51 commit 6600bd9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/ui/botpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,32 @@ void CButtonPanel::Draw()
//
const PixelPos pos(UI.ButtonPanel.Buttons[i].X, UI.ButtonPanel.Buttons[i].Y);

//Wyrmgus start
CIcon *button_icon = buttons[i].Icon.Icon;

// if there is a single unit selected, show the icon of its weapon/shield/boots/arrows equipped for the appropriate buttons
if (buttons[i].Icon.Name.empty() && buttons[i].Action == ButtonAttack && Selected[0]->Type->CanTransport() && Selected[0]->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value && Selected[0]->Type->CanAttack && Selected[0]->BoardCount > 0 && Selected[0]->UnitInside != NULL && Selected[0]->UnitInside->GetButtonIcon(buttons[i].Action) != NULL) {
button_icon = Selected[0]->UnitInside->GetButtonIcon(buttons[i].Action);
} else if (buttons[i].Icon.Name.empty() && Selected[0]->GetButtonIcon(buttons[i].Action) != NULL) {
button_icon = Selected[0]->GetButtonIcon(buttons[i].Action);
} else if ((buttons[i].Action == ButtonTrain || buttons[i].Action == ButtonBuild || buttons[i].Action == ButtonUpgradeTo || buttons[i].Action == ButtonExperienceUpgradeTo) && buttons[i].Icon.Name.empty() && UnitTypes[buttons[i].Value]->GetDefaultVariation(*ThisPlayer) != NULL && !UnitTypes[buttons[i].Value]->GetDefaultVariation(*ThisPlayer)->Icon.Name.empty()) {
button_icon = UnitTypes[buttons[i].Value]->GetDefaultVariation(*ThisPlayer)->Icon.Icon;
} else if ((buttons[i].Action == ButtonTrain || buttons[i].Action == ButtonBuild || buttons[i].Action == ButtonUpgradeTo || buttons[i].Action == ButtonExperienceUpgradeTo) && buttons[i].Icon.Name.empty() && !UnitTypes[buttons[i].Value]->Icon.Name.empty()) {
button_icon = UnitTypes[buttons[i].Value]->Icon.Icon;
}
//Wyrmgus end

if (cooldownSpell) {
buttons[i].Icon.Icon->DrawCooldownSpellIcon(pos,
//Wyrmgus start
// buttons[i].Icon.Icon->DrawCooldownSpellIcon(pos,
button_icon->DrawCooldownSpellIcon(pos,
//Wyrmgus end
maxCooldown * 100 / SpellTypeTable[buttons[i].Value]->CoolDown);
} else if (gray) {
buttons[i].Icon.Icon->DrawGrayscaleIcon(pos);
//Wyrmgus start
// buttons[i].Icon.Icon->DrawGrayscaleIcon(pos);
button_icon->DrawGrayscaleIcon(pos);
//Wyrmgus end
} else {
int player = -1;
if (Selected.empty() == false && Selected[0]->IsAlive()) {
Expand All @@ -1213,18 +1234,6 @@ void CButtonPanel::Draw()
pos, buf, player);
*/

CIcon *button_icon = buttons[i].Icon.Icon;

// if there is a single unit selected, show the icon of its weapon/shield/boots/arrows equipped for the appropriate buttons
if (buttons[i].Icon.Name.empty() && buttons[i].Action == ButtonAttack && Selected[0]->Type->CanTransport() && Selected[0]->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value && Selected[0]->Type->CanAttack && Selected[0]->BoardCount > 0 && Selected[0]->UnitInside != NULL && Selected[0]->UnitInside->GetButtonIcon(buttons[i].Action) != NULL) {
button_icon = Selected[0]->UnitInside->GetButtonIcon(buttons[i].Action);
} else if (buttons[i].Icon.Name.empty() && Selected[0]->GetButtonIcon(buttons[i].Action) != NULL) {
button_icon = Selected[0]->GetButtonIcon(buttons[i].Action);
} else if ((buttons[i].Action == ButtonTrain || buttons[i].Action == ButtonBuild || buttons[i].Action == ButtonUpgradeTo || buttons[i].Action == ButtonExperienceUpgradeTo) && buttons[i].Icon.Name.empty() && UnitTypes[buttons[i].Value]->GetDefaultVariation(*ThisPlayer) != NULL && !UnitTypes[buttons[i].Value]->GetDefaultVariation(*ThisPlayer)->Icon.Name.empty()) {
button_icon = UnitTypes[buttons[i].Value]->GetDefaultVariation(*ThisPlayer)->Icon.Icon;
} else if ((buttons[i].Action == ButtonTrain || buttons[i].Action == ButtonBuild || buttons[i].Action == ButtonUpgradeTo || buttons[i].Action == ButtonExperienceUpgradeTo) && buttons[i].Icon.Name.empty() && !UnitTypes[buttons[i].Value]->Icon.Name.empty()) {
button_icon = UnitTypes[buttons[i].Value]->Icon.Icon;
}
button_icon->DrawUnitIcon(*UI.ButtonPanel.Buttons[i].Style,
GetButtonStatus(buttons[i], ButtonUnderCursor),
pos, buf, player);
Expand Down
14 changes: 14 additions & 0 deletions src/unit/script_unittype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ static int CclDefineUnitType(lua_State *l)
type->RemoveButtons(ButtonAttack);
type->RemoveButtons(ButtonPatrol);
type->RemoveButtons(ButtonStandGround);
type->RemoveButtons(ButtonReturn);
//Wyrmgus end
} else {
type = NewUnitTypeSlot(str);
Expand Down Expand Up @@ -2171,6 +2172,19 @@ static int CclDefineUnitType(lua_State *l)
CclCommand(button_definition);
}

if (type->BoolFlag[HARVESTER_INDEX].value) {
std::string button_definition = "DefineButton({\n";
button_definition += "\tPos = 5,\n";
button_definition += "\tLevel = 0,\n";
button_definition += "\tAction = \"return-goods\",\n";
button_definition += "\tPopup = \"popup-commands\",\n";
button_definition += "\tKey = \"g\",\n";
button_definition += "\tHint = _(\"Return with ~!Goods\"),\n";
button_definition += "\tForUnit = {\"" + type->Ident + "\"},\n";
button_definition += "})";
CclCommand(button_definition);
}

// make units allowed by default
for (int i = 0; i < PlayerMax; ++i) {
AllowUnitId(Players[i], type->Slot, 65536);
Expand Down
3 changes: 3 additions & 0 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,9 @@ void CUnit::UpdateButtonIcons()
this->ChooseButtonIcon(ButtonMove);
this->ChooseButtonIcon(ButtonStandGround);
this->ChooseButtonIcon(ButtonPatrol);
if (this->Type->BoolFlag[HARVESTER_INDEX].value) {
this->ChooseButtonIcon(ButtonReturn);
}
}

void CUnit::ChooseButtonIcon(int button_action)
Expand Down

0 comments on commit 6600bd9

Please sign in to comment.