- Treballant en el editor de posició i tamany del bitmap
This commit is contained in:
61
source/m_editor_bitmap.cpp
Normal file
61
source/m_editor_bitmap.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "m_editor_bitmap.h"
|
||||
#include "jdraw.h"
|
||||
#include "jinput.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "room.h"
|
||||
#include "actor.h"
|
||||
#include "m_game.h"
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace editor_bitmap
|
||||
{
|
||||
int edit_mode = EDITING_BITMAP_POS;
|
||||
draw::surface *surf = nullptr;
|
||||
|
||||
void init(int editing)
|
||||
{
|
||||
edit_mode = editing;
|
||||
draw::resetViewport();
|
||||
surf = draw::getSurface(actor::getSelected()->bmp);
|
||||
}
|
||||
|
||||
bool loop()
|
||||
{
|
||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
|
||||
|
||||
const int tx = (520-surf->w)/2;
|
||||
const int ty = (240-surf->h)/2;
|
||||
|
||||
draw::cls(PAPER);
|
||||
draw::setSource(surf);
|
||||
draw::color(BLUE);
|
||||
draw::setViewport(tx, ty, surf->w, surf->h);
|
||||
draw::fillrect(0, 0, surf->w, surf->h);
|
||||
draw::color(BLUE+LIGHT);
|
||||
int x=0, y=0;
|
||||
while(y*32<surf->h)
|
||||
{
|
||||
draw::fillrect(x, y*32, 32, 32);
|
||||
x+=64; if (x>=surf->w) { y++; x = (y%2==0) ? 0 : 32; }
|
||||
}
|
||||
|
||||
draw::resetViewport();
|
||||
draw::color(WHITE);
|
||||
draw::rect(((520-surf->w)/2)-1, ((240-surf->h)/2)-1, surf->w+2, surf->h+2);
|
||||
draw::draw((520-surf->w)/2, (240-surf->h)/2, surf->w, surf->h, 0, 0, 0);
|
||||
|
||||
draw::setViewport(tx, ty, surf->w, surf->h);
|
||||
draw::color(RED+LIGHT);
|
||||
draw::hline(0, actor::getSelected()->bmp_rect.y, surf->w);
|
||||
draw::vline(actor::getSelected()->bmp_rect.x, 0, surf->h);
|
||||
draw::color(YELLOW);
|
||||
draw::hline(0, actor::getSelected()->bmp_rect.y+actor::getSelected()->bmp_rect.h, surf->w);
|
||||
draw::vline(actor::getSelected()->bmp_rect.x+actor::getSelected()->bmp_rect.w, 0, surf->h);
|
||||
draw::resetViewport();
|
||||
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
source/m_editor_bitmap.h
Normal file
13
source/m_editor_bitmap.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#define EDITING_BITMAP_POS 0
|
||||
#define EDITING_BITMAP_SIZE 1
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace editor_bitmap
|
||||
{
|
||||
void init(int editing);
|
||||
bool loop();
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,22 @@ namespace modules
|
||||
const int x = input::mouseX()/80;
|
||||
const int y = input::mouseY()/80;
|
||||
const int selected = x+y*6;
|
||||
actor::actor_t* act = actor::getSelected();
|
||||
strcpy(act->bmp, gifs[selected].c_str());
|
||||
act->surface = draw::getSurface(gifs[selected]);
|
||||
return false;
|
||||
if (selected < gifs.size())
|
||||
{
|
||||
actor::actor_t* act = actor::getSelected();
|
||||
strcpy(act->bmp, gifs[selected].c_str());
|
||||
act->surface = draw::getSurface(gifs[selected]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int selected = -1;
|
||||
if (input::mouseBtn(1))
|
||||
{
|
||||
const int x = input::mouseX()/80;
|
||||
const int y = input::mouseY()/80;
|
||||
selected = x+y*6;
|
||||
if (selected >= gifs.size()) selected = -1;
|
||||
}
|
||||
|
||||
draw::cls(2);
|
||||
@@ -47,6 +59,16 @@ namespace modules
|
||||
bx++; if (bx>5) { bx=0; by++; }
|
||||
}
|
||||
|
||||
if (selected!=-1)
|
||||
{
|
||||
draw::surface *surf = draw::getSurface(gifs[selected].c_str());
|
||||
draw::setSource(surf);
|
||||
draw::color(PAPER);
|
||||
draw::fillrect(((520-surf->w)/2)-4, ((240-surf->h)/2)-4, surf->w+8, surf->h+8);
|
||||
draw::color(WHITE);
|
||||
draw::rect(((520-surf->w)/2)-2, ((240-surf->h)/2)-2, surf->w+4, surf->h+4);
|
||||
draw::draw((520-surf->w)/2, (240-surf->h)/2, surf->w, surf->h, 0, 0, 0);
|
||||
}
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -455,8 +455,8 @@ namespace modules
|
||||
|
||||
draw::setViewport(0, 15, 100, 222);
|
||||
|
||||
const int mx = draw::getLocalX(input::mouseX());
|
||||
const int my = draw::getLocalY(input::mouseY());
|
||||
int mx = draw::getLocalX(input::mouseX());
|
||||
int my = draw::getLocalY(input::mouseY());
|
||||
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
||||
const bool btnClk = input::mouseClk(1) || input::mouseClk(3);
|
||||
|
||||
@@ -571,6 +571,8 @@ namespace modules
|
||||
}
|
||||
|
||||
draw::setViewport(420, 15, 100, 225);
|
||||
mx = draw::getLocalX(input::mouseX());
|
||||
my = draw::getLocalY(input::mouseY());
|
||||
|
||||
bool changed = false;
|
||||
|
||||
@@ -727,10 +729,12 @@ namespace modules
|
||||
*/
|
||||
line+=10;
|
||||
ui::label("POS", 2, line, 48, 11);
|
||||
if (input::mouseClk(1) && mx>=2 && mx <=48 && my>=line && my<=line+10) return_value = GAME_EDITOR_BITMAP_POS;
|
||||
changed |= btn_small(49, line, act->bmp_rect.x, 0, 512, 25);
|
||||
changed |= btn_small(73, line, act->bmp_rect.y, 0, 512, 25);
|
||||
line+=10;
|
||||
ui::label("SIZE", 2, line, 48, 11);
|
||||
if (input::mouseClk(1) && mx>=2 && mx <=48 && my>=line && my<=line+10) return_value = GAME_EDITOR_BITMAP_SIZE;
|
||||
changed |= btn_small(49, line, act->bmp_rect.w, 0, 512, 25);
|
||||
changed |= btn_small(73, line, act->bmp_rect.h, 0, 512, 25);
|
||||
line+=10;
|
||||
|
||||
@@ -6,13 +6,15 @@ namespace modules
|
||||
{
|
||||
namespace game
|
||||
{
|
||||
#define GAME_NONE -1
|
||||
#define GAME_MENU 0
|
||||
#define GAME_DEAD 1
|
||||
#define GAME_EDITOR_MAP 2
|
||||
#define GAME_EDITOR_TEMPLATES 3
|
||||
#define GAME_EDITOR_COLORS 4
|
||||
#define GAME_NONE -1
|
||||
#define GAME_MENU 0
|
||||
#define GAME_DEAD 1
|
||||
#define GAME_EDITOR_MAP 2
|
||||
#define GAME_EDITOR_TEMPLATES 3
|
||||
#define GAME_EDITOR_COLORS 4
|
||||
#define GAME_EDITOR_BITMAP_FILE 5
|
||||
#define GAME_EDITOR_BITMAP_POS 6
|
||||
#define GAME_EDITOR_BITMAP_SIZE 7
|
||||
|
||||
void init();
|
||||
int loop();
|
||||
|
||||
@@ -23,19 +23,22 @@
|
||||
#include "m_editor_templates.h"
|
||||
#include "m_editor_colors.h"
|
||||
#include "m_editor_bitmap_file.h"
|
||||
#include "m_editor_bitmap.h"
|
||||
|
||||
#define M_LOGO 0
|
||||
#define M_MENU 1
|
||||
#define M_GAME 2
|
||||
#define M_INGAME 3
|
||||
#define M_GAMEOVER 4
|
||||
#define M_CATSLIFE 5
|
||||
#define M_MENU_TECLES 6
|
||||
#define M_MENU_AUDIO 7
|
||||
#define M_EDITOR_MAP 8
|
||||
#define M_EDITOR_TEMPLATES 9
|
||||
#define M_EDITOR_COLORS 10
|
||||
#define M_LOGO 0
|
||||
#define M_MENU 1
|
||||
#define M_GAME 2
|
||||
#define M_INGAME 3
|
||||
#define M_GAMEOVER 4
|
||||
#define M_CATSLIFE 5
|
||||
#define M_MENU_TECLES 6
|
||||
#define M_MENU_AUDIO 7
|
||||
#define M_EDITOR_MAP 8
|
||||
#define M_EDITOR_TEMPLATES 9
|
||||
#define M_EDITOR_COLORS 10
|
||||
#define M_EDITOR_BITMAP_FILE 11
|
||||
#define M_EDITOR_BITMAP 12
|
||||
|
||||
|
||||
int current_module = M_LOGO;
|
||||
int zoom = 3;
|
||||
@@ -150,6 +153,10 @@ bool game::loop()
|
||||
modules::editor_colors::init(); current_module = M_EDITOR_COLORS;
|
||||
} else if (option==GAME_EDITOR_BITMAP_FILE) {
|
||||
modules::editor_bitmap_file::init(); current_module = M_EDITOR_BITMAP_FILE;
|
||||
} else if (option==GAME_EDITOR_BITMAP_POS) {
|
||||
modules::editor_bitmap::init(EDITING_BITMAP_POS); current_module = M_EDITOR_BITMAP;
|
||||
} else if (option==GAME_EDITOR_BITMAP_SIZE) {
|
||||
modules::editor_bitmap::init(EDITING_BITMAP_SIZE); current_module = M_EDITOR_BITMAP;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -173,6 +180,11 @@ bool game::loop()
|
||||
current_module = M_GAME;
|
||||
}
|
||||
break;
|
||||
case M_EDITOR_BITMAP:
|
||||
if (!modules::editor_bitmap::loop()) {
|
||||
current_module = M_GAME;
|
||||
}
|
||||
break;
|
||||
case M_INGAME:
|
||||
option = modules::ingame::loop();
|
||||
if (option != INGAME_NONE) {
|
||||
|
||||
Reference in New Issue
Block a user