Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   GuiPopUpMenuCtrl user input scanning (https://forums.graalonline.com/forums/showthread.php?t=134270088)

DustyPorViva 08-26-2015 08:24 PM

GuiPopUpMenuCtrl user input scanning
 
Just thought I'd share this since it's the only decent place to share GS2 code and I think it's something popup menus should support by default. Basically it lets you scan through popup menus via key input. It supports two methods:

> Jumping through first-key input(scanning through all rows that start with the same letter)
> Jumping to the first row that matches a string of characters

http://i.imgur.com/DLrmJ9g.gif

All you had to do is add a catch event to the GuiPopUpMenuCtrl:
PHP Code:

thiso.catchevent(this.name"onKeyDown""onScanRows"); 

Here is the actual code you need to include in the script:

PHP Code:

function onScanRows(temp.obj,temp.code,temp.key) {
  if (
temp.code == 8) {
    if (
temp.obj.findObject.length() > 0) {
      
temp.obj.findObject temp.obj.findObject.substring(0,temp.obj.findObject.length()-1);
      
cancelEvents("ForgetObjectFind");
      
scheduleEvent(.5,"ForgetObjectFind",temp.obj);
    }
  } else if (
temp.key != "") {
    
temp.scanThrough = (temp.key == temp.obj.lastKey || 
                        
temp.obj.lastKey == "") &&
                        
temp.obj.findObject.length() <= 1;

    if (
temp.scanThrough) {
      
temp.obj.findObject temp.key;
      
temp.list = new[0];
      for (
temp.temp.obj.rows) {
        if (
temp.i.text.starts(temp.key)) temp.list.add(temp.i.id);
      }
      
temp.ind temp.list.index(temp.obj.getselectedid());
      for (
temp.i=0;temp.i<temp.list.size();temp.i++) {
        if (
temp.temp.ind) break;
      }
      
temp.temp.i%temp.list.size();
      if (
temp.list.size() > 0temp.obj.setselectedrow(temp.list[temp.i]);
    } else {
      
temp.obj.findObject temp.obj.findObject temp.key;
      for (
temp.temp.obj.rows) {
        if (
temp.i.text.starts(temp.obj.findObject)) {
          
temp.obj.setselectedrow(temp.i.id);
          break;
        }
      }
    }
    
temp.obj.lastKey temp.key;
    
cancelEvents("ForgetObjectFind");
    
scheduleEvent(.5,"ForgetObjectFind",temp.obj);
  }
}

function 
onForgetObjectFind(temp.obj) {
  
temp.obj.lastKey "";
  
temp.obj.findObject "";


I had no intention on making something I planned to share, so excuse any mess/sloppy code.


All times are GMT +2. The time now is 05:09 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.