mirror of
https://github.com/zebrajr/SamRewritten.git
synced 2025-12-06 00:19:47 +01:00
Simplify achievement selection logic
Simplify handling and interaction with the GUI when an achievement is "active" - that is, when it is pending modification. Clean up makefile some Make makefile be sensitive to header file changes - For now, make every file sensitive to any header change for simplicity. This prevents build corruptions on header changes.
This commit is contained in:
parent
44f2b773c7
commit
816d860ef7
5
Makefile
5
Makefile
|
|
@ -1,6 +1,7 @@
|
|||
CXX=g++ -std=c++17 -g
|
||||
RM=rm -f
|
||||
RMDIR=rm -rf
|
||||
HFILES:=$(shell find src/ -type f -iname *.h -print)
|
||||
CXXFILES:=$(shell find src/ -type f -iname *.cpp -print)
|
||||
CXXFLAGS=$(shell pkg-config --cflags --libs gtk+-3.0) -rdynamic -export-dynamic -pthread -Wall -lpthread -lgmodule-2.0 -lsteam_api -lcurl -lyajl -ldl
|
||||
LDFLAGS=-L${CURDIR}/bin
|
||||
|
|
@ -10,9 +11,9 @@ OBJS=$(addprefix ${OBJDIR}/,$(subst .cpp,.o,${CXXFILES}))
|
|||
all: ${CURDIR}/bin/samrewritten
|
||||
|
||||
${CURDIR}/bin/samrewritten: $(OBJS)
|
||||
${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${CURDIR}/bin/samrewritten $(shell find obj/ -type f -iname *.o -print)
|
||||
${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${CURDIR}/bin/samrewritten $(OBJS)
|
||||
|
||||
${OBJDIR}/%.o: %.cpp
|
||||
${OBJDIR}/%.o: %.cpp $(HFILES)
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(CXX) $(CXXFLAGS) $< ${LDFLAGS} -c -o $@
|
||||
|
||||
|
|
|
|||
|
|
@ -16,42 +16,30 @@ extern "C"
|
|||
GtkAchievementBoxRow * this_row = (GtkAchievementBoxRow *)ach_row;
|
||||
if (this_row->m_ignore_toggle) return;
|
||||
|
||||
const Achievement_t* ach = &this_row->m_data;
|
||||
const bool active = gtk_toggle_button_get_active(but);
|
||||
const bool achieved = ach->achieved;
|
||||
const std::string ach_id = ach->id;
|
||||
|
||||
if (active && achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(but), "To relock");
|
||||
g_steam->add_modification_ach(ach_id, false);
|
||||
} else if (!active && achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(but), "🔓 Unlocked");
|
||||
g_steam->remove_modification_ach(ach_id);
|
||||
} else if (active && !achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(but), "To unlock");
|
||||
g_steam->add_modification_ach(ach_id, true);
|
||||
} else if (!active && !achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(but), "🔒 Locked");
|
||||
g_steam->remove_modification_ach(ach_id);
|
||||
}
|
||||
// TODO: just register invert as the signal handler directly when transformed
|
||||
// to proper GTKMM C++
|
||||
// This will cause GTK to call this function recursively once, but it will
|
||||
// be ignored.
|
||||
this_row->invert();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GtkAchievementBoxRow::unlock() {
|
||||
m_ignore_toggle = true;
|
||||
const bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button));
|
||||
const bool achieved = m_data.achieved;
|
||||
const std::string ach_id = m_data.id;
|
||||
|
||||
// The button wasn't actually clicked, so the condition is different
|
||||
if (!active && !achieved) {
|
||||
if (!m_active && !achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "To unlock");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), TRUE);
|
||||
m_active = true;
|
||||
g_steam->add_modification_ach(ach_id, true);
|
||||
} else if (active && achieved) {
|
||||
} else if (m_active && achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "🔓 Unlocked");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), FALSE);
|
||||
m_active = false;
|
||||
|
||||
g_steam->remove_modification_ach(ach_id);
|
||||
}
|
||||
// Do nothing for all other conditions
|
||||
|
|
@ -62,18 +50,18 @@ GtkAchievementBoxRow::unlock() {
|
|||
void
|
||||
GtkAchievementBoxRow::lock() {
|
||||
m_ignore_toggle = true;
|
||||
const bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button));
|
||||
const bool achieved = m_data.achieved;
|
||||
const std::string ach_id = m_data.id;
|
||||
|
||||
// The button wasn't actually clicked, so the condition is different
|
||||
if (!active && achieved) {
|
||||
if (!m_active && achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "To relock");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), TRUE);
|
||||
m_active = true;
|
||||
g_steam->add_modification_ach(ach_id, false);
|
||||
} else if (active && !achieved) {
|
||||
} else if (m_active && !achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "🔒 Locked");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), FALSE);
|
||||
m_active = false;
|
||||
g_steam->remove_modification_ach(ach_id);
|
||||
}
|
||||
// Do nothing for all other conditions
|
||||
|
|
@ -85,27 +73,29 @@ GtkAchievementBoxRow::lock() {
|
|||
void
|
||||
GtkAchievementBoxRow::invert() {
|
||||
m_ignore_toggle = true;
|
||||
const bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button));
|
||||
const bool achieved = m_data.achieved;
|
||||
const std::string ach_id = m_data.id;
|
||||
|
||||
// The button wasn't actually clicked, so the condition is different
|
||||
// TODO: is this the expected behavior for invert? Who uses this?
|
||||
if (!active && achieved) {
|
||||
if (!m_active && achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "To relock");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), TRUE);
|
||||
m_active = true;
|
||||
g_steam->add_modification_ach(ach_id, false);
|
||||
} else if (active && achieved) {
|
||||
} else if (m_active && achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "🔓 Unlocked");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), FALSE);
|
||||
m_active = false;
|
||||
g_steam->remove_modification_ach(ach_id);
|
||||
} else if (!active && !achieved) {
|
||||
} else if (!m_active && !achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "To unlock");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), TRUE);
|
||||
m_active = true;
|
||||
g_steam->add_modification_ach(ach_id, true);
|
||||
} else if (active && !achieved) {
|
||||
} else if (m_active && !achieved) {
|
||||
gtk_button_set_label(GTK_BUTTON(m_lock_unlock_button), "🔒 Locked");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_lock_unlock_button), FALSE);
|
||||
m_active = false;
|
||||
g_steam->remove_modification_ach(ach_id);
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +106,7 @@ GtkAchievementBoxRow::invert() {
|
|||
GtkAchievementBoxRow::GtkAchievementBoxRow(const Achievement_t& data)
|
||||
:
|
||||
m_data(data),
|
||||
m_active(false),
|
||||
m_ignore_toggle(false)
|
||||
{
|
||||
// TODO achievement icons
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ public:
|
|||
|
||||
GtkWidget* get_main_widget() { return m_main_box; };
|
||||
|
||||
// TODO: pull this data back into private when transformed
|
||||
// to proper GTKMM C++ signal handlers
|
||||
Achievement_t m_data;
|
||||
// Whether the achievement has a pending change
|
||||
// This simplifies logic with the toggle button.
|
||||
bool m_active;
|
||||
bool m_ignore_toggle;
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user