about summary refs log tree commit diff
path: root/src/game/client/components
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-09-24 14:47:03 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-09-24 14:47:03 +0000
commit917ebc17c617dfd27e4e997dce713cb1dfb6cfdc (patch)
tree11d85f18ef289de3de322bed5274dc616c23ac45 /src/game/client/components
parent2f28978237f0ead749a39229f1c683df63d34871 (diff)
downloadzcatch-917ebc17c617dfd27e4e997dce713cb1dfb6cfdc.tar.gz
zcatch-917ebc17c617dfd27e4e997dce713cb1dfb6cfdc.zip
begun the work on voting
Diffstat (limited to 'src/game/client/components')
-rw-r--r--src/game/client/components/menus.cpp22
-rw-r--r--src/game/client/components/voting.cpp61
-rw-r--r--src/game/client/components/voting.hpp39
3 files changed, 120 insertions, 2 deletions
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index 36bf6378..6c28138d 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -23,6 +23,7 @@ extern "C" {
 #include <game/generated/gc_data.hpp>
 #include <game/client/components/binds.hpp>
 #include <game/client/components/motd.hpp>
+#include <game/client/components/voting.hpp>
 #include <game/client/gameclient.hpp>
 #include <game/client/animstate.hpp>
 #include <game/client/gc_render.hpp>
@@ -620,8 +621,8 @@ void MENUS::render_news(RECT main_view)
 
 void MENUS::render_game(RECT main_view)
 {
-	RECT button;
-	ui_hsplit_t(&main_view, 45.0f, &main_view, 0);
+	RECT button, votearea;
+	ui_hsplit_t(&main_view, 45.0f, &main_view, &votearea);
 	ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
 
 	ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
@@ -688,6 +689,23 @@ void MENUS::render_game(RECT main_view)
 			}
 		}
 	}
+	
+	ui_hsplit_t(&votearea, 10.0f, 0, &votearea);
+	ui_hsplit_t(&votearea, 25.0f+10.0f*2, &votearea, 0);
+
+	ui_draw_rect(&votearea, color_tabbar_active, CORNER_ALL, 10.0f);
+
+	ui_vmargin(&votearea, 10.0f, &votearea);
+	ui_hmargin(&votearea, 10.0f, &votearea);
+	if(gameclient.voting->is_voting())
+	{
+		
+	}
+	else
+	{
+		ui_do_label(&votearea, "No vote in progress", 18.0f, -1);
+	}
+	
 }
 
 void MENUS::render_serverinfo(RECT main_view)
diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp
new file mode 100644
index 00000000..b81cfb97
--- /dev/null
+++ b/src/game/client/components/voting.cpp
@@ -0,0 +1,61 @@
+#include <engine/e_client_interface.h>
+#include <game/generated/g_protocol.hpp>
+#include "voting.hpp"
+
+void VOTING::con_callvote(void *result, void *user_data)
+{
+}
+
+void VOTING::con_vote(void *result, void *user_data)
+{
+}
+	
+VOTING::VOTING()
+{
+	on_reset();
+}
+
+void VOTING::on_reset()
+{
+	closetime = 0;
+	description[0] = 0;
+	command[0] = 0;
+	yes = no = pass = total = 0;
+	voted = 0;
+}
+
+void VOTING::on_console_init()
+{
+	MACRO_REGISTER_COMMAND("callvote", "r", con_callvote, this);
+	MACRO_REGISTER_COMMAND("vote", "r", con_vote, this);
+}
+
+void VOTING::on_message(int msgtype, void *rawmsg)
+{
+	if(msgtype == NETMSGTYPE_SV_VOTE_SET)
+	{
+		NETMSG_SV_VOTE_SET *msg = (NETMSG_SV_VOTE_SET *)rawmsg;
+		if(msg->timeout)
+		{
+			on_reset();
+			str_copy(description, msg->description, sizeof(description));
+			str_copy(command, msg->command, sizeof(description));
+			closetime = time_get() + time_freq() * msg->timeout;
+		}
+		else
+			on_reset();
+	}
+	else if(msgtype == NETMSGTYPE_SV_VOTE_STATUS)
+	{
+		NETMSG_SV_VOTE_STATUS *msg = (NETMSG_SV_VOTE_STATUS *)rawmsg;
+		yes = msg->yes;
+		no = msg->no;
+		pass = msg->pass;
+		total = msg->total;
+	}	
+}
+
+void VOTING::on_render()
+{
+}
+
diff --git a/src/game/client/components/voting.hpp b/src/game/client/components/voting.hpp
new file mode 100644
index 00000000..6f518d10
--- /dev/null
+++ b/src/game/client/components/voting.hpp
@@ -0,0 +1,39 @@
+#include <game/client/component.hpp>
+
+class VOTING : public COMPONENT
+{
+	/*
+	void render_goals(float x, float y, float w);
+	void render_spectators(float x, float y, float w);
+	void render_scoreboard(float x, float y, float w, int team, const char *title);
+
+	static void con_key_scoreboard(void *result, void *user_data);
+	
+	bool active;
+	*/
+
+	static void con_callvote(void *result, void *user_data);
+	static void con_vote(void *result, void *user_data);
+	
+	int64 closetime;
+	char description[512];
+	char command[512];
+	int voted;
+	
+public:
+	VOTING();
+	virtual void on_reset();
+	virtual void on_console_init();
+	virtual void on_message(int msgtype, void *rawmsg);
+	virtual void on_render();
+	
+	void vote(int v); // -1 = no, 1 = yes
+	
+	bool is_voting() { return closetime != 0; }
+	int taken_choice() const { return voted; }
+	const char *vote_description() const { return description; }
+	const char *vote_command() const { return command; }
+	
+	int yes, no, pass, total;
+};
+