Jump to content

Open Coterie  ·  19 members

SMF Staff People

ACM character colors


Jones
 Share

Recommended Posts

Hi. Me. Again. 😀

 

Easy way to show the character's name in it's Alliance/Department color on index, messageindex, display? No rush, just curious. 

 

Edited by Jones

 

operation: bowtruckles & bombs

R6MmD.png

Link to comment
Share on other sites

@Jones New threads for new things, hon.

 

In most places, the character names should already be determining their own colour. If they are not, you can try using link_color instead of just link, that may work, I remember doing it that way in a few places. If that doesn't, you'll have to find all of the character link calls in the source files and change it so that it'll load colours and use them properly. More or less you just need to add alliance_color and department_color to the SQL, and then do a bunch of if then else statements to add the colours to the links.

$request = $smcFunc['db_query']('','
		SELECT
			ch.id_character, ch.name_first, ch.name_last, ch.image, al.alliance_color, dp.department_color
		FROM {db_prefix}acm_characters AS ch
			LEFT JOIN {db_prefix}acm_alliances AS al ON (ch.id_alliance = al.id_alliance)
			LEFT JOIN {db_prefix}acm_departments AS dp ON (ch.id_department = dp.id_department)
		WHERE
			ch.id_member = {int:id_member}
			AND ch.is_activated = 1
			AND ch.is_npc = 0
		ORDER BY '.(!empty($modSettings['acmOrderCharsBy']) ? 'ch.name_last, ch.name_first' : 'ch.name_first, ch.name_last'),
		array(
			'id_member' => $profile['id_member'],
		)
	);
while ($row = $smcFunc['db_fetch_assoc']($request))
	{
		$characters[] = array(
			'id' => $row['id_character'],
			'name' => array(
				'first' => $row['name_first'],
				'last' => $row['name_last'],
			),
			'link' => '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row['id_character'].'" style="color: '.(!empty($row['department_color']) ? $row['department_color'].';"' : (!empty($row['alliance_color']) ? $row['alliance_color'] : '')).'">'.$row['name_first']. (!empty($row['name_last']) ? ' '.$row['name_last'] : '').'</a>',
			'link_lf' => '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row['id_character'].'" style="color: '.(!empty($row['department_color']) ? $row['department_color'].';"' : (!empty($row['alliance_color']) ? $row['alliance_color'] : '')).'">'.(!empty($row['name_last']) ? $row['name_last'].' ' : ''). $row['name_first'].'</a>',
			'link_lfc' => '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row['id_character'].'" style="color: '.(!empty($row['department_color']) ? $row['department_color'].';"' : (!empty($row['alliance_color']) ? $row['alliance_color'] : '')).'">'.(!empty($row['name_last']) ? $row['name_last'].', ' : ''). $row['name_first'].'</a>',
			'image' => array(
				'name' => !empty($row['image']) ? $row['image'] : '',
				'href' => !empty($row['image']) ? $boardurl.'/character_images/'.$row['image'] : '',
				'image' => !empty($row['image']) ? '<img src="'.$boardurl.'/character_images/'.$row['image'].'">' : '',
			),
		);
	}

If you need some guidance on how exactly to do this manually, this is my site's Load.php, where it loads user characters for display in profile and on memberlist.

nusignature.png nusignature.png

I am the darkness, always watching, always listening, ALWAYS THERE.
(If you're interested in Plain of Ice, message me, it's private. Bleach site, non-canon.)

Link to comment
Share on other sites

Plz send halp.

I got it working in the display template simply enough. 

<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '" style="color: ',  $message['member']['group_color'] ,';"> ',$message['member']['name'],' </a>

Buuut, obviously it couldn't be that easy for MessageIndex.template or BoardIndex.template. Link_color and group_color are not in the member/character source arrays for those templates. I don't know jack about databases other than how to go in and look at what the columns and rows say. So the rest was a little pretty far out of my ability. I looked over Source/BoardIndex.php and didn't find any member/character bits. So I decided to start with Source/MessageIndex.php. This is the mess I made, but all that does is throw me unknown column errors.

 

		$result = $smcFunc['db_query']('substring', '
			SELECT
				t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
				' . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from,
				t.id_last_msg, t.approved, t.unapproved_posts,  t.topic_description, ml.poster_time AS last_poster_time,
				ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
				ml.poster_name AS last_member_name, ml.id_member AS last_id_member,
				IFNULL(meml.real_name, ml.poster_name) AS last_display_name, t.id_first_msg,
				mf.poster_time AS first_poster_time, mf.subject AS first_subject, mf.icon AS first_icon,
				mf.poster_name AS first_member_name, mf.id_member AS first_id_member,
				mf.id_character AS id_fchar, ml.id_character AS id_lchar,
				ch1.image AS avatar_fchar, ch2.image AS avatar_lchar, ch1.name_first AS firstchar_namefirst, ch1.name_last AS firstchar_namelast,
				ch2.name_first AS lastchar_namefirst, ch2.name_last AS lastchar_namelast, 

				IFNULL(memf.real_name, mf.poster_name) AS first_display_name, SUBSTRING(ml.body, 1, 385) AS last_body,
				SUBSTRING(mf.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys,al.alliance_color, dp.department_color
			FROM {db_prefix}topics AS t
				INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
				INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
				LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
				LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
				LEFT JOIN {db_prefix}acm_characters AS ch1 ON (mf.id_character = ch1.id_character)
				LEFT JOIN {db_prefix}acm_characters AS ch2 ON (ml.id_character = ch2.id_character)' . ($user_info['is_guest'] ? '' : '
				LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
				LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})'). '
			WHERE ' . ($pre_query ? 't.id_topic IN ({array_int:topic_list})' : 't.id_board = {int:current_board}') . (!$modSettings['postmod_active'] || $context['can_approve_posts'] ? '' : '
				AND (t.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR t.id_member_started = {int:current_member}') . ')') . '
			ORDER BY ' . ($pre_query ? 'FIND_IN_SET(t.id_topic, {string:find_set_topics})' : (!empty($modSettings['enableStickyTopics']) ? 'is_sticky' . ($fake_ascending ? '' : ' DESC') . ', ' : '') . $_REQUEST['sort'] . ($ascending ? '' : ' DESC')) . '
			LIMIT ' . ($pre_query ? '' : '{int:start}, ') . '{int:maxindex}',
			array(
				'current_board' => $board,
				'current_member' => $user_info['id'],
				'topic_list' => $topic_ids,
				'is_approved' => 1,
				'find_set_topics' => implode(',', $topic_ids),
				'start' => $start,
				'maxindex' => $maxindex,
			)
		);

 

I also changed the 'character 'link' here to include alliance/department color and made the same changes in the 'last_post' array as well. I sort of feel like this part is right but honestly I am flying by the seat of my pants. 

 

$context['topics'][$row['id_topic']] = array(
				'id' => $row['id_topic'],
				'first_post' => array(
					'id' => $row['id_first_msg'],
					'member' => array(
						'username' => $row['first_member_name'],
						'name' => $row['first_display_name'],
						'id' => $row['first_id_member'],
						'href' => !empty($row['first_id_member']) ? $scripturl . '?action=profile;u=' . $row['first_id_member'] : '',
						'link' => !empty($row['first_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['first_id_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['first_display_name'] . '">' . $row['first_display_name'] . '</a>' : $row['first_display_name']
					),
					'character' => array(
						'id' => !empty($row['id_fchar']) ? $row['id_fchar'] : 0,
						'name' => !empty($row['id_fchar']) ? $firstchar_name : '',
						'href' => !empty($row['id_fchar']) ? $scripturl.'?action=characters;area=profile;id='.$row['id_fchar'] : '',
						'link' => !empty($row['id_fchar']) ? '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row['id_fchar'].'" style="color: '.(!empty($row['department_color']) ? $row['department_color'].';"' : (!empty($row['alliance_color']) ? $row['alliance_color'] : '')).'">>'.$firstchar_name.'</a>' : '',
						'avatar' => array(
							'name' => !empty($row['avatar_fchar']) ? $row['avatar_fchar'] : '',
							'image' => !empty($row['avatar_fchar']) ? '<img src="'.$boardurl.'/character_images/'.$row['avatar_fchar'].'">' : '',
							'href' => !empty($row['avatar_fchar']) ? $boardurl.'/character_images/'.$row['avatar_fchar'] : '',
							'url' => !empty($row['avatar_fchar']) ? $boardurl.'/character_images/'.$row['avatar_fchar'] : '',
						),
					),

 

operation: bowtruckles & bombs

R6MmD.png

Link to comment
Share on other sites

The first one is querying for alliance_color and department_color but you didn't join the tables. When you ping the database for two different instances of the same column in the same table, as well, you'll need to alias them so the query doesn't get confused.

		$result = $smcFunc['db_query']('substring', '
			SELECT
				t.id_topic, t.num_replies, t.locked, t.num_views, t.is_sticky, t.id_poll, t.id_previous_board,
				' . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from,
				t.id_last_msg, t.approved, t.unapproved_posts, t.topic_description, ml.poster_time AS last_poster_time,
				ml.id_msg_modified, ml.subject AS last_subject, ml.icon AS last_icon,
				ml.poster_name AS last_member_name, ml.id_member AS last_id_member,
				IFNULL(meml.real_name, ml.poster_name) AS last_display_name, t.id_first_msg,
				mf.poster_time AS first_poster_time, mf.subject AS first_subject, mf.icon AS first_icon,
				mf.poster_name AS first_member_name, mf.id_member AS first_id_member,
				mf.id_character AS id_fchar, ml.id_character AS id_lchar,
				ch1.image AS avatar_fchar, ch2.image AS avatar_lchar, ch1.name_first AS firstchar_namefirst, ch1.name_last AS firstchar_namelast,
				ch2.name_first AS lastchar_namefirst, ch2.name_last AS lastchar_namelast,
				al1.alliance_color AS ac1, dp1.department_color AS dc1, al2.alliance_color AS ac2, dp2.department_color AS dc2,
				IFNULL(memf.real_name, mf.poster_name) AS first_display_name, SUBSTRING(ml.body, 1, 385) AS last_body,
				SUBSTRING(mf.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys
			FROM {db_prefix}topics AS t
				INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
				INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
				LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
				LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
				LEFT JOIN {db_prefix}acm_characters AS ch1 ON (mf.id_character = ch1.id_character)
				LEFT JOIN {db_prefix}acm_characters AS ch2 ON (ml.id_character = ch2.id_character)
				LEFT JOIN {db_prefix}acm_alliances AS al1 ON (ch1.id_alliance = al1.id_alliance)
				LEFT JOIN {db_prefix}acm_alliances AS al2 ON (ch2.id_alliance = al2.id_alliance)
				LEFT JOIN {db_prefix}acm_departments AS dp1 ON (ch1.id_department = dp1.id_department)
				LEFT JOIN {db_prefix}acm_departments AS dp2 ON (ch2.id_department = dp2.id_department)' . ($user_info['is_guest'] ? '' : '
				LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
				LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = {int:current_board} AND lmr.id_member = {int:current_member})'). '

To make it shorter, I joined the alliance and department colours as ac1/ac2 and dc1/dc2 here, so if you just copy-pasta this, the HTML in the topics array looks like this:

'link' => !empty($row['id_fchar']) ? '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row['id_fchar'].'"'.(!empty($row['dc1']) ? ' style="color: '.$row['dc1'].';"' : (!empty($row['ac1']) ? ' style="color: '.$row['ac1'].';"' : '')).'>'.$firstchar_name.'</a>' : '',
'link' => !empty($row['id_lchar']) ? '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row['id_lchar'].'"'.(!empty($row['dc2']) ? ' style="color: '.$row['dc2'].';"' : (!empty($row['ac2']) ? ' style="color: '.$row['ac2'].';"' : '')).'>'.$lastchar_name.'</a>' : '',

For board index, you need to be in Subs-BoardIndex.php.

	$result_boards = $smcFunc['db_query']('boardindex_fetch_boards', '
		SELECT' . ($boardIndexOptions['include_categories'] ? '
			c.id_cat, c.name AS cat_name,' : '') . '
			b.id_board, b.name AS board_name, b.description,
			CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect,
			b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent,
			IFNULL(m.poster_time, 0) AS poster_time, IFNULL(mem.member_name, m.poster_name) AS poster_name,
			m.subject, m.id_topic, IFNULL(mem.real_name, m.poster_name) AS real_name,
			' . ($user_info['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
			(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read, IFNULL(lb.id_msg, -1) + 1 AS new_from,' . ($boardIndexOptions['include_categories'] ? '
			c.can_collapse, IFNULL(cc.id_member, 0) AS is_collapsed,' : '')) . '
			IFNULL(mem.id_member, 0) AS id_member, m.id_msg,
			IFNULL(mods_mem.id_member, 0) AS id_moderator, mods_mem.real_name AS mod_real_name,
			m.id_character, ch.image, ch.name_first, ch.name_last, al.alliance_color, dp.department_color
		FROM {db_prefix}boards AS b' . ($boardIndexOptions['include_categories'] ? '
			LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
			LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
			LEFT JOIN {db_prefix}acm_characters AS ch ON (m.id_character = ch.id_character)
			LEFT JOIN {db_prefix}acm_alliances AS al ON (ch.id_alliance = al.id_alliance)
			LEFT JOIN {db_prefix}acm_departments AS dp ON (ch.id_department = dp.id_department)' . ($user_info['is_guest'] ? '' : '
			LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})' . ($boardIndexOptions['include_categories'] ? '
			LEFT JOIN {db_prefix}collapsed_categories AS cc ON (cc.id_cat = c.id_cat AND cc.id_member = {int:current_member})' : '')) . '
			LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board)
			LEFT JOIN {db_prefix}members AS mods_mem ON (mods_mem.id_member = mods.id_member)
		WHERE {query_see_board}' . (empty($boardIndexOptions['countChildPosts']) ? (empty($boardIndexOptions['base_level']) ? '' : '
			AND b.child_level >= {int:child_level}') : '
			AND b.child_level BETWEEN ' . $boardIndexOptions['base_level'] . ' AND ' . ($boardIndexOptions['base_level'] + 1)),
		array(
			'current_member' => $user_info['id'],
			'child_level' => $boardIndexOptions['base_level'],
			'blank_string' => '',
		)
	);

And then in the character bit (it's quite a fucking ways down):

'link' => !empty($row_board['id_character']) ? '<a href="'.$scripturl.'?action=characters;area=profile;id='.$row_board['id_character'].'"'.(!empty($row_board['department_color']) ? ' style="color: '.$row_board['department_color'].';"' : (!empty($row_board['alliance_color']) ? ' style="color: '.$row_board['alliance_color'].';"' : '')).'>'.$character_name.'</a>' : '',

 

  • Thank you 1

nusignature.png nusignature.png

I am the darkness, always watching, always listening, ALWAYS THERE.
(If you're interested in Plain of Ice, message me, it's private. Bleach site, non-canon.)

Link to comment
Share on other sites

Thank you soooo much. One day I will understand db queries. One day. 😛 

 

awesome art GIF by #SayItWithPS

 

operation: bowtruckles & bombs

R6MmD.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use, Guidelines and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.