how to make an object visible again in game maker - game-maker

Fist of all, I'm really sorry for my bad English and I pretty new to game maker .
I have 2 object in the game : obj_apple and obj_door( I unchecked visible box)
my question is
how can I make an obj_door visible in the room when all the obj_apple are destroyed?

Object obj_door, Step event, place code (Add event -> Step -> Step -> tab Control -> section Code, first icon (Execute code)):
if !instance_exists(obj_apple) visible = true;

Another option, so you aren't making a check in every step event, is to put the check for the number of obj_apple in the destroy event of obj_apple.
For example, in the destroy event of obj_apple you would have:
if (instance_number(object_index) == 0) {
with (obj_door) {
visible = true;
}
}

Related

Showing progress window while creating other window/widgets

I have a function that looks like the following
void MainWindow::CreateEnvironment()
{
MdiWindow* sub = createSubWindow();
MyQTWidget* widget = CreateWidget();
..
..
}
I want that during this function a progress bar will be shown at the beggining and will close at the end of this function.
However adding
void MainWindow::CreateEnvironment()
{
**progressBarDialog->show();**
MdiWindow* sub = createSubWindow();
MyQTWidget* widget = CreateWidget();
..
..
**progressBarDialog->hide();**
}
Does not work, maybe because the function needs to exit first or something.
What is the best way to do this?
I assume that you use QProgressDialog?
You need to first setup the dialog with the correct number of steps you expect, how long you want to wait before it actually shows and more importantly: you need to call setValue() to update the progress bar.
Here is an example of how I would solve that (as far as I understand it)
void MainWindow::CreateEnvironment()
{
auto bar = new QProgressBarDialog(this);
bar->setLabelText(tr("Creating Environment..."));
bar->setCancelButton(nullptr); // No cancel button
bar->setRange(0, 10); // Let's say you have 10 steps
bar->setMinimumDuration(100); // If it takes more than 0.1 sec -> show the dialog
bar->setValue(0);
MdiWindow* sub = createSubWindow();
bar->setValue(1);
MyQTWidget* widget = CreateWidget();
..
..
bar->setValue(10);
MyLastWidget* last = CreateLastWidget();
bar->deleteLater(); // Not needed anymore, let's get rid of it
}
And don't worry too much if the dialog never shows. Unless you're doing really heavy computation (such as allocating / initialising huge portion of memory), creating widgets is very fast and would finish before the 100ms times out.
EDIT: Another thing to be aware of: QProgressDialog is meant to work after the main event loop started. (That is after the call to app.exec() in your main())
If you plan to show call this function in the constructor of your MainWindow, the dialog might even never show up because the window itself is not fully created and operational.
If you intended to call this function later, when the main window is already displayed on screen and the user hit a New Document button of some sort: you can ignore this part of the answer.

How to handle buttonclicked event of DDDW?

Situation:
I have a button in my DDDW and i want to capture buttonclicked event.
Problem:
when i click on the button in DDDW the buttonclicked event of DW Control is not fired and ItemChanged event is fired for DW control.
Question:
How do i capture buttonclicked event for the button in DDDW? Or is there any other way i can delete a row from DDDW when delete button is clicked for a particular row?
PowerBuilder 12.5
According to the PB help, a DataWindowChild has no events :|
But, that doesn't mean we still can't hook into it via the DW control's itemchanged event. Note: this is a hack, and underwent some very-limited testing. But, it demonstrates a point, I guess.
Here's what I did:
Created a DataWindow with the code and name columns, and a computed field (for the red X) named delete_button
Created another DataWindow and painted that DW as a DDDW on there, named profession
In my window control's open event, I got the DDDW from the DW and stuck it in an instance variable:
dw_1.GetChild("profession", REF idwc_profession)
Then, coded the itemchanged event for the DW control:
// dw_1::itemchanged
//
// - DDDW is named "profession"
IF dwo.Name = "profession" THEN
IF IsValid(idwc_profession) THEN
string ls_clickedobject
// Get the DataWindowCHILD object where the pointer was clicked:
ls_clickedobject = idwc_profession.GetObjectAtPointer()
IF IsNull(ls_clickedObject) OR (ls_clickedobject = "") THEN RETURN
// Return from GetChild is <column name>~t<row number>; let's get
// the position of the tab character so we can parse it
long ll_tabPos
ll_tabPos = Pos(ls_clickedObject, "~t")
IF ll_tabPos > 0 THEN
string ls_clickedDddwColumn
ls_clickedDddwColumn = Trim(Left(ls_clickedObject, ll_tabPos - 1))
// Check to see if we've clicked on the computed field with the delete button
IF Lower(ls_clickedDddwColumn) = "delete_button" THEN
long ll_clickedDddwRow
// grab the row we want to delete
ll_clickedDddwRow = Long(Trim(Right(ls_clickedObject, Len(ls_clickedObject) - ll_tabPos)))
IF ll_clickedDddwRow > 0 THEN
// delete the row from the DDDW
idwc_profession.DeleteRow(ll_clickedDddwRow)
SetNull(data) // reset our data
END IF
END IF
END IF
END IF
END IF
RETURN
Also note that you may have to play around with the return value from itemchanged to get it to do what you want. And, if you want to automatically dropdown the DDDW again after the deletion happens, you'd might be able to use the Send() method to do so (I don't know the right "number" for that, though).

JavaFX 8: Intercepting appication "exit"

In order to verify that all changes made by the user have been saved I want to intercept the exiting/quitting of a JavaFX application.
Is there a common way-to-go to achieve this like overriding an event or is there more to it?
As they have already said, this is done by intercepting WindowEvent.WINDOW_CLOSE_REQUEST. You can then stop the suspension by calling event.consume().
This is an example of how to capture the event and display a confirmation dialog. Depending on the user's choice, you can take serialization actions if you wish.
primaryStage.setOnCloseRequest(event -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.initOwner(primaryStage);
alert.initModality(Modality.APPLICATION_MODAL);
alert.setHeaderText("Exit");
alert.setContentText("Do you want to exit?");
alert.getDialogPane().getButtonTypes().setAll(ButtonType.OK, ButtonType.NO);
Optional<ButtonType> optional = alert.showAndWait();
if(optional.isPresent() && optional.get() == ButtonType.OK) {
// save data
return;
}
event.consume();
});
In order for the implementation to be complete, you need to implement a logic for clear exit from the application from control. For example, when choosing from the File menu -> Close. When capturing the event, you must run WindowEvent.WINDOW_CLOSE_REQUEST to trick the exit logic.
closeMenuItem.setOnAction(event -> {
Window window = menuBar.getScene().getWindow();
window.fireEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSE_REQUEST));
});
In the class Application there is the stop method which you can override possibly.

How to Stop Single Tap From firing before Double Tap

I am trying to set a simple double tap recognition before moving to more complicated interactions. I have the single and double tap being recognised. However, my problem is that the double tap doesn't fire without the single tap.
I have seen the code which covers introducing a requirement to fail, but the sample code I do not understand how to modify to make work with my standard approach.
Here is my code - at the moment I am just trying to get the log to fire and it is. But on double tap I get the single tap message which I don't want. I have tried changing the TapGestureRecognizer event settings to no avail.
- (IBAction)didTapPhoto1:(UITapGestureRecognizer *)sender; {
NSLog(#"Did Tap Photo1 !");
}
- (IBAction)didDoubleTapPhoto1:(UITapGestureRecognizer *)sender; {
NSLog(#"DoubleTap");
}
Thank you
Use UIGestureRecognizer requireGestureRecognizerToFail: method.
[singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTapGestureRecognizer].
There is a side effect of this method, if you only tap one time on the screen, it will react slower than that without calling the method.
Edit: It seems that you create the gesture recognizer in Storyboard or xib. You can also do it with code.
UITapGestureRecognizer *singleGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapPhoto1:)] ;
singleGR.numberOfTapsRequired = 1 ;
UITapGestureRecognizer *doubleGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didDoubleTapPhoto1:)] ;
doubleGR.numberOfTapsRequired = 2 ;
// you can change self.view to any view in the hierarchy.
[self.view addGestureRecognizer:singleGR] ;
[self.view addGestureRecognizer:doubleGR] ;
[singleGR requireGestureRecognizerToFail:doubleGR] ;

Drag & Drop from 2 Sources to 1 Target in Flex, is it possible?

My question is simple. Let's say I have 2 List Controls. 1 of Users and 1 of Tickets. (The 2 Sources)
And I have a DataGrid (the target). Is possible to select 1 user and 1 ticket in the 2 list mentioned before and drag & drop them at the same time to the DataGrid?
I know it's not as simple as they are going to get automatically mixed.. If it is possible... I would have to use the DragEnter Event of the Datagrid or something to mix them and create my dataProvider. But I don't know how you can drag & drop 2 items at the same time from different sources. It is possible with one source.. But no idea of how to do it with 2 sources.
Any Help would be really appreciated.
Thanks in advance
Yes, I think that would still be possible.
Your option would be:
(click) select the item on the Users and click (select) the item on the Tickets.
From whichever list you started the drag, you would still be able to populate the datagrid with the items from dragEvent and the selected item on the list.
//
boolUsers:Boolean;
On your datagrid:
private function dataGrid_dragDrop(evt:DragEvent) :void
{
// This will get the items from the list where you initiated the drag.
var objDrag:Object;
objDrag = evt.dragSource.dataForFormat("items");
// Depending on where the drag was initiated, get the items from the list.
var objList:Object;
if(boolUsers)
{
objList = listTickets.selectedItem;
}
else
{
objList = listUsers.selectedItem;
}
boolUsers = false;
}
And you would need to define a dragstart event for both your list
private function listUsers_dragStart(evt:DragEvent) :void
{
boolUsers = true;
}

Resources