Skip to content

Commit

Permalink
The single-selected unit button popup now has information on its stat…
Browse files Browse the repository at this point in the history
…s, and right-clicking the button leads to its encyclopedia entry
  • Loading branch information
Andrettin committed Mar 30, 2016
1 parent 0e4abab commit 59f5cbf
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 31 deletions.
3 changes: 0 additions & 3 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ void StartMap(const std::string &filename, bool clean)
Invalidate();

CleanGame();
//Wyrmgus start
CleanPlayers();
//Wyrmgus end
InterfaceState = IfaceStateMenu;
SetDefaultTextColors(nc, rc);

Expand Down
18 changes: 11 additions & 7 deletions src/include/ui/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class PopupConditionPanel
public:
PopupConditionPanel() : HasHint(false), HasDescription(false), HasDependencies(false),
//Wyrmgus start
Description(false), Quote(false),
AutoCast(0), Equipped(0), Equippable(0), Consumable(0), Affixed(0), Spell(0), CanUse(0), Work(0), ReadWork(0), Unique(0), Bound(0), Weapon(0), Shield(0), Boots(0), Arrows(0), Regeneration(0),
Class(false), Description(false), Quote(false), Encyclopedia(false),
Opponent(0), Neutral(0), AutoCast(0), Equipped(0), Equippable(0), Consumable(0), Affixed(0), Spell(0), CanUse(0), Work(0), ReadWork(0), Unique(0), Bound(0), Weapon(0), Shield(0), Boots(0), Arrows(0), Regeneration(0),
// ButtonAction(-1), BoolFlags(NULL), Variables(NULL) {}
ButtonAction(-1), ItemClass(-1), BoolFlags(NULL), Variables(NULL) {}
//Wyrmgus end
Expand All @@ -69,8 +69,10 @@ class PopupConditionPanel
bool HasDescription; /// check if button has description.
bool HasDependencies; /// check if button has dependencies or restrictions.
//Wyrmgus start
bool Class; /// check if the button's unit type has a class.
bool Description; /// check if the button's unit type has a description.
bool Quote; /// check if the button's unit type has a quote.
bool Encyclopedia; /// check if the button's unit type has an encyclopedia entry.
//Wyrmgus end
int ButtonAction; /// action type of button
//Wyrmgus start
Expand All @@ -79,15 +81,17 @@ class PopupConditionPanel
std::string ButtonValue; /// value used in ValueStr field of button

//Wyrmgus start
char Opponent; /// check if button's item is an opponent
char Neutral; /// check if button's item is neutral
char AutoCast; /// check if button's spell can be autocasted
char Equipped; /// check if button's item is equipped.
char Equippable; /// check if button's item is equippable by its owner.
char Consumable; /// check if button's item is consumable.
char Equipped; /// check if button's item is equipped
char Equippable; /// check if button's item is equippable by its owner
char Consumable; /// check if button's item is consumable
char Affixed; /// check if button's item has an affix
char Spell; /// check if button's item has a spell
char CanUse; /// check if button's item's can be used
char Work; /// check if button's item is a work.
char ReadWork; /// check if button's item is a work that has been read.
char Work; /// check if button's item is a work
char ReadWork; /// check if button's item is a work that has been read
char Unique; /// check if button's item is unique
char Bound; /// check if button's item is bound to its owner
char Weapon; /// check if button's item is a weapon
Expand Down
1 change: 1 addition & 0 deletions src/include/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ extern void AddUpgradeRequiredAbility(std::string upgrade_ident, std::string req
extern void AddUpgradeWeaponClass(std::string upgrade_ident, int weapon_class);
extern void SetUpgradeItem(std::string upgrade_ident, std::string item_ident);
extern std::string GetUpgradeEffectsString(std::string upgrade_ident);
extern bool IsPercentageVariable(int var);
//Wyrmgus end

//@}
Expand Down
4 changes: 2 additions & 2 deletions src/stratagus/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ std::string GetItemEffectsString(std::string item_ident)
item_effects_string += "+";
}
item_effects_string += std::to_string((long long) item->DefaultStat.Variables[var].Value);
if (var == BACKSTAB_INDEX || var == BONUSAGAINSTMOUNTED_INDEX || var == BONUSAGAINSTBUILDINGS_INDEX || var == BONUSAGAINSTAIR_INDEX || var == BONUSAGAINSTGIANTS_INDEX || var == BONUSAGAINSTDRAGONS_INDEX || var == FIRERESISTANCE_INDEX || var == COLDRESISTANCE_INDEX || var == ARCANERESISTANCE_INDEX || var == LIGHTNINGRESISTANCE_INDEX || var == AIRRESISTANCE_INDEX || var == EARTHRESISTANCE_INDEX || var == WATERRESISTANCE_INDEX || var == HACKRESISTANCE_INDEX || var == PIERCERESISTANCE_INDEX || var == BLUNTRESISTANCE_INDEX) {
if (IsPercentageVariable(var)) {
item_effects_string += "%";
}
item_effects_string += " ";
Expand Down Expand Up @@ -418,7 +418,7 @@ std::string GetUniqueItemEffectsString(std::string item_name)
item_effects_string += "+";
}
item_effects_string += std::to_string((long long) variable_value);
if (var == BACKSTAB_INDEX || var == BONUSAGAINSTMOUNTED_INDEX || var == BONUSAGAINSTBUILDINGS_INDEX || var == BONUSAGAINSTAIR_INDEX || var == BONUSAGAINSTGIANTS_INDEX || var == BONUSAGAINSTDRAGONS_INDEX || var == FIRERESISTANCE_INDEX || var == COLDRESISTANCE_INDEX || var == ARCANERESISTANCE_INDEX || var == LIGHTNINGRESISTANCE_INDEX || var == AIRRESISTANCE_INDEX || var == EARTHRESISTANCE_INDEX || var == WATERRESISTANCE_INDEX || var == HACKRESISTANCE_INDEX || var == PIERCERESISTANCE_INDEX || var == BLUNTRESISTANCE_INDEX || var == TIMEEFFICIENCYBONUS_INDEX) {
if (IsPercentageVariable(var)) {
item_effects_string += "%";
}
item_effects_string += " ";
Expand Down
4 changes: 2 additions & 2 deletions src/stratagus/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ std::string GetFactionEffectsString(std::string civilization_name, std::string f
effect_element_string += "+";
}
effect_element_string += std::to_string((long long) variable_difference);
if (j == BACKSTAB_INDEX || j == BONUSAGAINSTMOUNTED_INDEX || j == BONUSAGAINSTBUILDINGS_INDEX || j == BONUSAGAINSTAIR_INDEX || j == BONUSAGAINSTGIANTS_INDEX || j == BONUSAGAINSTDRAGONS_INDEX || j == FIRERESISTANCE_INDEX || j == COLDRESISTANCE_INDEX || j == ARCANERESISTANCE_INDEX || j == LIGHTNINGRESISTANCE_INDEX || j == AIRRESISTANCE_INDEX || j == EARTHRESISTANCE_INDEX || j == WATERRESISTANCE_INDEX || j == HACKRESISTANCE_INDEX || j == PIERCERESISTANCE_INDEX || j == BLUNTRESISTANCE_INDEX || j == TIMEEFFICIENCYBONUS_INDEX) {
if (IsPercentageVariable(j)) {
effect_element_string += "%";
}
effect_element_string += " ";
Expand Down Expand Up @@ -2320,7 +2320,7 @@ std::string GetFactionEffectsString(std::string civilization_name, std::string f
faction_effects_string += "+";
}
faction_effects_string += std::to_string((long long) UpgradeModifiers[z]->Modifier.Variables[j].Value);
if (j == BACKSTAB_INDEX || j == BONUSAGAINSTMOUNTED_INDEX || j == BONUSAGAINSTBUILDINGS_INDEX || j == BONUSAGAINSTAIR_INDEX || j == BONUSAGAINSTGIANTS_INDEX || j == BONUSAGAINSTDRAGONS_INDEX || j == FIRERESISTANCE_INDEX || j == COLDRESISTANCE_INDEX || j == ARCANERESISTANCE_INDEX || j == LIGHTNINGRESISTANCE_INDEX || j == AIRRESISTANCE_INDEX || j == EARTHRESISTANCE_INDEX || j == WATERRESISTANCE_INDEX || j == HACKRESISTANCE_INDEX || j == PIERCERESISTANCE_INDEX || j == BLUNTRESISTANCE_INDEX || j == TIMEEFFICIENCYBONUS_INDEX) {
if (IsPercentageVariable(j)) {
faction_effects_string += "%";
}
faction_effects_string += " ";
Expand Down
1 change: 1 addition & 0 deletions src/tolua/player.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ extern CPlayer Players[PlayerMax];
extern CPlayer *ThisPlayer;

//Wyrmgus start
extern void CleanPlayers();
extern void NetworkSetFaction(int player, std::string faction_name);
extern std::string GetFactionEffectsString(std::string civilization_name, std::string faction_name);
extern void GenerateMissingLanguageData();
Expand Down
51 changes: 41 additions & 10 deletions src/ui/botpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,21 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition,
}

//Wyrmgus start
if (condition->Class && type && type->Class.empty() && !(type->BoolFlag[ITEM_INDEX].value && type->ItemClass != -1)) {
return false;
}

if (condition->Description && type && type->Description.empty()) {
return false;
}

if (condition->Quote && type && type->Quote.empty() && !(button.Action == ButtonUnit && UnitManager.GetSlotUnit(button.Value).Unique && !GetUniqueItem(UnitManager.GetSlotUnit(button.Value).Name)->Quote.empty()) && !(button.Action == ButtonUnit && UnitManager.GetSlotUnit(button.Value).Work != NULL && !UnitManager.GetSlotUnit(button.Value).Work->Quote.empty())) {
return false;
}

if (condition->Encyclopedia && type && type->Description.empty() && type->Background.empty() && type->Quote.empty() && (!type->BoolFlag[ITEM_INDEX].value || type->ItemClass == -1)) {
return false;
}
//Wyrmgus end

if (condition->ButtonAction != -1 && button.Action != condition->ButtonAction) {
Expand Down Expand Up @@ -487,11 +495,6 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition,
return false;
}
}
if (condition->Affixed != CONDITION_TRUE) {
if ((condition->Affixed == CONDITION_ONLY) ^ (unit.Prefix != NULL || unit.Suffix != NULL)) {
return false;
}
}
if (condition->Spell != CONDITION_TRUE) {
if ((condition->Spell == CONDITION_ONLY) ^ (unit.Spell != NULL)) {
return false;
Expand All @@ -512,11 +515,6 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition,
return false;
}
}
if (condition->Unique != CONDITION_TRUE) {
if ((condition->Unique == CONDITION_ONLY) ^ (unit.Unique || unit.Character != NULL)) {
return false;
}
}
if (condition->Bound != CONDITION_TRUE) {
if ((condition->Bound == CONDITION_ONLY) ^ unit.Bound) {
return false;
Expand Down Expand Up @@ -559,6 +557,39 @@ static bool CanShowPopupContent(const PopupConditionPanel *condition,
}
}
}

if (condition->Opponent != CONDITION_TRUE) {
if ((condition->Opponent == CONDITION_ONLY) ^ ThisPlayer->IsEnemy(unit)) {
return false;
}
}
if (condition->Neutral != CONDITION_TRUE) {
if ((condition->Neutral == CONDITION_ONLY) ^ (!ThisPlayer->IsEnemy(unit) && !ThisPlayer->IsAllied(unit) && ThisPlayer != unit.Player && (unit.Container == NULL || (!ThisPlayer->IsEnemy(*unit.Container) && !ThisPlayer->IsAllied(*unit.Container) && ThisPlayer != unit.Container->Player)))) {
return false;
}
}

if (condition->Affixed != CONDITION_TRUE) {
if ((condition->Affixed == CONDITION_ONLY) ^ (unit.Prefix != NULL || unit.Suffix != NULL)) {
return false;
}
}
if (condition->Unique != CONDITION_TRUE) {
if ((condition->Unique == CONDITION_ONLY) ^ (unit.Unique || unit.Character != NULL)) {
return false;
}
}
} else { // always return false for "Affixed" and "Unique" for buttons that aren't individual unit buttons
if (condition->Affixed != CONDITION_TRUE) {
if (condition->Affixed == CONDITION_ONLY) {
return false;
}
}
if (condition->Unique != CONDITION_TRUE) {
if (condition->Unique == CONDITION_ONLY) {
return false;
}
}
}
//Wyrmgus end

Expand Down
23 changes: 20 additions & 3 deletions src/ui/mainscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,16 @@ static void DrawUnitInfo_portrait(const CUnit &unit)
#endif
if (UI.SingleSelectedButton) {
const PixelPos pos(UI.SingleSelectedButton->X, UI.SingleSelectedButton->Y);
const int flag = (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
//Wyrmgus start
// const int flag = (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0) ?
// (IconActive | (MouseButtons & LeftButton)) : 0;
int flag = (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0) ?
IconActive : 0;

if (flag == IconActive && ((MouseButtons & LeftButton) || (MouseButtons & MiddleButton) || (MouseButtons & RightButton))) {
flag = IconClicked;
}
//Wyrmgus end

//Wyrmgus start
// type.Icon.Icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : unit.Player->Index);
Expand Down Expand Up @@ -1540,7 +1548,16 @@ static void InfoPanel_draw_single_selection(CUnit *selUnit)
if (!Preference.NoStatusLineTooltips) {
UI.StatusLine.Set(unit.GetMessageName());
}
DrawGenericPopup(unit.GetMessageName(), UI.SingleSelectedButton->X, UI.SingleSelectedButton->Y);

//hackish way to make the popup appear correctly for the single selected unit
ButtonAction *ba = new ButtonAction;
ba->Hint = unit.GetMessageName();
ba->Action = ButtonUnit;
ba->Value = UnitNumber(unit);
ba->Popup = "popup-unit";
DrawPopup(*ba, *UI.SingleSelectedButton, UI.SingleSelectedButton->X, UI.SingleSelectedButton->Y);
delete ba;
LastDrawnButtonPopup = NULL;
//Wyrmgus end
}
}
Expand Down
41 changes: 39 additions & 2 deletions src/ui/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#include "action/action_build.h"
#include "action/action_train.h"
#include "actions.h"
//Wyrmgus start
#include "character.h"
//Wyrmgus end
#include "commands.h"
#include "cursor.h"
#include "font.h"
Expand Down Expand Up @@ -2132,6 +2135,8 @@ static void UIHandleButtonDown_OnButton(unsigned button)
}
}
} else if ((MouseButtons & MiddleButton)) {
//Wyrmgus start
/*
// clicked on info panel - single unit shown
if (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0 && Selected.size() == 1) {
PlayGameSound(GameSounds.Click.Sound, MaxSampleVolume);
Expand All @@ -2141,6 +2146,8 @@ static void UIHandleButtonDown_OnButton(unsigned button)
UI.SelectedViewport->Unit = Selected[0];
}
}
*/
//Wyrmgus end
} else if ((MouseButtons & RightButton)) {
}
}
Expand All @@ -2156,7 +2163,27 @@ static void UIHandleButtonUp_OnButton(unsigned button)
// clicked on single unit shown
if (ButtonUnderCursor == 0 && Selected.size() == 1) {
PlayGameSound(GameSounds.Click.Sound, MaxSampleVolume);
UI.SelectedViewport->Center(Selected[0]->GetMapPixelPosCenter());
if ((1 << button) == LeftButton) {
UI.SelectedViewport->Center(Selected[0]->GetMapPixelPosCenter());
} else if ((1 << button) == RightButton) {
std::string encyclopedia_ident = Selected[0]->Type->Ident;
std::string encyclopedia_state = "units";
if (Selected[0]->Character != NULL && Selected[0]->Character->Persistent && !Selected[0]->Character->Custom) {
encyclopedia_ident = Selected[0]->Character->GetFullName();
encyclopedia_state = "heroes";
} else if (Selected[0]->Unique && GetUniqueItem(Selected[0]->Name) != NULL) {
encyclopedia_ident = Selected[0]->Name;
encyclopedia_state = "unique_items";
}
CclCommand("if (OpenEncyclopediaUnitEntry ~= nil) then OpenEncyclopediaUnitEntry(\"" + encyclopedia_ident + "\", \"" + encyclopedia_state + "\") end;");
} else if ((1 << button) == MiddleButton) {
// clicked on info panel - single unit shown
if (UI.SelectedViewport->Unit == Selected[0]) {
UI.SelectedViewport->Unit = NULL;
} else {
UI.SelectedViewport->Unit = Selected[0];
}
}
}
// clicked on training button
} else if (ButtonAreaUnderCursor == ButtonAreaTraining) {
Expand Down Expand Up @@ -2388,7 +2415,17 @@ void UIHandleButtonUp(unsigned button)

//Wyrmgus start
// if ((1 << button) == LeftButton) {
if ((1 << button) == LeftButton || ((1 << button) == RightButton && ButtonAreaUnderCursor == ButtonAreaInventory)) {
if (
(1 << button) == LeftButton
|| (
(1 << button) == RightButton
&& (ButtonAreaUnderCursor == ButtonAreaInventory || (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0 && Selected.size() == 1))
)
|| (
(1 << button) == MiddleButton
&& (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0 && Selected.size() == 1)
)
) {
//Wyrmgus end
//
// Menu (F10) button
Expand Down
16 changes: 15 additions & 1 deletion src/ui/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include "unit_manager.h"
//Wyrmgus end
#include "unittype.h"
//Wyrmgus start
#include "upgrade.h"
//Wyrmgus end
#include "video.h"

/* virtual */ int CPopupContentTypeButtonInfo::GetWidth(const ButtonAction &button, int *) const
Expand Down Expand Up @@ -532,7 +535,10 @@ CPopupContentTypeLine::CPopupContentTypeLine() : Color(ColorWhite), Width(0), He
value = UnitManager.GetSlotUnit(button.Value).Variable[this->Index].Value;
}
}
label.Draw(x, y, value);
x += label.Draw(x, y, value);
if (IsPercentageVariable(this->Index)) {
x += label.Draw(x, y, "%");
}
//Wyrmgus end
}
}
Expand Down Expand Up @@ -587,10 +593,14 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l)
} else if (!strcmp(key, "HasDependencies")) {
condition->HasDependencies = LuaToBoolean(l, -1);
//Wyrmgus start
} else if (!strcmp(key, "Class")) {
condition->Class = LuaToBoolean(l, -1);
} else if (!strcmp(key, "Description")) {
condition->Description = LuaToBoolean(l, -1);
} else if (!strcmp(key, "Quote")) {
condition->Quote = LuaToBoolean(l, -1);
} else if (!strcmp(key, "Encyclopedia")) {
condition->Encyclopedia = LuaToBoolean(l, -1);
//Wyrmgus end
} else if (!strcmp(key, "ButtonValue")) {
condition->ButtonValue = LuaToString(l, -1);
Expand Down Expand Up @@ -651,6 +661,10 @@ static PopupConditionPanel *ParsePopupConditions(lua_State *l)
}
//Wyrmgus end
//Wyrmgus start
} else if (!strcmp(key, "Opponent")) {
condition->Opponent = Ccl2Condition(l, LuaToString(l, -1));
} else if (!strcmp(key, "Neutral")) {
condition->Neutral = Ccl2Condition(l, LuaToString(l, -1));
} else if (!strcmp(key, "AutoCast")) {
condition->AutoCast = Ccl2Condition(l, LuaToString(l, -1));
} else if (!strcmp(key, "Equipped")) {
Expand Down
4 changes: 4 additions & 0 deletions src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4085,6 +4085,10 @@ bool CUnit::CanUseItem(CUnit *item) const
return false;
}

if (item->Type->BoolFlag[ITEM_INDEX].value && item->Type->ItemClass != FoodItemClass && item->Type->ItemClass != PotionItemClass && item->Type->ItemClass != ScrollItemClass) {
return false;
}

if (item->Spell != NULL) {
if (!this->HasInventory() || !CanCastSpell(*this, *item->Spell, this, this->tilePos)) {
return false;
Expand Down
7 changes: 6 additions & 1 deletion src/unit/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ std::string GetUpgradeEffectsString(std::string upgrade_ident)
upgrade_effects_string += "+";
}
upgrade_effects_string += std::to_string((long long) UpgradeModifiers[z]->Modifier.Variables[var].Value);
if (var == BACKSTAB_INDEX || var == BONUSAGAINSTMOUNTED_INDEX || var == BONUSAGAINSTBUILDINGS_INDEX || var == BONUSAGAINSTAIR_INDEX || var == BONUSAGAINSTGIANTS_INDEX || var == BONUSAGAINSTDRAGONS_INDEX || var == FIRERESISTANCE_INDEX || var == COLDRESISTANCE_INDEX || var == ARCANERESISTANCE_INDEX || var == LIGHTNINGRESISTANCE_INDEX || var == AIRRESISTANCE_INDEX || var == EARTHRESISTANCE_INDEX || var == WATERRESISTANCE_INDEX || var == HACKRESISTANCE_INDEX || var == PIERCERESISTANCE_INDEX || var == BLUNTRESISTANCE_INDEX || var == TIMEEFFICIENCYBONUS_INDEX) {
if (IsPercentageVariable(var)) {
upgrade_effects_string += "%";
}
upgrade_effects_string += " ";
Expand Down Expand Up @@ -2043,6 +2043,11 @@ std::string GetUpgradeEffectsString(std::string upgrade_ident)

return "";
}

bool IsPercentageVariable(int var)
{
return var == BACKSTAB_INDEX || var == BONUSAGAINSTMOUNTED_INDEX || var == BONUSAGAINSTBUILDINGS_INDEX || var == BONUSAGAINSTAIR_INDEX || var == BONUSAGAINSTGIANTS_INDEX || var == BONUSAGAINSTDRAGONS_INDEX || var == FIRERESISTANCE_INDEX || var == COLDRESISTANCE_INDEX || var == ARCANERESISTANCE_INDEX || var == LIGHTNINGRESISTANCE_INDEX || var == AIRRESISTANCE_INDEX || var == EARTHRESISTANCE_INDEX || var == WATERRESISTANCE_INDEX || var == HACKRESISTANCE_INDEX || var == PIERCERESISTANCE_INDEX || var == BLUNTRESISTANCE_INDEX || var == TIMEEFFICIENCYBONUS_INDEX;
}
//Wyrmgus end

//@}

0 comments on commit 59f5cbf

Please sign in to comment.