add waitScreen (wait for refresh with timeout), gotToMainMenuScreen (with the help of back and menu navigate to a given main menu), enterMenu (to navigate withhin submenus), and step (send a key repeated)

This commit is contained in:
Sandra Keßler 2017-08-04 16:38:25 +02:00
parent d8ca2771fb
commit d35283ad74

View file

@ -429,6 +429,57 @@ public class RuffyScripter {
pressKey(Key.BACK,2000); pressKey(Key.BACK,2000);
log.debug("Releasing back key"); log.debug("Releasing back key");
} }
private boolean waitScreen(long timeout)
{
synchronized (screenlock) {
try {
screenlock.wait(timeout);
} catch (Exception e) {
return false;
}
}
return true;
}
public boolean goToMainMenuScreen(MenuType screen, long timeout)
{
long start = System.currentTimeMillis();
while((currentMenu == null || currentMenu.getType()!=screen) && start+timeout>System.currentTimeMillis())
{
if(currentMenu!=null && currentMenu.getType()==MenuType.WARNING_OR_ERROR)
{
//FIXME bad thing to do :D
pressCheckKey();
}
else if(currentMenu!=null && !currentMenu.getType().isMaintype())
{
pressBackKey();
}
else
pressMenuKey();
waitScreen(250);
}
return currentMenu != null && currentMenu.getType()==screen;
}
public boolean enterMenu(MenuType startType, MenuType targetType, byte key, long timeout)
{
if(currentMenu==null || currentMenu.getType() != startType)
return false;
long start = System.currentTimeMillis();
pressKey(key,2000);
while((currentMenu == null || currentMenu.getType()!=targetType) && start+timeout>System.currentTimeMillis()) {
waitScreen(100);
}
return currentMenu!=null && currentMenu.getType()==targetType;
}
public void step(int steps, byte key, long timeout) {
for(int i = 0; i < Math.abs(steps);i++)
pressKey(key,timeout);
}
// TODO v2, rework these two methods: waitForMenuUpdate shoud only be used by commands // TODO v2, rework these two methods: waitForMenuUpdate shoud only be used by commands
// then anything longer than a few seconds is an error; // then anything longer than a few seconds is an error;
// only ensureConnected() uses the method with the timeout parameter; inline that code, // only ensureConnected() uses the method with the timeout parameter; inline that code,