Exemple #1
0
static int key_dialog_handler(UI_DIALOG *dlg, d_event *event, key_dialog *k)
{
	int keypress = 0;
	int rval = 0;
	
	if (event->type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
	else if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		ui_dprintf_at( dlg, 10, 100, "%s     ", k->text  );
		return 1;
	}

	if (keypress > 0)
	{
		
		GetKeyDescription( k->text, keypress );
		rval = 1;
	}
	
	if (GADGET_PRESSED(k->DoneButton))
	{
		ui_close_dialog(dlg);
		rval = 1;
	}
	
	return rval;
}
Exemple #2
0
int object_dialog_handler(UI_DIALOG *, d_event *event, object_dialog *o)
{
	dxxobject *obj=&Objects[Cur_object_index];
	int keypress = 0;
	int rval = 0;
	
	if (event->type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
	
	Assert(MattWindow != NULL);

	//------------------------------------------------------------
	// Call the ui code..
	//------------------------------------------------------------
	ui_button_any_drawn = 0;


	if (event->type == EVENT_WINDOW_CLOSE)
	{
		d_free(o);
		MattWindow = NULL;
		return 0;
	}
	else if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		ui_dprintf_at( MattWindow, 10, 132,"&X:" );
		ui_dprintf_at( MattWindow, 10, 162,"&Y:" );
		ui_dprintf_at( MattWindow, 10, 192,"&Z:" );
	}
	
	if ( GADGET_PRESSED(o->quitButton) || (keypress==KEY_ESC))
	{

		if (o->initialMode[0]->flag) obj->movement_type = MT_NONE;
		if (o->initialMode[1]->flag) obj->movement_type = MT_SPINNING;

		obj->mtype.spin_rate.x = fl2f(atof(o->xtext->text));
		obj->mtype.spin_rate.y = fl2f(atof(o->ytext->text));
		obj->mtype.spin_rate.z = fl2f(atof(o->ztext->text));

		object_close_window();
		return 1;
	}
	
	return rval;
}
Exemple #3
0
int trigger_dialog_handler(UI_DIALOG *dlg, d_event *event, trigger_dialog *t)
{
	int i;
	short Markedwall, trigger_num;
	int keypress = 0;
	int rval = 0;

	Assert(MainWindow != NULL);
	if (!Markedsegp) {
		close_trigger_window();
		return 0;
	}

	//------------------------------------------------------------
	// Call the ui code..
	//------------------------------------------------------------
	ui_button_any_drawn = 0;
	
	if (event->type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
	
	//------------------------------------------------------------
	// If we change walls, we need to reset the ui code for all
	// of the checkboxes that control the wall flags.  
	//------------------------------------------------------------
	Markedwall = Markedsegp->sides[Markedside].wall_num;
	if (Markedwall != -1)
		trigger_num = Walls[Markedwall].trigger;
	else trigger_num = -1;

	if (t->old_trigger_num != trigger_num)
	{
		if (trigger_num != -1)
		{
			trigger *trig = &Triggers[trigger_num];

  			ui_checkbox_check(t->triggerFlag[0], trig->flags & TRIGGER_CONTROL_DOORS);
 			ui_checkbox_check(t->triggerFlag[1], trig->flags & TRIGGER_SHIELD_DAMAGE);
 			ui_checkbox_check(t->triggerFlag[2], trig->flags & TRIGGER_ENERGY_DRAIN);
 			ui_checkbox_check(t->triggerFlag[3], trig->flags & TRIGGER_EXIT);
 			ui_checkbox_check(t->triggerFlag[4], trig->flags & TRIGGER_ONE_SHOT);
 			ui_checkbox_check(t->triggerFlag[5], trig->flags & TRIGGER_ILLUSION_ON);
 			ui_checkbox_check(t->triggerFlag[6], trig->flags & TRIGGER_ILLUSION_OFF);
 			ui_checkbox_check(t->triggerFlag[7], trig->flags & TRIGGER_ON);
 			ui_checkbox_check(t->triggerFlag[8], trig->flags & TRIGGER_MATCEN);
 			ui_checkbox_check(t->triggerFlag[9], trig->flags & TRIGGER_SECRET_EXIT);
		}
	}
	
	//------------------------------------------------------------
	// If any of the checkboxes that control the wallflags are set, then
	// update the cooresponding wall flag.
	//------------------------------------------------------------
	if (IS_CHILD(Markedsegp->children[Markedside]))
	{
		rval = 1;
		
		if (GADGET_PRESSED(t->triggerFlag[0])) 
			trigger_flag_Markedside(TRIGGER_CONTROL_DOORS, t->triggerFlag[0]->flag); 
		else if (GADGET_PRESSED(t->triggerFlag[1]))
			trigger_flag_Markedside(TRIGGER_SHIELD_DAMAGE, t->triggerFlag[1]->flag); 
		else if (GADGET_PRESSED(t->triggerFlag[2]))
			trigger_flag_Markedside(TRIGGER_ENERGY_DRAIN, t->triggerFlag[2]->flag); 
		else if (GADGET_PRESSED(t->triggerFlag[3]))
			trigger_flag_Markedside(TRIGGER_EXIT, t->triggerFlag[3]->flag); 
		else if (GADGET_PRESSED(t->triggerFlag[4]))
			trigger_flag_Markedside(TRIGGER_ONE_SHOT, t->triggerFlag[4]->flag); 
		else if (GADGET_PRESSED(t->triggerFlag[5]))
			trigger_flag_Markedside(TRIGGER_ILLUSION_ON, t->triggerFlag[5]->flag); 
		else if (GADGET_PRESSED(t->triggerFlag[6]))
			trigger_flag_Markedside(TRIGGER_ILLUSION_OFF, t->triggerFlag[6]->flag);
		else if (GADGET_PRESSED(t->triggerFlag[7]))
			trigger_flag_Markedside(TRIGGER_ON, t->triggerFlag[7]->flag);
		else if (GADGET_PRESSED(t->triggerFlag[8])) 
			trigger_flag_Markedside(TRIGGER_MATCEN, t->triggerFlag[8]->flag);
		else if (GADGET_PRESSED(t->triggerFlag[9])) 
			trigger_flag_Markedside(TRIGGER_SECRET_EXIT, t->triggerFlag[9]->flag);
		else
			rval = 0;

	} else
		for (i = 0; i < NUM_TRIGGER_FLAGS; i++ )
			ui_checkbox_check(t->triggerFlag[i], 0);

	//------------------------------------------------------------
	// Draw the wall in the little 64x64 box
	//------------------------------------------------------------
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		gr_set_current_canvas( t->wallViewBox->canvas );

		if ((Markedsegp->sides[Markedside].wall_num == -1) || (Walls[Markedsegp->sides[Markedside].wall_num].trigger) == -1)
			gr_clear_canvas( CBLACK );
		else {
			if (Markedsegp->sides[Markedside].tmap_num2 > 0)  {
				gr_ubitmap(0,0, texmerge_get_cached_bitmap( Markedsegp->sides[Markedside].tmap_num, Markedsegp->sides[Markedside].tmap_num2));
			} else {
				if (Markedsegp->sides[Markedside].tmap_num > 0)	{
					PIGGY_PAGE_IN(Textures[Markedsegp->sides[Markedside].tmap_num]);
					gr_ubitmap(0,0, &GameBitmaps[Textures[Markedsegp->sides[Markedside].tmap_num].index]);
				} else
					gr_clear_canvas( CGREY );
			}
		}
	}

	//------------------------------------------------------------
	// If anything changes in the ui system, redraw all the text that
	// identifies this robot.
	//------------------------------------------------------------
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		if ( Markedsegp->sides[Markedside].wall_num > -1 )	{
			ui_dprintf_at( MainWindow, 12, 6, "Trigger: %d    ", trigger_num);
		}	else {
			ui_dprintf_at( MainWindow, 12, 6, "Trigger: none ");
		}
	}
	
	if (ui_button_any_drawn || (t->old_trigger_num != trigger_num) )
		Update_flags |= UF_WORLD_CHANGED;
		
	if (event->type == EVENT_WINDOW_CLOSE)
	{
		d_free(t);
		MainWindow = NULL;
		return 0;
	}

	if ( GADGET_PRESSED(t->quitButton) || (keypress==KEY_ESC))
	{
		close_trigger_window();
		return 1;
	}		

	t->old_trigger_num = trigger_num;
	
	return rval;
}
Exemple #4
0
static int browser_handler(UI_DIALOG *dlg, d_event *event, file_browser *b)
{
    int rval = 0;

    if (event->type == EVENT_UI_DIALOG_DRAW)
    {
        ui_dprintf_at( dlg, 10, 5, "%s", b->message );

        ui_dprintf_at( dlg, 20, 32,"N&ame" );
        ui_dprintf_at( dlg, 20, 86,"&Files" );
        ui_dprintf_at( dlg, 210, 86,"&Dirs" );

        ui_dprintf_at( dlg, 20, 60, "%s", b->spaces );
        ui_dprintf_at( dlg, 20, 60, "%s", b->view_dir );

        return 1;
    }

    if (GADGET_PRESSED(b->button2))
    {
        PHYSFS_freeList(b->filename_list);
        b->filename_list = NULL;
        PHYSFS_freeList(b->directory_list);
        b->directory_list = NULL;
        ui_close_dialog(dlg);
        return 1;
    }

    if (GADGET_PRESSED(b->help_button))
    {
        ui_messagebox( -1, -1, 1, "Sorry, no help is available!", "Ok" );
        rval = 1;
    }

    if (event->type == EVENT_UI_LISTBOX_MOVED)
    {
        if ((ui_event_get_gadget(event) == (UI_GADGET *)b->listbox1) && (b->listbox1->current_item >= 0) && b->filename_list[b->listbox1->current_item])
            ui_inputbox_set_text(b->user_file, b->filename_list[b->listbox1->current_item]);

        if ((ui_event_get_gadget(event) == (UI_GADGET *)b->listbox2) && (b->listbox2->current_item >= 0) && b->directory_list[b->listbox2->current_item])
            ui_inputbox_set_text(b->user_file, b->directory_list[b->listbox2->current_item]);

        rval = 1;
    }

    if (GADGET_PRESSED(b->button1) || GADGET_PRESSED(b->user_file) || (event->type == EVENT_UI_LISTBOX_SELECTED))
    {
        char *p;

        if (ui_event_get_gadget(event) == (UI_GADGET *)b->listbox2)
            strcpy(b->user_file->text, b->directory_list[b->listbox2->current_item]);

        strncpy(b->filename, b->view_dir, PATH_MAX);

        p = b->user_file->text;
        while (!strncmp(p, "..", 2))	// shorten the path manually
        {
            char *sep = strrchr(b->filename, '/');
            if (sep)
                *sep = 0;
            else
                *b->filename = 0;	// look directly in search paths

            p += 2;
            if (*p == '/')
                p++;
        }

        if (*b->filename && *p)
            strncat(b->filename, "/", PATH_MAX - strlen(b->filename));
        strncat(b->filename, p, PATH_MAX - strlen(b->filename));

        if (!PHYSFS_isDirectory(b->filename))
        {
            PHYSFS_file	*TempFile;

            TempFile = PHYSFS_openRead(b->filename);
            if (TempFile)
            {
                // Looks like a valid filename that already exists!
                PHYSFS_close(TempFile);
                ui_close_dialog(dlg);
                return 1;
            }

            // File doesn't exist, but can we create it?
            TempFile = PHYSFS_openWrite(b->filename);
            if (TempFile)
            {
                // Looks like a valid filename!
                PHYSFS_close(TempFile);
                PHYSFS_delete(b->filename);
                ui_close_dialog(dlg);
                return 1;
            }
        }
        else
        {
            if (b->filename[strlen(b->filename) - 1] == '/')	// user typed a separator on the end
                b->filename[strlen(b->filename) - 1] = 0;

            strcpy(b->view_dir, b->filename);


            PHYSFS_freeList(b->filename_list);
            b->filename_list = file_getfilelist(&b->num_files, b->filespec, b->view_dir);
            if (!b->filename_list)
            {
                PHYSFS_freeList(b->directory_list);
                b->directory_list = NULL;
                ui_close_dialog(dlg);
                return 1;
            }

            ui_inputbox_set_text(b->user_file, b->filespec);

            PHYSFS_freeList(b->directory_list);
            b->directory_list = file_getdirlist(&b->num_dirs, b->view_dir);
            if (!b->directory_list)
            {
                PHYSFS_freeList(b->filename_list);
                b->filename_list = NULL;
                ui_close_dialog(dlg);
                return 1;
            }

            ui_listbox_change(dlg, b->listbox1, b->num_files, b->filename_list);
            ui_listbox_change(dlg, b->listbox2, b->num_dirs, b->directory_list);

            //i = TICKER;
            //while ( TICKER < i+2 );

        }

        rval = 1;
    }

    return rval;
}
Exemple #5
0
int wall_dialog_handler(UI_DIALOG *dlg, d_event *event, wall_dialog *wd)
{
	int i;
	sbyte type;
	fix DeltaTime;
	fix64 Temp;
	int keypress = 0;
	int rval = 0;
	
	if (event->type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
	
	Assert(MainWindow != NULL);

	//------------------------------------------------------------
	// Call the ui code..
	//------------------------------------------------------------
	ui_button_any_drawn = 0;

	//------------------------------------------------------------
	// If we change walls, we need to reset the ui code for all
	// of the checkboxes that control the wall flags.  
	//------------------------------------------------------------
	if (wd->old_wall_num != Cursegp->sides[Curside].wall_num)
	{
		if ( Cursegp->sides[Curside].wall_num != -1)
		{
			wall *w = &Walls[Cursegp->sides[Curside].wall_num];

			ui_checkbox_check(wd->doorFlag[0], w->flags & WALL_DOOR_LOCKED);
			ui_checkbox_check(wd->doorFlag[1], w->flags & WALL_DOOR_AUTO);
			ui_checkbox_check(wd->doorFlag[2], w->flags & WALL_ILLUSION_OFF);

			ui_radio_set_value(wd->keyFlag[0], w->keys & KEY_NONE);
			ui_radio_set_value(wd->keyFlag[1], w->keys & KEY_BLUE);
			ui_radio_set_value(wd->keyFlag[2], w->keys & KEY_RED);
			ui_radio_set_value(wd->keyFlag[3], w->keys & KEY_GOLD);
		}
	}
	
	//------------------------------------------------------------
	// If any of the checkboxes that control the wallflags are set, then
	// update the corresponding wall flag.
	//------------------------------------------------------------

	if (Walls[Cursegp->sides[Curside].wall_num].type == WALL_DOOR) {
		if (GADGET_PRESSED(wd->doorFlag[0]))
		{
			if ( wd->doorFlag[0]->flag == 1 )	
				Walls[Cursegp->sides[Curside].wall_num].flags |= WALL_DOOR_LOCKED;
			else
				Walls[Cursegp->sides[Curside].wall_num].flags &= ~WALL_DOOR_LOCKED;
			rval = 1;
		}
		else if (GADGET_PRESSED(wd->doorFlag[1]))
		{
			if ( wd->doorFlag[1]->flag == 1 )	
				Walls[Cursegp->sides[Curside].wall_num].flags |= WALL_DOOR_AUTO;
			else
				Walls[Cursegp->sides[Curside].wall_num].flags &= ~WALL_DOOR_AUTO;
			rval = 1;
		}

		//------------------------------------------------------------
		// If any of the radio buttons that control the mode are set, then
		// update the corresponding key.
		//------------------------------------------------------------
		for (	i=0; i < 4; i++ )	{
			if (GADGET_PRESSED(wd->keyFlag[i]))
			{
				Walls[Cursegp->sides[Curside].wall_num].keys = 1<<i;		// Set the ai_state to the cooresponding radio button
				rval = 1;
			}
		}
	} else {
		for (i = 0; i < 2; i++)
			ui_checkbox_check(wd->doorFlag[i], 0);
		for (	i=0; i < 4; i++ )
			ui_radio_set_value(wd->keyFlag[i], 0);
	}

	if (Walls[Cursegp->sides[Curside].wall_num].type == WALL_ILLUSION) {
		if (GADGET_PRESSED(wd->doorFlag[2]))
		{
			if ( wd->doorFlag[2]->flag == 1 )	
				Walls[Cursegp->sides[Curside].wall_num].flags |= WALL_ILLUSION_OFF;
			else
				Walls[Cursegp->sides[Curside].wall_num].flags &= ~WALL_ILLUSION_OFF;
			rval = 1;
		}
	} else 
		for (	i=2; i < 3; i++ )	
			if (wd->doorFlag[i]->flag == 1) { 
				wd->doorFlag[i]->flag = 0;		// Tells ui that this button isn't checked
				wd->doorFlag[i]->status = 1;	// Tells ui to redraw button
			}

	//------------------------------------------------------------
	// Draw the wall in the little 64x64 box
	//------------------------------------------------------------
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		// A simple frame time counter for animating the walls...
		Temp = timer_query();
		DeltaTime = Temp - wd->time;

		gr_set_current_canvas( wd->wallViewBox->canvas );
		if (Cursegp->sides[Curside].wall_num != -1) {
			type = Walls[Cursegp->sides[Curside].wall_num].type;
			if ((type == WALL_DOOR) || (type == WALL_BLASTABLE)) {
				if (DeltaTime > ((F1_0*200)/1000)) {
					wd->framenum++;
					wd->time = Temp;
				}
				if (wd->framenum >= WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].num_frames)
					wd->framenum=0;
				PIGGY_PAGE_IN(Textures[WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].frames[wd->framenum]]);
				gr_ubitmap(0,0, &GameBitmaps[Textures[WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].frames[wd->framenum]].index]);
			} else {
				if (type == WALL_OPEN)
					gr_clear_canvas( CBLACK );
				else {
					if (Cursegp->sides[Curside].tmap_num2 > 0)
						gr_ubitmap(0,0, texmerge_get_cached_bitmap( Cursegp->sides[Curside].tmap_num, Cursegp->sides[Curside].tmap_num2));
					else	{
						PIGGY_PAGE_IN(Textures[Cursegp->sides[Curside].tmap_num]);
						gr_ubitmap(0,0, &GameBitmaps[Textures[Cursegp->sides[Curside].tmap_num].index]);
					}
				}
			}
		} else
			gr_clear_canvas( CGREY );
	}

	//------------------------------------------------------------
	// If anything changes in the ui system, redraw all the text that
	// identifies this wall.
	//------------------------------------------------------------
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		if ( Cursegp->sides[Curside].wall_num > -1 )	{
			ui_dprintf_at( MainWindow, 12, 6, "Wall: %d    ", Cursegp->sides[Curside].wall_num);
			switch (Walls[Cursegp->sides[Curside].wall_num].type) {
				case WALL_NORMAL:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Normal   " );
					break;
				case WALL_BLASTABLE:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Blastable" );
					break;
				case WALL_DOOR:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Door     " );
					ui_dprintf_at( MainWindow, 223, 6, "%s", WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].filename);
					break;
				case WALL_ILLUSION:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Illusion " );
					break;
				case WALL_OPEN:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Open     " );
					break;
				case WALL_CLOSED:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Closed   " );
					break;
				default:
					ui_dprintf_at( MainWindow, 12, 23, " Type: Unknown  " );
					break;
			}			
			if (Walls[Cursegp->sides[Curside].wall_num].type != WALL_DOOR)
					ui_dprintf_at( MainWindow, 223, 6, "            " );

			ui_dprintf_at( MainWindow, 12, 40, " Clip: %d   ", Walls[Cursegp->sides[Curside].wall_num].clip_num );
			ui_dprintf_at( MainWindow, 12, 57, " Trigger: %d  ", Walls[Cursegp->sides[Curside].wall_num].trigger );
		}	else {
			ui_dprintf_at( MainWindow, 12, 6, "Wall: none ");
			ui_dprintf_at( MainWindow, 12, 23, " Type: none ");
			ui_dprintf_at( MainWindow, 12, 40, " Clip: none   ");
			ui_dprintf_at( MainWindow, 12, 57, " Trigger: none  ");
		}
	}
	
	if (ui_button_any_drawn || (wd->old_wall_num != Cursegp->sides[Curside].wall_num) )
		Update_flags |= UF_WORLD_CHANGED;

	if (event->type == EVENT_WINDOW_CLOSE)
	{
		d_free(wd);
		MainWindow = NULL;
		return 0;
	}

	if ( GADGET_PRESSED(wd->quitButton) || (keypress==KEY_ESC) )
	{
		close_wall_window();
		return 1;
	}		

	wd->old_wall_num = Cursegp->sides[Curside].wall_num;
	
	return rval;
}
Exemple #6
0
static window_event_result hostage_dialog_handler(UI_DIALOG *dlg,const d_event &event, hostage_dialog *h)
{
	switch(event.type)
	{
		case EVENT_WINDOW_CREATED:
			return hostage_dialog_created(dlg, h);
		case EVENT_WINDOW_CLOSE:
			std::default_delete<hostage_dialog>()(h);
			MainWindow = nullptr;
			return window_event_result::ignored;
		default:
			break;
	}
	fix64 Temp;
	int keypress = 0;
	if (event.type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);

	Assert(MainWindow != NULL);

	SelectClosestHostage();

	//------------------------------------------------------------
	// Call the ui code..
	//------------------------------------------------------------
	ui_button_any_drawn = 0;

	//------------------------------------------------------------
	// If we change objects, we need to reset the ui code for all
	// of the radio buttons that control the ai mode.  Also makes
	// the current AI mode button be flagged as pressed down.
	//------------------------------------------------------------
	//------------------------------------------------------------
	// If any of the radio buttons that control the mode are set, then
	// update the cooresponding AI state.
	//------------------------------------------------------------

	//------------------------------------------------------------
	// Redraw the object in the little 64x64 box
	//------------------------------------------------------------
	if (event.type == EVENT_UI_DIALOG_DRAW)
	{
		ui_dprintf_at( MainWindow, 10, 32,"&Message:" );

		// A simple frame time counter for spinning the objects...
		Temp = timer_query();
		h->time = Temp;
		
		if (CurrentHostageIndex > -1 )	{
			gr_set_current_canvas( h->hostageViewBox->canvas );

				gr_clear_canvas( CGREY );
		} else {
			// no hostage, so just blank out
			gr_set_current_canvas( h->hostageViewBox->canvas );
			gr_clear_canvas( CGREY );
		}
	}

	//------------------------------------------------------------
	// If anything changes in the ui system, redraw all the text that
	// identifies this robot.
	//------------------------------------------------------------
	if (event.type == EVENT_UI_DIALOG_DRAW)
	{
		if ( CurrentHostageIndex > -1 )	{
			ui_dprintf_at( MainWindow, 10, 15, "Hostage: %d   Object: %d", CurrentHostageIndex, Hostages[CurrentHostageIndex].objnum );
			//@@ui_dprintf_at( MainWindow, 10, 73, "Type: %d   Sound: %d   ", Hostages[CurrentHostageIndex].type, Hostages[CurrentHostageIndex].sound_num );
		}	else {
			ui_dprintf_at( MainWindow, 10, 15, "Hostage: none " );
			//@@ui_dprintf_at( MainWindow, 10, 73, "Type:    Sound:       " );
			ui_dprintf_at( MainWindow, 10, 73, "Face:         " );
		}
	}
	
	if (ui_button_any_drawn || (LastHostageIndex != CurrentHostageIndex))
		Update_flags |= UF_WORLD_CHANGED;
	if (GADGET_PRESSED(h->quitButton.get()) || keypress==KEY_ESC)
	{
		return window_event_result::close;
	}		

	LastHostageIndex = CurrentHostageIndex;
	return window_event_result::ignored;
}
Exemple #7
0
int robot_dialog_handler(UI_DIALOG *, d_event *event, robot_dialog *r)
{
	int	i;
	fix	DeltaTime;
	fix64	Temp;
	int	first_object_index;
	int keypress = 0;
	int rval = 0;
	
	if (event->type == EVENT_KEY_COMMAND)
		keypress = event_key_get(event);
		
	Assert(MainWindow != NULL);

	first_object_index = Cur_object_index;
	while (!is_legal_type_for_this_window(Cur_object_index)) {
		LocalObjectSelectNextinMine();
		if (first_object_index == Cur_object_index) {
			break;
		}
	}

	//------------------------------------------------------------
	// Call the ui code..
	//------------------------------------------------------------
	ui_button_any_drawn = 0;

	//------------------------------------------------------------
	// If we change objects, we need to reset the ui code for all
	// of the radio buttons that control the ai mode.  Also makes
	// the current AI mode button be flagged as pressed down.
	//------------------------------------------------------------
	if (r->old_object != Cur_object_index )	{
		for (	i=0; i < NUM_BOXES; i++ )
			ui_radio_set_value(r->initialMode[i], 0);
		if ( Cur_object_index != object_none ) {
			int	behavior = Objects[Cur_object_index].ctype.ai_info.behavior;
			if ( !((behavior >= MIN_BEHAVIOR) && (behavior <= MAX_BEHAVIOR))) {
				Objects[Cur_object_index].ctype.ai_info.behavior = AIB_NORMAL;
				behavior = AIB_NORMAL;
			}
			ui_radio_set_value(r->initialMode[behavior - MIN_BEHAVIOR], 1);
		}
	}

	//------------------------------------------------------------
	// If any of the radio buttons that control the mode are set, then
	// update the cooresponding AI state.
	//------------------------------------------------------------
	for (	i=0; i < NUM_BOXES; i++ )	{
		if ( GADGET_PRESSED(r->initialMode[i]) )	
			if (Objects[Cur_object_index].ctype.ai_info.behavior != MIN_BEHAVIOR+i) {
				Objects[Cur_object_index].ctype.ai_info.behavior = MIN_BEHAVIOR+i;		// Set the ai_state to the cooresponding radio button
				call_init_ai_object(&Objects[Cur_object_index], MIN_BEHAVIOR+i);
				rval = 1;
			}
	}

	//------------------------------------------------------------
	// Redraw the object in the little 64x64 box
	//------------------------------------------------------------
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		// A simple frame time counter for spinning the objects...
		Temp = timer_query();
		DeltaTime = Temp - r->time;
		r->time = Temp;

		if (Cur_object_index != object_none )	{
			dxxobject *obj = &Objects[Cur_object_index];

			gr_set_current_canvas( r->robotViewBox->canvas );
			draw_object_picture(obj->id, &r->angles, obj->type );
			r->angles.h += fixmul(0x1000, DeltaTime );
		} else {
			// no object, so just blank out
			gr_set_current_canvas( r->robotViewBox->canvas );
			gr_clear_canvas( CGREY );

	//		LocalObjectSelectNextInMine();
		}
	}

	//------------------------------------------------------------
	// Redraw the contained object in the other little box
	//------------------------------------------------------------
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		if ((Cur_object_index != object_none ) && (Cur_goody_count > 0))	{
			gr_set_current_canvas( r->containsViewBox->canvas );
			if ( Cur_goody_id > -1 )
				draw_object_picture(Cur_goody_id, &r->goody_angles, Cur_goody_type);
			else
				gr_clear_canvas( CGREY );
			r->goody_angles.h += fixmul(0x1000, DeltaTime );
		} else {
			// no object, so just blank out
			gr_set_current_canvas( r->containsViewBox->canvas );
			gr_clear_canvas( CGREY );

	//		LocalObjectSelectNextInMine();
		}
	}

	//------------------------------------------------------------
	// If anything changes in the ui system, redraw all the text that
	// identifies this robot.
	//------------------------------------------------------------

	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		int	i;
		char	id_text[STRING_LENGTH+1];
		const char *type_text;

		if (Cur_object_index != object_none) {
			Cur_goody_type = Objects[Cur_object_index].contains_type;
			Cur_goody_id = Objects[Cur_object_index].contains_id;
			if (Objects[Cur_object_index].contains_count < 0)
				Objects[Cur_object_index].contains_count = 0;
			Cur_goody_count = Objects[Cur_object_index].contains_count;
		}

		ui_dprintf_at( MainWindow, GOODY_X, GOODY_Y,    " Type:");
		ui_dprintf_at( MainWindow, GOODY_X, GOODY_Y+24, "   ID:");
		ui_dprintf_at( MainWindow, GOODY_X, GOODY_Y+48, "Count:");

		for (i=0; i<STRING_LENGTH; i++)
			id_text[i] = ' ';
		id_text[i] = 0;

		switch (Cur_goody_type) {
			case OBJ_ROBOT:
				type_text = "Robot  ";
				strncpy(id_text, Robot_names[Cur_goody_id], strlen(Robot_names[Cur_goody_id]));
				break;
			case OBJ_POWERUP:
				type_text = "Powerup";
				strncpy(id_text, Powerup_names[Cur_goody_id], strlen(Powerup_names[Cur_goody_id]));
				break;
			default:
				editor_status("Illegal contained object type (%i), changing to powerup.", Cur_goody_type);
				Cur_goody_type = OBJ_POWERUP;
				Cur_goody_id = 0;
				type_text = "Powerup";
				strncpy(id_text, Powerup_names[Cur_goody_id], strlen(Powerup_names[Cur_goody_id]));
				break;
		}

		ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y, "%s", type_text);
		ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y+24, "%s", id_text);
		ui_dprintf_at( MainWindow, GOODY_X+108, GOODY_Y+48, "%i", Cur_goody_count);

		if ( Cur_object_index != object_none )	{
			int	id = Objects[Cur_object_index].id;
			char	id_text[12];
			int	i;

			for (i=0; i<STRING_LENGTH; i++)
				id_text[i] = ' ';
			id_text[i] = 0;

			strncpy(id_text, Robot_names[id], strlen(Robot_names[id]));

			ui_dprintf_at( MainWindow, 12,  6, "Robot: %3u ", static_cast<unsigned>(Cur_object_index) );
			ui_dprintf_at( MainWindow, 12, 22, "   Id: %3d", id);
			ui_dprintf_at( MainWindow, 12, 38, " Name: %8s", id_text);

		}	else {
			ui_dprintf_at( MainWindow, 12,  6, "Robot: none" );
			ui_dprintf_at( MainWindow, 12, 22, " Type: ?  "  );
			ui_dprintf_at( MainWindow, 12, 38, " Name: ________" );
		}
	}
	
	if (ui_button_any_drawn || (r->old_object != Cur_object_index) )
		Update_flags |= UF_WORLD_CHANGED;
		
	if (event->type == EVENT_WINDOW_CLOSE)
	{
		d_free(r);
		MainWindow = NULL;
		return 0;
	}

	if ( GADGET_PRESSED(r->quitButton) || (keypress==KEY_ESC))
	{
		robot_close_window();
		return 1;
	}		

	r->old_object = Cur_object_index;
	
	return rval;
}
Exemple #8
0
static window_event_result browser_handler(UI_DIALOG *const dlg, const d_event &event, ui_file_browser *const b)
{
	window_event_result rval = window_event_result::ignored;

	if (event.type == EVENT_UI_DIALOG_DRAW)
	{
		ui_dputs_at( dlg, 10, 5, b->message );

		ui_dprintf_at( dlg, 20, 32,"N&ame" );
		ui_dprintf_at( dlg, 20, 86,"&Files" );
		ui_dprintf_at( dlg, 210, 86,"&Dirs" );
		
		ui_dputs_at(dlg, 20, 60, b->spaces.data());
		ui_dputs_at( dlg, 20, 60, b->view_dir );
		
		return window_event_result::handled;
	}

	if (GADGET_PRESSED(b->button2.get()))
	{
		b->filename_list.reset();
		b->directory_list.reset();
		return window_event_result::close;
	}
	
	if (GADGET_PRESSED(b->help_button.get()))
	{
		ui_messagebox( -1, -1, 1, "Sorry, no help is available!", "Ok" );
		rval = window_event_result::handled;
	}
	
	if (event.type == EVENT_UI_LISTBOX_MOVED)
	{
		if ((ui_event_get_gadget(event) == b->listbox1.get()) && (b->listbox1->current_item >= 0) && b->filename_list[b->listbox1->current_item])
			ui_inputbox_set_text(b->user_file.get(), b->filename_list[b->listbox1->current_item]);

		if ((ui_event_get_gadget(event) == b->listbox2.get()) && (b->listbox2->current_item >= 0) && b->directory_list[b->listbox2->current_item])
			ui_inputbox_set_text(b->user_file.get(), b->directory_list[b->listbox2->current_item]);

		rval = window_event_result::handled;
	}
	
	if (GADGET_PRESSED(b->button1.get()) || GADGET_PRESSED(b->user_file.get()) || event.type == EVENT_UI_LISTBOX_SELECTED)
	{
		char *p;
		
		if (ui_event_get_gadget(event) == b->listbox2.get())
			strcpy(b->user_file->text.get(), b->directory_list[b->listbox2->current_item]);
		
		strncpy(b->filename, b->view_dir, PATH_MAX);
		
		p = b->user_file->text.get();
		while (!strncmp(p, "..", 2))	// shorten the path manually
		{
			char *sep = strrchr(b->filename, '/');
			if (sep)
				*sep = 0;
			else
				*b->filename = 0;	// look directly in search paths
			
			p += 2;
			if (*p == '/')
				p++;
		}
		
		if (*b->filename && *p)
			strncat(b->filename, "/", PATH_MAX - strlen(b->filename));
		strncat(b->filename, p, PATH_MAX - strlen(b->filename));
		
		if (!PHYSFS_isDirectory(b->filename))
		{
			if (RAIIPHYSFS_File{PHYSFS_openRead(b->filename)})
			{
				// Looks like a valid filename that already exists!
				return window_event_result::close;
			}
			
			// File doesn't exist, but can we create it?
			if (RAIIPHYSFS_File TempFile{PHYSFS_openWrite(b->filename)})
			{
				TempFile.reset();
				// Looks like a valid filename!
				PHYSFS_delete(b->filename);
				return window_event_result::close;
			}
		}
		else
		{
			if (b->filename[strlen(b->filename) - 1] == '/')	// user typed a separator on the end
				b->filename[strlen(b->filename) - 1] = 0;
			
			strcpy(b->view_dir, b->filename);
			b->filename_list = file_getfilelist(b->filespec, b->view_dir);
			if (!b->filename_list)
			{
				b->directory_list.reset();
				return window_event_result::close;
			}
			
			ui_inputbox_set_text(b->user_file.get(), b->filespec);
			b->directory_list = file_getdirlist(b->view_dir);
			if (!b->directory_list)
			{
				b->filename_list.reset();
				return window_event_result::close;
			}
			
			ui_listbox_change(dlg, b->listbox1.get(), b->filename_list.get_count(), b->filename_list.get());
			ui_listbox_change(dlg, b->listbox2.get(), b->directory_list.get_count(), b->directory_list.get());
			
			//i = TICKER;
			//while ( TICKER < i+2 );
			
		}
		
		rval = window_event_result::handled;
	}
	
	return rval;
}