11#include " menu.h"
2+ #include " text.h"
3+ #include " tiles.h"
24#include " window.h"
35#include " music.h"
46#include " alchemist/elements.h"
57#include " alchemist/axe.h"
68#include " alchemist/knife.h"
79#include " world.h"
810#include " craft.h"
11+ #include < cstddef>
912#include < cstdio>
1013#include < cstdlib>
1114
@@ -23,6 +26,7 @@ Menu *menu_inventory_categories;
2326Menu *menu_inventory;
2427Menu *menu_crafting;
2528Menu *menu_dev;
29+ Menu *menu_build;
2630
2731void load (char with_player);
2832void save (char with_player);
@@ -151,6 +155,7 @@ void create_menus()
151155 menu_main->add (" Change music volume" , MENU_MUSIC);
152156 menu_main->add (" Cancel" , MENU_CANCEL);
153157
158+
154159 menu_help = new Menu (" Help 1" , 9 );
155160 menu_help->add (" ; - show item info" , MENU_CANCEL);
156161 menu_help->add (" f11 - resize" , MENU_CANCEL);
@@ -202,8 +207,12 @@ void create_menus()
202207 menu_crafting->add (" Knife blade (1 ing.)" , MENU_CRAFT_KNIFE_BLADE);
203208 menu_crafting->add (" Knife handle (1 ing.)" , MENU_CRAFT_KNIFE_HANDLE);
204209 menu_crafting->add (" Knife (2 ing.)" , MENU_CRAFT_KNIFE);
210+
205211
206212 menu_crafting->add (" Cancel" , MENU_CANCEL);
213+
214+ menu_build = new Menu (" build" , 1 );
215+ menu_build->add (" Wall (1 ing.)" , MENU_BUILD_WALL);
207216
208217 menu_dev = new Menu (" dev options" , 4 );
209218 menu_dev->add (" axe" , MENU_GET_AXE);
@@ -253,56 +262,62 @@ void Menu::go_up()
253262int menu_interact (int key)
254263{
255264 switch (key)
256- {
257- case SDLK_ESCAPE:
258- {
259- if (current_menu) current_menu=NULL ; else current_menu=menu_main;
260- return 1 ;
261- }
262- case SDLK_l:
263- {
264- if (current_menu) current_menu=NULL ; else current_menu=menu_dev;
265- return 1 ;
266- }
267- case SDLK_c:
268- {
269- if (!current_menu) current_menu=menu_crafting; else if (current_menu == menu_crafting) current_menu=NULL ;
270- return 1 ;
271- }
265+ {
266+ case SDLK_b:
267+ {
268+ if (!current_menu) current_menu=menu_build; else if (current_menu == menu_build) current_menu=NULL ;
269+
270+ return 1 ;
271+ }
272+ case SDLK_ESCAPE:
273+ {
274+ if (current_menu) current_menu=NULL ; else current_menu=menu_main;
275+ return 1 ;
276+ }
277+ case SDLK_l:
278+ {
279+ if (current_menu) current_menu=NULL ; else current_menu=menu_dev;
280+ return 1 ;
281+ }
282+ case SDLK_c:
283+ {
284+ if (!current_menu) current_menu=menu_crafting; else if (current_menu == menu_crafting) current_menu=NULL ;
285+ return 1 ;
286+ }
272287 case SDLK_i:
273- {
274- player.inventory ->show ();
275- if (!current_menu) current_menu=menu_inventory_categories;
276- else if (current_menu == menu_inventory_categories) current_menu=NULL ;
277- return 1 ;
278- }
279-
280- case SDLK_DOWN:
281- case SDLK_s:
282- {
283- if (current_menu) current_menu->go_down ();
284- break ;
285- }
286- case SDLK_w:
287- case SDLK_UP:
288- {
289- if (current_menu) current_menu->go_up ();
290- break ;
291- }
292-
293- case SDLK_RETURN:
294- case SDLK_e:
295- {
296- if (current_menu)
297- {
298- if (interact (current_menu->actions [current_menu->menu_pos ]))
299- {
300- current_menu=NULL ;
301- return 1 ;
302- }
303- }
304- break ;
305- }
288+ {
289+ player.inventory ->show ();
290+ if (!current_menu) current_menu=menu_inventory_categories;
291+ else if (current_menu == menu_inventory_categories) current_menu=NULL ;
292+ return 1 ;
293+ }
294+
295+ case SDLK_DOWN:
296+ case SDLK_s:
297+ {
298+ if (current_menu) current_menu->go_down ();
299+ break ;
300+ }
301+ case SDLK_w:
302+ case SDLK_UP:
303+ {
304+ if (current_menu) current_menu->go_up ();
305+ break ;
306+ }
307+
308+ case SDLK_RETURN:
309+ case SDLK_e:
310+ {
311+ if (current_menu)
312+ {
313+ if (interact (current_menu->actions [current_menu->menu_pos ]))
314+ {
315+ current_menu=NULL ;
316+ return 1 ;
317+ }
318+ }
319+ break ;
320+ }
306321 }
307322 return current_menu ? 1 : 0 ;
308323}
@@ -332,6 +347,7 @@ int craft(menu_actions a)
332347 case MENU_CRAFT_AXE_BLADE: el = craft_axe_blade (); break ;
333348 case MENU_CRAFT_AXE_HANDLE: el = craft_axe_handle (); break ;
334349 case MENU_CRAFT_AXE: el = craft_axe (); break ;
350+
335351 }
336352 if (el) {
337353 set_item_at_ppos (el, &player);
@@ -347,6 +363,37 @@ int interact(enum menu_actions a)
347363 if (a & MENU_ITEM) return handle_item (a & ~MENU_ITEM);
348364 switch (a)
349365 {
366+ case MENU_BUILD_WALL:
367+ {
368+ sprintf (status_line, " Starting building" );
369+ if (player.hotbar [active_hotbar] && player.hotbar [active_hotbar]->get_form () == Form_solid)
370+ {
371+ Object * ob = new Object ();
372+ ob->base = ((Element *)(player.hotbar [active_hotbar]))->get_base ();
373+
374+ player.inventory ->remove (player.hotbar [active_hotbar]);
375+ player.hotbar [active_hotbar]=NULL ;
376+
377+ ob->type = OBJECT_wall;
378+ ob->set_posittion (player.x , player.y );
379+
380+ for (int i = 0 ; i < CHUNK_SIZE*CHUNK_SIZE; i++)
381+ {
382+ if (!world_table[player.map_y ][player.map_x ]->objects [i])
383+ {
384+ world_table[player.map_y ][player.map_x ]->objects [i] = ob;
385+ break ;
386+ }
387+ }
388+
389+ status_code = 1 ;
390+ }
391+ else {
392+ status_code = 0 ;
393+ }
394+ break ;
395+ }
396+
350397 case MENU_GET_AXE:
351398 {
352399 Element * el1=new Element (base_elements[0 ]);
0 commit comments