Docs, is-named bool functions and MSVC utf-8
This commit is contained in:
1 parent
1a0db1abbd
commit
1cf4d1ea85
18 files changed
+443
-586
No files matched your search
+10
-10
@@ -121,11 +121,12 @@ static void animations_parse(object list, std::vector<Anm2Animation>& animations
|
||||
}
|
||||
}
|
||||
|
||||
bool Anm2::load(const std::string& path, Renderer& renderer, Audio& audio)
|
||||
void Anm2::load(const std::string& path, Renderer& renderer, Audio& audio)
|
||||
{
|
||||
Json json;
|
||||
if (!json.load(path))
|
||||
return false;
|
||||
json.load(path);
|
||||
if (!json.isValid)
|
||||
return;
|
||||
object root = json.root;
|
||||
std::string folder = path.substr(0, path.find_last_of('/') + 1);
|
||||
fps = json_float(json_object(root, "info"), "fps", fps);
|
||||
@@ -174,7 +175,6 @@ bool Anm2::load(const std::string& path, Renderer& renderer, Audio& audio)
|
||||
|
||||
animations_parse(json_object(root, "animations"), animations, sheetRegions, layerSheets);
|
||||
defaultAnimation = std::max(0, animation_get(json_string(root, "defaultAnimation")));
|
||||
return !animations.empty();
|
||||
}
|
||||
|
||||
static int name_get(const std::vector<std::string>& names, const std::string& name)
|
||||
@@ -394,12 +394,12 @@ static Affine root_affine_get(const Anm2Frame& frame, Vec2 position = {})
|
||||
}
|
||||
|
||||
// The transform, tint and color offset a group (and its parents) give its items, or false if any is hidden.
|
||||
bool Actor::group_get(Anm2Animation& current, int group, float frameTime, Affine& model, Color& tint, Color& offset)
|
||||
bool Actor::is_group_visible(Anm2Animation& current, int group, float frameTime, Affine& model, Color& tint, Color& offset)
|
||||
{
|
||||
if (group < 0 || group >= (int)current.groups.size())
|
||||
return true;
|
||||
Anm2Group& entry = current.groups[group];
|
||||
if (!group_get(current, entry.parent, frameTime, model, tint, offset) || !entry.isVisible)
|
||||
if (!is_group_visible(current, entry.parent, frameTime, model, tint, offset) || !entry.isVisible)
|
||||
return false;
|
||||
if (entry.root.empty())
|
||||
return true;
|
||||
@@ -427,7 +427,7 @@ void Actor::render(Renderer& renderer, Affine view)
|
||||
Affine model = rootModel;
|
||||
Color tint = root.tint;
|
||||
Color offset = root.offset;
|
||||
if (!layer.isVisible || !group_get(*current, layer.group, time, model, tint, offset))
|
||||
if (!layer.isVisible || !is_group_visible(*current, layer.group, time, model, tint, offset))
|
||||
continue;
|
||||
Anm2Frame frame = frame_get(layer.frames, time, TARGET_LAYER, layer.id);
|
||||
int sheet = layer.id >= 0 && layer.id < (int)anm2->layerSheets.size() ? anm2->layerSheets[layer.id] : -1;
|
||||
@@ -448,7 +448,7 @@ void Actor::render(Renderer& renderer, Affine view)
|
||||
Color tint;
|
||||
Color offset;
|
||||
Anm2Frame frame = frame_get(null.frames, time, TARGET_NULL, null.id);
|
||||
if (null.isVisible && frame.isVisible && group_get(*current, null.group, time, model, tint, offset))
|
||||
if (null.isVisible && frame.isVisible && is_group_visible(*current, null.group, time, model, tint, offset))
|
||||
renderer.outline_draw(model * null_affine_get(frame), frame.scale.x, frame.scale.y, NULL_COLOR);
|
||||
}
|
||||
}
|
||||
@@ -468,7 +468,7 @@ Rect Actor::null_rect_get(int null, int index, float frameTime)
|
||||
Color tint;
|
||||
Color offset;
|
||||
Anm2Frame frame = frame_get(item.frames, frameTime, TARGET_NULL, null);
|
||||
if (!frame.isVisible || !group_get(*current, item.group, frameTime, model, tint, offset))
|
||||
if (!frame.isVisible || !is_group_visible(*current, item.group, frameTime, model, tint, offset))
|
||||
break;
|
||||
return affine_bounds(model * null_affine_get(frame), frame.scale.x, frame.scale.y);
|
||||
}
|
||||
@@ -492,7 +492,7 @@ Rect Actor::bounds_get()
|
||||
Color offset;
|
||||
Anm2Frame frame = frame_get(layer.frames, (float)frameTime, TARGET_LAYER, layer.id);
|
||||
if (!layer.isVisible || !frame.isVisible || frame.size.x <= 0 ||
|
||||
!group_get(*current, layer.group, (float)frameTime, model, tint, offset))
|
||||
!is_group_visible(*current, layer.group, (float)frameTime, model, tint, offset))
|
||||
continue;
|
||||
model = model * affine_get(frame.position, frame.rotation, frame.scale / PERCENT, frame.pivot);
|
||||
bounds = rect_merge(bounds, affine_bounds(model, frame.size.x, frame.size.y));
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ public:
|
||||
float fps = 30;
|
||||
int defaultAnimation = -1;
|
||||
|
||||
bool load(const std::string& path, Renderer& renderer, Audio& audio);
|
||||
void load(const std::string& path, Renderer& renderer, Audio& audio);
|
||||
int animation_get(const std::string& name) const;
|
||||
int event_get(const std::string& name) const;
|
||||
int layer_get(const std::string& name) const;
|
||||
@@ -178,5 +178,5 @@ public:
|
||||
|
||||
private:
|
||||
void request_apply(const Request& request);
|
||||
bool group_get(Anm2Animation& animation, int group, float frameTime, Affine& model, Color& tint, Color& offset);
|
||||
bool is_group_visible(Anm2Animation& animation, int group, float frameTime, Affine& model, Color& tint, Color& offset);
|
||||
};
|
||||
+16
-9
@@ -51,11 +51,12 @@ Entry* Dialogue::hook_get(const std::string& hook)
|
||||
return entry ? entry : entry_get(found->second);
|
||||
}
|
||||
|
||||
bool Character::preview_load(const std::string& path, Renderer& renderer)
|
||||
void Character::preview_load(const std::string& path, Renderer& renderer)
|
||||
{
|
||||
Json json;
|
||||
if (!json.load(path + "character.json"))
|
||||
return false;
|
||||
json.load(path + "character.json");
|
||||
if (!(isValid = json.isValid))
|
||||
return;
|
||||
object root = json.root;
|
||||
folder = path;
|
||||
key = path.substr(0, path.size() - 1);
|
||||
@@ -75,7 +76,6 @@ bool Character::preview_load(const std::string& path, Renderer& renderer)
|
||||
stages.push_back({json_string(fields, "animationSuffix"), json_string(fields, "dialoguePool"),
|
||||
json_float(fields, "weight"), json_int(fields, "area", -1)});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Anm2* Character::anm2_get(const std::string& path, Renderer& renderer, Audio& audio)
|
||||
@@ -86,7 +86,8 @@ Anm2* Character::anm2_get(const std::string& path, Renderer& renderer, Audio& au
|
||||
if (found != anm2s.end())
|
||||
return found->second.animations.empty() ? nullptr : &found->second;
|
||||
Anm2& loaded = anm2s[path];
|
||||
return loaded.load(folder + path, renderer, audio) ? &loaded : nullptr;
|
||||
loaded.load(folder + path, renderer, audio);
|
||||
return loaded.animations.empty() ? nullptr : &loaded;
|
||||
}
|
||||
|
||||
// Sets an interact area's fields from source, keeping what it doesn't name (its type's settings).
|
||||
@@ -397,17 +398,20 @@ void Character::load(Renderer& renderer, Audio& audio)
|
||||
return;
|
||||
isLoaded = true;
|
||||
Json json;
|
||||
if (json.load(folder + "character.json"))
|
||||
json.load(folder + "character.json");
|
||||
if (json.isValid)
|
||||
{
|
||||
character_parse(json.root, *this, renderer, audio);
|
||||
sounds_parse(json.root, FILE_CHARACTER, *this, audio);
|
||||
}
|
||||
if (json.load(folder + "items.json"))
|
||||
json.load(folder + "items.json");
|
||||
if (json.isValid)
|
||||
{
|
||||
items_parse(json.root, *this, renderer, audio);
|
||||
sounds_parse(json.root, FILE_ITEMS, *this, audio);
|
||||
}
|
||||
if (json.load(folder + "dialogue.json"))
|
||||
json.load(folder + "dialogue.json");
|
||||
if (json.isValid)
|
||||
dialogue_parse(json.root, *this, audio);
|
||||
}
|
||||
|
||||
@@ -450,7 +454,10 @@ std::vector<Character> characters_load(Renderer& renderer)
|
||||
std::vector<Character> characters;
|
||||
characters.reserve(sorted.size());
|
||||
for (const std::string& name : sorted)
|
||||
if (!characters.emplace_back().preview_load(folder + name + "/", renderer))
|
||||
{
|
||||
characters.emplace_back().preview_load(folder + name + "/", renderer);
|
||||
if (!characters.back().isValid)
|
||||
characters.pop_back();
|
||||
}
|
||||
return characters;
|
||||
}
|
||||
+2
-1
@@ -280,8 +280,9 @@ public:
|
||||
int talkDestination = -1;
|
||||
int talkSource = -1;
|
||||
bool isLoaded = false;
|
||||
bool isValid = false;
|
||||
|
||||
bool preview_load(const std::string& path, Renderer& renderer);
|
||||
void preview_load(const std::string& path, Renderer& renderer);
|
||||
void load(Renderer& renderer, Audio& audio);
|
||||
Anm2* anm2_get(const std::string& path, Renderer& renderer, Audio& audio);
|
||||
Actor item_actor_get(int item);
|
||||
|
||||
+11
-5
@@ -49,7 +49,7 @@ static int history_callback(ImGuiInputTextCallbackData* data)
|
||||
}
|
||||
|
||||
// A toggle's new state: what its argument says, or the opposite of now without one.
|
||||
static bool toggle_get(const std::string& argument, bool value)
|
||||
static bool is_toggled(const std::string& argument, bool value)
|
||||
{
|
||||
return argument.empty() ? !value : argument == "true" || argument == "1";
|
||||
}
|
||||
@@ -126,11 +126,17 @@ void Console::execute(Play* play, std::vector<Character>& characters)
|
||||
else if (name == "reload")
|
||||
action = ACTION_RELOAD;
|
||||
else if (name == "show_layers")
|
||||
Actor::isShowLayers = toggle_get(argument, Actor::isShowLayers);
|
||||
Actor::isShowLayers = is_toggled(argument, Actor::isShowLayers);
|
||||
else if (name == "show_nulls")
|
||||
Actor::isShowNulls = toggle_get(argument, Actor::isShowNulls);
|
||||
else if (name == "spawn" && !play->spawn_queue_add(SDL_atoi(argument.c_str())))
|
||||
history.push_back("Unable to spawn item " + argument + ".");
|
||||
Actor::isShowNulls = is_toggled(argument, Actor::isShowNulls);
|
||||
else if (name == "spawn")
|
||||
{
|
||||
int id = SDL_atoi(argument.c_str());
|
||||
if (argument.empty() || id < 0 || id >= (int)play->character->items.size())
|
||||
history.push_back("Unable to spawn item " + argument + ".");
|
||||
else
|
||||
play->spawn_queue_add(id);
|
||||
}
|
||||
else if (name == "stage" || name == "weight")
|
||||
{
|
||||
play->stage = name == "stage" ? std::max(0, SDL_atoi(argument.c_str()) - 1) : play->stage_get(number);
|
||||
|
||||
+1
-1
@@ -338,7 +338,7 @@ void Text::update(Play& play, Vec2 screenSize)
|
||||
{
|
||||
Choice& choice = current->choices[i];
|
||||
ImGui::PushID(i);
|
||||
if (fx(ImGui::Button(choice.text.c_str(), buttonSize)))
|
||||
if (is_fx(ImGui::Button(choice.text.c_str(), buttonSize)))
|
||||
set(play, dialogue.entry_get(choice.next), TEXT_SEQUENCE);
|
||||
ImGui::SetItemTooltip("%s", choice.text.c_str());
|
||||
ImGui::PopID();
|
||||
|
||||
+6
-8
@@ -51,24 +51,23 @@ bool Play::is_spawn_possible()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Play::spawn_queue_add(int id)
|
||||
void Play::spawn_queue_add(int id)
|
||||
{
|
||||
if (id < 0 || id >= (int)character->items.size())
|
||||
return false;
|
||||
return;
|
||||
Item& item = character->items[id];
|
||||
audio->play(character->sounds[SOUND_SUMMON]);
|
||||
if (item.rarity >= 0)
|
||||
audio->play(character->rarities[item.rarity].sound);
|
||||
spawnQueue.push_back(id);
|
||||
spawnDelay = spawn_delay_get();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Queues an item picked at random by rarity, once the spawn delay is up.
|
||||
bool Play::spawn_queue_add()
|
||||
void Play::spawn_queue_add()
|
||||
{
|
||||
if (spawnDelay > 0 || !is_spawn_possible())
|
||||
return false;
|
||||
return;
|
||||
float total = 0;
|
||||
for (int i = 0; i < (int)character->items.size(); i++)
|
||||
total += spawn_weight_get(*this, i);
|
||||
@@ -76,7 +75,6 @@ bool Play::spawn_queue_add()
|
||||
for (int i = 0; i < (int)character->items.size(); i++)
|
||||
if (float weight = spawn_weight_get(*this, i); weight > 0 && (roll -= weight) < 0)
|
||||
return spawn_queue_add(i);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Where an eat area takes food: its null now, or at the start of its animation when it isn't showing.
|
||||
@@ -426,7 +424,7 @@ void Play::interact_update(Pointer pointer)
|
||||
}
|
||||
|
||||
// Moves the cursor toward a target, braking to land on it. Returns whether it's there.
|
||||
static bool move_toward(Vec2& position, Vec2& velocity, Vec2 target, float speed, float acceleration)
|
||||
static bool is_target_reached(Vec2& position, Vec2& velocity, Vec2 target, float speed, float acceleration)
|
||||
{
|
||||
Vec2 delta = target - position;
|
||||
float distance = vec2_length(delta);
|
||||
@@ -520,7 +518,7 @@ void Play::autofeed_update(Pointer& itemPointer, Pointer& interactPointer)
|
||||
auto move = [&](Vec2 target, float speed, float acceleration) {
|
||||
isAutofeedActive = autoCursor.isVisible = true;
|
||||
itemPointer = interactPointer = {.position = autoCursor.position, .isAutomated = true};
|
||||
bool isThere = move_toward(autoCursor.position, autoVelocity, target, speed * speedScale,
|
||||
bool isThere = is_target_reached(autoCursor.position, autoVelocity, target, speed * speedScale,
|
||||
acceleration * speedScale);
|
||||
itemPointer.position = interactPointer.position = autoCursor.position;
|
||||
return isThere;
|
||||
|
||||
+5
-5
@@ -23,13 +23,13 @@ struct Json
|
||||
{
|
||||
simdjson::dom::parser parser;
|
||||
object root = json_empty_get("o").get_object().value_unsafe();
|
||||
bool isValid = false;
|
||||
|
||||
bool load(const std::string& path)
|
||||
void load(const std::string& path)
|
||||
{
|
||||
if (!parser.load(path).get(root))
|
||||
return true;
|
||||
SDL_Log("Failed to load %s", path.c_str());
|
||||
return false;
|
||||
isValid = !parser.load(path).get(root);
|
||||
if (!isValid)
|
||||
SDL_Log("Failed to load %s", path.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+12
-7
@@ -95,12 +95,13 @@ static void characters_reload()
|
||||
play_start(character_get(key), GAME_CONTINUE);
|
||||
}
|
||||
|
||||
static bool init()
|
||||
static void init()
|
||||
{
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
SDL_Log("Failed to initialize SDL: %s", SDL_GetError());
|
||||
return false;
|
||||
game.isRunning = false;
|
||||
return;
|
||||
}
|
||||
game.settings.load();
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GL_MAJOR);
|
||||
@@ -110,10 +111,13 @@ static bool init()
|
||||
game.window = SDL_CreateWindow(GAME_NAME, game.settings.width, game.settings.height,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||
game.context = game.window ? SDL_GL_CreateContext(game.window) : nullptr;
|
||||
if (!game.context || !game.renderer.init())
|
||||
if (game.context)
|
||||
game.renderer.init();
|
||||
if (!game.renderer.isValid)
|
||||
{
|
||||
SDL_Log("Failed to initialize OpenGL: %s", SDL_GetError());
|
||||
return false;
|
||||
game.isRunning = false;
|
||||
return;
|
||||
}
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
game.audio.init();
|
||||
@@ -134,7 +138,6 @@ static bool init()
|
||||
|
||||
game.characters = characters_load(game.renderer);
|
||||
play_start(character_get(game.settings.lastCharacter), GAME_CONTINUE);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void events_handle()
|
||||
@@ -168,7 +171,8 @@ static void update()
|
||||
Vec2 screen = {ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y};
|
||||
if (game.screen == SCREEN_SELECT)
|
||||
{
|
||||
if (ui.select_update(game.characters, game.settings, game.renderer, game.audio))
|
||||
ui.select_update(game.characters, game.settings, game.renderer, game.audio);
|
||||
if (ui.isRefresh)
|
||||
characters_reload();
|
||||
if (ui.isNewGame || ui.isContinue)
|
||||
play_start(ui.characterIndex, ui.isNewGame ? GAME_NEW : GAME_CONTINUE);
|
||||
@@ -250,7 +254,8 @@ static void quit()
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
if (!init())
|
||||
init();
|
||||
if (!game.isRunning)
|
||||
return 1;
|
||||
#ifdef SDL_PLATFORM_EMSCRIPTEN
|
||||
emscripten_set_main_loop(loop, 0, true);
|
||||
|
||||
+3
-3
@@ -268,7 +268,7 @@ void Play::values_clamp()
|
||||
|
||||
// Swaps a layer's region for the one a source layer shows at a time, while active. Turns itself off (and returns
|
||||
// false) when the animation lacks the source or the time runs past it.
|
||||
static bool region_swap(Actor& actor, int source, float& time, Override& swap, bool isActive)
|
||||
static bool is_region_swapped(Actor& actor, int source, float& time, Override& swap, bool isActive)
|
||||
{
|
||||
Anm2Animation* animation = actor.animation_get();
|
||||
swap.isRegion = false;
|
||||
@@ -373,14 +373,14 @@ void Play::body_update()
|
||||
actor.overrides[OVERRIDE_EXPAND + i * 2 + 1].scale = {add, add};
|
||||
}
|
||||
|
||||
isTalking = region_swap(actor, data.talkSource, talkTime, actor.overrides[OVERRIDE_TALK], isTalking);
|
||||
isTalking = is_region_swapped(actor, data.talkSource, talkTime, actor.overrides[OVERRIDE_TALK], isTalking);
|
||||
if (talkTime > source_length_get(actor, data.talkSource))
|
||||
talkTime = 0;
|
||||
int blinkLength = source_length_get(actor, data.blinkSource);
|
||||
if (blinkLength != 1)
|
||||
{
|
||||
isBlinking |= is_chance(data.blinkChance);
|
||||
isBlinking = region_swap(actor, data.blinkSource, blinkTime, actor.overrides[OVERRIDE_BLINK], isBlinking);
|
||||
isBlinking = is_region_swapped(actor, data.blinkSource, blinkTime, actor.overrides[OVERRIDE_BLINK], isBlinking);
|
||||
if (blinkTime >= blinkLength)
|
||||
{
|
||||
isBlinking = false;
|
||||
|
||||
+2
-2
@@ -172,8 +172,8 @@ public:
|
||||
void item_add(int id, Vec2 position, Vec2 velocity = {}, float rotation = 0);
|
||||
int spawn_delay_get();
|
||||
bool is_spawn_possible();
|
||||
bool spawn_queue_add(int id);
|
||||
bool spawn_queue_add();
|
||||
void spawn_queue_add(int id);
|
||||
void spawn_queue_add();
|
||||
void particles_spawn(const std::vector<std::string>& names, Vec2 position);
|
||||
Rect eat_rect_get(const EatArea& eatArea);
|
||||
|
||||
|
||||
+3
-3
@@ -119,7 +119,7 @@ static Texture texture_create(int width, int height, const void* pixels)
|
||||
return texture;
|
||||
}
|
||||
|
||||
bool Renderer::init()
|
||||
void Renderer::init()
|
||||
{
|
||||
bool isLoaded = true;
|
||||
#define GL_FUNCTION_LOAD(name) \
|
||||
@@ -128,7 +128,7 @@ bool Renderer::init()
|
||||
GL_FUNCTIONS(GL_FUNCTION_LOAD)
|
||||
#undef GL_FUNCTION_LOAD
|
||||
if (!isLoaded)
|
||||
return false;
|
||||
return;
|
||||
|
||||
program = gl.CreateProgram();
|
||||
GLuint vertexShader = shader_compile(GL_VERTEX_SHADER, VERTEX_SHADER);
|
||||
@@ -154,7 +154,7 @@ bool Renderer::init()
|
||||
attribute(3, 4, offsetof(Vertex, offset));
|
||||
|
||||
white = texture_create(WHITE_SIZE, WHITE_SIZE, &WHITE_PIXEL);
|
||||
return true;
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
Texture* Renderer::texture_get(const std::string& path)
|
||||
|
||||
+2
-1
@@ -35,8 +35,9 @@ class Renderer
|
||||
{
|
||||
public:
|
||||
Texture white;
|
||||
bool isValid = false;
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
Texture* texture_get(const std::string& path);
|
||||
void canvas_set(Canvas* canvas, int width, int height, Color clear = CLEAR);
|
||||
void quad_draw(const Texture& texture, Rect region, Affine transform, Color tint = WHITE, Color offset = CLEAR);
|
||||
|
||||
+37
-38
@@ -255,7 +255,7 @@ static void panel_bar_draw(Play& play, bool& isOpen, float slide, ImVec2 positio
|
||||
{
|
||||
ImVec2 buttonSize = ImGui::GetContentRegionAvail();
|
||||
ImVec2 cursor = ImGui::GetCursorScreenPos();
|
||||
bool isPressed = fx(ImGui::Button("##Toggle", buttonSize));
|
||||
bool isPressed = is_fx(ImGui::Button("##Toggle", buttonSize));
|
||||
if (slide <= 0 || slide >= 1)
|
||||
{
|
||||
tooltip_set(character.strings[isOpen ? closeTooltip : openTooltip].c_str());
|
||||
@@ -396,7 +396,7 @@ static void interact_tab_draw(Play& play, Settings& settings)
|
||||
if (play.spawnDelay <= 0)
|
||||
{
|
||||
ImGui::BeginDisabled(!play.is_spawn_possible());
|
||||
if (fx(ImGui::Button(strings[STRING_InteractSpawnItemButton].c_str(), {width, 0})))
|
||||
if (is_fx(ImGui::Button(strings[STRING_InteractSpawnItemButton].c_str(), {width, 0})))
|
||||
play.spawn_queue_add();
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
@@ -416,7 +416,7 @@ static void interact_tab_draw(Play& play, Settings& settings)
|
||||
isFood |= character.items[entity.id].use == USE_EDIBLE;
|
||||
ImGui::BeginDisabled(!isFood);
|
||||
StringId autofeedLabel = play.isAutofeed ? STRING_InventoryDisableAutofeedButton : STRING_InventoryEnableAutofeedButton;
|
||||
if (fx(ImGui::Button(strings[autofeedLabel].c_str(), {width, 0})))
|
||||
if (is_fx(ImGui::Button(strings[autofeedLabel].c_str(), {width, 0})))
|
||||
play.isAutofeed = !play.isAutofeed;
|
||||
ImGui::EndDisabled();
|
||||
tooltip_set(strings[play.isAutofeed ? STRING_InventoryDisableAutofeedTooltip : STRING_InventoryEnableAutofeedTooltip]
|
||||
@@ -430,7 +430,7 @@ static void interact_tab_draw(Play& play, Settings& settings)
|
||||
if (!isShown)
|
||||
return;
|
||||
ImGui::PushFont(nullptr, size);
|
||||
if (fx(ImGui::Button(strings[label].c_str(), {width, 0})))
|
||||
if (is_fx(ImGui::Button(strings[label].c_str(), {width, 0})))
|
||||
play.text.set(play, (dialogue.*get)(name));
|
||||
ImGui::PopFont();
|
||||
};
|
||||
@@ -476,7 +476,7 @@ static void catalog_tab_draw(Play& play, Ui& ui, Renderer& renderer, std::vector
|
||||
ImVec2 padding = {(ITEM_SIZE - image.x) / 2, (ITEM_SIZE - image.y) / 2};
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
|
||||
{ImGui::GetStyle().FramePadding.x + padding.x, ImGui::GetStyle().FramePadding.y + padding.y});
|
||||
if (fx(ImGui::ImageButton("##Item", texture_id_get(canvases[i].texture), image, {0, 0}, {1, 1}, {}, tint)))
|
||||
if (is_fx(ImGui::ImageButton("##Item", texture_id_get(canvases[i].texture), image, {0, 0}, {1, 1}, {}, tint)))
|
||||
ui.selectedItem = i;
|
||||
ImGui::PopStyleVar();
|
||||
if (isSelected)
|
||||
@@ -543,25 +543,25 @@ static void cheats_tab_draw(Play& play)
|
||||
std::array<std::string, STRING_COUNT>& strings = character.strings;
|
||||
if (!ImGui::BeginChild("##Cheats"))
|
||||
return ImGui::EndChild();
|
||||
fx(ImGui::SliderFloat(strings[STRING_CheatsCalories].c_str(), &progress.calories, 0, play.capacity_max_get(),
|
||||
is_fx(ImGui::SliderFloat(strings[STRING_CheatsCalories].c_str(), &progress.calories, 0, play.capacity_max_get(),
|
||||
"%0.0f kcal"));
|
||||
fx(ImGui::SliderFloat(strings[STRING_CheatsCapacity].c_str(), &progress.capacity, character.capacityMin,
|
||||
is_fx(ImGui::SliderFloat(strings[STRING_CheatsCapacity].c_str(), &progress.capacity, character.capacityMin,
|
||||
character.capacityMax, "%0.0f kcal"));
|
||||
if (fx(ImGui::SliderFloat(strings[STRING_CheatsWeight].c_str(), &progress.weight, character.weight,
|
||||
if (is_fx(ImGui::SliderFloat(strings[STRING_CheatsWeight].c_str(), &progress.weight, character.weight,
|
||||
character.weightMax, strings[STRING_CheatsWeightFormat].c_str())))
|
||||
play.idle_play();
|
||||
int stage = play.stage + 1;
|
||||
if (fx(ImGui::SliderInt(strings[STRING_CheatsStage].c_str(), &stage, 1, (int)character.stages.size() + 1)))
|
||||
if (is_fx(ImGui::SliderInt(strings[STRING_CheatsStage].c_str(), &stage, 1, (int)character.stages.size() + 1)))
|
||||
{
|
||||
play.stage = stage - 1;
|
||||
progress.weight = play.stage_threshold_get(play.stage);
|
||||
play.idle_play();
|
||||
}
|
||||
float rate = progress.digestionRate * TICK_RATE;
|
||||
if (fx(ImGui::SliderFloat(strings[STRING_CheatsDigestionRate].c_str(), &rate, character.digestionRateMin * TICK_RATE,
|
||||
if (is_fx(ImGui::SliderFloat(strings[STRING_CheatsDigestionRate].c_str(), &rate, character.digestionRateMin * TICK_RATE,
|
||||
character.digestionRateMax * TICK_RATE, strings[STRING_CheatsDigestionRateFormat].c_str())))
|
||||
progress.digestionRate = rate / TICK_RATE;
|
||||
if (fx(ImGui::Button(strings[STRING_CheatsDigestButton].c_str())))
|
||||
if (is_fx(ImGui::Button(strings[STRING_CheatsDigestButton].c_str())))
|
||||
progress.digestionProgress = DIGESTION_MAX;
|
||||
ImGui::EndChild();
|
||||
}
|
||||
@@ -581,7 +581,7 @@ static void tools_draw(Play& play, ImVec2 position, ImVec2 size)
|
||||
if (isActive)
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered));
|
||||
ImGui::BeginDisabled(isDisabled);
|
||||
bool isPressed = fx(ImGui::Button(isIcon ? "##Icon" : label.c_str(), {side, side}));
|
||||
bool isPressed = is_fx(ImGui::Button(isIcon ? "##Icon" : label.c_str(), {side, side}));
|
||||
if (isIcon)
|
||||
{
|
||||
ImVec2 min = ImGui::GetItemRectMin();
|
||||
@@ -647,41 +647,41 @@ void Ui::settings_update(Settings& settings, Audio& audio, const Character* char
|
||||
return character ? character->strings[id].c_str() : STRING_DEFAULTS[id];
|
||||
};
|
||||
ImGui::SeparatorText(string_get(STRING_SettingsMeasurementSystem));
|
||||
fx(ImGui::RadioButton(string_get(STRING_SettingsMetric), (int*)&settings.measurement, MEASUREMENT_METRIC));
|
||||
is_fx(ImGui::RadioButton(string_get(STRING_SettingsMetric), (int*)&settings.measurement, MEASUREMENT_METRIC));
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsMetricTooltip));
|
||||
ImGui::SameLine();
|
||||
fx(ImGui::RadioButton(string_get(STRING_SettingsImperial), (int*)&settings.measurement, MEASUREMENT_IMPERIAL));
|
||||
is_fx(ImGui::RadioButton(string_get(STRING_SettingsImperial), (int*)&settings.measurement, MEASUREMENT_IMPERIAL));
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsImperialTooltip));
|
||||
|
||||
ImGui::SeparatorText(string_get(STRING_SettingsWindow));
|
||||
const char* modes[] = {string_get(STRING_SettingsWindowed), string_get(STRING_SettingsFullscreen)};
|
||||
int mode = isFullscreen;
|
||||
if (fx(ImGui::Combo(string_get(STRING_SettingsWindowMode), &mode, modes, 2)))
|
||||
if (is_fx(ImGui::Combo(string_get(STRING_SettingsWindowMode), &mode, modes, 2)))
|
||||
isFullscreenToggled = true;
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsWindowModeTooltip));
|
||||
|
||||
ImGui::SeparatorText(string_get(STRING_SettingsSound));
|
||||
ImGui::BeginDisabled(settings.isMuted);
|
||||
if (fx(ImGui::SliderInt(string_get(STRING_SettingsVolume), &settings.volume, 0, (int)PERCENT, "%d%%")))
|
||||
if (is_fx(ImGui::SliderInt(string_get(STRING_SettingsVolume), &settings.volume, 0, (int)PERCENT, "%d%%")))
|
||||
audio.gain_set(settings.volume / PERCENT);
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsVolumeTooltip));
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
if (fx(ImGui::Checkbox(string_get(STRING_SettingsMute), &settings.isMuted)))
|
||||
if (is_fx(ImGui::Checkbox(string_get(STRING_SettingsMute), &settings.isMuted)))
|
||||
audio.gain_set(settings.isMuted ? 0 : settings.volume / PERCENT);
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsMuteTooltip));
|
||||
|
||||
ImGui::SeparatorText(string_get(STRING_SettingsAppearance));
|
||||
bool isColorChanged = fx(ImGui::Checkbox(string_get(STRING_SettingsUseCharacterColor), &settings.isCharacterColor));
|
||||
bool isColorChanged = is_fx(ImGui::Checkbox(string_get(STRING_SettingsUseCharacterColor), &settings.isCharacterColor));
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsUseCharacterColorTooltip));
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(settings.isCharacterColor);
|
||||
isColorChanged |= fx(ImGui::ColorEdit3(string_get(STRING_SettingsColor), &settings.color.r,
|
||||
isColorChanged |= is_fx(ImGui::ColorEdit3(string_get(STRING_SettingsColor), &settings.color.r,
|
||||
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoTooltip));
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsColorTooltip));
|
||||
ImGui::EndDisabled();
|
||||
ImGui::Separator();
|
||||
if (fx(ImGui::Button(string_get(STRING_SettingsResetButton), {-FLT_MIN, 0})))
|
||||
if (is_fx(ImGui::Button(string_get(STRING_SettingsResetButton), {-FLT_MIN, 0})))
|
||||
{
|
||||
settings.reset();
|
||||
audio.gain_set(settings.volume / PERCENT);
|
||||
@@ -693,10 +693,10 @@ void Ui::settings_update(Settings& settings, Audio& audio, const Character* char
|
||||
if (!character)
|
||||
return;
|
||||
ImGui::Separator();
|
||||
if (fx(ImGui::Button(string_get(STRING_SettingsSaveButton), {-FLT_MIN, 0})))
|
||||
if (is_fx(ImGui::Button(string_get(STRING_SettingsSaveButton), {-FLT_MIN, 0})))
|
||||
isSave = true;
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsSaveTooltip));
|
||||
if (fx(ImGui::Button(string_get(STRING_SettingsReturnToCharactersButton), {-FLT_MIN, 0})))
|
||||
if (is_fx(ImGui::Button(string_get(STRING_SettingsReturnToCharactersButton), {-FLT_MIN, 0})))
|
||||
isReturn = true;
|
||||
ImGui::SetItemTooltip("%s", string_get(STRING_SettingsReturnToCharactersTooltip));
|
||||
}
|
||||
@@ -738,22 +738,22 @@ void Ui::play_update(Play& play, Settings& settings, Renderer& renderer, Audio&
|
||||
ImGui::SetNextWindowPos({menuX, style.WindowPadding.y});
|
||||
if (ImGui::Begin("##Menu", nullptr, PANEL_FLAGS) && ImGui::BeginTabBar("##Tabs"))
|
||||
{
|
||||
if (fx(ImGui::BeginTabItem(strings[STRING_MenuTabInteract].c_str())))
|
||||
if (is_fx(ImGui::BeginTabItem(strings[STRING_MenuTabInteract].c_str())))
|
||||
{
|
||||
interact_tab_draw(play, settings);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (fx(ImGui::BeginTabItem(strings[STRING_MenuTabInventory].c_str())))
|
||||
if (is_fx(ImGui::BeginTabItem(strings[STRING_MenuTabInventory].c_str())))
|
||||
{
|
||||
catalog_tab_draw(play, *this, renderer, itemCanvases, itemActors);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (fx(ImGui::BeginTabItem(strings[STRING_MenuTabSettings].c_str())))
|
||||
if (is_fx(ImGui::BeginTabItem(strings[STRING_MenuTabSettings].c_str())))
|
||||
{
|
||||
settings_update(settings, audio, &character);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (play.isCheats && fx(ImGui::BeginTabItem(strings[STRING_MenuTabCheats].c_str())))
|
||||
if (play.isCheats && is_fx(ImGui::BeginTabItem(strings[STRING_MenuTabCheats].c_str())))
|
||||
{
|
||||
cheats_tab_draw(play);
|
||||
ImGui::EndTabItem();
|
||||
@@ -767,12 +767,12 @@ void Ui::play_update(Play& play, Settings& settings, Renderer& renderer, Audio&
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
bool Ui::select_update(std::vector<Character>& characters, Settings& settings, Renderer& renderer, Audio& audio)
|
||||
void Ui::select_update(std::vector<Character>& characters, Settings& settings, Renderer& renderer, Audio& audio)
|
||||
{
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec2 screen = ImGui::GetIO().DisplaySize;
|
||||
ImVec2 half = {screen.x / 2 - style.WindowPadding.x * 2, screen.y / 2 - style.WindowPadding.y * 2};
|
||||
bool isRefresh = false;
|
||||
isRefresh = false;
|
||||
characterIndex = characters.empty() ? -1 : std::clamp(characterIndex, 0, (int)characters.size() - 1);
|
||||
Character* selected = characterIndex >= 0 ? &characters[characterIndex] : nullptr;
|
||||
if (selected && progressIndex != characterIndex)
|
||||
@@ -789,7 +789,7 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
if (ImGui::Begin("##Preview", nullptr, PANEL_FLAGS) && ImGui::BeginTabBar("##Preview Tabs"))
|
||||
{
|
||||
ImVec2 available = ImGui::GetContentRegionAvail();
|
||||
if (fx(ImGui::BeginTabItem("Render")))
|
||||
if (is_fx(ImGui::BeginTabItem("Render")))
|
||||
{
|
||||
if (Texture* render = selected->render)
|
||||
{
|
||||
@@ -803,7 +803,7 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
ImGui::TextWrapped("%s\n%s", selected->name.c_str(), selected->description.c_str());
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
isPreview = fx(ImGui::BeginTabItem("In Game"));
|
||||
isPreview = is_fx(ImGui::BeginTabItem("In Game"));
|
||||
if (isPreview)
|
||||
{
|
||||
Anm2* anm2 = selected->anm2_get(selected->anm2Path, renderer, audio);
|
||||
@@ -866,11 +866,11 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
ImVec2 buttonSize = {row_width_get(selectedProgress.isValid ? 2 : 1), 0};
|
||||
if (selectedProgress.isValid)
|
||||
{
|
||||
isContinue = fx(ImGui::Button("Continue", buttonSize));
|
||||
isContinue = is_fx(ImGui::Button("Continue", buttonSize));
|
||||
tooltip_set("Continue from a saved game.");
|
||||
ImGui::SameLine();
|
||||
}
|
||||
if (fx(ImGui::Button("New Game", buttonSize)))
|
||||
if (is_fx(ImGui::Button("New Game", buttonSize)))
|
||||
{
|
||||
isNewGame = !selectedProgress.isValid;
|
||||
isNewGameWarning = selectedProgress.isValid;
|
||||
@@ -887,9 +887,9 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
{
|
||||
ImGui::TextWrapped("This will delete saved progress! Are you sure?");
|
||||
ImVec2 popupSize = {row_width_get(2), 0};
|
||||
isNewGame = fx(ImGui::Button("Yes", popupSize));
|
||||
isNewGame = is_fx(ImGui::Button("Yes", popupSize));
|
||||
ImGui::SameLine();
|
||||
if (fx(ImGui::Button("No", popupSize)))
|
||||
if (is_fx(ImGui::Button("No", popupSize)))
|
||||
isNewGameWarning = false;
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
@@ -902,7 +902,7 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
ImGui::SetNextWindowPos({screen.x / 2, style.WindowPadding.y});
|
||||
if (ImGui::Begin("##Main Menu", nullptr, PANEL_FLAGS) && ImGui::BeginTabBar("##Main Tabs"))
|
||||
{
|
||||
if (fx(ImGui::BeginTabItem("Characters")))
|
||||
if (is_fx(ImGui::BeginTabItem("Characters")))
|
||||
{
|
||||
if (ImGui::BeginPopupContextWindow("##Characters Context"))
|
||||
{
|
||||
@@ -923,7 +923,7 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
? ImGui::ImageButton(character.name.c_str(), texture_id_get(*character.portrait),
|
||||
{side, side})
|
||||
: ImGui::Button(character.name.c_str(), {side, side});
|
||||
if (fx(isPressed))
|
||||
if (is_fx(isPressed))
|
||||
characterIndex = i;
|
||||
if (isSelected)
|
||||
ImGui::PopStyleColor();
|
||||
@@ -936,7 +936,7 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (fx(ImGui::BeginTabItem("Settings")))
|
||||
if (is_fx(ImGui::BeginTabItem("Settings")))
|
||||
{
|
||||
settings_update(settings, audio, nullptr);
|
||||
ImGui::EndTabItem();
|
||||
@@ -946,5 +946,4 @@ bool Ui::select_update(std::vector<Character>& characters, Settings& settings, R
|
||||
ImGui::End();
|
||||
if (isRefresh)
|
||||
progressIndex = -1;
|
||||
return isRefresh;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ void widget_sounds_set(Audio* audio, const Sounds* hover, const Sounds* select);
|
||||
void widget_fx();
|
||||
|
||||
// Passes a widget's result through after giving it its sounds and hover border.
|
||||
inline bool fx(bool result)
|
||||
inline bool is_fx(bool result)
|
||||
{
|
||||
widget_fx();
|
||||
return result;
|
||||
@@ -59,10 +59,11 @@ public:
|
||||
bool isNewGame = false;
|
||||
bool isNewGameWarning = false;
|
||||
bool isPreview = false;
|
||||
bool isRefresh = false;
|
||||
bool isReturn = false;
|
||||
bool isSave = false;
|
||||
|
||||
void play_update(Play& play, Settings& settings, Renderer& renderer, Audio& audio);
|
||||
bool select_update(std::vector<Character>& characters, Settings& settings, Renderer& renderer, Audio& audio);
|
||||
void select_update(std::vector<Character>& characters, Settings& settings, Renderer& renderer, Audio& audio);
|
||||
void settings_update(Settings& settings, Audio& audio, const Character* character);
|
||||
};
|
||||
Reference in new issue
Block a user