Mercurial > molko
comparison libmlk-adventure/adventure/state/continue.c @ 281:87b8c7510717
rpg: implement load/save for characters
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 20 Dec 2020 10:55:53 +0100 |
parents | |
children | a15f77eda9a4 |
comparison
equal
deleted
inserted
replaced
280:11c824a82e63 | 281:87b8c7510717 |
---|---|
1 /* | |
2 * continue.c -- select save to continue the game | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <core/alloc.h> | |
20 #include <core/event.h> | |
21 #include <core/game.h> | |
22 #include <core/painter.h> | |
23 #include <core/state.h> | |
24 | |
25 #include <adventure/dialog/save.h> | |
26 | |
27 #include "mainmenu.h" | |
28 #include "continue.h" | |
29 | |
30 struct self { | |
31 struct state state; | |
32 struct dialog_save dialog; | |
33 }; | |
34 | |
35 static void | |
36 start(struct state *state) | |
37 { | |
38 struct self *self = state->data; | |
39 | |
40 dialog_save_init(&self->dialog); | |
41 } | |
42 | |
43 static void | |
44 handle(struct state *state, const union event *ev) | |
45 { | |
46 struct self *self = state->data; | |
47 bool selected = false; | |
48 | |
49 switch (ev->type) { | |
50 case EVENT_QUIT: | |
51 game_quit(); | |
52 break; | |
53 case EVENT_KEYDOWN: | |
54 if (ev->key.key == KEY_ESCAPE) | |
55 game_switch(mainmenu_state_new(), false); | |
56 else | |
57 selected = dialog_save_handle(&self->dialog, ev); | |
58 break; | |
59 default: | |
60 selected = dialog_save_handle(&self->dialog, ev); | |
61 break; | |
62 } | |
63 | |
64 if (selected) | |
65 game_quit(); | |
66 } | |
67 | |
68 static void | |
69 update(struct state *state, unsigned int ticks) | |
70 { | |
71 struct self *self = state->data; | |
72 | |
73 dialog_save_update(&self->dialog, ticks); | |
74 } | |
75 | |
76 static void | |
77 draw(struct state *state) | |
78 { | |
79 struct self *self = state->data; | |
80 | |
81 painter_set_color(0xffffffff); | |
82 painter_clear(); | |
83 dialog_save_draw(&self->dialog); | |
84 painter_present(); | |
85 } | |
86 | |
87 static void | |
88 finish(struct state *state) | |
89 { | |
90 struct self *self = state->data; | |
91 | |
92 dialog_save_finish(&self->dialog); | |
93 } | |
94 | |
95 struct state * | |
96 continue_state_new(void) | |
97 { | |
98 struct self *self; | |
99 | |
100 self = alloc_new0(sizeof (*self)); | |
101 self->state.data = self; | |
102 self->state.start = start; | |
103 self->state.handle = handle; | |
104 self->state.update = update; | |
105 self->state.draw = draw; | |
106 self->state.finish = finish; | |
107 | |
108 return &self->state; | |
109 } |