Progress bar when moving fleet in overview

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Progress bar when moving fleet in overview

      New

      Hello.,
      I implemented a progress bar when moving the fleet.
      Since I am a beginner, it took more time than expected.
      I hope you design various things based on this source.




      added style

      CSS Source Code

      1. .progress-bar-container {
      2. width: 100%;
      3. background-color: #f0f0f0;
      4. border-radius: 5px;
      5. overflow: hidden;
      6. }
      7. .progress-bar-overview {
      8. height: 13px;
      9. background-color: #4caf50;
      10. width: 0%;
      11. transition: width 1.0s linear;
      12. }
      Display All




      Add code to the scripts/game/overview.js file.


      JavaScript Source Code

      1. $(document).ready(function() {
      2. window.setInterval(function() {
      3. $('.progress-bar-overview').each(function() {
      4. var $progress = $(this);
      5. var startTime = $progress.data('start-time') * 1000; // Convert to milliseconds
      6. var returnTime = $progress.data('return-time') * 1000; // Convert to milliseconds
      7. var currentTime = serverTime.getTime(); // Assume serverTime is defined globally
      8. if (startTime && returnTime && currentTime <= returnTime) {
      9. var totalDuration = returnTime - startTime;
      10. var elapsedTime = currentTime - startTime;
      11. var progressPercent = Math.min((elapsedTime / totalDuration) * 100, 100);
      12. $progress.css('width', progressPercent + '%');
      13. } else {
      14. $progress.css('width', '100%'); // Complete if time is up
      15. }
      16. });
      17. }, 1000);
      18. });
      Display All


      Add the code to the includes/classes/class.FlyingFleetsTable.php file.


      PHP Source Code

      1. //Find code
      2. $Time = 0;
      3. $Rest = 0;
      4. $StartTime = $fleetRow['start_time']; //Add code
      5. //There are two identical codes and they are added.
      6. $Rest = $Return[0];
      7. $EventString .= $Return[1].'<br><br>';
      8. $Time = $Return[2];
      9. $StartTime = $Return[3]; //Add code
      10. //Find code
      11. return array('text'=> $EventString,
      12. 'returntime' => $Time,
      13. 'resttime' => $Rest,
      14. 'start_time' => $StartTime, //Add code
      15. );
      16. // Finished
      Display All


      Add the code to the styles/templates/game/page.overview.default.tpl file.


      HTML Source Code

      1. <!-- Find code (foreach $fleets as $index => $fleet) -->
      2. {foreach $fleets as $index => $fleet}
      3. <tr>
      4. <td id="fleettime_{$index}" class="fleets" data-fleet-end-time="{$fleet.returntime}" data-fleet-time="{$fleet.resttime}">{pretty_fly_time({$fleet.resttime})}</td>
      5. <td>{$fleet.text}</td>
      6. </tr>
      7. <!-- Add code. (If it consists of <div>, then you can just make it into <div>.) -->
      8. <tr>
      9. <td colspan="2">
      10. <div class="progress-bar-container">
      11. <div class="progress-bar-overview" id="progress_{$index}" data-start-time="{$fleet.start_time}" data-return-time="{$fleet.returntime}">
      12. </div>
      13. </div>
      14. </td>
      15. </tr>
      16. <!-- Add code END -->
      17. {/foreach}
      18. <tr>
      19. <td colspan="2">&nbsp;</td>
      20. </tr>
      21. {/if}
      Display All



      If JavaScript doesn't work, just press Ctrl+F5.
      Have a good day ~
      --------------------------------------------------------------------------------------

      The post was edited 1 time, last by noonn ().

    • New

      i have progress bar but always white ( no progress ) , this is the code for the class :


      private function BuildFleetEventTable($fleetRow, $FleetState)
      {
      $Time = 0;
      $Rest = 0;
      $Rest1 = 0;
      $StartTime = $fleetRow['start_time'];

      if ($FleetState == 0 && $this->IsPhalanx && $fleetRow['fleet_group'] != 0 && (strpos((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", 'page=phalanx') !== false))
      {
      $acsResult = $this->getFleets($fleetRow['fleet_group']);
      $EventString = '';

      foreach($acsResult as $acsRow)
      {
      $Return = $this->getEventData($acsRow, $FleetState);

      $Rest = $Return[0];
      $EventString .= $Return[1].'<br><br>';
      $Time = $Return[2];
      $Rest1 = $Return[3];
      $StartTime = $Return[3];
      }

      $EventString = substr($EventString, 0, -8);
      }
      else
      {
      list($Rest, $EventString, $Time, $Rest1) = $this->getEventData($fleetRow, $FleetState);
      }

      return array(
      'text' => $EventString,
      'returntime' => $Time,
      'resttime' => $Rest,
      'resttime1' => $Rest1,
      'start_time' => $StartTime,
      );
    • New

      Try changing this.

      $StartTime = $Return[3]; ----------> $StartTime = $Return[4];

      See the code below.

      ============

      private function BuildFleetEventTable($fleetRow, $FleetState)
      {
      $Time = 0;
      $Rest = 0;
      $Rest1 = 0;
      $StartTime = $fleetRow['start_time'];
      ...
      ...
      ...
      ...
      foreach($acsResult as $acsRow)
      {
      if($acsRow['fleet_group']!=0) {
      $Return= $this->getEventData($acsRow, $FleetState);

      $Rest= $Return[0];
      $EventString .= $Return[1].'<br><br>';
      $Time= $Return[2];
      $Rest1= $Return[3];
      $StartTime = $Return[4]; /////////////////////// Add code
      }
      }

      $EventString = substr($EventString, 0, -8);
      }
      else if ($FleetState == 0 && $fleetRow['fleet_group'] != 0)
      {
      $acsResult= $this->getFleets($fleetRow['fleet_group']);
      $EventString = '';

      foreach($acsResult as $acsRow)
      {
      $Return= $this->getEventData($acsRow, $FleetState);

      $Rest= $Return[0];
      $EventString .= $Return[1].'<br><br>';
      $Time= $Return[2];
      $Rest1= $Return[3];
      $StartTime = $Return[4]; /////////////////// Add code
      }

      $EventString = substr($EventString, 0, -8);
      }
      else
      {
      list($Rest, $EventString, $Time, $Rest1) = $this->getEventData($fleetRow, $FleetState);
      }

      return array(
      'text'=> $EventString,
      'returntime' => $Time,
      'resttime'=> $Rest,
      'resttime1'=> $Rest1,
      'start_time' => $StartTime, /////////////////// Add code
      );

      }
      --------------------------------------------------------------------------------------

      The post was edited 1 time, last by noonn ().

    • New

      Thanks for this nice mod! :thumbsup:

      for me it works perfect.



      one question:

      is it possible to give the bar, the same color like the fleet-text?

      spio - yellow, nebular - purple, attack - green... and so on
      Es zählt nicht wie lang man lebt, sondern wie intensiv.Euer Mond ist meine Sonne, Euer Montag - mein Sonntag.Musik ist Leben!

      ⭐Psy Love Is My Love⭐
    • New

      RonXTCdaBass wrote:

      Thanks for this nice mod! :thumbsup:

      for me it works perfect.



      one question:

      is it possible to give the bar, the same color like the fleet-text?

      spio - yellow, nebular - purple, attack - green... and so on
      I haven't tried that yet.
      --------------------------------------------------------------------------------------
    • New

      Dany92 wrote:

      only in the last 10 minutes the green bar starts, when the shipment ends the green bar reaches about 1 fifth of the total bar, I don't understand
      The above method works fine for me.
      I think there is something wrong with your code.
      Please try testing with another 2moons source.
      --------------------------------------------------------------------------------------
    • New

      mein Verdacht @Dany92

      irgendwo in einer .css die gleiche Klasse wie die progressbar, nur eben anderen maaßen.

      schau dir mal deine Übersicht mit der Entwicklerkonsole des Browser an.
      Es zählt nicht wie lang man lebt, sondern wie intensiv.Euer Mond ist meine Sonne, Euer Montag - mein Sonntag.Musik ist Leben!

      ⭐Psy Love Is My Love⭐
    • New

      in the end I rewrote the JS part ahha, here I attach an improved solution with animation of a spaceship at the end of the event, moreover when it is in progress the bar will be yellow, when completed it will become green (the class part remains the same)

      JS :

      <script>
      function updateProgressBars() {
      const bars = document.querySelectorAll('.progress3-bar-overview');

      bars.forEach(bar => {
      const startTime = parseInt(bar.dataset.startTime) * 1000;
      const endTime = parseInt(bar.dataset.returnTime) * 1000;
      const now = Date.now();

      if (now < startTime) {
      bar.style.width = '0%';
      bar.classList.remove('progress-in-progress', 'progress-complete');
      } else if (now >= endTime) {
      bar.style.width = '100%';
      bar.classList.remove('progress-in-progress');

      if (!bar.classList.contains('progress-complete')) {
      bar.classList.add('progress-complete');


      const ship = document.createElement('div');
      ship.classList.add('spaceship');
      bar.parentElement.appendChild(ship);


      setTimeout(() => {
      ship.remove();
      }, 2000);
      }
      } else {
      const progress = ((now - startTime) / (endTime - startTime)) * 100;
      bar.style.width = progress.toFixed(2) + '%';
      bar.classList.remove('progress-complete');
      bar.classList.add('progress-in-progress');
      }
      });
      }


      updateProgressBars();
      setInterval(updateProgressBars, 1000);
      </script>

      CSS :

      .progress3-bar {
      padding: 0 6px;
      line-height: 14px;
      font-size: 12px;
      margin-bottom: 5px;
      margin-top: 5px;
      overflow: hidden;
      position: relative;
      }
      .progress3-bar-container {
      width: 100%;
      background-color: #000c1b;
      border: 1px solid #000;
      border-radius: 5px;
      overflow: hidden;
      }
      .progress3-bar-overview {
      height: 13px;
      background-color: #4cac50;
      width: 0%;
      transition: width 1.0s linear;
      }

      @keyframes spaceGlow {
      0% { box-shadow: 0 0 10px #2ecc71; }
      50% { box-shadow: 0 0 20px #00ff99, 0 0 40px #00ffcc; }
      100% { box-shadow: 0 0 10px #2ecc71; }
      }

      @keyframes spaceshipFly {
      0% { left: 0%; opacity: 0; }
      10% { opacity: 1; }
      100% { left: 100%; opacity: 0; }
      }

      .progress-in-progress {
      background-color: #f1c40f;
      }

      .progress-complete {
      background-color: #2ecc71;
      animation: spaceGlow 2s infinite;
      }

      .spaceship {
      position: absolute;
      top: -10px;
      height: 100px;
      width: 100px;
      background-image: url(/styles/theme/nsc/img/bar.png);
      background-size: contain;
      background-repeat: no-repeat;
      animation: spaceshipFly 2s ease-in-out forwards;
      z-index: 10;
      }
    • New

      hey there!

      he @Dany92

      flying spaceship sounds interesting. where you take it from?

      i like the color-change from yellow to green,
      but for me, the updated progressbar ends a min before the time is over and i've not seen a spaceship.
      Es zählt nicht wie lang man lebt, sondern wie intensiv.Euer Mond ist meine Sonne, Euer Montag - mein Sonntag.Musik ist Leben!

      ⭐Psy Love Is My Love⭐
    • New

      I had to change the name of the bar, in fact I used "progress3" ( change it if necessary in your overview file )

      also you have to put the image you want in the CSS path ( /style/nsc/img ..... )