J-Script — File Browser

J-Scriptv2.2 / J-Scriptv2.2 / themes / mts.mrc

mts.mrc — 41.02 KB — Download this file

; MTS Theme Engine. 
; By Eric^^ <ericn@accesswave.ca>
; http://accesswave.ca/~ericn/
;
; Feel free to include this engine in your scripts.
; You may edit it as you like, but keep credits alive :P
;
;
; Thanks to Kamek, fubar and the rest of the mircscripts.org clan for helping me find bugs.
;
; You can use /_echo [text], /_echo.target [target] [text] and /_error [text] if you are implementing into script
;

alias theme {
  var %theme = $$sfile(*.mts,Select a theme:,OK)
  mtsload mts %theme
}
alias themes {
  dialog - $+ $iif($dialog(theme),v,md) theme theme
}

alias mtsecho {
  if ($1 != !script) && (%:echo) && ($1-) %:echo $1-
  else return
}

on *:start:mtsreload
on *:active:*:setfont $active

alias ctcp {
  if (!$2) return
  var %ctcp = $iif($2 == PING,PING $ctime,$upper($2) $3-)
  .raw privmsg $1 : $+ $chr(1) $+ %ctcp $+ $chr(1)
  set -un %::nick $1
  set -un %::target $1
  set -un %::chan $1
  set -un %::ctcp $gettok(%ctcp,1,32)
  set -un %::text $gettok(%ctcp,2-,32)
  set -un %:echo echo $colour(ctcp) -at
  set -un %::me $me
  if ($show) mtsecho $mtsget($iif($1 ischan,ctcpchanself,ctcpself))
}
alias _echo {
  set -un %::text $$1-
  set -un %:echo echo $colour(info) -at
  mtsecho $mtsget(ECHO)
}
alias _echo.target {
  set -un %::text $$2-
  set -un %::target $1
  set -un %:echo echo $colour(info) -t $1
  mtsecho $mtsget(ECHOTARGET)
}
alias _echo.error {
  set -un %::text $$1-
  set -un %:echo echo $colour(info2) -at
  mtsecho $mtsget(ERROR)
}
alias ctcpreply {
  if (!$2) return
  var %ctcp = $upper($2) $3-
  .raw notice $1 : $+ $chr(1) $+ %ctcp $+ $chr(1)
  set -un %::nick $1
  set -un %::target $1
  set -un %::ctcp $gettok(%ctcp,1,32)
  set -un %::text $gettok(%ctcp,2-,32)
  set -un %:echo echo $colour(ctcp) -at
  set -un %::me $me
  if ($show) mtsecho $mtsget(ctcpreplyself)
}
alias ended.notice {
  if (!$server) return
  if (!$2) return
  set -un %::nick $1
  set -un %::target $1
  set -un %::chan $1
  set -un %:echo echo $colour(notice) -ati3
  set -un %::text $2- 
  set -un %::cmode $remove($nick($1,$me).pnick,$me)
  set -un %::me $me
  .notice $1 %::text
  if ($show) mtsecho $mtsget($iif($1 ischan,NoticeSelfChan,NoticeSelf)).null
}
alias ended.me {
  if ($isid) { return $me } 
  else { 
    describe $active $1-
  }
}
alias ended.describe {
  if (!$server) return
  if ($2 == $null) return
  if ($show) {
    set -un %::nick $1 
    set -un %::target $1
    set -un %::chan $1
    set -un %:echo echo $colour(own) -ati3
    set -un %::text $2- 
    set -un %::me $me
    set -un %::cmode $remove($nick($1,$me).pnick,$me)
    var %mts = $iif($1 ischan,ActionChanSelf,ActionQuerySelf)
    if (#* iswm $1) && (!$chan($1)) var %mts = TextMsgSelf
    if ($chr(61) $+ = iswm $1) && (!$chat($1)) (!$query($1)) var %mts = TextMsgSelf
    if (#* !iswm $1) && ($chr(61) $+ * !iswm $1) && (!$query($1)) var %mts = TextMsgSelf
    if (%mts != TextMsgSelf) set -un %:echo echo $colour(own) -ti3 $1
    mtsecho $mtsget(%mts)
  }
  .msg $1 $chr(1) $+ ACTION %::text $+ $chr(1) 
}
alias ended.say {
  if ($isid) { return } 
  else { 
    msg $active $1-
  }
}
alias ended.msg {
  if (!$server) return
  if ($2 == $null) return
  if ($show) {
    set -un %::nick $1 
    set -un %::target $1
    set -un %::chan $1
    set -un %:echo echo $colour(own) -ati3
    set -un %::text $2- 
    set -un %::me $me
    set -un %::cmode $remove($nick($1,$me).pnick,$me)
    var %mts = $iif($1 ischan,TextChanSelf,TextQuerySelf)
    if (#* iswm $1) && (!$chan($1)) var %mts = TextMsgSelf
    if ($chr(61) $+ = iswm $1) && (!$chat($1)) (!$query($1)) var %mts = TextMsgSelf
    if (#* !iswm $1) && ($chr(61) $+ * !iswm $1) && (!$query($1)) var %mts = TextMsgSelf
    if (%mts != TextMsgSelf) set -un %:echo echo $colour(own) -ti3 $1
    mtsecho $mtsget(%mts)
  }
  .msg $1 $2-
}
alias ended.ame {
  var %c = 1
  while ($chan(%c)) {
    if ($show) describe $chan(%c) $$1-
    else .describe $chan(%c) $$1-
    inc %c
  }
}
alias ended.amsg {
  var %c = 1
  while ($chan(%c)) {
    if ($show) msg $chan(%c) $$1-
    else .msg $chan(%c) $$1-
    inc %c
  }
}

alias mtsdll return $dll($scriptdirmtsgen.dll,MTSPrecompile,$1-)
alias mtsget2 {
  alias mtsget {
    var %cs = $hget(theme,BASECOLORS)
    set -un %::c1 $gettok(%cs,1,44)
    set -un %::c2 $gettok(%cs,2,44)
    set -un %::c3 $gettok(%cs,3,44)
    set -un %::me $me
    set -un %::c4 $gettok(%cs,4,44)
    set -un %::timestamp $timestamp
    set -un %::pre [ [ $hget(theme,prefix) ] ]
    set -un %::parentext [ [ $iif(%::text,$hget(theme,parentext)) ] ]
    var %return = [ [ $hget(theme,$$1) ] ]
    if (%return == $null) return
    if (!script* iswm %return) {
      if ($gettok(%return,2-,32)) [ [ $ifmatch ] ] 
      return !script
    }
    if (!script* !iswm %return) return %return
  }
}
alias mtsget {
  var %cs = $hget(theme,BASECOLORS)
  set -un %::c1 $gettok(%cs,1,44)
  set -un %::c2 $gettok(%cs,2,44)
  set -un %::c3 $gettok(%cs,3,44)
  set -un %::me $me
  set -un %::c4 $gettok(%cs,4,44)
  set -un %::timestamp $timestamp
  set -un %::pre [ [ $hget(theme,prefix) ] ]
  set -un %::parentext [ [ $iif(%::text,$hget(theme,parentext)) ] ]
  var %return = [ [ $hget(theme,$$1) ] ]
  if (%return == $null) && ($prop != null) halt
  if (!script* iswm %return) {
    if ($gettok(%return,2-,32)) [ [ $ifmatch ] ] 
    else if ($prop != null) halt
    return !script
  }
  if (!script* !iswm %return) return %return
  if ($prop != null) halt
}
alias mtsreload {
  var %command = $iif(%theme,%theme)
  if (%command) $ifmatch
  else mtsload
}
alias mtsload {

  ; mtsload [[schemeN or MTS] [filename]]

  if ($1 == -s) { tokenize 32 $2- | var %silent = 1 }

  var %s = $1,%f = $2-,%d = $scriptdirdefault.mts,%w = @loadtheme

  if ($script($mtsget(script).null)) .unload -rs $nopath($ifmatch)
  if ($hget(theme)) { 
    set -un %:echo echo $colour(normal) -at 
    if ($hget(theme,unload)) && (!%silent) { 
      mtsecho $mtsget(unload)
    }
    hdel -w theme * 
  }
  if (!$hget(theme)) hmake theme 10
  set %theme mtsload $1-
  window -h %w
  if ($isfile(%d)) {
    loadbuf %w " $+ %d $+ "
    var %l = 1
    while (%l <= $line(%w,0)) {
      var %line = $line(%w,%l),%thing = $gettok(%line,1,32)
      if (self isin %thing) && (<me> !isin %line) && (ctcpself != %thing) var %line = $replace(%line,<nick>,<me>)
      if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
      inc %l
    }
  }
  clear %w
  if ($isfile(%f)) {
    loadbuf -tMTS %w " $+ %f $+ "
    var %l = 1
    while (%l <= $line(%w,0)) {
      var %line = $line(%w,%l),%thing = $gettok(%line,1,32)
      if (self isin %thing) && (<me> !isin %line) && (ctcpself != %thing) var %line = $replace(%line,<nick>,<me>)
      if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
      inc %l
    }
    if (%s != MTS) {
      clear %w
      loadbuf -t $+ %s %w " $+ %f $+ "
      var %l = 1
      while (%l <= $line(%w,0)) {
        var %line = $line(%w,%l),%thing = $gettok(%line,1,32)
        if (self isin %thing) && (<me> !isin %line) && (ctcpself != %thing) var %line = $replace(%line,<nick>,<me>)
        if ($gettok(%line,2,32)) && ($left(%line,1) != $chr(59)) hadd theme $mtsdll(%line)
        inc %l
      }
    }
  }
  clear %w
  if ($mtsget(SCRIPT).null) && (!$script($mtsget(SCRIPT).null)) .load -rs " $+ $+($nofile(%f),$mtsget(SCRIPT)) $+ "
  var %cs = $hget(theme,BASECOLORS),%::c1 = $gettok(%cs,1,44),%::c2 = $gettok(%cs,2,44),%::c3 = $gettok(%cs,3,44),%::c4 = $gettok(%cs,4,44)
  .timestamp $iif($mtsget(TIMESTAMP).null == ON,ON,OFF) 
  if ($mtsget(TIMESTAMPFORMAT).null) .timestamp -f [ [ $ifmatch ] ]
  if (!%silent) {
    mtscolor | mtsnicklist | setfonts | bg | set -un %:echo echo $colour(normal) -at 
    if ($hget(theme,load)) mtsecho $mtsget(load)
  }
}

alias colorset {
  if ($chr(44) isin $1-) { tokenize 44 $1- } 
  colour background $1 | colour action $2 | colour ctcp $3 | colour highlight $4 | colour info $5 | colour info2 $6 | colour invite $7 | colour join $8 | colour kick $9 | colour mode $10 | colour nick $11 | colour normal $12 | colour notice $13 | colour notify $14 
  colour other $15 | colour own $16 | colour part $17 | colour  quit $18 | colour topic $19 | colour wallops $20 | colour whois $21 | colour editbox $22 | colour editbox text $23 | colour listbox $24 | colour listbox text $25 | color grayed text $iif($26,$26,$25) | colour inactive $iif($27 isnum,$27,$22)
}
alias colorreset var %a = 0 | while (%a < 15) { colour -r %a | inc %a }
alias mtsnicklist {
  var %c = $cnick(0) 
  while (%c) {
    if ($cnick(%c)) { .cnick -r $cnick(%c) } 
    else { .cnick -r * } 
    dec %c 
  } 
  if ($hget(theme,CLINEME) isnum) { .cnick $eval($me,0) $fixcol($hget(theme,CLINEME)) } 
  if ($hget(theme,CLINEENEMY) isnum) { .cnick -i * $fixcol($hget(theme,CLINEENEMY)) } 
  if ($hget(theme,CLINEFRIEND) isnum) { .cnick -ovpn * $fixcol($hget(theme,CLINEFRIEND)) } 
  if ($hget(theme,CLINEOP) isnum) { .cnick * $fixcol($hget(theme,CLINEOP)) @ } 
  if ($hget(theme,CLINEHOP) isnum) { .cnick * $fixcol($hget(theme,CLINEHOP)) % } 
  if ($hget(theme,CLINEVOICE) isnum) { .cnick * $fixcol($hget(theme,CLINEVOICE)) + } 
  if ($hget(theme,CLINEREGULAR) isnum) { .cnick -n * $fixcol($hget(theme,CLINEREGULAR)) } 
}


alias fixcol return $right($+(0,$calc($1 % 16)),2)
alias mtscolor {
  var %rgbc = $mtsget(rgbcolors)
  if (!%rgbc) var %rgbc = 255,255,255 0,0,0 0,0,128 0,144,0 255,0,0 128,0,0 160,0,160 255,128,0 255,255,0 0,255,0 0,144,144 0,255,255 0,0,255 255,0,255 128,128,128 208,208,208
  var %colors = $mtsget(colors)
  if (!%colors) var %colors = 0,6,4,5,2,3,3,3,2,2,3,1,5,7,12,1,3,2,2,5,1,0,1,0,1,7
  var %a = 1 | while %a < 17 { colour $calc(%a -1) [ $rgb( [ $gettok(%rgbc,%a,32) ] ) ] | inc %a } 
  colorset %colors
}

on *:input:*:{
  return

  ;disabled

  if ($left($1,1) == /) && (!$ctrlenter) || ($1 == $null) || (!$server) || ($halted) { return }
  if ($target == Status Window) || (@* iswm $target) { return }

  ; *************************************************
  ; IF YOU ARE TO HAVE A NICK COMPLETOR YOU SHOULD
  ; MAKE IT WORK WITH THIS ENGINE. IT IS RECOMMENDED 
  ; THAT YOU INSERT THE NICK COMPLETOR CODE HERE.
  ; *************************************************
  ;
  ; EX:
  ; 
  ; Simply remove the ";" after the "CODE START" and before "CODE END" lines
  ; This simple nick completor will change 'nic: <text>' to 'Nickname, <text>'
  ; You may edit it to your liking
  ;
  ;
  ; *** CODE START ***

  if (*: iswm $1) {
    var %i = 1 
    while ($nick(#,%i)) { 
      if ($left($1,-1) $+ * iswm $nick(#,%i)) { 

        var %text = $nick(#,%i) $+ , $2- 
        break     

      }
      inc %i
    } 

    if (!%text) var %text = $1-
    .tokenize 32 %text

  }

  ; *** CODE END ***


  .signal mts.input $target $nick $1- | haltdef
}
;on ^*:join:*:if (!$halted) { .signal mts.join $target $nick $address | haltdef }
;on ^*:part:*:if (!$halted) { .signal mts.part $target $nick $address $1- | haltdef }
on ^*:quit:{
  if (!$halted) {
    var %q = 1
    while $comchan($nick,%q) {
      .signal mts.quit $nick $address $comchan($nick,%q) $1-
      inc %q
    }
    haltdef
  }
}
on ^*:nick:if (!$halted) { .signal mts.nick $nick $newnick | haltdef }
on ^*:chat:*:if (!$halted) { .signal mts.text $+(=,$target) $nick $address $1- | haltdef }
on ^*:text:*:*:if (!$halted) { .signal mts.text $target $nick $address $1- | haltdef }
on ^*:action:*:*:if (!$halted) { .signal mts.action $target $nick $address $1- | haltdef }
;on ^*:notice:*:*:if (!$halted) { .signal mts.notice $target $nick $address $1- | haltdef }
;on ^*:snotice:*:if (!$halted) { .signal mts.snotice $nick $1- | haltdef }
on ^*:rawmode:*:if (!$halted) { .signal mts.mode $target $nick $address $1- | haltdef }
on ^*:usermode:if (!$halted) { .signal mts.umode $1- | haltdef }
on ^*:error:*:if (!$halted) { .signal mts.error $1- | haltdef }
on ^*:kick:*:if (!$halted) { .signal mts.kick $target $nick $address $knick $1- | haltdef }
on ^*:notify:if (!$halted) { .signal mts.notify $nick | haltdef }
on ^*:unotify:if (!$halted) { .signal mts.unotify $nick | haltdef }
on *:ctcpreply:*:{

  ; OK, I added this line so that we can use lag bars. 
  ; you can make your lag bars like so...
  ;
  ; alias lagcheck .ctcpreply $me LAG $ticks
  ; on *:ctcpreply:LAG &:if ($nick == $me) && ($2 isnum) { echo -a Lag: $calc($ticks -$2) $+ ms }
  ;
  ; If you want this, uncomment the following line out.

  ; if ($1 == LAG) && ($2 isnum) { haltdef | halt }

  if (!$halted) { .signal mts.ctcpreply $nick $address $1- | haltdef }
}
on ^*:topic:*:if (!$halted) { .signal mts.topic $target $nick $address $1- | haltdef }
on ^*:invite:*:if (!$halted) { .signal mts.invite $nick $address $chan | haltdef }
on ^*:wallops:*:if (!$halted) { .signal mts.wallop $nick $1- | haltdef }
ctcp *:*:*:{
  if (!$halted) { 
    if ($1 == dcc) return
    if ($1 == PING) && ($2) .ctcpreply $nick PING $2
    if ($1 == TIME) .ctcpreply $nick TIME $asctime
    if ($1 == MOTFV) tokenize 32 VERSION $2-
    else return
    .signal mts.ctcp $target $nick $address $1- | haltdef
  }
}
raw *:*:.signal mts.raw $numeric $1- | halt
on *:DNS:{
  return
  ; disabled
  if (!$halted) { 
    set -un %:echo echo $colour(info2) -at
    if (!$raddress) { mtsecho $mtsget(DNSerror) }
    if ($raddress) { set -un %::raddress $raddress | set -un %::iaddress $iaddress | set -un %::naddress $naddress | mtsecho $mtsget(DNSresolve) }
    unset %::address
    haltdef
  }
}

on *:signal:mts.*:{
  scid $cid

  var %event = $right($signal,-4)
  set -un %::target $iif($1,$1,$active)
  set -un %::chan $1
  set -un %::nick $2
  set -un %::address $3
  set -un %::text $4-
  set -un %::me $me
  set -un %:echo echo $colour(info) -st

  if (%event == input) {
    set -un %:echo echo $colour(own) -ti3 $1
    set -un %::cmode $remove($nick($1,$2).pnick,$2)
    set -un %::text $3-
    set -un %::address $right($address($me,5),$calc($len($address($me,5)) - $pos($address($me,5),!)))
    set -un %::cnick $nick($1,$2).color
    if (#* iswm $1) var %mts = TextChanSelf
    elseif (#* !iswm $1) var %mts = TextQuerySelf
    mtsecho $mtsget(%mts)
    .msg $1 $3-
  }

  if (%event == text) {
    var %target = $iif(#* iswm $1,$1,$2)
    if (=* iswm $1) var %target = $1
    set -un %:echo echo $colour(normal) -mtli3 %target
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::cnick $nick($1, $2).color
    if (#* iswm $1) var %mts = TextChan
    elseif (#* !iswm $1) var %mts = TextQuery
    mtsecho $mtsget(%mts)
  }

  if (%event == action) {
    set -un %:echo echo $colour(action) -mtli3 $iif(#* iswm $1,$1,$2)
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::cnick $nick($1, $2).color
    if (#* iswm $1) var %mts = ActionChan
    elseif (#* !iswm $1) var %mts = ActionQuery
    mtsecho $mtsget(%mts)
  }

  if (%event == notice) {
    set -un %:echo echo $colour(notice) -ati3
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::cnick $nick($1, $2).color
    if (#* iswm $1) var %mts = NoticeChan
    elseif (#* !iswm $1) var %mts = Notice
    mtsecho $mtsget(%mts)
  }

  if (%event == snotice) {
    set -un %::address $address 
    set -un %::nick $1
    set -un %::server $1
    set -un %::text $2-
    set -un %:echo echo $colour(notice) -smt
    mtsecho $mtsget(noticeserver)
  }

  if (%event == umode) {
    set -un %::nick $me
    set -un %::address $right($address($me,5),$calc($len($address($me,5)) - $pos($address($me,5),!)))
    set -un %::modes $1-
    set -un %::text $1-
    set -un %:echo echo $colour(mode) -smt
    mtsecho $mtsget(modeuser)
  }

  if (%event == error) {
    set -un %:echo echo $colour(info2) -smt
    set -un %::text $1-
    mtsecho $mtsget(servererror)
  }

  if (%event == mode) {
    ;.timerredonicklist -m 1 500 mtsnicklist
    set -un %::cmode $left($remove($nick($1,$2).pnick,$2),1)
    set -un %::modes $4-
    set -un %:echo echo $colour(mode) -tm $1
    mtsecho $mtsget(mode)
  }

  if (%event == topic) {
    set -un %:echo echo $colour(topic) -mt $1
    mtsecho $mtsget(topic)
  }

  if (%event == invite) {
    set -un %::nick $1
    set -un %::address $2
    set -un %::chan $3
    set -un %:echo echo $colour(invite) -at
    mtsecho $mtsget(invite)
  }

  if (%event == ctcp) {
    set -un %::ctcp $4 
    set -un %::text $5- 
    if (#* iswm $1) { set -un %:echo echo $colour(ctcp) -mt $1 | var %mts = ctcpchan }
    else { set -un %:echo echo $colour(ctcp) -at | var %mts = ctcp }
    mtsecho $mtsget(%mts)
  }

  if (%event == ctcpreply) {
    if ($3 == PING) { 
      set -un %::ctcp PING 
      set -un %::text $iif($4 isnum,$duration($calc($ctime - $4)),$4-) 
      goto echo 
    }
    set -un %::ctcp $3
    set -un %::text $4-
    :echo 
    set -un %::nick $1
    set -un %::address $2
    set -un %:echo echo $colour(ctcp) -at 
    mtsecho $mtsget(ctcpreply) 
    halt
  }

  if (%event == join) {
    var %mts = join
    if ($2 == $me) { var %mts = joinself | bg | setfonts }
    ;.timerredonicklist -m 1 500 mtsnicklist
    set -un %:echo echo $colour(join) -mt $1
    mtsecho $mtsget(%mts)
  }  

  if (%event == part) {
    if ($2 == $me) halt
    set -un %:echo echo $colour(part) -mt $1
    mtsecho $mtsget(part)
  }

  if (%event == kick) {
    set -un %::knick $4
    set -un %::kaddress $right($address($knick,0),$calc($len($address($knick,0)) -2))
    set -un %::text $5-
    set -un %:echo echo $colour(kick) -mt $1
    if ($knick == $me) { set -un %:echo echo -st }
    mtsecho $mtsget($iif($knick == $me,KICKSELF,KICK))
  }

  if (%event == quit) {
    set -un %:echo echo $colour(quit) -mt $3
    set -un %::nick $1
    set -un %::address $2
    set -un %::text $4-
    set -un %::chan $3
    mtsecho $mtsget(quit)
  }

  if (%event == wallops) {
    set -un %::nick $1 
    set -un %::text $2- 
    set -un %:echo echo $colour(wallop) -st 
    mtsecho $mtsget(wallop)
  }

  if (%event == notify) {
    ;  var %ignore = insert,nicks,that,you,don't,want,to,notify,here
    if ($findtok(%ignore,$1,44)) halt
    set -un %::nick $1
    set -un %::text $notify($1).note
    set -un %:echo echo $colour(notify) -at 
    mtsecho $mtsget(notify)
  }

  if (%event == unotify) {
    ;  var %ignore = insert,nicks,that,you,don't,want,to,notify,here
    if ($findtok(%ignore,$1,44)) halt
    set -un %::nick $1
    set -un %::text $notify($1).note
    set -un %:echo echo $colour(notify) -at 
    mtsecho $mtsget(unotify)
  }

  if (%event == nick) {
    var %mts = Nick
    if ($2 == $me) || ($1 == $me) %mts = NickSelf
    set -un %::nick $1
    set -un %::newnick $2
    var %q = 1
    while $comchan($2,%q) {
      set -un %::chan $comchan($2,%q) 
      set -un %:echo echo $colour(nick) -mt %::chan
      mtsecho $mtsget(%mts)
      inc %q
    }
  }


  if (%event == raw) {
    var %raw = $right(00 $+ $1,3) | tokenize 32 $2-
    ; /list
    if (%raw == 322) halt

    ; /invite
    if (%raw == 341) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info) -tm $3 }

    ; /server
    if (%RAW == 001) { set -un %:echo echo $colour(info) -st }
    if (%RAW == 002) { set -un %::address $5 | set -un %::value $8 | set -un %:echo echo $colour(info) -st }
    if (%RAW == 003) { set -un %::value $6- | set -un %:echo echo $colour(info) -ts }
    if (%RAW == 005) { set -un %::text $2- | set -un %:echo echo $colour(info) -ts }

    ; /map
    if (%RAW == 015) { echo $colour(info) -ts $2- | halt }

    ; /links
    if (%RAW == 364) { echo $colour(info) -ts $2- | halt }

    ; /motd
    if (%RAW == 372) { set -un %::text $2- | set -un %:echo echo $colour(info) -ts }
    if (%RAW == 374) { set -un %:echo echo $colour(info) -st }
    if (%RAW == 376) { set -un %:echo echo $colour(info) -st }

    ; /Topic
    if (%RAW == 328) { set -un %::chan $2 | set -un %::text $3- | set -un %:echo echo $colour(topic) -mt $2 }
    if (%RAW == 332) { set -un %::chan $2 | set -un %::text $3- | set -un %:echo echo $colour(topic) -mt $2 }
    if (%RAW == 333) { set -un %::chan $2 | set -un %::nick $3 | set -un %::text $asctime($4) | set -un %:echo echo $colour(topic) -tm $2 }

    ; /Mode
    if (%RAW == 324) { if ($me ison $2) { set -un %::chan $2 | set -un %::modes $3- | set -un %:echo echo $colour(info) -tm $2 } }
    if (%RAW == 329) { if ($me ison $2) { set -un %::chan $2 | set -un %::text $asctime($3) | set -un %:echo echo $colour(info) -tm $2 }  }

    ; /Names
    if (%RAW == 353) { set -un %::chan $3 | set -un %::text $4- | set -un %:echo echo $colour(info2) -ts } 
    if (%RAW == 366) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st } 

    ; /Whois
    var %whois_raw = 307,311,319,312,301,317,318,313

    if ($istok(%whois_raw,%RAW,44) == $true) { return }

    if (%RAW == 307) { set -un %::nick $2 | set -un %::isreg is | set -un %:echo echo $colour(whois) -at | set -n %mu.nick $2 | set -n %mu.isreg is }


    if (%RAW == 311) { 
      set -un %::nick $2 | set -un %::address $+($3,@,$4) | set -un %::realname $6- | set -n %mu.address $+($3,@,$4) | set -n %mu.realname $6- | set -un %:echo echo $colour(whois) -at | if (!%mu.whois) { inc %mu.whois | goto skip }
      if (%mu.whois) { set -un %::isreg $iif(%mu.isreg,%mu.isreg,is not) | set -un %::wserver %mu.wserver | set -un %::ircop $iif(%mu.ircop,%mu.ircop,is not) | set -un %::signontime %mu.signontime | set -un %::idletime %mu.idletime | set -un %::text %mu.text | set -un %::serverinfo %mu.serverinfo | set -un %::chan %mu.chan | unset %mu.* | unset %mu.text | mtsecho $mtsget2(whois) }
      :skip
    }
    if (%RAW == 319) { set -un %::nick $2 | set -un %::chan $3- | set -un %:echo echo $colour(whois) -at | set -n %mu.chan $3- }
    if (%RAW == 312) { set -un %::nick $2 | set -un %::wserver $3 | set -un %::serverinfo $4- | set -n %mu.wserver $3 | set -n %mu.serverinfo $4- | set -un %:echo echo $colour(whois) -at }
    if (%RAW == 301) { set -un %::nick $2 | set -un %::text $3- | set -n %mu.text $3- | set -un %:echo echo $colour(whois) -at }
    if (%RAW == 317) { set -un %::nick $2 | set -un %::idletime $3 | set -un %::signontime $asctime($4) | set -un %:echo echo $colour(whois) -at | set -n %mu.idletime $3 | set -n %mu.signontime $asctime($4) }
    if (%RAW == 318) { 
      set -un %::nick $2 | set -un %:echo echo $colour(whois) -at 
      if (%mu.whois) { set -un %::isreg $iif(%mu.isreg,%mu.isreg,is not) | set -un %::address %mu.address | set -un %::realname %mu.realname  | set -un %::wserver %mu.wserver | set -un %::ircop $iif(%mu.ircop,%mu.ircop,is not) | set -un %::signontime %mu.signontime | set -un %::idletime %mu.idletime | set -un %::text %mu.text | set -un %::serverinfo %mu.serverinfo | set -un %::chan %mu.chan | unset %mu.* | unset %mu.text | mtsecho $mtsget2(whois) }
    }
    if (%RAW == 313) { set -un %::nick $2 | set -un %::ircop is | set -n %mu.ircop is | set -un %:echo echo $colour(whois) -at }

    ; /Who
    if (%RAW == 352) { set -un %::nick $6 | set -un %::chan $2 | set -un %::address $+($3,@,$4) | set -un %::wserver $5 | set -un %::away $7 | set -un %::value $8 | set -un %::realname $9- | set -un %:echo echo $colour(whois) -at }
    if (%RAW == 315) { set -un %::value $2 | set -un %:echo echo $colour(whois) -st }

    ; /Whowas
    ;    if (%RAW == 314) { 
    if (%RAW == 314) { return }
    ;      set -un %::nick $2 | set -un %::address $+($3,@,$4) | set -un %::realname $6- | set -n %mu.nick $2 | set -n %mu.address $+($3,@,$4) | set -n %mu.realname $6- | set -un %:echo echo $colour(whois) -st 
    ;      if (!%mu.whowas) { inc %mu.whowas | goto skip }
    ;      if (%mu.whowas) { set -un %::wserver %mu.wserver | unset %mu.* | mtsecho $hget(theme,whowas) } | :skip
    ;    }
    ;    if (%RAW == 369) { set -un %::nick $2 | set -un %:echo echo $colour(whois) -st | if (%mu.whowas) { set -un %::wserver %mu.wserver | set -un %::nick %mu.nick | set -un %::address %mu.address | set -un %::realname %mu.realname | unset %mu.* | mtsecho $hget(theme,WHOWAS) } }
    if (%RAW == 369) { return }


    ; /lusers
    if (%RAW == 251) { return }
    if (%RAW == 252) { return }
    if (%RAW == 253) { return }
    if (%RAW == 254) { return }
    if (%RAW == 255) { return }

    ;    if (%RAW == 251) { set -un %::users $4 | set -un %::text $7 | set -un %::value $10 | set -un %:echo echo $colour(info) -st }
    ;    if (%RAW == 252) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
    ;    if (%RAW == 253) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
    ;    if (%RAW == 254) { set -un %::value $2 | set -un %:echo echo $colour(info) -st }
    ;    if (%RAW == 255) { set -un %::users $4 | set -un %::value $7 | set -un %:echo echo $colour(info) -st }

    ; /userhost
    if (%RAW == 302) { set -un %::nick $gettok($2,1,62) | set -un %::address $remove($gettok($2,1,62),+,-,*) |  set -un %::value $remove($gettok($2,1,62),%%::address) | set -un %:echo echo $colour(whois) -at }

    ; /away
    if (%RAW == 305) { set -un %:echo echo $colour(info) -st }
    if (%RAW == 306) { set -un %:echo echo $colour(info) -st }

    ; Errors
    if (%RAW == 401) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -ast }
    if (%RAW == 402) { set -un %::server $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 403) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 404) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 405) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 406) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 407) { set -un %::nick $2 | set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 408) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 411) { set -un %::text $5- | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 412) { set -un %::text $1- | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 421) { set -un %::text $2 | set -un %::value $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 422) { set -un %::text $2- | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 411) { set -un %::server $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 431) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 432) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 433) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 406) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 436) { set -un %::nick $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 437) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 438) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 439) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 441) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 442) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 443) { set -un %::nick $2 | set -un %::chan $3 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 461) { set -un %::text $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 465) { set -un %:echo echo $colour(info2) -st }
    if (%RAW == 467) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 471) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 473) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 474) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 475) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if (%RAW == 482) { set -un %::chan $2 | set -un %:echo echo $colour(info2) -st }
    if ($istok(%whois_raw,%RAW,44)) && ($hget(theme,WHOIS)) return
    mtsecho $mtsget($+(raw,.,%raw))
  }
}

alias setfonts {
  var %i = $scon(0)
  while (%i) {
    scon %i
    var %a = $chan(0),%b = $query(0),%c = $chat(0)
    var %d = $gettok($hget(theme,fontdefault),2,44) $gettok($hget(theme,fontdefault),1,44),%e = $gettok($hget(theme,fontchan),2,44) $gettok($hget(theme,fontchan),1,44),%f = $gettok($hget(theme,fontquery),2,44) $gettok($hget(theme,fontquery),1,44),%d = $iif(%d,%d,12 tahoma),%e = $iif(%e,%e,%d),%f = $iif(%f,%f,%d)
    while (%a) { font $+(-d,$iif($gettok($mtsget(fontchan),3,44) == B,b)) $chan(%a) %e | dec %a }
    while (%b) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $query(%b) %f | dec %b } 
    while (%c) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $chat(%c) %f | dec %c } 
    if (%d) { 
      font $+(-ds,$iif($gettok($mtsget(fontdefault),3,44) == B,b)) %d 
      var %a = $window(0) | while %a { font -d $window(%a) %d | dec %a } 
    }
    dec %i
  }
} 
alias setfont {
  var %d = $gettok($hget(theme,fontdefault),2,44) $gettok($hget(theme,fontdefault),1,44),%e = $gettok($hget(theme,fontchan),2,44) $gettok($hget(theme,fontchan),1,44),%f = $gettok($hget(theme,fontquery),2,44) $gettok($hget(theme,fontquery),1,44),%d = $iif(%d,%d,12 tahoma),%e = $iif(%e,%e,%d),%f = $iif(%f,%f,%d)
  if ($1 ischan) { font $+(-d,$iif($gettok($mtsget(fontchan),3,44) == B,b)) $1 %e }
  if ($query($1)) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $1 %f } 
  if ($chat($1)) { font $+(-d,$iif($gettok($mtsget(fontquery),3,44) == B,b)) $1 %f } 
  if (%d) { font $+(-ds,$iif($gettok($mtsget(fontdefault),3,44) == B,b)) %d }
} 
alias bgrep {
  return $iif($1,$replace($1,fill,f,center,c,stretch,r,tile,t,photo,p),x)
}
alias bg {  
  var %i = 1,%td = $nofile($gettok(%theme,3-,32))
  while $scon(%i) {
    scon %i
    var %ch = $chan(0),%qu = $query(0),%cha = $chat(0)
    while (%ch) { background -e $+ $bgrep($gettok($hget(theme,IMAGECHAN),1,32)) $chan(%ch) $+(%td,$gettok($hget(theme,IMAGECHAN),2-,32)) | dec %ch }  
    while (%qu) { background -e $+ $bgrep($gettok($hget(theme,IMAGEQUERY),1,32)) $query(%qu) $+(%td,$gettok($hget(theme,IMAGEQUERY),2-,32)) | dec %qu }
    while (%cha) { background -e $+ $bgrep($gettok($hget(theme,IMAGEQUERY).null,1,32)) $chat(%cha) $+(%td,$gettok($hget(theme,IMAGEQUERY),2-,32)) | dec %cha }
    background -s $+ $bgrep($gettok($hget(theme,IMAGESTATUS),1,32)) $+(%td,$gettok($hget(theme,IMAGESTATUS),2-,32))
    inc %i
  }
  background -m $+ $bgrep($gettok($mtsget(IMAGEMIRC).null,1,32)) $+(%td,$gettok($mtsget(IMAGEMIRC).null,2-,32))
  if ($isfile($+(%td,$mtsget(imageswitchbar).null))) background -h $+(%td,$mtsget(imageswitchbar).null)
  if (!$isfile($+(%td,$mtsget(imageswitchbar).null))) background -hx
  if ($isfile($+(%td,$mtsget(imagetoolbar).null))) background -l $+(%td,$mtsget(imagetoolbar).null)
  if (!$isfile($+(%td,$mtsget(imagetoolbar).null))) background -lx
  if ($isfile($+(%td,$mtsget(imagebuttons).null))) background -u $+(%td,$mtsget(imagebuttons).null)
  if (!$isfile($+(%td,$mtsget(imagebuttons).null))) background -ux
}


dialog theme {
  icon $scriptdirthemes.ico
  title Themes Manager
  icon res\icons\themes.ico
  size -1 -1 440 287
  box "Themes", 1, 2 4 238 46
  combo 2, 10 20 222 150, size drop sort
  box "Schemes", 3, 242 4 196 46
  button "Apply", 6, 360 258 74 24
  button "Cancel", 7, 280 258 74 24, cancel
  button "OK", 8, 200 258 74 24, ok
  combo 10, 250 22 180 150, size drop
  box "Information", 11, 242 50 196 196
  text "Name:", 12, 248 64 42 16
  text "Author:", 13, 248 84 44 16
  text "E-mail:", 14, 248 104 46 16
  text "Website:", 15, 248 124 50 16
  text "Description:", 16, 248 168 88 16
  edit "", 17, 246 182 188 58,multi,autovs,vsbar,return,read
  edit "", 18, 310 64 124 20,read,autohs
  edit "", 19, 310 84 124 20,read,autohs
  edit "", 20, 310 104 124 20,read,autohs
  edit "", 21, 310 122 124 20,read,autohs
  text "Version:", 22, 248 144 50 16
  edit "", 23, 310 140 124 20,read,autohs
  box "Preview", 24, 2 50 238 196
  icon 25, 9 67 223 171
  menu &File,26
  item "",27, 
  item break , 28,
  item &Exit,29
  menu &About,30
  item more themes...,31
  item break,32
  item about,33
  button Generate Preview,34, 70 125 100 25,flat hide
}
alias -l themepreview {
  if ($isfile($2-)) {
    did -g $1 25 " $+ $2- $+ "
    did -v $1 25
    did -h $1 34
  }
  else {
    did -h $1 25
    did -v $1 34
  }
}
alias -l addschemes did -r $dname 10 | did -a $dname 10 ::Default:: | var %a = 1 | while $read(" $+ $1- $+ ",w,scheme $+ %a *) { did -a $dname 10 $gettok($read($1-,w,scheme $+ %a *),2-,32) | inc %a } | did -c $dname 10 1
alias -l resel var %a = $did($dname,2).sel,%b = $did($dname,10).sel | did -u $dname 2,10 | .timerresel -m 1 100 if ($dialog(theme)) did -c $dname 2 %a | .timerresel2 -m 1 100 if ($dialog(theme)) did -c $dname 10 %b
alias -l mtspreview {
  if (!$2) { if ($show) echo -at /mtspreview: insuficient parameters | halt }
  if (!$isfile($2-)) { if ($show) echo -at Cannot find $2- | halt }
  var %bmp = $+($scriptdir,temp\,$left($nopath($2-),-4),$1,.jpg)
  write -c " $+ %bmp $+ "
  if ($window(@preview)) window -c @preview
  window -fopk0hd +fl @preview -1 -1 223 171
  hsave -o theme temp-theme.erc
  if ($hget(theme)) { hdel -w theme * }
  if (!$hget(theme)) hmake theme 20 
  window -h @theme 
  loadbuf -t $+ MTS @theme " $+ $2- $+ "
  var %a = $line(@theme,0) 
  while %a { 
    if ($left($line(@theme,%a),1) != $chr(59)) && ($gettok($line(@theme,%a),2,32)) { 
      hadd theme $mtsdll($line(@theme,%a)) 
    } 
    dec %a 
  } 
  window -c @theme
  if ($1 != mts) {
    window -h @theme
    loadbuf -t $+ $1 @theme " $+ $2- $+ "
    var %a = $line(@theme,0) 
    while %a { 
      if ($left($line(@theme,%a),1) != $chr(59)) && ($gettok($line(@theme,%a),2,32)) { 
        hadd theme $mtsdll($line(@theme,%a)) 
      } 
      dec %a 
    } 
    window -c @theme
  }
  if ($hget(theme,SCRIPT)) && (!$script($hget(theme,SCRIPT))) .load -rs " $+ $+($nofile($2-),$hget(theme,SCRIPT)) $+ "
  var %cs = $hget(theme,BASECOLORS),%::c1 = $gettok(%cs,1,44),%::c2 = $gettok(%cs,2,44),%::c3 = $gettok(%cs,3,44),%::c4 = $gettok(%cs,4,44)
  .timestamp $iif($hget(theme,TIMESTAMP) == ON,ON,OFF) 
  if ($hget(theme,TIMESTAMPFORMAT)) .timestamp -f [ [ $ifmatch ] ] 
  window -fopk0h +fl @preview -1 -1 223 171
  var %color = $hget(theme,colors),%rgbs = $hget(theme,RGBColors)
  set -un %f.name " $+ $gettok($hget(theme,fontdefault),1,44) $+ " | set -un %f.size $gettok($hget(theme,fontdefault),2,44) | set -un %f.pos 0
  drawdot @preview $gettok(%color,1,44) 1000 0 0
  set -un %:echo mtsprview $gettok(%color,8,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::chan #eIRC | set -un %::address theme@preview.com | mtsecho $mtsget(JOIN).null
  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::me Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::cmode @ | set -un %::text Hi preview! | mtsecho $mtsget(TextChanSelf).null
  set -un %:echo mtsprview $gettok(%color,10,44) $gettok(%color,1,44) | set -un %::address Eric^^@owns.you.com | set -un %::nick Eric^^ | set -un %::modes +v preview | mtsecho $mtsget(Mode).null
  set -un %:echo mtsprview $gettok(%color,12,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text Hey Eric^^ $+ ! What's up? | mtsecho $mtsget(TextChan).null
  set -un %:echo mtsprview $gettok(%color,21,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::realname eIRC $ver | set -un %::wserver *.Undernet.org | set -un %::idletime 21 | set -un %::signontime Jan 4th 1987 at 5:00pm
  mtsecho $mtsget(WHOIS).null | mtsecho $mtsget(raw.311).null | mtsecho $mtsget(raw.319).null | mtsecho $mtsget(raw.312).null | mtsecho $mtsget(raw.317).null | mtsecho $mtsget(raw.318).null
  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::cmode @ | set -un %::me Eric^^ | set -un %::text Nothing, you? | mtsecho $mtsget(TextChanSelf).null
  set -un %:echo mtsprview $gettok(%color,2,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text gtg | mtsecho $mtsget(ActionChan).null
  set -un %:echo mtsprview $gettok(%color,16,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::cmode @ | set -un %::nick Eric^^ | set -un %::text See ya! :) | set -un %::me Eric^^ | mtsecho $mtsget(TextChanSelf).null
  set -un %:echo mtsprview $gettok(%color,12,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text I'll be back later, bye. | mtsecho $mtsget(TextChan).null
  set -un %:echo mtsprview $gettok(%color,18,44) $gettok(%color,1,44) | set -un %::nick preview | set -un %::address theme@preview.com | set -un %::cmode + | set -un %::text http://eircweb.com | mtsecho $mtsget(quit).null
  set -un %:echo mtsprview $gettok(%color,8,44) $gettok(%color,1,44) | set -un %::nick you-suck | set -un %::address I@am.du.mb | set -un %::chan #eirc | mtsecho $mtsget(join).null
  set -un %:echo mtsprview $gettok(%color,9,44) $gettok(%color,1,44) | set -un %::nick Eric^^ | set -un %::address Eric^^@owns.you.com | set -un %::text Don't come back. | set -un %::knick you-suck | set -un %::kaddress I@am.du.mb | set -un %::chan #eIRC | mtsecho $mtsget(Kick).null
  set -un %:echo mtsprview $gettok(%color,6,44) $gettok(%color,1,44) $colour(info) :: End of $nopath($2-) preview
  set -un %:echo mtsprview $gettok(%color,6,44) $gettok(%color,1,44) $colour(info) :: MTS Theme engine by Eric^^
  var %c = 1
  while (%c != 16) {
    var %r = [ $rgb( [ $gettok(%rgbs,%c,32) ] ) ]
    if ($gettok(%r,2,44)) var %r = [ $rgb( [ %r ] ) ]
    if (%r) drawreplace -r @preview $colour($calc(%c -1)).rgb [ %r ]
    inc %c
  }
  drawsave -b32q100 @preview " $+ %bmp $+ "
  window -c @preview
  if ($hget(theme,SCRIPT)) && ($script($hget(theme,SCRIPT))) { .unload -rs $hget(theme,SCRIPT) }
  hdel -w theme * | hload theme temp-theme.erc | .remove -q temp-theme.erc
  .timestamp $iif($hget(theme,TIMESTAMP) == ON,ON,OFF) 
  if ($hget(theme,TIMESTAMPFORMAT)) .timestamp -f [ [ $ifmatch ] ]
  return %bmp
}
alias mtsprview if ($3) { drawtext -pb @preview $1 $2 %f.name %f.size 2 %f.pos $3-    | inc %f.pos $height($3-,%f.name,%f.size)  }
on *:dialog:theme:*:*:{
  if (!$isdir($+($scriptdir,temp))) mkdir " $+ $+($scriptdir,temp) $+ "
  var %dir = $did($dname,27)
  if (($devent == sclick) && ($did == 34)) || (($devent == dclick) && ($did == 25)) {
    if (%theme.halt) halt
    mtspreview $iif($did($dname,10).sel != 1,scheme $+ $calc($ifmatch -1),MTS) $findfile(%dir,$did($dname,2),1)
    themepreview $dname $result
    set -u1 %theme.halt 1
    halt
  }
  if ($devent == menu) {
    if ($did == 27) { 
      var %dir = $$sdir(Select a new themes directory:)
      %themedir = %dir
      did -o $dname 27 %dir
      did -r $dname 2
      var %addthemes = $findfile(%dir,*.mts,0,did -a $dname 2 $nopath($1-))
      did -c $dname 2 1
      var %a = $findfile(%dir,$did($dname,2).seltext,1)
      if ($isfile(%a)) {
        addschemes %a
        themepreview $dname
      }
      halt
    }
    if ($did == 29) dialog -c $dname
    if ($did == 31) url http://www.mircscripts.org
    if ($did == 33) {
      echo $colour(info) -a *** MTS Theme engine by Eric^^
      echo $colour(info) -a *** ericn@accesswave.ca / http://accesswave.ca/~ericn/
    }
  }
  if ($devent == init) { 
    if (!$hget(theme)) hmake theme 20
    var %dir = $iif(($isdir(%themedir)) && (%themedir),%themedir,$scriptdirthemes\)
    did -o $dname 27 %dir
    var %addthemes = $findfile(%dir,*.mts,0,did -a $dname 2 $nopath($1-))
    did -c $dname 2 1
    var %a = $findfile(%dir,$did($dname,2).seltext,1)
    if ($isfile(%a)) {
      addschemes %a
      goto init
    }
  }
  var %a = $findfile(%dir,$did($dname,2).seltext,1)
  if ($devent == sclick) && (%a) { 
    if ($did == 2) || ($did == 10) {
      if ($did != 10) addschemes %a
      :init
      var %scheme = $iif($did($dname,10).sel == 1,MTS,scheme $+ $calc($did($dname,10).sel -1))
      var %bmp = $+($scriptdir,temp\,$left($nopath(%a),-4),%scheme,.bmp)
      did -ra $dname 18 $gettok($read(%a,w,NAME *),2-,32)
      did -ra $dname 19 $gettok($read(%a,w,AUTHOR *),2-,32)
      did -ra $dname 20 $gettok($read(%a,w,EMAIL *),2-,32)
      did -ra $dname 21 $gettok($read(%a,w,WEBSITE *),2-,32)
      did -ra $dname 23 $gettok($read(%a,w,VERSION *),2-,32)
      did -ra $dname 17 $gettok($read(%a,w,DESCRIPTION *),2-,32)
      :skip
      themepreview $dname %bmp
      resel
    }
    var %s = $iif($did($dname,10).sel == 1,MTS,scheme $+ $calc($did($dname,10).sel -1))
    if ($did == 6) { mtsload %s %a | resel | halt }
    if ($did == 8) { var %th = mtsload %s %a | if (%theme == %th) goto noload | %th | :noload | dialog -x $dname | halt }
  }
}
alias themereload mtsreload
menu menubar,status {
  Themes
  .Open dialog	[/themes]:themes
  .-
  .Load a theme	[/theme]:theme
  .Reload theme	[/themereload]:mtsreload
}