Slides for mIRC — File Browser

SlidesformIRCv1.0 / SlidesformIRCv1.0 / slides.mrc

slides.mrc — 5.36 KB — Download this file

; Slides for mIRC
; To start, type: /slides

; Features:
; # Single player mIRC game
; # Use your own pictures to start this game.
; # Use any grid up to 50 (theoratically it supports any number, but it's capped there because of loading times).
; # The script virtually plays a game (without moving the pieces) to construct valid grids.
; # Dialogs and windows so it's easy on the eye.
; # Use the mouse cursor to move the slides.


; A small warning though, using very large grid number may take mIRC to load for a long time. Enjoy!


alias slides {
  if ($hget(slides)) hfree slides
  $iif($window(@Slides),window -c @Slides)
  $iif($dialog(slides),dialog -v slides,dialog -dmrv slides slides)
}
alias -l slidestart {
  var %file = $+(",$iif($isfile($1-),$1-,$$sfile($mircdir $+ *.jpg)),"), %w = $int($calc($pic(%file).width / $n)), $&
    %h = $int($calc($pic(%file).height / $n)), %loop = 1, %x = $calc(%w * $n), %y = $calc(%h * $n)
  dec %w | dec %h

  ; Loading Start
  loading

  window -aCdfk0p @Slides -1 -1 $calc(%x + 1) $calc(%y + 1)
  window -fhnp @hslides 1 1 $calc(%x + 1) $calc(%y + 1)

  ; Save Config
  putcfg x 0 | putcfg y 0 | putcfg w %w | putcfg h %h

  ; Also temporarily creates a hidden window to store the original image
  drawpic -c @hslides 0 0 %file
  drawrect -f @hslides $c 0 $getmove

  ; Virtual play to construct a valid grid
  virtualplay

  var %x = 0, %y
  while (%x <= $calc($n - 1)) {
    %y = 0
    while (%y <= $calc($n - 1)) {
      tokenize 46 $getco(%x,%y)
      drawcopy @hslides $getmove($1,$2) @Slides $getmove(%x,%y)
      inc %y
    }
    inc %x
  }
  window -c @hslides

  ; Loading End
  loading
  window -o @Slides
}
alias -l makemove {
  ; Usage /makemove <n|e|s|w> [0|1]
  var %x = $calc($x + $co($$1).x), %y = $calc($y + $co($1).y)
  if (!$2) {
    if (($calc(%x + 1) !isnum $+(1,-,$n)) || ($calc(%y + 1) !isnum $+(1,-,$n))) return
    drawcopy @Slides $getmove(%x,%y) @Slides $getmove
    drawrect -f @Slides $c 0 $getmove(%x,%y)
    hinc -m slides total
  }
  putco $x $y $getco(%x,%y) | putco %x %y 0.0
  putcfg x $calc($x + $co($1).x) | putcfg y $calc($y + $co($1).y)
  if (!$2) $iif($endgame,$iif($input(Congratulations ( $+ $getcfg(total) turns)!,o,Puzzle Solved), $&
    $iif($input(Another Puzzle?,y,Again...),slides,window -c @slides),window -c @slides))
}
alias -l endgame {
  ; $endgame returns $true if user solved hte puzzle
  var %x = 0, %y
  while (%x <= $calc($n - 1)) {
    %y = 0
    while (%y <= $calc($n - 1)) {
      if ($getco(%x,%y) != $+(%x,.,%y)) return $false
      inc %y
    }
    inc %x
  }
  return $true
}
alias -l virtualplay {
  ; Virtually plays a game to construct a valid grid
  ; Initialize default grid
  var %x = 0, %y
  while (%x <= $calc($n - 1)) {
    %y = 0
    while (%y <= $calc($n - 1)) {
      putco %x %y $+(%x,.,%y)
      inc %y
    }
    inc %x
  }
  var %a = 1, %b, %m, %con = $calc($n ^ 3)
  while (%a <= %con) {
    %m = $suggestmove($reversemove(%m))
    makemove %m 1
    inc %a
  }
}
alias -l suggestmove {
  ; Suggest a move
  var %m = $iif($y != 0,n) $iif($x != $calc($n - 1),e) $iif($y != $calc($n - 1),s) $iif($x != 0,w), $&
    %m = $iif($1,$remtok(%m,$1,1,32),%m)
  return $gettok(%m,$r(1,$numtok(%m,32)),32)
}

; Some shortened for ease:
alias -l n return $getcfg(n)
alias -l x return $getcfg(x)
alias -l y return $getcfg(y)
alias -l c return $color(background)

; Hash aliases:
alias -l getcfg return $hget(slides,$$1)
alias -l putcfg hadd -m slides $1 $$2
alias -l getco return $hget(slides,$+(c,$1,.,$$2))
alias -l putco hadd -m slides $+(c,$1,.,$2) $$3

alias -l getmove {
  ; Get coördinate outputs, important alias, usage $getmove([x],[y])
  return $calc(1 + $iif($2 != $null,$1,$x) * ($getcfg(w) + 1)) $&
    $calc(1 + $iif($2 != $null,$2,$y) * ($getcfg(h) + 1)) $getcfg(w) $getcfg(h)
}
; $reversemove([n|e|s|w])
alias -l reversemove return $replacex($1,n,s,e,w,s,n,w,e)

; Replaces [n,e,s,w] with a numerical representation, usage $co(<n|e|s|w>).[x|y]
alias -l co return $calc($iif($prop = x,$replace($1,e,1,w,-1),$replace($1,n,-1,s,1)))

;-- Dialog and window stuff --
dialog -l slides {
  title "Slides"
  size -1 -1 160 50
  option dbu

  edit "", 1, 5 5 100 10, autohs
  button "Select Image...", 2, 110 5 45 11
  combo 3, 5 20 80 10, drop
  button "OK", 4, 5 35 40 11, ok
}
on *:dialog:slides:init,sclick:0,2,4: {
  if ($devent = init) {
    var %a = 2
    while (%a <= 50) {
      did -a $dname 3 %a x %a Puzzle
      inc %a
    }
    did -c $dname 3 3
  }
  else {
    if ($did = 2) did -o $dname 1 1 $shortfn($$sfile($mircdir $+ *.jpg))
    elseif ($did = 4) {
      putcfg n $gettok($did(3),1,32)
      slidestart $did(1)
    }
  }
}
alias -l loading {
  ; Loading screen, usage '/loading' to start, '/loading' to end
  if ($window(@loading)) {
    window -c @loading
    return
  }
  window -aBCdhk0op +b @loading -1 -1 100 50
  var %a = drawtext @loading 1 Arial
  %a 12 22 7 Loading
  %a 10 16 25 Scrambling...
}
menu @Slides {
  sclick:{
    tokenize 32 $getmove
    if ($mouse.x isnum $+($1,-,$calc($1 + $3))) makemove $iif($mouse.y < $2,n,$iif($mouse.y > $calc($2 + $4),s))
    elseif ($mouse.y isnum $+($2,-,$calc($2 + $4))) makemove $iif($mouse.x < $1,w,$iif($mouse.x > $calc($1 + $3),e))
  }
  New:slides
  Exit:window -c @Slides
}
; mknobbout [at] gmail [dot] com