From b59e5fc0787079d49c90ee6ede0e1ffd054258f9 Mon Sep 17 00:00:00 2001
From: Dylan G <1565516+Helloman892@users.noreply.github.com>
Date: Sun, 10 Dec 2017 23:55:55 +0000
Subject: [PATCH] Ask for confirmation before deletion from SD (#113)
* added awful way to confirm deletion
* improve solution for asking for confirmation
based on throw_error
* fix COLOR_WHITE evaluating to -1 (outside the u32 range)
* add confirmation for splash deletion
---
include/colors.h | 43 ++++++++++++++++++++++++++++++++++++++++++
include/draw.h | 4 +++-
include/instructions.h | 2 ++
source/draw.c | 32 ++++++++++++++++++++-----------
source/main.c | 16 +++++++++++-----
5 files changed, 80 insertions(+), 17 deletions(-)
create mode 100644 include/colors.h
diff --git a/include/colors.h b/include/colors.h
new file mode 100644
index 0000000..a48cbeb
--- /dev/null
+++ b/include/colors.h
@@ -0,0 +1,43 @@
+/*
+* This file is part of Anemone3DS
+* Copyright (C) 2016-2017 Alex Taber ("astronautlevel"), Dawid Eckert ("daedreth")
+*
+* 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 .
+*
+* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
+* * Requiring preservation of specified reasonable legal notices or
+* author attributions in that material or in the Appropriate Legal
+* Notices displayed by works containing it.
+* * Prohibiting misrepresentation of the origin of that material,
+* or requiring that modified versions of such material be marked in
+* reasonable ways as different from the original version.
+*/
+
+#ifndef COLORS_H
+#define COLORS_H
+
+#define ABGR8(a, b, g, r) ((((a)&0xFF)<<0) | (((b)&0xFF)<<8) | (((g)&0xFF)<<16) | (((r)&0xFF)<<24))
+#define RGBA8(r, g, b, a) ((((r)&0xFF)<<0) | (((g)&0xFF)<<8) | (((b)&0xFF)<<16) | (((a)&0xFF)<<24))
+
+typedef enum {
+ COLOR_BACKGROUND = ABGR8(255, 32, 28, 35), //silver-y black
+ COLOR_ACCENT = RGBA8(55, 122, 168, 255),
+ COLOR_WHITE = RGBA8(255, 255, 255, 255),
+ COLOR_CURSOR = RGBA8(200, 200, 200, 255),
+ COLOR_BLACK = RGBA8(0, 0, 0, 255),
+ COLOR_RED = RGBA8(200, 0, 0, 255),
+ COLOR_YELLOW = RGBA8(239, 220, 11, 255),
+} Color;
+
+#endif
diff --git a/include/draw.h b/include/draw.h
index b7d9919..96ceac7 100644
--- a/include/draw.h
+++ b/include/draw.h
@@ -29,6 +29,7 @@
#include "common.h"
#include "loading.h"
+#include "colors.h"
typedef enum {
INSTALL_SPLASH,
@@ -67,14 +68,15 @@ enum {
typedef struct {
const wchar_t * info_line;
+ Color info_line_color;
const wchar_t * instructions[BUTTONS_INFO_LINES][BUTTONS_INFO_COLUNMNS];
} Instructions_s;
void init_screens(void);
void exit_screens(void);
-void draw_themext_error(void);
void throw_error(char* error, ErrorLevel level);
+bool draw_confirm(const char* conf_msg, Entry_List_s* list, EntryMode current_mode);
void draw_preview(int preview_offset);
diff --git a/include/instructions.h b/include/instructions.h
index 37876c2..39bae9a 100644
--- a/include/instructions.h
+++ b/include/instructions.h
@@ -28,6 +28,7 @@
#define INSTRUCTIONS_H
#include "draw.h"
+#include "colors.h"
Instructions_s normal_instructions[MODE_AMOUNT] = {
{
@@ -76,6 +77,7 @@ Instructions_s normal_instructions[MODE_AMOUNT] = {
Instructions_s install_instructions = {
.info_line = L"Release \uE000 to cancel or hold \uE006 and release \uE000 to install",
+ .info_line_color = COLOR_WHITE,
.instructions = {
{
L"\uE079 Normal install",
diff --git a/source/draw.c b/source/draw.c
index ce95425..49a6f5e 100644
--- a/source/draw.c
+++ b/source/draw.c
@@ -26,21 +26,12 @@
#include "draw.h"
#include "unicode.h"
+#include "colors.h"
#include "pp2d/pp2d/pp2d.h"
#include
-enum Colors {
- COLOR_BACKGROUND = ABGR8(255, 32, 28, 35), //silver-y black
- COLOR_ACCENT = RGBA8(55, 122, 168, 255),
- COLOR_WHITE = RGBA8(255, 255, 255, 255),
- COLOR_CURSOR = RGBA8(200, 200, 200, 255),
- COLOR_BLACK = RGBA8(0, 0, 0, 255),
- COLOR_RED = RGBA8(200, 0, 0, 255),
- COLOR_YELLOW = RGBA8(239, 220, 11, 255),
-};
-
void init_screens(void)
{
pp2d_init();
@@ -153,6 +144,25 @@ void throw_error(char* error, ErrorLevel level)
}
}
+bool draw_confirm(const char* conf_msg, Entry_List_s* list, EntryMode current_mode)
+{
+ while(aptMainLoop())
+ {
+ draw_interface(list, current_mode);
+ pp2d_draw_on(GFX_TOP, GFX_LEFT);
+ draw_text_center(GFX_TOP, BUTTONS_Y_LINE_1, 0.7, 0.7, COLOR_YELLOW, conf_msg);
+ pp2d_draw_wtext_center(GFX_TOP, BUTTONS_Y_LINE_3, 0.6, 0.6, COLOR_WHITE, L"\uE000 Yes \uE001 No");
+ pp2d_end_draw();
+
+ hidScanInput();
+ u32 kDown = hidKeysDown();
+ if(kDown & KEY_A) return true;
+ if(kDown & KEY_B) return false;
+ }
+
+ return false;
+}
+
void draw_preview(int preview_offset)
{
pp2d_begin_draw(GFX_TOP, GFX_LEFT);
@@ -201,7 +211,7 @@ void draw_instructions(Instructions_s instructions)
pp2d_draw_on(GFX_TOP, GFX_LEFT);
if(instructions.info_line != NULL)
- pp2d_draw_wtext_center(GFX_TOP, BUTTONS_Y_INFO, 0.55, 0.55, COLOR_WHITE, instructions.info_line);
+ pp2d_draw_wtext_center(GFX_TOP, BUTTONS_Y_INFO, 0.55, 0.55, instructions.info_line_color, instructions.info_line);
const int y_lines[BUTTONS_INFO_LINES-1] = {
BUTTONS_Y_LINE_1,
diff --git a/source/main.c b/source/main.c
index 15c9606..5490ad9 100644
--- a/source/main.c
+++ b/source/main.c
@@ -295,8 +295,11 @@ int main(void)
current_entry->in_shuffle = !current_entry->in_shuffle;
break;
case MODE_SPLASHES:
- draw_install(INSTALL_SPLASH_DELETE);
- splash_delete();
+ if(draw_confirm("Are you sure you would like to delete\nthe installed splash?", current_list, current_mode))
+ {
+ draw_install(INSTALL_SPLASH_DELETE);
+ splash_delete();
+ }
break;
default:
break;
@@ -316,9 +319,12 @@ int main(void)
}
else if(kDown & KEY_SELECT)
{
- draw_install(INSTALL_ENTRY_DELETE);
- delete_entry(*current_entry);
- load_lists(lists);
+ if(draw_confirm("Are you sure you would like to delete this?", current_list, current_mode))
+ {
+ draw_install(INSTALL_ENTRY_DELETE);
+ delete_entry(*current_entry);
+ load_lists(lists);
+ }
}
// Movement in the UI