2018-08-20 14:30:31 +02:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-21 22:27:45 +02:00
|
|
|
#include <string.h>
|
2018-08-20 14:30:31 +02:00
|
|
|
#include "tooltip.h"
|
|
|
|
#include "gui_util.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "gui.h"
|
2018-10-05 13:08:38 +02:00
|
|
|
#include "texturecache.h"
|
|
|
|
|
2018-10-11 20:12:11 +02:00
|
|
|
static Uint8 controller_mode = 0;
|
2018-10-10 22:38:54 +02:00
|
|
|
|
2018-10-05 13:08:38 +02:00
|
|
|
static bool
|
|
|
|
render_button_texture_for(const char *text, Position pos, Camera *cam)
|
|
|
|
{
|
2018-10-10 22:38:54 +02:00
|
|
|
if (!controller_mode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-10 22:34:41 +02:00
|
|
|
Texture *t = texturecache_add("Extras/Controller.png");
|
|
|
|
SDL_Rect clip;
|
2018-10-05 13:08:38 +02:00
|
|
|
if (strcmp(text, "1") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CONTROLLER_BTN(0, controller_mode);
|
2018-10-09 14:19:59 +02:00
|
|
|
} else if (strcmp(text, "2") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CONTROLLER_BTN(16, controller_mode);
|
2018-10-10 22:34:41 +02:00
|
|
|
} else if (strcmp(text, "3") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CONTROLLER_BTN(32, controller_mode);
|
2018-10-10 22:34:41 +02:00
|
|
|
} else if (strcmp(text, "4") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CONTROLLER_BTN(48, controller_mode);
|
2018-10-10 22:34:41 +02:00
|
|
|
} else if (strcmp(text, "5") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CONTROLLER_BUMPER(32, controller_mode);
|
2018-10-10 22:34:41 +02:00
|
|
|
} else if (strcmp(text, "ESC") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CONTROLLER_OPT(32, controller_mode);
|
|
|
|
} else if (strcmp(text, "ENTER") == 0) {
|
|
|
|
clip = CONTROLLER_OPT(0, controller_mode);
|
2018-10-10 22:34:41 +02:00
|
|
|
} else if (strcmp(text, "SPACE") == 0) {
|
2018-10-11 20:12:11 +02:00
|
|
|
clip = CLIP16(0, 80);
|
2018-10-05 13:08:38 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-09 14:19:59 +02:00
|
|
|
SDL_Rect renderBox = { pos.x, pos.y, 16, 16 };
|
2018-10-05 13:08:38 +02:00
|
|
|
texture_render_clip(t, &renderBox, &clip, cam);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_texture_for(Texture *text,
|
|
|
|
char *content,
|
|
|
|
SDL_Rect *renderBox,
|
|
|
|
SDL_Renderer *renderer)
|
|
|
|
{
|
|
|
|
texture_load_from_text(text,
|
|
|
|
content,
|
|
|
|
C_WHITE,
|
|
|
|
C_WHITE,
|
|
|
|
renderer);
|
|
|
|
|
|
|
|
renderBox->w = text->dim.width;
|
|
|
|
renderBox->h = text->dim.height;
|
|
|
|
}
|
2018-08-20 14:30:31 +02:00
|
|
|
|
|
|
|
Sprite *
|
|
|
|
tooltip_create(char **content, Camera *cam)
|
|
|
|
{
|
|
|
|
int rowCount = 0;
|
|
|
|
char **contentIndex = content;
|
|
|
|
while (*contentIndex) {
|
|
|
|
rowCount++;
|
|
|
|
contentIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite *sprite = gui_util_create_tooltip_frame_sprite(BOTTOM_GUI_WIDTH/16 - 6,
|
2018-10-24 22:24:53 +02:00
|
|
|
(Uint32) ((rowCount * 8 + 48)/16),
|
2018-08-20 14:30:31 +02:00
|
|
|
cam);
|
|
|
|
sprite->pos.x = 48;
|
2018-10-09 14:19:59 +02:00
|
|
|
sprite->pos.y = 48;
|
2018-08-20 14:30:31 +02:00
|
|
|
Texture *texture = sprite->textures[0];
|
|
|
|
Texture *text = texture_create();
|
|
|
|
texture_load_font(text, "GUI/SDS_8x8.ttf", LOG_FONT_SIZE, 0);
|
|
|
|
SDL_SetRenderTarget(cam->renderer, texture->texture);
|
|
|
|
SDL_Rect renderBox = { 16, 16, 0, 0 };
|
|
|
|
|
|
|
|
while (*content) {
|
|
|
|
if (strlen(*content) > 0) {
|
2018-10-09 14:19:59 +02:00
|
|
|
if (render_button_texture_for(*content, POS(renderBox.x, renderBox.y - 4), cam)) {
|
2018-10-10 22:34:41 +02:00
|
|
|
renderBox.x += 16;
|
2018-10-09 14:19:59 +02:00
|
|
|
} else {
|
2018-10-05 13:08:38 +02:00
|
|
|
load_texture_for(text, *content, &renderBox, cam->renderer);
|
|
|
|
texture_render(text, &renderBox, cam);
|
2018-10-09 14:19:59 +02:00
|
|
|
renderBox.x += text->dim.width;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
renderBox.x = 16;
|
|
|
|
renderBox.y += 14;
|
2018-08-20 14:30:31 +02:00
|
|
|
}
|
|
|
|
content++;
|
|
|
|
}
|
|
|
|
SDL_SetRenderTarget(cam->renderer, NULL);
|
|
|
|
texture_destroy(text);
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
}
|
2018-10-10 22:38:54 +02:00
|
|
|
|
|
|
|
void
|
2018-10-11 20:12:11 +02:00
|
|
|
tooltip_set_controller_mode(Uint8 ctrl_mode)
|
2018-10-10 22:38:54 +02:00
|
|
|
{
|
|
|
|
controller_mode = ctrl_mode;
|
|
|
|
}
|