}
menu_init(&leveleditor_menu);
- menu_additem(&leveleditor_menu,menu_item_create(MN_LABEL,"Level Editor Menu",0,0));
- menu_additem(&leveleditor_menu,menu_item_create(MN_HL,"",0,0));
- menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Return To Level Editor",0,0));
- menu_additem(&leveleditor_menu,menu_item_create(MN_DEACTIVE,"Level Subset Settings",0,&subset_settings_menu));
- menu_additem(&leveleditor_menu,menu_item_create(MN_GOTO,"Load Level Subset",0,&subset_load_menu));
- menu_additem(&leveleditor_menu,menu_item_create(MN_GOTO,"New Level Subset",0,&subset_new_menu));
- menu_additem(&leveleditor_menu,menu_item_create(MN_HL,"",0,0));
- menu_additem(&leveleditor_menu,menu_item_create(MN_ACTION,"Quit Level Editor",0,0));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_LABEL,"Level Editor Menu",0,0));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_HL,"",0,0));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_ACTION,"Return To Level Editor",0,0));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_DEACTIVE,"Level Subset Settings",0,&subset_settings_menu));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_GOTO,"Load Level Subset",0,&subset_load_menu));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_GOTO,"New Level Subset",0,&subset_new_menu));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_HL,"",0,0));
+ menu_additem(&leveleditor_menu, menu_item_create(MN_ACTION,"Quit Level Editor",0,0));
menu_reset();
menu_set_current(&leveleditor_menu);
}
/* Return a pointer to a new menu item */
-menu_item_type* menu_item_create(int kind, char *text, int init_toggle, void* target_menu)
+menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* target_menu)
{
menu_item_type *pnew_item = (menu_item_type*) malloc(sizeof(menu_item_type));
pnew_item->kind = kind;
return -1;
}
-void menu_draw_item(menu_type* pmenu, const menu_item_type& pitem,
- int offset, // Position of the current item in the menu
+void menu_draw_item(menu_type* pmenu,
+ int index, // Position of the current item in the menu
int menu_width,
int menu_height)
{
- int a;
- int b;
- int e;
- int f;
+ const menu_item_type& pitem = pmenu->item[index];
+ int arrange = 0;
if(pmenu->arrange_left == YES)
- a = menu_width * 16;
- else
- a = 0;
+ arrange = ((menu_width - 48) + (16 * (strlen(pitem.text)
+ + strlen(pitem.input)
+ + strlen(string_list_active(pitem.list)))))/2;
- if(pmenu->arrange_left == YES)
- b = (a - ((strlen(pitem.text)+strlen(pitem.input)+ strlen(string_list_active(pitem.list))) * 16)) / 2;
- else
- b = 0;
+ int f = 0;
+ {
+ int effect_time = 0;
+ if(timer_check(&pmenu->effect))
+ effect_time = timer_get_left(&pmenu->effect) / 4;
- if(timer_check(&pmenu->effect))
- e = timer_get_left(&pmenu->effect) / 4;
- else
- e = 0;
-
- if(e != 0)
- f = (offset % 2) ? e : -e;
- else
- f = 0;
+ f = (index % 2) ? effect_time : -effect_time;
+ }
int x_pos = screen->w/2 - menu_width/2;
- int y_pos = offset*24 - menu_height/2;
+ int y_pos = index * 24 - menu_height/2;
- int center_x = screen->w/2;
- int center_y = screen->h /2;
- int start_x = center_x - b;
+ int start_x = screen->w/2 + arrange;
+ int center_y = screen->h /2;
- if(pitem.kind == MN_DEACTIVE)
- {
- text_drawf(&black_text, pitem.text,
- -b, y_pos + 10 + f,
- A_HMIDDLE, A_VMIDDLE, 2, NO_UPDATE);
- }
- else if(pitem.kind == MN_HL)
- {
- /* Draw a horizontal line with a little 3d effect */
- fillrect(x_pos, y_pos + 6 + center_y,
- menu_width, 4,
- 210,50,50,225);
- fillrect(x_pos, y_pos + 10 + center_y,
- menu_width, 2,
- 0,0,0,255);
- }
- else if(pitem.kind == MN_LABEL)
- {
- text_drawf(&white_big_text, pitem.text,
- -b, y_pos + 10,
- A_HMIDDLE, A_VMIDDLE, 2);
- }
- else if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
- {
- int input_pos = ((strlen(pitem.input)*16)/2);
- int text_pos = ((strlen(pitem.text) + 1)*16)/2;
- fillrect(-b +center_x - input_pos + text_pos - 1,y_pos + 10 + center_y - 10 + f,
- (strlen(pitem.input)+1)*16 + 2, 20,
- 255,255,255,255);
- fillrect(-b +center_x - input_pos + text_pos, y_pos + 10 + center_y - 9 + f,
- (strlen(pitem.input)+1)*16, 18,
- 0,0,0,128);
- text_drawf(&gold_text, pitem.input,
- -b + text_pos, y_pos + 10 + f,
- A_HMIDDLE, A_VMIDDLE, 2);
-
- if(offset == pmenu->active_item)
- {
- text_drawf(&blue_text,pitem.text, -b -(((strlen(pitem.input)+1) * 16)/2),y_pos + 10 + f,A_HMIDDLE, A_VMIDDLE,3);
- }
- else
- {
- text_drawf(&white_text,pitem.text, -b -(((strlen(pitem.input)+1) * 16)/2),y_pos +10 + f,A_HMIDDLE, A_VMIDDLE,2);
- }
- }
- else if(pitem.kind == MN_STRINGSELECT)
- {
- int list_pos = ((strlen(string_list_active(pitem.list))*16)/2);
- int list_pos_2 = (strlen(string_list_active(pitem.list))+1)*16;
- int text_pos = ((strlen(pitem.text) + 1)*16)/2;
-
- /* Draw arrows */
- texture_draw(&arrow_left, start_x - list_pos + text_pos - 17, y_pos + 10 + center_y -8 + f);
- texture_draw(&arrow_right, start_x - list_pos + text_pos - 1 + list_pos_2, y_pos + 10 + center_y -8 + f);
-
- /* Draw input background */
- fillrect(start_x - list_pos + text_pos - 1, y_pos + 10 + center_y - 10 + f,
- list_pos_2 + 2, 20,
- 255,255,255,255);
- fillrect(start_x - list_pos + text_pos, y_pos + 10 + center_y - 9 + f,
- list_pos_2, 18,
- 0,0,0,128);
-
- text_drawf(&gold_text, string_list_active(pitem.list),
- -b + text_pos, y_pos + 10 + f,
- A_HMIDDLE, A_VMIDDLE,2);
-
- if(offset == pmenu->active_item)
- {
- text_drawf(&blue_text,pitem.text,
- -b - list_pos_2/2, y_pos + 10 + f,
- A_HMIDDLE, A_VMIDDLE,3);
- }
- else
- {
- text_drawf(&white_text,pitem.text,
- -b - list_pos_2/2, y_pos +10 + f,
- A_HMIDDLE, A_VMIDDLE,2);
- }
- }
- else if(offset == pmenu->active_item)
+ int cen_y = center_y + y_pos;
+ int cen_y_10_f = 10 + f + cen_y;
+
+ int shadow_size = 2;
+ text_type* text_font = &white_text;
+ if(index == pmenu->active_item)
{
- text_drawf(&blue_text, pitem.text,
- -b,y_pos + 10 + f,
- A_HMIDDLE, A_VMIDDLE, 3);
+ shadow_size = 3;
+ text_font = &blue_text;
}
- else
+
+ switch (pitem.kind)
{
- text_drawf(&white_text, pitem.text,
- -b, y_pos + 10 + f,
- A_HMIDDLE, A_VMIDDLE, 2);
+ case MN_DEACTIVE:
+ {
+ text_drawf(&black_text, pitem.text,
+ arrange, y_pos + 10 + f,
+ A_HMIDDLE, A_VMIDDLE, 2);
+ break;
+ }
+
+ case MN_HL:
+ {
+ /* Draw a horizontal line with a little 3d effect */
+ fillrect(x_pos, cen_y + 6,
+ menu_width, 4,
+ 210,50,50,225);
+ fillrect(x_pos, 10 + cen_y + 6,
+ menu_width, 2,
+ 0,0,0,255);
+ break;
+ }
+ case MN_LABEL:
+ {
+ text_drawf(&white_big_text, pitem.text,
+ arrange, y_pos + 10,
+ A_HMIDDLE, A_VMIDDLE, 2);
+ break;
+ }
+ case MN_TEXTFIELD:
+ case MN_NUMFIELD:
+ {
+ int input_pos = ((strlen(pitem.input)*16)/2);
+ int text_pos = ((strlen(pitem.text) + 1)*16)/2;
+
+ fillrect(start_x - input_pos + text_pos - 1, cen_y_10_f - 10,
+ (strlen(pitem.input)+1)*16 + 2, 20,
+ 255,255,255,255);
+ fillrect(start_x - input_pos + text_pos, cen_y_10_f - 9,
+ (strlen(pitem.input)+1)*16, 18,
+ 0,0,0,128);
+
+ text_drawf(&gold_text, pitem.input,
+ arrange + text_pos, 10 + f + y_pos,
+ A_HMIDDLE, A_VMIDDLE, 2);
+
+ text_drawf(text_font, pitem.text,
+ arrange - (((strlen(pitem.input)+1) * 16)/2), y_pos + 10 + f,
+ A_HMIDDLE, A_VMIDDLE, shadow_size);
+ break;
+ }
+ case MN_STRINGSELECT:
+ {
+ int list_pos_2 = (strlen(string_list_active(pitem.list))+1)*16;
+ int list_pos = (strlen(string_list_active(pitem.list))*16)/2;
+ int text_pos = ((strlen(pitem.text) + 1)*16)/2;
+
+ /* Draw arrows */
+ texture_draw(&arrow_left, start_x - list_pos + text_pos - 17, cen_y_10_f - 8);
+ texture_draw(&arrow_right, start_x - list_pos + text_pos - 1 + list_pos_2, cen_y_10_f - 8);
+
+ /* Draw input background */
+ fillrect(start_x - list_pos + text_pos - 1, cen_y_10_f - 10,
+ list_pos_2 + 2, 20,
+ 255,255,255,255);
+ fillrect(start_x - list_pos + text_pos, cen_y_10_f - 9,
+ list_pos_2, 18,
+ 0,0,0,128);
+
+ text_drawf(&gold_text, string_list_active(pitem.list),
+ arrange + text_pos, 10 + f + y_pos,
+ A_HMIDDLE, A_VMIDDLE,2);
+
+ text_drawf(text_font, pitem.text,
+ arrange - list_pos_2/2, 10 + f + y_pos,
+ A_HMIDDLE, A_VMIDDLE, shadow_size);
+ break;
+ }
+ case MN_BACK:
+ {
+ texture_draw(&back, start_x + (strlen(pitem.text) * 16)/2 + 16, cen_y_10_f - 8);
+ break;
+ }
+
+ case MN_TOGGLE:
+ {
+ if(pitem.toggled == YES)
+ texture_draw(&checkbox_checked, start_x + (strlen(pitem.text) * 16)/2 + 16, cen_y_10_f - 8);
+ else
+ texture_draw(&checkbox, start_x + (strlen(pitem.text) * 16)/2 + 16, cen_y_10_f - 8);
+ break;
+ }
+ case MN_ACTION:
+ break;
+
+ case MN_GOTO:
+ break;
}
- if(pitem.kind == MN_TOGGLE)
+ switch (pitem.kind)
{
- if(pitem.toggled == YES)
- texture_draw(&checkbox_checked, -b + screen->w / 2 + (strlen(pitem.text) * 16)/2 + 16,y_pos + 10 + center_y -8 + f);
- else
- texture_draw(&checkbox, -b + screen->w / 2 + (strlen(pitem.text) * 16)/2 + 16,y_pos + 10 + center_y - 8 + f);
+ case MN_ACTION:
+ case MN_GOTO:
+ case MN_TOGGLE:
+ case MN_BACK:
+ text_drawf(text_font, pitem.text, arrange, 10 + f + y_pos, A_HMIDDLE, A_VMIDDLE, shadow_size);
+ break;
+ case MN_DEACTIVE:
+ case MN_TEXTFIELD:
+ case MN_NUMFIELD:
+ case MN_STRINGSELECT:
+ case MN_LABEL:
+ case MN_HL:
+ break;
}
- else if(pitem.kind == MN_BACK)
- {
- texture_draw(&back, -b + screen->w / 2 + (strlen(pitem.text) * 16)/2 + 16,y_pos + 10 + center_y -8 + f);
- }
}
/* Draw the current menu. */
for(int i = 0; i < pmenu->num_items; ++i)
{
- menu_draw_item(pmenu, pmenu->item[i], i, menu_width, menu_height);
+ menu_draw_item(pmenu, i, menu_width, menu_height);
}
}