SSH Productions: Module documentation for FileDialog.zip

Module: FileDialog 1.0, by SSH

Provide a dialog box to select a file from the current directory, with preview

Download FileDialog as a zip file

Author

Andrew MacCormack (SSH)

Please use the PM function on the AGS forums to contact

me about problems with this module

Abstract

Provides a file select dialog box with image preview

Dependencies

AGS 2.71 or later

FileDialog GUE imported to game

Functions

function FileDialog.Open(GUIControl *what, String default, String pattern);

This opens the dialog and stores the button pressed (1st argument),

and sets the default value to the 2nd argument. The pattern passed is

used to populate the list. Either specify pattern as "*.ext" or you can

have 2 different filetypes by separating them with a semicolon (';')

which also enables the image preview.

function FileDialog.Close(bool ok);

This is called by the Cancel and OK buttons with the argument indicating

whether it is OK or Cancel.

function FileDialog.Select(int s);

Called by the GUE to select a list item

GUIControl *FileDialog.Claim();

Should be called from repeatedly_execute after the processing on the

filename returned has been done.

Configuration

FileDialog deals with the possibility of multiple calls for different

purposes to it in one game by storing the GUIControl passed to it:

this would typically be the button pressed to open the dialog.

At the close of the dialog, FileDialog.file is set, and so this can be

checked for in repeatedly_execute. Also, FileDialog.what can be checked

to see which button was pressed to start the dialog, and the appropriate

action taken. See the examples below:

Example

function FileDialog_Close_Handler() {
  if (FileDialog.file!=null) {
    String file=FileDialog.file;
    GUIControl *what=FileDialog.Claim();
		 if (file=="") return;
		 if (what == goToolLoadImage) {
		   Paint.StoreUndo();
			 DynamicSprite *tmp=DynamicSprite.CreateFromFile(file);
			 if (Paint.Import(tmp.Graphic)) {
			   Paint.filename=file;
			   Paint.dirty=false;
			 } else {
			   tmp.Delete();
			 }
		 } else if (what == goAnimLoadBGImage) {
		   Bones.SetBackground(file);
		 } else if (what == goAnimLoadXML) {
		   Load_XML(file);
		 }
  }
}   
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  FileDialog_Close_Handler();
}

function goToolSaveImage_Click(GUIControl *control, MouseButton button) {
  FileDialog.Open(control, "", "*.pcx;*.bmp");
}

function goAnimLoadXML_Click(GUIControl *control, MouseButton button) {
  FileDialog.Open(control, "", "*.xml");
}

Caveats

Developed for SSH's Walkcycle generator and so hasn't been fully tested

as a standalone module

Revision History

16 May 06: v1.0 First release of FileDialog module

Licence

FileDialog AGS script module

Copyright (C) 2006 Andrew MacCormack

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to

deal in the Software without restriction, including without limitation the

rights to use, copy, modify, merge, publish, distribute, sublicense, and/or

sell copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in

all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

DEALINGS IN THE SOFTWARE.

In addition to the licences mentioned in the modules themselves, you may choose to use the following creative commons licence if you prefer for all AGS modules and open source code resources on my site.

Creative Commons License
This work is licenced under a Creative Commons Licence.