Browse Source

Remove 'visible' property from images, replaced with enable/disabled
call

Ivan Savenko 1 year ago
parent
commit
0fd966818f

+ 0 - 2
client/gui/InterfaceObjectConfigurable.cpp

@@ -310,8 +310,6 @@ std::shared_ptr<CPicture> InterfaceObjectConfigurable::buildPicture(const JsonNo
 	auto image = ImagePath::fromJson(config["image"]);
 	auto position = readPosition(config["position"]);
 	auto pic = std::make_shared<CPicture>(image, position.x, position.y);
-	if(!config["visible"].isNull())
-		pic->visible = config["visible"].Bool();
 
 	if ( config["playerColored"].Bool() && LOCPLINT)
 		pic->colorize(LOCPLINT->playerID);

+ 6 - 5
client/widgets/ComboBox.cpp

@@ -22,10 +22,11 @@ ComboBox::DropDown::Item::Item(const JsonNode & config, ComboBox::DropDown & _dr
 {
 	build(config);
 	
-	if(auto w = widget<CPicture>("hoverImage"))
+	if(auto w = widget<CIntObject>("hoverImage"))
 	{
 		pos.w = w->pos.w;
 		pos.h = w->pos.h;
+		w->disable();
 	}
 	setRedrawParent(true);
 }
@@ -42,14 +43,14 @@ void ComboBox::DropDown::Item::updateItem(int idx, const void * _item)
 
 void ComboBox::DropDown::Item::hover(bool on)
 {
-	auto h = widget<CPicture>("hoverImage");
+	auto h = widget<CIntObject>("hoverImage");
 	auto w = widget<CLabel>("labelName");
 	if(h && w)
 	{
-		if(w->getText().empty())
-			h->visible = false;
+		if(w->getText().empty() || on == false)
+			h->disable();
 		else
-			h->visible = on;
+			h->enable();
 	}
 	redraw();
 }

+ 2 - 4
client/widgets/Images.cpp

@@ -35,7 +35,6 @@
 
 CPicture::CPicture(std::shared_ptr<IImage> image, const Point & position)
 	: bg(image)
-	, visible(true)
 	, needRefresh(false)
 {
 	pos += position;
@@ -53,7 +52,6 @@ CPicture::CPicture( const ImagePath & bmpname )
 
 CPicture::CPicture( const ImagePath & bmpname, const Point & position )
 	: bg(GH.renderHandler().loadImage(bmpname))
-	, visible(true)
 	, needRefresh(false)
 {
 	pos.x += position.x;
@@ -81,13 +79,13 @@ CPicture::CPicture(std::shared_ptr<IImage> image, const Rect &SrcRect, int x, in
 
 void CPicture::show(Canvas & to)
 {
-	if (visible && needRefresh)
+	if (needRefresh)
 		showAll(to);
 }
 
 void CPicture::showAll(Canvas & to)
 {
-	if(bg && visible)
+	if(bg)
 	{
 		if (srcRect.has_value())
 			to.draw(bg, pos.topLeft(), *srcRect);

+ 0 - 4
client/widgets/Images.h

@@ -34,10 +34,6 @@ public:
 	/// If set to true, iamge will be redrawn on each frame
 	bool needRefresh;
 
-	/// If set to false, image will not be rendered
-	/// Deprecated, use CIntObject::disable()/enable() instead
-	bool visible;
-
 	std::shared_ptr<IImage> getSurface()
 	{
 		return bg;

+ 10 - 2
client/windows/CSpellWindow.cpp

@@ -449,8 +449,16 @@ void CSpellWindow::setCurrentPage(int value)
 	schoolPicture->visible = selectedTab!=4 && currentPage == 0;
 	if(selectedTab != 4)
 		schoolPicture->setFrame(selectedTab, 0);
-	leftCorner->visible = currentPage != 0;
-	rightCorner->visible = (currentPage+1) < pagesWithinCurrentTab();
+
+	if (currentPage != 0)
+		leftCorner->enable();
+	else
+		leftCorner->disable();
+
+	if (currentPage + 1 < pagesWithinCurrentTab())
+		rightCorner->enable();
+	else
+		rightCorner->disable();
 
 	mana->setText(std::to_string(myHero->mana));//just in case, it will be possible to cast spell without closing book
 }