VrS (Variant realities Script) — File Browser

VrSVariantrealitiesScriptv2.0 / VrSVariantrealitiesScriptv2.0 / VrS / System / Modules / vConfig / vConfig.MRC

vConfig.MRC — 13.44 KB — Download this file

;#[vHD@3.0 C!vConfig@3.0.0;2001.12.05;Ccowboy<ccowboy@variantrealities.com>]
;#[SD C!vGui@2.1.0]
;#[Incl ]
;#[VrS' Configuration box.]
;#[ ]
;#[ ]

; This is the main vConfig alias, which opens vConfig (or doesnt, if it's already open).
; Syntax: /vConfig [Section to start on, ie /vConfig vMI]
;	$vConfig = returns $true if vConfig is open, $false if it's not.
alias vConfig {
  if ($isid) { return $iif($window(@vGui.vConfig),$true,$false) }
  if (!$vLib.WinPosition(@vGui.vConfig)) { vLib.WinPosition @vGui.vConfig 25 25 }

  vConfig.CheckPages

  if ($1) && ($1 != $vConfig.CurPageName) {
    if ($vConfig.IsPage($1)) { set -u0 %vConfig.SelectedPage $findtok($vConfig.PageList,$1,1,44) }
    else { set -u0 %vConfig.SelectedPage 1 }
  }
  else { set %vConfig.SelectedPage $iif(%vConfig.SelectedPage && %vGui.vConfig.OptList.Selected < %vGui.vConfig.OptList.NumLines,$ifmatch,1) }

  if ($window(@vGui.vConfig)) {
    unset %vGui.vConfig.OptList.*
    vGui.vConfig.Process WINDOW Init
    vGui.Obj.!Listbox.Draw vConfig Normal 15 30 140 312 OptList
    vGui.vConfig.Process OptList Selected
    vGui.Update vConfig
  }
  if ($vConfig.PageList(0) > 0) { if (!$window(@vGui.vConfig)) { vGui.Window -tdo vConfig $vLib.WinPosition(@vGui.vConfig) 525 394 -x VrS2 Config | vConfig.Que -i } }
  else {
    EEcho /vConfig Page list is empty. 
  }
}

; Use this to add or remove a config page.
; Syntax: /vConfig.Page <-ra> <page alias name>
;	-a = add a page.
;	-l = launch vConfig when the page is added.
;	-r = to remove a page.
alias vConfig.Page {
  if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
  if (!$1) {
    :syntax
    SEcho /vConfig.Page <-ral> <page alias name>
    return
  }
  if (a isin %Options) {
    if ($isalias(vConfig. [ $+ [ $1 ] $+ ] .Page)) && (!$vConfig.IsPage($1)) { 
      vReg U vConfig PageList $addtok($vConfig.PageList,$1,44)
      if (l isin %Options) || ($vConfig) { vConfig $1 }
    }
  }
  elseif (r isin %Options) {
    vReg U vConfig PageList $remtok($vConfig.PageList,$1,1,44)
    if ($vConfig) {
      dec %vGui.vConfig.OptList.Numlines | unset %vGui.vConfig.OptList.Selected
      vConfig | vConfig.LargeTitle | vConfig.InitDraw | vGui.Update vConfig
    }
  }
  else { goto syntax }
}

; Used internally by vConfig to check if its page list isn't broken before it opens it.
alias -l vConfig.CheckPages {
  var %Counter = 1
  while (%Counter <= $vConfig.PageList(0)) {
    var %Alias = vConfig. [ $+ [ [ $vConfig.PageList(%Counter) ] ] $+ ] .Page
    if ($isalias(%Alias) == $true) { inc %Counter }
    else { vConfig.Page -r $vConfig.PageList(%Counter) | inc %Counter }
  }
}

; Used internally by vConfig to send the Init event to all vConfig pages, or just the one specified.
; Actually it never init's them all, but it used to so the code is still there :P
alias -l vConfig.Init {
  if ($1) && ($vConfig.IsPage($1)) { vConfig. [ $+ [ $1 ] $+ ] .Page Init | return }
  var %Counter = 1
  while (%Counter <= $vConfig.PageList(0)) {
    vConfig. [ $+ [ [ $vConfig.PageList(%Counter) ] ] $+ ] .Page Init
    inc %Counter
  }
}

alias vGui.vConfig.CheckObjects {
  ; Checks for the listbox, the only vGui object actually in the vConfig window that belongs to it ;)
  if ($inrect($1,$2,15,30,145,312) == $true) { return !listbox OptList 15 30 140 312 }
  elseif ($inrect($1,$2,290,358,69,26) == $true) { return button vConfig.OK 290 358 69 26 }
  elseif ($inrect($1,$2,366,358,69,26) == $true) { return button vConfig.Cancel 366 358 69 26 }
  elseif ($inrect($1,$2,442,358,69,26) == $true) && (%vGui.vConfig.Apply.Enabled) { return button vConfig.Apply 442 358 69 26 }
  elseif ($1-2 == WINDOW Icon) { return 56 42 $vrsdir(system\core\media\vGuiIcon.png) }

  ; If vGui has checked to see if your mouse is in vConfigs listbox and found that it's not, we can then check to see if the mouse is in an object
  ; belonging to our current vConfig page. This is done by passing on the X,Y parameters that were sent to this alias, to the current page's
  ; alias, which then returns here the same kind of $inrect stuff vGui needs. Quite clever really :P
  elseif ($vConfig.CurPageName) { return $vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .page(Checkobjects,$1,$2) }
}

alias vGui.vConfig.Process {
  ;if ($1 != vGuiTimer) { vecho 12vConfig: $1- }
  if ($1 == WINDOW) {
    if ($2 == Init) {
      var %Counter = 1
      set %vGui.vConfig.OptList.Numlines $vConfig.PageList(0)
      while (%Counter <= $vConfig.PageList(0)) {
        if ($vConfig. [ $+ [ $vConfig.PageList( [ %Counter ] ) ] $+ ] .Page( [ Getinfo ] , [ Icon ] )) {
          var %Icon = $ifmatch
          var %Line = %Icon $+ ; $+ $vConfig. [ $+ [ $vConfig.PageList(%Counter) ] $+ ] .page(GetInfo,ListName)
          hadd vGui vConfig.OptList.Line [ $+ [ %Counter ] ] %Line
        }
        else { hadd vGui vConfig.OptList.Line [ $+ [ %Counter ] ] $vConfig. [ $+ [ $vConfig.PageList(%Counter) ] $+ ] .page(GetInfo,ListName) }
        inc %Counter
      }
      set %vGui.vConfig.OptList.Selected %vConfig.SelectedPage
    }
    elseif ($2 == DrawObjects) {
      ;temp until drawpic -s is fixed.
      drawrect -fnr @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Face) ] ) 1 22 22 481 350
      ; Draws the listbox to display the list of pages, draws the page title then sends the init and draw events to the current page's alias.
      vGui.Obj.!Listbox.Draw vConfig Normal 15 30 140 312 OptList
      drawline -r @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Shadow) ] ) 1 14 349 510 349
      drawline -r @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Hilight) ] ) 1 14 350 510 350
      ; Draws the vConfig OK, Cancel and Apply buttons.
      vGui.Obj.Button.Draw vConfig Normal 290 358 69 26 vConfig.OK -8 OK
      vGui.Obj.Button.Draw vConfig Normal 366 358 69 26 vConfig.Cancel -8 Cancel
      vGui.Obj.Button.Draw vConfig Disabled 442 358 69 26 vConfig.Apply -8 Apply

      if (!%vGui.vConfig.Apply.Enabled) { vConfig.Status -c Select a page from the list above. }
      else { vConfig.Status -c Click OK or Apply to save changes. }

      vConfig.LargeTitle
      vConfig.InitDraw
    }
    elseif ($2 == Close) { 
      while ($window(@vConfig.Cache*,0) > 0) { !close -@ $window(@vConfig.Cache*,1) }
      vLib.WinPosition @vGui.vConfig $3 $4
      if ($hget(vConfig.Que)) { hfree vConfig.Que }
    }
  }

  ; This is where the re-drawing of the title text goes on, then the DrawObjects command is sent to the current page, to draw its objects ;)
  ; Also, if it's not already happened, the init parameter is sent to the page. vConfig pages can only init once while vConfig is open.
  elseif ($1-2 == OptList Selected) && (%vGui.vConfig.CurrentPage != %vGui.vConfig.OptList.Selected) {
    set %vGui.vConfig.CurrentPage %vGui.vConfig.OptList.Selected
    ; Clear the page area, status area, then draw the page.
    vConfig.LargeTitle
    if (!%vGui.vConfig.Apply.Enabled) { vConfig.Status -c Select a page from the list above. }
    else { vConfig.Status -c Click OK or Apply to save changes. }

    vConfig.InitDraw
    ; Show the changes.
    vGui.Update vConfig
    set -u0 %DrawnObjects $true
  }
  ; Check to see if it's a main vConfig button we're pressing, act accordingly.
  elseif ($2 == MouseClicked) {
    if ($1 == vConfig.OK) { vConfig.Que -px }
    elseif ($1 == vConfig.Cancel) { vGui.Close vConfig }
    elseif ($1 == vConfig.Apply) { vConfig.Que -p }
  }
  elseif ($2 == MouseOver) && ($istok(vConfig.OK vConfig.Cancel vConfig.Apply,$1,32)) {
    if ($1 == vConfig.OK) { vConfig.Status -c Click OK to save any changes and close. }
    elseif ($1 == vConfig.Cancel) { vConfig.Status -c Click Cancel to close without saving changes. }
    elseif ($1 == vConfig.Apply) { vConfig.Status -c Click Apply to save any changes without closing. }
  }

  ; If the current thing being processed is nothing to do with the vConfig window itself, or it's Listbox/buttons, the information can be passed
  ; on to the current pages vConfig alias to process its OWN objects. Makes sense? :P
  if (WINDOW* !iswm $1-) && ($1 != vGuiTimer) && ($vConfig.CurPageName) { vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .page Process $1- }
}

; Used internally by vConfig to check what to send to vConfig.DrawLargeTitle, as the title for the currently selected item
; from the listbox.
alias -l vConfig.LargeTitle {
  if ($vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .page(GetInfo,LargeTitle) != $null) { vConfig.DrawLargeTitle $vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .page(GetInfo,LargeTitle) }
  elseif (!$vConfig.PageList(%vGui.vConfig.OptList.Selected)) {
    ;set %vGui.vConfig.OptList.Selected 1
    ;vGui.vConfig.Process OptList Selected
  }
}

; Used internally by vConfig to clear and draw text to the bottom right hand corner of vConfig (status/info area).
; Can be used externally by vConfig pages to display whatever it wants in this restricted area. Can be quite usefull though I guess!
; You could /vConfig.Status -c and draw a button there to visit a web site maybe.. or anything *shrug*
; -c = Clear area before writing text.
; -h = Highlighted text.
; -d = Disabled text.
alias vConfig.Status {
  if ($vConfig) {
    if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
    if (c isin %Options) { vGui.DrawBackground vConfig 14 351 276 38 }
    if ($1-) { vGui.Drawtext $+(-c,$remove(%Options,c)) vConfig 11 14 362 276 20 $1- }
    if (u isin %Options) { vGui.Update vConfig }
  }
}

; Used internally by vConfig to draw the box and text for the title of the current page.
; Syntax:	/vConfig.DrawLargeTitle <Text>
alias -l vConfig.DrawLargeTitle {
  if ($vConfig) {
    drawrect -fnr @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Face) ] ) 1 166 30 345 30
    drawrect -fnr @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Shadow) ] ) 1 166 30 345 30
    drawrect -nr @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Hilight) ] ) 1 166 30 345 30
    if ($vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .Page( [ Getinfo ] , [ Icon ] )) {
      vGui.Drawicon vConfig 175 37 $gettok($vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .Page( [ Getinfo ] , [ Icon ] ),1-2,32) $vrsdir($gettok($vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .Page( [ Getinfo ] , [ Icon ] ),3-,32))
      drawtext -crn @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Text) ] ) "Tahoma Bold" 18 194 33 315 24 $1-
    }
    else { drawtext -crn @vGui.vConfig $rgb( [ $vGui.Setting(vGui,Text) ] ) "Tahoma Bold" 18 177 33 333 24 $1- }
  }
}

; Used internally by vConfig to send the init event to the current page's alias (if this hasn't happened already),
; then to send the draw event to current page's the alias.
alias vConfig.InitDraw {
  if ($vConfig.CurPageName) {
    vGui.DrawBackground vConfig 166 60 346 286
    if (!%vGui.vConfig.Init. [ $+ [ $vConfig.CurPageName ] ]) {
      vConfig.Init $vConfig.CurPageName
      set %vGui.vConfig.Init. [ $+ [ $vConfig.CurPageName ] ] $true 
    }
    vConfig. [ $+ [ $vConfig.CurPageName ] $+ ] .Page DrawObjects
  }
}

; Returns the config page currently being viewed. If a config page isn't being viewed this returns $null.
alias vConfig.CurPageName {
  if ($gettok($vConfig.PageList,%vGui.vConfig.OptList.Selected,44)) { return $ifmatch }
  return $null
}

alias vConfig.IsPage {
  if ($isalias(vConfig. [ $+ [ $1 ] $+ ] .page)) && ($istok($vConfig.PageList,$1,44)) { return $true }
  else { return $false }
}

alias vConfig.PageList {
  if ($1 != $null) {
    if ($1 == 0) { return $numtok($vReg(U,vConfig,PageList),44) }
    else { return $gettok($vReg(U,vConfig,PageList),$1,44) }
  }
  return $vReg(U,vConfig,PageList)
}

; Used internally by vConfig to loop through the que of options which need setting.
; Used by vConfig pages to add a command to the loop.
; Syntax: /vConfig.Que [-arpx] [<id, named, unique, so you can remove it from the que later if you want!> <what to add to the que>]
;	 -a = add to the que.
;	 -r = remove from the que.
;	 -p = perform the que.
;	 -x = close vConfig when que is done. (only used with -p).
alias vConfig.Que {
  if (!$vConfig) { return }
  if ($left($1,1) == -) { var %Options = $1 | tokenize 32 $2- }
  if (p isin %Options) {
    if (x !isin %Options) { vConfig.Status Saving changes... }
    var %Total = $hget(vConfig.Que,0).item, %Counter = 1
    while (%Counter <= %Total) {
      $hget(vConfig.Que,%Counter).data
      inc %Counter
    }
    if (x isin %Options) { vGui.Close vConfig }
    else {
      vConfig.Status -c Changes saved.
      vGui.Obj.Button.Draw vConfig Disabled 442 358 69 26 vConfig.Apply -8 Apply
      unset %vGui.vConfig.Apply.Enabled
      vGui.Update vConfig
    }
    if ($hget(vConfig.Que)) { hfree vConfig.Que }
  }
  elseif (i isin %Options) {
    if (!$hget(vConfig.Que)) { hmake vConfig.Que 20 }
    else { hfree vConfig.Que | hmake vConfig.Que 20 }
  }
  elseif (a isin %Options) { 
    if (!$hget(vConfig.Que)) { hmake vConfig.Que 20 }
    hadd vConfig.Que $1 $$2-
    if ($hget(vConfig.Que,0).item => 1) {
      vGui.Obj.Button.Draw vConfig Normal 442 358 69 26 vConfig.Apply -8 Apply
      set %vGui.vConfig.Apply.Enabled $true
      vConfig.Status -c Click OK or Apply to save changes.
      vGui.Update vConfig
    }
  }
  elseif (r isin %Options) {
    if ($hget(vConfig.Que,$1)) { hdel -s vConfig.Que $1 }
    if ($hget(vConfig.Que,0).item == 0) {
      vGui.Obj.Button.Draw vConfig Disabled 442 358 69 26 vConfig.Apply -8 Apply
      unset %vGui.vConfig.Apply.Enabled
      vConfig.Status -c Select a page from the list above.
      vGui.Update vConfig
    }
  }
}