@@ -11,6 +11,7 @@ UILoadingBarTests::UILoadingBarTests()
11
11
ADD_TEST_CASE (UILoadingBarTest_Right_Scale9);
12
12
ADD_TEST_CASE (UILoadingBarTest_Scale9_State_Change);
13
13
ADD_TEST_CASE (UILoadingBarReloadTexture);
14
+ ADD_TEST_CASE (UILoadingBarIssue12249);
14
15
}
15
16
16
17
// UILoadingBarTest_Left
@@ -403,3 +404,93 @@ void UILoadingBarReloadTexture::update(float delta)
403
404
LoadingBar* loadingBar = static_cast <LoadingBar*>(_uiLayer->getChildByTag (0 ));
404
405
loadingBar->setPercent (_count);
405
406
}
407
+
408
+
409
+ // UILoadingBarIssue12249
410
+
411
+ UILoadingBarIssue12249::UILoadingBarIssue12249 ()
412
+ : _count(0 )
413
+ {
414
+
415
+ }
416
+
417
+ UILoadingBarIssue12249::~UILoadingBarIssue12249 ()
418
+ {
419
+ unscheduleUpdate ();
420
+ }
421
+
422
+ bool UILoadingBarIssue12249::init ()
423
+ {
424
+ if (UIScene::init ())
425
+ {
426
+ scheduleUpdate ();
427
+
428
+ Size widgetSize = _widget->getContentSize ();
429
+
430
+ // Add the alert
431
+ Text* alert = Text::create (" Test LoadingBar Change Direction" ,
432
+ " fonts/Marker Felt.ttf" , 30 );
433
+ alert->setColor (Color3B (159 , 168 , 176 ));
434
+ alert->setPosition (Vec2 (widgetSize.width / 2 .0f ,
435
+ widgetSize.height / 2 .0f - alert->getContentSize ().height * 1 .75f ));
436
+ _uiLayer->addChild (alert);
437
+
438
+ // Create the loading bar
439
+ LoadingBar* loadingBar = LoadingBar::create (" cocosui/sliderProgress.png" );
440
+ loadingBar->setScale9Enabled (true );
441
+ loadingBar->setContentSize (Size (200 , loadingBar->getContentSize ().height * 1.5 ));
442
+ loadingBar->setTag (0 );
443
+ loadingBar->setPosition (Vec2 (widgetSize.width / 2 .0f ,
444
+ widgetSize.height / 2 .0f + loadingBar->getContentSize ().height / 4 .0f ));
445
+
446
+ LoadingBar* loadingBarCopy = LoadingBar::create ();
447
+ loadingBarCopy->setScale9Enabled (true );
448
+ loadingBarCopy->loadTexture (" cocosui/sliderProgress.png" );
449
+ loadingBarCopy->setContentSize (Size (200 , loadingBarCopy->getContentSize ().height * 1.5 ));
450
+ loadingBarCopy->setTag (1 );
451
+ loadingBarCopy->setPosition (loadingBar->getPosition ()
452
+ + Vec2 (0 , -40 ));
453
+ loadingBarCopy->setDirection (LoadingBar::Direction::RIGHT);
454
+
455
+ Button * button = Button ::create (" cocosui/animationbuttonnormal.png" ,
456
+ " cocosui/animationbuttonpressed.png" );
457
+ button->setPosition (Vec2 (widgetSize.width / 2 .0f , widgetSize.height / 2 .0f + 50 ));
458
+ button->setTitleText (" Click to change direction!" );
459
+
460
+ button->addTouchEventListener ([=](Ref*, Widget::TouchEventType type)
461
+ {
462
+ if (type == Widget::TouchEventType::ENDED)
463
+ {
464
+ if (loadingBar->getDirection () == LoadingBar::Direction::LEFT)
465
+ {
466
+ loadingBar->setDirection (LoadingBar::Direction::RIGHT);
467
+ loadingBarCopy->setDirection (LoadingBar::Direction::LEFT);
468
+ }
469
+ else
470
+ {
471
+ loadingBar->setDirection (LoadingBar::Direction::LEFT);
472
+ loadingBarCopy->setDirection (LoadingBar::Direction::RIGHT);
473
+ }
474
+ }
475
+ });
476
+ _uiLayer->addChild (loadingBar,1 );
477
+ _uiLayer->addChild (loadingBarCopy,2 );
478
+ _uiLayer->addChild (button);
479
+
480
+ return true ;
481
+ }
482
+ return false ;
483
+ }
484
+
485
+ void UILoadingBarIssue12249::update (float delta)
486
+ {
487
+ _count++;
488
+ if (_count > 100 )
489
+ {
490
+ _count = 0 ;
491
+ }
492
+ LoadingBar* loadingBar = static_cast <LoadingBar*>(_uiLayer->getChildByTag (0 ));
493
+ LoadingBar* loadingBarCopy = static_cast <LoadingBar*>(_uiLayer->getChildByTag (1 ));
494
+ loadingBar->setPercent (_count);
495
+ loadingBarCopy->setPercent (_count);
496
+ }
0 commit comments