Skip to content

Commit 13cb82a

Browse files
authored
Map edit hotkeys to rotate ab object and cycle through its frames (exult#636)
* Fix exult#622
1 parent 667ad64 commit 13cb82a

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

cheat.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,46 @@ void Cheat::move_selected(int dx, int dy, int dz) {
742742
}
743743
}
744744

745+
/*
746+
* Cycle the frame of the selected objects.
747+
*/
748+
void Cheat::cycle_selected_frame(int direction) {
749+
if (selected.empty()) {
750+
return;
751+
}
752+
for (auto& it : selected) {
753+
Game_object* obj = it.get();
754+
int maxFrames = obj->get_num_frames();
755+
int currentFrame = obj->get_framenum();
756+
int newFrame = currentFrame + direction;
757+
758+
if (newFrame >= maxFrames) {
759+
newFrame = 0;
760+
} else if (newFrame < 0) {
761+
newFrame = maxFrames - 1;
762+
}
763+
764+
obj->change_frame(newFrame);
765+
gwin->add_dirty(obj);
766+
}
767+
gwin->set_all_dirty();
768+
}
769+
770+
/*
771+
* Rotate the frame of the selected objects.
772+
*/
773+
void Cheat::rotate_selected_frame() {
774+
if (selected.empty()) {
775+
return;
776+
}
777+
for (auto& it : selected) {
778+
Game_object* obj = it.get();
779+
obj->change_frame(obj->get_rotated_frame(1));
780+
gwin->add_dirty(obj);
781+
}
782+
gwin->set_all_dirty();
783+
}
784+
745785
bool Cheat::is_selected(Game_object* o) {
746786
for (auto& it : selected) {
747787
if (o == it.get()) {

cheat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class Cheat : public Game_singletons {
205205
void delete_selected();
206206
void move_selected_objs(int dx, int dy, int dz);
207207
void move_selected(int dx, int dy, int dz);
208+
void cycle_selected_frame(int direction);
209+
void rotate_selected_frame();
208210

209211
const std::vector<Game_object_shared>& get_selected() const {
210212
return selected;

data/bg/defaultkeys.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Ctrl-pagedown move_selected 0 0 -1
5050
Ctrl-C copy
5151
Ctrl-x cut
5252
Ctrl-v paste
53+
Ctrl-KP+ cycle_frames_next 1
54+
Ctrl-KP- cycle_frames_prev -1
55+
CTRL-KP* rotate_frames
5356

5457
F2 cheat_screen
5558
F3 map_teleport

data/si/defaultkeys.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Ctrl-pagedown move_selected 0 0 -1
5050
Ctrl-C copy
5151
Ctrl-x cut
5252
Ctrl-v paste
53+
Ctrl-KP+ cycle_frames_next 1
54+
Ctrl-KP- cycle_frames_prev -1
55+
CTRL-KP* rotate_frames
5356

5457
F2 cheat_screen
5558
F3 map_teleport

keyactions.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,15 @@ void ActionMoveSelected(const int* params) {
692692
cheat.move_selected(params[0], params[1], params[2]);
693693
}
694694

695+
void ActionCycleFrames(const int* params) {
696+
cheat.cycle_selected_frame(params[0]);
697+
}
698+
699+
void ActionRotateFrames(const int* params) {
700+
ignore_unused_variable_warning(params);
701+
cheat.rotate_selected_frame();
702+
}
703+
695704
// { ActionToggleEggs, 0, "Toggle egg display", cheat_keys, NONE },
696705
void ActionToggleEggs(const int* params) {
697706
ignore_unused_variable_warning(params);

keyactions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void ActionCreateShape(const int* params);
7575
void ActionDeleteObject(const int* params);
7676
void ActionDeleteSelected(const int* params);
7777
void ActionMoveSelected(const int* params);
78+
void ActionCycleFrames(const int* params);
79+
void ActionRotateFrames(const int* params);
7880
void ActionToggleEggs(const int* params);
7981
void ActionGodMode(const int* params);
8082
void ActionGender(const int* params);

keys.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ const struct Action {
263263
Action::mapedit_keys, NONE, true, true, true, false},
264264
{ "MOVE_SELECTED", ActionMoveSelected, nullptr, "Move selected",
265265
Action::mapedit_keys, NONE, true, true, true, false},
266+
{ "CYCLE_FRAMES_NEXT", ActionCycleFrames, nullptr, "Cycle frames next",
267+
Action::mapedit_keys, NONE, true, true, true, false},
268+
{ "CYCLE_FRAMES_PREV", ActionCycleFrames, nullptr, "Cycle frames previus",
269+
Action::mapedit_keys, NONE, true, true, true, false},
270+
{ "ROTATE_FRAMES", ActionRotateFrames, nullptr, "Rotate frames",
271+
Action::mapedit_keys, NONE, true, true, true, false},
266272
{ "WRITE_MINIMAP", ActionWriteMiniMap, nullptr, "Write minimap",
267273
Action::mapedit_keys, NONE, false, true, true, false},
268274
{ "REPAINT", ActionRepaint, nullptr, "Repaint screen", Action::dont_show,

0 commit comments

Comments
 (0)