DMS3.0 或更高版本中的任何在后台运行并允许用户交互的函数如 FloatingModelessDialog

问题描述

在DMS3.42或更高版本中,我想知道我们是否有允许用户选择图像进行操作的功能。基本上,该函数需要在后台运行并允许用户交互,例如以前版本中的“FloatingModelessDialog”(似乎DMS3.0不支持“FloatingModelessDialog”)。

谢谢!

解决方法

FloatingModelessDialog 在 GMS 3 中仍受支持:

// $BACKGROUND$
number sem = NewSemaphore()
FloatingModelessDialog("Message","YES",sem )
Result("\n Do continue stuff...")

// hold and wait for the dialog
number OK
Try { GrabSemaphore(sem); OK = 1; }
catch { OK = 0; break; }

Result("\n Button pressed:" + OK )

然而,这只是一种变通的解决方案,需要在后台线程上执行脚本(或 GMS 似乎被冻结。) 更完整的方法是创建一个对话框并让其按钮驱动操作,如下例所示:

class MyActionDialog : UIFrame{
    void Launch( object self ){
        // Build dialog
        TagGroup DLGtgs,DLGItems
        DLGtgs = DLGCreateDialog( "My Dialog",DLGItems )
        TagGroup Button1 = DLGCreatePushButton( "Act on front image","OnButtonAct" )
        TagGroup Button2 = DLGCreatePushButton( "Close","OnButtonClose" )
        DLGItems.DLGAddElement( Button1 )
        DLGItems.DLGAddElement( Button2 )
        DLGtgs.DLGTableLayout( 2,1,0 )
        // Create and display the modeless Dialog
        self.init( DLGtgs )
        self.Display( "My Dialog" )
    }

    void OnButtonAct( object self ){
        image front
        if ( !GetFrontImage(front) ) 
            Result( "\n Please select an image first." )
        else
            Result("\n Acting on image [" + front.ImageGetLabel() + "]....")
    }

    void OnButtonClose( object self ){
        Result( "\n Closing dialog actions." )
        self.close()
    }
}

Alloc(MyActionDialog).Launch()