if(pbutton->show_info == YES)
{
char str[80];
+ int i = -32;
+
+ if(0 > pbutton->x - (int)strlen(pbutton->info) * white_small_text.w)
+ i = pbutton->w + strlen(pbutton->info) * white_small_text.w;
+
if(pbutton->info)
- text_draw(&white_small_text, pbutton->info, pbutton->x - strlen(pbutton->info) * white_small_text.w, pbutton->y, 1, NO_UPDATE);
+ text_draw(&white_small_text, pbutton->info, i + pbutton->x - strlen(pbutton->info) * white_small_text.w, pbutton->y, 1, NO_UPDATE);
sprintf(str,"(%s)", SDL_GetKeyName(pbutton->shortcut));
- text_draw(&white_small_text, str, pbutton->x - strlen(str) * white_small_text.w, pbutton->y + white_small_text.h+2, 1, NO_UPDATE);
+ text_draw(&white_small_text, str, i + pbutton->x - strlen(str) * white_small_text.w, pbutton->y + white_small_text.h+2, 1, NO_UPDATE);
}
if(pbutton->state == BN_PRESSED)
fillrect(pbutton->x,pbutton->y,pbutton->w,pbutton->h,75,75,75,200);
+ else if(pbutton->state == BN_HOVER)
+ fillrect(pbutton->x,pbutton->y,pbutton->w,pbutton->h,150,150,150,128);
}
void button_free(button_type* pbutton)
void button_event(button_type* pbutton, SDL_Event *event)
{
-SDLKey key = event->key.keysym.sym;
+ SDLKey key = event->key.keysym.sym;
if(event->motion.x > pbutton->x && event->motion.x < pbutton->x + pbutton->w &&
event->motion.y > pbutton->y && event->motion.y < pbutton->y + pbutton->h)
pbutton->show_info = YES;
}
}
- if(event->type == SDL_MOUSEBUTTONUP)
+ else if(event->type == SDL_MOUSEBUTTONUP)
{
if(event->button.button == SDL_BUTTON_LEFT && pbutton->state == BN_PRESSED)
{
pbutton->show_info = YES;
}
}
+
+ if(pbutton->state != BN_PRESSED && pbutton->state != BN_CLICKED)
+ {
+ pbutton->state = BN_HOVER;
+ }
}
- else if(event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP)
+ else if(event->type != SDL_KEYDOWN && event->type != SDL_KEYUP)
{
pbutton->state = -1;
if(pbutton->show_info)
pbutton->show_info = NO;
}
}
-
+
if(event->type == SDL_KEYDOWN)
{
if(key == pbutton->shortcut)
void button_panel_draw(button_panel_type* pbutton_panel)
{
int i;
+ fillrect(pbutton_panel->x,pbutton_panel->y,pbutton_panel->w,pbutton_panel->h,100,100,100,200);
for(i = 0; i < pbutton_panel->num_items; ++i)
{
button_draw(&pbutton_panel->item[i]);
static int done;
static char le_current_tile;
static int le_mouse_pressed;
+static button_type le_save_level_bt;
static button_type le_test_level_bt;
static button_type le_next_level_bt;
static button_type le_previous_level_bt;
{
subset_load(&le_level_subset,level_subsets[i-2]);
leveleditor_menu.item[3].kind = MN_GOTO;
- menu_item_change_input(&subset_settings_menu.item[2],le_level_subset.title);
- menu_item_change_input(&subset_settings_menu.item[3],le_level_subset.description);
+ menu_item_change_input(&subset_settings_menu.item[2],le_level_subset.title);
+ menu_item_change_input(&subset_settings_menu.item[3],le_level_subset.description);
le_level = 1;
arrays_init();
loadshared();
if(subset_new_menu.item[2].input[0] == '\0')
subset_new_menu.item[3].kind = MN_DEACTIVE;
else
- {
- subset_new_menu.item[3].kind = MN_ACTION;
-
- switch (i = menu_check(&subset_new_menu))
{
- case 3:
- le_new_subset(subset_new_menu.item[2].input);
- break;
+ subset_new_menu.item[3].kind = MN_ACTION;
+
+ switch (i = menu_check(&subset_new_menu))
+ {
+ case 3:
+ le_new_subset(subset_new_menu.item[2].input);
+ break;
+ }
}
- }
}
}
texture_load(&le_selection,DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA);
/* Load buttons */
+ button_load(&le_save_level_bt,"/images/icons/save.png","Save level", SDLK_F6,screen->w-64,32);
button_load(&le_next_level_bt,"/images/icons/up.png","Next level", SDLK_PAGEUP,screen->w-64,0);
button_load(&le_previous_level_bt,"/images/icons/down.png","Previous level",SDLK_PAGEDOWN,screen->w-32,0);
- button_load(&le_rubber_bt,"/images/icons/rubber.png","Rubber",SDLK_DELETE,screen->w-64,32);
- button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select single tile",SDLK_F3,screen->w-64,16);
- button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select multiple tiles",SDLK_F3,screen->w-32,16);
+ button_load(&le_rubber_bt,"/images/icons/rubber.png","Rubber",SDLK_DELETE,screen->w-32,48);
+ button_load(&le_select_mode_one_bt,"/images/icons/select-mode1.png","Select single tile",SDLK_F3,screen->w-64,48);
+ button_load(&le_select_mode_two_bt,"/images/icons/select-mode2.png","Select multiple tiles",SDLK_F3,screen->w-64,64);
button_load(&le_test_level_bt,"/images/icons/test-level.png","Test level",SDLK_F4,screen->w-64,screen->h - 64);
button_load(&le_settings_bt,"/images/icons/settings.png","Level settings",SDLK_F5,screen->w-32,screen->h - 64);
- button_load(&le_move_left_bt,"/images/icons/left.png","Move left",SDLK_LEFT,screen->w-64,screen->h - 32);
- button_load(&le_move_right_bt,"/images/icons/right.png","Move right",SDLK_RIGHT,screen->w-48,screen->h - 32);
- button_panel_init(&le_bt_panel, screen->w - 64,64, 64, 380);
+ button_load(&le_move_left_bt,"/images/icons/left.png","Move left",SDLK_LEFT,0,0);
+ button_load(&le_move_right_bt,"/images/icons/right.png","Move right",SDLK_RIGHT,screen->w-80,0);
+ button_panel_init(&le_bt_panel, screen->w - 64,82, 64, 334);
menu_init(&leveleditor_menu);
menu_additem(&leveleditor_menu,menu_item_create(MN_LABEL,"Level Editor Menu",0,0));
if(le_current_level != NULL)
{
+ button_draw(&le_save_level_bt);
button_draw(&le_test_level_bt);
button_draw(&le_next_level_bt);
button_draw(&le_previous_level_bt);
button_panel_draw(&le_bt_panel);
sprintf(str, "%d/%d", le_level,le_level_subset.levels);
- text_draw(&white_text, "LEV", 0, 0, 1, NO_UPDATE);
- text_draw(&gold_text, str, 80, 0, 1, NO_UPDATE);
+ text_drawf(&white_text, str, -8, 16, A_RIGHT, A_NONE, 1, NO_UPDATE);
text_draw(&white_small_text, "F1 for Help", 10, 430, 1, NO_UPDATE);
}
if(show_menu)
{
menu_event(&event.key.keysym);
+ if(key == SDLK_ESCAPE)
+ {
+ show_menu = NO;
+ menu_set_current(&leveleditor_menu);
+ }
break;
}
switch(key)
if(le_current_level != NULL)
{
if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w &&
- event.motion.y > 0 && event.motion.y < screen->h)))
+ event.motion.y > 0 && event.motion.y < screen->h)))
{
/* Check for button events */
button_event(&le_test_level_bt,&event);
if(button_get_state(&le_test_level_bt) == BN_CLICKED)
le_testlevel();
+ button_event(&le_save_level_bt,&event);
+ if(button_get_state(&le_save_level_bt) == BN_CLICKED)
+ level_save(le_current_level,le_level_subset.name,le_level);
button_event(&le_next_level_bt,&event);
if(button_get_state(&le_next_level_bt) == BN_CLICKED)
{
if(le_level > 1)
le_goto_level(--le_level);
}
- button_event(&le_move_left_bt,&event);
- if(button_get_state(&le_move_left_bt) == BN_PRESSED)
- pos_x -= 180;
- button_event(&le_move_right_bt,&event);
- if(button_get_state(&le_move_right_bt) == BN_PRESSED)
- pos_x += 180;
button_event(&le_rubber_bt,&event);
if(button_get_state(&le_rubber_bt) == BN_CLICKED)
le_current_tile = '.';
}
}
+ button_event(&le_move_left_bt,&event);
+ if(button_get_state(&le_move_left_bt) == BN_PRESSED)
+ {
+ pos_x -= 192;
+ }
+ else if(button_get_state(&le_move_left_bt) == BN_HOVER)
+ {
+ pos_x -= 96;
+ }
+ button_event(&le_move_right_bt,&event);
+ if(button_get_state(&le_move_right_bt) == BN_PRESSED)
+ {
+ pos_x += 192;
+ }
+ else if(button_get_state(&le_move_right_bt) == BN_HOVER)
+ {
+ pos_x += 96;
+ }
+
if(le_mouse_pressed)
{
le_change(cursor_x, cursor_y, le_current_tile);