Skip to content

Commit 2919409

Browse files
committed
creature editing is like done??? yeah
1 parent 12203f7 commit 2919409

8 files changed

Lines changed: 1320 additions & 306 deletions

File tree

Creature.cpp

Lines changed: 351 additions & 44 deletions
Large diffs are not rendered by default.

Creature.h

Lines changed: 550 additions & 144 deletions
Large diffs are not rendered by default.

CreatureEdit.cpp

Lines changed: 385 additions & 101 deletions
Large diffs are not rendered by default.

CreatureList.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,27 @@ void displayCreatures(void* s) {
5454
ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(0, 0),
5555
ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_AutoResizeX);
5656
const auto& creature = state->page.creatures[i];
57-
ImGui::Text("%s", creature.get_name().value().c_str());
58-
ImGui::Text("AC: %s, HP: %s", creature.get_armor_class().value().c_str(),
59-
creature.get_hit_points().value().c_str());
60-
ImGui::Text("Challenge: %s", creature.get_challenge().value().c_str());
61-
if (ImGui::Button("Edit")) {
62-
state->clear_image = true;
63-
state->current_creature = creature;
64-
// Focus on the edit tab
65-
ImGui::SetWindowFocus("Creature Edit");
66-
}
57+
ImGui::Text("%s (%s)", creature.get_name().value().c_str(),
58+
creature.original_list.c_str());
59+
ImGui::Text("AC: %d, HP: %d (%s)", creature.get_ac().value(),
60+
creature.get_max_hit_points(),
61+
creature.get_hit_dice().value().c_str());
6762
if (state->encounter_planner) {
63+
if (ImGui::Button("Edit")) {
64+
state->clear_image = true;
65+
state->current_creature = creature;
66+
// Focus on the edit tab
67+
ImGui::SetWindowFocus("Creature Edit");
68+
}
6869
ImGui::SameLine();
6970
ImGui::Button("Add");
71+
} else if (state->encounter_battler) {
72+
if (ImGui::Button("View")) {
73+
state->clear_image = true;
74+
state->current_creature = creature;
75+
// Focus on the view tab
76+
ImGui::SetWindowFocus("Creature View");
77+
}
7078
}
7179
if (i < state->page.creatures.size() - 1) {
7280
ImGui::Separator();

EncounterMaster.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
#include "Menu.h"
1313

14+
static const char* _IMGUIGetClipboardText(void *) { return SDL_GetClipboardText(); }
15+
16+
static void _IMGUISetClipboardText(void *, const char *text) { SDL_SetClipboardText(text); }
17+
1418
bool doCreaturesExist()
1519
{
1620
// Check `creatures/` directory for any .json files
@@ -85,6 +89,8 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
8589
ImGui::CreateContext();
8690
ImGuiIO& io = ImGui::GetIO();
8791
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
92+
io.SetClipboardTextFn = _IMGUISetClipboardText;
93+
io.GetClipboardTextFn = _IMGUIGetClipboardText;
8894
ImGui::StyleColorsDark();
8995

9096
ImGui_ImplSDL3_InitForSDLRenderer(state->window, state->renderer);

Menu.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ void menuDraw(ToolState* state) {
5656
}
5757
});
5858
}
59-
ImGui::Separator();
60-
if (ImGui::MenuItem("Create New", "Ctrl-Shift-N"))
61-
{
62-
59+
if (ImGui::MenuItem("Reload Creatures")) {
60+
state->creatures = parse_creatures_from_directory("creatures");
61+
state->filtered_creatures.clear();
62+
state->creature_page = 0;
63+
state->creature_selected_index = -1;
64+
state->page.creatures.clear();
6365
}
6466
ImGui::EndMenu();
6567
}
@@ -87,7 +89,9 @@ void menuDraw(ToolState* state) {
8789

8890
std::regex filter_regex(state->creature_filter,
8991
std::regex_constants::icase);
90-
if (std::regex_search(creature.get_name().value(), filter_regex)) {
92+
if (std::regex_search(
93+
creature.get_name().value() + " (" + creature.original_list + ")",
94+
filter_regex)) {
9195
state->filtered_creatures.push_back(creature);
9296
}
9397
}

Menu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct ToolState {
3636
bool image_error = false;
3737
SDL_Texture* current_creature_texture = nullptr;
3838

39-
4039
// Creatures in progress of being added/edited
4140
std::vector<dnd::Creature> working_creatures;
4241

creature_mirrors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://thekade.net/mirrors/dnd/tkfu-dnd-creatures-5e-mini.json
1+
https://thekade.net/mirrors/dnd/dnd-5e-creature.json

0 commit comments

Comments
 (0)