mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Replaced CIntObject::type bitfield with bool's. Added input blocking.
This commit is contained in:
parent
48eb8ab54f
commit
8b61c0d59b
@ -318,7 +318,6 @@ void AdventureMapInterface::onEnemyTurnStarted(PlayerColor playerID)
|
||||
widget->getMinimap()->setAIRadar(true);
|
||||
widget->getInfoBar()->startEnemyTurn(LOCPLINT->cb->getCurrentPlayer());
|
||||
setState(EAdventureState::ENEMY_TURN);
|
||||
|
||||
}
|
||||
|
||||
void AdventureMapInterface::setState(EAdventureState state)
|
||||
@ -333,17 +332,8 @@ void AdventureMapInterface::adjustActiveness()
|
||||
bool widgetMustBeActive = isActive() && shortcuts->optionSidePanelActive();
|
||||
bool mapViewMustBeActive = isActive() && (shortcuts->optionMapViewActive());
|
||||
|
||||
if (widgetMustBeActive && !widget->isActive())
|
||||
widget->activate();
|
||||
|
||||
if (!widgetMustBeActive && widget->isActive())
|
||||
widget->deactivate();
|
||||
|
||||
if (mapViewMustBeActive && !widget->getMapView()->isActive())
|
||||
widget->getMapView()->activate();
|
||||
|
||||
if (!mapViewMustBeActive && widget->getMapView()->isActive())
|
||||
widget->getMapView()->deactivate();
|
||||
widget->setInputEnabled(widgetMustBeActive);
|
||||
widget->getMapView()->setInputEnabled(mapViewMustBeActive);
|
||||
}
|
||||
|
||||
void AdventureMapInterface::onCurrentPlayerChanged(PlayerColor playerID)
|
||||
|
@ -34,7 +34,7 @@ CInGameConsole::CInGameConsole()
|
||||
: CIntObject(KEYBOARD | TIME | TEXTINPUT)
|
||||
, prevEntDisp(-1)
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
}
|
||||
|
||||
void CInGameConsole::showAll(Canvas & to)
|
||||
|
@ -20,18 +20,14 @@
|
||||
CIntObject::CIntObject(int used_, Point pos_):
|
||||
parent_m(nullptr),
|
||||
parent(parent_m),
|
||||
type(0)
|
||||
redrawParent(false),
|
||||
inputEnabled(true),
|
||||
captureAllKeys(false),
|
||||
used(used_),
|
||||
recActions(GH.defActionsDef),
|
||||
defActions(GH.defActionsDef),
|
||||
pos(pos_, Point())
|
||||
{
|
||||
captureAllKeys = false;
|
||||
used = used_;
|
||||
|
||||
recActions = defActions = GH.defActionsDef;
|
||||
|
||||
pos.x = pos_.x;
|
||||
pos.y = pos_.y;
|
||||
pos.w = 0;
|
||||
pos.h = 0;
|
||||
|
||||
if(GH.captureChildren)
|
||||
GH.createdObj.front()->addChild(this, true);
|
||||
}
|
||||
@ -76,7 +72,11 @@ void CIntObject::activate()
|
||||
if (isActive())
|
||||
return;
|
||||
|
||||
if (inputEnabled)
|
||||
activateEvents(used | GENERAL);
|
||||
else
|
||||
activateEvents(GENERAL);
|
||||
|
||||
assert(isActive());
|
||||
|
||||
if(defActions & ACTIVATE)
|
||||
@ -141,6 +141,32 @@ void CIntObject::setEnabled(bool on)
|
||||
disable();
|
||||
}
|
||||
|
||||
void CIntObject::setInputEnabled(bool on)
|
||||
{
|
||||
if (inputEnabled == on)
|
||||
return;
|
||||
|
||||
inputEnabled = on;
|
||||
|
||||
if (!isActive())
|
||||
return;
|
||||
|
||||
assert((used & GENERAL) == 0);
|
||||
|
||||
if (on)
|
||||
activateEvents(used);
|
||||
else
|
||||
deactivateEvents(used);
|
||||
|
||||
for(auto & elem : children)
|
||||
elem->setInputEnabled(on);
|
||||
}
|
||||
|
||||
void CIntObject::setRedrawParent(bool on)
|
||||
{
|
||||
redrawParent = on;
|
||||
}
|
||||
|
||||
void CIntObject::fitToScreen(int borderWidth, bool propagate)
|
||||
{
|
||||
Point newPos = pos.topLeft();
|
||||
@ -210,7 +236,7 @@ void CIntObject::redraw()
|
||||
//it should fix glitches when called by inactive elements located below active window
|
||||
if (isActive())
|
||||
{
|
||||
if (parent_m && (type & REDRAW_PARENT))
|
||||
if (parent_m && redrawParent)
|
||||
{
|
||||
parent_m->redraw();
|
||||
}
|
||||
|
@ -47,11 +47,10 @@ class CIntObject : public IShowActivatable, public AEventsReceiver //interface o
|
||||
//non-const versions of fields to allow changing them in CIntObject
|
||||
CIntObject *parent_m; //parent object
|
||||
|
||||
public:
|
||||
//redraw parent flag - this int may be semi-transparent and require redraw of parent window
|
||||
enum {REDRAW_PARENT=8};
|
||||
int type; //bin flags using etype
|
||||
bool inputEnabled;
|
||||
bool redrawParent;
|
||||
|
||||
public:
|
||||
std::vector<CIntObject *> children;
|
||||
|
||||
/// read-only parent access. May not be a "clean" solution but allows some compatibility
|
||||
@ -82,6 +81,13 @@ public:
|
||||
/// deactivates or activates UI element based on flag
|
||||
void setEnabled(bool on);
|
||||
|
||||
/// Block (or allow) all user input, e.g. mouse/keyboard/touch without hiding element
|
||||
void setInputEnabled(bool on);
|
||||
|
||||
/// Mark this input as one that requires parent redraw on update,
|
||||
/// for example if current control might have semi-transparent elements and requires redrawing of background
|
||||
void setRedrawParent(bool on);
|
||||
|
||||
// activate or deactivate object. Inactive object won't receive any input events (keyboard\mouse)
|
||||
// usually used automatically by parent
|
||||
void activate() override;
|
||||
|
@ -493,7 +493,7 @@ public:
|
||||
InterfaceLayoutWidget::InterfaceLayoutWidget()
|
||||
:CIntObject()
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
}
|
||||
|
||||
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildLayout(const JsonNode & config)
|
||||
|
@ -115,7 +115,7 @@ InfoCard::InfoCard()
|
||||
: showChat(true)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
CIntObject::type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos.x += 393;
|
||||
pos.y += 6;
|
||||
|
||||
@ -311,7 +311,7 @@ CChatBox::CChatBox(const Rect & rect)
|
||||
OBJ_CONSTRUCTION;
|
||||
pos += rect.topLeft();
|
||||
captureAllKeys = true;
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
|
||||
const int height = static_cast<int>(graphics->fonts[FONT_SMALL]->getLineHeight());
|
||||
inputBox = std::make_shared<CTextInput>(Rect(0, rect.h - height, rect.w, height), EFonts::FONT_SMALL, 0);
|
||||
|
@ -371,7 +371,7 @@ TemplatesDropBox::ListItem::ListItem(const JsonNode & config, TemplatesDropBox &
|
||||
pos.w = w->pos.w;
|
||||
pos.h = w->pos.h;
|
||||
}
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
}
|
||||
|
||||
void TemplatesDropBox::ListItem::updateItem(int idx, const CRmgTemplate * _item)
|
||||
|
@ -179,7 +179,7 @@ SelectionTab::SelectionTab(ESelectionScreen Type)
|
||||
break;
|
||||
case ESelectionScreen::campaignList:
|
||||
tabTitle = CGI->generaltexth->allTexts[726];
|
||||
type |= REDRAW_PARENT; // we use parent background so we need to make sure it's will be redrawn too
|
||||
setRedrawParent(true); // we use parent background so we need to make sure it's will be redrawn too
|
||||
pos.w = parent->pos.w;
|
||||
pos.h = parent->pos.h;
|
||||
pos.x += 3;
|
||||
|
@ -95,7 +95,7 @@ CMenuScreen::CMenuScreen(const JsonNode & configNode)
|
||||
menuNameToEntry.push_back("credits");
|
||||
|
||||
tabs = std::make_shared<CTabbedInt>(std::bind(&CMenuScreen::createTab, this, _1));
|
||||
tabs->type |= REDRAW_PARENT;
|
||||
tabs->setRedrawParent(true);
|
||||
}
|
||||
|
||||
std::shared_ptr<CIntObject> CMenuScreen::createTab(size_t index)
|
||||
@ -248,7 +248,7 @@ std::shared_ptr<CButton> CMenuEntry::createButton(CMenuScreen * parent, const Js
|
||||
CMenuEntry::CMenuEntry(CMenuScreen * parent, const JsonNode & config)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos = parent->pos;
|
||||
|
||||
for(const JsonNode & node : config["images"].Vector())
|
||||
@ -258,7 +258,7 @@ CMenuEntry::CMenuEntry(CMenuScreen * parent, const JsonNode & config)
|
||||
{
|
||||
buttons.push_back(createButton(parent, node));
|
||||
buttons.back()->hoverable = true;
|
||||
buttons.back()->type |= REDRAW_PARENT;
|
||||
buttons.back()->setRedrawParent(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ CreditsScreen::CreditsScreen(Rect rect)
|
||||
{
|
||||
pos.w = rect.w;
|
||||
pos.h = rect.h;
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
auto textFile = CResourceHandler::get()->load(ResourceID("DATA/CREDITS.TXT"))->readAll();
|
||||
std::string text((char *)textFile.first.get(), textFile.second);
|
||||
|
@ -281,7 +281,7 @@ void CSelectableComponent::init()
|
||||
CSelectableComponent::CSelectableComponent(const Component &c, std::function<void()> OnSelect):
|
||||
CComponent(c),onSelect(OnSelect)
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
addUsedEvents(LCLICK | KEYBOARD);
|
||||
init();
|
||||
}
|
||||
@ -289,7 +289,7 @@ CSelectableComponent::CSelectableComponent(const Component &c, std::function<voi
|
||||
CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, ESize imageSize, std::function<void()> OnSelect):
|
||||
CComponent(Type,Sub,Val, imageSize),onSelect(OnSelect)
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
addUsedEvents(LCLICK | KEYBOARD);
|
||||
init();
|
||||
}
|
||||
@ -466,7 +466,7 @@ CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _component
|
||||
betweenRows(betweenRows),
|
||||
componentsInRow(componentsInRow)
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos = position + pos.topLeft();
|
||||
placeComponents(false);
|
||||
}
|
||||
@ -484,7 +484,7 @@ CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>>
|
||||
betweenRows(betweenRows),
|
||||
componentsInRow(componentsInRow)
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos = position + pos.topLeft();
|
||||
placeComponents(true);
|
||||
|
||||
|
@ -17,7 +17,7 @@ CreatureCostBox::CreatureCostBox(Rect position, std::string titleText)
|
||||
{
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
||||
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos = position + pos.topLeft();
|
||||
|
||||
title = std::make_shared<CLabel>(pos.w/2, 10, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, titleText);
|
||||
|
@ -143,6 +143,7 @@ public:
|
||||
class LRClickableAreaWTextComp: public LRClickableAreaWText
|
||||
{
|
||||
public:
|
||||
int type;
|
||||
int baseType;
|
||||
int bonusValue;
|
||||
virtual void clickLeft(tribool down, bool previousState) override;
|
||||
|
@ -47,7 +47,7 @@ void CLabel::showAll(Canvas & to)
|
||||
CLabel::CLabel(int x, int y, EFonts Font, ETextAlignment Align, const SDL_Color & Color, const std::string & Text)
|
||||
: CTextContainer(Align, Font, Color), text(Text)
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
autoRedraw = true;
|
||||
pos.x += x;
|
||||
pos.y += y;
|
||||
@ -299,7 +299,7 @@ CTextBox::CTextBox(std::string Text, const Rect & rect, int SliderStyle, EFonts
|
||||
OBJECT_CONSTRUCTION_CAPTURING(255 - DISPOSE);
|
||||
label = std::make_shared<CMultiLineLabel>(rect, Font, Align, Color);
|
||||
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos.x += rect.x;
|
||||
pos.y += rect.y;
|
||||
pos.h = rect.h;
|
||||
@ -492,7 +492,7 @@ CTextInput::CTextInput(const Rect & Pos, EFonts font, const CFunctionList<void(c
|
||||
cb(CB),
|
||||
CFocusable(std::make_shared<CKeyboardFocusListener>(this))
|
||||
{
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
pos.h = Pos.h;
|
||||
pos.w = Pos.w;
|
||||
captureAllKeys = true;
|
||||
|
@ -1160,7 +1160,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInst
|
||||
updateShadow();
|
||||
|
||||
garr = std::make_shared<CGarrisonInt>(305, 387, 4, Point(0,96), town->getUpperArmy(), town->visitingHero);
|
||||
garr->type |= REDRAW_PARENT;
|
||||
garr->setRedrawParent(true);
|
||||
|
||||
heroes = std::make_shared<HeroSlots>(town, Point(241, 387), Point(241, 483), garr, true);
|
||||
title = std::make_shared<CLabel>(85, 387, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, town->getNameTranslated());
|
||||
|
@ -1776,7 +1776,7 @@ CObjectListWindow::CItem::CItem(CObjectListWindow * _parent, size_t _id, std::st
|
||||
border = std::make_shared<CPicture>("TPGATES");
|
||||
pos = border->pos;
|
||||
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
|
||||
text = std::make_shared<CLabel>(pos.w/2, pos.h/2, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, _text);
|
||||
select(index == parent->selected);
|
||||
@ -1850,7 +1850,7 @@ void CObjectListWindow::init(std::shared_ptr<CIntObject> titleWidget_, std::stri
|
||||
}
|
||||
list = std::make_shared<CListBox>(std::bind(&CObjectListWindow::genItem, this, _1),
|
||||
Point(14, 151), Point(0, 25), 9, items.size(), 0, 1, Rect(262, -32, 256, 256) );
|
||||
list->type |= REDRAW_PARENT;
|
||||
list->setRedrawParent(true);
|
||||
|
||||
ok = std::make_shared<CButton>(Point(15, 402), "IOKAY.DEF", CButton::tooltip(), std::bind(&CObjectListWindow::elementSelected, this), EShortcut::GLOBAL_ACCEPT);
|
||||
ok->block(!list->size());
|
||||
|
@ -34,7 +34,7 @@ AdventureOptionsTab::AdventureOptionsTab()
|
||||
: InterfaceObjectConfigurable()
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
|
||||
const JsonNode config(ResourceID("config/widgets/settings/adventureOptionsTab.json"));
|
||||
addCallback("playerHeroSpeedChanged", [this](int value)
|
||||
|
@ -21,7 +21,7 @@
|
||||
BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
|
||||
const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json"));
|
||||
addCallback("viewGridChanged", [this, owner](bool value)
|
||||
|
@ -94,7 +94,7 @@ GeneralOptionsTab::GeneralOptionsTab()
|
||||
onFullscreenChanged(settings.listen["video"]["fullscreen"])
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
type |= REDRAW_PARENT;
|
||||
setRedrawParent(true);
|
||||
|
||||
addConditional("touchscreen", GH.input().hasTouchInputDevice());
|
||||
#ifdef VCMI_MOBILE
|
||||
|
@ -71,7 +71,7 @@ SettingsMainWindow::SettingsMainWindow(BattleInterface * parentBattleUi) : Inter
|
||||
|
||||
parentBattleInterface = parentBattleUi;
|
||||
tabContentArea = std::make_shared<CTabbedInt>(std::bind(&SettingsMainWindow::createTab, this, _1), Point(0, 0), defaultTabIndex);
|
||||
tabContentArea->type |= REDRAW_PARENT;
|
||||
tabContentArea->setRedrawParent(true);
|
||||
|
||||
std::shared_ptr<CToggleGroup> mainTabs = widget<CToggleGroup>("settingsTabs");
|
||||
mainTabs->setSelected(defaultTabIndex);
|
||||
|
Loading…
Reference in New Issue
Block a user