LoadScreen.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. Rectangle {
  4. id: load_screen
  5. property real progress: 0
  6. property real display_progress: 0
  7. property real target_progress: 0
  8. property bool is_loading: false
  9. property string stage_text: "Loading..."
  10. property bool use_real_progress: true
  11. property var _bgSources: ["qrc:/StandardOfIron/assets/visuals/load_screen.png", "qrc:/assets/visuals/load_screen.png", "assets/visuals/load_screen.png", "qrc:/qt/qml/StandardOfIron/assets/visuals/load_screen.png"]
  12. property int _bgIndex: 0
  13. function complete_loading() {
  14. load_screen.target_progress = 1;
  15. load_screen.display_progress = 1;
  16. }
  17. anchors.fill: parent
  18. color: "#000000"
  19. visible: is_loading
  20. onIs_loadingChanged: {
  21. if (is_loading) {
  22. target_progress = 0;
  23. display_progress = 0;
  24. } else {
  25. target_progress = 1;
  26. display_progress = 1;
  27. }
  28. }
  29. onProgressChanged: {
  30. if (!use_real_progress)
  31. return ;
  32. target_progress = Math.max(target_progress, progress);
  33. }
  34. Timer {
  35. id: progressTicker
  36. interval: 16
  37. running: is_loading
  38. repeat: true
  39. onTriggered: {
  40. var target = target_progress;
  41. if (use_real_progress && target < 0.98)
  42. target = Math.min(0.98, Math.max(target, display_progress + 0.002));
  43. var delta = target - display_progress;
  44. var step = delta * 0.15;
  45. if (step < 0.001 && delta > 0)
  46. step = 0.001;
  47. display_progress = Math.min(1, Math.max(0, display_progress + step));
  48. }
  49. }
  50. Image {
  51. id: background_image
  52. anchors.fill: parent
  53. source: load_screen._bgSources[load_screen._bgIndex]
  54. cache: true
  55. asynchronous: false
  56. fillMode: Image.PreserveAspectCrop
  57. onStatusChanged: {
  58. if (status === Image.Error && load_screen._bgIndex + 1 < load_screen._bgSources.length) {
  59. load_screen._bgIndex += 1;
  60. source = load_screen._bgSources[load_screen._bgIndex];
  61. }
  62. }
  63. }
  64. Rectangle {
  65. anchors.fill: parent
  66. color: "#40000000"
  67. }
  68. Column {
  69. anchors.centerIn: parent
  70. anchors.verticalCenterOffset: parent.height * 0.3
  71. spacing: 20
  72. width: parent.width * 0.6
  73. Text {
  74. text: qsTr("Loading...")
  75. color: "#ecf0f1"
  76. font.pixelSize: 48
  77. font.bold: true
  78. anchors.horizontalCenter: parent.horizontalCenter
  79. }
  80. Rectangle {
  81. width: parent.width
  82. height: 40
  83. color: "#2c3e50"
  84. border.color: "#34495e"
  85. border.width: 2
  86. radius: 4
  87. Rectangle {
  88. id: progress_fill
  89. readonly property real available_width: parent.width - 8
  90. anchors.left: parent.left
  91. anchors.top: parent.top
  92. anchors.bottom: parent.bottom
  93. anchors.margins: 4
  94. width: Math.max(0, Math.min(available_width, available_width * load_screen.display_progress))
  95. color: "#f39c12"
  96. radius: 2
  97. Rectangle {
  98. anchors.fill: parent
  99. radius: parent.radius
  100. gradient: Gradient {
  101. GradientStop {
  102. position: 0
  103. color: "#40ffffff"
  104. }
  105. GradientStop {
  106. position: 0.5
  107. color: "#00ffffff"
  108. }
  109. GradientStop {
  110. position: 1
  111. color: "#40ffffff"
  112. }
  113. }
  114. }
  115. }
  116. Text {
  117. anchors.centerIn: parent
  118. text: Math.floor(load_screen.display_progress * 100) + "%"
  119. color: "#ecf0f1"
  120. font.pixelSize: 18
  121. font.bold: true
  122. }
  123. }
  124. Text {
  125. text: load_screen.stage_text
  126. color: "#bdc3c7"
  127. font.pixelSize: 18
  128. anchors.horizontalCenter: parent.horizontalCenter
  129. }
  130. }
  131. }