-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathantis.c
140 lines (119 loc) · 4.72 KB
/
antis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <input/input.h>
#include <stdlib.h>
#include "antis_icons.h"
#include "dolphin_state.h"
#include "saved_struct.h"
#include <power/power_service/power.h>
#include "tinyfont.h"
const char* funnyText[] =
{"\"Stop poking my brain\"",
"\"You're a terrible owner\"",
"\"I'll remember this!\"",
"\"This really isnt ok\"",
"\"Just feed me RFID cards!\"",
"\"Forget to charge me too?\"",
"\"Asshole...\""};
int funnyTextIndex = 0;
DolphinState* stateLocal = 0;
char strButthurt[16];
char strXp[16];
int btnIndex = 0;
int yOffset = 9;
static void draw_callback(Canvas* canvas, void* ctx) {
UNUSED(ctx);
//graphics
canvas_clear(canvas);
canvas_draw_frame(canvas, 0, 0, 128, 64);
canvas_draw_icon(canvas, 3, 3 + yOffset, &I_passport_bad1_46x49);
if(btnIndex == 0){ canvas_draw_icon(canvas, 120, 19 + yOffset, &I_ButtonLeftSmall_3x5); }
else if(btnIndex == 1){ canvas_draw_icon(canvas, 120, 29 + yOffset, &I_ButtonLeftSmall_3x5); }
//strings
canvas_set_custom_u8g2_font(canvas, u8g2_font_5x7_tf);
canvas_draw_str(canvas, 3, 9, funnyText[funnyTextIndex]);
canvas_set_font(canvas, FontSecondary);
snprintf(strButthurt, 16, "Butthurt: %lu", stateLocal->data.butthurt);
snprintf(strXp, 16, "XP: %lu", stateLocal->data.icounter);
canvas_draw_str(canvas, 51, 25 + yOffset, strButthurt);
canvas_draw_str(canvas, 51, 35 + yOffset, strXp);
//save button
if(btnIndex == 2){
canvas_draw_rbox(canvas, 51, 37 + yOffset, 74, 15, 3);
canvas_invert_color(canvas);
canvas_draw_str_aligned(canvas, 88, 45 + yOffset, AlignCenter, AlignCenter, "Save & Reboot");
canvas_invert_color(canvas);
canvas_draw_rframe(canvas, 51, 37 + yOffset, 74, 15, 3);
}
else{
canvas_invert_color(canvas);
canvas_draw_rbox(canvas, 51, 37 + yOffset, 74, 15, 3);
canvas_invert_color(canvas);
canvas_draw_str_aligned(canvas, 88, 45 + yOffset, AlignCenter, AlignCenter, "Save & Reboot");
canvas_draw_rframe(canvas, 51, 37 + yOffset, 74, 15, 3);
}
}
static void input_callback(InputEvent* input_event, void* ctx) {
furi_assert(ctx);
FuriMessageQueue* event_queue = ctx;
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
}
int32_t bigsad_app(void* p) {
UNUSED(p);
InputEvent event;
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, draw_callback, NULL);
view_port_input_callback_set(view_port, input_callback, event_queue);
Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
funnyTextIndex = rand() % 7;
stateLocal = malloc(sizeof(DolphinState));
bool running = true;
bool success = saved_struct_load("/int/.dolphin.state", &stateLocal->data, sizeof(DolphinStoreData), 0xD0, 0x01);
if(!success){ running = false; }
view_port_update(view_port);
while(running) {
furi_check(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk);
view_port_update(view_port);
if(event.type == InputTypePress){
if(event.key == InputKeyOk && btnIndex == 2) {
bool result = saved_struct_save("/int/.dolphin.state", &stateLocal->data, sizeof(DolphinStoreData), 0xD0, 0x01);
if(result){
furi_delay_ms(100);
furi_hal_power_reset();
running = false;
return 0;
}
}
if(event.key == InputKeyUp) {
if(btnIndex == 0){ btnIndex = 2; }
else{ btnIndex--; }
}
if(event.key == InputKeyDown) {
if(btnIndex == 2){ btnIndex = 0; }
else{ btnIndex++; }
}
if(event.key == InputKeyRight){
if(btnIndex == 0 && stateLocal->data.butthurt < 14){ stateLocal->data.butthurt++; }
else if(btnIndex == 1){ stateLocal->data.icounter += 10; }
}
if(event.key == InputKeyLeft){
if(btnIndex == 0 && stateLocal->data.butthurt > 0){ stateLocal->data.butthurt--; }
else if(btnIndex == 1){
if(stateLocal->data.icounter < 10){ stateLocal->data.icounter = 0; }
else{ stateLocal->data.icounter -= 10; }
}
}
if(event.key == InputKeyBack) {
running = false;
}
}
}
furi_message_queue_free(event_queue);
gui_remove_view_port(gui, view_port);
view_port_free(view_port);
furi_record_close(RECORD_GUI);
return 0;
}