Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
3 | * described in COPYING.txt. |
||
4 | * Portions of this file are copyright Parallax Software and licensed |
||
5 | * according to the Parallax license below. |
||
6 | * See COPYING.txt for license details. |
||
7 | |||
8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
18 | */ |
||
19 | |||
20 | /* |
||
21 | * |
||
22 | * Routines for placing hostages, etc... |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | |||
27 | #include <stdlib.h> |
||
28 | #include <stdio.h> |
||
29 | #include <string.h> |
||
30 | #include <math.h> |
||
31 | |||
32 | #include "dxxerror.h" |
||
33 | #include "screens.h" |
||
34 | #include "editor/esegment.h" |
||
35 | #include "ehostage.h" |
||
36 | |||
37 | #include "timer.h" |
||
38 | #include "objpage.h" |
||
39 | #include "maths.h" |
||
40 | #include "gameseg.h" |
||
41 | #include "kdefs.h" |
||
42 | #include "object.h" |
||
43 | #include "polyobj.h" |
||
44 | #include "game.h" |
||
45 | #include "powerup.h" |
||
46 | #include "ai.h" |
||
47 | #include "hostage.h" |
||
48 | #include "key.h" |
||
49 | #include "bm.h" |
||
50 | #include "sounds.h" |
||
51 | #include "centers.h" |
||
52 | #include "piggy.h" |
||
53 | #include "u_mem.h" |
||
54 | #include "event.h" |
||
55 | #include <memory> |
||
56 | |||
57 | //------------------------------------------------------------------------- |
||
58 | // Variables for this module... |
||
59 | //------------------------------------------------------------------------- |
||
60 | static UI_DIALOG *MainWindow = NULL; |
||
61 | |||
62 | namespace { |
||
63 | |||
64 | struct hostage_dialog |
||
65 | { |
||
66 | std::unique_ptr<UI_GADGET_BUTTON> quitButton, delete_object, new_object; |
||
67 | }; |
||
68 | |||
69 | } |
||
70 | |||
71 | static int PlaceHostage() |
||
72 | { |
||
73 | auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state(); |
||
74 | auto &Vertices = LevelSharedVertexState.get_vertices(); |
||
75 | int ctype,i; |
||
76 | //update_due_to_new_segment(); |
||
77 | auto &vcvertptr = Vertices.vcptr; |
||
78 | const auto cur_object_loc = compute_segment_center(vcvertptr, Cursegp); |
||
79 | |||
80 | ctype = -1; |
||
81 | for (i=0; i<Num_total_object_types; i++ ) { |
||
82 | if (ObjType[i] == OL_HOSTAGE ) { |
||
83 | ctype = i; |
||
84 | break; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | Assert( ctype != -1 ); |
||
89 | |||
90 | if (place_object(Cursegp, cur_object_loc, ctype, 0 )==0) { |
||
91 | Int3(); // Debug below |
||
92 | i=place_object(Cursegp, cur_object_loc, ctype, 0 ); |
||
93 | return 1; |
||
94 | } |
||
95 | return 0; |
||
96 | } |
||
97 | |||
98 | static window_event_result hostage_dialog_handler(UI_DIALOG *dlg,const d_event &event, hostage_dialog *h); |
||
99 | |||
100 | //------------------------------------------------------------------------- |
||
101 | // Called from the editor... does one instance of the hostage dialog box |
||
102 | //------------------------------------------------------------------------- |
||
103 | int do_hostage_dialog() |
||
104 | { |
||
105 | // Only open 1 instance of this window... |
||
106 | if ( MainWindow != NULL ) return 0; |
||
107 | |||
108 | // Close other windows |
||
109 | close_all_windows(); |
||
110 | |||
111 | auto h = std::make_unique<hostage_dialog>(); |
||
112 | |||
113 | // Open a window with a quit button |
||
114 | MainWindow = ui_create_dialog(TMAPBOX_X+10, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, DF_DIALOG, hostage_dialog_handler, std::move(h)); |
||
115 | return 1; |
||
116 | } |
||
117 | |||
118 | static window_event_result hostage_dialog_created(UI_DIALOG *const w, hostage_dialog *const h) |
||
119 | { |
||
120 | h->quitButton = ui_add_gadget_button(w, 20, 222, 48, 40, "Done", NULL); |
||
121 | // A bunch of buttons... |
||
122 | int i = 90; |
||
123 | h->delete_object = ui_add_gadget_button(w, 155, i, 140, 26, "Delete", ObjectDelete); i += 29; |
||
124 | h->new_object = ui_add_gadget_button(w, 155, i, 140, 26, "Create New", PlaceHostage); i += 29; |
||
125 | return window_event_result::ignored; |
||
126 | } |
||
127 | |||
128 | void hostage_close_window() |
||
129 | { |
||
130 | if ( MainWindow!=NULL ) { |
||
131 | ui_close_dialog( MainWindow ); |
||
132 | MainWindow = NULL; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | static window_event_result hostage_dialog_handler(UI_DIALOG *dlg,const d_event &event, hostage_dialog *h) |
||
137 | { |
||
138 | switch(event.type) |
||
139 | { |
||
140 | case EVENT_WINDOW_CREATED: |
||
141 | return hostage_dialog_created(dlg, h); |
||
142 | case EVENT_WINDOW_CLOSE: |
||
143 | std::default_delete<hostage_dialog>()(h); |
||
144 | MainWindow = nullptr; |
||
145 | return window_event_result::ignored; |
||
146 | default: |
||
147 | break; |
||
148 | } |
||
149 | int keypress = 0; |
||
150 | if (event.type == EVENT_KEY_COMMAND) |
||
151 | keypress = event_key_get(event); |
||
152 | |||
153 | Assert(MainWindow != NULL); |
||
154 | |||
155 | //------------------------------------------------------------ |
||
156 | // Redraw the object in the little 64x64 box |
||
157 | //------------------------------------------------------------ |
||
158 | if (GADGET_PRESSED(h->quitButton.get()) || keypress==KEY_ESC) |
||
159 | { |
||
160 | return window_event_result::close; |
||
161 | } |
||
162 | return window_event_result::ignored; |
||
163 | } |