about summary refs log tree commit diff
path: root/src/game/client/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/client/components')
-rw-r--r--src/game/client/components/binds.cpp22
-rw-r--r--src/game/client/components/binds.hpp1
-rw-r--r--src/game/client/components/hud.cpp28
-rw-r--r--src/game/client/components/hud.hpp1
-rw-r--r--src/game/client/components/menus.cpp48
-rw-r--r--src/game/client/components/menus_settings.cpp2
-rw-r--r--src/game/client/components/voting.cpp61
-rw-r--r--src/game/client/components/voting.hpp3
8 files changed, 120 insertions, 46 deletions
diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp
index 7fa5da5e..b55e7333 100644
--- a/src/game/client/components/binds.cpp
+++ b/src/game/client/components/binds.cpp
@@ -63,6 +63,21 @@ const char *BINDS::get(int keyid)
 	return "";
 }
 
+const char *BINDS::get_key(const char *bindstr)
+{
+	for(int keyid = 0; keyid < KEY_LAST; keyid++)
+	{
+		const char *bind = get(keyid);
+		if(!bind[0])
+			continue;
+			
+		if(strcmp(bind, bindstr) == 0)
+			return inp_key_name(keyid);
+	}
+	
+	return "";
+}
+
 void BINDS::set_defaults()
 {
 	// set default key bindings
@@ -90,6 +105,9 @@ void BINDS::set_defaults()
 	
 	bind('T', "chat all");
 	bind('Y', "chat team");	
+
+	bind(KEY_F3, "vote yes");
+	bind(KEY_F4, "vote no");	
 }
 
 void BINDS::on_console_init()
@@ -104,8 +122,6 @@ void BINDS::on_console_init()
 	set_defaults();
 }
 
-
-
 void BINDS::con_bind(void *result, void *user_data)
 {
 	BINDS *binds = (BINDS *)user_data;
@@ -159,7 +175,7 @@ void BINDS::con_dump_binds(void *result, void *user_data)
 int BINDS::get_key_id(const char *key_name)
 {
 	// check for numeric
-	if(key_name[0] == '#')
+	if(key_name[0] == '&')
 	{
 		int i = atoi(key_name+1);
 		if(i > 0 && i < KEY_LAST)
diff --git a/src/game/client/components/binds.hpp b/src/game/client/components/binds.hpp
index 1c9bf388..bdf242f9 100644
--- a/src/game/client/components/binds.hpp
+++ b/src/game/client/components/binds.hpp
@@ -27,6 +27,7 @@ public:
 	void set_defaults();
 	void unbindall();
 	const char *get(int keyid);
+	const char *get_key(const char *bindstr);
 	
 	virtual void on_save();
 	virtual void on_console_init();
diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp
index f2c37b83..86ce6257 100644
--- a/src/game/client/components/hud.cpp
+++ b/src/game/client/components/hud.cpp
@@ -13,6 +13,8 @@
 #include "controls.hpp"
 #include "camera.hpp"
 #include "hud.hpp"
+#include "voting.hpp"
+#include "binds.hpp"
 
 HUD::HUD()
 {
@@ -196,12 +198,35 @@ void HUD::render_teambalancewarning()
 				gfx_text_color(1,1,0.5f,1);
 			else
 				gfx_text_color(0.7f,0.7f,0.2f,1.0f);
-			gfx_text(0x0, 5, 50, 6, text, -1);
+			gfx_text(0x0, 5, 40, 6, text, -1);
 			gfx_text_color(1,1,1,1);
 		}
 	}
 }
 
+
+void HUD::render_voting()
+{
+	if(!gameclient.voting->is_voting())
+		return;
+	
+	gfx_text_color(1,1,1,1);
+	gfx_text(0x0, 5, 50, 6, gameclient.voting->vote_description(), -1);
+
+	RECT base = {5, 60, 119, 3};
+	gameclient.voting->render_bars(base, false);
+	
+	char buf[512];
+	const char *yes_key = gameclient.binds->get_key("vote yes");
+	const char *no_key = gameclient.binds->get_key("vote no");
+	str_format(buf, sizeof(buf), "%s - Vote Yes", yes_key);
+	base.y += base.h+1;
+	ui_do_label(&base, buf, 6.0f, -1);
+
+	str_format(buf, sizeof(buf), "Vote No - %s", no_key);
+	ui_do_label(&base, buf, 6.0f, 1);
+}
+
 void HUD::render_cursor()
 {
 	if(!gameclient.snap.local_character)
@@ -283,5 +308,6 @@ void HUD::on_render()
 	render_connectionwarning();
 	render_tunewarning();
 	render_teambalancewarning();
+	render_voting();
 	render_cursor();
 }
diff --git a/src/game/client/components/hud.hpp b/src/game/client/components/hud.hpp
index 15b9e52c..3ec102f1 100644
--- a/src/game/client/components/hud.hpp
+++ b/src/game/client/components/hud.hpp
@@ -10,6 +10,7 @@ class HUD : public COMPONENT
 	void render_connectionwarning();
 	void render_tunewarning();
 	void render_teambalancewarning();
+	void render_voting();
 	void render_healthandammo();
 	void render_goals();
 	
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp
index 8cfd211b..d2759642 100644
--- a/src/game/client/components/menus.cpp
+++ b/src/game/client/components/menus.cpp
@@ -621,8 +621,9 @@ void MENUS::render_news(RECT main_view)
 
 void MENUS::render_game(RECT main_view)
 {
-	RECT button, votearea;
-	ui_hsplit_t(&main_view, 45.0f, &main_view, &votearea);
+	RECT button;
+	//RECT votearea;
+	ui_hsplit_t(&main_view, 45.0f, &main_view, 0);
 	ui_draw_rect(&main_view, color_tabbar_active, CORNER_ALL, 10.0f);
 
 	ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
@@ -690,6 +691,7 @@ void MENUS::render_game(RECT main_view)
 		}
 	}
 	
+	/*
 	RECT bars;
 	ui_hsplit_t(&votearea, 10.0f, 0, &votearea);
 	ui_hsplit_t(&votearea, 25.0f + 10.0f*3 + 25.0f, &votearea, &bars);
@@ -731,52 +733,14 @@ void MENUS::render_game(RECT main_view)
 		// do bars
 		ui_hsplit_t(&bars, 10.0f, 0, &bars);
 		ui_hmargin(&bars, 5.0f, &bars);
-		ui_draw_rect(&bars, vec4(0.8f,0.8f,0.8f,1), CORNER_ALL, 5.0f);
 		
-		if(gameclient.voting->total)
-		{
-			RECT pass_area = bars;
-			if(gameclient.voting->yes)
-			{
-				RECT yes_area = bars;
-				yes_area.w *= gameclient.voting->yes/(float)gameclient.voting->total;
-				ui_draw_rect(&yes_area, vec4(0.4f,0.8f,0.4f,1), CORNER_ALL, 5.0f);
-				
-				char buf[256];
-				str_format(buf, sizeof(buf), "%d", gameclient.voting->yes);
-				ui_do_label(&yes_area, buf, 12.0f, 0);
-				
-				pass_area.x += yes_area.w;
-				pass_area.w -= yes_area.w;
-			}
-			
-			if(gameclient.voting->no)
-			{
-				RECT no_area = bars;
-				no_area.w *= gameclient.voting->no/(float)gameclient.voting->total;
-				no_area.x = (bars.x + bars.w)-no_area.w;
-				ui_draw_rect(&no_area, vec4(0.8f,0.4f,0.4f,1), CORNER_ALL, 5.0f);
-				
-				char buf[256];
-				str_format(buf, sizeof(buf), "%d", gameclient.voting->no);
-				ui_do_label(&no_area, buf, 12.0f, 0);
-
-				pass_area.w -= no_area.w;
-			}
+		gameclient.voting->render_bars(bars, true);
 
-			if(gameclient.voting->pass)
-			{
-				char buf[256];
-				str_format(buf, sizeof(buf), "%d", gameclient.voting->pass);
-				ui_do_label(&pass_area, buf, 12.0f, 0);
-			}
-		}
 	}		
 	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/menus_settings.cpp b/src/game/client/components/menus_settings.cpp
index e43793a4..9311477e 100644
--- a/src/game/client/components/menus_settings.cpp
+++ b/src/game/client/components/menus_settings.cpp
@@ -250,6 +250,8 @@ void MENUS::render_settings_controls(RECT main_view)
 		{ "Console:", "toggle_local_console", 0 },
 		{ "Remote Console:", "toggle_remote_console", 0 },
 		{ "Screenshot:", "screenshot", 0 },
+		{ "Vote Yes:", "vote yes", 0 },
+		{ "Vote No:", "vote no", 0 },
 	};
 
 	const int key_count = sizeof(keys) / sizeof(KEYINFO);
diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp
index d90e617f..e835aa8f 100644
--- a/src/game/client/components/voting.cpp
+++ b/src/game/client/components/voting.cpp
@@ -1,5 +1,8 @@
 #include <engine/e_client_interface.h>
 #include <game/generated/g_protocol.hpp>
+#include <base/vmath.hpp>
+#include <game/client/gc_render.hpp>
+//#include <game/client/gameclient.hpp>
 #include "voting.hpp"
 
 void VOTING::con_callvote(void *result, void *user_data)
@@ -76,3 +79,61 @@ void VOTING::on_render()
 {
 }
 
+
+void VOTING::render_bars(RECT bars, bool text)
+{
+	ui_draw_rect(&bars, vec4(0.8f,0.8f,0.8f,0.5f), CORNER_ALL, bars.h/3);
+	
+	RECT splitter = bars;
+	splitter.x = splitter.x+splitter.w/2;
+	splitter.w = splitter.h/2.0f;
+	splitter.x -= splitter.w/2;
+	ui_draw_rect(&splitter, vec4(0.4f,0.4f,0.4f,0.5f), CORNER_ALL, splitter.h/4);
+			
+	if(total)
+	{
+		RECT pass_area = bars;
+		if(yes)
+		{
+			RECT yes_area = bars;
+			yes_area.w *= yes/(float)total;
+			ui_draw_rect(&yes_area, vec4(0.2f,0.9f,0.2f,0.85f), CORNER_ALL, bars.h/3);
+			
+			if(text)
+			{
+				char buf[256];
+				str_format(buf, sizeof(buf), "%d", yes);
+				ui_do_label(&yes_area, buf, bars.h*0.75f, 0);
+			}
+			
+			pass_area.x += yes_area.w;
+			pass_area.w -= yes_area.w;
+		}
+		
+		if(no)
+		{
+			RECT no_area = bars;
+			no_area.w *= no/(float)total;
+			no_area.x = (bars.x + bars.w)-no_area.w;
+			ui_draw_rect(&no_area, vec4(0.9f,0.2f,0.2f,0.85f), CORNER_ALL, bars.h/3);
+			
+			if(text)
+			{
+				char buf[256];
+				str_format(buf, sizeof(buf), "%d", no);
+				ui_do_label(&no_area, buf, bars.h*0.75f, 0);
+			}
+
+			pass_area.w -= no_area.w;
+		}
+
+		if(text && pass)
+		{
+			char buf[256];
+			str_format(buf, sizeof(buf), "%d", pass);
+			ui_do_label(&pass_area, buf, bars.h*0.75f, 0);
+		}
+	}	
+}
+
+
diff --git a/src/game/client/components/voting.hpp b/src/game/client/components/voting.hpp
index e5338d10..03de629d 100644
--- a/src/game/client/components/voting.hpp
+++ b/src/game/client/components/voting.hpp
@@ -1,4 +1,5 @@
 #include <game/client/component.hpp>
+#include <game/client/ui.hpp>
 
 class VOTING : public COMPONENT
 {
@@ -27,6 +28,8 @@ public:
 	virtual void on_message(int msgtype, void *rawmsg);
 	virtual void on_render();
 	
+	void render_bars(RECT bars, bool text);
+	
 	void vote(int v); // -1 = no, 1 = yes
 	
 	int seconds_left() { return (closetime - time_get())/time_freq(); }