Horizontal Latest Scores Block

Started by Chen Zhen, September 13, 2024, 01:12:50 PM

Previous topic - Next topic

Chen Zhen

Horizontal javascript marquee: Latest Scores
Version: SMF-Arcade v2.7.0.2+

Use the code content shown below in a php portal block.
Some adjustable variables are at the start of the block code.

PHP Block Code:
/*  Latest High Scores with Icons - Using javascript marquee */
/**************************
set $gameTypes
0 = Permission based
1 = Flash/HTML
2 = ROM only
3 = All game types
**************************/
global $boardurl;
$gameTypes = 0;

switch($gameTypes) {
case 1:
$where = 'WHERE rom_flag = {int:romflag} ';
$romflag = 0;
break;
case 2:
$where = 'WHERE rom_flag = {int:romflag} ';
$romflag = 1;
break;
case 3:
$where = '';
$romflag = 0;
break;
default:
$romflag = 0;
if (allowedTo('arcade_view_retro_arch')) {
$where = '';
}
else {
$where = 'WHERE rom_flag = {int:romflag} ';
}
}

/* For these dimensions... Set width to what suits your block, set height to what is needed for your images +5 */
$mar_width = 1400;
$mar_height = 55;
$mar_speed = 3;
$mar_pause = 1;

/* Thumbnail dimensions  */
$width = 50;
$height = 50;

/*  Number of scores to display,  games folder, enable thumbnail display */
$no_games = 29;  /* Set 1 to 29 games to display  */
$show_thumbnail = true;

$mar_width = empty($mar_width) || $mar_width > 1400 ? 1400 : abs($mar_width);
$no_games = empty($no_games) || $no_games > 29 ? 29 : abs($no_games);

if ($no_games < 1) {$no_games = 1;}
/*  Execute the function and start the display  */
$display = latest_scores2($no_games, $width, $height, $show_thumbnail, $where, $romflag);
echo '
    <div style="display: flex-block;overflow:hidden;border: 0px;white-space: nowrap;">
        <div style="display: inline;position:relative;width:' . $mar_width . 'px;height:' . $mar_height . 'px;overflow:hidden;">
            <div style="display: inline;position:relative;width:' . $mar_width . 'px;height:' . $mar_height . 'px;">
                <div id="arcadeBlockInnerMarquee" style="position:relative;left:0px;top:0px;" onmouseover="arcadeMarqueeSpeedVar(true)" onmouseout="arcadeMarqueeSpeedVar(false)">
                    <div id="arcadeBlockInnerContainer1" style="display: inline;visibility:hidden;position:relative;"></div>
                </div>
            </div>
        </div>
    </div>';
echo javascript_marquee($display, $mar_width, $mar_height, $mar_speed, $mar_pause, $where, $romflag);

function javascript_marquee($display2, $mar_width, $mar_height, $mar_speed, $mar_pause, $where, $romflag)
{
    echo '
    <script type="text/javascript">
        var marqueewidth = "' . $mar_width . 'px";
        var marqueeheight = "' . $mar_height . 'px";
        var marqueespeed = "' . $mar_speed . '";
        var pauseit = "' . $mar_pause . '";
        var marqueecontentArcade1 = \'<span id="arcadeBlockInnerContainer1" style="font-face: Arial;white-space: nowrap;">' . $display2 . '</span>\';
        marqueespeed = Math.max(1, marqueespeed-1);
        var copyspeed = marqueespeed;
        var pausespeed = (pauseit==0) ? copyspeed: 0;
        document.getElementById("arcadeBlockInnerContainer1").innerHTML = marqueecontentArcade1;

        var actualwidth = "";
        var cross_marquee, ns_marquee;
        function arcadePopulateBlockContainer1(){
            cross_marquee = document.getElementById("arcadeBlockInnerMarquee");
            cross_marquee.style.left = parseInt(marqueewidth)+8+"px";
            cross_marquee.innerHTML = marqueecontentArcade1;
            actualwidth = document.getElementById("arcadeBlockInnerContainer1") ? document.getElementById("arcadeBlockInnerContainer1").offsetWidth : 0;
            lefttime=setInterval("scrollmarquee()",20);
        }

        function scrollmarquee(){
            if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
                cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px";
            else
                cross_marquee.style.left=parseInt(marqueewidth)+8+"px";
        }
        function arcadeMarqueeSpeedVar(pauseitz) {
            if (!pauseitz)
                copyspeed = marqueespeed;
            else {
                copyspeed = pausespeed;
            }
        }
        if (window.addEventListener)
            window.addEventListener("load", arcadePopulateBlockContainer1, false);
        else if (window.attachEvent)
            window.attachEvent("onload", arcadePopulateBlockContainer1);
        else
            window.onload = arcadePopulateBlockContainer1();
    </script>';
}

/*  Function to read the db for latest scores and relevant info */
function latest_scores2($no_games, $width, $height, $show_thumbnail, $where, $romflag)
{
    $start = 0;
    $count = $no_games;
    $display = '&nbsp;';
    $space1 = '<span style="padding-left: 3em;"></span>';
    $space2 = '<span style="padding-left: 14em;"></span>';
    $space3 =  '<span style="padding-left: 1em;"></span>';
  /* show latest high scores */
    global $smcFunc, $scripturl, $db_prefix, $txt, $arcadeModSettings;

    $result = $smcFunc['db_query']('', '
        SELECT game.id_game, game.game_name, game.thumbnail, game.game_directory, score.score, score.position, game.rom_flag,
        IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, score.player_name) AS real_name,  score.end_time
        FROM {db_prefix}arcade_scores AS score
        INNER JOIN {db_prefix}arcade_games AS game ON (game.id_game = score.id_game)
        LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = score.id_member)
        ' . $where . 'ORDER BY end_time DESC
        LIMIT {int:start}, {int:count}',
        array(
            'start' => $start,
            'count' => $count,
            'empty' => '',
'romflag' => $romflag,
        )
    );

    while ($game = $smcFunc['db_fetch_assoc']($result))
    {
$gamesUrl = !empty($game['rom_flag']) ? $arcadeModSettings['romGamesUrl'] : $arcadeModSettings['gamesUrl'];
$action = !empty($game['rom_flag']) ? 'retro_arch' : 'arcade';
        $game_thumb = $gamesUrl . '/' . $game['game_directory'] . '/' . $game['thumbnail'];

        $scoring = '<a style="padding: 0.075em 0em 0.075em 0em;" href="'.$scripturl.'?action=arcade;sa=highscore;game='.$game['id_game'].'">Scored: '. $game['score'].'</a>';
        $thumb = '';
        if ($show_thumbnail == true)
            $thumb = '<a href="'.$scripturl.'?action=' . $action . ';sa=play;game='.$game['id_game'].'"><img src="'.$game_thumb.'" style="border: 0px;height: ' . $height . 'px;width: ' . $width . 'px;" alt="'.$game['game_name'].'" title="Play '.$game['game_name'].'" /></a>' . $space3;

        $display .= $thumb . '<span style="width: 14em;min-width: 14em;"><span style="max-width: 12em;line-height: 98%;min-height: ' . $height . 'px;vertical-align: middle;position: absolute;padding: 0.15em 0em 0.15em 0em;"><a style="vertical-align: middle;padding: 0.075em 0em 0.075em 0em;" href="'.$scripturl.'?action=arcade;sa=play;game='.$game['id_game'].'">' . $game['game_name'] . '</a><span style="display: block;"></span><a style="padding: 0.075em 0em 0.075em 0em;" href="'.$scripturl.'?action=profile;u='.$game['id_member'].'">' . $game['real_name'] . '</a><span style="display: block;"></span>' . $scoring . '</span></span>' . $space2;

    }
    $smcFunc['db_free_result']($result);
    return $display;
}